| 1 |
""" |
| 2 |
========================================= |
| 3 |
Downloading and plotting a AIA lightcurve |
| 4 |
========================================= |
| 5 |
|
| 6 |
This example shows how to download AIA 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 |
# Some keywords we are interested in; you can use client.keys(series) to get a |
| 20 |
# list of all available keywords of a series. |
| 21 |
|
| 22 |
keys = [ |
| 23 |
"T_REC", |
| 24 |
"T_OBS", |
| 25 |
"DATAMIN", |
| 26 |
"DATAMAX", |
| 27 |
"DATAMEAN", |
| 28 |
"DATARMS", |
| 29 |
"DATASKEW", |
| 30 |
"DATAKURT", |
| 31 |
"QUALITY", |
| 32 |
] |
| 33 |
|
| 34 |
############################################################################### |
| 35 |
# Get detailed information about the series. Some keywords from |
| 36 |
# aia.lev1_euv_12s are links to keywords in aia.lev1 and unfortunately some |
| 37 |
# entries (like note) are missing for linked keywords, so we are using the |
| 38 |
# entries from aia.lev1 in this case. |
| 39 |
|
| 40 |
print("Querying series info...") |
| 41 |
series_info = client.info("aia.lev1_euv_12s") |
| 42 |
series_info_lev1 = client.info("aia.lev1") |
| 43 |
linkinfo = series_info.keywords.linkinfo |
| 44 |
missing_linkinfo = linkinfo.isna() |
| 45 |
for key in keys: |
| 46 |
if not missing_linkinfo.loc[key] and linkinfo.loc[key].startswith("lev1->"): |
| 47 |
note_str = series_info_lev1.keywords.loc[key].note |
| 48 |
else: |
| 49 |
note_str = series_info.keywords.loc[key].note |
| 50 |
print(f"{key:>10} : {note_str}") |
| 51 |
|
| 52 |
############################################################################### |
| 53 |
# Construct the DRMS query string: "Series[timespan][wavelength]" |
| 54 |
|
| 55 |
qstr = "aia.lev1_euv_12s[2014-01-01T00:00:01Z/365d@1d][335]" |
| 56 |
|
| 57 |
# Get keyword values for the selected timespan and wavelength |
| 58 |
print(f"Querying keyword data...\n -> {qstr}") |
| 59 |
result = client.query(qstr, key=keys) |
| 60 |
print(f" -> {len(result)} lines retrieved.") |
| 61 |
|
| 62 |
# Only use entries with QUALITY==0 |
| 63 |
result = result[result.QUALITY == 0] |
| 64 |
print(f" -> {len(result)} lines after QUALITY selection.") |
| 65 |
|
| 66 |
# Convert T_REC strings to datetime and use it as index for the series |
| 67 |
result.index = drms.to_datetime(result.T_REC) |
| 68 |
|
| 69 |
############################################################################### |
| 70 |
# Create some simple plots |
| 71 |
|
| 72 |
ax = result[["DATAMIN", "DATAMAX", "DATAMEAN", "DATARMS", "DATASKEW"]].plot(figsize=(8, 10), subplots=True) |
| 73 |
ax[0].set_title(qstr, fontsize="medium") |
| 74 |
plt.tight_layout() |
| 75 |
plt.show() |