:py:mod:`exo_k.util.spectrum` ============================= .. py:module:: exo_k.util.spectrum .. autoapi-nested-parse:: @author: jeremy leconte A module to handle ouputs rebinning and plotting Module Contents --------------- .. py:data:: planckovclum .. py:class:: 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) Bases: :py:obj:`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. :param value: spectrum values :type value: :class:`Array` :param wns: Spectral grid (can be wavenumbers or wavelengths) :type wns: :class:`Array` :param wnedges: Bin edges grid (can be wavenumbers or wavelengths) :type wnedges: :class:`Array` :param input_spectral_unit: Unit of the input spectral grid :type input_spectral_unit: :class:`str` :param spectral_unit: desired output unit for the spectral grid :type spectral_unit: :class:`str` :param filename: Name of a file where the spectrum is stored. If a filename is given, there is no need to provide values, wns, ... :type filename: :class:`str` :param spectral_radiance: 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) :type spectral_radiance: :class:`bool` .. py:property:: total Defines the weighted sum over the spectrum .. py:method:: convert_spectral_units(input_spectral_unit='cm^-1', spectral_unit='cm^-1', spectral_radiance = None) .. py:method:: normalize(bolometric_flux) Normalize the spectrum to a specified bolometric flux :param bolometric_flux: Integral of the flux over the total bandpass after normalization. :type bolometric_flux: :class:`float` .. py:method:: photonize() Translate to photon count in each bin .. py:method:: dephotonize() Translate back to energy .. py:method:: integrate_per_bin() integrate energy in each bin .. py:method:: copy() Deep copy of the spectrum. .. py:method:: plot_spectrum(ax, per_wavenumber=True, x_axis='wls', xscale=None, yscale=None, **kwarg) Plot the spectrum :param ax: A pyplot axes instance where to put the plot. :type ax: :class:`pyplot.Axes` :param per_wavenumber: Defines the units of spectral flux density. False converts to per wavelength units. :type per_wavenumber: :class:`bool`, *optional* :param x_axis: If 'wls', x axis is wavelength. Wavenumber otherwise. :type x_axis: :class:`str`, *optional* :param xscale: If 'log' log axes are used. :type xscale: :class:`str`, *optional* :param yscale: If 'log' log axes are used. :type yscale: :class:`str`, *optional* .. py:method:: bin_down(wnedges) Bins down the spectrum to a new grid of wnedges by conserving area. :param wnedges: Wavenumbers of the bin edges to be used :type wnedges: :class:`array`, :class:`np.ndarray` .. py:method:: bin_down_cp(wnedges) Returns a new binned down spectrum to a grid of wnedges by conserving area. :param wnedges: Wavenumbers of the bin edges to be used :type wnedges: :class:`array`, :class:`np.ndarray` :returns: :class:`Spectrum` Binned down spectrum .. py:method:: clip_spectral_range(wn_range=None, wl_range=None) 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 .. py:method:: randomize(uncertainty=0.0) Adds random noise with a given uncertainty. .. py:method:: std() Defines standard deviation .. py:method:: abs() Defines absolute value .. py:method:: log10() Defines Log 10 .. py:method:: read_hdf5(filename=None) Reads data in a hdf5 file :param filename: Name of the file to be created and saved :type filename: :class:`str` .. py:method:: write_hdf5(filename) Saves data in a hdf5 format :param filename: Name of the file to be created and saved :type filename: :class:`str` .. py:method:: read_ascii(filename, usecols=(0, 1), skip_header=0) Saves data in a ascii format :param filename: Name of the file to be read :type filename: :class:`str` :param spec_axis: Whether the spectral axis in the file is wavenumber in cm^-1 ('wns') or wavelength in microns ('wls') :type spec_axis: :class:`str` :param skip_header: Number of lines to skip :type skip_header: :class:`int` .. py:method:: write_ascii(filename, fmt='%.18e', spec_axis='wns', header=None) Saves data in a ascii format :param filename: Name of the file to be created and saved :type filename: :class:`str` .. py:method:: load_taurex(filename, dataset='native_spectrum') Loads a taurex file :param filename: Full name (path) of the hdf5 file to load :type filename: :class:`str` :param dataset: Name of the hdf5 dataset to load :type dataset: :class:`str`