In [1]:
%matplotlib inline
In [2]:
import matplotlib.pyplot as plt
In [3]:
waves = np.arange(0.8, 1.1, 0.005)
In [4]:
waves.shape
Out[4]:
In [5]:
wavenos = 1e4/waves
In [6]:
wavenos
Out[6]:
In [7]:
import hapi
In [8]:
hapi.db_begin('hapi_db')
In [9]:
nu_min = 1e7/1150
nu_max = 1e7/800
hapi.fetch('CO2', 2, 1, nu_min, nu_max)
In [10]:
# %%timeit
# nu, coeff_co2 = hapi.absorptionCoefficient_Voigt(SourceTables='CO2',
# Environment={'p': 90,
# 'T': 700},
# GammaL='gamma_self')
In [11]:
# %%timeit
# nu, coeff_co2 = hapi.absorptionCoefficient_Voigt(SourceTables='CO2',
# Environment={'p': 90,
# 'T': 700},
# OmegaStep=0.1,
# GammaL='gamma_self')
In [12]:
# %%timeit
# nu, coeff_co2 = hapi.absorptionCoefficient_Voigt(SourceTables='CO2',
# Environment={'p': 90,
# 'T': 700},
# OmegaGrid=wavenos,
# GammaL='gamma_self')
The %timeit (for 1-liners) and %%timeit (for several lines of code) ipython magics (that's what they call %-functions) don't actually store the results for memory protection reasons (imagine each of your tests create a lot of data), so you have to run it without the timing test to actually get to the result.
Also, even so the wavenumber min delta required would have been around 40, anything larger than 0.1 wavenumbers and the code barks that that would lead to declining accuracy.
Interestingly, using OmegaGrid, it does not bark, even so the deltas are between 40 and 70 wavenumbers.
In [13]:
nu, coeff_co2 = hapi.absorptionCoefficient_Voigt(SourceTables='CO2',
Environment={'p': 90,
'T': 700},
OmegaGrid=wavenos,
# OmegaRange=[wavenos.min(),
# wavenos.max()],
# OmegaStep=0.1,
GammaL='gamma_self')
In [14]:
print(wavenos[::-1])
In [15]:
waves_nu = 1e4/nu
I understand it now. When one calculates the wavenumbers from wavelengths and does NOT invert them in sequence and provides it to the coeff calculator, the confusing part is that it returns things in increasing wavenumber order.
This means, if I plot the result over un-inverted wavelengths, it's wrong! One has to invert the wavelengths, now that the results are sorted by increasing wavenumber. This is no Python-ism but a decision of the HAPI API, probably based on old calculation formulas that were used to start at the lowest wavenumber. See below how to get it correct and consistent.
In [16]:
plt.semilogy(waves[::-1], coeff_co2)
Out[16]:
In [17]:
plt.semilogy(nu, coeff_co2)
Out[17]:
This strongly looks like 0.005 micron is not enough resolution, the plots looks a lot different then before. I go to 0.001 micron resolution for the following plots:
In [18]:
waves = np.arange(0.8, 1.1, 0.001)
In [19]:
wavenos = 1e4/waves
In [20]:
nu, coeff_co2 = hapi.absorptionCoefficient_Voigt(SourceTables='CO2',
Environment={'p': 90,
'T': 700},
OmegaGrid=wavenos,
GammaL='gamma_self')
In [21]:
plt.semilogy(waves[::-1], coeff_co2)
Out[21]:
In [22]:
plt.semilogy(nu, coeff_co2)
Out[22]:
I changed x-axis to use nu instead of wavenumbers, just to see that the results are consistent. The nice thing is when using OmegaGrid as a parameter, the nu array really contains only the numbers that were provided in the first place.
In [ ]: