%matplotlib inline import matplotlib.pyplot as plt import numpy as np import sunpy sunpy.system_info() import wcsaxes wcsaxes.__version__ import sunpy.coordinates import astropy.units as u from astropy.coordinates import SkyCoord SkyCoord(100*u.arcsec, 200*u.arcsec, frame='helioprojective') import sunpy.map hmimap = sunpy.map.Map('/home/stuart/SyncBox/Programming/SunPy/hmi_m_45s_2014_03_01_00_01_30_tai_magnetogram_fits.fits') %matplotlib inline hmimap.plot() from astropy.wcs import WCS def get_wcs(smap): """ Use map properties to generate an astropy WCS object """ w2 = WCS(naxis=2) w2.wcs.crpix = [smap.reference_pixel['x'], smap.reference_pixel['y']] w2.wcs.cdelt = [smap.scale['x'], smap.scale['y']] w2.wcs.crval = [smap.reference_coordinate['x'], smap.reference_coordinate['y']] w2.wcs.ctype = [smap.coordinate_system['x'], smap.coordinate_system['y']] w2.wcs.pc = smap.rotation_matrix w2.wcs.cunit = [smap.units['x'], smap.units['y']] return w2 hmimap.wcs = get_wcs(hmimap) def frame_hpln_hplt(wcs): if wcs.wcs.ctype[0].find('HPLN') != -1 and wcs.wcs.ctype[1].find('HPLT') != -1: return sunpy.coordinates.HelioProjective from wcsaxes.utils import register_coordinate_system_identifier register_coordinate_system_identifier(frame_hpln_hplt) coordmap = {'type': ['longitude', 'latitude'], 'wrap':[180, None], 'unit':['arcsec', 'arcsec'], 'name':['lon', 'lat']} # Make colorscale figure fig = plt.figure(figsize=(6,6)) # Create axes ax = wcsaxes.WCSAxes(fig, [0.1, 0.1, 0.8, 0.8], wcs=hmimap.wcs) fig.add_axes(ax) # Show colormap hmimap.plot(axes=ax, extent=None, vmin=np.nanmin(hmimap), vmax=np.nanmax(hmimap)*0.3) x = ax.coords[0] y = ax.coords[1] x.set_major_formatter('s.s') y.set_major_formatter('s.s') ax.coords.grid(color='black', alpha=0.9) overlay = ax.get_coords_overlay('heliocentric', coord_meta=coordmap) lon = overlay[0] lat = overlay[1] lon.coord_wrap = 180 lon.set_major_formatter('dd') lon.set_ticklabel(size='x-small') lat.set_ticklabel(size='x-small') lon.set_axislabel('Solar Longitude', weight='bold') lat.set_axislabel('Solar Latitude', weight='bold') lon.set_ticks_position('tr') lat.set_ticks_position('tr') lon.set_ticks(spacing=5. * u.deg, color='white') lat.set_ticks(spacing=5. * u.deg, color='white') overlay.grid(color='black', alpha=1) overlay