Utilities

Submodules

taurex.util.emission module

Functions related to computing emission spectrums.

black_body(lamb: ndarray[tuple[int, ...], dtype[float64]], temp: float)

Black body function to use.

black_body_numba(lamb: ndarray[tuple[int, ...], dtype[float64]], temp: float)[source]

Compute black body spectrum using numpy (numba not available).

black_body_numba_II(lamb: ndarray[tuple[int, ...], dtype[float64]], temp: float)[source]

Compute black body spectrum using numpy (numba not available).

black_body_numexpr(lamb: ndarray[tuple[int, ...], dtype[_ScalarType_co]], temp: ndarray[tuple[int, ...], dtype[_ScalarType_co]]) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

Compute black body spectrum using numexpr.

black_body_numpy(lamb: ndarray[tuple[int, ...], dtype[_ScalarType_co]], temp: ndarray[tuple[int, ...], dtype[_ScalarType_co]]) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

Compute black body spectrum using numpy.

Parameters:
  • lamb (npt.NDArray) – Wavelengths in microns

  • temp (npt.NDArray) – Temperature in Kelvin

Returns:

Black body spectrum

Return type:

npt.NDArray

integrate_emission_layer(dtau: ndarray[tuple[int, ...], dtype[_ScalarType_co]], layer_tau: ndarray[tuple[int, ...], dtype[_ScalarType_co]], mu: ndarray[tuple[int, ...], dtype[_ScalarType_co]], bb: ndarray[tuple[int, ...], dtype[_ScalarType_co]]) Tuple[ndarray[tuple[int, ...], dtype[_ScalarType_co]], ndarray[tuple[int, ...], dtype[_ScalarType_co]]][source]

Integrate emission layer.

Parameters:
  • dtau (npt.NDArray) – Optical depth of layer

  • layer_tau (npt.NDArray) – Optical depth of layer

  • mu (npt.NDArray) – Cosine of zenith angle

  • BB (npt.NDArray) – Black body spectrum

Returns:

Integrated emission layer, optical depth of layer

Return type:

t.Tuple[npt.NDArray, npt.NDArray]

taurex.util.math module

Optimized Math functions used in taurex

class OnlineVariance[source]

Bases: object

USes the M2 algorithm to compute the variance in a streaming fashion

combine_variance(averages: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], variance: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], counts: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) Tuple[ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]]][source]

Combine different variance calculations together.

parallelVariance() float | int | float64 | int64 | ndarray | _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes][source]

Compute the variance in parallel.

reset() None[source]

Reset the class.

property sampleVariance: float | int | float64 | int64 | ndarray | _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]

Return the sample variance.

update(value: float | int | float64 | int64 | ndarray | _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], weight: float | None = 1.0)[source]

Update the variance.

property variance: float

Return the variance.

compute_rayleigh_cross_section(wngrid: ndarray[tuple[int, ...], dtype[float64]], n: float, n_air: float | None = 2.6867805e+25, king: float | None = 1.0) ndarray[tuple[int, ...], dtype[float64]][source]

Compute Rayleigh cross section.

intepr_bilin(x11: ndarray[tuple[int, ...], dtype[float64]], x12: ndarray[tuple[int, ...], dtype[float64]], x21: ndarray[tuple[int, ...], dtype[float64]], x22: ndarray[tuple[int, ...], dtype[float64]], temperature: float, temperature_min: float, temperature_max: float, pressure: float, pressure_min: float, pressure_max: float) ndarray[tuple[int, ...], dtype[float64]]
intepr_bilin_double(x11: ndarray[tuple[int, ...], dtype[float64]], x12: ndarray[tuple[int, ...], dtype[float64]], x21: ndarray[tuple[int, ...], dtype[float64]], x22: ndarray[tuple[int, ...], dtype[float64]], temperature: float, temperature_min: float, temperature_max: float, pressure: float, pressure_min: float, pressure_max: float) ndarray[tuple[int, ...], dtype[float64]][source]
intepr_bilin_numexpr(x11: ndarray[tuple[int, ...], dtype[float64]], x12: ndarray[tuple[int, ...], dtype[float64]], x21: ndarray[tuple[int, ...], dtype[float64]], x22: ndarray[tuple[int, ...], dtype[float64]], temperature: float, temperature_min: float, temperature_max: float, pressure: float, pressure_min: float, pressure_max: float) ndarray[tuple[int, ...], dtype[float64]][source]
intepr_bilin_old(x11: ndarray[tuple[int, ...], dtype[float64]], x12: ndarray[tuple[int, ...], dtype[float64]], x21: ndarray[tuple[int, ...], dtype[float64]], x22: ndarray[tuple[int, ...], dtype[float64]], temperature: float, temperature_min: float, temperature_max: float, pressure: float, pressure_min: float, pressure_max: float) ndarray[tuple[int, ...], dtype[float64]][source]
interp_bilin_numpy(x11: ndarray[tuple[int, ...], dtype[float64]], x12: ndarray[tuple[int, ...], dtype[float64]], x21: ndarray[tuple[int, ...], dtype[float64]], x22: ndarray[tuple[int, ...], dtype[float64]], temperature: float, temperature_min: float, temperature_max: float, pressure: float, pressure_min: float, pressure_max: float) ndarray[tuple[int, ...], dtype[float64]][source]
interp_exp_and_lin(x11: ndarray[tuple[int, ...], dtype[float64]], x12: ndarray[tuple[int, ...], dtype[float64]], x21: ndarray[tuple[int, ...], dtype[float64]], x22: ndarray[tuple[int, ...], dtype[float64]], temperature: float, temperature_min: float, temperature_max: float, pressure: float, pressure_min: float, pressure_max: float) ndarray[tuple[int, ...], dtype[float64]]

2D interpolation.

Applies linear interpolation across pressure and e interpolation across temperature between pressure_min,pressure_max and temperature_min,temperature_max

Parameters:
  • x11 (array) – Array corresponding to pressure_min,temperature_min

  • x12 (array) – Array corresponding to pressure_min,temperature_max

  • x21 (array) – Array corresponding to pressure_max,temperature_min

  • x22 (array) – Array corresponding to pressure_max,temperature_max

  • temperature (float) – Coordinate to exp interpolate to

  • temperature_min (float) – Nearest known temperature coordinate where temperature_min < temperature

  • temperature_max (float) – Nearest known temperature coordinate where temperature < temperature_max

  • pressure (float) – Coordinate to linear interpolate to

  • pressure_min (float) – Nearest known pressure coordinate where pressure_min < pressure

  • pressure_max (float) – Nearest known pressure coordinate where pressure < pressure_max

interp_exp_and_lin_numpy(x11: ndarray[tuple[int, ...], dtype[float64]], x12: ndarray[tuple[int, ...], dtype[float64]], x21: ndarray[tuple[int, ...], dtype[float64]], x22: ndarray[tuple[int, ...], dtype[float64]], temperature: float, temperature_min: float, temperature_max: float, pressure: float, pressure_min: float, pressure_max: float) ndarray[tuple[int, ...], dtype[float64]][source]

2D interpolation.

Applies linear interpolation across pressure and e interpolation across temperature between pressure_min,pressure_max and temperature_min,temperature_max

Parameters:
  • x11 (array) – Array corresponding to pressure_min,temperature_min

  • x12 (array) – Array corresponding to pressure_min,temperature_max

  • x21 (array) – Array corresponding to pressure_max,temperature_min

  • x22 (array) – Array corresponding to pressure_max,temperature_max

  • temperature (float) – Coordinate to exp interpolate to

  • temperature_min (float) – Nearest known temperature coordinate where temperature_min < temperature

  • temperature_max (float) – Nearest known temperature coordinate where temperature < temperature_max

  • pressure (float) – Coordinate to linear interpolate to

  • pressure_min (float) – Nearest known pressure coordinate where pressure_min < pressure

  • pressure_max (float) – Nearest known pressure coordinate where pressure < pressure_max

interp_exp_numpy(x11: ndarray[tuple[int, ...], dtype[float64]], x12: ndarray[tuple[int, ...], dtype[float64]], temperature, temperature_min, temperature_max) ndarray[tuple[int, ...], dtype[float64]][source]
interp_exp_only(x11: ndarray[tuple[int, ...], dtype[float64]], x12: ndarray[tuple[int, ...], dtype[float64]], temperature, temperature_min, temperature_max) ndarray[tuple[int, ...], dtype[float64]]
interp_lin_numpy(x11: ndarray[tuple[int, ...], dtype[float64]], x12: ndarray[tuple[int, ...], dtype[float64]], pressure: float, pressure_min: float, pressure_max: float) ndarray[tuple[int, ...], dtype[float64]][source]
interp_lin_only(x11: ndarray[tuple[int, ...], dtype[float64]], x12: ndarray[tuple[int, ...], dtype[float64]], pressure: float, pressure_min: float, pressure_max: float) ndarray[tuple[int, ...], dtype[float64]]
test_nan(val: float | _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) bool[source]

Test if a value is nan.

taurex.util.util module

General utility functions.

bindown(original_bin: ndarray[tuple[int, ...], dtype[_ScalarType_co]], original_data: ndarray[tuple[int, ...], dtype[_ScalarType_co]], new_bin: ndarray[tuple[int, ...], dtype[_ScalarType_co]]) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

This method quickly bins down by taking the mean.

The numpy histogram function is exploited to do this quickly. This is prone to nans if no data is present in the bin.

Parameters:
  • original_bin (numpy.array) – The original bins for the that we want to bin down

  • original_data (numpy.array) – The associated data that will be averaged along the new bins

  • new_bin (numpy.array) – The new binnings we want to use (must have less points than the original)

Returns:

Binned mean of original_data

Return type:

array

calculate_weight(chem: str) float[source]

Compute the molecular weight of a molecule in amu.

Parameters:

chem (str) – Molecule name e.g. H2O, CO2, CH4, etc.

Returns:

Molecular weight in amu

Return type:

float

class_for_name(class_name: str)[source]

Converts a string to a class.

Searches TauREx3 registry of classes (including plugins) for name.

Parameters:

class_name (str) – Name of class

class_from_keyword(keyword, class_filter=None)[source]
clip_native_to_wngrid(native_grid: ndarray[tuple[int, ...], dtype[_ScalarType_co]], spectral: ndarray[tuple[int, ...], dtype[_ScalarType_co]]) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

Clips native grid values to a different spectral grid.

Parameters:
  • native_grid (array) – Native spectral grid

  • spectral (array) – spectral grid

Returns:

Clipped native spectral grid

Return type:

array

compute_bin_edges(spectral_grid: ndarray[tuple[int, ...], dtype[_ScalarType_co]]) Tuple[ndarray[tuple[int, ...], dtype[_ScalarType_co]], ndarray[tuple[int, ...], dtype[_ScalarType_co]]][source]

Computes bin edges from a spectral grid.

Parameters:

spectral_grid (array) – Spectral grid

Returns:

  • array – Bin edges

  • array – Bin widths

compute_dz(altitude: ndarray[tuple[int, ...], dtype[_ScalarType_co]]) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]
conversion_factor(from_unit: str, to_unit: str) float[source]

Determine conversion from one unit to another.

Parameters:
  • from_unit (Unit) – Unit to convert from

  • to_unit (Unit) – Unit to convert to

Returns:

Conversion factor.

Return type:

float

create_grid_res(resolution: float | int | float64 | int64, spectral_min: float | int | float64 | int64, spectral_max: float | int | float64 | int64) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

Creates a grid with a given resolution.

Resolution is defined as \(R = \frac{\lambda}{\Delta \lambda}\)

Parameters:
  • resolution (float) – Resolution to use

  • spectral_min (float) – Minimum wavelength

  • spectral_max (float) – Maximum wavelength

Returns:

Grid with resolution and spectral bin widths

Return type:

array

decode_string_array(f)[source]

Helper to decode strings from hdf5.

ensure_string_utf8(val: str) str[source]

Ensures a string is utf8 encoded.

find_closest_pair(arr, value) -> (<class 'int'>, <class 'int'>)[source]

Will find the indices that lie to the left and right of the value.

arr[left] <= value <= arr[right]

If the value is less than the array minimum then it will always return left=0 and right=1

If the value is above the maximum

Parameters:
  • arr (array) – Array to search, must be sorted

  • value (float) – Value to find in array

Returns:

  • left (int)

  • right (int)

get_molecular_weight(gasname: str) float[source]

For a given molecule return the molecular weight in kg

Parameters:

gasname (str) – Name of molecule

Returns:

molecular weight in amu or 0 if not found

Return type:

float

has_duplicates(arr: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) bool[source]

Checks if an array has duplicates.

loadtxt2d(intext: str) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

Wraps loadtext.

Returns a 2d array or 1d array depending on the input text.

Parameters:

intext (str) – Input text

Returns:

2d array or 1d array

Return type:

array

merge_elements(elem1: Dict[str, int], elem2: Dict[str, int], factor: int | None = 1) Dict[str, int][source]

Merge two element dictionaries.

molecule_texlabel(gasname: str) str[source]

For a given molecule return its latex form

Parameters:

gasname (str) – Name of molecule

Returns:

Latex form of the molecule or just the passed name if not found

Return type:

str

movingaverage(a: ndarray[tuple[int, ...], dtype[_ScalarType_co]], n: int | None = 3) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

Computes moving average given an array and window size.

Parameters:
  • a (array) – Array to compute average

  • n (int) – Averaging window

Returns:

Resultant array

Return type:

array

quantile_corner(x: ndarray[tuple[int, ...], dtype[_ScalarType_co]], q: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | float, weights: float | ndarray[tuple[int, ...], dtype[_ScalarType_co]] | None = None) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

Compute quantiles from an array with weighting.

  • Taken from corner.py

__author__ = “Dan Foreman-Mackey (danfm@nyu.edu)” __copyright__ = “Copyright 2013-2015 Daniel Foreman-Mackey”

Like numpy.percentile, but:

  • Values of q are quantiles [0., 1.] rather than percentiles [0., 100.]

  • scalar q not supported (q must be iterable)

  • optional weights on x

Parameters:
  • x (array) – Input array or object that can be converted to an array.

  • q (array or float) – Percentile or sequence of percentiles to compute, which must be between 0 and 1 inclusive.

  • weights (array or float , optional) – Weights on x

Returns:

percentile

Return type:

scalar or ndarray

random_int_iter(total: int, fraction: float | None = 1.0) Iterator[int][source]

Iterator to randomly sample integers up to a total number.

Fraction is the fraction of total to sample. For example if total = 100 and fraction = 0.1 then 10 random integers will be sampled between 0 and 99.

Parameters:
  • total (int) – Maximum number

  • fraction (float) – Fraction of total to sample

Yields:

int – Random integer

read_error_into_dict(line: str, d: Dict[str, float]) None[source]

Reads multinest error into dict.

read_error_line(line: str) Tuple[str, float, float][source]

Reads line from multinest

read_table(txt: str, d: Dict[str, float] | None = None, title: str | None = None)[source]

Reads a table into a dictionary from multinest outputs.

recursively_save_dict_contents_to_output(output: OutputGroup, dic: Dict[str, float | int | int64 | float64 | ndarray | str | List | Tuple | dict])[source]

Will recursive write a dictionary into output.

Parameters:
  • output – Group (or root) in output file to write to

  • dic (dict) – Dictionary we want to write

Raises:

ValueError – If item is not a supported type

sanitize_molecule_string(molecule: str) str[source]

Cleans a molecule string to match up with molecule naming in TauREx3.

For example:

>>> sanitize_molecule_string('H2O')
'H2O'
>>> sanitize_molecule_string('H2-16O')
'H2O'
Parameters:

molecule (str) – Molecule to sanitize

Returns:

Sanitized name

Return type:

str

split_molecule_elements(molecule: str | None = None, tokens: List[str] | None = None) Dict[str, int][source]

Split a molecule string into its elements and numbers.

For example when run with H2O:

>>> split_molecule_elements('H2O')
{'H': 2, 'O': 1}
Parameters:
  • molecule (str, optional) – Molecule string to split

  • tokens (list[str], optional) – List of presplit tokens.

Returns:

Dictionary of elements and their counts

Return type:

dict[str, int]

store_thing(output: OutputGroup, key: str, item: float | int | int64 | float64 | ndarray | str | List | Tuple | dict) None[source]

Stores a single item into output.

Parameters:
  • output – Group (or root) in output file to write to

  • key (str) – Name of item

  • item – Item to store

Raises:

TypeError – If item is not a supported type

tokenize_molecule(molecule: str) list[str][source]

Tokenize a molecule string into its elements and numbers.

weighted_avg_and_std(values: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], weights: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], axis: int | None = None) Tuple[float | int | float64 | int64 | ndarray | _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], float | int | float64 | int64 | ndarray | _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]][source]

Computes weight average and standard deviation.

Parameters:
  • values (array) – Input array

  • weights (array) – Must be same shape as values

axisint , optional

axis to perform weighting

wnwidth_to_wlwidth(wngrid: ndarray[tuple[int, ...], dtype[_ScalarType_co]], wnwidth: ndarray[tuple[int, ...], dtype[_ScalarType_co]]) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

Converts a wavenumber width to wavelength width and vice versa.

Given a spectral grid and its associated spectral bin widths, this function will convert the wavenumber widths to wavelength widths and vice versa.

The formula used is:

\[\Delta \lambda = \frac{10000 \Delta \nu}{\nu^2}\]
Parameters:
  • wngrid (array) – Wavenumber grid in \(cm^{-1}\)

  • wnwidth (array) – Wavenumber width in \(cm^{-1}\)

Returns:

Wavelength width in \(\mu m\)

Return type:

array

Module contents

Common functions that are used and are quite helpful

bindown(original_bin: ndarray[tuple[int, ...], dtype[_ScalarType_co]], original_data: ndarray[tuple[int, ...], dtype[_ScalarType_co]], new_bin: ndarray[tuple[int, ...], dtype[_ScalarType_co]]) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

This method quickly bins down by taking the mean.

The numpy histogram function is exploited to do this quickly. This is prone to nans if no data is present in the bin.

Parameters:
  • original_bin (numpy.array) – The original bins for the that we want to bin down

  • original_data (numpy.array) – The associated data that will be averaged along the new bins

  • new_bin (numpy.array) – The new binnings we want to use (must have less points than the original)

Returns:

Binned mean of original_data

Return type:

array

calculate_weight(chem: str) float[source]

Compute the molecular weight of a molecule in amu.

Parameters:

chem (str) – Molecule name e.g. H2O, CO2, CH4, etc.

Returns:

Molecular weight in amu

Return type:

float

class_for_name(class_name: str)[source]

Converts a string to a class.

Searches TauREx3 registry of classes (including plugins) for name.

Parameters:

class_name (str) – Name of class

class_from_keyword(keyword, class_filter=None)[source]
clip_native_to_wngrid(native_grid: ndarray[tuple[int, ...], dtype[_ScalarType_co]], spectral: ndarray[tuple[int, ...], dtype[_ScalarType_co]]) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

Clips native grid values to a different spectral grid.

Parameters:
  • native_grid (array) – Native spectral grid

  • spectral (array) – spectral grid

Returns:

Clipped native spectral grid

Return type:

array

compute_bin_edges(spectral_grid: ndarray[tuple[int, ...], dtype[_ScalarType_co]]) Tuple[ndarray[tuple[int, ...], dtype[_ScalarType_co]], ndarray[tuple[int, ...], dtype[_ScalarType_co]]][source]

Computes bin edges from a spectral grid.

Parameters:

spectral_grid (array) – Spectral grid

Returns:

  • array – Bin edges

  • array – Bin widths

compute_dz(altitude: ndarray[tuple[int, ...], dtype[_ScalarType_co]]) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]
conversion_factor(from_unit: str, to_unit: str) float[source]

Determine conversion from one unit to another.

Parameters:
  • from_unit (Unit) – Unit to convert from

  • to_unit (Unit) – Unit to convert to

Returns:

Conversion factor.

Return type:

float

create_grid_res(resolution: float | int | float64 | int64, spectral_min: float | int | float64 | int64, spectral_max: float | int | float64 | int64) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

Creates a grid with a given resolution.

Resolution is defined as \(R = \frac{\lambda}{\Delta \lambda}\)

Parameters:
  • resolution (float) – Resolution to use

  • spectral_min (float) – Minimum wavelength

  • spectral_max (float) – Maximum wavelength

Returns:

Grid with resolution and spectral bin widths

Return type:

array

decode_string_array(f)[source]

Helper to decode strings from hdf5.

ensure_string_utf8(val: str) str[source]

Ensures a string is utf8 encoded.

find_closest_pair(arr, value) -> (<class 'int'>, <class 'int'>)[source]

Will find the indices that lie to the left and right of the value.

arr[left] <= value <= arr[right]

If the value is less than the array minimum then it will always return left=0 and right=1

If the value is above the maximum

Parameters:
  • arr (array) – Array to search, must be sorted

  • value (float) – Value to find in array

Returns:

  • left (int)

  • right (int)

get_molecular_weight(gasname: str) float[source]

For a given molecule return the molecular weight in kg

Parameters:

gasname (str) – Name of molecule

Returns:

molecular weight in amu or 0 if not found

Return type:

float

has_duplicates(arr: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) bool[source]

Checks if an array has duplicates.

loadtxt2d(intext: str) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

Wraps loadtext.

Returns a 2d array or 1d array depending on the input text.

Parameters:

intext (str) – Input text

Returns:

2d array or 1d array

Return type:

array

merge_elements(elem1: Dict[str, int], elem2: Dict[str, int], factor: int | None = 1) Dict[str, int][source]

Merge two element dictionaries.

molecule_texlabel(gasname: str) str[source]

For a given molecule return its latex form

Parameters:

gasname (str) – Name of molecule

Returns:

Latex form of the molecule or just the passed name if not found

Return type:

str

movingaverage(a: ndarray[tuple[int, ...], dtype[_ScalarType_co]], n: int | None = 3) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

Computes moving average given an array and window size.

Parameters:
  • a (array) – Array to compute average

  • n (int) – Averaging window

Returns:

Resultant array

Return type:

array

quantile_corner(x: ndarray[tuple[int, ...], dtype[_ScalarType_co]], q: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | float, weights: float | ndarray[tuple[int, ...], dtype[_ScalarType_co]] | None = None) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

Compute quantiles from an array with weighting.

  • Taken from corner.py

__author__ = “Dan Foreman-Mackey (danfm@nyu.edu)” __copyright__ = “Copyright 2013-2015 Daniel Foreman-Mackey”

Like numpy.percentile, but:

  • Values of q are quantiles [0., 1.] rather than percentiles [0., 100.]

  • scalar q not supported (q must be iterable)

  • optional weights on x

Parameters:
  • x (array) – Input array or object that can be converted to an array.

  • q (array or float) – Percentile or sequence of percentiles to compute, which must be between 0 and 1 inclusive.

  • weights (array or float , optional) – Weights on x

Returns:

percentile

Return type:

scalar or ndarray

random_int_iter(total: int, fraction: float | None = 1.0) Iterator[int][source]

Iterator to randomly sample integers up to a total number.

Fraction is the fraction of total to sample. For example if total = 100 and fraction = 0.1 then 10 random integers will be sampled between 0 and 99.

Parameters:
  • total (int) – Maximum number

  • fraction (float) – Fraction of total to sample

Yields:

int – Random integer

read_error_into_dict(line: str, d: Dict[str, float]) None[source]

Reads multinest error into dict.

read_error_line(line: str) Tuple[str, float, float][source]

Reads line from multinest

read_table(txt: str, d: Dict[str, float] | None = None, title: str | None = None)[source]

Reads a table into a dictionary from multinest outputs.

recursively_save_dict_contents_to_output(output: OutputGroup, dic: Dict[str, float | int | int64 | float64 | ndarray | str | List | Tuple | dict])[source]

Will recursive write a dictionary into output.

Parameters:
  • output – Group (or root) in output file to write to

  • dic (dict) – Dictionary we want to write

Raises:

ValueError – If item is not a supported type

sanitize_molecule_string(molecule: str) str[source]

Cleans a molecule string to match up with molecule naming in TauREx3.

For example:

>>> sanitize_molecule_string('H2O')
'H2O'
>>> sanitize_molecule_string('H2-16O')
'H2O'
Parameters:

molecule (str) – Molecule to sanitize

Returns:

Sanitized name

Return type:

str

split_molecule_elements(molecule: str | None = None, tokens: List[str] | None = None) Dict[str, int][source]

Split a molecule string into its elements and numbers.

For example when run with H2O:

>>> split_molecule_elements('H2O')
{'H': 2, 'O': 1}
Parameters:
  • molecule (str, optional) – Molecule string to split

  • tokens (list[str], optional) – List of presplit tokens.

Returns:

Dictionary of elements and their counts

Return type:

dict[str, int]

store_thing(output: OutputGroup, key: str, item: float | int | int64 | float64 | ndarray | str | List | Tuple | dict) None[source]

Stores a single item into output.

Parameters:
  • output – Group (or root) in output file to write to

  • key (str) – Name of item

  • item – Item to store

Raises:

TypeError – If item is not a supported type

tokenize_molecule(molecule: str) list[str][source]

Tokenize a molecule string into its elements and numbers.

weighted_avg_and_std(values: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], weights: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], axis: int | None = None) Tuple[float | int | float64 | int64 | ndarray | _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], float | int | float64 | int64 | ndarray | _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]][source]

Computes weight average and standard deviation.

Parameters:
  • values (array) – Input array

  • weights (array) – Must be same shape as values

axisint , optional

axis to perform weighting

wnwidth_to_wlwidth(wngrid: ndarray[tuple[int, ...], dtype[_ScalarType_co]], wnwidth: ndarray[tuple[int, ...], dtype[_ScalarType_co]]) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

Converts a wavenumber width to wavelength width and vice versa.

Given a spectral grid and its associated spectral bin widths, this function will convert the wavenumber widths to wavelength widths and vice versa.

The formula used is:

\[\Delta \lambda = \frac{10000 \Delta \nu}{\nu^2}\]
Parameters:
  • wngrid (array) – Wavenumber grid in \(cm^{-1}\)

  • wnwidth (array) – Wavenumber width in \(cm^{-1}\)

Returns:

Wavelength width in \(\mu m\)

Return type:

array