API Reference
eleos.constants
This module contains any constants used across the module. These attributes are not intended to be used from outside the module but may be useful in some circumstances.
- eleos.constants.CH4_LINES = wavelength intensity 0 3.260196 2.114000e-19 1 3.270445 2.106000e-19 2 3.240617 1.693000e-19 3 3.240408 1.659000e-19 4 3.313769 1.642000e-19 ... ... ... 58460 3.138428 1.002000e-29 58461 3.399955 1.002000e-29 58462 3.473636 1.001000e-29 58463 3.413562 1.001000e-29 58464 3.462683 1.000000e-29 [58465 rows x 2 columns]
The database of methane emission lines
- eleos.constants.DISTANCE = {'jupiter': 5.2, 'neptune': 30.0, 'saturn': 9.546, 'titan': 9.546, 'uranus': 19.2}
The distances from the Sun for all the bodies with significant atmospheres
- eleos.constants.GASES = radtrans_id ... isotopes 0 1 ... [161, 181, 171, 162, 182, 172, 262] 1 2 ... [626, 636, 628, 627, 638, 637, 828, 827, 727, ... 2 3 ... [666, 668, 686, 667, 676] 3 4 ... [446, 456, 546, 448, 447] 4 5 ... [26, 36, 28, 27, 38, 37] .. ... ... ... 133 134 ... [896] 134 135 ... [326] 135 136 ... [761] 136 137 ... [4061] 137 138 ... [916] [138 rows x 9 columns]
The database of gas names and IDs used by NEMESIS
- eleos.constants.GRAVITY = {'jupiter': 24.79, 'neptune': 11.15, 'saturn': 10.44, 'titan': 1.352, 'uranus': 8.69}
The surface gravity for all the bodies with significant atmospheres
- eleos.constants.MAKEPHASE_GASES = {'CH4': 6, 'H2O': 3, 'N2H4': 8, 'NH3': 4, 'NH4SH': 7, 'Tholins': 5}
The IDs used by Makephase for looking up refractive indicies of the gases
- eleos.constants.PATH = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/eleos/envs/latest/lib/python3.10/site-packages/eleos')
The absolute path of the prepackaged data directory
eleos.cores
- class eleos.cores.FixedPeak(central_wavelength, width, error)[source]
Bases:
objectUsed internally to specify if any spectral regions should be fixed so that NEMESIS always fits it there. Don’t instantiate, instead use
fix_peak()
- class eleos.cores.NemesisCore(parent_directory, spectrum, reference=None, aerosols=None, cia_file=None, sol_file=None, profiles=[], planet='jupiter', scattering=True, forward=False, num_iterations=20, num_layers=39, min_pressure=None, max_pressure=None, instrument_ktables='NIRSPEC', use_gases=[], sparsify_ktables=False, fmerror_factor=None, fmerror_pct=None, fmerror_value=None, cloud_cover=1.0, reference_wavelength=None)[source]
Bases:
objectThe class that constructs a core directory and all the required files for NEMESIS to run.
- parent_directory
The directory in which the core directory is created
- Type:
Path
- directory
The directory in which the core files are stored
- Type:
Path
- id_
The unique ID of the core
- Type:
int
- profiles
A dictionary of profiles.Profile objects to retrieve, where the keys are the profile labels and the values are the Profile objects themselves
- Type:
dict
- spectrum
The spectrum object to fit
- Type:
- spectrum_filepath
The filepath to the spectrum .spx file
- Type:
Path
- cia_file
The path to the collision-induced absorbtion file to use (default: mgRT_mgRV_40-400K_dnu4.0.tab, warning: always assumes d nu = 4.0)
- Type:
Path
- sol_file
The path to the solar spectrum file to use (default: solar_spec.dat)
- Type:
Path
- ref
The parsed ref file
- Type:
- planet
The name of the planet being observed
- Type:
str
- scattering
Whether to run a scattering retrieval or not
- Type:
bool
- num_aerosol_modes
The number of aerosol profiles in the retrieval
- Type:
int
- forward
Whether of not to run a forward model (ie. set number of iterations = 0)
- Type:
bool
- num_iterations
Number of iterations to run in the retrieval (if forward is set this has no effect)
- Type:
int
- num_layers
The number of atmospheric layers to simulate
- Type:
int
- layer_type
The type of layering to use
- Type:
int
- min_pressure
The minimum pressure in the atmosphere
- Type:
float
- max_pressure
The maximum pressure in the atmosphere
- Type:
float
- bottom_layer_height
The height in km of the bottom of the atmosphere
- Type:
int
- fixed_peaks
A list of FixedPeak objects that specify regions of the spectrum to fix
- Type:
list
- instrument_ktables
Either ‘NIRSPEC’ or ‘MIRI’; determines which set of ktables to use.
- Type:
str
- fmerror_factor
The factor by which to multiply the error on the spectrum (see also, fmerror_pct and fmerror_value)
- Type:
float
- fmerror_pct
If given, instead of using fmerror_factor or fmerror_value, use a flat percentage of the brightness (eg. 0.1 = 10%) (see also, fmerror_factor and fmerror_value)
- Type:
float
- fmerror_value
If given, instead of using fmerror_factor or fmerror_pct, use a flat value in W/cm2/sr/um (see also, fmerror_factor and fmerror_pct)
- Type:
float
- cloud_cover
If scattering mode is on, then this is the fractional cloud cover between 0 and 1 (usually doesn’t need to be changed)
- Type:
bool
- reference_wavelength
If scattering mode is on, then normalise the cross-sections at the closest wavelength to this value in the .xsc file
- Type:
float
- __init__(parent_directory, spectrum, reference=None, aerosols=None, cia_file=None, sol_file=None, profiles=[], planet='jupiter', scattering=True, forward=False, num_iterations=20, num_layers=39, min_pressure=None, max_pressure=None, instrument_ktables='NIRSPEC', use_gases=[], sparsify_ktables=False, fmerror_factor=None, fmerror_pct=None, fmerror_value=None, cloud_cover=1.0, reference_wavelength=None)[source]
Create a NEMESIS core directory with a given set of profiles to retrieve
- Parameters:
parent_directory (str) – The directory in which to create the core folder
spectrum (str or NemesisSpx) – Either the path to the .spx file to fit or a parsers.NemesisSpx object
reference (str or NemesisRef) – Either the path to the nemesis.ref file to use or a parsers.NemesisRef object
aerosols (str or AerosolRef) – Either the path to the aerosol.ref file to use or a parsers.AerosolRef object
cia_file (str) – Path to the collision-indced absorbtion file to use
sol_file (str) – Path to the solar spectrum file to use
List[str] (profiles) – List of profiles.Profile objects to retrieve
planet (str) – Name of the planet being observed. Must be one of ‘jupiter’, ‘saturn’, ‘uranus’, ‘neptune’ or ‘titan’.
scattering (bool) – Whether to run a scattering retrieval or not
forward (bool) – Whether of not to run a forward model (ie. set number of iterations = 0)
num_iterations (int) – Number of iterations to run in the retrieval (if forward is set this has no effect)
num_layers (int) – The number of atmospheric layers to simulate - for scattering runs the default maximum is 39.
min_pressure (float) – The pressure at the top of the model atmosphere
max_pressure (float) – The pressure at the bottom of the model atmosphere
instrument_ktables (str) – Either ‘NIRSPEC’ or ‘MIRI’; determines which set of ktables to use.
use_gases (list) – A list of the gases to use in the model, with names corresponding the to ktable names (eg. “ch4.combi.kta” would be [“ch4”])
sparsify_ktables (bool) – Whether to reduce the number of wavelengths in the ktables to only those that are required (may significantly speed up computation)
fmerror_factor (float) – The factor by which to multiply the error on the spectrum (see also, fmerror_pct and fmerror_value)
fmerror_pct (float) – If given, instead of using fmerror_factor or fmerror_value, use a flat percentage of the brightness (eg. 0.1 = 10%) (see also, fmerror_factor and fmerror_value)
fmerror_value (float) – If given, instead of using fmerror_factor or fmerror_pct, use a flat value in W/cm2/sr/um (see also, fmerror_factor and fmerror_pct)
cloud_cover (bool) – If scattering mode is on, then this is the fractional cloud cover between 0 and 1 (usually doesn’t need to be changed)
reference_wavelength (float) – If scattering mode is on, then normalise the cross-sections at the closest wavelength to this value in the .xsc file. This parameter will be updated with the exact wavelength
- add_profile(profile)[source]
Add a profile to retrieve. It’s recommended to do this during instantiation using the profiles argument.
- Parameters:
profile – profiles.Profile object to add
- Returns:
None
- change_aerosols(new_aerosols)[source]
Replace the existing aerosol.ref file of the core with a new
- Parameters:
new_aerosols (parsers.AerosolRef or pathlike) – The new ref file to use as either a path to a .ref file, or a parsers.AerosolRef object.
file. (If a prf file is specified then it will be used as the new ref)
heights (If new_aerosols is None then create a file with zero aerosols at all)
- Returns:
None
- change_reference(new_reference)[source]
Replace the existing .ref file of the core with a new
- Parameters:
new_reference (parsers.NemesisRef or pathlike) – The new ref file to use as either a path to a .ref file, or a parsers.NemesisRef object.
file. (If a prf file is specified then it will be used as the new ref)
- Returns:
None
- change_spectrum(new_spectrum)[source]
Replace the existing .spx file of the core with a new
- Parameters:
new_spectrum (parsers.NemesisSpx or pathlike) – The new spx file to use as either a path to a .spx file, or a parsers.NemesisSpx object
- Returns:
None
- copy_core(new_parent_directory=None)[source]
Create a copy of the current core object with a new ID.
- Parameters:
new_parent_directory (pathlike) – Optionally, specify a new parent directory for the copied core. If None then use the same parent directory as the original core.
- Returns:
The copied core object
- Return type:
- delete_auxillary_files()[source]
Delete most of the input files and some rarely used ouptut files from the core to reduce disk space. Note, in order to run this core again the missing input files will need to be regenrated with generate_core().
- Parameters:
None
- Returns:
None
- delete_core_directory(confirm=True)[source]
Delete the entire core directory and all its contents.
- Parameters:
confirm (bool) – Whether to confirm with the user before deleting
- Returns:
None
- fix_peak(central_wavelength, width, error=1e-15)[source]
Set a region of the spectra to be fixed (ie. NEMESIS will be forced to match it). This is done internally by setting the error on that region to be extrmemely small.
- Parameters:
central_wavelength (float) – The central wavelength of the peak
width (float) – The width of the spectral feature (this is a full width, so the region being fixed is centre-width/2 to centre+width/2)
error (float) – Optionally, give the error to be assigned to the region. This should be very small and there is not much need to change this
- Returns:
None
- property forward
- generate_core(verbosity=1, confirm=True)[source]
Create all the files necessary for a NEMESIS retrieval in the directory specified by NemesisCore.directory.
- Parameters:
verbosity (int) – One of 0, 1, 2. If 0 then do not print any progress. If 1 then print core number. If 2 then print status for each file
- Returns:
None
- Creates:
See _generate_* methods
- generate_prior_distributions()[source]
Run NEMESIS briefly in a temporary directory to generate the prior gas and aerosol profiles.
- Parameters:
None
- Returns:
Data from the .prf files generated. Columns are: ‘height’, ‘pressure’, ‘temperature’, the gas profiles, and the aerosol profiles
- Return type:
pd.DataFrame
- get_aerosol_profile(id=None)[source]
Given an aerosol ID (as used by NEMESIS) return the corresponding AerosolProfile object.
- Parameters:
id (int) – The aerosol ID
label (str) – The label associated with the AerosolProfile object
- Returns:
The corresponding aerosol profile
- Return type:
- get_height_limits()[source]
Get the heights of the top and bottom layers of the atmosphere in km.
- Parameters:
None
- Returns:
Height of the top of the atmosphere bottom_height: Height at the bottom of the atmosphere
- Return type:
top_height
- get_ktable_gas_names()[source]
Return the names of the gases used in the filenames of the ktables. Assumes a format of ‘[molecule].combi.kta: eg. ch4.combi.kta -> “ch4”
- get_new_id()[source]
Refresh the core ID to a new sequential value and update the core directory accordingly.
- Parameters:
None
- Returns:
None
- get_profile_constant_names()[source]
Return the names of the constants (ie. the parameters that NEMESIS doesnt fit) in each profile. See also: get_profile_constant_names and get_profile_parameter_names`
- Parameters:
None
- Returns:
Dictionary of the form {profile_label: [variable names, …]}
- Return type:
dict
- get_profile_parameter_names()[source]
Return the names of the parameters (variables and constants) in each profile. See also: get_profile_constant_names and get_profile_parameter_names`
- Parameters:
None
- Returns:
Dictionary of the form {profile_label: [variable names, …]}
- Return type:
dict
- get_profile_variable_names()[source]
Return the names of the variables (ie the parameters that NEMESIS can vary) in each profile. See also: get_profile_constant_names and get_profile_parameter_names`
- Parameters:
None
- Returns:
Dictionary of the form {profile_label: [variable names, …]}
- Return type:
dict
- get_spx_wavelength_grid()[source]
Return the wavelength grid of the spx file associated with the core.
- Parameters:
None
- Returns:
The wavelength grid in microns
- Return type:
np.ndarray
- remove_profile(profile_label)[source]
Remove a profile. WIP - DOES NOT WORK FOR AEROSOL PROFILES
- Parameters:
profile_label (str) – The label of the profile to remove
- Returns:
None
- run(verbosity=0, confirm=False)[source]
Run NEMESIS on the core. This method should only be used for short forward models as it does not schedule the jobs on the ALICE compute nodes (see run_alice_job() for that), instead running it in the current terminal.
- Parameters:
None
- Returns:
The results object for the core
- Return type:
NemeisResult
- set_pressure_limits(max_pressure, min_pressure)[source]
Change the pressure limits of the core. Also sets the bottom layer height to the closest value in the .ref file
- Parameters:
max_pressure (float) – The new maximum pressure in bar. If None then use the maximum pressure in the .ref file
min_pressure (float) – The new minimum pressure in bar. If None then use the minimum pressure in the .ref file
- Returns:
None
- set_random_priors(parameters)[source]
For each eleos.mcmc.Parameter object given, set the values randomly based on a normal distribution with mean and standard deviation given by the current param and param_error
- Parameters:
parameters (List[mcmc.Parameters]) – The parameters to randomise
- Returns:
None
- eleos.cores.add_to_raddata(filepath)[source]
Copy a file into the local raddata/ directory. Useful for choosing arbitrary solar spectrum files for example.
- eleos.cores.clear_parent_directory(parent_directory, confirm=True)[source]
Attempt to delete all the child files/directories from the specified folder. It is recommended to call this function at the start of every core generation script as it ensures that the script is fully stateless. If a script generates N cores when first run and is subsequently modified to produce N/2 cores, then the remaining N/2 core directories will remain in the parent directory. This should not matter as the SLURM script will only run the correct subset of cores, but it can get confusing. If the parent directory specified does not exist then it will print a warning and return.
- Parameters:
parent_directory (str) – The directory to clear
confirm (bool) – Whether to confirm with the user before deleting the directory
- Returns:
None
- eleos.cores.create_gas_analysis_cores(parent_directory, template_core, generate_cores=True, new_spx=None)[source]
Create a set of cores where each core has a single gas excluded. Useful for determining where in the spectrum each gas contributes.
- Parameters:
parent_directory (str) – The parent directory to create the new cores in
template_core (NemesisCore) – The core to use as a template
generate_cores (bool) – Whether to generate the cores or just return the list of cores to be generated
new_spx (str) – The path to a new spx file to use instead of the one in the template core. This is useful if you want to use a different resolution or wavelength range
- Returns:
A list of new cores with the gases excluded
- Return type:
List[NemesisCore]
- eleos.cores.create_sensitivity_analysis(parent_directory, template_core, generate_cores=True, factors=(0.8, 0.9, 0.95, 1.05, 1.1, 1.2), forward=True, parameters=None)[source]
Create a sensitivity analysis on the template core. This is done by creating a new core for each parameter in each profile, and varying that parameter by a small amount.
- Parameters:
parent_directory (str) – The parent directory to create the new cores in
template_core (NemesisCore) – The core to use as a template
generate_cores (bool) – Whether to generate the cores or just return the list of cores to be generated
factors (tuple) – The factors to vary the parameters by. Default is (0.8, 0.9, 0.95, 1.05, 1.1, 1.2). Note there is no need to include 1.00 as a factor as this is equivalent to the baseline which is already calculated
forward (bool) – Whether to run forward models or retrievals. Use forward models to see where each parameter affects each spectrum and retrievals to test if different priors converge on different solutions
parameters (List[mcmc.Parameter]) – Optionally, a list of specific parameters to vary. If None, all variable parameters will be varied.
- Returns:
A list of new cores with the parameters varied
- Return type:
List[NemesisCore]
- eleos.cores.generate_alice_job(parent_directory, python_env_name, memory=16, hours=0, minutes=0, username=None, notify=('end', 'fail'), type_='normal')[source]
Generate an sbatch submission script for use on ALICE. The job is an array job over all the specified cores. After running NEMESIS it will run Eleos to create some summary plots in the parent/core_N/plots directory
- Parameters:
parent_directory (str) – The directory containing the NEMESIS core directories to be run
python_env_name (str) – The name of a conda environment which has Eleos installed
memory (int) – The amount of memory to use as a string, formatted like ‘100mb’ or ‘16gb’
hours (int) – The number of hours to schedule the job for
minutes (int) – The number of minutes to schedule the job for
username (str) – The username of the user running the job (eg, scat2, lnf2)
notify (List[str] or str) – What email notifications to send. Can be any combination of ‘begin’, ‘end’, ‘fail’
type (str) – The type of job to run. Can be ‘normal’ or ‘sensitivity’. This will determine how Eleos is run at the end of the job.
- Returns:
None
- Creates:
submitjob.sh in the parent directory of the cores
- eleos.cores.get_refractive_indicies(name, start_wl, end_wl, wl_step)[source]
Run Makephase to get the refractive indicies of the gases in the lookup tables.
- Parameters:
name (str) – The gas name to use (see constants.MAKEPHGASE_GASES for a list)
start_wl – Start wavelength
end_wl – End wavelength
wl_step – Wavelength step size
- Returns:
Dataframe containing the wavelength and the real and imaginary refractive indicies. Columns are: ‘wavelength’, ‘real’, and ‘imag’
- Return type:
pd.DataFrame
- eleos.cores.load_core(core_directory)[source]
Load a NemesisCore object saved using NemesisCore._save_core. Do not use this to load a core that has been retrieved; use results.NemesisResult for that purpose
- Parameters:
None
- Returns:
The unpickled core
- Return type:
- eleos.cores.load_from_previous(previous_directory, parent_directory, use_retrieval_errors=False)[source]
Load a core from a previous retrieval to use as a template for creating a new core. This method loads the core using the core.pkl file and then calls from_previous_retrieval on all Profile objects stored, as well as resetting core ID, parent_directory, etc…
- Parameters:
previous_directory (str) – The path to the core directory to load
parent_directory – The new parent directory to create the new core under
use_retrieval_errors (bool) – Whether to use the retrieval errors from the previous retrieval as the new parameter errors. If False, the original parameter errors from the previous core are used.
- Returns:
The new core object
- Return type:
- eleos.cores.parallelise_forward(core, n_chunks=None, chunk_size=None, spx_save_dir=None)[source]
Split a single forward model into multiple by distrubuting chunks of the spectrum between each core. Useful for running high spectral resolution cores. You must specify ONE of n_chunks or chunk_size.
- Parameters:
core (NemesisCore) – The core to run
n_chunks (int) – Number of chunks to split into
chunk_size (int) – Alternatively, specify the size of each chunk
- Returns:
The cores to run in parallel
- Return type:
list[NemesisCore]
- eleos.cores.reset_core(core_directory)[source]
Delete all the files that NEMESIS generates and leave only the input files. Useful for re-running a retrieval from scratch.
- eleos.cores.reset_core_numbering()[source]
Reset the automatic core numbering. Useful for creating multiple sets of cores in one program.
- Parameters:
None
- Returns:
None
- eleos.cores.run_alice_job(parent_directory, print_queue_delay=2)[source]
Run the script created by generate_alice_job
- Parameters:
parent_directory (str) – Path to the directory containing all the cores
print_queue_delay (float) – Duration to wait (in seconds) before printing the current job queue
- Returns:
None
eleos.parsers
This module provides parsing objects for reading some NEMESIS files, such as nemesis.ref
- class eleos.parsers.AerosolRef(filepath)[source]
Bases:
ParserParser for the aerosol.prf file
- num_modes
The number of aerosol modes defined in the file
- Type:
int
- data
DataFrame containing the aerosol density as a function of height. The units of aerosol density are particles per gram of atmosphere
- Type:
pandas.DataFrame
- class eleos.parsers.HGPhase(filepath)[source]
Bases:
ParserParser for the HG phase function file
- hg
DataFrame containing f, g1, and g2 as a function of wavelength
- Type:
DataFrame
- class eleos.parsers.NemesisCov(filepath)[source]
Bases:
ParserParser for nemesis.cov
- cov
Covariance matrix of the retrieved parameters
- Type:
np.ndarray
- class eleos.parsers.NemesisInp(filepath)[source]
Bases:
ParserParser for nemesis.inp
- wavelength
Whether to use wavelength or wavenumber
- Type:
bool
- scattering
Whether to use a scattering run
- Type:
bool
- linebyline
Whether to use line-by-line or corrrelated-k method
- Type:
bool
- woff
Wavelength offset
- Type:
float
- fmerror_path
Path to the file contianing forward modelling errors for each wavelength
- Type:
str
- num_iterations
Maximum number of iterations
- Type:
int
- min_phi_change
Minimim percentage change in phi before terminating
- Type:
float
- num_spectra
Number of spectra to retrieve
- Type:
int
- start_spectra
ID of spectra to start with
- Type:
int
- sub_previous
Whether to use a previous retrieval
- Type:
bool
- output_format
Format of the output files
- Type:
int
- class eleos.parsers.NemesisItr(filepath, mre=None)[source]
Bases:
ParserParser for nemesis.itr. Also requires a NemesisMre parser
- state_vectors
Linear state vectors for each iteration
- Type:
pd.DataFrame
- class eleos.parsers.NemesisMre(filepath)[source]
Bases:
ParserParser for the nemesis.mre file
- ispec
Don’t know
- Type:
int
- wavenumber
Whether the spectrum is in wavenumber (cm-1) or wavelength (um) space
- Type:
bool
- ngeom
Number of geometries (should be 1)
- Type:
int
- latitude
Latitude of the observation
- Type:
float
- longitude
Longitude of the observation
- Type:
float
- retrieved_spectrum pd.DataFrame
DataFrame containing the measured spectrum + all error sources and the fitted model spectra and its errors
- retrieved_parameters List[pd.DataFrame]
List of DataFrames containing the retrieved parameters from each Profile
- class eleos.parsers.NemesisPrc(filepath)[source]
Bases:
ParserParser for nemesis.prc
- chisq
List of chi-squared values
- Type:
List[float]
- class eleos.parsers.NemesisRef(filepath)[source]
Bases:
ParserParser for nemesis.ref and nemesis.prf
- amform
How the VMRs add up (always assumed to be 1: sum(VMR per layer)==1)
- planet_id
ID of the planet being analysed.
- latitude
Latitude at which the .ref file applies
- num_layers
Number of layers used
- num_gases
Number of gases in the file
- gas_names
List of the names of all the gases
- data
Contains the pressure, temperature, and VMR profiles of each gas at each height
- class eleos.parsers.NemesisSpx(filepath)[source]
Bases:
ParserParser for the nemesis.spx file
- lat
Latitude of the observation
- Type:
float
- lon
longitude of the observation
- Type:
float
- phase
Phase angle of the observation
- Type:
float
- emission
Emission angle of the observation
- Type:
float
- azimuth
Azimuth angle of the observation
- Type:
float
- wgeom
wgeom
- Type:
float
- nconv
nconv
- Type:
int
nav
- Type:
int
- fwhm
FWHM of the instrument
- Type:
float
- wavelengths
Wavelengths of the observed spectra in um
- Type:
np.ndarray
- spectrum
The observed spectra in W/cm2/sr/um
- Type:
np.ndarray
- error
The error on the observed spectra in W/cm2/sr/um
- Type:
np.ndarray
- static convert_MJysr_to_Wcm2srum(wavelengths: ndarray, spectrum: ndarray) ndarray[source]
Convert a spectrum or cube from MJy/sr to W/cm2/sr/micron.
- static convert_Wcm2srum_to_MJysr(wavelengths: ndarray, spectrum: ndarray) ndarray[source]
Convert a spectrum or cube from W/cm2/sr/micron to MJy/sr.
- property errors
- classmethod from_lists(wavelengths, spectrum, error, lat, lon, phase, emission, azimuth, fwhm=0, convert=True)[source]
Create a new NemesisSpx object from three lists (wavelength, spectrum, errors) and a set of parameters (lat, lon etc…) See also: NemesisSpx.get_angles()
- Parameters:
wavelengths (list or array-like) – Wavelength values of the observation.
spectrum (list or array-like) – Measured spectral radiance/reflectance values in units of MJy/sr or W/cm2/sr/um (see convert).
error (list or array-like) – Measurement uncertainties for each spectral point.
lat (float) – Latitude of the observation point (degrees).
lon (float) – Longitude of the observation point (degrees).
phase (float) – Phase angle between the observer, target, and light source (degrees).
emission (float) – Emission angle of the observation (degrees).
azimuth (float) – Azimuth angle (degrees).
fwhm (float, optional) – Full width at half maximum of the spectral resolution. Defaults to 0.
convert (bool, optional) – If True, converts the input values from MJy/sr to W/cm2/sr/um. Defaults to False.
- Returns:
A new instance populated with the given spectral and geometric data.
- Return type:
- get_angles()[source]
Retrieve the geometric parameters of the observation. useful for creating modified versions of the same spectrum (see NemesisSpx.from_lists())
- Parameters:
None
- Returns:
- Dictionary containing:
’lat’ (float): Latitude in degrees.
’lon’ (float): Longitude in degrees.
’phase’ (float): Phase angle in degrees.
’emission’ (float): Emission angle in degrees.
’azimuth’ (float): Azimuth angle in degrees.
- Return type:
dict
- property wavelength
- class eleos.parsers.NemesisXsc(filepath)[source]
Bases:
ParserParser for the nemesis.xsc file
- xsc
The aerosol cross-sections as a function of wavelength for each aerosol mode
- Type:
pd.DataFrame
- ssa
The single scattering albedos as a function of wavelength for each aerosol modes
- Type:
pd.DataFrame
- add_aerosol_names(names=None)[source]
Add the aerosol profile names/labels to the ssa and xsc DataFrames
- Parameters:
names (None / str / AerosolProfile / list[AerosolProfile]) – The names to give the aerosol profiles.
generated. (By default it looks for a aerosol_names.txt file that Eleos generated when a core is)
string (This can be overridden with a)
AerosolProfile
type. (or a list of either)
- Returns:
None
- class eleos.parsers.ParaH2Ref(filepath)[source]
Bases:
ParserParser for the parah2.ref file
- data
pd.DataFrame containing the aerosol density as a function of height. The units of aerosol density are particles per gram of atmosphere
- class eleos.parsers.kTable(filepath)[source]
Bases:
ParserParser for ktables
- Atributes:
ktable (np.ndarray): 4D array of absorption coefficients with axes (wavelength, pressure, temperature, g-ordinate). wavelength (np.ndarray): Array of spectral points pressure (np.ndarray): Array of pressure levels temperature (np.ndarray): Array of temperature levels g_ordinates (np.ndarray): Array of g-ordinates used in correlated-k integration g_weights (np.ndarray): Corresponding quadrature weights for g-ordinates irec0 (int): Number of header records npoint (int): Number of spectral points vmin (float): Starting value of the spectral axis delv (float): Spectral spacing. If negative, grid is non-uniform and read from file. fwhm (float): Full Width at Half Maximum for spectral bins np_ (int): Number of pressure levels nt (int): Number of temperature levels ng (int): Number of g-ordinates idgas (int): Identifier for the gas species isogas (int): Identifier for the isotope of the gas
eleos.profiles
This module contains the classes for creating Profile objects. There are currently 3 profiles available through Eleos: temperature (TemperatureProfile) gases (GasProfile) aerosols (AerosolProfile)
- class eleos.profiles.AerosolProfile(shape, radius, variance, n_lookup=None, real_n=None, imag_n=None, retrieve_optical=False, radius_error=None, variance_error=None, imag_n_error=None, label=None)[source]
Bases:
Profile- __init__(shape, radius, variance, n_lookup=None, real_n=None, imag_n=None, retrieve_optical=False, radius_error=None, variance_error=None, imag_n_error=None, label=None)[source]
Create a profile for an aerosol layer with a given shape and particle/optical properties.
Call signatures:
Constant refractive index over range (not retrieved): AerosolProfile(shape, radius, variance, real_n, imag_n)
Constant refractive index over range (retrieved; ie with an attached 444): AerosolProfile(shape, radius, radius_error, variance, variance_error, real_n, imag_n, imag_n_error)
Use refractive index from lookup table (not retrieved): AerosolProfile(shape, radius, variance, n_lookup)
Use refractive index from lookup table (retrieved; ie with an attached 444): AerosolProfile(shape, radius, radius_error, variance, variance_error, n_lookup)
Currently you cannot specify an arbitrary list of refractive index points to use, but this will be added!
- Parameters:
shape (Shape) – A Shape object to use for the profile shape
label (str) – A label to associate with this Profile. By default it is “Aerosol <aerosol_id>” (eg. “Aerosol 1”)
shape – A Shape object that describes the profile shape
radius (float) – Particle radius in microns
variance (float) – Variance of the particle size distribution in microns (gamma distribution)
n_lookup (str) – If given, use the refractive indicies of this gas (eg. ‘CH4’)
real_n (float) – If n_lookup is not given, then use this as the real part of the refractive index
imag_n (float) – If n_lookup is not given, then use this as the imaginary part of the refractive index,
retrieve_optical (bool) – Whether to retrieve the optical porperties of the aerosol (this adds a 444 profile in NEMESIS)
radius_error (float) – If retrieve_optical is set, the error used for the particle radius prior
variance_error (float) – If retrieve_optical is set, the error used for the particle size variance prior
imag_n_error (float) – If retrieve_optical is set, the error used for the imaginary part of the refractive index
label – A label to assosiate with this profile
- check_validity()[source]
Check that the parameters for each Profile and Shape are valid. This should be overridden by subclasses
- class eleos.profiles.GasProfile(gas_name=None, gas_id=None, isotope_id=0, shape=None, label=None)[source]
Bases:
Profile- __init__(gas_name=None, gas_id=None, isotope_id=0, shape=None, label=None)[source]
Create a profile for a given gas (optionally an isotopologue) with a given shape. Call signatures:
Create profile with the name of the gas (ie ‘NH3’) GasProfile(gas_name, isotope_id, shape)
Create profile with the ID of the gas (eg. 11) GasProfile(gas_id, isotope_id, shape)
- Parameters:
gas_name (str) – The name of the gas (eg ‘CH4’). Specify either this OR gas_id
gas_id (int) – The radtrans ID of the gas (eg. 6). Specify either this OR gas_name
isotope_id (int) – The ID of the isotopologue to use. Use 0 for a mix of all at terrestrial abundance
shape (Shape) – A Shape object to use for the profile shape
label (str) – A label to associate with this Profile. By default it is “<gas_name> <isotope_id>” (eg. “PH3 0”)
- class eleos.profiles.Profile(label=None)[source]
Bases:
object- __init__(label=None)[source]
This is the base class for all Profile objects. It should never be instantiated directly, use a subclass such as
GasProfileorAerosolProfile
- check_validity()[source]
Check that the parameters for each Profile and Shape are valid. This should be overridden by subclasses
- classmethod from_previous_retrieval(result, label, use_retrieval_errors=False)[source]
Create a Profile object using the retrieved parameters from a previous retrieval as priors. Use either id or label to specify the profile to use in the previous retrieval.
- Parameters:
result (NemesisResult) – The result object from the previous retrieval
label (str) – The label of the profile to use in the previous retrieval
- class eleos.profiles.TemperatureProfile(filepath, label=None)[source]
Bases:
Profile- __init__(filepath, label=None)[source]
Create a temperature profile from a prior file. NOT IMPLEMENTED YET
- Parameters:
filepath – The filepath of the prior temperature profile
label (str) – A label to associate with this Profile. By default it is “Temperature”
- create_nemesis_string()[source]
Create the NEMESIS code that represents the temperature profile. Temperature profiles currently only support mode 0 0 0 so this function’s return value is always constant
- Parameters:
None
- Returns:
‘0 0 0’
- Return type:
str
eleos.results
- class eleos.results.NemesisResult(core_directory)[source]
Bases:
objectClass for storing and using the results of a NEMESIS retrieval.
- core_directory
The directory of the core being analysed
- Type:
str
- core
The NemesisCore object that generated the core directory
- Type:
- profiles
A dictionary of all the retrieved Profile objects from the run. The keys are the labels given to the Profiles on creation (eg. GasProfiles have the form “<gas_name> <isotope_id>” such as “PH3 0”)
- Type:
dict[Profile]
- latitude
Latitude of the observed spectrum
- Type:
float
- longitude
Longitude of the observed spectrum
- Type:
float
- chi_sq
The chi-squared value of the retrieval
- Type:
float
- elapsed_time
The time taken for the retrieval in decimal hours
- Type:
float
- retrieved_spectrum
A DataFrame containing the measured and modelled spectrum
- Type:
pandas.DataFrame
- retrieved_aerosols
A DataFrame containing the retrieved aerosol profiles
- Type:
pandas.DataFrame
- retrieved_gases
A DataFrame containing the retrieved chemical profiles
- Type:
pandas.DataFrame
- __init__(core_directory)[source]
Constructor for NemesisResult
- Parameters:
core_directory (str) – The directory of the core
- delete(confirm=True)[source]
Delete the NemesisResult object AND delete the corresponding core directory. This action is irreviersible!
- Parameters:
confirm (bool) – Whether to prompt for confirmation
- Returns:
None
- property elapsed_time
Return the time taken for the retrieval in hours
- make_iterations_plot(figsize=(14, 10))[source]
Plot the state vector for each iteration of the retrieval. Each retreived parameter is plotted on a separate axis.
- Parameters:
None
- Returns:
The Figure object to which the Axes belong matplotlib.Axes: The Axes object onto which the data was plotted
- Return type:
matplotlib.Figure
- make_summary_plot(figsize=(11, 10), log=False)[source]
Make a summary plot with prior and retrieved spectra, error on the spectra, aerosol and chemical profiles, and chi-squared values.
- Parameters:
figsize (int, int) – matplotlib figure size
- Returns:
The produced figure dict(str: matplotlib.Axes): The axes of the produced figure with labels:
’A’ for the spectrum ‘B’ for the residuals ‘C’ for the chi-sqaured plot ‘D’ for the aerosol profiles ‘E’ for the gas profiles
- Return type:
matplotlib.Figure
- plot_aerosol_profiles(ax, pressure, unit='tau/bar')[source]
Plot the retrieved aerosol profiles either in units of particles/gram of atmosphere or in units of optical thickness/bar against either height or pressure
- Parameters:
ax – The matplotlib.Axes object to plot to. If omitted then create a new Figure and Axes
unit – The unit to convert the aerosol profiles to. Valid values are: ‘tau/bar’ for optical depth per bar, ‘tau/km’ for optical depth per bar, ‘tau’ for pressure-integrated optical depth, ‘cm2/g’ for the native prf units
pressure – Whether to plot the aerosol profiles against pressure (if True) or height (if False)
- Returns:
The Figure object to which the Axes belong matplotlib.Axes: The Axes object onto which the data was plotted
- Return type:
matplotlib.Figure
- plot_chisq(ax)[source]
Plot the chi-squared values as a function of iteration number
- Parameters:
ax – The matplotlib.Axes object to plot to. If omitted then create a new Figure and Axes
- Returns:
The Figure object to which the Axes belong matplotlib.Axes: The Axes object onto which the data was plotted
- Return type:
matplotlib.Figure
- plot_gas_profiles(ax, pressure, unit='', gas_names=None, plot_retrieved_profiles=True, plot_prior_profiles=False, plot_ref_profiles=True)[source]
Plot gas profiles from the .prf file.
- Parameters:
ax (matplotlib.Axes) – The matplotlib.Axes object to plot to. If omitted then create a new Figure and Axes.
pressure (bool) – Whether to plot the gas profiles against pressure (if True) or height (if False).
unit (str) – One of ‘’, ‘ppm’, ‘ppb’ or ‘ppt’.
gas_names (list[str], optional) – List of gas names to plot. If None, plot all gases.
plot_retrieved_profiles (bool) – Whether to plot the retrieved gas profiles
plot_prior_profiles (bool) – Whether to plot the prior gas profiles
plot_ref_profiles (bool) – Whether to plot the profile in the .ref file
- Returns:
The Figure object to which the Axes belong matplotlib.Axes: The Axes object onto which the data was plotted
- Return type:
matplotlib.Figure
- plot_spectrum(ax, show_chisq=True, legend=True, log=False)[source]
Plot the measured and model spectrum on a matplotlib Axes.
- Parameters:
ax – The matplotlib.Axes object to plot to. If omitted then create a new Figure and Axes
show_chisq (bool) – Whether to display the chi-squared value of the fit
legend (bool) – Whether to draw the legend
log (bool) – Whether to use a log plot
- Returns:
The Figure object to which the Axes belong matplotlib.Axes: The Axes object onto which the data was plotted
- Return type:
matplotlib.Figure
- plot_spectrum_residuals(ax, log=False)[source]
Plot the spectrum residuals on a matplotlib Axes.
- Parameters:
ax – The matplotlib.Axes object to plot to. If omitted then create a new Figure and Axes
show_chisq (bool) – Whether to display the chi-squared value of the fit
log (bool) – Whether to use a log plot
- Returns:
The Figure object to which the Axes belong matplotlib.Axes: The Axes object onto which the data was plotted
- Return type:
matplotlib.Figure
- plot_temperature(ax, pressure)[source]
Plot the prior and retrieved temperature profile on a matplotlib Axes.
- Parameters:
ax – The matplotlib.Axes object to plot to. If omitted then create a new Figure and Axes
pressure – Whether to plot the temperature profile against pressure (if True) or height (if False)
- Returns:
The Figure object to which the Axes belong matplotlib.Axes: The Axes object onto which the data was plotted
- Return type:
matplotlib.Figure
- savefig(name, fig=None, **kwargs)[source]
Save a matplotlib figure to a file in the core’s plots directory.
- Parameters:
name (str) – The name of the file to save the figure as.
fig (matplotlib.Figure, optional) – The figure to save. If None, the current figure will be saved. Default is None.
**kwargs – Additional keyword arguments to pass to savefig.
- Returns:
None
- class eleos.results.SensitivityAnalysis(parent_directory)[source]
Bases:
objectClass for analysing the sensitivity cores generated by eleos.cores.create_sensitivity_analysis
- parent_directory
The directory containing the sensitivity cores
- Type:
str
- results
A list of NemesisResult objects for each core
- Type:
list[NemesisResult]
- baseline
The baseline result, an alias for results[0]
- Type:
- params
A DataFrame detailing which parameters were varied in each core and their value
- Type:
pandas.DataFrame
- __init__(parent_directory)[source]
- Parameters:
parent_directory (str) – The directory containing all the individual cores
- get_results(profile_label, parameter)[source]
Get the cores that varied the given parameter in the given profile.
- Parameters:
profile_label – The label of the profile
parameter – The parameter that was varied
- Returns:
A list of NemesisResult objects that varied the given parameter in the given profile
- Return type:
list[NemesisResult]
- plot_parameter(ax, profile_label, parameter)[source]
Plot the sensitivity of the model to the given parameter in the given profile.
- Parameters:
ax – The matplotlib.Axes object to plot to. If omitted then create a new Figure and Axes
profile_label – The label of the profile to plot
parameter – The variable to plot
- Returns:
The Figure object to which the Axes belong matplotlib.Axes: The Axes object onto which the data was plotted
- Return type:
matplotlib.Figure
- savefig(name, fig=None, **kwargs)[source]
Save a matplotlib figure to a file in the parent_directory.
- Parameters:
name (str) – The name of the file to save the figure as.
fig (matplotlib.Figure, optional) – The figure to save. If None, the current figure will be saved. Default is None.
**kwargs – Additional keyword arguments to pass to savefig.
- Returns:
None
- eleos.results.load_best_cores(parent_directory, n, failed='warn')[source]
Load n cores from the parent_directory with the lowest chi-squared values.
- Parameters:
parent_directory (str) – The directory containing all the individual core directories
n (int) – The number of cores to load
- Returns:
A list containing the result object for each core, sorted by chi-squared value (so lowest chi-sqared is index 0 in the list)
- Return type:
list[NemesisResult]
- eleos.results.load_multiple_cores(parent_directory, failed='warn')[source]
Read in all the cores in a given directory and return a list of NemesisResult objects.
- Parameters:
parent_directory (str) – The directory containing all the individual core directories
failed (str) – Whether to raise an error if a retieval failed (‘raise’) or to warn and skip it (‘warn’), or silently skip (‘skip’)
- Returns:
A list containing the result object for each core
- Return type:
list[NemesisResult]
- eleos.results.load_parallelised_cores(parent_directory)[source]
Given a directory of cores generated with cores.parallelise_forward, load them and recombine into a single NemesisResult object. The chi-sq of the core will be set to None, and the chi_sqs attribute will be set to the chi squared values of each chunk (ie, chi squared as a coarse function of wavelength)
- Parameters:
parent_directory (str) – Path to the directory of cores
- Returns:
The recombined results object
- Return type:
eleos.shapes
Each Shape object represents a differnet model in NEMESIS. Eg. Shape1 represents profile shape 1 which is a constant VMR
up to a knee pressure then a fractional scale height. For a ful list of possible models see the NEMESIS manual. Please note:
due to the large number of profile shapes NEMESIS supports,
Adding a Shape subclass
- All subclasses of Shape must implement:
ID: Integer ID of the shape in NEMESIS
CONSTANTS: The names of parameters that are not fitted by NEMESIS but required for the model
VARIABLES: The names of the parameters in order they appear in the mre file (do not include error parameters here). These MUST be defined in the order that they appear in the .apr file!!
- generate_apr_data: Returns a string of the profile shape parameters in the format
that the .apr file expects.
Additionally, some shapes require additional files in the core (eg. tempapr.dat). If this is the case, override the create_required_files method.
Finally, add the new ShapeN class to the ALL_SHAPES list at the end of the file.
Class template:
@shapeclass
class ShapeN(Shape):
"copy the desciption from the NEMESIS manual here (use triple quotes!)"
ID: ClassVar[int] = N
CONSTANTS: ClassVar[list[str]] = ["arg_name_1", ...]
VARIABLES: ClassVar[list[str]] = ["arg_name_2", "arg_name_3", ...]
arg_name_1: type_1
arg_name_2: type_2
arg_name_2_error: type_2
...
def generate_apr_data(self):
return a string for apr file
# optionally
def create_required_files(self, directory):
shutil.copy(..., directory)
- eleos.shapes.ALL_SHAPES = [<class 'eleos.shapes.Shape0'>, <class 'eleos.shapes.Shape1'>, <class 'eleos.shapes.Shape2'>, <class 'eleos.shapes.Shape4'>, <class 'eleos.shapes.Shape20'>, <class 'eleos.shapes.Shape32'>, <class 'eleos.shapes.Shape37'>, <class 'eleos.shapes.Shape47'>, <class 'eleos.shapes.Shape48'>]
A list of all the Shape classes
- class eleos.shapes.Shape[source]
Bases:
object- check_validity()[source]
Check that the parameters for the Shape are valid. This should be overridden by subclasses
- create_required_files(directory)[source]
Some Shapes require additional files to be created/copied into the core directory
- generate_apr_data()[source]
Generate the section of the .apr file that stores the shape parameters
- Parameters:
None
- Returns:
The string to write to the .apr file
- Return type:
str
- sample_from_distribution(**kwargs)[source]
Set parameters of the Shape to random values pulled from a normal distribution, with arguments mean_[parameter] and std_[parameter]. For example: calling Shape4.sample_from_distribution(mean_deep_vmr=0.1, std_deep_vmr=0.05) will set the deep vmr to a random value drawn from a gaussian with the centre at 0.1 and a standard deviation of 0.05. Multiple parameters may be specified at once.
- Parameters:
mean_[parameter] (*) – The mean of the distribution to sample for parameter [parameter]
std_[parameter] (*) – The standard deviation of the distribution to sample for parameter [parameter]
- Returns:
None
- class eleos.shapes.Shape0(filepath: str | None = None, values: list[float] | None = None, errors: list[float] | None = None)[source]
Bases:
ShapeProfile is to be treated as continuous over the pressure range of runname.ref, the next line of the .apr file should then contain a filename, which specifies the a priori profile as a function of height and should have the same number of levels as the .ref file.
In Eleos, one can specify either a filepath or give the values and error to be used directly.
- Parameters:
filepath (str, optional) – Path to the input profile file.
values (list[float], optional) – Profile values to be written if no file is given.
errors (list[float], optional) – Error values corresponding to values.
- CONSTANTS: ClassVar[list[str]] = []
- ID: ClassVar[int] = 0
- VARIABLES: ClassVar[list[str]] = []
- __init__(filepath: str | None = None, values: list[float] | None = None, errors: list[float] | None = None) None
Do not instantiate directly, use a subclass
- create_required_files(directory)[source]
Some Shapes require additional files to be created/copied into the core directory
- errors: list[float] = None
- filepath: str = None
- generate_apr_data()[source]
Generate the section of the .apr file that stores the shape parameters
- Parameters:
None
- Returns:
The string to write to the .apr file
- Return type:
str
- values: list[float] = None
- class eleos.shapes.Shape1(knee_pressure: float, deep_vmr: float, deep_vmr_error: float, fsh: float, fsh_error: float)[source]
Bases:
ShapeProfile is to be represented as a deep VMR up to a certain ‘knee’ pressure, and then a defined fractional scale height.
- Parameters:
knee_pressure (float) – Pressure at which the transition occurs.
deep_vmr (float) – Deep volume mixing ratio.
deep_vmr_error (float) – Error estimate for deep_vmr.
fsh (float) – Fractional scale height.
fsh_error (float) – Error estimate for fsh.
- CONSTANTS: ClassVar[list[str]] = ['knee_pressure']
- ID: ClassVar[int] = 1
- VARIABLES: ClassVar[list[str]] = ['deep_vmr', 'fsh']
- __init__(knee_pressure: float, deep_vmr: float, deep_vmr_error: float, fsh: float, fsh_error: float) None
Do not instantiate directly, use a subclass
- check_validity()[source]
Check that the parameters for the Shape are valid. This should be overridden by subclasses
- deep_vmr: float
- deep_vmr_error: float
- fsh: float
- fsh_error: float
- generate_apr_data()[source]
Generate the section of the .apr file that stores the shape parameters
- Parameters:
None
- Returns:
The string to write to the .apr file
- Return type:
str
- knee_pressure: float
- class eleos.shapes.Shape2(scale_factor: float, scale_factor_error: float)[source]
Bases:
ShapeProfile is to be represented by a simple scaling of the corresponding profile runname.ref, aerosol.ref, parah2.ref or fcloud.ref.
- Parameters:
scale_factor (float) – Scaling factor applied to the reference profile.
scale_factor_error (float) – Error estimate for scale_factor.
- CONSTANTS: ClassVar[list[str]] = []
- ID: ClassVar[int] = 2
- VARIABLES: ClassVar[list[str]] = ['scale_factor']
- __init__(scale_factor: float, scale_factor_error: float) None
Do not instantiate directly, use a subclass
- generate_apr_data()[source]
Generate the section of the .apr file that stores the shape parameters
- Parameters:
None
- Returns:
The string to write to the .apr file
- Return type:
str
- scale_factor: float
- scale_factor_error: float
- class eleos.shapes.Shape20(knee_pressure: float, tropopause_pressure: float, deep_vmr: float, deep_vmr_error: float, fsh: float, fsh_error: float)[source]
Bases:
ShapeSimilar to Shape1, but profile forced to a small number above tropopause.
- Parameters:
knee_pressure (float) – Pressure at which the transition occurs.
tropopause_pressure (float) – Pressure representing the tropopause.
deep_vmr (float) – Deep volume mixing ratio.
deep_vmr_error (float) – Error estimate for deep_vmr.
fsh (float) – Fractional scale height.
fsh_error (float) – Error estimate for fsh.
- CONSTANTS: ClassVar[list[str]] = ['knee_pressure', 'tropopause_pressure']
- ID: ClassVar[int] = 20
- VARIABLES: ClassVar[list[str]] = ['deep_vmr', 'fsh']
- __init__(knee_pressure: float, tropopause_pressure: float, deep_vmr: float, deep_vmr_error: float, fsh: float, fsh_error: float) None
Do not instantiate directly, use a subclass
- check_validity()[source]
Check that the parameters for the Shape are valid. This should be overridden by subclasses
- deep_vmr: float
- deep_vmr_error: float
- fsh: float
- fsh_error: float
- generate_apr_data()[source]
Generate the section of the .apr file that stores the shape parameters
- Parameters:
None
- Returns:
The string to write to the .apr file
- Return type:
str
- knee_pressure: float
- tropopause_pressure: float
- class eleos.shapes.Shape32(base_pressure: float, base_pressure_error: float, opacity: float, opacity_error: float, fsh: float, fsh_error: float)[source]
Bases:
ShapeCloud profile with variable base pressure, opacity, and fractional scale height.
- Parameters:
base_pressure (float) – Cloud base pressure (bar).
base_pressure_error (float) – Error estimate for base_pressure.
opacity (float) – Cloud opacity (log-scaled).
opacity_error (float) – Error estimate for opacity.
fsh (float) – Fractional scale height (log-scaled).
fsh_error (float) – Error estimate for fsh.
- CONSTANTS: ClassVar[list[str]] = []
- ID: ClassVar[int] = 32
- VARIABLES: ClassVar[list[str]] = ['opacity', 'fsh', 'base_pressure']
- __init__(base_pressure: float, base_pressure_error: float, opacity: float, opacity_error: float, fsh: float, fsh_error: float) None
Do not instantiate directly, use a subclass
- base_pressure: float
- base_pressure_error: float
- check_validity()[source]
Check that the parameters for the Shape are valid. This should be overridden by subclasses
- fsh: float
- fsh_error: float
- generate_apr_data()[source]
Generate the section of the .apr file that stores the shape parameters
- Parameters:
None
- Returns:
The string to write to the .apr file
- Return type:
str
- opacity: float
- opacity_error: float
- class eleos.shapes.Shape37(bottom_pressure: float, top_pressure: float, opacity: float, opacity_error: float)[source]
Bases:
ShapeCloud with constant opacity/bar between two pressure levels.
- Parameters:
bottom_pressure (float) – Bottom pressure level (bar).
top_pressure (float) – Top pressure level (bar).
opacity (float) – Cloud opacity per bar.
opacity_error (float) – Error estimate for opacity.
- CONSTANTS: ClassVar[list[str]] = ['bottom_pressure', 'top_pressure']
- ID: ClassVar[int] = 37
- VARIABLES: ClassVar[list[str]] = ['opacity']
- __init__(bottom_pressure: float, top_pressure: float, opacity: float, opacity_error: float) None
Do not instantiate directly, use a subclass
- bottom_pressure: float
- check_validity()[source]
Check that the parameters for the Shape are valid. This should be overridden by subclasses
- generate_apr_data()[source]
Generate the section of the .apr file that stores the shape parameters
- Parameters:
None
- Returns:
The string to write to the .apr file
- Return type:
str
- opacity: float
- opacity_error: float
- top_pressure: float
- class eleos.shapes.Shape4(knee_pressure: float, knee_pressure_error: float, deep_vmr: float, deep_vmr_error: float, fsh: float, fsh_error: float)[source]
Bases:
ShapeVery similar to Shape1, but knee pressure is also a variable parameter.
- Parameters:
knee_pressure (float) – Pressure at which the transition occurs.
knee_pressure_error (float) – Error estimate for knee_pressure.
deep_vmr (float) – Deep volume mixing ratio.
deep_vmr_error (float) – Error estimate for deep_vmr.
fsh (float) – Fractional scale height.
fsh_error (float) – Error estimate for fsh.
- CONSTANTS: ClassVar[list[str]] = []
- ID: ClassVar[int] = 4
- VARIABLES: ClassVar[list[str]] = ['deep_vmr', 'fsh', 'knee_pressure']
- __init__(knee_pressure: float, knee_pressure_error: float, deep_vmr: float, deep_vmr_error: float, fsh: float, fsh_error: float) None
Do not instantiate directly, use a subclass
- check_validity()[source]
Check that the parameters for the Shape are valid. This should be overridden by subclasses
- deep_vmr: float
- deep_vmr_error: float
- fsh: float
- fsh_error: float
- generate_apr_data()[source]
Generate the section of the .apr file that stores the shape parameters
- Parameters:
None
- Returns:
The string to write to the .apr file
- Return type:
str
- knee_pressure: float
- knee_pressure_error: float
- class eleos.shapes.Shape47(central_pressure: float, central_pressure_error: float, pressure_width: float, pressure_width_error: float, opacity: float, opacity_error: float)[source]
Bases:
ShapeCloud centred at specified pressure with variable FWHM and opacity.
- Parameters:
central_pressure (float) – Pressure where cloud distribution peaks (bar).
central_pressure_error (float) – Error estimate for central_pressure (bar).
pressure_width (float) – Full width at half maximum in log pressure units.
pressure_width_error (float) – Error estimate for pressure_width.
opacity (float) – Total cloud opacity.
opacity_error (float) – Error estimate for opacity.
- CONSTANTS: ClassVar[list[str]] = []
- ID: ClassVar[int] = 47
- VARIABLES: ClassVar[list[str]] = ['opacity', 'central_pressure', 'pressure_width']
- __init__(central_pressure: float, central_pressure_error: float, pressure_width: float, pressure_width_error: float, opacity: float, opacity_error: float) None
Do not instantiate directly, use a subclass
- central_pressure: float
- central_pressure_error: float
- check_validity()[source]
Check that the parameters for the Shape are valid. This should be overridden by subclasses
- generate_apr_data()[source]
Generate the section of the .apr file that stores the shape parameters
- Parameters:
None
- Returns:
The string to write to the .apr file
- Return type:
str
- opacity: float
- opacity_error: float
- pressure_width: float
- pressure_width_error: float
- class eleos.shapes.Shape48(base_pressure: float, base_pressure_error: float, top_pressure: float, top_pressure_error: float, opacity: float, opacity_error: float, fsh: float, fsh_error: float)[source]
Bases:
ShapeCloud profile with variable base, top pressure, opacity, and scale height.
- Parameters:
base_pressure (float) – Cloud base pressure (bar).
base_pressure_error (float) – Error estimate for base_pressure (bar).
top_pressure (float) – Cloud top pressure (bar).
top_pressure_error (float) – Error estimate for top_pressure (bar).
opacity (float) – Cloud opacity.
opacity_error (float) – Error estimate for opacity.
fsh (float) – Fractional scale height.
fsh_error (float) – Error estimate for fsh.
- CONSTANTS: ClassVar[list[str]] = []
- ID: ClassVar[int] = 48
- VARIABLES: ClassVar[list[str]] = ['opacity', 'fsh', 'base_pressure', 'top_pressure']
- __init__(base_pressure: float, base_pressure_error: float, top_pressure: float, top_pressure_error: float, opacity: float, opacity_error: float, fsh: float, fsh_error: float) None
Do not instantiate directly, use a subclass
- base_pressure: float
- base_pressure_error: float
- check_validity()[source]
Check that the parameters for the Shape are valid. This should be overridden by subclasses
- fsh: float
- fsh_error: float
- generate_apr_data()[source]
Generate the section of the .apr file that stores the shape parameters
- Parameters:
None
- Returns:
The string to write to the .apr file
- Return type:
str
- opacity: float
- opacity_error: float
- top_pressure: float
- top_pressure_error: float
eleos.spectra
- eleos.spectra.add_error_cubes(observations)[source]
Add the error cube from a JWST observation to a list (or a single) planetmapper.Observation object, accessible using the new Observation.error attribute.
- Parameters:
observations – planetmapper.Observation or List[planetmapper.Observation]: The observation(s) to add errors for
- Returns:
planetmapper.Observation or List[planetmapper.Observation]: The observation(s) with added errors
- Return type:
observations
- eleos.spectra.combine_multiple_spectra(*spectra_units)[source]
Combine multiple spectra with errors. Preserves original wavelength resolution in non-overlapping regions and uses weighted average (inverse variance) in overlaps.
- Parameters:
*spectra_units – Tuples of (wavelength, spectrum, error), where each element is a 1D array.
- Returns:
Stitched wavelength grid spectrum (np.array): Combined spectral values error (np.array): Combined errors
- Return type:
wavelengths (np.array)
- eleos.spectra.convolve_gaussian(wavelength, data, R, lambda0)[source]
Convolve a spectrum with a Gaussian, assuming constant R. In reality resolution varies as a function of wavelength and depends on the filters used (for JWST/NIRSpec see https://jwst-docs.stsci.edu/jwst-near-infrared-spectrograph/nirspec-instrumentation/nirspec-dispersers-and-filters)
- Parameters:
wavelength (np.ndarray) –
Wavelength array (same length as data).
data (np.ndarray): The data to be convolved.
R (float) – Resolving power of the instrument
lambda0 (float) – The wavelength at which R is defined. For G395H this is ~4um. For G235H this is ~2.4um.
- Returns:
The convolved data.
- Return type:
np.ndarray
- eleos.spectra.downsample_spectrum(wavelengths, spectrum, errors=None, num_points=100, special_regions=None)[source]
Downsample a spectrum to a given number of spectral points.
- Parameters:
wavelengths (np.ndarray) – The corresponding wavelengths
spectrum (np.ndarray) – The spectral data
error (np.ndarray) – The error on the spectral data (optional)
num_points (int) – The number of points to reduce the spectrum to
(dict([int (special_regions) – int)): A dict of regions of the form {(start, end): num_points} where the spectrum should be downsampled to a specific number of points. Use -1 for full-resolution sampling
int] – int)): A dict of regions of the form {(start, end): num_points} where the spectrum should be downsampled to a specific number of points. Use -1 for full-resolution sampling
- Returns:
The trimmed wavelengths spectrum (np.ndarray): The trimmed spectrum errors (np.ndarray): The trimmed errors (if provided)
- Return type:
wavelengths (np.ndarray)
- eleos.spectra.flatten_tiles(filepaths)[source]
Flatten a set of navigated cubes into a single dataframe of spaxels
- eleos.spectra.get_observations(pattern, add_errors=True)[source]
Get a list of planetmapper.Observation objects from a glob-style file pattern
- Parameters:
pattern (str) – The pattern to use to search for .fits files
add_errors (bool) – Whether to add the error cubes as an attribute (Observation.error)
- Returns:
The found observations
- Return type:
List[planetmapper.Observation]
- eleos.spectra.get_single_spectra(file_pattern, out_filename=None, max_emission=99, margins=0, pct_error=0, num_points=None, min_wl=-999, max_wl=999)[source]
Get a single spectrum from multiple observations, with options to restrict emission angle, downsample, and restrict wavelength range. Saves the output to a .spx file.
- Parameters:
file_pattern (str) – File pattern to match observation files.
out_filename (str) – Output filename template for saving the processed spectrum (if None then don’t save). This can contain any of the parameters passed into the function surrounded by curly braces. eg. “spectra_n{num_points}.spx” will become “spectra_n80.spx” if num_points=80 is passed in.
max_emission (float) – Maximum allowable emission angle.
margins (int) – Number of pixels around the edge of the image to remove.
pct_error (float) – Flat percentage error to apply to the spectrum.
num_points (int) – Number of points to downsample the spectrum to.
min_wl (float) – Minimum wavelength in the spectrum.
max_wl (float) – Maximum wavelength in the spectrum.
- Returns:
The wavelengths in the new .spx file np.ndarray: The radiances in the new spx file (returns MJy/sr, writes W/cm2/sr/um to the .spx file) np.ndarray: The radiance error in the new spx file (same units as radiance)
- Return type:
np.ndarray
- eleos.spectra.groupby(filepaths, by='EMISSION', binsize=2, binstart=0, binend=90, rmsd_threshold=10, filters=None)[source]
Group spaxels from a set of JWST navigated cubes by a given backplane value.
- Parameters:
filepaths (List(str)) – List of filepaths to tiles to use
by (str) – The planetmapper backplane name to group by
binsize (float) – The size of the bins to group by
binstart (float) – The start of the first bin (if None then use min of backplane)
binend (float) – The end of the last bin (if None then use max of backplane)
rmsd_threshold (int) – Reject any spaxels that are in the top x percentile for root-mean-square deviation from the median
filters (dict) – Apply any filters to remove spaxels before averaging. Format is key=planetmapper backplane name (str) and value=(min, max). For example, filters={‘EMISSION’:(0, 70)} will accept only spaxels with emission angles between 0 and 70
- Returns:
Indexed with bin midpoints, columns are wavelength, spectrum, error, num_spaxels, **average value of backplanes
- Return type:
pd.DataFrame
- eleos.spectra.margin_trim(cube, margin_size=3)[source]
Set the outer rings of spaxels in a cube to NaN.
- Parameters:
cube (np.ndarray) – The spectral cube to trim with shape (wavelengths, x, y).
margin_size (int) – The size of the margin to trim from each edge (eg. 2 will set every spaxel within 2 spaxels of the edge to NaN).
- Returns:
The trimmed spectral cube with NaN values in the margins.
- Return type:
np.ndarray
- eleos.spectra.quickview(wavelength, spectrum, errors=None, log=True, block=True)[source]
Quickly view a spectrum using matplotlib.
- Parameters:
wavelength (np.ndarray) – The wavelength grid
spectrum (np.ndarray) – The spectral data
errors (np.ndarray) – The error on the spectral data (optional)
log (bool) – Whether to use a logarithmic scale for the y-axis
block (bool) – Whether to block the execution until the plot is closed (default True
- eleos.spectra.resample_to_new(wavelength_source, spectrum_source, wavelength_target, kind='linear', fill_value='extrapolate')[source]
Resample a spectrum onto a new wavelength grid via interpolation.
- Parameters:
wavelength_source (array-like) – Original wavelength values of the spectrum (must be sorted).
spectrum_source (array-like) – Spectrum values corresponding to wavelength_source.
wavelength_target (array-like) – Target wavelength grid to resample onto.
kind (str, optional) – Interpolation type. Options include “linear”, “nearest”, “cubic”, etc. Defaults to “linear”.
fill_value (str or float, optional) – Value to use outside the range of wavelength_source. If “extrapolate”, allows extrapolation. Defaults to “extrapolate”.
- Returns:
Spectrum values resampled onto the wavelength_target grid.
- Return type:
np.ndarray
- eleos.spectra.subtract_ch4(wavelengths, spectrum, nlines=25, linewidth=0.008, A0=1e-06, lineshape='voigt', return_model=False)[source]
Subtract the brightest N individual CH4 lines from a spectrum.
- Parameters:
wavelengths (np.ndarray) – The wavelength grid
spectrum (np.ndarray) – The spectral data in units of W/cm2/sr/um
nlines (int) – The number of peaks to fit
linewidth (float) – The intial guess for the line FWHM in microns
A0 (float) – The initial guess for the amplitude of the lines
lineshape (str) – The shape of the lines to use, either ‘gaussian’, ‘lorentzian’, or ‘voigt’
return_model (bool) – If True, then return the model spectrum as well as the final spectrum
- Returns:
The spectrum with CH4 subtracted in units of W/cm2/sr/um
- Return type:
np.ndarray
- eleos.spectra.subtract_h3p(wavelengths, spectrum, latitude=-60, region=(3.525, 3.55), return_model=False, **h3p_kwargs)[source]
Subtract H3+ emission from a spectrum
- Parameters:
wavelengths (np.ndarray) – Wavelength grid
spectrum (np.ndarray) – Measured spectrum in units of W/cm2/sr/um
latitude (float) – Optionally specify a latitude to make a more informed guess at initial values
region (float, float) – The region to use to fit the H3+ model (by default this is a triple of bright lines)
return_model (bool) – If True, then return the h3p object used for the fit
- Returns:
Spectrum with H3+ subtracted in units of W/cm2/sr/um h3ppy.h3p: If return_model, the h3p object that was used to fit
- Return type:
np.ndarray
- eleos.spectra.subtract_non_lte(wavelengths, spectrum)[source]
Utility function for combining subtract_h3p and subtract_ch4. For more fine-grained control, use those function independently.
- Parameters:
wavelengths (np.ndarray) – Wavelength grid (microns)
spectrum (np.ndarray) – Spectral data (in units of W/cm2/sr/um)
- Returns:
The wavelength grid (unchanged) np.ndarray: The spectrum with H3+ and CH4 removed
- Return type:
np.ndarray
- eleos.spectra.wavelength_select(wavelengths, spectrum, errors=None, min_wl=None, max_wl=None, epsilon=0)[source]
Select a range of wavelengths from a spectrum.
- Parameters:
wavelengths (np.ndarray) – The wavelength grid
spectrum (np.ndarray) – The spectral data
errors (np.ndarray) – The error on the spectral data (optional)
min_wl (float) – The minimum wavelength to select
max_wl (float) – The maximum wavelength to select
epsilon (float) – A small fudge factor to the end of the mask to fix FPE when grouping spectra
- Returns:
The trimmed wavelengths spectrum (np.ndarray): The trimmed spectrum errors (np.ndarray): The trimmed errors (if provided)
- Return type:
wavelengths (np.ndarray)
- eleos.spectra.zonal_average_tiles(filepaths, lat_width, error_scale=1, rmsd_threshold=10, filters=None)[source]
Get the zonal averages from a set of JWST navigated cubes.
- Parameters:
filepaths (List(str)) – List of filepaths to tiles to use in the averaging
lat_width (float) – The width of the latitude bins. The given latitude is in the centre of the bin.
error_scale (float) – Multiply the average error by this amount (unused so far)
rmsd_threshold (int) – Reject any spaxels that are in the top x percentile for root-mean-square deviation from the median
filters (dict) – Apply any filters to remove spaxels before averaging. Format is key=planetmapper backplane name (str) and value=(min, max). For example, filters={‘EMISSION’:(0, 70)} will reject any spaxels with emission angle greater than 70
- Returns:
Wavelength grid, temporary - will be added to df later pandas.DataFrame: DataFrame containing the zonal means and information for .spx files.
Columns are spectrum, error (np.ndarrays), phase, emission, azimuth, lon (floats), num_spaxels (int). Use df.index to get latitudes
- Return type:
np.ndarray
eleos.spx
- class eleos.spx.SpxFileData(fwhm, lat, lon, geometries)[source]
Bases:
NamedTuple- fwhm: float
Alias for field number 0
- geometries: tuple[SpxGeometry, ...]
Alias for field number 3
- lat: float
Alias for field number 1
- lon: float
Alias for field number 2
- class eleos.spx.SpxGeometry(nav, lat, lon, phase, emission, azimuth, wgeom, wavelengths, spectrum, error)[source]
Bases:
NamedTuple- azimuth: float
Alias for field number 5
- emission: float
Alias for field number 4
- error: ndarray
Alias for field number 9
- lat: float
Alias for field number 1
- lon: float
Alias for field number 2
Alias for field number 0
- phase: float
Alias for field number 3
- spectrum: ndarray
Alias for field number 8
- wavelengths: ndarray
Alias for field number 7
- wgeom: float
Alias for field number 6
- eleos.spx.construct_spx(wavelengths: ndarray, spectrum: ndarray, error: ndarray, convert: bool = True, *, fwhm: float, lat: float, lon: float, phase: float, emission: float, azimuth: float) SpxFileData[source]
Construct an SpxFileData object from the given data.
The units should be MJy/sr if convert is True, else W/cm2/sr/um.
- eleos.spx.convert_MJysr_to_Wcm2srum(wavelengths: ndarray, spectrum: ndarray) ndarray[source]
Convert a spectrum or cube from MJy/sr to W/cm2/sr/micron.
- eleos.spx.convert_Wcm2srum_to_MJysr(wavelengths: ndarray, spectrum: ndarray) ndarray[source]
Convert a spectrum or cube from W/cm2/sr/micron to MJy/sr.
- eleos.spx.read(path: str) SpxFileData[source]
Read in a .spx file from disk.
The returned data is a SpxFileData object containing the data from the .spx file. For example, you can access the latitude of the observation with data.lat or the spectrum of the first geometry with data.geometries[0].spectrum.
- Parameters:
path – The path to the .spx file.
- Returns:
A SpxFileData object of the form (fwhm, lat, lon, geometries) containing the data from the .spx file.
- eleos.spx.write(path: str | Path, data: SpxFileData | None = None, convert: bool = True, **kwargs) None[source]
Write an SPX file to disk, for example:
- spx.write(
‘spectrum.spx’, wavelengths=wavelengths, spectrum=spectrum, # In MJy/sr if convert is False, else W/cm2/sr/um error=error, # In MJy/sr if convert is False, else W/cm2/sr/um fwhm=0, lat=20.0, lon=30.0, phase=0.0, emission=0.0, azimuth=0.0,
)
- Parameters:
path – The path to write the SPX file to.
data – An SpxFileData object to write to disk. If None, the data will be constructed from the keyword arguments.
kwargs – Keyword arguments to construct the SpxFileData object if data is None. These are passed to construct_spx.
eleos.utils
- eleos.utils.find_nearest(array, value)[source]
Get the closest item to a given value in a Numpy array
- Parameters:
array (np.ndarray) – The array to search in
value (float) – The value to find
- Returns:
The index of the closest item in the array float: The closest item in the array
- Return type:
int
- eleos.utils.indent(string, level=1, spaces_per_level=4)[source]
Take in a string and return the same string indented at each line break.
- Parameters:
string – The string to indent
level – The level at which to indent
spaces_per_level – How many spaces to add per level of indentation
- Returns:
The indented string
- Return type:
str
- eleos.utils.label_axes(axs, labels='abcdefghijklmnopqrstuvwxyz', append=')', loc=(0.01, 0.01), **kwargs)[source]
Take a list of mpl Axes and add alhpabetic labels to them.
- Parameters:
axs (mpl.Axes) – The axes to label
labels (Iterable) – The labels to use (default is lowercase alphabet)
append (str) – What to put after the label. default is ‘)’ for a final label of eg. ‘a)’
log (Tuple[float, float]) – The location of the label in Axes coordinates
**kwargs – Additional arguments passed to ax.text()
- Returns:
None
Take the average (mean) of a np array, ignoring NaN values
- Parameters:
data (np.ndarray) – The data to be averaged
weights (np.ndarray) – Optionally, weights for each point
np.ma.average() (kwargs passed to)
- Returns:
The averaged data
- Return type:
np.MaskedArray or float
- eleos.utils.read_between_lines(file, start, end)[source]
Take in an open file object and get the data between line numbers ‘start’ and ‘end’. It is inclusive of start and exclusive of end (ie. start <= line < end)
- Parameters:
file – File-like object to read from
start – Line number to start reading from
end – Line number to stop reading at
- Returns:
File data
- Return type:
str
- eleos.utils.reconstruct_real_n(wavenumbers, imag_n, ref_wavenumber, ref_realn, tol=1e-12)[source]
Kramers-Kronig reconstruction of the real refractive-index spectrum.
- Parameters:
wavenumbers (array_like) – Wavenumbers (length N). Can be ascending or descending.
imag_n (array_like) – Imaginary part of refractive index (length N).
ref_wavenumber (float) – Reference wavenumber at which real part ref_realn is specified.
ref_realn (float) – Real part of refractive index at ref_wavenumber.
tol (float, optional) – Small tolerance for comparing floating values to zero.
- Returns:
n (ndarray) – Reconstructed real part of refractive index (length N), in the same ordering as the input wavenumbers.
km (float) – Interpolated value of imaginary refractive index at ref_wavenumber.