Utilities

Submodules

taurex.util.emission module

Functions related to computing emission spectrums

black_body
black_body_numba[source]
black_body_numba_II[source]
black_body_numexpr(lamb, temp)[source]
black_body_numpy(lamb, temp)[source]
integrate_emission_layer(dtau, layer_tau, mu, BB)[source]
integrate_emission_numba[source]

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, variance, counts)[source]
parallelVariance()[source]
reset()[source]
property sampleVariance
update(value, weight=1.0)[source]
property variance
compute_rayleigh_cross_section(wngrid, n, n_air=2.6867805e+25, king=1.0)[source]
intepr_bilin
intepr_bilin_double(x11, x12, x21, x22, T, Tmin, Tmax, P, Pmin, Pmax)[source]
intepr_bilin_numba[source]
intepr_bilin_numba_II[source]
intepr_bilin_numexpr(x11, x12, x21, x22, T, Tmin, Tmax, P, Pmin, Pmax)[source]
intepr_bilin_old(x11, x12, x21, x22, T, Tmin, Tmax, P, Pmin, Pmax)[source]
interp_exp_and_lin(x11, x12, x21, x22, T, Tmin, Tmax, P, Pmin, Pmax)

2D interpolation

Applies linear interpolation across P and e interpolation across T between Pmin,Pmax and Tmin,Tmax

Parameters
  • x11 (array) – Array corresponding to Pmin,Tmin

  • x12 (array) – Array corresponding to Pmin,Tmax

  • x21 (array) – Array corresponding to Pmax,Tmin

  • x22 (array) – Array corresponding to Pmax,Tmax

  • T (float) – Coordinate to exp interpolate to

  • Tmin (float) – Nearest known T coordinate where Tmin < T

  • Tmax (float) – Nearest known T coordinate where T < Tmax

  • P (float) – Coordinate to linear interpolate to

  • Pmin (float) – Nearest known P coordinate where Pmin < P

  • Pmax (float) – Nearest known P coordinate where P < Tmax

interp_exp_and_lin_broken[source]
interp_exp_and_lin_numpy(x11, x12, x21, x22, T, Tmin, Tmax, P, Pmin, Pmax)[source]

2D interpolation

Applies linear interpolation across P and e interpolation across T between Pmin,Pmax and Tmin,Tmax

Parameters
  • x11 (array) – Array corresponding to Pmin,Tmin

  • x12 (array) – Array corresponding to Pmin,Tmax

  • x21 (array) – Array corresponding to Pmax,Tmin

  • x22 (array) – Array corresponding to Pmax,Tmax

  • T (float) – Coordinate to exp interpolate to

  • Tmin (float) – Nearest known T coordinate where Tmin < T

  • Tmax (float) – Nearest known T coordinate where T < Tmax

  • P (float) – Coordinate to linear interpolate to

  • Pmin (float) – Nearest known P coordinate where Pmin < P

  • Pmax (float) – Nearest known P coordinate where P < Tmax

interp_exp_numba[source]
interp_exp_numpy(x11, x12, T, Tmin, Tmax)[source]
interp_exp_only(x11, x12, T, Tmin, Tmax)
interp_lin_numba[source]
interp_lin_numpy(x11, x12, P, Pmin, Pmax)[source]
interp_lin_only
test_nan(val)[source]

taurex.util.util module

General utility functions

bindown(original_bin, original_data, new_bin, last_point=None)[source]

This method quickly bins down by taking the mean. The numpy histogram function is exploited to do this quickly

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)[source]
class_for_name(class_name)[source]
class_from_keyword(keyword, class_filter=None)[source]
clip_native_to_wngrid(native_grid, wngrid)[source]
compute_bin_edges(wngrid)[source]
compute_dz(altitude)[source]
conversion_factor(from_unit, to_unit)[source]
create_grid_res(resolution, wave_min, wave_max)[source]
decode_string_array(f)[source]

Helper to decode strings from hdf5

ensure_string_utf8(val)[source]
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)[source]

For a given molecule return the molecular weight in atomic units

Parameters

gasname (str) – Name of molecule

Returns

molecular weight in amu or 0 if not found

Return type

float

has_duplicates(arr)[source]
loadtxt2d(intext)[source]

Wraps loadtext and either returns a 2d array or 1d array

merge_elements(elem1, elem2, factor=1)[source]
molecule_texlabel(gasname)[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, n=3)[source]

Computes moving average

Parameters
  • a (array) – Array to compute average

  • n (int) – Averaging window

Returns

Resultant array

Return type

array

quantile_corner(x, q, weights=None)[source]
  • 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, fraction)[source]
read_error_into_dict(l, d)[source]

Reads the error into dict?

read_error_line(l)[source]

Reads line?

read_table(txt, d=None, title=None)[source]

Yeah whatever i give up

recursively_save_dict_contents_to_output(output, dic)[source]

Will recursive write a dictionary into output.

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

  • dic (dict) – Dictionary we want to write

sanitize_molecule_string(molecule)[source]

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

e.g:

H2O -> H2O

1H2-16O -> H2O

Parameters

molecule (str) – Molecule to sanitize

Returns

Sanitized name

Return type

str

split_molecule_elements(molecule=None, tokens=None)[source]
store_thing(output, key, item)[source]
tokenize_molecule(molecule)[source]
weighted_avg_and_std(values, weights, axis=None)[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, wnwidth)[source]

Module contents

Common functions that are used and are quite helpful