Debian Codegraph @

examples/plot_hmi_modes.py

raw
1 """
2 =============================================
3 Downloading and plotting solar modes with HMI
4 =============================================
5
6 This example shows how to download HMI data from JSOC and make a plot of the solar modes.
7 """
8
9 import matplotlib.pyplot as plt
10 import numpy as np
11
12 import drms
13
14 ###############################################################################
15 # First we will create a `drms.Client`, using the JSOC baseurl.
16
17 client = drms.Client()
18
19 ###############################################################################
20 # Construct the DRMS query string: "Series[timespan][wavelength]"
21
22 qstr = "hmi.v_sht_modes[2024.09.19_00:00:00_TAI]"
23
24 # TODO: Add text here.
25 segname = "m6" # 'm6', 'm18' or 'm36'
26
27 # Send request to the DRMS server
28 print(f"Querying keyword data...\n -> {qstr}")
29 result, filenames = client.query(qstr, key=["T_START", "T_STOP", "LMIN", "LMAX", "NDT"], seg=segname)
30 print(f" -> {len(result)} lines retrieved.")
31
32 # Use only the first line of the query result
33 result = result.iloc[0]
34 fname = f"http://jsoc.stanford.edu{filenames[segname][0]}"
35
36 # Read the data segment
37 print(f"Reading data from {fname}...")
38 a = np.genfromtxt(fname)
39
40 # For column names, see appendix of Larson & Schou (2015SoPh..290.3221L)
41 l = a[:, 0].astype(int)
42 n = a[:, 1].astype(int)
43 nu = a[:, 2] / 1e3
44 if a.shape[1] in [24, 48, 84]:
45 # tan(gamma) present
46 sig_offs = 5
47 elif a.shape[1] in [26, 50, 86]:
48 # tan(gamma) not present
49 sig_offs = 6
50 snu = a[:, sig_offs + 2] / 1e3
51
52 ###############################################################################
53 # Plot the zoomed in on lower l
54 fig, ax = plt.subplots(1, 1, figsize=(11, 7))
55 ax.set_title(
56 f"Time = {result.T_START} ... {result.T_STOP}, L = {result.LMIN} ... {result.LMAX}, NDT = {result.NDT}",
57 fontsize="medium",
58 )
59 for ni in np.unique(n):
60 idx = n == ni
61 ax.plot(l[idx], nu[idx], "b.-")
62 ax.set_xlim(0, 120)
63 ax.set_ylim(0.8, 4.5)
64 ax.set_xlabel("Harmonic degree")
65 ax.set_ylabel("Frequency [mHz]")
66 fig.tight_layout()
67
68 ###############################################################################
69 # Plot the zoomed in on higher l, n <= 20, with errors
70
71 fig, ax = plt.subplots(1, 1, figsize=(11, 7))
72 ax.set_title(
73 f"Time = {result.T_START} ... {result.T_STOP}, L = {result.LMIN} ... {result.LMAX}, NDT = {result.NDT}",
74 fontsize="medium",
75 )
76 for ni in np.unique(n):
77 if ni <= 20:
78 idx = n == ni
79 ax.plot(l[idx], nu[idx], "b.", ms=3)
80 if ni < 10:
81 ax.plot(l[idx], nu[idx] + 1000 * snu[idx], "g")
82 ax.plot(l[idx], nu[idx] - 1000 * snu[idx], "g")
83 else:
84 ax.plot(l[idx], nu[idx] + 500 * snu[idx], "r")
85 ax.plot(l[idx], nu[idx] - 500 * snu[idx], "r")
86 ax.legend(
87 loc="upper right",
88 handles=[
89 plt.Line2D([0], [0], color="r", label="500 sigma"),
90 plt.Line2D([0], [0], color="g", label="1000 sigma"),
91 ],
92 )
93 ax.set_xlim(-5, 305)
94 ax.set_ylim(0.8, 4.5)
95 ax.set_xlabel("Harmonic degree")
96 ax.set_ylabel("Frequency [mHz]")
97 fig.tight_layout()
98
99 plt.show()