... and faster versions for sunxspex too
Parameter | Unit | Default | Hard Min | Soft Min | Soft Max | Hard Max | Delta | |
---|---|---|---|---|---|---|---|---|
1 | a0 | 1e-35 | 100.0 | 1.0 | 10.0 | 1e6 | 1e7 | 1.0 |
2 | p | "" | 4.0 | 1.1 | 1.5 | 15.0 | 20.0 | 0.1 |
3 | eebrk | keV | 150.0 | 1.0 | 5.0 | 100. | 1e5 | 0.5 |
4 | q | "" | 6.0 | 0.0 | 1.5 | 15.0 | 20.0 | 0.1 |
5 | eelow | keV | 20.0 | 0.0 | 1.0 | 100. | 1e3 | 1.0 |
6 | eehigh | keV | 3200.0 | 1.0 | 10.0 | 1e6 | 1e7 | 1.0 |
A quick comparison between the speed of the original integration and the optimized version...
%%timeit
thick_optimized,_=emission.split_and_integrate(model='thick-target', photon_energies=photon_energies, maxfcn=maxfcn, rerr=rerr,eelow=eelow, eebrk=eebrk, eehigh=eehigh,p=p, q=q, z=z, efd=False)
12.6 ms ± 533 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
%%timeit
thick_original,_=emission.split_and_integrate0(model='thick-target', photon_energies=photon_energies, maxfcn=maxfcn, rerr=rerr,eelow=eelow, eebrk=eebrk, eehigh=eehigh,p=p, q=q, z=z, efd=False)
151 ms ± 1.09 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
%%timeit
thin_optimized,_=emission.split_and_integrate(model='thin-target', photon_energies=photon_energies, maxfcn=maxfcn, rerr=rerr,eelow=eelow, eebrk=eebrk, eehigh=eehigh,p=p, q=q, z=z, efd=True)
11.9 ms ± 229 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
%%timeit
thin_original,_=emission.split_and_integrate0(model='thin-target', photon_energies=photon_energies, maxfcn=maxfcn, rerr=rerr,eelow=eelow, eebrk=eebrk, eehigh=eehigh,p=p, q=q, z=z, efd=True)
151 ms ± 840 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
xspec.AllData("1:1 stx_spectrum_20210908_1712.fits{13}")
xspec.Xset.abund="file feld92a_coronal0.txt"
m1=xspec.Model('apec')
Fitting with single thermal model initially over range 2.0-10.0 keV
Single thermal fit took 0.401 seconds
Model par | Model comp | Component | Parameter | Unit | Value | Sigma |
---|---|---|---|---|---|---|
1 | 1 | kT | apec | keV | 1.79e+00 | +/-4.62e-03 |
2 | 1 | Abundanc | apec | 1.00e+00 | frozen | |
3 | 1 | Redshift | apec | 0.00e+00 | frozen | |
4 | 1 | norm | apec | 9.53e+05 | +/-7.65e+03 |
Fit statistic: Chi 561.792 Null hypothesis probability of 1.93e-121 with 3 degrees of freedom
Thick target model fit initially over range 10.0-30.0 keV
m2=xspec.Model('thick2')
Thick target fit took 5.337 seconds
Model par | Model comp | Component | Parameter | Unit | Value | Sigma |
---|---|---|---|---|---|---|
1 | 1 | a0 | thick2 | 1e-35 | 1.41e+03 | +/-4.46e+05 |
2 | 1 | p | thick2 | 7.52e+00 | +/-2.05e-01 | |
3 | 1 | eebrk | thick2 | keV | 2.86e+01 | +/-6.51e+01 |
4 | 1 | q | thick2 | 3.40e+00 | +/-8.11e+01 | |
5 | 1 | eelow | thick2 | keV | 1.02e+01 | +/-7.32e-01 |
6 | 1 | eehigh | thick2 | keV | 3.94e+01 | +/-6.10e+01 |
7 | 1 | norm | thick2 | 5.54e-04 | +/-1.75e-01 |
Fit statistic: Chi 22.604 Null hypothesis probability of 1.52e-04 with 4 degrees of freedom
Single thermal plus thick target model fit over range 6.5-30.0 keV, all parameters free
m3=xspec.Model('apec+thick2')
m3.setPars({1:f"{apec_kt[0]:.2f} ,,,"}) #set kT to be the same from apec fit
m3.setPars({4:f"{apec_norm[0]:.2f} ,,,"}) #set norm to be the same from apec fit
for i,t in enumerate(tparams): #set thick_target parameters to be the same from thick_target fit
m3.setPars({i+5:f"{t} ,,,"})
m3.setPars({7:f"{tparams[2]} ,,{tparams[4]},{tparams[4]},,"})
m3.setPars({9:f"{tparams[4]} ,,,,{tparams[2]},{tparams[2]}"}) #force eelow < eebrk
for p in ['a0','p','q','eebrk','eelow','norm','eehigh']: #unfreeze all parameters
pp=getattr(m3.thick2,p)
pp.frozen=False
for p in ['kT','norm']:
pp=getattr(m3.apec,p)
pp.frozen=False
m3.show()
Thermal + thick target fit took 6.938 seconds
Model par | Model comp | Component | Parameter | Unit | Value | Sigma |
---|---|---|---|---|---|---|
1 | 1 | kT | apec | keV | 1.59e+00 | +/-2.81e-01 |
2 | 1 | Abundanc | apec | 1.00e+00 | frozen | |
3 | 1 | Redshift | apec | 0.00e+00 | frozen | |
4 | 1 | norm | apec | 1.30e+06 | +/-6.54e+05 | |
5 | 2 | a0 | thick2 | 1e-35 | 7.52e+02 | +/--1.00e+00 |
6 | 2 | p | thick2 | 2.42e+00 | +/-4.50e+00 | |
7 | 2 | eebrk | thick2 | keV | 1.71e+01 | +/-1.05e+00 |
8 | 2 | q | thick2 | 6.31e+00 | +/-5.36e-01 | |
9 | 2 | eelow | thick2 | keV | 8.96e+00 | +/-3.38e+01 |
10 | 2 | eehigh | thick2 | keV | 4.51e+01 | +/-1.05e+00 |
11 | 2 | norm | thick2 | 1.91e-04 | +/--1.00e+00 |
Fit statistic: Chi 48.575 Null hypothesis probability of 2.71e-09 with 5 degrees of freedom
Original | Optimized | Improvement | |
---|---|---|---|
thick-target | 33.95 | 5.34 | 6.4x |
apec + thick-target | 26.57 | 6.94 | 3.8x |
total | 60.52 | 12.28 | 4.9x |
Parameter | Unit | Original Value | Optimized Value | Original Sigma | Optimized Sigma |
---|---|---|---|---|---|
kT | keV | 1.59e+00 | 1.59e+00 | +/- 3.03e-01 | +/- 2.81e-01 |
Abundanc | 1.00e+00 | 1.00e+00 | frozen | +/- 0.00e+00 | |
Redshift | 0.00e+00 | 0.00e+00 | frozen | +/- 0.00e+00 | |
norm | 1.31e+06 | 1.30e+06 | +/- 7.09e+05 | +/- 6.54e+05 | |
a0 | 1e-35 | 7.56e+02 | 7.52e+02 | +/- 4.43e+05 | +/- -1.00e+00 |
p | 2.54e+00 | 2.42e+00 | +/- 4.93e+00 | +/- 4.50e+00 | |
eebrk | keV | 1.71e+01 | 1.71e+01 | +/- 1.31e+00 | +/- 1.05e+00 |
q | 6.28e+00 | 6.31e+00 | +/- 9.34e-01 | +/- 5.36e-01 | |
eelow | keV | 8.97e+00 | 8.96e+00 | +/- 3.42e+01 | +/- 3.38e+01 |
eehigh | keV | 4.48e+01 | 4.51e+01 | +/- 9.44e+00 | +/- 1.05e+00 |
norm | 1.95e-04 | 1.91e-04 | +/- 1.13e-01 | +/- -1.00e+00 |
Original | Optimized | $\Delta$ | |
---|---|---|---|
thick-target | 24.58 | 22.60 | 1.98 |
apec + thick-target | 48.30 | 48.57 | -0.28 |