### Calculate Lorentz Profile Absorption Source: https://context7.com/hitranonline/hapi/llms.txt Calculates absorption coefficients for pressure-dominated regimes. The second example demonstrates saving the output directly to a file. ```python nu, coef = absorptionCoefficient_Lorentz( SourceTables='CH4', Components=[(6, 1)], # CH4, main isotopologue Environment={'T': 296., 'p': 10.}, # 10 atm pressure WavenumberRange=[3000, 3100], WavenumberStep=0.01, HITRAN_units=True ) # Save to file nu, coef = absorptionCoefficient_Lorentz( SourceTables='CH4', Components=[(6, 1)], Environment={'T': 296., 'p': 1.}, WavenumberRange=[3050, 3060], WavenumberStep=0.001, File='ch4_lorentz.txt', Format='%12.6f %12.6e' ) ``` -------------------------------- ### Get Available Tables with tableList Source: https://context7.com/hitranonline/hapi/llms.txt Returns a list of all tables currently loaded in the database cache. This function is useful for managing multiple datasets within the HAPI environment. ```python from hapi import * db_begin('data') fetch('H2O', 1, 1, 1000, 1100) fetch('CO2', 2, 1, 2000, 2100) # Get list of all available tables tables = tableList() print("Tables:", tables) # Output: Tables: ['H2O', 'CO2'] ``` -------------------------------- ### Calculate Speed-Dependent Voigt Profile Source: https://context7.com/hitranonline/hapi/llms.txt Accounts for velocity dependence of collisional parameters. The example compares the result against a standard Voigt profile. ```python from hapi import * db_begin('data') fetch('CO2', 2, 1, 2380, 2400) # Speed-dependent Voigt profile nu, coef = absorptionCoefficient_SDVoigt( SourceTables='CO2', Components=[(2, 1)], Environment={'T': 296., 'p': 1.}, WavenumberRange=[2380, 2400], WavenumberStep=0.001, Diluent={'air': 1.0}, HITRAN_units=True ) # Compare with standard Voigt nu_v, coef_v = absorptionCoefficient_Voigt( SourceTables='CO2', Components=[(2, 1)], Environment={'T': 296., 'p': 1.}, WavenumberRange=[2380, 2400], WavenumberStep=0.001 ) import matplotlib.pyplot as plt plt.plot(nu, coef, 'b-', label='SD-Voigt') plt.plot(nu_v, coef_v, 'r--', label='Voigt') plt.legend() plt.xlabel('Wavenumber (cm-1)') plt.ylabel('Absorption Coefficient') plt.show() ``` -------------------------------- ### Calculate Hartmann-Tran Profile Source: https://context7.com/hitranonline/hapi/llms.txt Utilizes the most comprehensive line shape model. Includes examples for standard usage and custom environment configurations. ```python from hapi import * db_begin('data') fetch('CO2', 2, 1, 2380, 2400) # Hartmann-Tran (HT) profile - most accurate nu, coef = absorptionCoefficient_HT( SourceTables='CO2', Components=[(2, 1)], Environment={'T': 296., 'p': 1.}, WavenumberRange=[2380, 2400], WavenumberStep=0.001, Diluent={'air': 1.0}, HITRAN_units=True, LineMixingRosen=True # Include first-order line mixing ) # HT profile with custom environment nu, coef = absorptionCoefficient_HT( SourceTables='CO2', Components=[(2, 1)], Environment={'T': 250., 'p': 0.5}, WavenumberRange=[2385, 2395], WavenumberStep=0.0005, Diluent={'air': 0.8, 'self': 0.2}, HITRAN_units=False # returns cm^-1 ) ``` -------------------------------- ### Get Molecule Name with moleculeName Source: https://context7.com/hitranonline/hapi/llms.txt Retrieves the name of a HITRAN molecule using its molecule number. ```python from hapi import * # Get molecule names print(moleculeName(1)) # 'H2O' print(moleculeName(2)) # 'CO2' print(moleculeName(3)) # 'O3' print(moleculeName(4)) # 'N2O' print(moleculeName(5)) # 'CO' print(moleculeName(6)) # 'CH4' ``` -------------------------------- ### Get Natural Abundance with abundance Source: https://context7.com/hitranonline/hapi/llms.txt Returns the natural abundance of a HITRAN isotopologue. Requires molecule and isotopologue numbers as input. ```python from hapi import * # Get abundance of main H2O isotopologue (H2-16O) ab_h2o = abundance(1, 1) print(f"H2O abundance: {ab_h2o}") # ~0.997 # Get abundance of HDO ab_hdo = abundance(1, 4) print(f"HDO abundance: {ab_hdo}") # ~3.1e-4 # Get abundance of 13CO2 ab_co2_13 = abundance(2, 2) print(f"13CO2 abundance: {ab_co2_13}") # ~0.011 ``` -------------------------------- ### Get Isotopologue Name with isotopologueName Source: https://context7.com/hitranonline/hapi/llms.txt Returns the name of a specific isotopologue given its molecule and isotopologue numbers. ```python from hapi import * # Get isotopologue names for water print(isotopologueName(1, 1)) # 'H2(16O)' print(isotopologueName(1, 2)) # 'H2(18O)' print(isotopologueName(1, 3)) # 'H2(17O)' print(isotopologueName(1, 4)) # 'HD(16O)' # Get isotopologue names for CO2 print(isotopologueName(2, 1)) # '(12C)(16O)2' print(isotopologueName(2, 2)) # '(13C)(16O)2' ``` -------------------------------- ### Get Molecular Mass with molecularMass Source: https://context7.com/hitranonline/hapi/llms.txt Returns the molecular mass in atomic mass units for a given isotopologue. Requires molecule and isotopologue numbers. ```python from hapi import * # Get mass of main H2O isotopologue mass_h2o = molecularMass(1, 1) print(f"H2O mass: {mass_h2o} amu") # ~18.01 # Get mass of CO2 mass_co2 = molecularMass(2, 1) print(f"CO2 mass: {mass_co2} amu") # ~43.99 # Get mass of heavy water D2O mass_d2o = molecularMass(1, 7) print(f"D2O mass: {mass_d2o} amu") # ~20.02 ``` -------------------------------- ### Initialize Database Connection with db_begin Source: https://context7.com/hitranonline/hapi/llms.txt Opens a database connection to store and retrieve spectroscopic data. Data is stored in a folder specified by the `db` parameter, with the default being the current directory. Use `tableList()` to see available tables. ```python from hapi import * # Initialize database in default directory (current folder) db_begin() # Initialize database in a custom directory db_begin('my_spectroscopy_data') # List all tables in the current database tables = tableList() print("Available tables:", tables) ``` -------------------------------- ### Complete Atmospheric Data Workflow Source: https://context7.com/hitranonline/hapi/llms.txt Demonstrates a full analysis pipeline including database initialization, property retrieval, spectral calculation, convolution, and multi-panel plotting. ```python from hapi import * import matplotlib.pyplot as plt # Initialize database db_begin('atmospheric_data') # Download CO2 data in the 15 micron band fetch('CO2', 2, 1, 600, 750) # Display table information print("Available tables:", tableList()) describe('CO2') # Get molecular properties print(f"Molecule: {moleculeName(2)}") print(f"Isotopologue: {isotopologueName(2, 1)}") print(f"Mass: {molecularMass(2, 1)} amu") print(f"Abundance: {abundance(2, 1)}") # Calculate partition sum Q_296 = partitionSum(2, 1, 296) print(f"Partition sum at 296K: {Q_296}") # Calculate high-resolution absorption coefficient nu, coef = absorptionCoefficient_Voigt( SourceTables='CO2', Components=[(2, 1)], Environment={'T': 296., 'p': 1.}, WavenumberRange=[660, 680], WavenumberStep=0.01, HITRAN_units=False ) # Calculate transmittance for 10 m path nu, trans = transmittanceSpectrum(nu, coef, Environment={'l': 1000.}) # Simulate low-resolution measurement nu_lr, trans_lr, _, _, _ = convolveSpectrum( nu, trans, Resolution=1.0, AF_wing=5.0, SlitFunction=SLIT_GAUSSIAN ) # Plot results fig, axes = plt.subplots(2, 2, figsize=(14, 10)) # Stick spectrum x, y = getStickXY('CO2') axes[0, 0].plot(x, y) axes[0, 0].set_xlim([660, 680]) axes[0, 0].set_xlabel('Wavenumber (cm-1)') axes[0, 0].set_ylabel('Line Intensity') axes[0, 0].set_title('Stick Spectrum') # Absorption coefficient axes[0, 1].semilogy(nu, coef) axes[0, 1].set_xlabel('Wavenumber (cm-1)') axes[0, 1].set_ylabel('Absorption Coefficient (cm-1)') axes[0, 1].set_title('Voigt Absorption Coefficient') # High-res transmittance axes[1, 0].plot(nu, trans) axes[1, 0].set_xlabel('Wavenumber (cm-1)') axes[1, 0].set_ylabel('Transmittance') axes[1, 0].set_ylim([0, 1]) axes[1, 0].set_title('High-Resolution Transmittance (10m path)') # Low-res transmittance axes[1, 1].plot(nu_lr, trans_lr) axes[1, 1].set_xlabel('Wavenumber (cm-1)') axes[1, 1].set_ylabel('Transmittance') axes[1, 1].set_ylim([0, 1]) axes[1, 1].set_title('Convolved Spectrum (1 cm-1 resolution)') plt.tight_layout() plt.savefig('co2_analysis.png', dpi=150) plt.show() # Save database db_commit() ``` -------------------------------- ### Calculate Partition Sums with partitionSum Source: https://context7.com/hitranonline/hapi/llms.txt Calculates total internal partition sums at specified temperatures using TIPS data. Supports various TIPS versions and temperature ranges. ```python from hapi import * # Calculate partition sum at single temperature Q_296 = partitionSum(1, 1, 296) # H2O at 296 K print(f"Q(296K) = {Q_296}") # Calculate partition sums at multiple temperatures temps = [200, 296, 500, 1000] Q_list = partitionSum(1, 1, temps) for T, Q in zip(temps, Q_list): print(f"Q({T}K) = {Q}") # Calculate over temperature range with step T_grid, Q_grid = partitionSum(1, 1, [200, 1000], step=10) # Use specific TIPS version Q_2021 = partitionSum(1, 1, 296, version=2021) Q_2017 = partitionSum(1, 1, 296, version=2017) Q_2011 = partitionSum(1, 1, 296, version=2011) # Plot partition sum vs temperature import matplotlib.pyplot as plt T, Q = partitionSum(2, 1, [100, 3000], step=10) # CO2 plt.plot(T, Q) plt.xlabel('Temperature (K)') plt.ylabel('Partition Sum Q(T)') plt.title('CO2 Partition Sum') plt.show() ``` -------------------------------- ### Display Table Information with describe Source: https://context7.com/hitranonline/hapi/llms.txt Prints detailed information about a table including parameter names, formats, number of rows, and wavenumber range. This is useful for understanding the structure of downloaded spectroscopic data. ```python from hapi import * db_begin('data') fetch('H2O', 1, 1, 1000, 1100) # Display table structure and metadata describe('H2O') # Output: # Name: H2O # Rows: 1234 # Wavenumber range: 1000.000 - 1100.000 cm-1 # Parameters: molec_id, local_iso_id, nu, sw, a, gamma_air, ... ``` -------------------------------- ### partitionSum Source: https://context7.com/hitranonline/hapi/llms.txt Calculates total internal partition sums at specified temperatures using TIPS data. ```APIDOC ## partitionSum ### Description Calculates total internal partition sums at specified temperatures using TIPS (Total Internal Partition Sums) data. Supports TIPS-2011, TIPS-2017, TIPS-2021, and TIPS-2025 versions. ### Parameters #### Request Body - **molecule_number** (int) - Required - HITRAN molecule number - **isotopologue_number** (int) - Required - HITRAN isotopologue number - **temperature** (float/list) - Required - Temperature(s) in Kelvin - **version** (int) - Optional - TIPS version year ### Request Example partitionSum(1, 1, 296, version=2021) ``` -------------------------------- ### Download Single Isotopologue Data with fetch Source: https://context7.com/hitranonline/hapi/llms.txt Downloads line-by-line spectroscopic data from HITRANonline for a single molecule/isotopologue combination and saves it to a local table. You can specify molecule name, isotopologue ID, wavenumber range, and optional parameters like broadening. ```python from hapi import * db_begin('data') # Fetch water vapor (M=1) main isotopologue (I=1) between 1000-1100 cm-1 fetch('H2O', 1, 1, 1000, 1100) # Fetch CO2 (M=2) main isotopologue (I=1) between 2000-2100 cm-1 fetch('CO2', 2, 1, 2000, 2100) # Fetch with additional parameters (e.g., broadening parameters) fetch('H2O_extended', 1, 1, 1000, 1100, ParameterGroups=['Standard', 'Broadening'], Parameters=[]) # Verify download by describing the table describe('H2O') # Output includes: parameter names, formats, wavenumber range ``` -------------------------------- ### Calculate Transmittance Spectrum Source: https://context7.com/hitranonline/hapi/llms.txt Initializes the calculation of transmittance using the Beer-Lambert law. ```python from hapi import * db_begin('data') fetch('CO2', 2, 1, 2300, 2400) ``` -------------------------------- ### Calculate Gas Mixture Absorption Source: https://context7.com/hitranonline/hapi/llms.txt Demonstrates calculating absorption for mixtures by specifying mixing ratios or summing individual species contributions. ```python from hapi import * db_begin('data') # Fetch multiple species fetch('H2O', 1, 1, 1500, 1600) fetch('CO2', 2, 1, 1500, 1600) fetch('CH4', 6, 1, 1500, 1600) # Calculate mixture absorption (all in one table) fetch_by_ids('atmosphere', [1, 7, 26], 1500, 1600) nu, coef = absorptionCoefficient_Voigt( SourceTables='atmosphere', Components=[ (1, 1, 0.01), # H2O, 1% mixing ratio (2, 1, 0.0004), # CO2, 400 ppm (6, 1, 0.00002) # CH4, 20 ppm ], Environment={'T': 296., 'p': 1.}, WavenumberRange=[1500, 1600], WavenumberStep=0.01, HITRAN_units=False ) # Calculate individual species and sum nu_h2o, coef_h2o = absorptionCoefficient_Voigt( SourceTables='H2O', Components=[(1, 1, 0.01)], Environment={'T': 296., 'p': 1.}, WavenumberRange=[1500, 1600], WavenumberStep=0.01 ) nu_co2, coef_co2 = absorptionCoefficient_Voigt( SourceTables='CO2', Components=[(2, 1, 0.0004)], Environment={'T': 296., 'p': 1.}, WavenumberRange=[1500, 1600], WavenumberStep=0.01 ) ``` -------------------------------- ### Simulate FTIR Spectrum with Michelson Function Source: https://context7.com/hitranonline/hapi/llms.txt Calculates the absorption coefficient and transmittance, then applies a Michelson interferometer convolution. ```python db_begin('data') fetch('CO2', 2, 1, 2380, 2400) nu, coef = absorptionCoefficient_Voigt( SourceTables='CO2', Components=[(2, 1)], Environment={'T': 296., 'p': 1.}, WavenumberRange=[2380, 2400], WavenumberStep=0.001 ) nu, trans = transmittanceSpectrum(nu, coef, Environment={'l': 10.}) # Michelson interferometer simulation nu_ftir, trans_ftir, _, _, _ = convolveSpectrum( nu, trans, Resolution=0.1, # 0.1 cm-1 resolution AF_wing=2.0, SlitFunction=SLIT_MICHELSON ) ``` -------------------------------- ### Plot Stick Spectrum Data Source: https://context7.com/hitranonline/hapi/llms.txt Retrieves stick spectrum data using getStickXY and visualizes it alongside calculated Voigt absorption coefficients. ```python from hapi import * db_begin('data') fetch('CO2', 2, 1, 2380, 2400) # Get stick spectrum data x, y = getStickXY('CO2') import matplotlib.pyplot as plt # Plot stick spectrum plt.figure(figsize=(12, 4)) plt.plot(x, y, 'b-') plt.xlabel('Wavenumber (cm-1)') plt.ylabel('Line Intensity') plt.title('CO2 Stick Spectrum') plt.xlim([2380, 2400]) plt.show() # Combine with calculated absorption coefficient nu, coef = absorptionCoefficient_Voigt( SourceTables='CO2', Components=[(2, 1)], Environment={'T': 296., 'p': 1.}, WavenumberRange=[2380, 2400], WavenumberStep=0.01 ) fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 8), sharex=True) ax1.plot(x, y, 'b-') ax1.set_ylabel('Line Intensity') ax1.set_title('Stick Spectrum') ax2.plot(nu, coef, 'r-') ax2.set_xlabel('Wavenumber (cm-1)') ax2.set_ylabel('Absorption Coefficient') ax2.set_title('Voigt Absorption') plt.tight_layout() plt.show() ``` -------------------------------- ### Database Management Source: https://context7.com/hitranonline/hapi/llms.txt Functions for initializing and committing changes to the HAPI database. ```APIDOC ## Database Management ### db_begin - Initialize Database Connection Opens a database connection to store and retrieve spectroscopic data. Data is stored in a folder specified by the `db` parameter, with default being the current directory. ```python from hapi import * # Initialize database in default directory (current folder) db_begin() # Initialize database in a custom directory db_begin('my_spectroscopy_data') # List all tables in the current database tables = tableList() print("Available tables:", tables) ``` ### db_commit - Save Database Changes Commits all changes made to the opened database, saving all tables to their corresponding files on disk. ```python from hapi import * db_begin('spectral_data') # After making modifications to tables... # Save all changes to disk db_commit() ``` ``` -------------------------------- ### Data Fetching Source: https://context7.com/hitranonline/hapi/llms.txt Functions for downloading spectroscopic line-by-line data from HITRANonline. ```APIDOC ## Data Fetching ### fetch - Download Single Isotopologue Data Downloads line-by-line spectroscopic data from HITRANonline for a single molecule/isotopologue combination and saves it to a local table. ```python from hapi import * db_begin('data') # Fetch water vapor (M=1) main isotopologue (I=1) between 1000-1100 cm-1 fetch('H2O', 1, 1, 1000, 1100) # Fetch CO2 (M=2) main isotopologue (I=1) between 2000-2100 cm-1 fetch('CO2', 2, 1, 2000, 2100) # Fetch with additional parameters (e.g., broadening parameters) fetch('H2O_extended', 1, 1, 1000, 1100, ParameterGroups=['Standard', 'Broadening'], Parameters=[]) # Verify download by describing the table describe('H2O') # Output includes: parameter names, formats, wavenumber range ``` ### fetch_by_ids - Download Multiple Isotopologues Downloads line-by-line data for multiple isotopologues using global isotopologue IDs, allowing multiple species in a single table. ```python from hapi import * db_begin('data') # Fetch multiple water isotopologues (IDs 1,2,3,4) in 4000-4100 cm-1 range fetch_by_ids('water_isotopes', [1, 2, 3, 4], 4000, 4100) # Fetch all main isotopologues of H2O, CO2, and O3 # (global IDs: H2O=1, CO2=7, O3=16) fetch_by_ids('atmospheric_mix', [1, 7, 16], 2000, 2500) describe('water_isotopes') ``` ``` -------------------------------- ### Download Multiple Isotopologues with fetch_by_ids Source: https://context7.com/hitranonline/hapi/llms.txt Downloads line-by-line data for multiple isotopologues using global isotopologue IDs, allowing multiple species in a single table. This is useful for fetching data for a mixture of gases or different isotopes of the same gas. ```python from hapi import * db_begin('data') # Fetch multiple water isotopologues (IDs 1,2,3,4) in 4000-4100 cm-1 range fetch_by_ids('water_isotopes', [1, 2, 3, 4], 4000, 4100) # Fetch all main isotopologues of H2O, CO2, and O3 # (global IDs: H2O=1, CO2=7, O3=16) fetch_by_ids('atmospheric_mix', [1, 7, 16], 2000, 2500) describe('water_isotopes') ``` -------------------------------- ### Calculate Radiance Spectrum Source: https://context7.com/hitranonline/hapi/llms.txt Computes thermal emission radiance using the Planck function for different temperatures. ```python from hapi import * db_begin('data') fetch('CO2', 2, 1, 600, 700) # Calculate absorption coefficient nu, coef = absorptionCoefficient_Voigt( SourceTables='CO2', Components=[(2, 1)], Environment={'T': 296., 'p': 1.}, WavenumberRange=[600, 700], WavenumberStep=0.1, HITRAN_units=False ) # Calculate radiance spectrum (thermal emission) nu, radi = radianceSpectrum( nu, coef, Environment={'l': 100., 'T': 296.} # path length and temperature ) # Radiance at different temperatures nu, radi_hot = radianceSpectrum( nu, coef, Environment={'l': 100., 'T': 500.} ) import matplotlib.pyplot as plt plt.plot(nu, radi, label='296 K') plt.plot(nu, radi_hot, label='500 K') plt.xlabel('Wavenumber (cm-1)') plt.ylabel('Radiance (W/sr/cm²/cm⁻¹)') plt.legend() plt.title('CO2 Radiance Spectrum') plt.show() ``` -------------------------------- ### Calculate Absorption Spectrum Source: https://context7.com/hitranonline/hapi/llms.txt Computes the absorption spectrum as 1 minus transmittance. ```python from hapi import * db_begin('data') fetch('H2O', 1, 1, 1500, 1600) # Calculate absorption coefficient nu, coef = absorptionCoefficient_Voigt( SourceTables='H2O', Components=[(1, 1)], Environment={'T': 296., 'p': 1.}, WavenumberRange=[1500, 1600], WavenumberStep=0.01, HITRAN_units=False ) # Calculate absorption spectrum nu, absorp = absorptionSpectrum( nu, coef, Environment={'l': 100.} # 1 meter path ) import matplotlib.pyplot as plt plt.plot(nu, absorp) plt.xlabel('Wavenumber (cm-1)') plt.ylabel('Absorption (1 - Transmittance)') plt.title('H2O Absorption Spectrum') plt.show() ``` -------------------------------- ### Calculate Lorentz Absorption Coefficient Source: https://context7.com/hitranonline/hapi/llms.txt Calculates absorption coefficient using the Lorentzian profile, suitable for high-pressure conditions. Requires database initialization and data fetching. ```python from hapi import * db_begin('data') fetch('CH4', 6, 1, 3000, 3100) ``` -------------------------------- ### Calculate Transmittance Spectrum Source: https://context7.com/hitranonline/hapi/llms.txt Calculates transmittance for various path lengths and saves results to a file. ```python # Calculate absorption coefficient first nu, coef = absorptionCoefficient_Voigt( SourceTables='CO2', Components=[(2, 1)], Environment={'T': 296., 'p': 1.}, WavenumberRange=[2300, 2400], WavenumberStep=0.01, HITRAN_units=False # cm^-1 for transmittance calculation ) # Calculate transmittance for 10 cm path length nu, trans = transmittanceSpectrum( nu, coef, Environment={'l': 10.} # path length in cm ) # Calculate for 1 meter path nu, trans_1m = transmittanceSpectrum( nu, coef, Environment={'l': 100.} # 100 cm = 1 m ) # Save to file nu, trans = transmittanceSpectrum( nu, coef, Environment={'l': 10.}, File='transmittance.txt' ) import matplotlib.pyplot as plt plt.plot(nu, trans) plt.xlabel('Wavenumber (cm-1)') plt.ylabel('Transmittance') plt.ylim([0, 1]) plt.title('CO2 Transmittance (10 cm path)') plt.show() ``` -------------------------------- ### Apply Instrumental Slit Functions Source: https://context7.com/hitranonline/hapi/llms.txt Convolves high-resolution spectra with various instrumental slit functions to simulate experimental data. ```python from hapi import * db_begin('data') fetch('CO2', 2, 1, 2380, 2400) # Calculate high-resolution spectrum nu, coef = absorptionCoefficient_Voigt( SourceTables='CO2', Components=[(2, 1)], Environment={'T': 296., 'p': 1.}, WavenumberRange=[2380, 2400], WavenumberStep=0.001, # High resolution HITRAN_units=False ) nu, trans = transmittanceSpectrum(nu, coef, Environment={'l': 10.}) # Convolve with rectangular slit function nu_conv, trans_conv, i1, i2, slit = convolveSpectrum( nu, trans, Resolution=0.5, # Instrumental resolution in cm-1 AF_wing=5.0, # Wing of apparatus function SlitFunction=SLIT_RECTANGULAR ) # Convolve with Gaussian slit function nu_gauss, trans_gauss, _, _, _ = convolveSpectrum( nu, trans, Resolution=0.5, AF_wing=5.0, SlitFunction=SLIT_GAUSSIAN ) # Convolve with triangular slit function nu_tri, trans_tri, _, _, _ = convolveSpectrum( nu, trans, Resolution=0.5, AF_wing=5.0, SlitFunction=SLIT_TRIANGULAR ) import matplotlib.pyplot as plt plt.plot(nu, trans, 'b-', alpha=0.5, label='High-res') plt.plot(nu_conv, trans_conv, 'r-', label='Rectangular') plt.plot(nu_gauss, trans_gauss, 'g-', label='Gaussian') plt.xlabel('Wavenumber (cm-1)') plt.ylabel('Transmittance') plt.legend() plt.title('Effect of Slit Functions') plt.show() ``` -------------------------------- ### Save Database Changes with db_commit Source: https://context7.com/hitranonline/hapi/llms.txt Commits all changes made to the opened database, saving all tables to their corresponding files on disk. Ensure `db_begin()` has been called prior to using this function. ```python from hapi import * db_begin('spectral_data') # After making modifications to tables... # Save all changes to disk db_commit() ``` -------------------------------- ### Extract Column Data with getColumns Source: https://context7.com/hitranonline/hapi/llms.txt Retrieves specified columns from HITRAN data tables as Python lists or numpy arrays. Requires database initialization and data fetching. ```python from hapi import * db_begin('data') fetch('H2O', 1, 1, 1000, 1100) # Get single column wavenumbers = getColumns('H2O', ['nu']) # Get multiple columns nu, sw, gamma_air = getColumns('H2O', ['nu', 'sw', 'gamma_air']) # Use for plotting import matplotlib.pyplot as plt plt.semilogy(nu, sw, 'b.') plt.xlabel('Wavenumber (cm-1)') plt.ylabel('Line Intensity') plt.show() ``` -------------------------------- ### List Available Slit Functions Source: https://context7.com/hitranonline/hapi/llms.txt Enumerates the available slit function constants in HAPI. ```python from hapi import * # Available slit functions: # SLIT_RECTANGULAR - Boxcar function # SLIT_TRIANGULAR - Triangular function # SLIT_GAUSSIAN - Gaussian function # SLIT_DISPERSION - Lorentzian (dispersion) function # SLIT_COSINUS - Cosine function # SLIT_DIFFRACTION - Diffraction pattern # SLIT_MICHELSON - Michelson interferometer sinc function ``` -------------------------------- ### Calculate Voigt Absorption Coefficient Source: https://context7.com/hitranonline/hapi/llms.txt Calculates absorption coefficient using the Voigt profile, combining Doppler and Lorentzian broadening. Supports custom diluent mixtures and units. ```python from hapi import * db_begin('data') fetch('CO2', 2, 1, 2000, 2100) # Basic Voigt absorption coefficient calculation nu, coef = absorptionCoefficient_Voigt( SourceTables='CO2', Components=[(2, 1)], # CO2, main isotopologue Environment={'T': 296., 'p': 1.}, WavenumberRange=[2000, 2100], WavenumberStep=0.01, HITRAN_units=True # cm^2/molecule ) # With custom diluent mixture (70% N2, 30% self) nu, coef = absorptionCoefficient_Voigt( SourceTables='CO2', Components=[(2, 1)], Environment={'T': 300., 'p': 0.5}, WavenumberRange=[2050, 2070], WavenumberStep=0.001, Diluent={'air': 0.7, 'self': 0.3}, HITRAN_units=False # cm^-1 ) # Plot result import matplotlib.pyplot as plt plt.plot(nu, coef) plt.xlabel('Wavenumber (cm-1)') plt.ylabel('Absorption Coefficient') plt.title('CO2 Voigt Absorption') plt.show() ``` -------------------------------- ### Filter and Query Data with select Source: https://context7.com/hitranonline/hapi/llms.txt Filters table data using SQL-like conditions and optionally outputs to a new table or file. This function allows for precise selection of spectral lines based on various parameters and criteria. ```python from hapi import * db_begin('data') fetch('H2O', 1, 1, 1000, 1100) # Select lines with intensity greater than 1e-25 select('H2O', DestinationTableName='H2O_strong', Conditions=('>', 'sw', 1e-25)) # Select specific parameters with multiple conditions # Lines with nu between 1050-1060 cm-1 AND sw > 1e-26 select('H2O', DestinationTableName='H2O_filtered', ParameterNames=['nu', 'sw', 'gamma_air'], Conditions=('and', ('>', 'nu', 1050), ('<', 'nu', 1060), ('>', 'sw', 1e-26))) # Output to file select('H2O', File='h2o_lines.txt') ``` -------------------------------- ### getColumns Source: https://context7.com/hitranonline/hapi/llms.txt Retrieves one or more columns from a table as Python lists or numpy arrays. ```APIDOC ## getColumns ### Description Retrieves one or more columns from a table as Python lists or numpy arrays. ### Parameters #### Request Body - **molecule** (string) - Required - Name of the molecule - **columns** (list) - Required - List of column names to retrieve ### Request Example getColumns('H2O', ['nu', 'sw', 'gamma_air']) ``` -------------------------------- ### Calculate Doppler Profile Absorption Source: https://context7.com/hitranonline/hapi/llms.txt Calculates absorption using pure Gaussian broadening, suitable for low-pressure or high-temperature conditions. ```python from hapi import * db_begin('data') fetch('CO', 5, 1, 2100, 2200) # Doppler profile (low pressure regime) nu, coef = absorptionCoefficient_Doppler( SourceTables='CO', Components=[(5, 1)], # CO, main isotopologue Environment={'T': 1000., 'p': 0.001}, # High T, low p WavenumberRange=[2100, 2200], WavenumberStep=0.001, # Fine step for narrow Doppler lines HITRAN_units=True ) import matplotlib.pyplot as plt plt.plot(nu, coef) plt.xlabel('Wavenumber (cm-1)') plt.ylabel('Absorption Coefficient (cm²/molecule)') plt.title('CO Doppler Profile at 1000K') plt.show() ``` -------------------------------- ### Table Operations Source: https://context7.com/hitranonline/hapi/llms.txt Functions for inspecting and manipulating data tables within the HAPI database. ```APIDOC ## Table Operations ### describe - Display Table Information Prints detailed information about a table including parameter names, formats, number of rows, and wavenumber range. ```python from hapi import * db_begin('data') fetch('H2O', 1, 1, 1000, 1100) # Display table structure and metadata describe('H2O') # Output: # Name: H2O # Rows: 1234 # Wavenumber range: 1000.000 - 1100.000 cm-1 # Parameters: molec_id, local_iso_id, nu, sw, a, gamma_air, ... ``` ### tableList - Get Available Tables Returns a list of all tables currently loaded in the database cache. ```python from hapi import * db_begin('data') fetch('H2O', 1, 1, 1000, 1100) fetch('CO2', 2, 1, 2000, 2100) # Get list of all available tables tables = tableList() print("Tables:", tables) # Output: Tables: ['H2O', 'CO2'] ``` ### select - Filter and Query Data Filters table data using SQL-like conditions and optionally outputs to a new table or file. ```python from hapi import * db_begin('data') fetch('H2O', 1, 1, 1000, 1100) # Select lines with intensity greater than 1e-25 select('H2O', DestinationTableName='H2O_strong', Conditions=(">", 'sw', 1e-25)) # Select specific parameters with multiple conditions # Lines with nu between 1050-1060 cm-1 AND sw > 1e-26 select('H2O', DestinationTableName='H2O_filtered', ParameterNames=['nu', 'sw', 'gamma_air'], Conditions=('and', ('>', 'nu', 1050), ('<', 'nu', 1060), ('>', 'sw', 1e-26))) # Output to file select('H2O', File='h2o_lines.txt') ``` ``` -------------------------------- ### abundance Source: https://context7.com/hitranonline/hapi/llms.txt Returns the natural (Earth) abundance of a specified HITRAN isotopologue. ```APIDOC ## abundance ### Description Returns the natural (Earth) abundance of a specified HITRAN isotopologue. ### Parameters #### Request Body - **molecule_number** (int) - Required - HITRAN molecule number - **isotopologue_number** (int) - Required - HITRAN isotopologue number ### Request Example abundance(1, 1) ``` -------------------------------- ### absorptionCoefficient_Voigt Source: https://context7.com/hitranonline/hapi/llms.txt Calculates absorption coefficient using the Voigt line profile, which combines Doppler and Lorentzian broadening. ```APIDOC ## absorptionCoefficient_Voigt ### Description Calculates absorption coefficient using the Voigt line profile, which combines Doppler and Lorentzian broadening. ### Parameters #### Request Body - **SourceTables** (string) - Required - Name of the source table - **Components** (list) - Required - List of (molecule, isotopologue) tuples - **Environment** (dict) - Required - Dictionary containing 'T' (temperature) and 'p' (pressure) - **WavenumberRange** (list) - Required - [min, max] range - **WavenumberStep** (float) - Required - Step size - **HITRAN_units** (bool) - Optional - Whether to use cm^2/molecule units ### Request Example absorptionCoefficient_Voigt(SourceTables='CO2', Components=[(2, 1)], Environment={'T': 296., 'p': 1.}, WavenumberRange=[2000, 2100], WavenumberStep=0.01) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.