exo_k.util.spectrum

@author: jeremy leconte

A module to handle ouputs rebinning and plotting

Module Contents

exo_k.util.spectrum.planckovclum
class exo_k.util.spectrum.Spectrum(value=None, wns=None, wnedges=None, input_spectral_unit='cm^-1', spectral_unit='cm^-1', filename=None, spectral_radiance=False, from_taurex=False, dataset='native_spectrum', **kwargs)[source]

Bases: exo_k.util.spectral_object.Spectral_object

A class defining a Spectrum object to plot and manipulate.

Instanciate with a value, bin centers, and bin edges. Can also load a Taurex spectrum if filename is provided.

Parameters:
  • value (Array) – spectrum values

  • wns (Array) – Spectral grid (can be wavenumbers or wavelengths)

  • wnedges (Array) – Bin edges grid (can be wavenumbers or wavelengths)

  • input_spectral_unit (str) – Unit of the input spectral grid

  • spectral_unit (str) – desired output unit for the spectral grid

  • filename (str) – Name of a file where the spectrum is stored. If a filename is given, there is no need to provide values, wns, …

  • spectral_radiance (bool) – If True, the spectrum is assumed to be a flux in units of inverse spectral units (for example W/micron if the spectral unit is microns) If False, the spectrum is considered as monochromatic values (like Rp/Rs**2)

property total

Defines the weighted sum over the spectrum

convert_spectral_units(input_spectral_unit='cm^-1', spectral_unit='cm^-1', spectral_radiance=None)[source]
Parameters:

spectral_radiance (Optional[bool]) –

normalize(bolometric_flux)[source]

Normalize the spectrum to a specified bolometric flux

Parameters:

bolometric_flux (float) – Integral of the flux over the total bandpass after normalization.

photonize()[source]

Translate to photon count in each bin

dephotonize()[source]

Translate back to energy

integrate_per_bin()[source]

integrate energy in each bin

copy()[source]

Deep copy of the spectrum.

plot_spectrum(ax, per_wavenumber=True, x_axis='wls', xscale=None, yscale=None, **kwarg)[source]

Plot the spectrum

Parameters:
  • ax (pyplot.Axes) – A pyplot axes instance where to put the plot.

  • per_wavenumber (bool, optional) – Defines the units of spectral flux density. False converts to per wavelength units.

  • x_axis (str, optional) – If ‘wls’, x axis is wavelength. Wavenumber otherwise.

  • xscale (str, optional) – If ‘log’ log axes are used.

  • yscale (str, optional) – If ‘log’ log axes are used.

bin_down(wnedges)[source]

Bins down the spectrum to a new grid of wnedges by conserving area.

Parameters:

wnedges (array, np.ndarray) – Wavenumbers of the bin edges to be used

bin_down_cp(wnedges)[source]

Returns a new binned down spectrum to a grid of wnedges by conserving area.

Parameters:

wnedges (array, np.ndarray) – Wavenumbers of the bin edges to be used

Returns:

Spectrum

Binned down spectrum

clip_spectral_range(wn_range=None, wl_range=None)[source]

Limits the data to the provided spectral range (inplace):

  • Wavenumber in cm^-1 if using wn_range argument

  • Wavelength in micron if using wl_range

randomize(uncertainty=0.0)[source]

Adds random noise with a given uncertainty.

std()[source]

Defines standard deviation

abs()[source]

Defines absolute value

log10()[source]

Defines Log 10

read_hdf5(filename=None)[source]

Reads data in a hdf5 file

Parameters:

filename (str) – Name of the file to be created and saved

write_hdf5(filename)[source]

Saves data in a hdf5 format

Parameters:

filename (str) – Name of the file to be created and saved

read_ascii(filename, usecols=(0, 1), skip_header=0)[source]

Saves data in a ascii format

Parameters:
  • filename (str) – Name of the file to be read

  • spec_axis (str) – Whether the spectral axis in the file is wavenumber in cm^-1 (‘wns’) or wavelength in microns (‘wls’)

  • skip_header (int) – Number of lines to skip

write_ascii(filename, fmt='%.18e', spec_axis='wns', header=None)[source]

Saves data in a ascii format

Parameters:

filename (str) – Name of the file to be created and saved

load_taurex(filename, dataset='native_spectrum')[source]

Loads a taurex file

Parameters:
  • filename (str) – Full name (path) of the hdf5 file to load

  • dataset (str) – Name of the hdf5 dataset to load