Note
Go to the end to download the full example code.
Reproject PHI Blos to CEA#
This example demonstrates how to reproject line-of-sight magnetic field (L2 Blos) data from the Solar Orbiter PHI instrument to a CEA projection.
import sunpy.map
import astropy.units as u
from astropy.wcs import WCS
from astropy.io import fits
import sunpy.coordinates
from sunpy.coordinates import propagate_with_solar_surface
from sunpy.map.header_helper import make_fitswcs_header
import numpy as np
import os
import sunpy_soar
from sunpy.net import Fido, attrs as a
from astropy.time import Time
import sunpy.visualization.colormaps
import matplotlib.pyplot as plt
Searching for PHI-HRT Blos Data#
We first search for Solar Orbiter PHI-HRT (High Resolution Telescope) Blos data in a given time range. The search results will return metadata about available files.
t_start_hrt = Time('2024-10-14T00:25:00', format='isot', scale='utc')
t_end_hrt = Time('2024-10-14T00:35:00', format='isot', scale='utc')
search_results_phi_hrt = Fido.search(a.Instrument('PHI'), a.Time(t_start_hrt.value, t_end_hrt.value), (a.soar.Product('phi-hrt-blos')))
print(search_results_phi_hrt)
sr_phi_hrt = search_results_phi_hrt[0,0]
blos_file = Fido.fetch(sr_phi_hrt)
blos_map = sunpy.map.Map(blos_file[0])
Results from 1 Provider:
1 Results from the SOARClient:
Instrument Data product Level Start time End time Filesize SOOP Name Detector Wavelength
Mbyte
---------- ------------ ----- ----------------------- ----------------------- -------- ------------------------------ -------- ----------
PHI phi-hrt-blos L2 2024-10-14 00:29:55.981 2024-10-14 00:31:19.289 13.081 R_SMALL_MRES_MCAD_AR-Long-Term HRT 6173.341
Files Downloaded: 0%| | 0/1 [00:00<?, ?file/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 0%| | 0.00/13.1M [00:00<?, ?B/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 0%| | 1.02k/13.1M [00:00<38:03, 5.73kB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 0%| | 63.9k/13.1M [00:00<00:47, 276kB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 1%| | 120k/13.1M [00:00<00:34, 378kB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 2%|▏ | 250k/13.1M [00:00<00:18, 684kB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 3%|▎ | 380k/13.1M [00:00<00:14, 869kB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 4%|▍ | 510k/13.1M [00:00<00:12, 988kB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 5%|▍ | 640k/13.1M [00:00<00:11, 1.06MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 6%|▌ | 770k/13.1M [00:00<00:11, 1.12MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 7%|▋ | 901k/13.1M [00:01<00:10, 1.15MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 8%|▊ | 1.03M/13.1M [00:01<00:10, 1.18MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 9%|▉ | 1.16M/13.1M [00:01<00:09, 1.19MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 10%|▉ | 1.29M/13.1M [00:01<00:09, 1.20MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 11%|█ | 1.42M/13.1M [00:01<00:09, 1.21MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 12%|█▏ | 1.55M/13.1M [00:01<00:09, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 13%|█▎ | 1.68M/13.1M [00:01<00:09, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 14%|█▍ | 1.81M/13.1M [00:01<00:09, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 15%|█▍ | 1.94M/13.1M [00:01<00:09, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 16%|█▌ | 2.07M/13.1M [00:01<00:09, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 17%|█▋ | 2.20M/13.1M [00:02<00:08, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 18%|█▊ | 2.33M/13.1M [00:02<00:08, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 19%|█▉ | 2.46M/13.1M [00:02<00:08, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 20%|█▉ | 2.59M/13.1M [00:02<00:08, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 21%|██ | 2.72M/13.1M [00:02<00:08, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 22%|██▏ | 2.85M/13.1M [00:02<00:08, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 23%|██▎ | 2.98M/13.1M [00:02<00:08, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 24%|██▍ | 3.11M/13.1M [00:02<00:08, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 25%|██▍ | 3.24M/13.1M [00:02<00:08, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 26%|██▌ | 3.37M/13.1M [00:03<00:07, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 27%|██▋ | 3.50M/13.1M [00:03<00:07, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 28%|██▊ | 3.63M/13.1M [00:03<00:07, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 29%|██▊ | 3.76M/13.1M [00:03<00:07, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 30%|██▉ | 3.89M/13.1M [00:03<00:07, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 31%|███ | 4.02M/13.1M [00:03<00:07, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 32%|███▏ | 4.15M/13.1M [00:03<00:07, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 33%|███▎ | 4.28M/13.1M [00:03<00:07, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 34%|███▎ | 4.41M/13.1M [00:03<00:07, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 35%|███▍ | 4.54M/13.1M [00:03<00:06, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 36%|███▌ | 4.67M/13.1M [00:04<00:06, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 37%|███▋ | 4.80M/13.1M [00:04<00:06, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 38%|███▊ | 4.93M/13.1M [00:04<00:06, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 39%|███▊ | 5.06M/13.1M [00:04<00:06, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 40%|███▉ | 5.19M/13.1M [00:04<00:06, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 41%|████ | 5.32M/13.1M [00:04<00:06, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 42%|████▏ | 5.45M/13.1M [00:04<00:06, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 43%|████▎ | 5.58M/13.1M [00:04<00:06, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 44%|████▎ | 5.71M/13.1M [00:04<00:06, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 45%|████▍ | 5.84M/13.1M [00:05<00:05, 1.22MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 46%|████▌ | 5.97M/13.1M [00:05<00:05, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 47%|████▋ | 6.10M/13.1M [00:05<00:05, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 48%|████▊ | 6.23M/13.1M [00:05<00:05, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 49%|████▊ | 6.36M/13.1M [00:05<00:05, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 50%|████▉ | 6.49M/13.1M [00:05<00:05, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 51%|█████ | 6.62M/13.1M [00:05<00:05, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 52%|█████▏ | 6.75M/13.1M [00:05<00:05, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 53%|█████▎ | 6.88M/13.1M [00:05<00:05, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 54%|█████▎ | 7.01M/13.1M [00:06<00:04, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 55%|█████▍ | 7.14M/13.1M [00:06<00:04, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 56%|█████▌ | 7.27M/13.1M [00:06<00:04, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 57%|█████▋ | 7.40M/13.1M [00:06<00:04, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 58%|█████▊ | 7.53M/13.1M [00:06<00:04, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 59%|█████▊ | 7.66M/13.1M [00:06<00:04, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 60%|█████▉ | 7.79M/13.1M [00:06<00:04, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 61%|██████ | 7.92M/13.1M [00:06<00:04, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 62%|██████▏ | 8.05M/13.1M [00:06<00:04, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 63%|██████▎ | 8.18M/13.1M [00:06<00:03, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 64%|██████▎ | 8.31M/13.1M [00:07<00:03, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 65%|██████▍ | 8.44M/13.1M [00:07<00:03, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 66%|██████▌ | 8.57M/13.1M [00:07<00:03, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 67%|██████▋ | 8.70M/13.1M [00:07<00:03, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 68%|██████▊ | 8.83M/13.1M [00:07<00:03, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 69%|██████▊ | 8.96M/13.1M [00:07<00:03, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 70%|██████▉ | 9.09M/13.1M [00:07<00:03, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 71%|███████ | 9.22M/13.1M [00:07<00:03, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 71%|███████▏ | 9.35M/13.1M [00:07<00:03, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 72%|███████▏ | 9.48M/13.1M [00:08<00:02, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 73%|███████▎ | 9.61M/13.1M [00:08<00:02, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 74%|███████▍ | 9.74M/13.1M [00:08<00:02, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 75%|███████▌ | 9.87M/13.1M [00:08<00:02, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 76%|███████▋ | 10.0M/13.1M [00:08<00:02, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 77%|███████▋ | 10.1M/13.1M [00:08<00:02, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 78%|███████▊ | 10.3M/13.1M [00:08<00:02, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 79%|███████▉ | 10.4M/13.1M [00:08<00:02, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 80%|████████ | 10.5M/13.1M [00:08<00:02, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 81%|████████▏ | 10.7M/13.1M [00:08<00:01, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 82%|████████▏ | 10.8M/13.1M [00:09<00:01, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 83%|████████▎ | 10.9M/13.1M [00:09<00:01, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 84%|████████▍ | 11.0M/13.1M [00:09<00:01, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 85%|████████▌ | 11.2M/13.1M [00:09<00:01, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 86%|████████▋ | 11.3M/13.1M [00:09<00:01, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 87%|████████▋ | 11.4M/13.1M [00:09<00:01, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 88%|████████▊ | 11.6M/13.1M [00:09<00:01, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 89%|████████▉ | 11.7M/13.1M [00:09<00:01, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 90%|█████████ | 11.8M/13.1M [00:09<00:01, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 91%|█████████▏| 12.0M/13.1M [00:10<00:00, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 92%|█████████▏| 12.1M/13.1M [00:10<00:00, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 93%|█████████▎| 12.2M/13.1M [00:10<00:00, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 94%|█████████▍| 12.3M/13.1M [00:10<00:00, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 95%|█████████▌| 12.5M/13.1M [00:10<00:00, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 96%|█████████▋| 12.6M/13.1M [00:10<00:00, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 97%|█████████▋| 12.7M/13.1M [00:10<00:00, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 98%|█████████▊| 12.9M/13.1M [00:10<00:00, 1.23MB/s]
solo_L2_phi-hrt-blos_20241014T002955_V01_0450140601.fits: 99%|█████████▉| 13.0M/13.1M [00:10<00:00, 1.23MB/s]
Files Downloaded: 100%|██████████| 1/1 [00:11<00:00, 11.18s/file]
Files Downloaded: 100%|██████████| 1/1 [00:11<00:00, 11.18s/file]
blos_map.plot_settings['cmap'] = 'hmimag'
blos_map.plot_settings['vmin'] = -1500
blos_map.plot_settings['vmax'] = 1500
#blos_map.plot()
Reproject PHI Blos to CEA#
Make a CEA WCS header
from sunpy.map.mapbase import SpatialPair
from sunpy.coordinates import frames as cf
from astropy.coordinates import SkyCoord
cea_scale = u.Quantity(SpatialPair(0.03 * u.deg/u.pix, 0.03 * u.deg/u.pix)) # CEA scale in degrees. (same as HMI SHARP maps)
hgs_center = blos_map.center.transform_to(cf.HeliographicStonyhurst(obstime=blos_map.date))
dlon = 0.03 * u.deg # pixel size in longitude
dlat = 0.03 * u.deg # pixel size in latitude
lon_half_width = 25 * u.deg # +/- 30 deg around center of PHI-HRT image
lat_half_height = 15 * u.deg
nx = int(np.round((2 * lon_half_width / dlon).to_value(u.one)))
ny = int(np.round((2 * lat_half_height / dlat).to_value(u.one)))
ref_hgs = SkyCoord(hgs_center.lon, hgs_center.lat, frame=cf.HeliographicStonyhurst, obstime=blos_map.date)
cea_hdr = make_fitswcs_header((ny, nx), ref_hgs, scale=cea_scale, projection_code="CEA",\
instrument=blos_map.instrument, wavelength=blos_map.wavelength)
Reproject with Hann kernel#
with propagate_with_solar_surface():
outmap = blos_map.reproject_to(cea_hdr,algorithm='adaptive', kernel='Hann')
outmap.plot_settings['cmap'] = 'hmimag'
outmap.plot_settings['vmin'] = -1500
outmap.plot_settings['vmax'] = 1500
fig = plt.figure(figsize=(9,6))
ax = plt.subplot(projection=outmap) # WCS-aware axes
im = outmap.plot(axes=ax)
cbar = fig.colorbar(im, fraction=0.03)
cbar.set_label('BLOS [G]')

Compute Mu value in each PHI pixel to overplot contours of Mu#
mu = cos (heliocentric_angle)
$mu = cos(theta)$ where $theta$ is the heliocentric angle
it describes the angle between the line-of-sight and the surface normal vector on the Sun
Below are helper functions
def center_coord(hdr):
"""calculate the center of the solar disk in the rotated reference system
center: [x,y,1] coordinates of the solar disk center (units: pixel)
"""
pxsc = hdr['CDELT1']
crval1 = hdr['CRVAL1']
crval2 = hdr['CRVAL2']
crpix1 = hdr['CRPIX1']
crpix2 = hdr['CRPIX2']
if 'PC1_1' in hdr:
PC1_1 = hdr['PC1_1']
PC1_2 = hdr['PC1_2']
PC2_1 = hdr['PC2_1']
PC2_2 = hdr['PC2_2']
else:
if 'CROTA2' in hdr:
CROTA = hdr['CROTA2']
else:
CROTA = hdr['CROTA']
PC1_1 = np.cos(CROTA*np.pi/180)
PC1_2 = -np.sin(CROTA*np.pi/180)
PC2_1 = np.sin(CROTA*np.pi/180)
PC2_2 = np.cos(CROTA*np.pi/180)
HPC1 = 0
HPC2 = 0
x0 = crpix1 + 1/pxsc * (PC1_1*(HPC1-crval1) - PC1_2*(HPC2-crval2)) - 1
y0 = crpix2 + 1/pxsc * (PC2_2*(HPC2-crval2) - PC2_1*(HPC1-crval1)) - 1
return np.asarray([x0,y0,1])
def muSO_arr(h,shape):
"""compute mu in each pixel of array
"""
if type(h) is str:
h = fits.getheader(h)
center=center_coord(h)
try:
Rpix=(h['RSUN_ARC']/h['CDELT1']) # PHI
except:
Rpix=(h['RSUN_OBS']/h['CDELT1']) # HMI
X,Y = np.meshgrid(np.arange(shape[1]) - center[0],np.arange(shape[0]) - center[1])
mu = np.sqrt(Rpix**2 - (X**2 + Y**2)) / Rpix
return mu
hrt_mu = muSO_arr(blos_map.fits_header, blos_map.data.shape)
ax = plt.subplot(projection=blos_map)
im = plt.imshow(blos_map.data,origin="lower", cmap='hmimag', vmin=-1500, vmax=1500)
CS = plt.contour(hrt_mu, levels = np.linspace(0,1,11), colors='black')
plt.clabel(CS, inline=True, fontsize=10)
cbar = plt.colorbar(im)
cbar.set_label(r'$\mu$')
plt.show()

hrt_mu_map = sunpy.map.Map(hrt_mu, blos_map.fits_header)
with propagate_with_solar_surface():
out_mu_map = hrt_mu_map.reproject_to(cea_hdr,algorithm='adaptive', kernel='Hann')
fig = plt.figure(figsize=(9,6))
ax = plt.subplot(projection=outmap) # WCS-aware axes
im = outmap.plot(axes=ax)
CS = plt.contour(out_mu_map.data, levels=np.linspace(0, 1, 11), colors='black')
plt.clabel(CS, inline=True, fontsize=10)
cbar = fig.colorbar(im, fraction=0.03)
cbar.set_label('BLOS [G]')

Remap PHI-HRT BLOS onto HMI SHARP CEA magnetogram#
First get the nearest SHARP dataset
Set ‘JSOC_EMAIL’ environment variable to your registered email address to download data from JSOC
jsoc_email = os.environ["JSOC_EMAIL"]
result = Fido.search(
a.Time("2024-10-14 00:35:00", "2024-10-14 00:37:00"),
a.Sample(1*u.hour),
a.jsoc.Series("hmi.sharp_cea_720s"),
a.jsoc.PrimeKey("HARPNUM", 12032), #used JSOC, SolarMonitor and HEK to find out the right HARPNUM
a.jsoc.Notify(jsoc_email),
a.jsoc.Segment("magnetogram"))
print(result)
Results from 1 Provider:
1 Results from the JSOCClient:
Source: http://jsoc.stanford.edu
T_REC TELESCOP INSTRUME WAVELNTH CAR_ROT
----------------------- -------- ------------ -------- -------
2024.10.14_00:36:00_TAI SDO/HMI HMI_COMBINED 6173.0 2289
file = Fido.fetch(result)
INFO: 1 URLs found for download. Full request totaling 1MB [sunpy.net.jsoc.jsoc]
Files Downloaded: 0%| | 0/1 [00:00<?, ?file/s]
hmi.sharp_cea_720s.12032.20241014_003600_TAI.magnetogram.fits: 0%| | 0.00/870k [00:00<?, ?B/s]
hmi.sharp_cea_720s.12032.20241014_003600_TAI.magnetogram.fits: 0%| | 1.02k/870k [00:00<04:28, 3.23kB/s]
hmi.sharp_cea_720s.12032.20241014_003600_TAI.magnetogram.fits: 11%|█▏ | 99.0k/870k [00:00<00:02, 303kB/s]
hmi.sharp_cea_720s.12032.20241014_003600_TAI.magnetogram.fits: 49%|████▉ | 427k/870k [00:00<00:00, 1.19MB/s]
Files Downloaded: 100%|██████████| 1/1 [00:01<00:00, 1.06s/file]
Files Downloaded: 100%|██████████| 1/1 [00:01<00:00, 1.06s/file]
sharp_map = sunpy.map.Map(file)
sharp_map.plot_settings['cmap'] = 'hmimag'
fig = plt.figure(figsize=(9,6))
ax = fig.add_subplot(projection=sharp_map)
im = sharp_map.plot(axes=ax)
cbar = fig.colorbar(im, fraction=0.03)
cbar.set_label('BLOS [G]')
plt.show()

Plot PHI-HRT CEA Blos (60s) and HMI SHARP CEA (720s) magnetograms side by side#
Take a crop and plot.
Notice that there is a shift between them.
This can easily be corrected using a cross correlation function such as ‘image_register’ in the PHI WCS example
submap = outmap.submap(top_right = sharp_map.top_right_coord, bottom_left = sharp_map.bottom_left_coord)
submap.plot_settings = sharp_map.plot_settings #set the same plot settings
submap_mu = out_mu_map.submap(top_right = sharp_map.top_right_coord, bottom_left = sharp_map.bottom_left_coord)
fig = plt.figure(figsize=(12,10))
ax = plt.subplot(211, projection=sharp_map)
im = sharp_map.plot(axes=ax)
cbar = fig.colorbar(im, fraction=0.03)
cbar.set_label('BLOS [G]')
ax1 = plt.subplot(212, projection=sharp_map)
im1 = submap.plot(axes=ax1)
CS = plt.contour(submap_mu.data, levels=np.linspace(0, 1, 11), colors='black')
plt.clabel(CS, inline=True, fontsize=10)
cbar = fig.colorbar(im1, fraction=0.03)
cbar.set_label('BLOS [G]')
plt.tight_layout()
plt.show()

INFO: Using mesh-based autoalignment [sunpy.map.mapbase]
Alternatively, reproject the PHI Blos onto the HMI SHARP magnetogram#
def make_cea_hdr_for_phi(hmi_mag_map, phi_blos_map):
cea_hdr_phi = make_fitswcs_header(hmi_mag_map.data.shape, \
hmi_mag_map.reference_coordinate.replicate(rsun=phi_blos_map.reference_coordinate.rsun),\
projection_code='CEA',scale=u.Quantity(hmi_mag_map.scale),
instrument = phi_blos_map.instrument,
wavelength = phi_blos_map.wavelength)
cea_hdr_phi['dsun_obs'] = hmi_mag_map.coordinate_frame.observer.radius.to(u.m).value
cea_hdr_phi['hglt_obs'] = hmi_mag_map.coordinate_frame.observer.lat.value
cea_hdr_phi['hgln_obs'] = hmi_mag_map.coordinate_frame.observer.lon.value
cea_hdr_phi['crpix1'] = hmi_mag_map.fits_header['CRPIX1']
cea_hdr_phi['crpix2'] = hmi_mag_map.fits_header['CRPIX2']
cea_hdr_phi['crval1'] = hmi_mag_map.fits_header['CRVAL1']
cea_hdr_phi['crval2'] = hmi_mag_map.fits_header['CRVAL2']
cea_hdr_phi['PC1_1'] = 1
cea_hdr_phi['PC1_2'] = 0
cea_hdr_phi['PC2_1'] = 0
cea_hdr_phi['PC2_2'] = 1
cea_hdr_phi['cdelt1'] = hmi_mag_map.fits_header['cdelt1']
cea_hdr_phi['cdelt2'] = hmi_mag_map.fits_header['cdelt2']
return cea_hdr_phi
def reproject_phi_2_hmi_cea(phi_blos_map, cea_hdr_phi):
with propagate_with_solar_surface():
outmap = phi_blos_map.reproject_to(cea_hdr_phi,algorithm='adaptive', kernel='Hann')
return outmap
cea_on_hmi_hdr = make_cea_hdr_for_phi(sharp_map, blos_map)
phi_blos_on_sharp_map = reproject_phi_2_hmi_cea(blos_map, cea_on_hmi_hdr)
fig = plt.figure(figsize=(12,10))
ax = plt.subplot(211, projection=sharp_map)
im = sharp_map.plot(axes=ax)
cbar = fig.colorbar(im, fraction=0.03)
cbar.set_label('BLOS [G]')
phi_blos_on_sharp_map.plot_settings = sharp_map.plot_settings
ax1 = plt.subplot(212, projection=sharp_map)
im1 = phi_blos_on_sharp_map.plot(axes=ax1)
cbar = fig.colorbar(im1, fraction=0.03)
cbar.set_label('BLOS [G]')
plt.tight_layout()
plt.show()

INFO: Using image-based autoalignment [sunpy.map.mapbase]
Total running time of the script: (0 minutes 36.215 seconds)