Note
Go to the end to download the full example code.
Parsing ADAPT Ensemble .fits files#
Parse an ADAPT FITS file into a sunpy.map.MapSequence
.
import matplotlib.pyplot as plt
from matplotlib import gridspec
from astropy.io import fits
import sunpy.map
from sunkit_magex import pfss
Load an example ADAPT fits file.
adapt_fname = pfss.sample_data.get_adapt_map()
Files Downloaded: 0%| | 0/1 [00:00<?, ?file/s]
sunkit_magex.adapt40311_03k012_202001010000_i00005600n1.fts.gz: 0%| | 0.00/3.11M [00:00<?, ?B/s]
sunkit_magex.adapt40311_03k012_202001010000_i00005600n1.fts.gz: 0%| | 1.02k/3.11M [00:00<05:09, 10.0kB/s]
sunkit_magex.adapt40311_03k012_202001010000_i00005600n1.fts.gz: 23%|██▎ | 728k/3.11M [00:00<00:00, 4.23MB/s]
Files Downloaded: 100%|██████████| 1/1 [00:00<00:00, 2.66file/s]
Files Downloaded: 100%|██████████| 1/1 [00:00<00:00, 2.65file/s]
ADAPT synoptic magnetograms contain 12 realizations of synoptic magnetograms output as a result of varying model assumptions. See [here](https://www.swpc.noaa.gov/sites/default/files/images/u33/SWW_2012_Talk_04_27_2012_Arge.pdf))
Because the fits data is 3D, it cannot be passed directly to sunpy.map.Map
,
because this will take the first slice only and the other realizations are
lost. We want to end up with a sunpy.map.MapSequence
containing all these
realiations as individual maps. These maps can then be individually accessed
and PFSS solutions generated from them.
We first read in the fits file:
adapt_fits
is a list of HDPair
objects. The first of these contains
the 12 realizations data and a header with sufficient information to build
the MapSequence
. We unpack this HDPair
into a list of
(data,header)
tuples where data
are the different adapt realizations.
data_header_pairs = [(map_slice, adapt_fits[0].header) for map_slice in adapt_fits[0].data]
Next, pass this list of tuples as the argument to sunpy.map.Map
to create
the map sequence:
adapt_maps = sunpy.map.Map(data_header_pairs, sequence=True)
adapt_map_sequence
is now a list of our individual adapt realizations.
Note the .peek()` and ``.plot()
methods of MapSequence
returns instances of
sunpy.visualization.MapSequenceAnimator
and
matplotlib.animation.FuncAnimation1
. Here, we generate a static
plot accessing the individual maps in turn:
fig = plt.figure(figsize=(7, 8))
gs = gridspec.GridSpec(4, 3, figure=fig)
for i, a_map in enumerate(adapt_maps):
ax = fig.add_subplot(gs[i], projection=a_map)
a_map.plot(axes=ax, cmap='bwr', vmin=-2, vmax=2, title=f"Realization {1+i:02d}")
plt.tight_layout(pad=5, h_pad=2)
plt.show()
INFO: Missing metadata for solar radius: assuming the standard radius of the photosphere. [sunpy.map.mapbase]
/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/latest/lib/python3.10/site-packages/sunpy/map/mapbase.py:633: SunpyMetadataWarning: Missing metadata for observer: assuming Earth-based observer.
For frame 'heliographic_stonyhurst' the following metadata is missing: hgln_obs,dsun_obs,hglt_obs
For frame 'heliographic_carrington' the following metadata is missing: crln_obs,dsun_obs,crlt_obs
obs_coord = self.observer_coordinate
INFO: Missing metadata for solar radius: assuming the standard radius of the photosphere. [sunpy.map.mapbase]
/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/latest/lib/python3.10/site-packages/sunpy/map/mapbase.py:633: SunpyMetadataWarning: Missing metadata for observer: assuming Earth-based observer.
For frame 'heliographic_stonyhurst' the following metadata is missing: hgln_obs,dsun_obs,hglt_obs
For frame 'heliographic_carrington' the following metadata is missing: crln_obs,dsun_obs,crlt_obs
obs_coord = self.observer_coordinate
INFO: Missing metadata for solar radius: assuming the standard radius of the photosphere. [sunpy.map.mapbase]
/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/latest/lib/python3.10/site-packages/sunpy/map/mapbase.py:633: SunpyMetadataWarning: Missing metadata for observer: assuming Earth-based observer.
For frame 'heliographic_stonyhurst' the following metadata is missing: hgln_obs,dsun_obs,hglt_obs
For frame 'heliographic_carrington' the following metadata is missing: crln_obs,dsun_obs,crlt_obs
obs_coord = self.observer_coordinate
INFO: Missing metadata for solar radius: assuming the standard radius of the photosphere. [sunpy.map.mapbase]
/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/latest/lib/python3.10/site-packages/sunpy/map/mapbase.py:633: SunpyMetadataWarning: Missing metadata for observer: assuming Earth-based observer.
For frame 'heliographic_stonyhurst' the following metadata is missing: hgln_obs,dsun_obs,hglt_obs
For frame 'heliographic_carrington' the following metadata is missing: crln_obs,dsun_obs,crlt_obs
obs_coord = self.observer_coordinate
INFO: Missing metadata for solar radius: assuming the standard radius of the photosphere. [sunpy.map.mapbase]
/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/latest/lib/python3.10/site-packages/sunpy/map/mapbase.py:633: SunpyMetadataWarning: Missing metadata for observer: assuming Earth-based observer.
For frame 'heliographic_stonyhurst' the following metadata is missing: hgln_obs,dsun_obs,hglt_obs
For frame 'heliographic_carrington' the following metadata is missing: crln_obs,dsun_obs,crlt_obs
obs_coord = self.observer_coordinate
INFO: Missing metadata for solar radius: assuming the standard radius of the photosphere. [sunpy.map.mapbase]
/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/latest/lib/python3.10/site-packages/sunpy/map/mapbase.py:633: SunpyMetadataWarning: Missing metadata for observer: assuming Earth-based observer.
For frame 'heliographic_stonyhurst' the following metadata is missing: hgln_obs,dsun_obs,hglt_obs
For frame 'heliographic_carrington' the following metadata is missing: crln_obs,dsun_obs,crlt_obs
obs_coord = self.observer_coordinate
INFO: Missing metadata for solar radius: assuming the standard radius of the photosphere. [sunpy.map.mapbase]
/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/latest/lib/python3.10/site-packages/sunpy/map/mapbase.py:633: SunpyMetadataWarning: Missing metadata for observer: assuming Earth-based observer.
For frame 'heliographic_stonyhurst' the following metadata is missing: hgln_obs,dsun_obs,hglt_obs
For frame 'heliographic_carrington' the following metadata is missing: crln_obs,dsun_obs,crlt_obs
obs_coord = self.observer_coordinate
INFO: Missing metadata for solar radius: assuming the standard radius of the photosphere. [sunpy.map.mapbase]
/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/latest/lib/python3.10/site-packages/sunpy/map/mapbase.py:633: SunpyMetadataWarning: Missing metadata for observer: assuming Earth-based observer.
For frame 'heliographic_stonyhurst' the following metadata is missing: hgln_obs,dsun_obs,hglt_obs
For frame 'heliographic_carrington' the following metadata is missing: crln_obs,dsun_obs,crlt_obs
obs_coord = self.observer_coordinate
INFO: Missing metadata for solar radius: assuming the standard radius of the photosphere. [sunpy.map.mapbase]
/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/latest/lib/python3.10/site-packages/sunpy/map/mapbase.py:633: SunpyMetadataWarning: Missing metadata for observer: assuming Earth-based observer.
For frame 'heliographic_stonyhurst' the following metadata is missing: hgln_obs,dsun_obs,hglt_obs
For frame 'heliographic_carrington' the following metadata is missing: crln_obs,dsun_obs,crlt_obs
obs_coord = self.observer_coordinate
INFO: Missing metadata for solar radius: assuming the standard radius of the photosphere. [sunpy.map.mapbase]
/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/latest/lib/python3.10/site-packages/sunpy/map/mapbase.py:633: SunpyMetadataWarning: Missing metadata for observer: assuming Earth-based observer.
For frame 'heliographic_stonyhurst' the following metadata is missing: hgln_obs,dsun_obs,hglt_obs
For frame 'heliographic_carrington' the following metadata is missing: crln_obs,dsun_obs,crlt_obs
obs_coord = self.observer_coordinate
INFO: Missing metadata for solar radius: assuming the standard radius of the photosphere. [sunpy.map.mapbase]
/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/latest/lib/python3.10/site-packages/sunpy/map/mapbase.py:633: SunpyMetadataWarning: Missing metadata for observer: assuming Earth-based observer.
For frame 'heliographic_stonyhurst' the following metadata is missing: hgln_obs,dsun_obs,hglt_obs
For frame 'heliographic_carrington' the following metadata is missing: crln_obs,dsun_obs,crlt_obs
obs_coord = self.observer_coordinate
INFO: Missing metadata for solar radius: assuming the standard radius of the photosphere. [sunpy.map.mapbase]
/home/docs/checkouts/readthedocs.org/user_builds/sunkit-magex/conda/latest/lib/python3.10/site-packages/sunpy/map/mapbase.py:633: SunpyMetadataWarning: Missing metadata for observer: assuming Earth-based observer.
For frame 'heliographic_stonyhurst' the following metadata is missing: hgln_obs,dsun_obs,hglt_obs
For frame 'heliographic_carrington' the following metadata is missing: crln_obs,dsun_obs,crlt_obs
obs_coord = self.observer_coordinate
Total running time of the script: (0 minutes 8.987 seconds)