Opacity Factory¶
PICASO
currently comes with single opacity database that includes both the continuum and molecular opacity. The opacity file that comes included with has a 0.3-14 \(\mu\)m opacity grid sampled at R=15000. This is why we consistently bin our spectra to R~100. Contact us with opacity needs.
We chose those use sqlite3
for our database because of it’s 1) user-friendliness, 2) speed, 3) scalability, 4) compatibility with parallel programing. We tried out various other methods as well– json
, hdf5
, ascii
, sqlalchemy
– but sqlite3
was truly better for this specific problem.
In this tutorial you wil learn how to quickly grab any opacity data
[1]:
import warnings
warnings.filterwarnings('ignore')
import io
import numpy as np
import os
import picaso.opacity_factory as opa
#plotting
from bokeh.io import output_notebook
output_notebook()
from bokeh.plotting import show,figure
General Sqlite3 and how our database is structured¶
3 Tables:
header
,continuum
, andmolecular
header: contains units and the wavenumber grid
continuum: contains a grid continuum opacity and is temperature dependent
molecular: contains all molecular opacity and is pressure-temperature dependent.
How to Query the Database¶
[2]:
#this is where your opacity file should be located if you've set your environments correctly
db_filename = os.path.join(os.getenv('picaso_refdata'), 'opacities','opacities.db')
What Species, Pressures and Temperatures are Available¶
[3]:
molecules, pt_pairs = opa.molecular_avail(db_filename)
[4]:
print(molecules)
['CH4', 'CO', 'CO2', 'H2O', 'K', 'NH3', 'Na', 'TiO', 'VO']
[5]:
pt_pairs[0:10] #full list of all the pt pairs. the first value is just an index for bookkeeping
[5]:
[(1, 1e-06, 75.0),
(2, 3e-06, 75.0),
(3, 1e-05, 75.0),
(4, 3e-05, 75.0),
(5, 0.0001, 75.0),
(6, 0.0003, 75.0),
(7, 0.001, 75.0),
(8, 0.003, 75.0),
(9, 0.01, 75.0),
(10, 0.03, 75.0)]
[6]:
species_to_get = ['H2O']
temperature = list(np.arange(400,1000,10)) #this will find the nearest point for you in the db
pressure = [1]*len(temperature) #in bars
#NOTE: temperature and pressure lists are defined as pairs. The list above is
#grabbing temperatures from 400-1000 all at 1 bar.
data = opa.get_molecular(db_filename, species_to_get, temperature,pressure)
[7]:
data.keys()
[7]:
dict_keys(['H2O', 'wavenumber'])
[8]:
#note these temperatures might be different from your input
#if there isnt an exact point matching your input
data['H2O'].keys()
[8]:
dict_keys([400.0, 425.0, 450.0, 475.0, 500.0, 575.0, 650.0, 725.0, 800.0, 900.0, 1000.0])
[9]:
data['H2O'][400.0].keys() #in this case we had the exact point (1.0 bar)
[9]:
dict_keys([1.0])
[10]:
from bokeh.palettes import Spectral11
f = figure(y_axis_type='log',height=500,y_range=[1e-29,1e-17],
y_axis_label='Cross Section (cm2/species)', x_axis_label='Micron')
for T , C in zip(data['H2O'].keys(), Spectral11):
f.line(1e4/data['wavenumber'],data['H2O'][T][1.0], color=C,legend_label=str(T))
show(f)