Using the model
Follow the Getting started instructions. Only read on once you have confirmed that the model runs on your machine. Otherwise, see the Troubleshooting guide.
Input data files
The minimal input data required to run the model will have been downloaded automatically from Zenodo. If you require more data, such as additional stellar spectra or opacities, then these can also be easily obtained using the get_data script in the AGNI root directory. To see how to use this script, run it without arguments like so:
./src/get_data.shOpacities are contained within "spectral files". Use the table within res/spectral_files/reference.pdf to decide which spectral files are best for you.
For example, if you wanted to get the spectral file "Honeyside48" you would run:
./src/get_data.sh anyspec Honeyside 48Tutorials
There are Jupyter notebooks containing tutorials in the tutorials/ directory of the repository.
General execution
The environment variable RAD_DIR must point to the SOCRATES installation directory. This is required for AGNI to find the SOCRATES libraries. The best way to do this is to add RAD_DIR=path/to/socrates/folder/ to your shell rc file (e.g. ~/.bashrc).
Then to use the model, simply run
./agni.jl [cfg]where [cfg] is the path to the desired configuration file. If [cfg] is not passed, then the default configuration file will be used.
You should see the following output:
[ INFO ] Using configuration 'Default'
[ INFO ] Setting-up a new atmosphere struct
[ INFO ] Loading thermodyamic data
[ INFO ] Inserting stellar spectrum and Rayleigh coefficients
[ INFO ] Allocating atmosphere with composition:
[ INFO ] 1 H2O 1.00e+00 (EOS_AQUA)
[ INFO ] Setting T(p): dry, sat
[ INFO ] Solving with 'none'
[ INFO ] done
[ INFO ] Total RT evalulations: 2
[ INFO ] Writing results
[ INFO ] Plotting results
[ INFO ] Deallocating memory
[ INFO ] Model runtime: 16.60 secondsThe line following "Allocating atmosphere with composition" is a table of gases, their volume mixing ratios, and flags. In this case there is only one gas.
Potential flags for each species are:
EOS_[XX]- using the[XX]equation of state (e.g. ideal gas, AQUA)NO_OPACITY- no opacity data available, but can contribute to the thermodynamicsNO_THERMO- no thermodynamic data available, so will be treated as a diatomic ideal gasCOND- this gas is allowed to condense
Solver flags
During each step of the iteration, AGNI will flag the solver status to indicate what was done and if any problems arose. These flags are separated by a hyphen (-).
Potential solver flags are:
CsorCf- chemistry and condensation schemes either (s)ucceeded or (f)ailedGg- radiative transfer performed with double-grey schemeMorMr- convective fluxes are being modulated for stabilityC2orC4orF2orF4- a central or forward finite-difference scheme was used (at 2nd or 4th order)Ls- a linesearch method was appliedP- step was forcibly extrapolated because the solver is not making good progressU- the atmosphere has become gravitationally unbound
Grids of models parallelised with multiple processes
The code is not explicitly parallelised. However, there is functionality to run a grid of models using by the script located at misc/grid/worker.jl. This script operates a single worker (of potentially many). All parameter configuration should be done by editing the worker.jl file directly.
For example, to run worker ID=1 and allocate two workers to the whole grid:
julia --project=. misc/grid/worker.jl 1 2By allocating multiple workers and running them simultaneously using the manager script, which is located at misc/grid/manager.jl, we can parallelise the simulations. The number of workers is defined by the number of threads with which the manager script is run.
For example, run this manager script with four threads (and thus have four workers):
julia -t4 misc/grid/manager.jlThe manager script can also be executed on a HPC cluster by using the Slurm workload manager - assuming it is available on your server. You should then define the number of workers (and the allotted time) inside slurm.sh by setting cpus-per-task=XX.
For example:
sbatch --export=ALL misc/grid/slurm.shOnce finished, combine the results of these workers by using the consolidate.jl script. This will generate consolidated_* files (2 CSV, 1 NetCDF) in the root folder of the grid.
For example, assuming that the grid root is located at the path out/:
julia misc/grid/consolidate.jl out/Configuration
AGNI configuration files are formatted using TOML. There are examples in res/config/. The default configuration file contains comments explaining the purpose of each parameter, although some are explained in greater detail below. Take care to format the variables in the TOML file correctly. There are no 'default values'. Not all parameters are required in all cases, but the model will return an error naming any parameters which are both necessary and absent.
The configuration files are broken up into four sections (or "tables"), each containing a number of parameters. These tables of parameters are described below.
[planet]
General properties of the planet.
| Parameter | Description |
|---|---|
tmp_surf | Temperature of the surface [kelvin]. |
instellation | Stellar flux at planet's orbital distance [W m-2]. |
albedo_b | A pseudo bond-albedo which downscales the stellar flux by 1-albedo_b. |
s0_fact | Stellar flux scale factor which accounts for planetary rotation (c.f. Cronin+13). |
zenith_angle | Characteristic zenith angle for incoming stellar radiation [degrees]. |
surface_material | Surface material (can be "greybody" or path to data file in res/). |
albedo_s | Spectrally-grey surface albedo used when material=greybody. Optional otherwise. |
radius | Radius of the planet's surface [m]. |
gravity | Gravitational acceleration at the surface [m s-2]. Incompatible with mass option. |
mass | Total mass of material below the atmosphere [kg]. Incompatible with gravity option. |
skin_d | Thickness of the conductive boundary layer [m]. Used when solution_type=2. |
skin_k | Conductivity of the conductive boundary layer [W m-1 K-1]. Used when solution_type=2. |
tmp_magma | Temperature of the topmost layer of the planet's mantle [K]. Used when solution_type=2. |
flux_int | Internal flux [W m-2] to be solved-for when solution_type=3. |
roughness | Surface roughness length scale [m] |
wind_speed | Effective wind speed for sensible heat transport [m s-1]. |
star_Teff | Stellar photospheric temperature [K] used if files.input_star=="blackbody". |
[files]
Input/output files and other paths.
| Parameter | Description |
|---|---|
input_sf | Path to the desired spectral file in res/spectral_files/. If "greygas", uses double-grey RT scheme. |
input_star | Path to stellar spectrum. If blank, spectrum assumed to be inside spectral file. If "blackbody" must provide planet.star_Teff. |
output_dir | Path to the output directory. |
rfm_parfile | Path to .par linelist file, for running line-by-line calculations with the RFM. |
[composition]
Atmospheric composition and chemistry. There are three main ways to set the composition: partial pressures (p_dict), mixing ratios (vmr_dict or vmr_file), or by metallicities (metallicities).
| Parameter | Description |
|---|---|
p_top | Total top-of-atmosphere pressure [bar]. |
p_dict | Dictionary of gas partial surface pressures [bar]. Summed to obtain p_surf. |
p_surf | Total surface pressure [bar]. Incompatible with p_dict. |
vmr_dict | Gas volume mixing ratios (=mole fractions) at the surface. Must also set p_surf. |
vmr_file | Path to a file containing mixing ratio profiles. Must also set p_surf. |
metallicities | Dictionary of elemental mass abundance ratios relative to hydrogen. Must also set p_surf. |
condensates | List of volatiles which are allowed to condense. Incompatible with chemistry > 0. |
transparent | Make the atmosphere transparent (see below). Replaces all of the above parameters in this table. |
[execution]
Parameters that tell the model what to do.
| Parameter | Description |
|---|---|
clean_output | Clean old files from the output folder at model startup (true/false). |
verbosity | Logging verbosity (0: quiet, 1: normal, 2: extra logging) |
max_steps | Maximum number of steps the solver should take before giving up (typically <200). |
max_runtime | Maximum wall-clock runtime [s] before giving up. |
num_levels | Number of model levels. Typically ~50, and ideally less than 100. |
converge_atol | Convergence criterion, absolute amount of energy flux lost [W m-2]. |
converge_rtol | Convergence criterion, relative amount of energy flux lost [dimensionless]. |
initial_state | Ordered list of requests describing the initial state of the atmosphere (see below). |
solution_type | Solution type (see below). |
solver | Solver to use (see below). |
dx_max | Maximum step size [kelvin] allowed to be taken by the solver during each step. |
linesearch | Linesearch method to be used (0: None, 1: Golden section, 2: Backtracking) |
easy_start | Initially scale energy fluxes, to help with stability if the model is struggling. |
grey_start | Initially solve with double-grey RT scheme, to help with stability if the model is struggling. |
perturb_all | Perturb all rows of jacobian matrix at each solver iteration? True=stable, False=fast. |
rfm_wn_min | Line-by-line RFM radiative transfer, minimum wavenumber [cm-1] |
rfm_wn_max | Line-by-line RFM radiative transfer, maximum wavenumber [cm-1] |
[physics]
Parameters that describe how the model should treat the physics.
| Parameter | Description |
|---|---|
chemistry | Include 1D equilibrium chemistry in the atmosphere (true/false) |
continua | Include collisional/continuum absorption in radiative transfer (true/false) |
rayleigh | Include Rayleigh scattering in radiative transfer (true/false) |
cloud | Include cloud scattering and opacity in radiative transfer (true/false) |
overlap_method | Method for treating overlapping gas opacities within a given spectral band (see below) |
grey_lw | Grey opacity [m2/kg] of longwave (thermal) radiation. Used when input_sf="greygas" |
grey_sw | Grey opacity [m2/kg] of shortwave (stellar) radiation. Used when input_sf="greygas" |
real_gas | Use real-gas equation(s) of state where possible (true/false) |
thermo_funct | Use temperature-dependent thermodynamic properties (true/false) |
sensible_heat | Include turbulent sensible heat transport at the surface (true/false) |
advection | Include advective heat transport into each cell (true/false) |
convection | Include vertical heat transport associated with convection (true/false) |
convection_crit | Criterion for convective stability. Options: (s)chwarzschild, (l)edoux |
latent_heat | Include vertical heat transport from condensation and evaporation (true/false) |
rainout | Enable condensation and evaporation of condensables aloft. Required for latent_heat=true. |
oceans | Enable condensation and evaporation of condensables at the surface. |
[plots]
Configure plotting routines all of these should be true or false.
| Parameter | Description |
|---|---|
at_runtime | Make some plots at runtime? |
temperature | Plot temperature-pressure profile? |
fluxes | Plot energy flux profiles? |
contribution | Plot spectral contribution function? |
emission | Plot outgoing emission spectrum? |
albedo | Plot spectral albedo? This is the ratio of upward:downward SW fluxes |
mixing_ratios | Plot mixing ratio profiles? |
height | Plot radius-pressure profile? |
animate | Make an animation of the solver obtaining its solution? |
cloud | Plot water cloud mass fraction and area fraction profiles? |
Details on specific parameters
composition.transparentconfigures the atmosphere to be transparent. This works by setting the pressure to be small, and turning off the gas opacity. With this provided, the rest of the parameters in[configuration]are redundant. With this enabled, make sure to use the appropriate solver in the[execution]table.execution.solution_typetells the model which state to solve for. The allowed values (integers) are...- 1 : zero flux divergence at fixed
tmp_surf - 2 : zero flux divergence such that the conductive skin (CBL) conserves energy flux with fixed
tmp_magma - 3 : the net flux (up minus down) at each layer is equal to
flux_int
See the Model description page for an explanation of these solution types.
- 1 : zero flux divergence at fixed
execution.solvertells the model which solver to use. Allowed solvers are...- [empty string] : no solving takes place, so the model just calculates fluxes using the initial state
newton: the Newton-Raphson algorithm is usedgauss: the Gauss-Newton algorithm is usedlevenberg: the Levenberg–Marquardt algorithm is usedtransparent: solver to be used whencomposition.transparent=true.
execution.initial_statedescribes the initial temperature profile applied to the atmosphere. This is a list of strings which are applied in the given order, which allows the user to describe a specific state as required. The descriptors are listed below, some of which take a single argument that needs to immediately follow the descriptor in the list order.dry: integrate the dry adiabatic lapse rate from the surface upwardsstr,tmp: apply an isothermal stratosphere at temperaturetmpiso,tmp: set the whole atmosphere to be isothermal at temperaturetmpcsv,pth: set the temperature profile using the CSV file at the file pathpthsat,gas: apply Clausius-Clapeyron saturation curve for the gasgasncdf,pth: load profile from the NetCDF file located atpthloglin,tmp: log-linear profile betweentmp_surfat the bottom andtmpat the topana: use the Guillot (2010) analytical temperature solution
For example, setting
initial_state = ["dry", "sat", "H2O", "str", "180"]will set T(p) to follow the dry adiabat from the surface, the water condensation curve above that, and then to be isothermal at 180 K until the top of the model. Providetmp="Teq"to have AGNI automatically substitute-in the planet's radiative equilibrium temperature here.physics.chemistryenables a calculation of equilibrium thermochemistry in the atmosphere. This is handled externally by FastChem, so you must set the environment variableFC_DIRto point to the FastChem directory. More information on the chemistry is available on the Equilibrium chemistry page.physics.overlap_methodtells SOCRATES which algorithm to use to combine gas opacities. The spectral files contain k-tables for pure gases, and combining these coefficients can be done in several ways. See Amundsen+2017 for a nice comparison of overlap methods. Allowed options are..."ee": equivalent extinction (fastest)"rorr": random overlap, with resorting and re-binning"ro": random overlap (most accurate, slowest)
Accessing AGNI from Python
It is possible to interact with AGNI from Python. This is best done with the juliacall package from PythonCall.jl.
Coupling with Python is done via juliacall within the modular PROTEUS framework, which couples AGNI self-consistently to models of planetary interior evolution and volatile outgassing. You can see this implemented in agni.py within the PROTEUS source code.
A skeleton example is given below:
# Import juliacall
from juliacall import Main as jl
# Import AGNI
jl.seval("using Pkg")
jl.Pkg.activate(AGNI_ROOT_DIR) # <---- set AGNI_ROOT_DIR to your installation path
jl.seval("import AGNI")
jl.AGNI.setup_logging("out.log", 1)
# Setup atmosphere
atmos = jl.AGNI.atmosphere.Atmos_t()
jl.AGNI.atmosphere.setup_b(atmos, ...) # <--- complete function arguments as per docstring in `AGNI.atmosphere.setup!()`
# Allocate atmosphere
jl.AGNI.atmosphere.allocate_b(atmos, STAR_SPECTRUM_FILE) # <-- provide path to spectrum
# Solve T(p)
jl.AGNI.solver.solve_energy_b(atmos)
# Write results to a file
jl.AGNI.save.write_ncdf(atmos, "out.nc")Line-by-line radiative transfer
Performed using the Reference Forward Model. You must provide a HITRAN-formatted .par file, setting the path via files.rfm_parfile. This parfile can contain absorption from multiple species, and can be obtained from hitran.org. Alternatively, get the parfiles stored on Zenodo using: ./src/get_data.sh parfiles.
Then, you must also set the variables execution.rfm_wn_min and execution.rfm_wn_max. These two parameters specify the wavenumber [cm-1] range over which to perform the LbL calculations. The wavenumber resolution is set to 1 cm-1.
Results are saved to the NetCDF file, alongside all the usual data, as rfm_wn and rfm_fl arrays.