Skip to content

Commit ef4d6ba

Browse files
committed
add continuum comparison example
1 parent ea0ef7c commit ef4d6ba

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
"""
2+
CHIANTI IDL Comparison: Continuum
3+
==================================
4+
5+
Compare the free-free and free-bound calculations to that in the CHIANTI IDL routines.
6+
"""
7+
import hissw
8+
import matplotlib.colors
9+
import matplotlib.pyplot as plt
10+
import numpy as np
11+
12+
from astropy.visualization import quantity_support
13+
14+
import fiasco
15+
16+
from fiasco.tests.idl.helpers import read_idl_test_output
17+
18+
quantity_support()
19+
20+
################################################
21+
# Define a function for comparing and plotting
22+
# the outputs from fiasco and IDL. Note that we have precomputed
23+
# the IDL outputs.
24+
def plot_idl_comparison(wavelength, temperature, result_fiasco, result_idl):
25+
wave_mesh, temp_mesh = np.meshgrid(wavelength, temperature)
26+
temp_mesh = temp_mesh.to_value('K')
27+
wave_mesh = wave_mesh.to_value('Angstrom')
28+
result_fiasco = result_fiasco.to_value('erg cm3 s-1 Angstrom-1')
29+
result_idl = result_idl.to_value('erg cm3 s-1 Angstrom-1')
30+
difference = result_fiasco - result_idl
31+
difference_norm = difference / result_idl
32+
33+
fig = plt.figure(figsize=(10,10))
34+
axes = fig.subplot_mosaic(
35+
"""
36+
AABB
37+
.CC.
38+
""",
39+
sharex=True,
40+
sharey=True,
41+
)
42+
norm = matplotlib.colors.LogNorm(vmin=1e-30,vmax=1e-26)
43+
# IDL result
44+
im = axes['A'].pcolormesh(temp_mesh, wave_mesh, result_idl, norm=norm)
45+
axes['A'].set_title('IDL')
46+
axes['A'].set_xscale('log')
47+
axes['A'].set_xlabel('Temperature [K]')
48+
axes['A'].set_ylabel(r'Wavelength [$\AA$]')
49+
# fiasco result
50+
im = axes['B'].pcolormesh(temp_mesh, wave_mesh, result_fiasco, norm=norm)
51+
axes['B'].set_title('fiasco')
52+
fig.colorbar(im, ax=[axes['A'], axes['B']], orientation='horizontal')
53+
# Normalized difference
54+
im = axes['C'].pcolormesh(temp_mesh, wave_mesh, difference_norm,
55+
norm=matplotlib.colors.SymLogNorm(1e-3, vmin=-1, vmax=1),
56+
cmap='RdBu')
57+
axes['C'].set_title('Normalized Difference')
58+
fig.colorbar(im, ax=axes['C'])
59+
plt.show()
60+
61+
62+
################################################
63+
# First, let's compare the outputs for the free-free
64+
# continuum emission, i.e. that emission produced by
65+
# thermal bremsstrahlung.
66+
idl_result_freefree = read_idl_test_output('freefree_all_ions', '8.0.7')
67+
ion_kwargs = {'abundance': idl_result_freefree['abundance'], 'ioneq_filename': idl_result_freefree['ioneq']}
68+
all_ions = [fiasco.Ion(ion_name, idl_result_freefree['temperature'], **ion_kwargs) for ion_name in fiasco.list_ions()]
69+
all_ions = fiasco.IonCollection(*all_ions)
70+
free_free = all_ions.free_free(idl_result_freefree['wavelength'])
71+
plot_idl_comparison(idl_result_freefree['wavelength'],
72+
idl_result_freefree['temperature'],
73+
free_free,
74+
idl_result_freefree['free_free'])
75+
# This is just for printing the code used to produce the IDL result
76+
env = hissw.Environment(ssw_home='', idl_home='')
77+
template = env.env.from_string(idl_result_freefree['idl_script'])
78+
print('IDL code to produce free-free result:')
79+
print(template.render(**idl_result_freefree))
80+
81+
################################################
82+
# Next, let's compare the outputs for the free-bound
83+
# continuum emission.
84+
idl_result_freebound = read_idl_test_output('freebound_all_ions', '8.0.7')
85+
ion_kwargs = {'abundance': idl_result_freebound['abundance'], 'ioneq_filename': idl_result_freebound['ioneq']}
86+
all_ions = [fiasco.Ion(ion_name, idl_result_freebound['temperature'], **ion_kwargs) for ion_name in fiasco.list_ions()]
87+
all_ions = fiasco.IonCollection(*all_ions)
88+
free_bound = all_ions.free_bound(idl_result_freebound['wavelength'])
89+
plot_idl_comparison(idl_result_freebound['wavelength'],
90+
idl_result_freebound['temperature'],
91+
free_bound,
92+
idl_result_freebound['free_bound'])
93+
# This is just for printing the code used to produce the IDL result
94+
template = env.env.from_string(idl_result_freebound['idl_script'])
95+
print('IDL code to produce free-free result:')
96+
print(template.render(**idl_result_freebound))

0 commit comments

Comments
 (0)