exojax.utils package

Submodules

exojax.utils.astrofunc module

Astronomical messy functions.

  • Astronomy is the oldest science in the world.

  • That’s why we need this module.

exojax.utils.astrofunc.gravity_jupiter(Rp, Mp)

gravity in cgs from radius and mass in the Jovian unit.

Parameters:
  • Rp – radius in the unit of Jovian radius

  • Mp – radius in the unit of Jovian mass

Returns:

gravity (cm/s2)

Note

Mpcgs=Mp*const.MJ, Rpcgs=Rp*const.RJ then gravity is given by (const.G*Mpcgs/Rpcgs**2)

exojax.utils.astrofunc.logg_jupiter(Rp, Mp)

logg from radius and mass in the Jovian unit.

Parameters:
  • Rp – radius in the unit of Jovian radius

  • Mp – radius in the unit of Jovian mass

Returns:

logg

Note

Mpcgs=Mp*const.MJ, Rpcgs=Rp*const.RJ, then logg is given by log10(const.G*Mpcgs/Rpcgs**2)

exojax.utils.checkarray module

exojax.utils.checkarray.is_outside_range(xarr, xs, xe)

Check if all elements in the array are outside the specified range.

Parameters:
  • xarr (numpy.ndarray) – An array of numerical values.

  • xs (float) – The start of the range (exclusive).

  • xe (float) – The end of the range (exclusive).

Returns:

True if all elements in xarr are outside the range (xs, xe), False otherwise.

Return type:

bool

Examples

>>> xarr = np.array([1.2, 1.4, 1.7, 1.3, 1.0])
>>> xs = 0.7
>>> xe = 0.8
>>> result = is_outside_range(xarr, xs, xe) #-> True
exojax.utils.checkarray.is_sorted(x)

Check if a list is sorted in ascending or descending order.

Parameters:

x – List to check.

Returns:

‘single’ if x is not list, but a single value ‘ascending’ if the list is sorted in ascending order, ‘descending’ if the list is sorted in descending order, ‘unordered’ otherwise.

exojax.utils.constants module

constants.

  • constants in cgs or km/s

  • Tref_original: reference temperature used in exojax.spec

exojax.utils.files module

exojax.utils.files.find_files_by_extension(directory_path, extension)

Finds all files with the given extension in the specified directory.

Parameters:
  • directory_path (str) – Path to the directory where to search for files.

  • extension (str) – File extension to search for. Include the dot, e.g., ‘.txt’.

Returns:

A list of paths to the files found with the specified extension.

Return type:

list

Examples

>>> directory_path = '/path/to/your/directory'
>>> extension = '.txt'
>>> files = find_files_by_extension(directory_path, extension)
exojax.utils.files.get_file_names_without_extension(file_paths)

Extracts the file names without extensions from a list of file paths.

Parameters:

file_paths (list) – A list of file paths as strings.

Returns:

A list of file names without extensions.

Return type:

list

Examples

>>> file_paths = ["/home/kawahara/A.txt", "/home/kawahara/B.txt"]
>>> file_names = get_file_names_without_extension(file_paths)
>>> print(file_names) # ["A", "B"]

exojax.utils.gpkernel module

Kernels used in Gaussian process.

exojax.utils.gpkernel.gpkernel_RBF(t, tau, a, err)

RBF kernel with diagnoal error.

Parameters:
  • t – variable vector (N)

  • tau – scale parameter (scalar)

  • a – amplitude (scalar)

  • err – diagnonal error vector (N)

Returns:

kernel

exojax.utils.grids module

generate various grids

exojax.utils.grids.check_eslog_wavenumber_grid(nus, crit1=1e-05, crit2=1e-14, gridmode='ESLOG')

checking if wavenumber_grid is evenly spaced in a logarithm scale (ESLOG) or a liner scale (ESLIN)

Parameters:
  • nus – wavenumber grid

  • crit1 – criterion for the maximum deviation of log10(nu)/median(log10(nu)) from ESLOG

  • crit2 – criterion for the maximum deviation of log10(nu) from ESLOG

  • gridmode – ESLOG or ESLIN

Returns:

True (wavenumber grid is ESLOG) or False (not)

exojax.utils.grids.check_scale_xsmode(xsmode)

checking if the scale of xsmode assumes ESLOG(log) or ESLIN(linear)

Parameters:

xsmode – xsmode

Returns:

ESLOG/ESLIN/UNKNOWN

exojax.utils.grids.delta_velocity_from_resolution(resolution)

delta velocity from spectral resolution R

Parameters:

resolution – spectral resolution

Note

See also [#294](https://github.com/HajimeKawahara/exojax/issues/294) and exojax/tests/figures/functions/delta_velocity_comp.py

Returns:

delta velocity

exojax.utils.grids.grid_resolution(grid_mode, nus)
exojax.utils.grids.velocity_grid(resolution, vmax)

generate velocity grid for a rigid rotation

Parameters:
  • resolution – spectral resolution

  • vmax – maximum velocity (or Vsini) allowed (km/s)

Returns:

delta velocity grid

Return type:

1D array

exojax.utils.grids.warn_resolution(resolution, crit=700000.0)

warning poor resolution.

Parameters:
  • resolution – spectral resolution

  • crit – critical resolution

exojax.utils.grids.wavenumber_grid(x0, x1, N, xsmode, wavelength_order='descending', unit='cm-1')

generating the recommended wavenumber grid based on the cross section computation mode.

Parameters:
  • x0 – start wavenumber (cm-1) or wavelength (nm) or (AA)

  • x1 – end wavenumber (cm-1) or wavelength (nm) or (AA)

  • N – the number of the wavenumber grid (even number)

  • xsmode – cross section computation mode (lpf, dit, modit, premodit)

  • order (wavlength) – wavelength order: “ascending” or “descending”

  • unit – unit of the input grid, “cm-1”, “nm”, or “AA”

Note

The wavenumber (nus) and wavelength (wav) grids are in ascending orders. Therefore, wav[-1] corresponds to the wavelength of nus[0]. ESLIN sets evenly-spaced linear grid in wavenumber space while ESLOG sets evenly-spaced log grid both in wavenumber and wavelength spaces.

Returns:

wavenumber grid evenly spaced in log space in ascending order (nus) wav: corresponding wavelength grid (AA) in ascending order (wav). wav[-1] corresponds to nus[0] resolution: spectral resolution

Return type:

nu_grid

exojax.utils.indexing module

index manipulation

  • (np)getix provides the contribution and index.

exojax.utils.indexing.find_or_add_index(new_index, index_array)

find a position of a new index in index_array, if not exisited add the new index in index_array

Parameters:
  • new_index – new index investigated

  • index_array – index array

Returns:

position, index_array updated

exojax.utils.indexing.getix(x, xv)

jnp version of getix.

Parameters:
  • x – x array

  • xv – x grid, should be ascending order

Returns:

cont (contribution) index (index)

Note

cont is the contribution for i=index+1. 1 - cont is the contribution for i=index. For other i, the contribution should be zero.

Example

>>> from exojax.utils.indexing import getix
>>> import jax.numpy as jnp
>>> y=jnp.array([1.1,4.3])
>>> yv=jnp.arange(6)
>>> getix(y,yv)
(DeviceArray([0.10000002, 0.3000002 ], dtype=float32), DeviceArray([1, 4], dtype=int32))
exojax.utils.indexing.npgetix(x, xv)

numpy version of getix.

Parameters:
  • x – x array

  • xv – x grid, should be ascending order

Returns:

cont (contribution) index (index)

Note

cont is the contribution for i=index+1. 1 - cont is the contribution for i=index. For other i, the contribution should be zero.

exojax.utils.indexing.uniqidx(input_array)

compute indices based on uniq values of the input M-dimensional array.

Parameters:

input_array – input array (N,M), will use unique M-dim vectors

Returns:

unique index, unique value

Examples

>>> a=np.array([[4,1],[7,1],[7,2],[7,1],[8,0],[4,1]])
>>> uidx, uval=uniqidx(a) #->[0,1,2,1,3,0], [[4,1],[7,1],[7,2],[8,0]]
exojax.utils.indexing.uniqidx_neibouring(index_array)

compute indices based on uniq values of the input index array and input index + one vector

Parameters:

index_array – input index array (N,M), will use unique M-dim vectors

Returns:

unique index (udix) neibouring index (nidx) for udix [N_uidx, 3] multi index as a function of nidx

exojax.utils.indexing.unique_rows(x)

memory saved version of np.unique(,axis=0)

Notes

Originally from a snippet/Answer #4 (https://discuss.dizzycoding.com/find-unique-rows-in-numpy-array/?amp=1)

Parameters:

x (2D array) – 2D array (N x M), need to be C-contiguous

Returns:

unique 2D array (N’ x M), where N’ <= N, removed duplicated M vector.

Return type:

2D array

exojax.utils.instfunc module

Utility Functions about Instruments.

exojax.utils.instfunc.R2STD(resolution)
exojax.utils.instfunc.nx_from_resolution_eslog(nu0, nu1, resolution)

Compute the number of wavenumber grid for a given resolution for ESLOG

Parameters:
  • nu0 (float) – wavenumber min

  • nu1 (float) – wavenumber max

  • resolution (float) – resolution

Returns:

the number of wavenumber grid for a given resolution

Return type:

int

exojax.utils.instfunc.resolution_eslin(nu)

min max spectral resolution for ESLIN.

Parameters:

nu – wavenumber bin

Returns:

min, approximate, max of the resolution

exojax.utils.instfunc.resolution_eslog(nu)

spectral resolution for ESLOG.

Parameters:

nu – wavenumber bin

Returns:

resolution

exojax.utils.instfunc.resolution_to_gaussian_std(resolution)

compute Standard deveiation of Gaussian velocity distribution from spectral resolution.

Parameters:

resolution – spectral resolution R

Returns:

standard deviation of Gaussian velocity distribution (km/s)

exojax.utils.interp module

multi d interpolation

exojax.utils.interp.interp2d_bilinear(x, y, xp, yp, fp)

2D bilinear interpolation

Parameters:
  • x (float ir 1D array) – x (or x array) you want know the value

  • y (float or 1D array) – y (or y array) you want know the value

  • xp (1D array) – x grid (x.size = M)

  • yp (1D array) – y grid (y.size = N)

  • fp (2D or nD array) – value grid (shape = (M,N) or (M,N,…))

Returns:

bilinear interpolated value(s) at (x,y)

Return type:

float or nD array

exojax.utils.isodata module

Mass number and abundance list.

exojax.utils.isodata.read_mnlist()

loading mass number list.

Note

this code reads data/atom/iso_mn.txt, taken from https://www.chem.ualberta.ca/~massspec/atomic_mass_abund.pdf The isotopic mass data is from G. Audi, A. H. Wapstra Nucl. Phys A. 1993, 565, 1-65 and G. Audi, A. H. Wapstra Nucl. Phys A. 1995, 595, 409-480. The percent natural abundance data is from the 1997 report of the IUPAC Subcommittee for Isotopic Abundance Measurements by K.J.R. Rosman, P.D.P. Taylor Pure Appl. Chem. 1999, 71, 1593-1607.

Returns:

dictionary of mass number, keys=”isotope”,”mass_number”,”abundance”

exojax.utils.isotopes module

Isotope

These are the same isotope of CO.

  • 16O-13C-17O (ExoMol)

  • (16O)(13C)(17O) (HITRAN)

  • 637 (HITRAN)

  • 6 (isotope number, defined in HITRAN_molparam.txt, starting from 1)

Notes

ExoJAX follows the definition of isotope number used in HITRAN, which starts from 1, but isotope_number = 0 implies the mean value of all of the isotopes.

exojax.utils.isotopes.get_isotope(atom, isolist)

get isotope info.

Parameters:
  • atom – simple atomic symbol, such as “H”, “Fe”

  • isolist – isotope list

Returns:

isotope list, such as “1H”, “2H” mass_number: mass_number list abundance: abundance list

Return type:

iso

exojax.utils.isotopes.get_stable_isotope(atom, isolist)

get isotope info.

Parameters:
  • atom – simple atomic symbol, such as “H”, “Fe”

  • isolist – isotope list

Returns:

stabel isotope such as “1H”, “2H” mass_number: mass_number abundance: abundance

Return type:

iso

exojax.utils.isotopes.molmass_hitran()

molar mass info from HITRAN_molparam.txt

Returns:

molmass_isotope, abundance_isotope

Return type:

dict

Examples

>>> path = pkgutil.get_data('exojax', 'data/atom/HITRAN_molparam.txt')
>>> mean_molmass, molmass_isotope, abundance_isotope = read_HITRAN_molparam(path)
>>> molmass_isotope["CO"][1] # molar mass for CO isotope number = 1
>>> abundance_isotope["CO"][1] # relative abundance for CO isotope number = 1
>>> molmass_isotope["CO"][0] # mean molar mass for CO

exojax.utils.jaxstatus module

exojax.utils.jaxstatus.check_jax64bit(allow_32bit)

check if the JAX precision mode is 64bit mode

Parameters:

allow_32bit (_type_) – exception to use 32bit mode. if True, just send warning message

Raises:

ValueError – _description_

exojax.utils.memuse module

exojax.utils.memuse.device_memory_use(opa, art=None, nfree=None, print_summary=True)

device memory use given opa and art (optional), n free parameters (optional)

Parameters:
  • opa (opa) – opa instance

  • art (art, optional) – art instance. Defaults to None.

  • nfree (int, optional) – the number of free parameters. Defaults to None.

  • print_summary (bool) – printing summary Defaults to True.

Raises:

ValueError – method not implemented yet

Returns:

estimated device memory use

Return type:

float

exojax.utils.memuse.premodit_devmemory_use(ngrid_nu_grid, ngrid_broadpar, ngrid_elower, nlayer=None, nfree=None, precision='FP64')

compute approximate required device memory for PreMODIT algorithm

Notes

This method estimates the major device moemory use for PreMODIT. In Case 0 (memcase=0), the use is limited by FFT/IFFT by modit_scanfft while in Case1 (memcase) by LBD.

Parameters:
  • ngrid_nu_grid (int) – the number of the wavenumber grid

  • ngrid_broadpar (int) – the number of the broadening parameter grid

  • ngrid_elower – (int): the number of the lower energy grid

  • nlayer (int, optional) – If not None (when computing spectrum), the number of the atmospheric layers. Defaults to None.

  • nfree (_type_, optional) – If not None (when computing an HMC or optimization), the number of free parameters. Defaults to None.

  • precision (str, optional) – precision of JAX mode FP32/FP64. Defaults to “FP64”.

Raises:

ValueError – _description_

Returns:

predicted required device memory (byte) (str, str): memory computation case (memcase), info

Return type:

float

exojax.utils.mollabel module

exojax.utils.mollabel.format_molecule(simple_molecule_name)

Format a given molecule string with subscript numbers and convert it to LaTeX syntax.

This function takes in a molecule string, where elements are represented by their symbols and the number of atoms is represented by a subscript number following the symbol. The function converts the molecule string to a LaTeX string, with subscript numbers formatted correctly and the string surrounded by LaTeX math mode and “mathrm” syntax.

Parameters:

molecule (str) – A string representation of a molecule.

Returns:

A LaTeX-formatted string representation of the molecule.

Return type:

str

Examples

>>> format_molecule("H2O")
"$\mathrm{H_2O}$"
>>> format_molecule("CH4")
"$\mathrm{CH_4}$"
>>> format_molecule("CO")
"$\mathrm{CO}$"
exojax.utils.mollabel.format_molecules_list(molecules)

Format a list of molecule strings with subscript numbers and convert them to LaTeX syntax.

This function takes in a list of molecule strings, where elements are represented by their symbols and the number of atoms is represented by a subscript number following the symbol. The function converts each molecule string to a LaTeX string, with subscript numbers formatted correctly and the string surrounded by LaTeX math mode and “mathrm” syntax.

Parameters:

molecules (list of str) – A list of string representations of molecules.

Returns:

A list of LaTeX-formatted string representations of the molecules.

Return type:

list of str

Examples

>>> format_molecules_list(["H2O", "CH4", "CO"])
["$\mathrm{H_2O}$", "$\mathrm{CH_4}$", "$\mathrm{CO}$"]
exojax.utils.mollabel.format_molecules_lists(molecules_lists)

Format a list of lists of molecule strings with subscript numbers and convert them to LaTeX syntax.

This function takes in a list of lists of molecule strings, where elements are represented by their symbols and the number of atoms is represented by a subscript number following the symbol. The function converts each molecule string to a LaTeX string, with subscript numbers formatted correctly and the string surrounded by LaTeX math mode and “mathrm” syntax.

Parameters:

molecules_lists (list of list of str) – A list of lists of string representations of molecules.

Returns:

A list of lists of LaTeX-formatted string representations of the molecules.

Return type:

list of list of str

Examples

>>> format_molecules_lists([["H2O", "CH4", "CO"], ["H2O", "CH4", "CO"]])
[["$\mathrm{H_2O}$", "$\mathrm{CH_4}$", "$\mathrm{CO}$"], ["$\mathrm{H_2O}$", "$\mathrm{CH4}$", "$\mathrm{CO}$"]]
exojax.utils.mollabel.molecule_color(simple_molecule_name)

return the individual matplotlib color label (CN) for a given molecule simple name

Parameters:

simple_molecule_name (str) – simple molecule name, “H2O”

Examples

>>> format_molecule_color("H2O")
"C1"
Returns:

CN label, such as C1 for “H2O” based on HITRAN identifier. If the molecule does not exist in the HITRAN identifiers, return gray

Return type:

str

exojax.utils.mollabel.molecules_color_list(simple_molecule_name_list)

return the individual matplotlib color label (CN) for a given molecule simple name list

Parameters:

simple_molecule_name_list (array) – simple molecule name list such as [“H2O”,”CO”]

Returns:

CN label, such as C1 for “H2O”

Return type:

str

exojax.utils.mollabel.molecules_color_lists(simple_molecule_name_lists)

exojax.utils.molname module

molecular name conversion

  • CO -> 12C-16O : simple_molname_to_exact_exomol_stable

  • (12C)(16O) -> 12C-16O : exact_molname_hitran_to_exomol

  • (12C)(16O) -> CO : exact_molname_hitran_to_simple_molname

  • 12C-16O -> (12C)(16O) : exact_molname_exomol_to_hitran

  • 12C-16O -> CO exact_molname_exomol_to_simple_molname

  • CO+isotope -> (12C)(16O) or 12C-16O :exact_exact_molecule_name_from_isotope

  • To get the recommended ExoMol database, use radis.api.exomolapi.get_exomol_database_list(“CO2”,”12C-16O2”)

exojax.utils.molname.e2s(exact_exomol_molecule_name)
exojax.utils.molname.exact_molecule_name_from_isotope(simple_molecule_name, isotope, dbtype='hitran')

exact isotope name from isotope (number)

Parameters:
  • simple_molecular_name (str) – simple molecular name such as CO

  • isotope (int) – isotope number starting from 1

  • dbtype (str) – “hitran” or “exomol”

Returns:

HITRAN exact isotope name such as (12C)(16O) for dbtype=”hitran”, 12C-16O for “exomol”

Return type:

str

exojax.utils.molname.exact_molecule_name_to_isotope_number(exact_molecule_name)

Convert exact molecule name to isotope number

Parameters:

exact_molecule_name (str) – exact exomol, hitran, molecule name such as 12C-16O, (12C)(16O)

Returns:

molecular number, isotope number (or None, None)

Return type:

int

exojax.utils.molname.exact_molname_exomol_to_hitran(exact_exomol_molecule_name)

Convert exact_molname used in ExoMol to those in HITRAN

Parameters:

exact_exomol_molecule_name (str) – exact exomol molecule name such as 12C-16O

Returns:

exact exomol molecule name such as (12C)(16O)

Return type:

str

exojax.utils.molname.exact_molname_exomol_to_simple_molname(exact_exomol_molecule_name)

convert the exact molname (used in ExoMol) to the simple molname.

Parameters:

exact_exomol_molecule_name – the exact exomol molecule name

Returns:

simple molname

Examples

>>> print(exact_molname_exomol_to_simple_molname("12C-1H4"))
>>> CH4
>>> print(exact_molname_exomol_to_simple_molname("23Na-16O-1H"))
>>> NaOH
>>> print(exact_molname_exomol_to_simple_molname("HeH_p"))
>>> HeH_p
>>> print(exact_molname_exomol_to_simple_molname("trans-31P2-1H-2H")) #not working
>>> Warning: Exact molname  trans-31P2-1H-2H cannot be converted to simple molname
>>> trans-31P2-1H-2H
exojax.utils.molname.exact_molname_hitran_to_exomol(exact_molecule_name_hitran)

Convert exact_molname used in HITRAN to those in ExoMol

Parameters:

exact_exomol_molecule_name (str) – exact exomol molecule name such as (12C)(16O)

Returns:

exact exomol molecule name such as 12C-16O

Return type:

str

exojax.utils.molname.exact_molname_hitran_to_simple_molname(exact_hitran_molecule_name)

convert exact hitran molname (16C)(13C)(17O) to simple molname, CO2.

Parameters:

exact_hitran_molecule_name (str) – exact_hitran_molecule_name, such as (16C)(13C)(17O)

Returns:

simple molecue name, such as CO2

Return type:

str

exojax.utils.molname.simple_molname_to_exact_exomol_stable(molname_simple)

convert the simple molname to the exact molname (used in ExoMol) using stable isotopes.

Parameters:

molname_simple – simple molname, such as CO

Returns:

exact exomol molecule name such as 12C-16O

exojax.utils.molname.split_simple(molname_simple)

split simple molname.

Parameters:

molname_simple – simple molname

Returns:

atom list number list

Example

>>> split_simple("Fe2O3")
>>> (['Fe', 'O'], ['2', '3'])

exojax.utils.progbar module

exojax.utils.progbar.print_progress(i, total_interation, desc='', bar_length=20)

print ptqdm like rogress bar

Parameters:
  • i (int) – step number starting from 0

  • total_interation (int) – total iteration number

  • desc (str) – description

  • bar_length (int, optional) – bar length. Defaults to 20.

exojax.utils.recexomol module

Get Recommendation from ExoMol.

exojax.utils.recexomol.get_exomol_database_list(molecule, isotope_full_name)

Parse ExoMol website and return list of available databases, and recommended database.

Parameters:
  • molecule – str

  • isotope_full_name – str, isotope full name (ex. 12C-1H4 for CH4,1). Get it from

Returns:

database list database recomendation

Example

databases, recommended = get_exomol_database_list(“CH4”, “12C-1H4”) >>> [‘xsec-YT10to10’, ‘YT10to10’, ‘YT34to10’], ‘YT34to10’

Note

This function is borrowed from radis (https://github.com/radis/radis by @erwanp). See https://github.com/radis/radis/issues/319 in detail.

exojax.utils.url module

url.

  • This module contains various url for downloading. Because url can be changed by the orner of the site, you might need to change it. Or, if you notice the change, it would be great if you send a pull-request.

exojax.utils.url.url_ExoMol()

return URL for ExoMol.

Returns:

URL for ExoMol db

exojax.utils.url.url_Exomol_iso(molecule, isotope_full_name)

return URL for ExoMol for isotope.

Returns:

URL for ExoMol for isotope

exojax.utils.url.url_HITEMP()

return URL for HITEMP bz2 parfile.

Returns:

URL for HITEMP bz2 file

exojax.utils.url.url_HITEMP10()

return URL for HITEMP2010.

Returns:

URL for HITEMP2010 db

exojax.utils.url.url_HITRAN12()

return URL for HITRAN 12 parfile.

Returns:

URL for HITRAN 12 parfile

exojax.utils.url.url_HITRANCIA()

return URL for HITRAN CIA ciafile.

Returns:

URL for HITRAN CIA file

exojax.utils.url.url_developer_data()

return URL for data in exojax.

Returns:

URL for ExoJAX

exojax.utils.url.url_virga()

return URL for VIRGA refractive index data from ZENODO

Returns:

URL for VIRGA refractive index data

exojax.utils.zsol module

solar abundance.

  • Solar abundance data

  • AAG21 = Asplund, M., Amarsi, A. M., & Grevesse, N. 2021, arXiv:2105.01661

exojax.utils.zsol.nsol(database='AAG21')

provide solar abundance dictionary.

Parameters:

database – name of database.

Returns:

number ratio of solar abundance

Example

>>>  nsun=nsol()
>>>  print(nsun["Fe"])
>>>  2.6602622265852853e-05

Module contents