"""Contains the basic definition of an observed spectrum for TauRex 3."""importtypingastimportnumpyasnpimportnumpy.typingasnptfromtaurex.binningimportBinnerfromtaurex.coreimportDerivedType,Fittable,FittingTypefromtaurex.logimportLoggerfromtaurex.outputimportOutputGroupfromtaurex.output.writeableimportWriteable
[docs]classBaseSpectrum(Logger,Fittable,Writeable):"""A base class that represents spectrums. *Abstract class* A base class where spectrums are loaded (or later created). This is used to either plot against the forward model or passed into the optimizer to be used to fit the forward model. """def__init__(self,name:str):"""Initialize. Parameters ---------- name : str Name to be used in logging """Logger.__init__(self,name)Fittable.__init__(self)
[docs]defcreate_binner(self)->Binner:"""Creates the appropriate binning object."""fromtaurex.binningimportFluxBinnerreturnFluxBinner(wngrid=self.wavenumberGrid,wngrid_width=self.binWidths)
@propertydefspectrum(self)->npt.NDArray[np.float64]:"""Spectrum of the observation. **Requires Implementation** Should return the observed spectrum. Raises ------ NotImplementedError """raiseNotImplementedError@propertydefrawData(self)->t.Any:# noqa: N802"""Raw data of the observation. **Requires Implementation** Should return the raw data set. Raises ------ NotImplementedError """raiseNotImplementedError@propertydefwavelengthGrid(self)->npt.NDArray[np.float64]:# noqa: N802"""Wavelength grid of the spectrum in microns. **Requires Implementation** Should return the wavelength grid of the spectrum in microns. This does not need to necessarily match the shape of :func:`spectrum` Raises ------ NotImplementedError """raiseNotImplementedError@propertydefwavenumberGrid(self):# noqa: N802"""Wavenumber grid in :math:`cm^{-1}` Returns ------- wngrid : :obj:`array` """return10000/self.wavelengthGrid@propertydefbinEdges(self)->npt.NDArray[np.float64]:# noqa: N802"""Bin edges of the wavenumber grid. **Requires Implementation** Should return the bin edges of the wavenumber grid Raises ------ NotImplementedError """raiseNotImplementedError@propertydefbinWidths(self)->npt.NDArray[np.float64]:# noqa: N802"""Widths of each bin in the wavenumber grid **Requires Implementation** Should return the widths of each bin in the wavenumber grid Raises ------ NotImplementedError """raiseNotImplementedError@propertydeferrorBar(self)->npt.NDArray[np.float64]:# noqa: N802"""Return error or uncertainty of the spectrum. **Requires Implementation** Should return the error. *Must* be the same shape as :func:`spectrum` Raises ------ NotImplementedError """raiseNotImplementedError@propertydeffittingParameters(self)->t.Dict[str,FittingType]:# noqa: N802"""Return fitting parameters."""returnself.fitting_parameters()@propertydefderivedParameters(self)->t.Dict[str,DerivedType]:# noqa: N802"""Return derived parameters."""returnself.derived_parameters()
[docs]defwrite(self,output:OutputGroup)->OutputGroup:"""Write spectrum to output group."""output.write_array("wlgrid",self.wavelengthGrid)output.write_array("spectrum",self.spectrum)output.write_array("binedges",self.binEdges)output.write_array("binwidths",self.binWidths)output.write_array("errorbars",self.errorBar)returnoutput