Created
October 19, 2021 09:46
-
-
Save dstansby/40da5f009774ba169490d36896917988 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sunpy.map | |
from astropy.wcs import WCS | |
from reproject import reproject_interp | |
import matplotlib.pyplot as plt | |
import astropy.units as u | |
# Load WISPR map | |
m = sunpy.map.Map('~/Downloads/psp_L1_wispr_20200125T000229_V1_2302.fits') | |
# Create a new WCS in a helioprojective (HPLN/HPLT) coordinate system with a | |
# plate-carée projection (CAR) | |
new_wcs = {'ctype1': 'HPLN-CAR', | |
'ctype2': 'HPLT-CAR', | |
'cunit1': 'deg', | |
'cunit2': 'deg', | |
# Reference pixel coordinate values | |
'crval1': 0, | |
'crval2': 0, | |
# Reference pixel | |
'crpix1': 0, | |
'crpix2': 180, | |
# Pixel size in (deg/pixel) | |
'cdelt1': 0.5, | |
'cdelt2': 0.5} | |
# Copy observer information from WISPR map to new WCS | |
for obs_key in ['DSUN_OBS', 'RSUN_REF', 'HGLT_OBS', 'HGLN_OBS', 'DATE-OBS']: | |
new_wcs[obs_key] = m.meta[obs_key] | |
# Reproject into the new WCS | |
new_wcs = WCS(new_wcs) | |
array, footprint = reproject_interp((m.data, m.wcs), new_wcs, shape_out=(360, 360)) | |
new_map = sunpy.map.Map(array, new_wcs) | |
# Plot new map | |
fig = plt.figure() | |
ax = fig.add_subplot(111, projection=new_map) | |
new_map.plot(axes=ax) | |
lon = ax.coords[0].set_format_unit(u.deg) | |
lat = ax.coords[1].set_format_unit(u.deg) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment