Utilities¶
Submodules¶
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
-
property
sampleVariance
¶
-
property
variance
¶
-
property
-
intepr_bilin
¶
-
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_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_only
(x11, x12, T, Tmin, Tmax)¶
-
interp_lin_only
¶
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 downoriginal_data (
numpy.array
) – The associated data that will be averaged along the new binsnew_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
-
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 sortedvalue (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
-
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 averagen (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
-
recursively_save_dict_contents_to_output
(output, dic)[source]¶ Will recursive write a dictionary into output.
- Parameters
output (
Output
orOutputGroup
) – Group (or root) in output file to write todic (
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
Module contents¶
Common functions that are used and are quite helpful