SpectralElement.h
Classes
- SpectralElement -- Describes (a set of related) spectral lines (full description)
- Global Functions -- Global functions (full description)
Types
- GAUSSIAN
-
A gaussian profile
- POLYNOMIAL
-
A polynomial baseline
- N_Types
-
Interface
- Public Members
- SpectralElement()
- SpectralElement(SpectralElement::Types tp, const Double ampl, const Double center, const Double sigma)
- explicit SpectralElement(const uInt n)
- SpectralElement(SpectralElement::Types tp, const Vector<Double> ¶m)
- SpectralElement(const SpectralElement &other)
- ~SpectralElement()
- SpectralElement &operator=(const SpectralElement &other)
- Double operator()(const Double x) const
- Double operator[](const uInt n) const
- static const String *const allTypes(Int &nall, const SpectralElement::Types *&typ)
- static const String &fromType(SpectralElement::Types tp)
- static Bool toType(SpectralElement::Types &tp, const String &typName)
- SpectralElement::Types getType() const
- Double getAmpl() const
- Double getCenter() const
- Double getSigma() const
- Double getFWHM() const
- void get(Vector<Double> ¶m) const
- Double getAmplErr() const
- Double getCenterErr() const
- Double getSigmaErr() const
- Double getFWHMErr() const
- void getError(Vector<Double> &err) const
- uInt getDegree() const
- uInt getOrder() const
- template <class MT> void set(SpectralElement::MT tp, const Types<MT> ¶m)
- template <class MT> void set(const MT<MT> ¶m)
- void setError(const Vector<Double> &err)
- void setAmpl(Double ampl)
- void setCenter(Double center)
- void setSigma(Double sigma)
- void setFWHM(Double fwhm)
- void setDegree(uInt n)
- void fixAmpl(const Bool fix=True)
- void fixCenter(const Bool fix=True)
- void fixSigma(const Bool fix=True)
- void fixFWHM(const Bool fix=True)
- void fix(const Vector<Bool> &fix)
- Bool fixedAmpl() const
- Bool fixedCenter() const
- Bool fixedSigma() const
- Bool fixedFWHM() const
- const Vector<Bool> &fixed() const
- static SpectralElement* fromRecord(const RecordInterface &container)
- virtual Bool fromRecord(String &error, const RecordInterface &in)
- virtual Bool fromString(String &error, const String &in)
- virtual Bool toRecord(String &error, RecordInterface &out) const
- virtual const String &ident() const
- Private Members
- void SpectralElement::checkGauss() const
- void SpectralElement::checkPoly() const
- void SpectralElement::check() const
- static Double sigmaToFWHM (const Double sigma)
- static Double sigmaFromFWHM (const Double fwhm)
Review Status
- Date Reviewed:
- yyyy/mm/dd
- Programs:
- Tests:
Prerequisite
Etymology
From spectral line and element
Synopsis
The SpectralElement class is a container for a spectral line descriptor.
It can contain a single line (like a Gaussian profile), or a set of
related lines (like a doublet or so).
The element can be used in the
SpectralFit class and in the
SpectralEstimate class.
The default type is a Gaussian, defined as:
AMPL.exp[ -(x-CENTER)<sup>2</sup>/2 SIGMA<sup>2</sup>]
Example
Motivation
To have a container for fitting of spectral profiles to an observed spectrum
To Do
Member Description
Types of spectral lines known
Default constructor creates a default Gaussian element with an amplitude
of 1; an integral (sigma=2sqrt(ln2)/pi) of 1;
a central frequency of zero.
SpectralElement(SpectralElement::Types tp, const Double ampl, const Double center, const Double sigma)
Construct with given type and values
Thrown Exceptions
- AipsError if sigma == 0.0
- AipsError if type not GAUSSIAN
Construct an n-degree polynomial
Construct the given tp with the given param
Thrown Exceptions
- AipsError if incorrect number of parameters (e.g. not 3 for GAUSSIAN)
- AipsError if sigma == 0.0
Copy constructor (deep copy)
Thrown Exceptions
- AipsError if sigma == 0.0
Destructor
SpectralElement &operator=(const SpectralElement &other)
Assignment (copy semantics)
Thrown Exceptions
- AipsError if sigma == 0.0
Double operator()(const Double x) const
Evaluate the value of the element at x
Double operator[](const uInt n) const
Get parameter n
Thrown Exceptions
static const String *const allTypes(Int &nall, const SpectralElement::Types *&typ)
Get all the types available as String and codes, and number available
Get a string from the type
static Bool toType(SpectralElement::Types &tp, const String &typName)
Get a type from a (non-case sensitive; minimum match) String
SpectralElement::Types getType() const
Get the data for this element
Thrown Exceptions
- AipsError if element does not have data
(e.g. amplitude for POLYNOMIAL)
Get type of this element
Double getAmpl() const
Get the data for this element
Thrown Exceptions
- AipsError if element does not have data
(e.g. amplitude for POLYNOMIAL)
Get amplitude
Get the data for this element
Thrown Exceptions
- AipsError if element does not have data
(e.g. amplitude for POLYNOMIAL)
Get center value
Double getSigma() const
Double getFWHM() const
Get the data for this element
Thrown Exceptions
- AipsError if element does not have data
(e.g. amplitude for POLYNOMIAL)
Get the width
Get the data for this element
Thrown Exceptions
- AipsError if element does not have data
(e.g. amplitude for POLYNOMIAL)
Get amplitude error estimate
Get the data for this element
Thrown Exceptions
- AipsError if element does not have data
(e.g. amplitude for POLYNOMIAL)
Get center value error estimate
Get the data for this element
Thrown Exceptions
- AipsError if element does not have data
(e.g. amplitude for POLYNOMIAL)
Get the width error estimate
Get the data for this element
Thrown Exceptions
- AipsError if element does not have data
(e.g. amplitude for POLYNOMIAL)
Get the degree of e.g. polynomial
void get(Vector<Double> ¶m) const
void getError(Vector<Double> &err) const
Get the data for this element
Thrown Exceptions
- AipsError if element does not have data
(e.g. amplitude for POLYNOMIAL)
Get the order (i.e. the number of parameters)
template <class MT> void set(SpectralElement::MT tp, const Types<MT> ¶m)
Set data for element
Set all data
Thrown Exceptions
- AipsError if incorrect number of parameters (e.g. not 3 for GAUSSIAN)
- AipsError if sigma == 0.0
Reset a complete element
template <class MT> void set(const MT<MT> ¶m)
Set data for element
Set all data
Thrown Exceptions
- AipsError if incorrect number of parameters (e.g. not 3 for GAUSSIAN)
- AipsError if sigma == 0.0
void setAmpl(Double ampl)
Set data for element
Set amplitude
Thrown Exceptions
- AipsError if non GAUSSIAN
void setCenter(Double center)
Set data for element
Set center
Thrown Exceptions
- AipsError if non GAUSSIAN
Set data for element
void setSigma(Double sigma)
void setFWHM(Double fwhm)
Set width
Thrown Exceptions
- AipsError if non GAUSSIAN
- AipsError if sigma == 0.0
Set degree
Thrown Exceptions
- AipsError if non POLYNOMIAL
void fix(const Vector<Bool> &fix)
Set fixed parameters (True) or unset them (False)
Thrown Exceptions
- AipsError if incorrect number of parameters (e.g. not 3 for GAUSSIAN)
Fix/unfix all in one go
void fixAmpl(const Bool fix=True)
void fixCenter(const Bool fix=True)
void fixSigma(const Bool fix=True)
void fixFWHM(const Bool fix=True)
Set fixed parameters (True) or unset them (False)
Thrown Exceptions
- AipsError if incorrect number of parameters (e.g. not 3 for GAUSSIAN)
Get the fix state[s]
Thrown Exceptions
- AipsError if incorrect number of parameters (e.g. not 3 for GAUSSIAN)
static SpectralElement* fromRecord(const RecordInterface &container)
Construct from record. Must hold fields "type" (String) and
"parameters" (Vector). For type=GAUSSIAN, parameters
holds amplitude, center and sigma. For type=POLYNOMIAL,
parameters(0) holds the degree.
virtual Bool fromRecord(String &error, const RecordInterface &in)
virtual Bool fromString(String &error, const String &in)
Create a SpectralElement from a record.
An error message is generated, and False
returned if an invalid record is given. A valid record will return True.
A valid record contains the following fields (any additional fields are
ignored):
- type = TpString: type of element (gaussian etc; case
insensitive)
- parameters = TpVector(Double): one or more values giving the parameters
for the type
A SpectralElement can be created from a string. In that case the string
will only indicate the type of element (like gaussian), and will
create a default element of that given type.
Error messages are postfixed to error.
virtual Bool toRecord(String &error, RecordInterface &out) const
Save to a record. The return will be False and an error
message generated only if the SpectralElement is illegal (could not happen)
Error messages are postfixed to error. For Gaussian elements,
the width is defined as a FWHM in the record interface.
virtual const String &ident() const
Get the identification of a record
void SpectralElement::checkGauss() const
Check if GAUSSIAN type
Thrown Exceptions
- AipsError if non-Gaussian
void SpectralElement::checkPoly() const
Check if POLYNOMIAL type
Thrown Exceptions
- AipsError if non-polynomial
void SpectralElement::check() const
Check if sigma non-equal to zero and positive if a GAUSSIAN
Thrown Exceptions
- AipsError if illegal sigm
static Double sigmaToFWHM (const Double sigma)
static Double sigmaFromFWHM (const Double fwhm)
Sigma to FWHM
Convert from sigma to FWHM and vice versa
Interface
- ostream &operator<<(ostream &os, const SpectralElement &elem)
Member Description
ostream &operator<<(ostream &os, const SpectralElement &elem)
Output declaration