AIA, XRT and NuSTAR data to calculate DEM for 12 Sep 2020 event¶

based on this notebook by Iain Hannah

Units¶

Instrument Data Response function Loci (Data/response) DEM output units
AIA DN s$^{-1}$ px$^{-1}$ DN s$^{-1}$ px$^{-1}$ cm$^5$ K$^{-1}$ cm$^{-5}$ K$^{-1}$ cm$^{-5}$ K$^{-1}$
XRT DN s$^{-1}$ px$^{-1}$ DN s$^{-1}$ px$^{-1}$ cm$^5$ K$^{-1}$ cm$^{-5}$ K$^{-1}$ cm$^{-5}$ K$^{-1}$
NuSTAR counts s$^{-1}$ counts s$^{-1}$ cm$^3$ K$^{-1}$ cm$^{-3}$ K$^{-1}$ cm$^{-5}$ K$^{-1}$
NuSTAR response*area counts s$^{-1}$ counts s$^{-1}$ cm$^5$ K$^{-1}$ cm$^{-5}$ K$^{-1}$ cm$^{-5}$ K$^{-1}$

AIA processed in IDL with aia_prep, /normalize

Area in cm$^2$ determined from AIA images

XRT processed in IDL with xrt_prep, then adjusted for exposure here

XRT was summed on board by 16 pixels! So to get the true per-pixel values, divide the XRT-prepped data by 16

NuSTAR data 20s cadence images, adjusted such that pixel values are counts/s

Response Functions¶

trmatrix2=np.zeros((len(aia_tresp_logt),9))
trmatrix2[:,:6]=aia_trmatrix
trmatrix2[:,6]=xtrint
trmatrix2[:,7]=nstrint_lo
trmatrix2[:,8]=nstrint_hi
og_trmatrix=trmatrix2
pickle.dump(og_trmatrix,open('aia_xrt_nustar_trmatrix_091220.p','wb'))
trmatrix2=np.zeros((len(aia_tresp_logt),9))
trmatrix2[:,:6]=aia_trmatrix
trmatrix2[:,6]=xtrint
trmatrix2[:,7]=nstrint_lo*area #run cells in Data section first
trmatrix2[:,8]=nstrint_hi*area
full_trmatrix=trmatrix2

Load data¶

XRT¶

select 10"x10" submap. Because of pixel size and source location, this ends up as >10" x ~ 10" or 3x2 px

AIA¶

tidx=single_time_indices(dfaia,obstime)
tmaps=[dfaia.maps[idx] for idx in tidx]
type(tmaps[0]),tmaps[0].meta['date-obs']
(sunpy.map.sources.sdo.AIAMap, '2020-09-12T20:40:23.12')
all_six_AIA(tmaps)
cmask=make_contour_mask(211,submap=tmaps[4],contour=[80],plot=True)
Could not make difference image, using peak flare image only
1
npix=np.product(cmask.shape)-np.sum(cmask)
npix
9

ROI based on AIA contour

area=npix*(arcsec_to_cm(tmaps[0].meta['cdelt2']*u.arcsec))**2 
print(area)
1.724874971917349e+16 cm2
#  Correct the AIA data for the degradation
cor_data=datavec/degs
print(datavec)
print(cor_data)

# Get into DN/s/px for the DEM stuff
adn_in=cor_data/durs
print('DN/s/px: ',adn_in,'\n')
[8.358437, 73.33333333333333, 989.6666666666666, 1104.0, 616.5555555555555, 14.11111111111111]
[   9.25448016  144.58598185 1337.50868497 2239.15511161 1532.82583401
   81.93785425]
DN/s/px:  [   3.18895019   49.83413958  668.69549728 1119.78135601  528.34382926
   28.24647479] 

NuSTAR¶

lowE,highE=nustar_dem_prep(bottom_left,top_right,how='sum') #contour option not activated yet..
lowE,highE #total counts/s in each channel
(0.026794877, 0.0027598343)

put all the data together, calculate error

dn_in=np.hstack([adn_in,xdnspx,lowE,highE])
dn_in
array([3.18895019e+00, 4.98341396e+01, 6.68695497e+02, 1.11978136e+03,
       5.28343829e+02, 2.82464748e+01, 3.60276434e+00, 2.67948769e-02,
       2.75983429e-03])
aia_err=generate_errors(0,0,6,dn_in[:6])
aia_err
array([  2.7989203 ,   9.98465407,  72.27363412, 116.69425551,
        57.07644205,   5.06830841])
#assume 1% error for the rest:
edn_in=np.hstack([aia_err,0.1*np.copy(dn_in)[6:]])
edn_in
array([2.79892030e+00, 9.98465407e+00, 7.22736341e+01, 1.16694256e+02,
       5.70764421e+01, 5.06830841e+00, 3.60276434e-01, 2.67948769e-03,
       2.75983429e-04])

DEM calculations¶

# What temperature binning do we want for the DEM ?
temps=np.logspace(5.6,6.8,num=42)
dtemps=([temps[i+1]-temps[i] for i in np.arange(0,len(temps)-1)])
mlogt=([np.mean([(np.log10(temps[i])),np.log10((temps[i+1]))]) \
        for i in np.arange(0,len(temps)-1)])

Compare everything¶

  1. AIA only, selfnorm
  2. AIA + XRT selfnorm
  3. AIA + XRT - EMloci min
  4. AIA + 2*XRT - EMloci min
  5. AIA + XRT + NuSTAR - selfnorm
  6. AIA + XRT + NuSTAR - EMloci min
  7. AIA + 2*XRT + NuSTAR - EMloci min
  8. AIA + NuSTAR - selfnorm
  9. AIA + NuSTAR - EMloci min

DEM Comparison¶

Parameter grid search¶

aia_contours=[70,75,80,85] #also no large correlation
xrt_submap_radii=[5,10,15] #nustar radii no effect really
xrt_facs=[.5,1,1.5,2,2.5,3] #multiplicative factor for data
nustar_facs=[.01,.1,1,2,5,10,15,25,50]
nustar_areas=['AIA','XRT'] #which instrument does NuSTAR take the area measurement from
initial_weightvals=['guess','loci_min',6,6.5]
results.describe()
index aia_area aia_contour aia_mask_channel aia_ratio chisq nustar_fac nustar_submap_radius xray_ratio xrt_area xrt_fac xrt_submap_radius
count 5184.0 5.184000e+03 5184.000000 5184.0 5184.000000 5184.000000 5184.000000 5184.0 5184.000000 5.184000e+03 5184.000000 5184.000000
mean 0.0 2.491486e+16 77.500000 211.0 0.157363 37.708994 12.012222 55.0 0.764704 2.613507e+18 1.750000 10.000000
std 0.0 1.005133e+16 5.590709 0.0 0.129971 3.660444 15.569877 0.0 0.204740 1.857341e+18 0.853995 4.082877
min 0.0 1.341569e+16 70.000000 211.0 0.030099 16.182034 0.010000 55.0 0.153513 5.407255e+17 0.500000 5.000000
25% 0.0 1.629049e+16 73.750000 211.0 0.064819 36.945918 1.000000 55.0 0.680621 5.407255e+17 1.000000 5.000000
50% 0.0 2.395660e+16 77.500000 211.0 0.106633 38.366676 5.000000 55.0 0.804067 2.253023e+18 1.750000 10.000000
75% 0.0 3.258097e+16 81.250000 211.0 0.184983 39.651748 15.000000 55.0 0.929853 5.046771e+18 2.500000 15.000000
max 0.0 3.833055e+16 85.000000 211.0 0.579205 43.810567 50.000000 55.0 1.010971 5.046771e+18 3.000000 15.000000
good_results=results.where(np.log10(results.ratio_ratio)>np.log10(.85))
good_results=good_results.where(np.log10(good_results.ratio_ratio)<np.log10(1.15))
good_results['ratio_sum']=good_results.aia_ratio+good_results.xray_ratio
good_results.sort_values(['ratio_sum'],ascending=False,inplace=True)
good_results[['aia_ratio','xray_ratio','ratio_ratio','ratio_sum']].head(10)
aia_ratio xray_ratio ratio_ratio ratio_sum
1562 0.543496 0.606009 0.896845 1.149505
1560 0.543496 0.606009 0.896845 1.149505
2920 0.552761 0.590615 0.935908 1.143376
2922 0.552761 0.590615 0.935908 1.143376
4138 0.520980 0.607123 0.858113 1.128103
4136 0.520980 0.607123 0.858113 1.128103
344 0.562062 0.558999 1.005480 1.121061
346 0.562062 0.558999 1.005480 1.121061
266 0.531715 0.588653 0.903274 1.120369
264 0.531715 0.588653 0.903274 1.120369
plot_results=good_results.drop(columns=['aia_mask_channel','initial_weights','nustar_area','dem','dn_in','dn_reg','edem','elogt','mlogt','nustar_submap_radius','selfnorm','ratio_ratio','ratio_sum']).head(20)
best=results.loc[good_results.head().index[0]] #first one...
best
index                                                                   0
aia_area                                                      3.06644e+16
aia_contour                                                            75
aia_mask_channel                                                      211
aia_ratio                                                        0.543496
chisq                                                             25.4777
dem                     [[15043975307.596079, 341417690159.0855, 62923...
dn_in                   [[8.931356792940631, 141.21778568461554, 1307....
dn_reg                  [[4.436821585832275, 17.08305879154923, 1335.5...
edem                    [[2170432409.9255633, 49491910394.78156, 90879...
elogt                   [[0.03899325338481579, 0.024370783365509772, 0...
initial_weights                                                         6
mlogt                   [[5.614634146341463, 5.64390243902439, 5.67317...
nustar_area                                                           AIA
nustar_fac                                                             15
nustar_submap_radius                                                   55
selfnorm                                                            False
xray_ratio                                                       0.606009
xrt_area                                                      5.40725e+17
xrt_fac                                                                 2
xrt_submap_radius                                                       5
ratio_ratio                                                      0.896845
Name: 1562, dtype: object

Correrlation heatmap