Skip to content
This repository was archived by the owner on Aug 24, 2023. It is now read-only.

Commit d2adcea

Browse files
committed
Add HMI example
1 parent 91903f2 commit d2adcea

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

examples/using_pfsspy/plot_hmi.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
"""
2+
HMI PFSS solutions
3+
------------------
4+
Calculating a PFSS solution from a HMI synoptic map.
5+
6+
This example shows how to calcualte a PFSS solution from a HMI synoptic map.
7+
There are a couple of important things that this example shows:
8+
9+
- HMI maps have non-standard metadata, so this needs to be fixed
10+
- HMI synoptic maps are very big (1440 x 3600), so need to be downsampled
11+
in order to calculate the PFSS solution in a reasonable time.
12+
"""
13+
14+
###############################################################################
15+
# First import the required modules
16+
import astropy.units as u
17+
import matplotlib.pyplot as plt
18+
from sunpy.net import Fido, attrs as a
19+
import sunpy.map
20+
import pfsspy
21+
import pfsspy.utils
22+
23+
###############################################################################
24+
# Set up the search.
25+
#
26+
# Note that for SunPy versions earlier than 2.0, a time attribute is needed to
27+
# do the search, even if (in this case) it isn't used, as the synoptic maps are
28+
# labelled by Carrington rotation number instead of time
29+
time = a.Time('2010/01/01', '2010/01/01')
30+
series = a.jsoc.Series('hmi.synoptic_mr_polfil_720s')
31+
crot = a.jsoc.PrimeKey('CAR_ROT', 2210)
32+
33+
###############################################################################
34+
# Do the search.
35+
#
36+
# If you use this code, please replace this email address
37+
# with your own one, registered here:
38+
# http://jsoc.stanford.edu/ajax/register_email.html
39+
result = Fido.search(time, series, crot, a.jsoc.Notify("[email protected]"))
40+
files = Fido.fetch(result)
41+
42+
###############################################################################
43+
# Read in a file. This will read in the first file downloaded to a sunpy Map
44+
# object. Note that HMI maps have several bits of metadata that do not comply
45+
# to the FITS standard, so we need to fix them first.
46+
hmi_map = sunpy.map.Map(files[0])
47+
pfsspy.utils.fix_hmi_meta(hmi_map)
48+
print('Data shape: ', hmi_map.data.shape)
49+
50+
###############################################################################
51+
# Since this map is far to big to calculate a PFSS solution quickly, lets
52+
# resample it down to a smaller size.
53+
hmi_map = hmi_map.resample([360, 180] * u.pix)
54+
print('New shape: ', hmi_map.data.shape)
55+
56+
###############################################################################
57+
# Now calculate the PFSS solution
58+
nrho = 35
59+
rss = 2.5
60+
input = pfsspy.Input(hmi_map, nrho, rss)
61+
output = pfsspy.pfss(input)
62+
63+
###############################################################################
64+
# Using the Output object we can plot the source surface field, and the
65+
# polarity inversion line.
66+
ss_br = output.source_surface_br
67+
# Create the figure and axes
68+
fig = plt.figure()
69+
ax = plt.subplot(projection=ss_br)
70+
71+
# Plot the source surface map
72+
ss_br.plot()
73+
# Plot the polarity inversion line
74+
ax.plot_coord(output.source_surface_pils[0])
75+
# Plot formatting
76+
plt.colorbar()
77+
ax.set_title('Source surface magnetic field')
78+
79+
plt.show()

0 commit comments

Comments
 (0)