### Install ExoJAX from GitHub Source Source: https://github.com/hajimekawahara/exojax/blob/master/documents/userguide/installation.rst Clone the ExoJAX repository and install it locally. This method is useful for development or when needing the latest unreleased features. ```sh git clone https://github.com/HajimeKawahara/exojax.git cd exojax pip install . ``` -------------------------------- ### Flux-based Reflection with No Emission (OpartReflectPure Setup) Source: https://github.com/hajimekawahara/exojax/blob/master/documents/userguide/rtransfer_fbased.rst Sets up the OpartReflectPure class for radiative transfer calculations, requiring a custom OpaLayer class. This example defines a basic OpaLayer with a specified wavenumber grid. ```python from exojax.opacity import OpaPremodit from exojax.rt import OpartReflectPure from exojax.rt.layeropacity import single_layer_optical_depth from exojax.utils.grids import wavenumber_grid from exojax.database.exomol.api import MdbExomol from exojax.utils.astrofunc import gravity_jupiter import jax.numpy as jnp from jax import config config.update("jax_enable_x64", True) class OpaLayer: # user defined class, needs to define self.nugrid def __init__(self, Nnus=100000): self.nu_grid, self.wav, self.resolution = wavenumber_grid( #1900.0, 2300.0, Nnus, unit="cm-1", xsmode="premodit" 2050.0, 2150.0, Nnus, unit="cm-1", xsmode="premodit" ``` -------------------------------- ### Install Specutils and JoviSpec Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/Fitting_Telluric_Lines.ipynb Install the necessary external packages, specutils and JoviSpec, using pip and by cloning the repository and running setup.py. ```sh pip install specutils git clone https://github.com/HajimeKawahara/jovispec.git cd jovispec python setup.py install ``` -------------------------------- ### Initial Installation Attempt Source: https://github.com/hajimekawahara/exojax/wiki/Error-about-yaml This command attempts to install exojax, which may lead to a PyYAML version error if an incompatible version is already present. ```sh python setup.py install ``` -------------------------------- ### Install ExoJAX from PyPI Source: https://github.com/hajimekawahara/exojax/blob/master/documents/userguide/installation.rst Use this command to install the latest stable version of ExoJAX from the Python Package Index. ```sh pip install exojax ``` -------------------------------- ### Build Documentation Source: https://github.com/hajimekawahara/exojax/blob/master/CLAUDE.md Build the HTML documentation using Sphinx. Ensure you are in the 'documents' directory and have Sphinx installed. ```bash cd documents && make clean && make html ``` -------------------------------- ### Import ExoJAX and Setup Precision Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/ckd_transpure.ipynb Imports necessary libraries for ExoJAX, including modules for opacity, radiative transfer, and testing. Enables 64-bit precision for calculations. ```python # Import required packages import numpy as np import matplotlib.pyplot as plt from jax import config # ExoJAX imports from exojax.test.emulate_mdb import mock_mdbExomol, mock_wavenumber_grid from exojax.opacity import OpaCKD, OpaPremodit from exojax.rt import ArtTransPure from exojax.test.data import get_testdata_filename, TESTDATA_CO_EXOMOL_PREMODIT_TRANSMISSION_REF # Enable 64-bit precision for accurate calculations config.update("jax_enable_x64", True) print("ExoJAX CKD Tutorial: Transmission Spectroscopy") print("=============================================") ``` -------------------------------- ### Set up Stochastic Variational Inference (SVI) Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/Differentiable_Programming.ipynb Initialize SVI with a guide, optimizer, and loss function. This is used for Bayesian inference when gradients are available. ```python from numpyro.infer import SVI from numpyro.infer import Trace_ELBO import numpyro.optim as optim from numpyro.infer.autoguide import AutoMultivariateNormal guide = AutoMultivariateNormal(model) optimizer = optim.Adam(0.01) svi = SVI(model, guide, optimizer, loss=Trace_ELBO()) ``` -------------------------------- ### Initialize Atmospheric and Instrumental Parameters Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/Reverse_modeling_for_methane_using_MODIT.rst Sets up atmospheric pressure layers, wavenumber grid, and instrumental spectral resolution. ```ipython3 from exojax.rt.rtransfer import pressure_layer,wavenumber_grid from exojax.utils.constants import c from exojax.utils.instfunc import resolution_to_gaussian_std NP=100 Parr, dParr, k=pressure_layer(NP=NP) Nx=5000 nus,wav,res=wavenumber_grid(np.min(wavd)-5.0,np.max(wavd)+5.0,Nx,unit="AA",xsmode="modit") Rinst=100000. #instrumental spectral resolution beta_inst=resolution_to_gaussian_std(Rinst) #equivalent to beta=c/(2.0*np.sqrt(2.0*np.log(2.0))*R) ``` -------------------------------- ### Troubleshooting Missing libcudnn.so.7 Source: https://github.com/hajimekawahara/exojax/wiki/Error-about-DNN If the error message mentions 'libcudnn.so.7', verify that this specific version is installed and accessible. This snippet shows an example of such an error message. ```sh 2021-08-15 12:06:46.013903: W external/org_tensorflow/tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudnn.so.7'; dlerror: libcudnn.so.7: cannot open shared object file: No such file or directory; ``` -------------------------------- ### Load ExoMol Database and Create OpaPremodit Source: https://github.com/hajimekawahara/exojax/blob/master/documents/userguide/history.rst Demonstrates how to load an ExoMol database and initialize OpaPremodit with specific parameters for auto-ranging, broadening resolution, and memory policy. ```python from exojax.database.exomol.api import MdbExomol from exojax.opacity.premodit.api import OpaPremodit from exojax.opacity.policies import MemoryPolicy mdb = MdbExomol(".database/CO/12C-16O/Li2015", nu_grid) opa = OpaPremodit.from_mdb( mdb, nu_grid, auto_trange=(500,1500), broadening_resolution={"mode":"manual","value":0.2}, memory_policy=MemoryPolicy(allow_32bit=True, nstitch=2) ) xs = opa.xsvector(T=1200.0, P=0.1) # or opa.xsmatrix(Tarr, Parr) ``` -------------------------------- ### Check Installed Version Source: https://github.com/hajimekawahara/exojax/blob/master/CLAUDE.md Verify the installed version of ExoJAX. This is useful for confirming installation and compatibility. ```python import exojax print(exojax.__version__) ``` -------------------------------- ### Set up and Run frun with Specific Parameters Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/reverse_premodit.rst Initializes parameters and calls the `frun` function to generate a test spectrum. ```python import matplotlib.pyplot as plt #g = gravity_jupiter(0.88, 33.2) Rp = 0.88 Mp = 33.2 alpha = 0.1 MMR_CH4 = 0.0059 vsini = 20.0 RV = 10.0 T0 = 1200.0 u1 = 0.0 u2 = 0.0 Tarr = art.powerlaw_temperature(T0, alpha) Ftest = frun(Tarr, MMR_CH4, Mp, Rp, u1, u2, RV, vsini) ``` -------------------------------- ### Setting up Opacity Calculator with HITRAN and PreMODIT Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/Fitting_Telluric_Lines.ipynb Initializes an opacity calculator using HITRAN molecular database and the PreMODIT method. This is suitable for low-temperature environments. Ensure the nu_grid is correctly defined. ```python wavelength_start = 7100.0 # AA wavelength_end = 7450.0 # AA from exojax.database.api import MdbHitran from exojax.opacity import OpaDirect from exojax.opacity import OpaPremodit from exojax.utils.grids import wavenumber_grid from exojax.utils.grids import wav2nu N = 40000 margin = 10 # cm-1 nus_start = wav2nu(wavelength_end, unit="AA") - margin nus_end = wav2nu(wavelength_start, unit="AA") + margin #nus_start = 1.e8/wavelength_end - margin #nus_end = 1.e8/wavelength_start + margin mdb_water = MdbHitran("H2O", nurange=[nus_start, nus_end], isotope=1) nus, wav, res = wavenumber_grid(nus_start, nus_end, N, xsmode="lpf", unit="cm-1") # opa = OpaDirect(mdb_water, nu_grid=nus) opa = OpaPremodit(mdb_water, nu_grid=nus, allow_32bit=True, auto_trange=[150.0, 300.0]) ``` -------------------------------- ### Install CUDA 11.5 and cuDNN on Ubuntu Source: https://github.com/hajimekawahara/exojax/wiki/installing-or-updating-JAX Use aptitude to install CUDA 11.5 and dpkg to install a local cuDNN repository. This is a prerequisite for installing JAX with specific CUDA/cuDNN versions. ```shell sudo aptitude install cuda-11-5 sudo dpkg -i cudnn-local-repo-ubuntu2004-8.3.1.22_1.0-1_amd64.deb ``` -------------------------------- ### Initialize AutoMultivariateNormal Guide Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/get_started_svi.ipynb Initializes the AutoMultivariateNormal guide for a given model. This guide is suitable for models where latent variables can be approximated by a multivariate normal distribution. ```python from numpyro.infer.autoguide import AutoMultivariateNormal guide = AutoMultivariateNormal(model_prob) optimizer = optim.Adam(0.01) svi = SVI(model_prob, guide, optimizer, loss=Trace_ELBO()) ``` -------------------------------- ### Initialize Wavenumber Grid and Molecular Database Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/elower_setting.ipynb Sets up the wavenumber grid and loads the Exomol molecular database. Ensure the database path is correct and the wavenumber grid is in ascending order. ```python from exojax.utils.grids import wavenumber_grid from exojax.database.exomol.api import MdbExomol nu_grid, wav, resolution = wavenumber_grid(2200., 2300., 10000, unit="cm-1", xsmode="premodit") mdb = MdbExomol(".database/CO/12C-16O/Li2015", nurange=nu_grid) ``` -------------------------------- ### Initialize AutoBNAFNormal Guide Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/get_started_svi.rst Initialize the AutoBNAFNormal guide for a given probabilistic model. This guide uses Block Neural Autoregressive Flow (BNAF) for more flexible dependency modeling. ```ipython3 from numpyro.infer.autoguide import AutoBNAFNormal guide = AutoBNAFNormal(model_prob) optimizer = optim.Adam(0.01) svi = SVI(model_prob, guide, optimizer, loss=Trace_ELBO()) ``` -------------------------------- ### Setup Wavenumber Grid, Molecular Database, and Atmospheric Model Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/ckd_emispure.rst Sets up a mock wavenumber grid, creates a mock H2O molecular database, and initializes the ArtEmisPure atmospheric radiative transfer solver with specified pressure and layer parameters. ```python # Setup wavenumber grid and molecular database nu_grid, wav, res = mock_wavenumber_grid() print(f"Wavenumber grid: {len(nu_grid)} points from {nu_grid[0]:.1f} to {nu_grid[-1]:.1f} cm⁻¹") print(f"Spectral resolution: {res:.1f}") # Create mock H2O molecular database mdb = mock_mdbExomol("H2O") print(f"Molecular database: {mdb.nurange[0]:.1f} - {mdb.nurange[1]:.1f} cm⁻¹") # Setup atmospheric radiative transfer art = ArtEmisPure( pressure_top=1.0e-8, pressure_btm=1.0e2, nlayer=100, nu_grid=nu_grid ) print(f"Atmospheric layers: {art.nlayer}") print(f"Pressure range: {art.pressure_top:.1e} - {art.pressure_btm:.1e} bar") ``` -------------------------------- ### Install NumPyro with CUDA Support Source: https://github.com/hajimekawahara/exojax/wiki/Installation-on-py3.9-conda-for-v2.0 Installs NumPyro version 0.13.2 with CUDA support from a specific URL. Ensure your system has compatible NVIDIA drivers and CUDA toolkit installed. ```shell pip install numpyro[cuda]==0.13.2 -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html ``` -------------------------------- ### Resolving PyYAML Version Conflict Source: https://github.com/hajimekawahara/exojax/wiki/Error-about-yaml This command installs the latest PyYAML version while ignoring the currently installed one, resolving the dependency conflict. It is followed by the exojax installation command. ```sh pip install pyyaml --ignore-installed PyYAML python setup.py install ``` -------------------------------- ### Sample Posterior Parameters with AutoBNAFNormal Guide Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/get_started_svi.rst Sample posterior parameters using the trained AutoBNAFNormal guide. This is similar to the initial parameter sampling but uses the guide optimized by SVI. ```ipython3 predictive_posterior = Predictive( model_prob, guide=guide, params=params, num_samples=2000, return_sites=param_entries, ) posterior_sample = predictive_posterior(rng_key, spectrum=None) ``` -------------------------------- ### Install Core ExoJAX Dependencies Source: https://github.com/hajimekawahara/exojax/wiki/Installation-on-py3.9-conda-for-v2.0 Installs essential Python packages for ExoJAX, including astroquery, vaex-astro, msgpack, ndindex, pybind11, vaex, cython, and shapely. Also installs pytest for testing. ```shell pip install astroquery vaex-astro msgpack ndindex pybind11 vaex cython shapely pytest ``` -------------------------------- ### Install Sphinx Dependencies Source: https://github.com/hajimekawahara/exojax/blob/master/documents/developers/doc.rst Installs the required Sphinx themes and emoji support for documentation. ```sh pip install sphinx_rtd_theme sphinxemoji ``` -------------------------------- ### Install JAX with CUDA 11.5 and cuDNN 8.2 Source: https://github.com/hajimekawahara/exojax/wiki/installing-or-updating-JAX Uninstall any existing JAX installation and then install the specific JAX version compatible with CUDA 11.5 and cuDNN 8.2 using pip. The -f flag specifies the release URL. ```shell pip uninstall jax pip install "jax[cuda11_cudnn82]" -f https://storage.googleapis.com/jax-releases/jax_releases.html ``` -------------------------------- ### Setting up spectral model components Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/Reverse_modeling_for_methane_using_MODIT.rst Initializes components for spectral modeling, including exomol for line data, xsmatrix for cross-section matrices, and velocity grids for spectral resolution. ```python from exojax.opacity.modit.modit import exomol,xsmatrix from exojax.rt.rtransfer import dtauM, dtauCIA, rtrun from exojax.rt import planck, response from exojax.postproc.response import ipgauss_sampling from exojax.postproc.spin_rotation import convolve_rigid_rotation from exojax.utils.grids import velocity_grid vsini_max = 100.0 vr_array = velocity_grid(res, vsini_max) ``` -------------------------------- ### Initial Parameter Setup and Spectrum Calculation Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/Reverse_modeling_with_VALD_using_MODIT.ipynb Sets up initial atmospheric parameters and calculates a synthetic spectrum using the `frun` function. This is useful for comparing model predictions with observed data. ```python T0 = 3000. alpha = 0.07 Mp=0.155 *1.99e33/1.90e30 Rp=0.186 *6.96e10/6.99e9 u1=0.0 u2=0.0 RV=0.00 vsini=2.0 mmw=2.33 log_e_H = -4.2 VMR_H = 0.09 VMR_H2 = 0.77 VMR_FeH = 10**-8 VMR_H2O = 10**-4 VMR_OH = 10**-4 VMR_TiO = 10**-8 A_Fe = 1.5 A_Ti = 1.2 adjust_continuum = 0.99 mu = frun(T0, alpha, Mp, Rp, u1, u2, RV, vsini, \ mmw, log_e_H, VMR_H, VMR_H2, \ VMR_FeH, VMR_H2O, VMR_OH, VMR_TiO, \ A_Fe, A_Ti, adjust_continuum) plt.figure(figsize = (10, 3)) plt.plot(wavd[::-1], nflux, label = "observed data") plt.plot(wavd[::-1], mu, label="frun", ls='--') plt.legend(); plt.grid(); plt.ylim(0.1, 1.05) plt.show() ``` -------------------------------- ### Set up Wavenumber Grid and Atmosphere Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/jupiters/Jupiter_cloud_model_using_amp.ipynb Initializes the wavenumber grid and atmospheric parameters for reflection modeling. Ensure the wavenumber grid is in ascending order. ```python from exojax.utils.grids import wavenumber_grid N = 10000 nus, wav, res = wavenumber_grid(10**3, 10**4, N, xsmode="premodit") from exojax.rt import ArtReflectPure from exojax.utils.astrofunc import gravity_jupiter art = ArtReflectPure(nu_grid=nus, pressure_btm=1.0e2, pressure_top=1.0e-3, nlayer=100) art.change_temperature_range(80.0, 400.0) Tarr = art.powerlaw_temperature(150.0, 0.2) Parr = art.pressure mu = 2.3 # mean molecular weight gravity = gravity_jupiter(1.0, 1.0) ``` -------------------------------- ### Install JAX CPU Version Source: https://github.com/hajimekawahara/exojax/blob/master/documents/userguide/installation.rst Installs the CPU-only version of JAX. Use this if you do not have a compatible GPU or do not require GPU acceleration. ```sh pip install --upgrade jax ``` -------------------------------- ### Install JAX with CUDA 11 Support Source: https://github.com/hajimekawahara/exojax/blob/master/documents/userguide/installation.rst Installs JAX with support for CUDA 11. Ensure your CUDA toolkit is compatible. ```sh pip install --upgrade "jax[cuda11]" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html ``` -------------------------------- ### Initialize Cloud Model and Load Data Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/jupiters/Jupiter_Hires_Modeling.ipynb Initializes the PdbCloud for ammonia and sets up an atmospheric model with background gas. It also checks the temperature range and prepares for condensate calculations. ```python from exojax.database.pardb import PdbCloud from exojax.atm.atmphys import AmpAmcloud pdb_nh3 = PdbCloud("NH3") amp_nh3 = AmpAmcloud(pdb_nh3, bkgatm="H2") amp_nh3.check_temperature_range(Tarr) ``` -------------------------------- ### Install JAX with CUDA 12 Support Source: https://github.com/hajimekawahara/exojax/blob/master/documents/userguide/installation.rst Installs JAX with support for CUDA 12. Ensure your CUDA toolkit is compatible. ```sh pip install --upgrade "jax[cuda12]" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html ``` -------------------------------- ### Initialize Wavenumber Grid and Load CH4 Database (Exomol) Source: https://github.com/hajimekawahara/exojax/blob/master/documents/analysis/freq_elower.ipynb Sets up a wavenumber grid and loads the CH4 molecular database from Exomol. Ensure the database path is correct for your system. ```python from exojax.database.exomol.api import MdbExomol from exojax.utils.grids import wavenumber_grid import numpy as np nus, wav, r = wavenumber_grid(16370, 16390, 20000, unit="AA",xsmode="premodit") mdbCH4 = MdbExomol("/home/kawahara/.database/CH4/12C-1H4/YT34to10/",nus) ``` -------------------------------- ### Install libcst for Script Source: https://github.com/hajimekawahara/exojax/blob/master/documents/userguide/history.rst Install the libcst library to run the script for updating import statements. Ensure you back up your files before execution. ```sh pip install libcst ``` -------------------------------- ### CH4 Setting (PREMODIT) Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/reverse_premodit.ipynb Initializes the Exomol database for CH4 and sets up the OpaPremodit object for spectral calculations. Ensure the database path is correct and the nu_grid is defined. ```python mdb = MdbExomol('.database/CH4/12C-1H4/YT10to10/', nurange=nu_grid, gpu_transfer=False) print('N=', len(mdb.nu_lines)) diffmode = 0 opa = OpaPremodit(mdb=mdb, nu_grid=nu_grid, diffmode=diffmode, auto_trange=[Tlow, Thigh], dit_grid_resolution=1.0,allow_32bit=True) ``` -------------------------------- ### Minimal OpaPremodit Example (ExoMol) Source: https://github.com/hajimekawahara/exojax/blob/master/documents/userguide/opacity_di.rst Builds OpaPremodit opacity from a snapshot or directly from an mdb. Use `from_snapshot` to avoid dependencies on concrete mdb classes, or `from_mdb` for legacy usage. ```python from exojax.database.exomol.api import MdbExomol from exojax.opacity import OpaPremodit from exojax.utils.grids import wavenumber_grid # Make a grid and load an mdb nu_grid, _, _ = wavenumber_grid(4200.0, 4300.0, 20000, xsmode="premodit") mdb = MdbExomol(".database/CO/12C-16O/Li2015", nurange=nu_grid) # 1) Build from a snapshot (data-only DTO) snap = mdb.to_snapshot() opa1 = OpaPremodit.from_snapshot( snap, nu_grid, manual_params=(5.0, 1000.0, 1200.0) ) # 2) Back-compat: build directly from an mdb opa2 = OpaPremodit.from_mdb( mdb, nu_grid, manual_params=(5.0, 1000.0, 1200.0) ) ``` -------------------------------- ### Initialize plotting and get VIRGA gas recommendations Source: https://github.com/hajimekawahara/exojax/blob/master/documents/userguide/amclouds_comparison_virga.ipynb Sets up the Bokeh plotting environment for notebooks and uses VIRGA's `recommend_gas` function to determine relevant gases for the given atmospheric conditions. ```python from bokeh.io import output_notebook from bokeh.plotting import show, figure from bokeh.palettes import Colorblind output_notebook() metallicity = 1 #atmospheric metallicity relative to Solar #get virga recommendation for which gases to run recommended = jdi.recommend_gas(pressure, temperature, metallicity,mu, #Turn on plotting plot=True) #print the results print(recommended) ``` -------------------------------- ### Install Conda-Managed Libraries Source: https://github.com/hajimekawahara/exojax/wiki/Installation-on-py3.9-conda-for-v2.0 Installs HDF5, pytables, and GEOS using Conda-Forge. These are often required for data handling and geospatial operations. ```shell conda install -c conda-forge hdf5 pytables geos ``` -------------------------------- ### Initialize Wavenumber Grid and Opacity Database Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/jupiters/Jupiter_Hires_Modeling.ipynb Sets up the wavenumber grid and loads the Hitran database for H2O opacity. Ensure wavelength units are correctly converted to wavenumbers. ```python from exojax.database.api import MdbHitran from exojax.opacity import OpaDirect from exojax.opacity import OpaPremodit from exojax.utils.grids import wavenumber_grid from exojax.utils.grids import wav2nu N = 40000 margin = 10 # cm-1 nus_start = wav2nu(wavelength_end, unit="AA") - margin nus_end = wav2nu(wavelength_start, unit="AA") + margin mdb_water = MdbHitran("H2O", nurange=[nus_start, nus_end], isotope=1) nus, wav, res = wavenumber_grid(nus_start, nus_end, N, xsmode="lpf", unit="cm-1") opa_telluric = OpaPremodit(mdb_water, nu_grid=nus, allow_32bit=True, auto_trange=[80.0, 400.0]) ``` -------------------------------- ### Downloading ExoMol Transition Files Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/Comparing_HITEMP_and_ExoMol.rst This snippet demonstrates downloading transition files for a specific molecule and isotopologue from ExoMol. It also mentions the caching mechanism for faster subsequent downloads and the option to delete the compressed file. ```text Molecule: CO Isotopologue: 12C-16O ExoMol database: None Local folder: CO/12C-16O/Li2015 Transition files: => File 12C-16O__Li2015.trans Total download size ['12C-16O__Li2015.trans.bz2'] is: 0.001307 GB => Downloading from https://www.exomol.com/db/CO/12C-16O/Li2015/12C-16O__Li2015.trans.bz2 => Caching the *.trans.bz2 file to the vaex (*.h5) format. After the second time, it will become much faster. => You can deleted the 'trans.bz2' file by hand. Broadener: H2 Broadening code level: a0 ``` -------------------------------- ### Clone and Install JoviSpec Repository Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/jupiters/Jupiter_Hires_Modeling_Exomol.ipynb Instructions to clone the JoviSpec repository from GitHub and install it locally. This is necessary to access Jupiter spectral data. ```shell git clone https://github.com/HajimeKawahara/jovispec.git python setup.py install ``` -------------------------------- ### Install with Pip in Development Mode Source: https://github.com/hajimekawahara/exojax/blob/master/CLAUDE.md Alternative method to install the package in development mode using pip. This is a common practice for Python projects. ```bash pip install -e . ``` -------------------------------- ### Set Up Initial Guess for Fitting Parameters Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/Fitting_Telluric_Lines.ipynb Defines the initial guess for fitting parameters including temperature, pressure, column density, continuum, and instrumental broadening. Requires exojax.utils.instfunc and numpy. ```python from exojax.utils.instfunc import resolution_to_gaussian_std T_b = 200.0 P_b = 0.5 nl_b = 2.0e22 a_b = 0.52 Rinst = 100000.0 beta_inst_b = resolution_to_gaussian_std(Rinst) initial_guess = np.array([T_b, P_b, nl_b, a_b, beta_inst_b]) initpar = np.ones_like(initial_guess) ``` -------------------------------- ### Initialize PreMOLIT Opacity Calculator Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/jupiters/Jupiter_Hires_Modeling.ipynb Initializes the PreMOLIT opacity calculator with the reduced methane data. This method is memory-efficient and suitable for high-resolution spectra. ```python opa = OpaPremodit(mdb_reduced, nu_grid=nus, allow_32bit=True, auto_trange=[80.0, 300.0]) #this reduced the device memory use in 5/6. ``` -------------------------------- ### Verify JAX sparse module import in Python Source: https://github.com/hajimekawahara/exojax/wiki/installing-or-updating-JAX After installation, verify that the JAX sparse module can be imported successfully within a Python interpreter. This confirms the installation and CUDA/cuDNN compatibility. ```python from jax.experimental.sparse import coo ``` -------------------------------- ### Initialize PreMoidit Opacity with Mock Data Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/ckd_principle.rst This snippet demonstrates how to initialize the OpaPremodit class using mock molecular database and wavenumber grid data. It sets up the opacity object for a specific molecule (H2O) and wavenumber range, with automatic temperature range handling. ```python from exojax.test.emulate_mdb import mock_mdbExomol, mock_wavenumber_grid from exojax.opacity.premodit.api import OpaPremodit from exojax.opacity.ckd.api import OpaCKD from exojax.opacity.ckd.core import compute_g_ordinates import jax.numpy as jnp import matplotlib.pyplot as plt from jax import config config.update("jax_enable_x64", True) nus, wav, res = mock_wavenumber_grid(lambda0=22930.0, lambda1=22940.0, Nx=20000) mdb = mock_mdbExomol("H2O") opa = OpaPremodit(mdb, nus, auto_trange=[500.0, 1500.0]) ``` -------------------------------- ### Installing cuDNN for Exojax Source: https://github.com/hajimekawahara/exojax/wiki/Error-about-DNN This command sequence provides instructions for installing cuDNN, including copying library files and headers to the appropriate CUDA directories. This is a common solution for cuDNN version mismatch errors. ```sh tar xvfz cudnn-10.1-linux-x64-v7.6.5.32.tgz sudo cp cuda/lib64/libcudnn* /usr/local/cuda/targets/x86_64-linux/lib/ sudo cp cuda/include/cudnn*.h /usr/local/cuda/include sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64 sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn* ``` -------------------------------- ### Set up T-P profile and partial pressures Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/Forward_modeling_for_Fe_I_lines_of_Kurucz.rst Initializes an atmospheric model with a specified number of layers and defines temperature and pressure profiles. It also calculates partial pressures for different gas species. ```ipython3 from exojax.rt import ArtEmisPure nlayer = 100 T0 = 3000.0 # 10000. #3000. #1295.0 #K alpha = 0.1 Tlow = 500.0 Thigh = 4500.0 art = ArtEmisPure(nu_grid=nu_grid, pressure_top=1.e-8, pressure_btm=1.e2, nlayer=nlayer) art.change_temperature_range(Tlow, Thigh) Tarr = art.powerlaw_temperature(T0, alpha) Parr = art.pressure dParr = art.dParr H_He_HH_VMR = [0.0, 0.16, 0.84] # typical quasi-"solar-fraction" PH = Parr * H_He_HH_VMR[0] PHe = Parr * H_He_HH_VMR[1] PHH = Parr * H_He_HH_VMR[2] fig = plt.figure(figsize=(6, 4)) plt.plot(Tarr, Parr, label="$P_\mathrm{total}$") plt.plot(Tarr, PH, "--", label="$P_\mathrm{H}$") plt.plot(Tarr, PHH, "--", label="$P_\mathrm{H_2}$") plt.plot(Tarr, PHe, "--", label="$P_\mathrm{He}$") plt.plot(Tarr[80], Parr[80], marker="*", markersize=15) plt.yscale("log") plt.xlabel("temperature (K)") plt.ylabel("pressure (bar)") plt.gca().invert_yaxis() plt.legend() plt.show() ``` -------------------------------- ### Chemical Setup and Species Indexing Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/equilibrium_chemistry.rst Sets up chemical equilibrium calculations using `chemsetup` from `exogibbs.presets.fastchem`. It prints the indices and JANAF names for CO and H2, and lists the available elements. ```ipython3 from exogibbs.presets.fastchem import chemsetup # chemical setup chem = chemsetup() idx_co = chem.species.index("C1O1") print("idx for CO=",idx_co, "JANAF name", chem.species[idx_co]) # check index of CO idx_h2 = chem.species.index("H2") print("idx for H2=",idx_h2, "JANAF name", chem.species[idx_h2]) # check index of H2 print("element:", chem.elements) ``` -------------------------------- ### Initialize and Setup CKD Opacity Calculator Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/ckd_emispure.rst Sets up the Correlated-k (CKD) opacity calculator using a base opacity calculator. It configures parameters like the number of g-ordinates and spectral band width. The setup also includes printing the calculator's configuration details. ```python # Initialize CKD opacity calculator opa_ckd = OpaCKD( base_opa, # Base opacity calculator Ng=32, # Number of g-ordinates for quadrature band_width=0.5 # Spectral band width ) print(f"CKD Opacity Calculator Setup:") print(f" Number of g-ordinates (Ng): {opa_ckd.Ng}") print(f" Band width: {opa_ckd.band_width}") print(f" Number of spectral bands: {len(opa_ckd.nu_bands)}") print(f" Spectral range: {opa_ckd.nu_bands[0]:.1f} - {opa_ckd.nu_bands[-1]:.1f} cm⁻¹") ``` -------------------------------- ### Get Molecular Mass Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/Forward_modeling_using_PreMODIT.ipynb Retrieves the molecular mass of CO from the loaded database. ```python molmassCO=mdbCO.molmass ``` -------------------------------- ### Initialize ExoMol with Optional Quantum States Source: https://github.com/hajimekawahara/exojax/blob/master/documents/userguide/api.rst Illustrates initializing an ExoMol database with optional quantum states enabled and activation turned off. This setup is necessary for filtering lines based on vibrational or electronic states using the DataFrame. ```ipython >>> from exojax.utils.grids import wavenumber_grid >>> from exojax.database.exomol.api import MdbExomol >>> >>> nus, wav, res = wavenumber_grid(24000.0, 26000.0, 1000, unit="AA") >>> mdb =MdbExomol("CO/12C-16O/Li2015/", nus, optional_quantum_states=True, activation=False) ``` -------------------------------- ### Get Molecular Mass Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/Forward_modeling_using_the_DIT_Cross_Section_for_methane.ipynb Fetches the molecular mass for CH4 using the molinfo module. ```python from exojax.database import molinfo molmassCH4=molinfo.molmass("CH4") ``` -------------------------------- ### Initialize Cloud and Microphysics Models Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/jupiters/Jupiter_cloud_model_using_amp.ipynb Sets up the particulate database for NH3 clouds and the atmospheric microphysics model (AM01). Ensure the temperature range of the atmosphere is compatible with the cloud model. ```python from exojax.database.pardb import PdbCloud from exojax.atm.atmphys import AmpAmcloud pdb_nh3 = PdbCloud("NH3") #pdb_nh3.generate_miegrid() # when you use the miegrid #pdb_nh3.load_miegrid() # when you use the miegrid amp_nh3 = AmpAmcloud(pdb_nh3,bkgatm="H2") amp_nh3.check_temperature_range(Tarr) ``` -------------------------------- ### Define Wavelength Range Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/jupiters/Jupiter_Hires_Modeling.ipynb Sets the start and end wavelengths for spectral analysis in Angstroms. ```python wavelength_start = 8500.0 #AA wavelength_end = 8800.0 #AA ``` -------------------------------- ### Plot Temperature-Pressure Profile Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/Forward_modeling.ipynb Visualizes the generated temperature-pressure profile. Ensure matplotlib is installed for plotting. ```python import matplotlib.pyplot as plt plt.plot(Tarr,Parr) plt.yscale("log") plt.gca().invert_yaxis() plt.show() ``` -------------------------------- ### CH4 Setting (PREMODIT) Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/reverse_premodit.rst Initializes the MdbExomol database and OpaPremodit for CH4 opacity calculations. Ensure the database path is correct and specify the desired nu_grid. ```ipython3 ### CH4 setting (PREMODIT) mdb = MdbExomol('.database/CH4/12C-1H4/YT10to10/', nurange=nu_grid, gpu_transfer=False) print('N=', len(mdb.nu_lines)) diffmode = 0 opa = OpaPremodit(mdb=mdb, nu_grid=nu_grid, diffmode=diffmode, auto_trange=[Tlow, Thigh], dit_grid_resolution=1.0,allow_32bit=True) ``` -------------------------------- ### Get Exact Isotope Name Source: https://github.com/hajimekawahara/exojax/blob/master/documents/userguide/api.rst Retrieve the exact name of an isotope given its numerical identifier. ```ipython >>> mdb.exact_isotope_name(1) #-> (12C)(16O) ``` -------------------------------- ### Set up Wavenumber Grid and Load Molecular Database Source: https://github.com/hajimekawahara/exojax/blob/master/documents/analysis/freq_elower.ipynb Initializes a wavenumber grid and loads a molecular database for CH4. Ensure the database path is correct for your system. ```python nusa, wava, ra = wavenumber_grid(16350, 16450, 1000, unit="AA",xsmode="premodit") mdbCH4a = MdbExomol("/home/kawahara/.database/CH4/12C-1H4/YT34to10/",nusa) ``` -------------------------------- ### Get Methane Molecular Mass Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/Forward_modeling_using_PreMODIT_Cross_Section_for_methane.ipynb Retrieves the molecular mass of methane from the loaded molecular database. ```python molmassCH4=mdbCH4.molmass ``` -------------------------------- ### Setting up and Running the MCMC Sampler Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/Reverse_modeling_with_VALD_using_MODIT.ipynb Initializes the NUTS kernel and MCMC object for sampling from the posterior distribution defined by `model_c`. Requires a PRNGKey for reproducibility. ```python rng_key = random.PRNGKey(0) rng_key, rng_key_ = random.split(rng_key) num_warmup, num_samples = 100, 200 #500, 1000 kernel = NUTS(model_c,forward_mode_differentiation=True,max_tree_depth=7) mcmc = MCMC(kernel, num_warmup=num_warmup, num_samples=num_samples) ``` -------------------------------- ### Get molecular mass Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/Forward_modeling_using_DIT.rst Retrieves the molecular mass for CO, which is needed for Doppler broadening calculations. ```ipython3 from exojax.database import molinfo molmassCO=molinfo.molmass("CO") ``` -------------------------------- ### Uninstall ExoJAX Source: https://github.com/hajimekawahara/exojax/blob/master/documents/userguide/installation.rst Recommended command to run before installing a new version to prevent conflicts with removed modules. ```sh pip uninstall exojax ``` -------------------------------- ### Initialize Wavenumber Grid Source: https://github.com/hajimekawahara/exojax/blob/master/documents/tutorials/branch.ipynb Sets up the wavenumber grid for spectral analysis. Ensure the grid is in ascending order; descending order will raise an error. ```python from exojax.database.exomol.api import MdbExomol from exojax.utils.grids import wavenumber_grid nus,wave,resolution = wavenumber_grid(1900.0,2300.0,150000,xsmode="lpf") ``` -------------------------------- ### Generate Sphinx Documentation Source: https://github.com/hajimekawahara/exojax/blob/master/documents/developers/doc.rst Installs the package, generates API documentation from source, and builds the HTML documentation. ```python3 python setup.py install rm -rf documents/exojax sphinx-apidoc -F -o documents/exojax src/exojax cd documents make clean make html ```