Module Contents



This class stores the spectral data to be retrieved from a single instrument or observation.

class, path_to_observations=None, data_resolution=None, model_resolution=None, distance=None, external_pRT_reference=None, model_generating_function=None, wlen_range_micron=None, scale=False, scale_err=False, wlen_bins=None, photometry=False, photometric_transformation_function=None, photometric_bin_edges=None, opacity_mode='c-k')

This class stores the spectral data to be retrieved from a single instrument or observation.

Each dataset is associated with an instance of petitRadTrans and an atmospheric model. The pRT instance can be overwritten, and associated with an existing pRT instance with the external_pRT_reference parameter. This setup allows for joint or independant retrievals on multiple datasets.


Identifier for this data set.


Path to observations file, including filename. This can be a txt or dat file containing the wavelength, flux, transit depth and error, or a fits file containing the wavelength, spectrum and covariance matrix.


The distance to the object in cgs units. Defaults to a 10pc normalized distance.


Spectral resolution of the instrument. Optional, allows convolution of model to instrumental line width.


Will be None by default. The resolution of the c-k opacity tables in pRT. This will generate a new c-k table using exo-k. The default (and maximum) correlated k resolution in pRT is \(\lambda/\Delta \lambda > 1000\) (R=500). Lowering the resolution will speed up the computation. If integer positive value, and if opacities == 'lbl' is True, then this will sample the the high-resolution opacities at the specified resolution. This may be desired in the case where medium-resolution spectra are required with a \(\lambda/\Delta \lambda > 1000\), but much smaller than \(10^6\), which is the resolution of the lbl mode. In this case it may make sense to carry out the calculations with lbl_opacity_sampling = 10e5, for example, and then rebinning to the final desired resolution: this may save time! The user should verify whether this leads to solutions which are identical to the rebinned results of the fiducial \(10^6\) resolution. If not, this parameter must not be used. Note the difference between this parameter and the lbl_opacity_sampling parameter in the RadTrans class - the actual desired resolution should be set here.


An existing RadTrans object. Leave as none unless you’re sure of what you’re doing.


A function, typically defined in that returns the model wavelength and spectrum (emission or transmission). This is the function that contains the physics of the model, and calls pRT in order to compute the spectrum.


Set the wavelength range of the pRT object. Defaults to a range +/-5% greater than that of the data. Must at least be equal to the range of the data.


Turn on or off scaling the data by a constant factor. Set to True if scaling the data during the retrieval.


Set the wavelength bins to bin the pRT model to the data. Defaults to the data bins.


Set to True if using photometric data.


Transform the photometry (account for filter transmission etc.). This function must take in the wavelength and flux of a spectrum, and output a single photometric point (and optionally flux error).

photometric_bin_edgesTuple, numpy.ndarray

The edges of the photometric bin in micron. [low,high]


Should the retrieval be run using correlated-k opacities (default, ‘c-k’), or line by line (‘lbl’) opacities? If ‘lbl’ is selected, it is HIGHLY recommended to set the model_resolution parameter. In general, ‘c-k’ mode is recommended for retrievals of everything other than high-resolution (R>40000) spectra.

loadtxt(path, delimiter=',', comments='#')

This function reads in a .txt or .dat file containing the spectrum. Headers should be commented out with ‘#’, the first column must be the wavelength in micron, the second column the flux or transit depth, and the final column must be the error on each data point. Checks will be performed to determine the correct delimiter, but the recommended format is to use a csv file with columns for wavlength, flux and error.


Directory and filename of the data.

delimiterstring, int

The string used to separate values. By default, commas act as delimiter. An integer or sequence of integers can also be provided as width(s) of each field.


The character used to indicate the start of a comment. All the characters occurring on a line after a comment are discarded


Load in an x1d fits file as produced by the STSci JWST pipeline. Expects units of Jy for the flux and micron for the wavelength.


Directory and filename of the data.


Load in a particular style of fits file. Must include extension SPECTRUM with fields WAVLENGTH, FLUX and COVARIANCE (or ERROR).


Directory and filename of the data.


Sets the distance variable in the data class. This does NOT rescale the flux to the new distance. In order to rescale the flux and error, use the scale_to_distance method.


The distance to the object in cgs units.


Updates the distance variable in the data class. This will rescale the flux to the new distance.


The distance to the object in cgs units.

get_chisq(wlen_model, spectrum_model, plotting)

Calculate the chi square between the model and the data.


The wavlengths of the model


The model flux in the same units as the data.


Show test plots.


The log likelihood of the model given the data.

convolve(input_wavelength, input_flux, instrument_res)

This function convolves a model spectrum to the instrumental wavelength using the provided data_resolution Args:


The wavelength grid of the model spectrum


The flux as computed by the model


\(\lambda/\Delta \lambda\), the width of the gaussian kernel to convolve with the model spectrum.


The convolved spectrum.