Computing Cross Sections for a Grid of Pressures and Temperatures
Often, a user will want to compute a cross section at multiple pressure and temperatures. In this tutorial, we demonstrate how to do just that, along with plotting all the cross sections on the same graph. We assume the user has read the Cross Sections for Beginners tutorial already.
Pressure Grid
To compute the cross section for a grid, simply enter an array instead of a single number for either the pressure, temperature, or both. Everything else remains the same. In this section, we’ll compute over a grid of pressures, and in the next section we’ll compute over a grid of temperatures.
[1]:
from Cthulhu.core import summon, compute_cross_section
species = 'CO'
database = 'ExoMol'
# Download line list
summon(database=database, species = species)
P = [0.01, 0.1, 1.0] # Pressure in bars
T = [1000.0] # Temperature in Kelvin
input_directory = './input/' # Top level directory containing line lists
# Calculate the cross section
compute_cross_section(species = species, database = database, temperature = T,
pressure = P, input_dir = input_directory,
)
***** Downloading requested data from ExoMol. You have chosen the following parameters: *****
Molecule: CO
Isotopologue: 12C-16O
Line List: Li2015
Starting by downloading the .broad, .pf, and .states files...
Fetched the broadening coefficients, partition functions, and energy levels.
Now downloading the Li2015 line list...
Downloading .trans file 1 of 2
100%|██████████| 1.40M/1.40M [00:00<00:00, 1.68MiB/s]
Converting this .trans file to HDF to save storage space...
This file took 0.3 seconds to reformat to HDF.
Downloading .trans file 2 of 2
100%|██████████| 63.5k/63.5k [00:00<00:00, 283kiB/s]
Converting this .trans file to HDF to save storage space...
This file took 0.1 seconds to reformat to HDF.
Line list ready.
Beginning cross-section computations...
Loading ExoMol format
Loading partition function
Pre-computing Voigt profiles...
Voigt profiles computed in 5.459220441996877 s
Pre-computation steps complete
Generating cross section for CO at P = 0.01 bar, T = 1000.0 K [1 of 3]
Computing transitions from E2.h5 | 0.0% complete
Completed 6474 transitions in 1.660071459999017 s
Computing transitions from Li2015.h5 | 50.0% complete
Completed 125496 transitions in 0.5521966680025798 s
Calculation complete!
Completed 131970 transitions in 2.213538334995974 s
Pre-computing Voigt profiles...
Voigt profiles computed in 4.45014415300102 s
Pre-computation steps complete
Generating cross section for CO at P = 0.1 bar, T = 1000.0 K [2 of 3]
Computing transitions from E2.h5 | 0.0% complete
Completed 6474 transitions in 0.033792235000873916 s
Computing transitions from Li2015.h5 | 50.0% complete
Completed 125496 transitions in 0.5599274929991225 s
Calculation complete!
Completed 131970 transitions in 0.5946834560018033 s
Pre-computing Voigt profiles...
Voigt profiles computed in 4.073088478005957 s
Pre-computation steps complete
Generating cross section for CO at P = 1.0 bar, T = 1000.0 K [3 of 3]
Computing transitions from E2.h5 | 0.0% complete
Completed 6474 transitions in 0.05859716499981005 s
Computing transitions from Li2015.h5 | 50.0% complete
Completed 125496 transitions in 1.0286980919991038 s
Calculation complete!
Completed 131970 transitions in 1.088124058995163 s
Total runtime: 24.200665153002774 s
Next, we need to parse the cross section files and extract the cross section data. As usual, we first import the relevant functions from cthulhu.plot.
Then, we create an empty array called cross_sections that will contain all of our cross sections. We add the first cross section to this empty collection of cross sections. This is done by calling the cross_section_collection function with the data of the new cross section (nu and sigma) along with the cross sections parameter. We call this statement a second and third time to add the other temperature-pressure combinations to the collection as well. By passing in the
collection = cross_sections parameter every time, we ensure that all of our cross sections are added to the same collection, to make the plotting easier in the next part.
[2]:
from Cthulhu.misc import read_cross_section_file, cross_section_collection
# Read in the 3 cross sections we just computed
nu, sigma = read_cross_section_file(species = species, database = database,
filename = 'CO_T1000K_log_P-2.0_H2-He_sigma.txt')
nu2, sigma2 = read_cross_section_file(species = species, database = database,
filename = 'CO_T1000K_log_P-1.0_H2-He_sigma.txt')
nu3, sigma3 = read_cross_section_file(species = species, database = database,
filename = 'CO_T1000K_log_P0.0_H2-He_sigma.txt')
# Generate an empty collection object for plotting
cross_sections = []
# Add first cross section to collection
cross_sections = cross_section_collection(new_x = nu, new_y = sigma, collection = cross_sections)
# Add second cross section to collection, making sure to specify the previous collection as a parameter
cross_sections = cross_section_collection(new_x = nu2, new_y = sigma2, collection = cross_sections)
# Add third cross section to collection
cross_sections = cross_section_collection(new_x = nu3, new_y = sigma3, collection = cross_sections)
Let’s show all 3 cross sections for different pressures on the same plot
[3]:
from Cthulhu.plot import plot_cross_section
plot_cross_section(collection = cross_sections,
labels = ['P = 0.01 bar', 'P = 0.1 bar', 'P = 1 bar'],
filename = 'CO_Cross_Section_at_Diff_Pressures',
y_min = 1.0e-30,
)
Temperature Grid
Now we’ll do the same process, but instead of varying the pressure, we’ll vary the temperature.
Since there is only one parameter that changes (T), we leave the code below with no intermediary comments, so that the user can see all of Cthulhu in action at once. For clarity, we redefine the parameters and reimport functions.
[5]:
from Cthulhu.core import summon, compute_cross_section
species = 'CO'
database = 'ExoMol'
# Download the line list
summon(database=database, species = species) # Already done above, so Cthulhu doesn't need to be summoned!
# Specify pressure and temperature range
P = [1.0] # Pressure in bars
T = [1000.0, 2000.0, 3000.0] # Temperature in Kelvin
input_directory = './input/' # Top level directory containing line lists
# Calculate cross section
compute_cross_section(species = species, database = database, temperature = T,
pressure = P, input_dir = input_directory,
)
# Read in the 3 cross sections we just computed
nu, sigma = read_cross_section_file(species = species, database = database,
filename = 'CO_T1000.0K_log_P0.0_H2-He_sigma.txt')
nu2, sigma2 = read_cross_section_file(species = species, database = database,
filename = 'CO_T2000.0K_log_P0.0_H2-He_sigma.txt')
nu3, sigma3 = read_cross_section_file(species = species, database = database,
filename = 'CO_T3000.0K_log_P0.0_H2-He_sigma.txt')
# Generate an empty collection object for plotting
cross_sections = []
# Add first cross section to collection
cross_sections = cross_section_collection(new_x = nu, new_y = sigma, collection = cross_sections)
# Add second cross section to collection, making sure to specify the previous collection as a parameter
cross_sections = cross_section_collection(new_x = nu2, new_y = sigma2, collection = cross_sections)
# Add third cross section to collection
cross_sections = cross_section_collection(new_x = nu3, new_y = sigma3, collection = cross_sections)
# Plot all 3 cross sections on the same plot'''
plot_cross_section(collection = cross_sections,
labels = ['P = 0.01 bar', 'P = 0.1 bar', 'P = 1 bar'],
filename = 'CO_Cross_Section_at_Diff_Pressures',
y_min = 1.0e-30,
)
***** Downloading requested data from ExoMol. You have chosen the following parameters: *****
Molecule: CO
Isotopologue: 12C-16O
Line List: Li2015
Starting by downloading the .broad, .pf, and .states files...
This file is already downloaded. Moving on.
Fetched the broadening coefficients, partition functions, and energy levels.
Now downloading the Li2015 line list...
Downloading .trans file 1 of 2
This file is already downloaded. Moving on.
Downloading .trans file 2 of 2
This file is already downloaded. Moving on.
Line list ready.
Beginning cross-section computations...
Loading ExoMol format
Loading partition function
Pre-computing Voigt profiles...
Voigt profiles computed in 4.007787078997353 s
Pre-computation steps complete
Generating cross section for CO at P = 1.0 bar, T = 1000.0 K [1 of 3]
Computing transitions from E2.h5 | 0.0% complete
Completed 6474 transitions in 0.05898992100264877 s
Computing transitions from Li2015.h5 | 50.0% complete
Completed 125496 transitions in 1.052203617997293 s
Calculation complete!
Completed 131970 transitions in 1.1123167639962048 s
Pre-computing Voigt profiles...
Voigt profiles computed in 4.575220471000648 s
Pre-computation steps complete
Generating cross section for CO at P = 1.0 bar, T = 2000.0 K [2 of 3]
Computing transitions from E2.h5 | 0.0% complete
Completed 6474 transitions in 0.05450546000065515 s
Computing transitions from Li2015.h5 | 50.0% complete
Completed 125496 transitions in 1.040411749992927 s
Calculation complete!
Completed 131970 transitions in 1.09579663999466 s
Pre-computing Voigt profiles...
Voigt profiles computed in 4.652520743999048 s
Pre-computation steps complete
Generating cross section for CO at P = 1.0 bar, T = 3000.0 K [3 of 3]
Computing transitions from E2.h5 | 0.0% complete
Completed 6474 transitions in 0.05505319999792846 s
Computing transitions from Li2015.h5 | 50.0% complete
Completed 125496 transitions in 1.0762401559986756 s
Calculation complete!
Completed 131970 transitions in 1.1322044289991027 s
Total runtime: 23.23582079899643 s
[ ]: