Submaps and Cropping

In this example we demonstrate how to get a submap of a map.

Start by importing the necessary modules.

from __future__ import print_function, division

import astropy.units as u
from astropy.coordinates import SkyCoord

import sunpy.map
import sunpy.data.sample
import matplotlib.pyplot as plt

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

swap_map = sunpy.map.Map(sunpy.data.sample.SWAP_LEVEL1_IMAGE)

This has resolution and ranges of:

print(swap_map.dimensions)
print(swap_map.data)

Out:

PixelPair(x=<Quantity 1024. pix>, y=<Quantity 1024. pix>)
[[0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 ...
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]]

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

print(swap_map.meta)

Out:

MetaDict([('simple', True), ('bitpix', 16), ('naxis', 2), ('naxis1', 1024), ('naxis2', 1024), ('comment', '------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------$Id: swap_fits_template 3732 2010-09-28 20:42:23Z bogdan $------------------------------------------------------------------------------------------------------------------------------------------------This is a level-1 SWAP FITS file produced by p2sw_prep v1.3 at the Royal  Observatory of Belgium. If you have difficulty with this file or wish  to make suggestions for improvements, please contact the SWAP  Instrument Team via email at swap_lyra@oma.be.------------------------------------------------------------------------'), ('filename', 'swap_lv1_20110607_063329.fits'), ('file_tmr', 'swap_00823959642982_2d12fa4a.fits'), ('file_raw', 'BINSWAP201106070633430000335466PROCESSED'), ('file_tar', 'BINSWAP_4818_SVA1_2011.06.07T09.40.44.tar'), ('date', '2011-11-22T19:48:23'), ('date-obs', '2011-06-07T06:33:29.759'), ('level', 1), ('creator', 'P2SW_PREP.PRO v1.3'), ('origin', 'ROB'), ('telescop', 'PROBA2'), ('instrume', 'SWAP'), ('object', 'Sun EUV'), ('filter', 'Al'), ('detector', 'SWAP'), ('wavelnth', 174), ('obs_mode', 'Variable off-pointing'), ('cap_mode', 'CDS'), ('exptime', 10.0), ('bscale', 0.00625), ('bzero', 204.8), ('bunit', 'DN/s/pixel'), ('datamin', 0.0), ('datamax', 368.088), ('swavint', 13.4808), ('firstrow', 1), ('last_row', 1024), ('firstcol', 1), ('last_col', 1024), ('rebin', 'off'), ('wcsname', 'Helioprojective-cartesian'), ('ctype1', 'HPLN-TAN'), ('ctype2', 'HPLT-TAN'), ('cunit1', 'arcsec'), ('cunit2', 'arcsec'), ('cd1_1', 3.16227), ('cd1_2', 0.0), ('cd2_1', 0.0), ('cd2_2', 3.16227), ('cdelt1', 3.16226783969), ('cdelt2', 3.16226783969), ('crval1', 0.0), ('crval2', 0.0), ('crpix1', 512.5), ('crpix2', 512.5), ('lonpole', 180.0), ('crota1', 0.0), ('crota2', 0.0), ('swxcen', 478.45), ('swycen', 534.28), ('dtplar1', 365.0), ('dtplar2', 2000.0), ('p2_x0', 0.0124005594716), ('p2_y0', 0.0253841016749), ('p2_roll', 179.998572874), ('solar_ep', 7.25187694733), ('hglt_obs', 0.0340964722021), ('hgln_obs', -0.000849540811517), ('rsun_arc', 945.587958879), ('dsun_obs', 151820143333.0), ('heex_obs', 151820143176.0), ('heey_obs', -3056074.7792), ('heez_obs', -6183475.65411), ('gsex_obs', -1667474.1514), ('gsey_obs', 3056074.77919), ('gsez_obs', -6183475.6541), ('los_alt', 531927.560994), ('trapprot', 0.0), ('trapelec', 2.45), ('geod_alt', 733468.040583), ('geod_lat', -58.3028506576), ('geod_lon', 160.297951898), ('temp1det', 2.629999), ('temp2det', 2.629999), ('ttemp1', '2011-06-07T06:33:06.000'), ('ttemp2', '2011-06-07T06:33:36.000'), ('tempdark', 2.629999), ('is_proc', 1), ('trantime', 823959642982.0), ('sacqtime', 823959415264.0), ('eacqtime', 823959642982.0), ('lang_rot', 1.0), ('pav_rot0', 0.0), ('pav_rot1', 0.0), ('hasstdby', 0), ('readrdiv', 0), ('pga_offs', 59), ('pga_gain', 1), ('led_pow', 'off'), ('led_sel', 'a'), ('hasblack', 4), ('hasoffst', 11), ('artefx', 'on'), ('recoding', 'fixed'), ('recnum', 3600), ('recbias', 10), ('compress', 'jpeg'), ('lzwdecor', 'off'), ('pn', 131), ('sizcompi', 664256), ('nprescr', 0), ('npreslzw', 0), ('checksum', 'J9lTK7lRJ7lRJ7lR'), ('datasum', '3949782845'), ('history', 'SWTMR 10448SWEDG 10994FITSHEAD2STRUCT run at: Tue Nov 22 19:48:16 2011p2sw_hdrchk v1.3  Computed detector temp.: 2.6299990 Celsiusp2sw_pmcdiv v1.3  Reverted wrt swap_pmc_20100308_164500.fitsp2sw_pixrep v1.3  Replaced wrt swap_satcds_20100113_152800.fitsp2sw_drksub v1.3  Subtracted modeled dark with coefficients inp2sw_drksub v1.3   swap_dark_coefs_20110101_000000.save usingp2sw_drksub v1.3   T=275.78 K, dt=10.0000 sp2sw_pmcrep v1.3  Reverted wrt swap_pmc_20100308_164500.fitsp2sw_ffcorr v1.3  Flat-field: swap_flatcds_20100308_164500.fitsp2sw_despike v1.3  Despiked at the 6.0-sigma level (7061 pix)p2sw_imgcor v1.3  Image centred on solar disk centrep2sw_imgcor v1.3  Image scaled to square pixelsp2sw_imgcor v1.3  Image rotated to solar North upp2sw_expnorm v1.3  Exposure time normalized data (DN/s/pixel)'), ('keycomments', {'CUNIT1': 'WCS axis X units', 'LZWDECOR': 'LZW decorrelation', 'LOS_ALT': '[m]   s/c LOS altitude (1000000=no atmosphere)', 'HEEX_OBS': '[m]   s/c Heliocentric Earth Ecliptic X', 'LONPOLE': '[deg] native longitude of the celestial pole', 'RECNUM': 'recoding upper limit', 'TEMP1DET': '[Celsius] detector temperature (SW HK T CF)', 'GSEX_OBS': '[m]   s/c Geocentric   Solar Ecliptic X', 'GEOD_LAT': '[deg] s/c sub-point geodetic latitude', 'CRPIX1': '[pixel] reference point axis 1', 'CTYPE2': 'WCS axis Y', 'HASBLACK': 'HAS detector black  level', 'BUNIT': 'unit of physical value', 'RSUN_ARC': '[arcsec] photospheric solar radius', 'READRDIV': 'read-out rate divider', 'CUNIT2': 'WCS axis Y units', 'PAV_ROT0': 'commanded paving rotation component 0', 'REBIN': 'on-board rebin (2x2 pixel average)', 'EXPTIME': '[s] commanded exposure time', 'TEMPDARK': '[Celsius] temperature used in dark subtraction', 'TTEMP1': 'UTC time of detector temp 1st sample', 'LAST_ROW': 'last  read-out detector row', 'DETECTOR': 'HAS CMOS detector 1024x1024 pixels', 'NPRESLZW': '# preserved pixels - LZW decorrelation', 'PGA_GAIN': 'PGA gain', 'SIMPLE': 'Written by IDL:  Tue Nov 22 19:48:23 2011', 'DTPLAR1': '[s] predicted time to prev large angle rotation', 'FIRSTCOL': 'first read-out detector column', 'ARTEFX': '(off,on,cosmic rays) on-board artefact removal', 'PAV_ROT1': 'commanded paving rotation component 1', 'DATE': 'UTC time of FITS file creation', 'EACQTIME': '[OBET] end   acquisition time', 'HEEZ_OBS': '[m]   s/c Heliocentric Earth Ecliptic Z', 'CROTA2': '[deg] axis 2 to WCS rotation angle', 'PN': 'on-board priority number', 'TRAPELEC': '[ct/cm^2/s] AE-8 MAX >  1MeV @ 725km model', 'IS_PROC': 'on-board image processing', 'CHECKSUM': 'HDU checksum updated 2011-11-22T19:48:23', 'TEMP2DET': '[Celsius] detector temperature (SW HK T CF)', 'CDELT1': '[arcsec] average pixel scale along axis 1', 'LANG_ROT': 'commanded large angle rotation component', 'DSUN_OBS': '[m]   s/c distance from Sun', 'P2_Y0': '[deg] s/c pitch', 'NAXIS1': 'length of data axis 1', 'TTEMP2': 'UTC time of detector temp 2nd sample', 'HASSTDBY': 'HAS detector standby mode', 'HGLN_OBS': '[deg] s/c heliographic longitude', 'OBJECT': 'object observed', 'FILTER': 'Aluminum filter', 'DATE-OBS': 'UTC time of observation', 'NPRESCR': '# preserved pixels - cosmic rays', 'WAVELNTH': '[Angstrom] bandpass peak response', 'LED_SEL': 'calibration LED selection', 'SIZCOMPI': 'size of on-board compressed image', 'NAXIS': 'number of data axes', 'SWXCEN': '[pixel] axis 1 location of solar center in lv0', 'PGA_OFFS': 'PGA offset', 'GEOD_LON': '[deg] s/c sub-point longitude', 'COMPRESS': '(off,lzw,jpeg) on-board compression algorithm', 'CD2_2': 'WCS coordinate description matrix', 'CAP_MODE': '(DS,CDS) capture mode', 'SWYCEN': '[pixel] axis 2 location of solar center in lv0', 'CTYPE1': 'WCS axis X', 'CD1_1': 'WCS coordinate description matrix', 'FILE_TAR': 'raw telemetry package', 'OBS_MODE': 'sun_cen, fix_off, var_off, cme_track', 'HGLT_OBS': '[deg] s/c heliographic latitude', 'FILE_TMR': 'SWTMR filename', 'LED_POW': 'calibration LED power', 'GEOD_ALT': '[m]   s/c WGS84 altitude', 'RECODING': '(off,fixed,adaptive) on-board recoding', 'P2_X0': '[deg] s/c yaw', 'HASOFFST': 'HAS detector offset level', 'CD2_1': 'WCS coordinate description matrix', 'BZERO': 'physical value for the array value 0', 'INSTRUME': 'instrument name', 'DTPLAR2': '[s] predicted time to next large angle rotation', 'FILENAME': 'FITS filename', 'CD1_2': 'WCS coordinate description matrix', 'FILE_RAW': 'raw telemetry filename', 'CRPIX2': '[pixel] reference point axis 2', 'SWAVINT': '[DN/s] average intensity in calibrated image', 'BITPIX': 'number of bits per data pixel', 'TELESCOP': 'satellite name', 'LAST_COL': 'last  read-out detector column', 'GSEY_OBS': '[m]   s/c Geocentric   Solar Ecliptic Y', 'CRVAL2': '[arcsec] reference point WCS axis Y', 'SACQTIME': '[OBET] start acquisition time', 'CREATOR': 'FITS creation software', 'WCSNAME': 'aligned with solar North', 'GSEZ_OBS': '[m]   s/c Geocentric   Solar Ecliptic Z', 'HEEY_OBS': '[m]   s/c Heliocentric Earth Ecliptic Y', 'DATAMAX': 'maximum valid physical value', 'DATAMIN': 'minimum valid physical value', 'CRVAL1': '[arcsec] reference point WCS axis X', 'TRAPPROT': '[ct/cm^2/s] AP-8 MAX > 10MeV @ 725km model', 'NAXIS2': 'length of data axis 2', 'CDELT2': '[arcsec] average pixel scale along axis 2', 'LEVEL': 'data processing level', 'ORIGIN': 'Royal Observatory of Belgium', 'CROTA1': '[deg] axis 1 to WCS rotation angle', 'RECBIAS': 'recoding lower limit', 'P2_ROLL': '[deg] s/c roll', 'BSCALE': 'ratio of physical to array value at 0 offset', 'SOLAR_EP': '[deg] s/c ecliptic North to solar North angle', 'FIRSTROW': 'first read-out detector row', 'DATASUM': 'data unit checksum updated 2011-11-22T19:48:23', 'TRANTIME': '[OBET] transferring time'}), ('waveunit', 'Angstrom'), ('obsrvtry', 'PROBA2')])

To crop the data you create a submap, specifying the top right and bottom left as SkyCoord objects.

top_right = SkyCoord(0*u.arcsec, -200 * u.arcsec, frame=swap_map.coordinate_frame)
bottom_left = SkyCoord(-900 * u.arcsec, -900 * u.arcsec, frame=swap_map.coordinate_frame)
swap_submap = swap_map.submap(bottom_left, top_right)
swap_submap.peek(draw_limb=True, draw_grid=True)
plt.tight_layout(pad=1.00)
plt.show()
../../_images/sphx_glr_submaps_and_cropping_001.png

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

Gallery generated by Sphinx-Gallery