Single Instrument Dashboard
Setup AIA Inputs
Import Statements
[ ]:
#%pip install astropy scipy ipympl ndcube xrtpy sunpy lxml drms zeep
from IPython.display import display, HTML
display(HTML("<style>:root { --jp-notebook-max-width: 100% !important; }</style>"))
import importlib
import numpy as np
from sys import path
import astropy.units as u
import os
import matplotlib as mpl
mpl.use("Agg")
import matplotlib.pyplot as plt
# Enable interactive plotting with widgets
%matplotlib widget
# Set matplotlib parameters for better visualization
plt.rcParams.update({'image.origin': 'lower'})
np.set_printoptions(linewidth=128)
# Define base path and append EMToolKit path
base_path = os.getcwd()
# import EMToolKit and its visualization module
import EMToolKit.EMToolKit as emtk
import EMToolKit
import EMToolKit.visualization
# Reload EMToolKit modules to ensure the latest version is used
importlib.reload(EMToolKit)
importlib.reload(EMToolKit.visualization)
# Initialize an empty EM collection
em_collection = 0
[2]:
# These flags tell the program not to recalculate the data if it has already been calculated
redownload = False
recalc_sparse = False
recalc_simple = False
recalc_sparse_nlmap = False
Download the Imagery
[3]:
from EMToolKit.instruments.aia import download_sdo_data
date='2010/07/25 17:58:44'
# Download the data
aia_paths, sdo_data_dir = download_sdo_data(base_path, date, redownload=redownload)
paths = aia_paths
Found 6 AIA images on disk.
Load and Crop the Imagery
[4]:
from EMToolKit.instruments.aia import load_from_paths, aia_wrapper
xl, yl, = 240*u.arcsec, -525*u.arcsec # Left edge of FOV in arcseconds (relative to disk center)
# Right edge of FOV in arcseconds (relative to disk center)
xlen, ylen = 270*u.arcsec, 240*u.arcsec # X size of FOV in arcseconds # Y size of FOV in arcseconds
# Load the AIA Images ###
aiamaps = load_from_paths(aia_paths,xl=xl,yl=yl,dx=xlen,dy=ylen)
temperature_array = np.arange(5.5, 7.5, 0.025)
[maps,errs,trlogts,tresps] = aia_wrapper(aiamaps, temperature_array=temperature_array)
[5]:
# Normalizing the response functions makes them much easier for the solver to handle.
datmax_nominal = 1.0e4 # The nominal maximum of the data
overall_norm = datmax_nominal/np.max(np.array(tresps))
norms = np.max(np.array(tresps),axis=0)/np.max(np.array(tresps))/overall_norm
[6]:
# Make data sequence from AIA:
datasequence = emtk.em_data(maps,errs,trlogts,tresps)
# Create em_collection with data sequence:
em_collection = emtk.em_collection(datasequence)
[7]:
# Show some of the AIA channels and their temperature responses for illustration:
plt_emmax = 5.0e28 # Maximum emission value for plotting
gfac = 1.0 / 2.2 # Gamma correction factor for visualization
fig, axs = plt.subplots(2, 3) # Create a figure with a 2x3 grid of subplots
# Plot AIA 193 Angstrom channel
axs[0, 0].imshow(np.clip(maps[1].data / np.max(tresps[1]), 0, plt_emmax) ** gfac, cmap=plt.get_cmap('gray'))
axs[0, 0].set(title='AIA 193 Angstrom')
axs[1, 0].plot(trlogts[1], tresps[1] / 1.0e-27)
axs[1, 0].set(title='AIA 193 TResp', xlabel='Temperature (dB Kelvin)', ylabel='Response (DN/s/(10$^9$ cm$^{-3})^2$/Mm)')
# Plot AIA 335 Angstrom channel
axs[0, 1].imshow(np.clip(maps[2].data / np.max(tresps[2]), 0, plt_emmax) ** gfac, cmap=plt.get_cmap('gray'))
axs[0, 1].set(title='AIA 335 Angstrom')
axs[1, 1].plot(trlogts[2], tresps[2] / 1.0e-27)
axs[1, 1].set(title='AIA 335 TResp', xlabel='Temperature (dB Kelvin)')
# Plot AIA 94 Angstrom channel
axs[0, 2].imshow(np.clip(maps[5].data / np.max(tresps[5]), 0, plt_emmax) ** gfac, cmap=plt.get_cmap('gray'))
axs[0, 2].set(title='AIA 94 Angstrom')
axs[1, 2].plot(trlogts[5], tresps[5] / 1.0e-27)
axs[1, 2].set(title='AIA 94 TResp', xlabel='Temperature (dB Kelvin)')
# Adjust layout and show the plots
plt.tight_layout()
plt.show()
DEM Analysis
Compute the Differential Emission Measure
Three algorithms are currently supported.
[8]:
from EMToolKit.algorithms.sparse_em_wrapper import autoloading_sparse_em_wrapper
from EMToolKit.algorithms.simple_reg_dem_wrapper import autoloading_simple_reg_dem_wrapper
from EMToolKit.algorithms.sparse_nlmap_dem_wrapper import autoloading_sparse_nlmap_dem_wrapper
simple_reg_demsequence, simpl_out = autoloading_simple_reg_dem_wrapper(datasequence, recalc=recalc_simple)
# simpl_coeffs, simpl_logts, simpl_bases, simpl_coords, simpl_algorithm = simpl_out
em_collection.add_model(simple_reg_demsequence)
# Compute the DEM for Cheung et al. sparse EM method:
# Make DEM sequence from the DEM and add it to the collection:
sparse_em_demsequence, spars_out = autoloading_sparse_em_wrapper(datasequence, recalc=recalc_sparse)
em_collection.add_model(sparse_em_demsequence)
# Make DEM sequence from the DEM and add it to the collection: (Work in Progress)
# sparse_nlmap_demsequence, spars_nlmap_out = autoloading_sparse_nlmap_dem_wrapper(datasequence, recalc=recalc_sparse_nlmap)
# em_collection.add_model(sparse_nlmap_demsequence)
Loading simple_reg_demsequence from .data/default/single_simple_reg_demsequence.pkl
Loading sparse_em_demsequence from .data/default/single_sparse_em_demsequence.pkl
Run the Dashboard
[9]:
# Get the most recent version from the tool kit:
from EMToolKit.visualization.dashboard import dashboard_object
importlib.reload(EMToolKit.visualization.dashboard)
from EMToolKit.visualization.dashboard import dashboard_object
# Suppress specific SunpyMetadataWarning
import warnings
from sunpy.util.exceptions import SunpyMetadataWarning
warnings.filterwarnings("ignore", category=SunpyMetadataWarning)
[11]:
# Create the dashboard:
dash = dashboard_object(em_collection, xsize=10, ysize=5, fontsize=8)
dash.display(True)
Click on the image to populate the dashboard
[ ]: