Map Resampling and Superpixels

In this example you will see how to resample a map using the resample method (which implements interpolation) and superpixels.

Start by importing the necessary modules.

from __future__ import print_function, division

import astropy.units as u

import sunpy.map
import sunpy.data.sample

Sunpy sample data contains a number of suitable maps, where the sunpy.data.sample.NAME returns the location of the given FITS file.

aia_map = sunpy.map.Map(sunpy.data.sample.AIA_171_IMAGE)

This has a resolution of:

print(aia_map.dimensions)

Out:

Pair(x=<Quantity 1024.0 pix>, y=<Quantity 1024.0 pix>)

To find out more specifics about this map and the instrument used, check it’s metatdata:

print(aia_map.meta)

Out:

MapMeta([('simple', True), ('bitpix', 32), ('naxis', 2), ('naxis1', 1024), ('naxis2', 1024), ('extend', True), ('comment', "FITS (Flexible Image Transport System) format is defined in 'Astronomy  and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H"), ('origin', 'SDO/JSOC-SDP'), ('date', '2011-03-19T11:08:25'), ('telescop', 'SDO/AIA'), ('instrume', 'AIA_3'), ('date-obs', '2011-03-19T10:54:00.34'), ('t_obs', '2011-03-19T10:54:01.34Z'), ('tobsstep', 90.0), ('tobsepoc', '1977.01.01_00:00:00_TAI'), ('camera', 3), ('img_type', 'LIGHT'), ('exptime', 1.999601), ('expsdev', 0.00016), ('int_time', 2.273438), ('wavelnth', 171), ('waveunit', 'angstrom'), ('wave_str', '171_THIN'), ('fsn', 22642033), ('fid', 0), ('lvl_num', 1.5), ('quallev0', 0), ('quality', 1073741824), ('totvals', 16777216), ('datavals', 16777216), ('missvals', 0), ('percentd', 100.0), ('datamin', -7), ('datamax', 16228), ('datamedn', 192), ('datamean', 236.57), ('datarms', 294.02), ('dataskew', 4.63), ('datakurt', 49.56), ('oscnmean', 'nan'), ('oscnrms', 'nan'), ('flat_rec', 'aia.flatfield[:#7]'), ('ctype1', 'HPLN-TAN'), ('cunit1', 'arcsec'), ('crval1', 0.0), ('cdelt1', 2.4), ('crpix1', 512.5), ('ctype2', 'HPLT-TAN'), ('cunit2', 'arcsec'), ('crval2', 0.0), ('cdelt2', 2.4), ('crpix2', 512.5), ('crota2', 0.0), ('r_sun', 1608.94397), ('mpo_rec', 'sdo.master_pointing[:#116]'), ('inst_rot', 0.102488), ('imscl_mp', 0.599076), ('x0_mp', 2052.399902), ('y0_mp', 2046.589966), ('rsun_lf', 'nan'), ('x0_lf', 'nan'), ('y0_lf', 'nan'), ('asd_rec', 'sdo.lev0_asd_0004[:#8948067]'), ('sat_y0', -0.365593), ('sat_z0', 14.820671), ('sat_rot', -8.8e-05), ('acs_mode', 'SCIENCE'), ('acs_eclp', 'NO'), ('acs_sunp', 'YES'), ('acs_safe', 'NO'), ('acs_cgt', 'GT3'), ('orb_rec', 'sdo.fds_orbit_vectors[2011.03.19_10:54:00_UTC]'), ('dsun_ref', 149597870691.0), ('dsun_obs', 148940609626.98), ('rsun_ref', 696000000.0), ('rsun_obs', 963.879683), ('gciec_x', 'nan'), ('gciec_y', 'nan'), ('gciec_z', 'nan'), ('hciec_x', 'nan'), ('hciec_y', 'nan'), ('hciec_z', 'nan'), ('obs_vr', -2132.568376), ('obs_vw', 30775.731671), ('obs_vn', 2177.6711), ('crln_obs', 315.285065), ('crlt_obs', -7.064078), ('car_rot', 2108), ('roi_nwin', -2147483648), ('roi_sum', -2147483648), ('roi_nax1', -2147483648), ('roi_nay1', -2147483648), ('roi_llx1', -2147483648), ('roi_lly1', -2147483648), ('roi_nax2', -2147483648), ('roi_nay2', -2147483648), ('roi_llx2', -2147483648), ('roi_lly2', -2147483648), ('ispsname', 'aia.lev0_isp_0011'), ('isppktim', '2011-03-19T10:53:57.50Z'), ('isppktvn', '001.197'), ('aivnmst', 453), ('aimgots', 1679223275), ('asqhdr', 2170125681), ('asqtnum', 2), ('asqfsn', 22642033), ('aiahfsn', 22642025), ('aecdelay', 1540), ('aiaecti', 0), ('aiasen', 0), ('aifdbid', 241), ('aimgotss', 5339), ('aifcps', 10), ('aiftswth', 0), ('aifrmlid', 3024), ('aiftsid', 40960), ('aihismxb', 7), ('aihis192', 8381297), ('aihis348', 8388262), ('aihis604', 8388597), ('aihis860', 8388603), ('aifwen', 204), ('aimgshce', 2000), ('aectype', 0), ('aecmode', 'ON'), ('aistate', 'CLOSED'), ('aiaecenf', 1), ('aifiltyp', 0), ('aimshobc', 41.099998), ('aimshobe', 26.076), ('aimshotc', 55.312), ('aimshote', 69.316002), ('aimshcbc', 2040.791992), ('aimshcbe', 2025.864014), ('aimshctc', 2054.875977), ('aimshcte', 2068.676025), ('aicfgdl1', 0), ('aicfgdl2', 137), ('aicfgdl3', 201), ('aicfgdl4', 236), ('aifoenfl', 1), ('aimgfsn', 5), ('aimgtyp', 0), ('aiawvlen', 7), ('aiagp1', 0), ('aiagp2', 0), ('aiagp3', 0), ('aiagp4', 0), ('aiagp5', 0), ('aiagp6', 0), ('aiagp7', 0), ('aiagp8', 393), ('aiagp9', 457), ('aiagp10', 748), ('agt1svy', 18), ('agt1svz', 10), ('agt2svy', 10), ('agt2svz', 8), ('agt3svy', 2), ('agt3svz', 0), ('agt4svy', 14), ('agt4svz', 0), ('aimgshen', 4), ('recnum', 76202), ('blank', -2147483648), ('bzero', 0.0), ('bscale', 0.0625), ('checksum', 'J7qAL7o6J7oAJ7o5'), ('datasum', '3958014355'), ('history', ''), ('keycomments', {'NAXIS': 'number of data axes', 'NAXIS1': 'length of data axis 1', 'DATASUM': 'data unit checksum updated 2011-03-19T11:08:18', 'EXTEND': 'FITS dataset may contain extensions', 'BITPIX': 'number of bits per data pixel', 'SIMPLE': 'file does conform to FITS standard', 'CHECKSUM': 'HDU checksum updated 2011-03-19T11:08:18', 'NAXIS2': 'length of data axis 2'}), ('detector', 'AIA')])

To reduce the angular resolution of the map you can use the resample method, specifying the dimensions as an Astropy Quantity in pixels:

dimensions = u.Quantity([40, 40], u.pixel)
aia_resampled_map = aia_map.resample(dimensions)
aia_resampled_map.peek(draw_limb=True, draw_grid=True)
# Note that this uses linear interpolation, you can change this using the method
# (‘neighbor’, ‘nearest’, ‘linear’ or ‘spline’) keyword argument option.
../../../_images/sphx_glr_map_resampling_and_superpixels_001.png

Similar to resampling you can use the superpixel method, this will reduce the resolution of the image by combining the number of pixels (in each dimension) in the dimensions argument into one single pixel. This can be used to increase the signal to noise ratio. For this the new dimensions must divide original image size exactly, for example you can reduce the AIA map resolution by a factor of 16 using:

dimensions = u.Quantity(aia_map.dimensions) / 16
aia_superpixel_map = aia_map.superpixel(dimensions)
aia_superpixel_map.peek(draw_limb=True, draw_grid=True)
../../../_images/sphx_glr_map_resampling_and_superpixels_002.png

Total running time of the script: ( 0 minutes 0.864 seconds)

Generated by Sphinx-Gallery