hitranonline / hapi

HITRAN Application Programming Interface (HAPI)
Other
75 stars 35 forks source link

querying any absorption coefficient gives always the same result #21

Open gfacciol opened 4 years ago

gfacciol commented 4 years ago

Hi, I'm trying to extract the transmittance spectrum for several gases. I followed the manual, however I always get the same profile. What am I doing wrong? Thanks in advance!

import hapi
hapi.db_begin('hitran_data')
for x in ['NO2', 'CO2']:
    hapi.fetch(x,1,1,3000,7000)
    nu,coef = hapi.absorptionCoefficient_Lorentz(SourceTables=x, HITRAN_units=False)
    nu,trans = hapi.transmittanceSpectrum(nu,coef)
    plt.figure()
    plt.plot(nu,trans)
GibClark commented 4 years ago

Hi @gfacciol, hapi.fetch() requires integer inputs that specify the molecule ID and isotopologue ID in the HITRAN database. These inputs are M and I respectively in the fetch() documentation:

fetch(TableName, M, I, numin, numax, ParameterGroups=[], Parameters=[])

the first line in your for loop is actually fetching the 1st isotopologue of H2O molecule from HITRAN and naming the table with your iterating variable x . To access the molecules NO2 and CO2, you need to specify molecule ID's 10, and 2, respectively. A dictionary with the molecule string as the key and the molecule ID as the value might be a better structure to iterate through for your example above.

Species = {
    'NO2': 10,
    'CO2': 2
    }

for x,M in Species.items():
    hapi.fetch(x,M,1,3000,7000)
    . . .

EDIT NB the above analyzes only the 1st isotopologue.

dima72 commented 1 year ago

Hi guys, should fetch('CH4',2,1,2000,2100) and fetch('NH3',2,1,2000,2100) and any other molecule use different set of data? I have enabled DISPLAY_FETCH_URL and can see that fetch on any molecule uses the same URL

https://hitran.org/lbl/api?iso_ids_list=7&numin=2000&numax=2100

is this how it supposed to be?

I'm also having the same Spectrum for absorptionCoefficient_Lorentz with different molecules.

erwanp commented 1 year ago

The molecule name is more of a key for the local database. The molecule index is what matters I have a converter there just copy and paste : https://github.com/radis/radis/blob/27a80617bb2675ef8b7c88e549c430ef947418c2/radis/db/classes.py#L220

dima72 commented 1 year ago

Erwanp, why fetch(MoleculeName, 2,1,2000, 2100 ) on any molecule brings all the same data for any molecule? it uses all the same query https://hitran.org/lbl/api?iso_ids_list=7&numin=2000&numax=2100

erwanp commented 1 year ago

Use

fetch(MoleculeName, get_molecule_identifier(MoleculeName),isotope_number,2000, 2100 ) 

with the get_molecule_identifier code mentioned above (copy-paste it)

dima72 commented 1 year ago

Erwanp, thank you for clarification! Now it is clear that the first parameter TableName has no effect on the data, but parameters M_id and I_id are determining the iso_ids_list parameter of http query.

The RADIS library looks awesome addition to Hitran!

erwanp commented 1 year ago

Radis is simpler to use but hapi is more complete for advanced spectroscopy usages