Filter classes#
Code author: Hugo Plombat - LUPM <hugo.plombat@umontpellier.fr> & Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
Base classes used to generate resolved stellar and SFR maps with LePhare or Cigale SED fitting codes.
- class pixSED.filters.Filter(filt: str, file: str, varFile: str, zeropoint: float, ext: int = 0, ext2: int = 0, extErr: int = 0, file2: Optional[str] = None, verbose: bool = True)[source]#
Bases:
objectCode author: Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
Class implementing all data related to a single filter.
Note
Data and variance maps can be given in any units, but the unit of the variance map is expected to be the square of that of the data map. No unit check is performed using header information.
The code will convert the data map using the zeropoint following the expression:
\[d_{\rm{new}} = d_{\rm{original}} \times 10^{-(zpt + 48.6)/2.5}\]where \(d_{\rm{original}}\) is the original data map in any arbitrary unit and \(d_{\rm{new}}\) is the new data map converted in \(\rm erg\,s^{-1}\,Hz^{-1}\,cm^{-2}\). Thus, the zeropoint must be chosen so that the conversion is properly done to that unit.
The variance map will be converted by first taking the square root to have the std and then performing the same conversion as above.
Important
The code assumes by default that all noise types are included in the variance map. If the Poisson noise is missing, one can provide the file2 parameter which is the file containing the data map convolved by the square of the PSF. The code will then use that file to compute its own Poisson noise that will be added in quadrature to the given variance map.
- Parameters:
filt (
str) – filter name. This name must be compatible with the filter names availble in the chosen SED fitting code.file (
str) – file name of the data flux map. File must exist and be a loadable FITS file.varFile (
str) – file name of the variance flux map. File must exist and be a loadable FITS file.zeropoint (
float) – magnitude zeropoint (see note above)
Keyword arguments
- Parameters:
ext (
int) – extension number in the data FITS fileext2 (
int) – extension number in the data squared FITS fileextErr (
int) – extension number in the variance FITS filefile2 (
str) – file name for the data convolved by the square of the PSF. File must exist and be a loadable FITS file. IfNone, no file is loaded and Poisson noise will not be added to the variance map.verbose (
bool) – whether to print info messages or not
- Raises:
TypeError –
if filt is not of type
strif file is not of type
strif varFile is not of type
strif file2 is not
Noneand not of typestrif zeropoint is neither
intnorfloat
- _checkFile(file: str, *args, **kwargs) bool[source]#
Code author: Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
Check whether a file exists.
- Parameters:
file (
str) – file name- Returns:
Trueif file existsFalseotherwise
- Raises:
TypeError – if file is not of type
str
- _loadFits(file: str, ext: int = 0, **kwargs) Tuple[Any][source]#
Code author: Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
Load data and header from a FITS file at the given extension.
- Parameters:
file (
str) – file name
Keyword arguments
- Parameters:
ext (
str) – extension to load data from- Returns:
(None, None) if the file cannot be loaded as a FITS file or if the hdu extension is too large
(header, data)
- Return type:
- Raises:
TypeError – if ext is not an
intValueError – if ext is negative
- static _mask(arr: ndarray, mask: ndarray, *args, **kwargs) ndarray[source]#
Code author: Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
Apply the given mask by placing NaN values onto the array.
- class pixSED.filters.FilterList(filters: List[Filter], mask: Optional[ndarray] = None, code: SEDcode = SEDcode.CIGALE, redshift: Union[int, float] = 0, **kwargs)[source]#
Bases:
objectCode author: Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
Base class implementing the object used to stored SED fitting into.
- Parameters:
filters (
list[Filter]) – filters used to perform the SED fitting
Keyword arguments
- Parameters:
mask (ndarray [
bool]) – mask for bad pixels (Truefor bad pixels,Falsefor good ones). IfNone, no mask is applied.code (SEDcode) – code used to perform the SED fitting. Either
LEPHAREorCIGALEare accepted.redshift (
intorfloat) – redshift of the galaxy**kwargs – additional parameters to pass to
setCode()andgenTable()
- Raises:
TypeError –
if filters is not a
listif redshift is neither an
intnor afloatif one of the filters is not of type
Filter
- _CigaleTableFactory(cleanMethod: CleanMethod = CleanMethod.ZERO, texpFac: int = 0, **kwargs) Tuple[list][source]#
Code author: Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
Factory function used to build a data table for Cigale SED fitting code.
Keyword arguments
- Parameters:
cleanMethod (CleanMethod) – method used to clean pixel with negative values. Accepted values are
ZEROorMIN.texpFac (
int) – exposure factor used to divide the exposure time when computing Poisson noise. A value of0means no Poisson noise is added to the variance map.
- Returns:
(columns, column names and column types)
- Return type:
(
list[int/float/str], list[str], list[Any])
- _LePhareTableFactory(cleanMethod: CleanMethod = CleanMethod.ZERO, scaleFactor: Union[int, float] = 100, texpFac: int = 0, **kwargs) Tuple[list][source]#
Code author: Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
Factory function used to build a data table for LePhare SED fitting code.
Keyword arguments
- Parameters:
cleanMethod (CleanMethod) – method used to clean pixel with negative values. Accepted values are
ZEROorMIN.scaleFactor (
intorfloat) – factor used to multiply data and std maptexpFac (
int) – exposure factor used to divide the exposure time when computing Poisson noise. A value of0means no Poisson noise is added to the variance map.
- Returns:
(columns, column names and column types)
- Return type:
(
list[int/float/str], list[str], list[Any])
- _buildFilters(filters: Iterable[Filter]) list[source]#
Code author: Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
- _checkFilters(msg: str = '', **kwargs) None[source]#
Code author: Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
Keyword arguments
- Parameters:
msg (
str) – message to append to the error message- Raises:
ShapeError – if at least one filter has a different shape
- _toCigaleCat(fname: str) CigaleCat[source]#
Code author: Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
Construct a
CigaleCatinstance given the table associated to the filter list.- Parameters:
fname (
str) – name of the output file containing the catalogue when it is saved- Returns:
a Cigale catalogue instance
- Return type:
- _toLePhareCat(fname: str, tunit: TableUnit = TableUnit.MAG, magtype: MagType = MagType.AB, tformat: TableFormat = TableFormat.MEME, ttype: TableType = TableType.LONG, **kwargs) LePhareCat[source]#
Code author: Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
Construct a
LePhareCatinstance given the table associated to the filter list.- Parameters:
fname (
str) – name of the output file containing the catalogue when it is saved
Keyword arguments
- Parameters:
tunit (TableUnit) – unit of the table data. Must either be
MAGfor magnitude orFLUXfor flux.magtype (MagType) – magnitude type if data are in magnitude unit. Must either be
ABorVEGA.tformat (TableFormat) – format of the table. Must either be
MEMEif data and error columns are intertwined orMMEEif columns are first data and then errors.ttype (TableType) – data type. Must either be
SHORTorLONG.
- Returns:
a LePhare catalogue instance
- Return type:
- static arraysTo1D(data: List[ndarray], var: List[ndarray], indices: bool = False)[source]#
Code author: Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
Convert list of data and variance maps into 1D vectors and remove nan values.
Note
Provide
indices = Trueto get the indices of the non-NaN pixels in the 1D array (before NaN values are removed).Keyword arguments
- Parameters:
indices (
bool) – whether to return the list of indices of non-NaN values or not- Returns:
(1D data, 1D variance (and the indices if indices is
True))- Return type:
- Raises:
TypeError –
if data or var are not
listif one element of data or var is not a ndarray
if indices is not a
bool
- static clean(data: ndarray, var: ndarray, mask: ndarray, method: CleanMethod = CleanMethod.ZERO, **kwargs) Tuple[ndarray][source]#
Code author: Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
Clean given data and error maps by masking pixels and dealing with negative values.
Note
- Parameters:
Keyword arguments
- Parameters:
method (CleanMethod) – method to deal with negative values. Possible values are:
ZEROorMIN.- Returns:
cleaned data and variance maps
- Return type:
- cleanAndNoise(data, data2, var, mask, cleanMethod: CleanMethod = CleanMethod.ZERO, texp: Optional[Union[int, float]] = None, texpFac: int = 0, verbose: bool = False, **kwargs) Tuple[ndarray][source]#
Code author: Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
Clean data and variance maps from bad pixels and add Poisson noise to the variance map.
Note
If texpFac is
0or texp isNone, no Poisson noise is added to the variance map- Parameters:
Keyword arguments
- Parameters:
cleanMethod (CleanMethod) – method used for the cleaning process
texp (
intorfloat) – exposition timetexpFac (
int) – factor used to divide the exposition timeverbose (
bool) – whether to print info text or not
- Returns:
cleaned data and cleaned variance map (with potentially Poisson noise added)
- Return type:
- Raises:
TypeError if
not isinstance(verbose, bool)
- computeMeanMap(maskVal: Union[int, float] = 0, **kwargs) Tuple[ndarray][source]#
Code author: Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
Compute the averaged data and error maps over the spectral dimension for non masked pixels.
Keyword arguments
- filters#
Filter list
- genTable(cleanMethod: CleanMethod = CleanMethod.ZERO, scaleFactor: Union[int, float] = 100, texpFac: int = 0, **kwargs) Table[source]#
Code author: Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
Generate an input table for the SED fitting codes.
Keyword arguments
- Parameters:
cleanMethod (CleanMethod) – method used to clean pixel with negative values. Accepted values are
ZEROorMIN.scaleFactor (
intorfloat) – factor used to multiply data and std map. Only used if SED fitting code is LePhare.texpFac (
int) – exposure factor used to divide the exposure time when computing Poisson noise. A value of0means no Poisson noise is added to the variance map.
- Returns:
an output table
- Return type:
- Raises:
ValueError – if there are no filters in the filter list
- meanMap#
Mean map used when building the table (default is None, updated each time meanMap method is called)
- static poissonVar(data2: ndarray, texp: Union[int, float] = 1, texpFac: Union[int, float] = 1, **kwargs) ndarray[source]#
Code author: Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
Compute a scaled Poisson variance term from a given flux map. The variance \((\Delta F)^2\) is computed as
\[(\Delta F)^2 = | \alpha F |,\]where \(F\) is the flux map and \(\alpha\) is a scale factor defined as
\[\alpha = {\rm{TEXP / TEXPFAC}},\]where \(\rm{TEXP}\) is the exposure time and \(\rm{TEXPFAC}\) is a coefficient used to scale it down.
- Parameters:
data2 (ndarray) – flux map convolved by the square of the PSF
Keyword arguments
- Parameters:
texp (
intorfloat) – exposure time in secondstexpFac (
intorfloat) – exposure factor
- Raises:
TypeError – if texp or texpFac are not both
intorfloatValueError –
if
texp <= 0if
texpFac < 0
- scale(data: ndarray, var: ndarray, norm: ndarray, factor: Union[int, float] = 100) Tuple[ndarray][source]#
Code author: Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
Normalise given data and error maps using a norm map and scale by a certain amount. Necessary for LePhare SED fitting code.
- Parameters:
Keyword arguments
- scaleFac#
Scale factor used to normalise the data and error maps (default is None, updated each time genTable method is called)
- setCigale(*args, **kwargs) None#
Set Cigale as fitting code
- setCode(code: SEDcode, *args, **kwargs) None[source]#
Code author: Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
Set the SED fitting code.
Warning
This function also recomputes and rewrites the output table used for the SED fitting. If you want a table with different parameters you must run
genTable()again, for e.g.>>> from SED.misc import SEDcode, CleanMethod >>> flist = FilterList(filters, mask) # setCode and genTable methods are called with default SED fitting code name >>> flist.setCode(SEDcode.LEPHARE, # setCode and genTable methods are called with 'lephare' SED fitting code name cleanMethod=CleanMethod.MIN, # Additional parameters are passed to genTable scaleFactor=50)
- setLePhare(*args, **kwargs) None#
Set LePhare as fitting code
- shape#
Data shape for easy access
- toCatalogue(fname: str, *args, **kwargs) Catalogue[source]#
Code author: Wilfried Mercier - IRAP/LAM <wilfried.mercier@lam.fr>
Construct a Catalogue instance given the table associated to the filter list and the given SED fitting code.
Note
This function should always be used instead of
_toLePhareCat()or_toCigaleCat()private methods as it automatically builds the correct catalogue object.See their definition to know which parameters to pass.
- Parameters:
fname (
str) – name of the output file containing the catalogue when it is saved*args – (Optional) arguments to pass to the private method building the catalogue
**kwargs – (Optional) keyword aguments to pass to the private method building the catalogue
- Raises:
ValueError – if self.code is not recognised