Modules Documentation
This document details the modules of the multirex package.
spectra Module
MultiREx: A Python library for generating synthetic exoplanet transmission spectra.
This module provides classes and functions for creating planetary systems, generating synthetic spectra, and analyzing the results. It extends the functionalities of the TauREx library, enabling the massive generation of spectra and observations with added noise.
- The main classes in this module are:
Physics: Utility functions for spectrum generation and manipulation
Planet: Represents a planet with physical properties and atmosphere
Atmosphere: Defines atmospheric properties and composition
Star: Represents a star with physical properties
System: Combines a planet and star to generate transmission spectra
Multiverse: Generates multiple spectra with random parameter variations
- class multirex.spectra.Atmosphere(seed=None, temperature=None, base_pressure=None, top_pressure=None, composition=None, fill_gas=None)
Bases:
objectRepresents a plane parallel atmosphere with specified properties and composition.
This class allows you to define an atmosphere with properties like temperature and pressure, as well as its chemical composition. The composition is specified as a dictionary of gases with their mixing ratios in log10 values. The class supports both fixed values and random generation from ranges.
- seed
Random seed for reproducibility.
- Type:
int
- temperature
Temperature of the atmosphere in Kelvin.
- Type:
float
- base_pressure
Base (bottom) pressure of the atmosphere in Pa.
- Type:
float
- top_pressure
Top pressure of the atmosphere in Pa.
- Type:
float
- composition
Composition of the atmosphere with gases and their mixing ratios in log10 values (e.g., {“H2O”: -3, “CO2”: -2}).
- Type:
dict
- fill_gas
Gas or list of gases used as filler in the atmosphere composition to ensure the total mixing ratio equals 1.
- Type:
str or list
- original_params
The original parameters used to initialize the atmosphere, including any ranges specified for random generation.
- Type:
dict
Note
The mixing ratios in the composition dictionary are in log10 scale. For example, a value of -3 corresponds to a mixing ratio of 10^-3 = 0.001.
- add_gas(gas, mix_ratio)
Adds a gas to the atmosphere composition with a log10 mix ratio. If the gas already exists, its value is updated. Parameters: gas (str): Gas name. mix_ratio (float or tuple): Mix ratio of the gas in log10.
- property base_pressure
noindex:
- property composition
- property fill_gas
- get_params()
Returns the current parameters of the atmosphere.
- Returns:
- A dictionary containing the atmosphere’s parameters including temperature,
base_pressure, top_pressure, composition, fill_gas, and seed.
- Return type:
dict
- property original_params
- remove_gas(gas)
Removes a gas from the atmosphere composition. Parameters: gas (str): Gas name.
- reshuffle()
Regenerates the atmosphere based on original values or range of values.
- property seed
- set_base_pressure(value)
Sets the base pressure of the atmosphere. Parameters: value (float or tuple): Base pressure of the atmosphere in Pa (single value or range).
- set_composition(gases)
Sets the composition of the atmosphere. Parameters: gases (dict): Composition of the atmosphere with gases and mix ratios in log10 values. (eg.{“H2O”: -3, “CO2”: [-2,-1]})
- set_fill_gas(gas)
Sets the filler gas of the atmosphere. Parameters: gas (str or list): Gas or list of gases used as filler in the atmosphere composition.
- set_seed(value)
Sets the seed used for randomness.
- set_temperature(value)
Sets the temperature of the atmosphere, as an isothermal profile. Parameters: value (float or tuple): Temperature of the atmosphere in K (single value or range).
- set_top_pressure(value)
Sets the top pressure of the atmosphere. Parameters: value (float or tuple): Top pressure of the atmosphere in Pa (single value or range).
- property temperature
- property top_pressure
- validate()
Validates the atmosphere’s essential properties are defined, allowing for an undefined composition if fill_gas is present.
- validate_composition()
Validates that the sum of gas mix ratios in the atmosphere composition does not exceed 1. Also checks if the maximum possible values from ranges could exceed 1 and issues a warning.
- class multirex.spectra.Physics
Bases:
object- df2spectra()
Convert observations dataframe to spectra
- generate_df_SNR_noise(n_repeat, SNR, seed=None)
Generates a new DataFrame by applying Gaussian noise in a vectorized manner to the spectra, and then concatenates this result with another DataFrame containing other columns of information.
- Parameters:
df (DataFrame) – DataFrame with parameters and spectra. It must have attributes ‘params’ and ‘data’. Example: df.params, df.data
n_repeat (int) – How many times each spectrum is replicated.
SNR (float) – Signal-to-noise ratio for each observation.
seed (int, optional) – Seed for the random number generator. Default is None.
- Returns:
- New DataFrame with parameters and spectra with noise added in
the same format as the input DataFrame. The returned DataFrame has the attributes df.params and df.data.
- Return type:
DataFrame
- generate_parameter_space_values()
Generate a sequence of values for parameter space exploration.
This utility function handles different input types to generate a sequence of values:
If given a single value, returns a list with just that value
If given a tuple range (min, max), returns a list with a random value in that range
If given a list, returns the list unchanged
If given a dict with keys ‘min’, ‘max’, ‘n’, and optionally ‘distribution’, returns a sequence of n values between min and max with the specified distribution
If given None, returns None
- Parameters:
value –
The input value which can be: None: Returns None tuple (min, max): Returns a list with a random value between min and max list: Returns the list unchanged dict: With keys:
’min’: Minimum value ‘max’: Maximum value ‘n’: Number of points ‘distribution’: ‘linear’ or ‘log’ (default: ‘linear’)
Any other type: Returns a list with just that value
- Returns:
A list of values based on the input type
- Return type:
list
Examples
>>> Physics.generate_parameter_space_values(5) [5] >>> Physics.generate_parameter_space_values((1, 10)) # Returns random value between 1 and 10 [7.3546] >>> Physics.generate_parameter_space_values([1, 2, 3]) [1, 2, 3] >>> Physics.generate_parameter_space_values({'min': -10, 'max': -1, 'n': 10, 'distribution': 'linear'}) [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1] >>> Physics.generate_parameter_space_values({'min': 100, 'max': 1000, 'n': 4, 'distribution': 'log'}) [100, 215.44, 464.16, 1000]
- generate_value()
Generate a value based on the input type.
This utility function handles different input types to generate values:
If given a single value, returns that value
If given a tuple range (min, max), returns a random value in that range
If given a list, returns a random choice from the list
If given None, returns None
- Parameters:
value – The input value which can be: None: Returns None tuple (min, max): Returns a random value between min and max list: Returns a random element from the list Any other type: Returns the value unchanged
- Returns:
The generated value based on the input type
Examples
>>> Physics.generate_value(5) 5 >>> Physics.generate_value((1, 10)) # Returns random value between 1 and 10 7.3546 >>> Physics.generate_value(['red', 'green', 'blue']) # Returns random element 'green' >>> Physics.generate_value(None) None
- spectrum2altitude(Rp, Rs)
Converts the transit depth to the atmospheric effective altitude.
- Parameters:
spectrum (float) – Transit depth.
Rp (float) – Planet radius in Earth radii.
Rs (float) – Star radius in solar radii.
- Returns:
Atmospheric effective altitude in km.
- Return type:
float
- wavenumber_grid(wl_max, resolution)
Generate a wave number grid from a wavelength range and resolution.
This function converts a wavelength range (in microns) to a wavenumber grid (in cm^-1). The conversion uses the formula: wavenumber = 10000/wavelength, where wavelength is in microns and wavenumber is in cm^-1.
- Parameters:
wl_min (float) – Minimum wavelength in microns.
wl_max (float) – Maximum wavelength in microns.
resolution (int) – Number of points in the resulting grid.
- Returns:
Wave number grid in cm^-1, sorted in ascending order.
- Return type:
wn (np.array)
Notes
To convert back from wavenumber (cm^-1) to wavelength:
>>> wl = 10000/wn # in microns
Or to get wavelength in meters:
>>> wl = 10000/(wn*1e6) # in meters
- class multirex.spectra.Planet(seed=None, radius=None, mass=None, atmosphere=None)
Bases:
objectRepresents a planet with specified properties and an optional atmosphere.
This class allows you to define a planet with physical properties like radius and mass, and optionally attach an atmosphere with specific composition. The class supports both fixed values and random generation from ranges.
- seed
Random seed for reproducibility.
- Type:
int
- radius
Radius of the planet in Earth radii.
- Type:
float
- mass
Mass of the planet in Earth masses.
- Type:
float
- atmosphere
An Atmosphere object defining the planet’s atmosphere.
- Type:
- original_params
The original parameters used to initialize the planet, including any ranges specified for random generation.
- Type:
dict
- property atmosphere
- get_params()
Gets the current parameters of the planet and its atmosphere.
- Returns:
A dictionary of the planet’s parameters and its atmosphere’s parameters.
- Return type:
dict
- property mass
- property original_params
- property radius
- reshuffle(atmosphere=False)
Regenerates the planet’s attributes using the original values and optionally updates the atmosphere, excluding albedo.
- property seed
- set_atmosphere(value)
Define the atmosphere of the planet.
Parameters: value (Atmosphere): An Atmosphere multirex object.
- set_mass(value)
Define the mass of the planet. Parameters: value (float or tuple): Mass of the planet in Earth masses (single value or range).
- set_radius(value)
Sets the radius of the planet. Parameters: value (float or tuple): Radius of the planet in Earth radii (single value or range).
- set_seed(value)
Sets the seed used for randomness.
- validate()
Validates that all essential attributes of the planet are defined.
Returns: bool: True if all attributes are defined, False otherwise.
- class multirex.spectra.Star(seed=None, temperature=None, radius=None, mass=None, phoenix_path=None)
Bases:
objectRepresents a star with specified properties.
This class allows you to define a star with physical properties like temperature, radius, and mass. The class supports both fixed values and random generation from ranges. It can use either a blackbody model or the more sophisticated Phoenix stellar model.
- seed
Random seed for reproducibility.
- Type:
int
- temperature
Temperature of the star in Kelvin.
- Type:
float
- radius
Radius of the star in solar radii.
- Type:
float
- mass
Mass of the star in solar masses.
- Type:
float
- phoenix
Whether the star uses the Phoenix stellar model (True) or a simple blackbody model (False).
- Type:
bool
- phoenix_path
Path to the Phoenix model files. This parameter automates the management of Phoenix model files. Providing a path that lacks a ‘Phoenix’ folder prompts the automatic download of necessary model files into a newly created ‘Phoenix’ folder at the specified path. An empty string (“”) uses the current working directory.
- Type:
str, optional
- original_params
The original parameters used to initialize the star, including any ranges specified for random generation.
- Type:
dict
Note
When using the Phoenix stellar model, the appropriate model files will be automatically downloaded if they don’t exist at the specified path.
- get_params()
Retrieves the current parameters of the star.
- Returns:
A dictionary containing the star’s parameters.
- Return type:
dict
- property mass
- property radius
- reshuffle()
Regenerates the star’s attributes using the original values.
- property seed
- set_mass(value)
Sets the star’s mass. Can be a single value or a range for random generation. :param value: Mass in solar masses. :type value: float or tuple
- set_radius(value)
Sets the star’s radius. Can be a single value or a range for random generation. :param value: Radius in solar radii. :type value: float or tuple
- set_seed(value)
Sets the seed used for randomness and reproducibility. :param value: Seed value. :type value: int
- set_temperature(value)
Sets the star’s temperature. :param value: Temperature in Kelvin. :type value: float or tuple
- property temperature
- validate()
Validates that all essential attributes of the star are defined.
- Returns:
True if all essential attributes are defined and valid, False otherwise.
- Return type:
bool
- class multirex.spectra.System(planet, star, seed=None, sma=None)
Bases:
objectRepresents a planetary system consisting of a planet orbiting a star.
This class combines a Planet and a Star object to create a complete planetary system. It provides methods to generate transmission spectra, analyze spectral contributions from different atmospheric components, and simulate observations with noise.
- sma
Semi-major axis of the planet’s orbit in AU.
- Type:
float
- seed
Random seed for reproducibility.
- Type:
int
- transmission
The TauREx transmission model for the system, created after calling make_tm().
- Type:
TransmissionModel
- original_params
The original parameters used to initialize the system, including any ranges specified for random generation.
- Type:
dict
Note
After creating a System object, you must call make_tm() to generate the transmission model before generating spectra or observations.
- clone_frozen()
Creates a new System instance with the current state, without reshuffling.
- Returns:
A clone of the current System with the same current parameter values.
- Return type:
- clone_shuffled()
Creates a new System instance using the original initialization parameters, which will regenerate (reshuffle) the random values.
- Returns:
A freshly initialized System instance.
- Return type:
- explore_multiverse(wn_grid, snr=10, n_universes=1, labels=None, header=False, n_observations=1, spectra=True, observations=True, path=None, n_jobs=1)
Explore the multiverse by generating spectra and observations, and optionally save them in Parquet format.
- Parameters:
wn_grid (array) – Wave number grid.
snr (float, optional) – Signal-to-noise ratio. Defaults to 10.
n_universes (int, optional) – Number of universes to explore. One planet per universe is generated with properties drawn from the priors. Defaults to 1.
labels (list, optional) – Labels for atmospheric composition. Example: [[“CO2”, “CH4”], “CH4”]. Defaults to None.
header (bool, optional) – Whether to include header information (system parameters) in the output. Defaults to False.
n_observations (int, optional) – Number of observations to generate per spectrum. Defaults to 1.
spectra (bool, optional) – Whether to save the spectra. Defaults to True.
observations (bool, optional) – Whether to save the observations. Defaults to True.
path (str, optional) – Path to save the files. If not provided, files are not saved.
n_jobs (int, optional) – Number of parallel jobs to run. Defaults to 1 (sequential execution). Use -1 to utilize all available cores.
- Returns:
- Dictionary containing ‘spectra’ and/or ‘observations’ DataFrames depending on the arguments.
spectra (DataFrame): Spectra of the universes.
observations (DataFrame): Observations of the universes.
- Return type:
dict
Example
>>> system = System(planet, star, sma=1.0) >>> results = system.explore_multiverse(wn_grid, snr=10, n_universes=5, header=True)
- explore_parameter_space(wn_grid, parameter_space, snr=10, labels=None, header=False, n_observations=1, spectra=True, observations=True, path=None, n_jobs=1)
Explore a parameter space by systematically varying parameters across specified ranges.
This method allows for structured parameter space exploration by generating spectra for all combinations of parameter values specified in the parameter_space dictionary.
- Parameters:
wn_grid (array) – Wave number grid.
parameter_space (dict) –
Dictionary specifying the parameter space to explore. Each key should be a parameter path (e.g., ‘planet.atmosphere.temperature’) and each value should be one of:
A single value
A list of values
A dict with keys ‘min’, ‘max’, ‘n’, and optionally ‘distribution’
(‘linear’ or ‘log’)
snr (float, optional) – Signal-to-noise ratio. Defaults to 10.
labels (list, optional) – Labels for atmospheric composition. Example: [[“CO2”, “CH4”], “CH4”]. Defaults to None.
header (bool, optional) – Whether to include header information in the saved files. Defaults to False.
n_observations (int, optional) – Number of observations to generate. Defaults to 1.
spectra (bool, optional) – Whether to save the spectra. Defaults to True.
observations (bool, optional) – Whether to save the observations. Defaults to True.
path (str, optional) – Path to save the files. If not provided, files are not saved.
n_jobs (int, optional) – Number of jobs to run in parallel. Defaults to 1, meaning sequential execution. Use -1 to utilize all available cores.
- Returns:
- Dictionary containing ‘spectra’ and/or ‘observations’ DataFrames
depending on the arguments. - spectra (DataFrame): Spectra of the parameter space exploration. - observations (DataFrame): Observations of the parameter space exploration.
- Return type:
dict
Examples
>>> system = System(planet, star, sma=1.0) >>> parameter_space = { ... 'planet.atmosphere.temperature': {'min': 200, 'max': 400, 'n': 3}, ... 'planet.atmosphere.composition.CH4': { ... 'min': -10, 'max': -1, 'n': 10, 'distribution': 'linear' ... } ... } >>> wn_grid = Physics.wavenumber_grid(1.0, 10.0, 1000) >>> results = system.explore_parameter_space(wn_grid, parameter_space, snr=10)
- generate_contributions(wn_grid)
Generate a differentiated spectrum contribution based on a wave number grid.
- Parameters:
wn_grid (array) – Wave number grid.
- Returns:
- A tuple containing:
bin_wn (array): Wave number grid.
bin_rprs (dict): Fluxes in rp^2/rs^2 per contribution and molecule.
- Return type:
tuple
- generate_observations(wn_grid, snr, n_observations=1)
Generate simulated observations with noise based on the system’s spectrum.
This method generates synthetic observations by adding gaussian noise to the system’s transmission spectrum. The noise level is determined by the specified signal-to-noise ratio (SNR). Multiple observations can be generated at once.
- Parameters:
wn_grid (numpy.ndarray) – Wave number grid in cm^-1, defining the wavelengths at which the observations are made. Can be created using the Physics.wavenumber_grid() method.
snr (float) – Signal-to-noise ratio, used to determine the level of noise added to the observations. Higher values result in less noise.
n_observations (int, optional) – Number of noisy observations to generate. Defaults to 1.
- Returns:
DataFrame containing the simulated observations with added noise. The DataFrame has the following structure:
Columns labeled with wavelengths (from wn_grid) containing the fluxes in (Rp/Rs)^2 units with added noise.
’SNR’ column indicating the signal-to-noise ratio used.
’noise’ column showing the noise level added to each observation.
The DataFrame also has two special attributes: - df.params: Contains the system parameters and noise information. - df.data: Contains only the spectral data (wavelength columns).
- Return type:
pandas.DataFrame
- Raises:
ValueError – If no transmission model has been generated. Call make_tm() before using this method.
Examples
>>> system = System(planet, star, sma=1.0) >>> system.make_tm() >>> wn_grid = Physics.wavenumber_grid(1.0, 10.0, 1000) >>> observations = system.generate_observations(wn_grid, snr=10, n_observations=5)
- generate_spectrum(wn_grid)
Generate a transmission spectrum based on a wave number grid.
This method uses the system’s transmission model to generate a synthetic spectrum at the specified wave numbers. The transmission model must be created first by calling make_tm().
- Parameters:
wn_grid (numpy.ndarray) – Wave number grid in cm^-1. Can be created using
method. (the Physics.wavenumber_grid())
- Returns:
- A tuple containing:
bin_wn (numpy.ndarray): Binned wave number grid in cm^-1. bin_rprs (numpy.ndarray): Binned spectrum in (Rp/Rs)^2 units, representing the transit depth at each wavelength.
- Return type:
tuple
- Raises:
ValueError – If no transmission model has been generated. Call make_tm() before using this method.
Examples
>>> system = System(planet, star, sma=1.0) >>> system.make_tm() >>> wn_grid = Physics.wavenumber_grid(1.0, 10.0, 1000) >>> wn, spectrum = system.generate_spectrum(wn_grid)
- get_params()
Get the current parameters of the system.
- Returns:
A dictionary containing the system’s parameters including semi-major axis, seed, and all parameters from the planet and star.
- Return type:
dict
- make_tm()
Generate a transmission model for the system.
This method creates a TauREx transmission model based on the properties of the planet, star, and atmosphere. It is a necessary step before generating any spectra or observations. If you make any changes to the system properties, you must call this method again to update the transmission model.
The method configures: - The planet’s physical properties - The star’s properties (using Phoenix model if specified) - The atmosphere’s temperature profile (isothermal) - The atmosphere’s chemistry based on the composition - Contributions from absorption and Rayleigh scattering
- Returns:
- The transmission model is stored internally and can be accessed
through the transmission property.
- Return type:
None
- Raises:
ValueError – If the system configuration is invalid (e.g., missing essential attributes or invalid parameter values).
- property original_params
- property planet
- plot_contributions(wn_grid, showfig=True, showspectrum=True, xscale='linear', syslegend=True)
Plot the spectrum for each contribution and molecule.
- Parameters:
wn_grid (array) – Wave number grid (in cm-1).
showfig (bool, optional) – Whether to show the plot. Defaults to True.
showspectrum (bool, optional) – Whether to show the total spectrum. Defaults to True.
xscale (str, optional) – Scale for x-axis (‘linear’ or ‘log’). Defaults to ‘linear’.
syslegend (bool, optional) – Whether to show system legend. Defaults to True.
- Returns:
- A tuple containing:
fig (matplotlib.figure): Figure of the plot.
ax (matplotlib.axes): Axes of the plot.
- Return type:
tuple
- plot_spectrum(wn_grid, showfig=True, xscale='linear', syslegend=True)
Plot the spectrum.
- Parameters:
wn_grid (array) – Wave number grid (in cm-1).
showfig (bool, optional) – Whether to show the plot. Defaults to True.
xscale (str, optional) – Scale for x-axis (‘linear’ or ‘log’). Defaults to ‘linear’.
syslegend (bool, optional) – Whether to show system legend. Defaults to True.
- Returns:
- A tuple containing:
fig (matplotlib.figure): Figure of the plot.
ax (matplotlib.axes): Axes of the plot.
- Return type:
tuple
- reshuffle()
Regenerates the system’s attributes using the original values.
- property seed
- set_planet(value)
Define the planet of the system. Parameters: value (Planet): A Planet object of multirex.
- set_seed(value)
Sets the seed used for randomness.
- set_sma(value)
Define the semi-major axis of the planet’s orbit. Args: value (float or tuple): Semi-major axis of the planet’s orbit in AU (single value or range).
- set_star(value)
Define the star of the system. Args: value (Star): A Star object of multirex.
- property sma
- property star
- property transmission
Get the transmission model of the system.
- validate()
Validates that all essential attributes of the system are defined.
Returns: bool: True if all essential attributes are defined, False otherwise.
- multirex.spectra.generate_df_SNR_noise(df, n_repeat, SNR, seed=None)
Generates a new DataFrame by applying Gaussian noise in a vectorized manner to the spectra, and then concatenates this result with another DataFrame containing other columns of information.
- Parameters:
df (DataFrame) – DataFrame with parameters and spectra. It must have attributes ‘params’ and ‘data’. Example: df.params, df.data
n_repeat (int) – How many times each spectrum is replicated.
SNR (float) – Signal-to-noise ratio for each observation.
seed (int, optional) – Seed for the random number generator. Default is None.
- Returns:
- New DataFrame with parameters and spectra with noise added in
the same format as the input DataFrame. The returned DataFrame has the attributes df.params and df.data.
- Return type:
DataFrame
- multirex.spectra.generate_parameter_space_values(value)
Generate a sequence of values for parameter space exploration.
This utility function handles different input types to generate a sequence of values:
If given a single value, returns a list with just that value
If given a tuple range (min, max), returns a list with a random value in that range
If given a list, returns the list unchanged
If given a dict with keys ‘min’, ‘max’, ‘n’, and optionally ‘distribution’, returns a sequence of n values between min and max with the specified distribution
If given None, returns None
- Parameters:
value –
The input value which can be: None: Returns None tuple (min, max): Returns a list with a random value between min and max list: Returns the list unchanged dict: With keys:
’min’: Minimum value ‘max’: Maximum value ‘n’: Number of points ‘distribution’: ‘linear’ or ‘log’ (default: ‘linear’)
Any other type: Returns a list with just that value
- Returns:
A list of values based on the input type
- Return type:
list
Examples
>>> Physics.generate_parameter_space_values(5) [5] >>> Physics.generate_parameter_space_values((1, 10)) # Returns random value between 1 and 10 [7.3546] >>> Physics.generate_parameter_space_values([1, 2, 3]) [1, 2, 3] >>> Physics.generate_parameter_space_values({'min': -10, 'max': -1, 'n': 10, 'distribution': 'linear'}) [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1] >>> Physics.generate_parameter_space_values({'min': 100, 'max': 1000, 'n': 4, 'distribution': 'log'}) [100, 215.44, 464.16, 1000]
- multirex.spectra.generate_value(value)
Generate a value based on the input type.
This utility function handles different input types to generate values:
If given a single value, returns that value
If given a tuple range (min, max), returns a random value in that range
If given a list, returns a random choice from the list
If given None, returns None
- Parameters:
value – The input value which can be: None: Returns None tuple (min, max): Returns a random value between min and max list: Returns a random element from the list Any other type: Returns the value unchanged
- Returns:
The generated value based on the input type
Examples
>>> Physics.generate_value(5) 5 >>> Physics.generate_value((1, 10)) # Returns random value between 1 and 10 7.3546 >>> Physics.generate_value(['red', 'green', 'blue']) # Returns random element 'green' >>> Physics.generate_value(None) None
- multirex.spectra.wavenumber_grid(wl_min, wl_max, resolution)
Generate a wave number grid from a wavelength range and resolution.
This function converts a wavelength range (in microns) to a wavenumber grid (in cm^-1). The conversion uses the formula: wavenumber = 10000/wavelength, where wavelength is in microns and wavenumber is in cm^-1.
- Parameters:
wl_min (float) – Minimum wavelength in microns.
wl_max (float) – Maximum wavelength in microns.
resolution (int) – Number of points in the resulting grid.
- Returns:
Wave number grid in cm^-1, sorted in ascending order.
- Return type:
wn (np.array)
Notes
To convert back from wavenumber (cm^-1) to wavelength:
>>> wl = 10000/wn # in microns
Or to get wavelength in meters:
>>> wl = 10000/(wn*1e6) # in meters
utils Module
MultiREx Utilities Module
This module provides utility functions for the MultiREx library, primarily focused on downloading and managing external data files needed for spectrum generation.
- The main functions in this module are:
get_stellar_phoenix: Downloads Phoenix stellar spectra models
get_gases: Downloads opacity database for atmospheric gases
list_gases: Lists available gases in the opacity database
- multirex.utils.get_gases(path='')
Download the opacity database from the Google Drive link and extract the content to the specified path.
This function automates the download and extraction of opacity data files for atmospheric gases, which are required for spectrum generation. The opacity data is used by TauREx to calculate the absorption of light by different gases in the atmosphere. If the opacity database already exists at the specified path, no download occurs.
- Parameters:
path (str, optional) – Directory path where the opacity database will be
string (downloaded and extracted. If empty)
directory. (uses current)
"". (Defaults to)
Note
This function requires an internet connection for the initial download. After downloading, the opacity path is automatically set in the TauREx OpacityCache for immediate use.
The opacity database is approximately 3GB in size.
- multirex.utils.get_stellar_phoenix(path='')
Download the Phoenix stellar spectra from the Google Drive link and extract the content to the specified path.
This function automates the download and extraction of Phoenix stellar model files, which are used for more accurate stellar spectrum modeling compared to blackbody models. If the Phoenix directory already exists at the specified path, no download occurs.
- Parameters:
path (str, optional) – Directory path where the Phoenix folder will be created and model files will be downloaded. If empty string, uses current directory. Defaults to “”.
- Returns:
Path to the Phoenix directory containing the stellar model files.
- Return type:
str
Note
This function requires an internet connection for the initial download. The Phoenix models are approximately 2GB in size.
- multirex.utils.list_gases()
List all available gases in the opacity database.
This function prints the names of all atmospheric gases available in the current opacity database. These gases can be used in the composition of an Atmosphere object.
- Returns:
The list of available gases is printed to the console.
- Return type:
None
Note
You must first download the opacity database using get_gases() before this function will show the complete list of available gases.
Example
>>> import multirex.utils as Util >>> Util.get_gases() # Download the opacity database >>> Util.list_gases() # List available gases