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 BinnedSpectrumType[source]¶
Bases:
TypedDictBinned spectrum type.
- binned_spectrum: ndarray[tuple[int, ...], dtype[float64]]¶
- binned_tau: ndarray[tuple[int, ...], dtype[float64]] | None¶
- binned_wlgrid: ndarray[tuple[int, ...], dtype[float64]] | None¶
- binned_wlwidth: ndarray[tuple[int, ...], dtype[float64]] | None¶
- binned_wngrid: ndarray[tuple[int, ...], dtype[float64]] | None¶
- binned_wnwidth: ndarray[tuple[int, ...], dtype[float64]] | None¶
- native_spectrum: ndarray[tuple[int, ...], dtype[float64]]¶
- native_tau: ndarray[tuple[int, ...], dtype[float64]] | None¶
- native_wlgrid: ndarray[tuple[int, ...], dtype[float64]]¶
- native_wlwidth: ndarray[tuple[int, ...], dtype[float64]]¶
- native_wngrid: ndarray[tuple[int, ...], dtype[float64]]¶
- native_wnwidth: ndarray[tuple[int, ...], dtype[float64]]¶
- class Binner[source]¶
Bases:
LoggableAbstract 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: Tuple[ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]] | None, Dict | T | None]) Tuple[ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]] | None, ndarray[tuple[int, ...], dtype[float64]] | None][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
- Return type:
See
bindown()
- bindown(wngrid: ndarray[tuple[int, ...], dtype[float64]], spectrum: ndarray[tuple[int, ...], dtype[float64]], grid_width: ndarray[tuple[int, ...], dtype[float64]] | None = None, error: ndarray[tuple[int, ...], dtype[float64]] | None = None) Tuple[ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]] | None, ndarray[tuple[int, ...], dtype[float64]] | None][source]¶
Bin down a spectrum from a high resolution to a lower resolution. 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 gridspectrum (
array) – The spectra we wish to bin-down. Must be same shape aswngrid.grid_width (
array, optional) – Wavenumber grid full-widths for the spectrum to be binned down. Must be same shape aswngrid. Optional, generally if you require this but the user does not pass it then you must compute it yourself usingwngrid. This can be done easily using the function func:~taurex.util.compute_bin_edges.error (
array, optional) – Associated errors or noise of the spectrum. Must be same shape aswngrid.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 gridspectrum (
array) – Binned spectrum.grid_width (
array) – New grid-widthserror (
arrayor None) – If passed, should be the binned error otherwise None
- Raises:
NotImplementedError – If not implemented
- generate_spectrum_output(model_output: Tuple[ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]] | None, Dict | T | None], output_size: OutputSize | None = OutputSize.heavy) BinnedSpectrumType[source]¶
Generate binned spectrum output.
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¶
Module for the flux binner class
- class FluxBinner(wngrid: ndarray[tuple[int, ...], dtype[float64]], wngrid_width: ndarray[tuple[int, ...], dtype[float64]] | None = None)[source]¶
Bases:
BinnerBins to a wavenumber grid given by
wngridusing 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 gridwngrid_width (
array, optional) – Must have same shape aswngridFull bin widths for each wavenumber grid point given inwngrid. If not provided then this is automatically computed fromwngrid.
- bindown(wngrid: ndarray[tuple[int, ...], dtype[float64]], spectrum: ndarray[tuple[int, ...], dtype[float64]], grid_width: ndarray[tuple[int, ...], dtype[float64]] | None = None, error: ndarray[tuple[int, ...], dtype[float64]] | None = None) Tuple[ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]] | None, ndarray[tuple[int, ...], dtype[float64]] | 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 aswngrid.grid_width (
array, optional) – Wavenumber grid full-widths for the spectrum to be binned down. Must be same shape aswngrid. Optional.error (
array, optional) – Associated errors or noise of the spectrum. Must be same shape aswngrid.Optional parameter.
- Returns:
binned_wngrid (
array) – New wavenumber gridspectrum (
array) – Binned spectrum.grid_width (
array) – New grid-widthserror (
arrayor None) – Binned error if given elseNone
- generate_spectrum_output(model_output: Tuple[ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]] | None, Dict | T | None], output_size: OutputSize | None = OutputSize.heavy) BinnedSpectrumType[source]¶
Generate binned spectrum output.
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:
BinnerBins 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 gridwngrid_width (
array, optional) – Must have same shape aswngridFull bin widths for each wavenumber grid point given inwngrid. If not provided then this is automatically computed fromwngrid.
- 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 aswngrid.grid_width (
array, optional) – Wavenumber grid full-widths for the spectrum to be binned down. Must be same shape aswngrid. Optional.error (
array, optional) – Associated errors or noise of the spectrum. Must be same shape aswngrid.Optional parameter.
- Returns:
binned_wngrid (
array) – New wavenumber gridspectrum (
array) – Binned spectrum.grid_width (
array) – New grid-widthserror (
arrayor None) – Binned error if given elseNone
- generate_spectrum_output(model_output, output_size=OutputSize.heavy)[source]¶
Generate binned spectrum output.
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:
BinnerA special class of binning used for lightcurves.
This is essentially the same as
NativeBinnerbut for lightcurve forward models.- bindown(wngrid: ndarray[tuple[int, ...], dtype[float64]], spectrum: ndarray[tuple[int, ...], dtype[float64]], grid_width: ndarray[tuple[int, ...], dtype[float64]] | None = None, error: ndarray[tuple[int, ...], dtype[float64]] | None = None) Tuple[ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]] | None, ndarray[tuple[int, ...], dtype[float64]] | None][source]¶
Does nothing, only returns function arguments
- generate_spectrum_output(model_output: Tuple[ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]] | None, Dict | T | None], output_size: OutputSize | None = OutputSize.heavy)[source]¶
Generate spectrum output for lightcurves.
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:
BinnerA 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.
- bin_model(model_output: Tuple[ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]] | None, Dict | T | None]) Tuple[ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]] | None, ndarray[tuple[int, ...], dtype[float64]] | None][source]¶
Does nothing, only returns function arguments
- bindown(wngrid: ndarray[tuple[int, ...], dtype[float64]], spectrum: ndarray[tuple[int, ...], dtype[float64]], grid_width: ndarray[tuple[int, ...], dtype[float64]] | None = None, error: ndarray[tuple[int, ...], dtype[float64]] | None = None) Tuple[ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]] | None, ndarray[tuple[int, ...], dtype[float64]] | None][source]¶
Bin down a spectrum from a high resolution to a lower resolution.
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 gridspectrum (
array) – The spectra we wish to bin-down. Must be same shape aswngrid.grid_width (
array, optional) – Wavenumber grid full-widths for the spectrum to be binned down. Must be same shape aswngrid. Optional, generally if you require this but the user does not pass it then you must compute it yourself usingwngrid. This can be done easily using the function func:~taurex.util.compute_bin_edges.error (
array, optional) – Associated errors or noise of the spectrum. Must be same shape aswngrid.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 gridspectrum (
array) – Binned spectrum.grid_width (
array) – New grid-widthserror (
arrayor None) – If passed, should be the binned error otherwise None
- generate_spectrum_output(model_output: Tuple[ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]] | None, Dict | T | None], output_size: OutputSize | None = OutputSize.heavy) BinnedSpectrumType[source]¶
Generate spectrum output for lightcurves.
- Parameters:
model_output (obj:tuple) – Result from running a TauREx3 forward model
output_size (
OutputSize) – Size of the output.
- Returns:
Dictionary of spectra containing both lightcurves and spectra.
- Return type:
dict