Binning Module (taurex.binning)

The classes here deal with binning spectra down to different resolutions. These exist within the taurex.binning namespace

Base Module

Module for the base binning class

class Binner[source]

Bases: taurex.log.logger.Logger

Abstract class

The binner class deals with binning down spectra to different resolutions. It also provides a method to generate spectrum output format from a forward model result in the form of a dictionary. Using this class does not need to be restricted to TauREx3 results and can be used to bin down any arbitrary spectra.

bin_model(model_output)[source]

Bins down a TauREx3 forward model. This automatically splits the output and passes it to the bindown() function. Its general usage is of the form:

>>> fm = TransmissionModel()
>>> fm.build()
>>> result = fm.model()
>>> binner.bin_model(result)

Or in a single line:

>>> binner.bin_model(fm.model())
Parameters

model_output (obj:tuple) – Result from running a TauREx3 forward model

Returns

Return type

See bindown()

bindown(wngrid, spectrum, grid_width=None, error=None)[source]

Requires implementation

This should handle the binning of a spectrum passed into the function. Parameters given are guidelines on expectation of usage.

Parameters
  • wngrid (array) – The wavenumber grid of the spectrum to be binned down. Generally the ‘native’ wavenumber grid

  • spectrum (array) – The spectra we wish to bin-down. Must be same shape as wngrid.

  • grid_width (array, optional) – Wavenumber grid full-widths for the spectrum to be binned down. Must be same shape as wngrid. Optional, generally if you require this but the user does not pass it then you must compute it yourself using wngrid. This can be done easily using the function func:~taurex.util.util.compute_bin_edges.

  • error (array, optional) – Associated errors or noise of the spectrum. Must be same shape as wngrid.Optional parameter, when implementing you must deal with the cases where either the error is passed or not passed.

Returns

  • binned_wngrid (array) – New wavenumber grid

  • spectrum (array) – Binned spectrum.

  • grid_width (array) – New grid-widths

  • error (array or None) – If passed, should be the binned error otherwise None

generate_spectrum_output(model_output, output_size=<OutputSize.heavy: 6>)[source]

Given a forward model output, generate a dictionary that can be used to store to file. This can include storing the native and binned spectrum. Not necessary for the function of the class but useful for full intergation into TauREx3, especially when storing results from a retrieval. Can be overwritten to store more information.

Parameters
  • model_output (obj:tuple) – Result from running a TauREx3 forward model

  • output_size (OutputSize) – Size of the output.

Returns

Dictionary of spectra

Return type

dict

Flux-Binning

class FluxBinner(wngrid, wngrid_width=None)[source]

Bases: taurex.binning.binner.Binner

Bins to a wavenumber grid given by wngrid using a more accurate method that takes into account the amount of contribution from each native bin. This method also handles cases where bins are not continuous and/or overlapping.

Parameters
  • wngrid (array) – Wavenumber grid

  • wngrid_width (array, optional) – Must have same shape as wngrid Full bin widths for each wavenumber grid point given in wngrid. If not provided then this is automatically computed from wngrid.

bindown(wngrid, spectrum, grid_width=None, error=None)[source]

Bins down spectrum.

Parameters
  • wngrid (array) – The wavenumber grid of the spectrum to be binned down.

  • spectrum (array) – The spectra we wish to bin-down. Must be same shape as wngrid.

  • grid_width (array, optional) – Wavenumber grid full-widths for the spectrum to be binned down. Must be same shape as wngrid. Optional.

  • error (array, optional) – Associated errors or noise of the spectrum. Must be same shape as wngrid.Optional parameter.

Returns

  • binned_wngrid (array) – New wavenumber grid

  • spectrum (array) – Binned spectrum.

  • grid_width (array) – New grid-widths

  • error (array or None) – Binned error if given else None

generate_spectrum_output(model_output, output_size=<OutputSize.heavy: 6>)[source]

Given a forward model output, generate a dictionary that can be used to store to file. This can include storing the native and binned spectrum. Not necessary for the function of the class but useful for full intergation into TauREx3, especially when storing results from a retrieval. Can be overwritten to store more information.

Parameters
  • model_output (obj:tuple) – Result from running a TauREx3 forward model

  • output_size (OutputSize) – Size of the output.

Returns

Dictionary of spectra

Return type

dict

Simple-Binning

class SimpleBinner(wngrid, wngrid_width=None)[source]

Bases: taurex.binning.binner.Binner

Bins to a wavenumber grid given by wngrid. The method places flux into the correct bins using histogramming methods. This is fast but can suffer as it assumes that there are no gaps in the wavenumber grid. This can cause weird results and may cause the flux to be higher in the boundary of points between two distinct regions (such as WFC3 + Spitzer)

Parameters
  • wngrid (array) – Wavenumber grid

  • wngrid_width (array, optional) – Must have same shape as wngrid Full bin widths for each wavenumber grid point given in wngrid. If not provided then this is automatically computed from wngrid.

bindown(wngrid, spectrum, grid_width=None, error=None)[source]

Bins down spectrum.

Parameters
  • wngrid (array) – The wavenumber grid of the spectrum to be binned down.

  • spectrum (array) – The spectra we wish to bin-down. Must be same shape as wngrid.

  • grid_width (array, optional) – Wavenumber grid full-widths for the spectrum to be binned down. Must be same shape as wngrid. Optional.

  • error (array, optional) – Associated errors or noise of the spectrum. Must be same shape as wngrid.Optional parameter.

Returns

  • binned_wngrid (array) – New wavenumber grid

  • spectrum (array) – Binned spectrum.

  • grid_width (array) – New grid-widths

  • error (array or None) – Binned error if given else None

generate_spectrum_output(model_output, output_size=<OutputSize.heavy: 6>)[source]

Given a forward model output, generate a dictionary that can be used to store to file. This can include storing the native and binned spectrum. Not necessary for the function of the class but useful for full intergation into TauREx3, especially when storing results from a retrieval. Can be overwritten to store more information.

Parameters
  • model_output (obj:tuple) – Result from running a TauREx3 forward model

  • output_size (OutputSize) – Size of the output.

Returns

Dictionary of spectra

Return type

dict

Lightcurve-Binning

class LightcurveBinner[source]

Bases: taurex.binning.binner.Binner

A special class of binning used to generate the correct spectrum output. This is essentially the same as NativeBinner but for lightcurve forward models.

bindown(wngrid, spectrum, grid_width=None, error=None)[source]

Does nothing, only returns function arguments

generate_spectrum_output(model_output, output_size=<OutputSize.heavy: 6>)[source]

Accepts only a lightcurve forward model. Stores the lightcurve as well as the spectrum.

Parameters
  • model_output (obj:tuple) – Result from running a TauREx3 lightcurve forward model

  • output_size (OutputSize) – Size of the output.

Returns

Dictionary of spectra containing both lightcurves and spectra.

Return type

dict

Native-Binning

class NativeBinner[source]

Bases: taurex.binning.binner.Binner

A do-nothing binner. This is useful when the pipeline expects a binner but none is given. Simplifies implementation and also handles dictionary writing of the forward model.

bindown(wngrid, spectrum, grid_width=None, error=None)[source]

Does nothing, only returns function arguments

generate_spectrum_output(model_output, output_size=<OutputSize.heavy: 6>)[source]

Given a forward model output, generate a dictionary that can be used to store to file. This can include storing the native and binned spectrum. Not necessary for the function of the class but useful for full intergation into TauREx3, especially when storing results from a retrieval. Can be overwritten to store more information.

Parameters
  • model_output (obj:tuple) – Result from running a TauREx3 forward model

  • output_size (OutputSize) – Size of the output.

Returns

Dictionary of spectra

Return type

dict