Core (taurex.core)

Retrieval

This module relates to defining fitting parameters in TauREx3.

class DerivedCallable(*args, **kwargs)[source]

Bases: Protocol

Protocol for derived callables.

compute: bool

Compute by default?

decorated: Literal['derivedparam'] = 'derivedparam'

Decorated type.

fget: Callable[[], float]

Getter.

param_latex: str

Parameter name in latex.

param_name: str

Parameter name.

class DerivedPropertyType[source]

Bases: object

fget: DerivedCallable
class FitPropertyType[source]

Bases: object

fget: FittingCallable
fset: Callable[[T], None]
class Fittable[source]

Bases: object

A class that manages fitting parameters.

Not really used on its own it should really be inherited from to be used properly. It also provides class with the ability to read and write fitting parameters using their params names, for example, if we create a class like this:

class Foo(Fittable):

    def __init__(self):
        self.value = 10

    @fitparam(param_name='foobar',param_latex='$Foo^{bar}$',default_bounds=[1,12])
    def bar(self):
        return self.value

    @bar.setter
    def bar(self,value):
        self.value = value

We can read and write data in the standard python way like so:

>>> foo = Foo()
>>> foo.bar
10
>>> foo.bar = 20
>>> foo.bar
20

but we also get this functionality for free:

>>> foo['foobar']
20
>>> foo['foobar'] = 30
>>> foo['foobar']
30
add_derived_param(param_name: str, param_latex: str, fget: Callable[[], float], compute: bool) None[source]
add_fittable_param(param_name: str, param_latex: str, fget: Callable[[], float], fset: Callable[[float], None], default_mode: Literal['linear', 'log'], default_fit: bool, default_bounds: Tuple[float, float]) None[source]

Adds a fittable parameter to the internal dictionary.

Used during init to add all fitparam() decorated methods and can also be utilized by a user to manually add new fitting parameters. This is useful for giving fitting parameters names that depend on certain attributes (e.g. molecule name in a gas profile see ConstantGas) or when converting lists into fitting parameters (e.g. Normalization factor in light curves see: LightCurveModel )

Parameters:
  • param_name (str) – Nicer name of the parameter. Referenced by the optimizer.

  • param_latex (str) – Latex version of the parameter name, useful in plotting and making figures

  • fget (function) – a function that returns the value of the parameter

  • fset (function) – a function the writes the value of the parameter

  • default_mode (linear or log) – Defines how the optimizer should read and write the parameter. linear reads/write everything as is. log informs the optimizer to transform from native->log space when read and to transfrom log->native when writing. This also applies to the boundaries

  • default_fit (bool) – Whether this is included in the fit without the user explicity saying so (Default: False)

  • default_bounds (list) – Default minimum and maximum fitting boundary. Must always be defined in the native space

compile_fitparams() None[source]

Loops through and finds all fitting parameters.

These are defined through the decorator in the class and adds it to the internal dictionary

derived_parameters() Dict[str, Tuple[str, str, Callable[[], float], bool]][source]

Returns all derived fitting parameters.

find_derivedparams() Generator[DerivedPropertyType, None, None][source]

Finds and returns fitting parameters.

Yields:

method (function) – class method that is defined with the derivedparam() decorator

find_fitparams() Generator[FitPropertyType, None, None][source]

Finds and returns fitting parameters.

Yields:

method (function) – class method that is defined with the fitparam() decorator

fitting_parameters() Dict[str, Tuple[str, str, Callable[[], float], Callable[[float], None], Literal['linear', 'log'], bool, Tuple[float, float]]][source]

Returns all fitting parameters found as a dictionary.

Returns:

params – Dictionary with key as the parameter name (param_name) and value as a tuple with:

  • parameter name

  • parameter name in Latex form

  • get function

  • set function

  • fitting scale

  • fit as default

  • fitting boundaries

Return type:

dict

modify_bounds(parameter: str, new_bounds: Tuple[float, float])[source]

Modifies the fitting boundary of a parameter

Parameters:
  • parameter (str) – Name of parameter (given by param_name in fitparam())

  • new_bounds (list) – New minimum and maximum fitting boundaries.

class FittingCallable(*args, **kwargs)[source]

Bases: Protocol

Protocol for fitting callables.

decorated: Literal['fitparam'] = 'fitparam'

Decorated type.

default_bounds: List[float]

Default fitting boundaries.

default_fit: bool

Fit by default?

default_mode: Literal['linear', 'log']

Default fitting mode.

doc: str | None = None

Docstring.

fdel: Callable[[], None] | None = None
fget: Callable[[], float]

Getter.

fset: Callable[[float], None]

Setter.

param_latex: str

Parameter name in latex.

param_name: str

Parameter name.

class T

Generic type.

alias of TypeVar(‘T’)

derivedparam(f: Callable[[], float] | None = None, param_name: str | None = None, param_latex: str | None = None, compute: bool | None = False) DerivedCallable[source]

Dectorator to mark derivable parameters.

A decorator used in conjunction with Fittable to inform which parameters should be derived during retrieval. This allows for posteriors of parameters such as log(g) and mu

Parameters:
  • f (function) – Function being passed. Automatically done when used as a decorator

  • param_name (str) – Nicer name of the parameter. Referenced by the optimizer.

  • param_latex (str) – Latex version of the parameter name, useful in plotting and making figures

  • compute (bool) – By default, is this computed?

fitparam(f: Callable[[float], T] | None = None, param_name: str | None = None, param_latex: str | None = None, default_mode: Literal['linear', 'log'] | None = 'linear', default_fit: bool | None = False, default_bounds: List[float] | None = None) FittingCallable[source]

Decorator to mark fittable parameters.

A decorator used in conjunction with Fittable to inform which parameters can be fit and its properties. On its own it acts like the property decorator. When used within a Fittable class it serves to tag a property as able to fit and allows the class to compile all parameters that can be fit.

Its usage is simple, simply wrap a method and define its properties:

class Foo(Fittable):

    @fitparam(param_name='foobar',param_latex='$Foo^{bar}$')
    def bar(self):
        return 'Foobar'

    @bar.setter
    def bar(self,value):
        self.value = value
Parameters:
  • f (function) – Function being passed. Automatically done when used as a decorator

  • param_name (str) – Nicer name of the parameter. Referenced by the optimizer.

  • param_latex (str) – Latex version of the parameter name, useful in plotting and making figures

  • default_mode (linear or log) – Defines how the optimizer should read and write the parameter. linear reads/write everything as is. log informs the optimizer to transform from native->log space when read and to transfrom log->native when writing. This also applies to the boundaries

  • default_fit (bool) – Whether this is included in the fit without the user explicity saying so (Default: False)

  • default_bounds (list) – Default minimum and maximum fitting boundary. Must always be defined in linear space

Raises:

ValueError – If no parameter name is given

Bibliography

Handles citation information for Taurex.

class Citable[source]

Bases: object

Defines a class that contains citation information.

BIBTEX_ENTRIES = []

List of bibtex entries.

citations() List[str][source]

Returns a list of citations.

nice_citation(prefix: str | None = '', start_idx: int | None = 0, indent: int | None = 0) str[source]

Returns a nice printable string of citations.

Parameters:
  • prefix (str, optional) – Prefix to add to each citation

  • start_idx (int, optional) – Starting index of citation

  • indent (int, optional) – Indentation of citation

cleanup_string(string: str) str[source]

Cleans up a string for bibtex.

construct_nice_printable_string(entry: str, indent: int = 0) str[source]

Constructs a nice printable string for each entry.

doi_to_bibtex(doi: str) str | None[source]

Converts a doi to bibtex.

Parameters:

doi (str) – DOI to convert

handle_publication(fields: Dict[str, str]) str[source]

Handles publication information.

recurse_bibtex(obj: Citable, entries: List[str] | None = None) List[str][source]

Recursively search for bibtex entries in base classes.

stringify_people(authors: List[str]) str[source]

Converts authors to a string.

to_bibtex(citations: List[str]) str[source]

Converts citations to bibtex.

unique_citations_only(citations: List[str]) List[str][source]

Removes duplicate citations.

Priors (taurex.core.priors)

Handles how priors are defined for retrievals.

class Gaussian(mean: float | None = 0.5, std: float | None = 0.25)[source]

Bases: Prior

Defines a gaussian prior.

boundaries() Tuple[float, float][source]

Return the boundaries of the prior.

params() str[source]

Return the parameters of the prior in string form.

sample(x: float) float[source]

Sample the prior.

Parameters:

x (float) – A random number between 0 and 1.

class LogGaussian(mean: float | None = 0.5, std: float | None = 0.25, lin_mean: float | None = None, lin_std: float | None = None)[source]

Bases: Gaussian

Defines a log-gaussian prior.

class LogUniform(bounds: Tuple[float, float] | None = (0.0, 1.0), lin_bounds=None)[source]

Bases: Uniform

Defines a log-uniform prior.

class Prior[source]

Bases: Loggable

Defines a prior function

boundaries() Tuple[float, float][source]

Return the (rough) boundaries of the prior.

Raises:

NotImplementedError – [description]

params() str[source]

Return the parameters of the prior in string form.

Raises:

NotImplementedError – [description]

prior(value: float) float[source]

Convert a value from prior space to linear space.

property priorMode: PriorMode

Defined prior mode.

sample(x: float) float[source]

Sample the prior.

Parameters:

x (float) – A random number between 0 and 1.

Raises:

NotImplementedError – [description]

class PriorMode(value)[source]

Bases: Enum

Defines the type of prior space.

LINEAR = 0
LOG = 1
class Uniform(bounds: Tuple[float, float] | None = (0.0, 1.0))[source]

Bases: Prior

Defines a uniform prior.

boundaries() Tuple[float, float][source]

Return the boundaries of the prior.

params()[source]

Return the parameters of the prior in string form.

Returns:

String representation of the prior.

Return type:

str

sample(x: float) float[source]

Sample the prior.

Parameters:

x (float) – A random number between 0 and 1.

set_bounds(bounds: Tuple[float, float])[source]

Set the bounds of the prior.

Parameters:

bounds (t.Tuple[float, float]) – Bounds of the prior.