| 1 |
""" |
| 2 |
========================================= |
| 3 |
Downloading and plotting a HMI lightcurve |
| 4 |
========================================= |
| 5 |
|
| 6 |
This example shows how to download HMI data from JSOC and make a lightcurve plot. |
| 7 |
""" |
| 8 |
|
| 9 |
import matplotlib.pyplot as plt |
| 10 |
|
| 11 |
import drms |
| 12 |
|
| 13 |
############################################################################### |
| 14 |
# First we will create a `drms.Client`, using the JSOC baseurl. |
| 15 |
|
| 16 |
client = drms.Client() |
| 17 |
|
| 18 |
############################################################################### |
| 19 |
# Construct the DRMS query string: "Series[timespan]" |
| 20 |
|
| 21 |
qstr = "hmi.ic_720s[2010.05.01_TAI-2016.04.01_TAI@6h]" |
| 22 |
|
| 23 |
# Send request to the DRMS server |
| 24 |
print(f"Querying keyword data...\n -> {qstr}") |
| 25 |
result = client.query(qstr, key=["T_REC", "DATAMEAN", "DATARMS"]) |
| 26 |
print(f" -> {len(result)} lines retrieved.") |
| 27 |
|
| 28 |
############################################################################### |
| 29 |
# Now to plot the image. |
| 30 |
|
| 31 |
# Convert T_REC strings to datetime and use it as index for the series |
| 32 |
result.index = drms.to_datetime(result.pop("T_REC")) |
| 33 |
|
| 34 |
# Note: DATARMS contains the standard deviation, not the RMS! |
| 35 |
t = result.index |
| 36 |
avg = result.DATAMEAN / 1e3 |
| 37 |
std = result.DATARMS / 1e3 |
| 38 |
|
| 39 |
# Create plot |
| 40 |
fig, ax = plt.subplots(1, 1, figsize=(15, 7)) |
| 41 |
ax.set_title(qstr, fontsize="medium") |
| 42 |
ax.fill_between( |
| 43 |
t, |
| 44 |
avg + std, |
| 45 |
avg - std, |
| 46 |
edgecolor="none", |
| 47 |
facecolor="b", |
| 48 |
alpha=0.3, |
| 49 |
interpolate=True, |
| 50 |
) |
| 51 |
ax.plot(t, avg, color="b") |
| 52 |
ax.set_xlabel("Time") |
| 53 |
ax.set_ylabel("Disk-averaged continuum intensity [kDN/s]") |
| 54 |
fig.tight_layout() |
| 55 |
|
| 56 |
plt.show() |