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: object

Code 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 file

  • ext2 (int) – extension number in the data squared FITS file

  • extErr (int) – extension number in the variance FITS file

  • file2 (str) – file name for the data convolved by the square of the PSF. File must exist and be a loadable FITS file. If None, 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 str

  • if file is not of type str

  • if varFile is not of type str

  • if file2 is not None and not of type str

  • if zeropoint is neither int nor float

_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:

  • True if file exists

  • False otherwise

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:

(Astropy Header, ndarray)

Raises:
  • TypeError – if ext is not an int

  • ValueError – 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.

Parameters:
  • arr (ndarray) – array to mask

  • mask (ndarray [bool]) – mask with boolean values

Returns:

array with masked values

Return type:

ndarray

class pixSED.filters.FilterList(filters: List[Filter], mask: Optional[ndarray] = None, code: SEDcode = SEDcode.CIGALE, redshift: Union[int, float] = 0, **kwargs)[source]#

Bases: object

Code 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 (True for bad pixels, False for good ones). If None, no mask is applied.

  • code (SEDcode) – code used to perform the SED fitting. Either LEPHARE or CIGALE are accepted.

  • redshift (int or float) – redshift of the galaxy

  • **kwargs – additional parameters to pass to setCode() and genTable()

Raises:

TypeError

  • if filters is not a list

  • if redshift is neither an int nor a float

  • if 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 ZERO or MIN.

  • texpFac (int) – exposure factor used to divide the exposure time when computing Poisson noise. A value of 0 means 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 ZERO or MIN.

  • scaleFactor (int or float) – factor used to multiply data and std map

  • texpFac (int) – exposure factor used to divide the exposure time when computing Poisson noise. A value of 0 means 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>

Parameters:

filters (Iterable [Filter]) – list of Filter objects

Returns:

list of checked Filter objects

Return type:

list [Filter]

Raises:

TypeError – if one of the filters is not of type Filter

_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 CigaleCat instance 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:

CigaleCat

_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 LePhareCat instance 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 MAG for magnitude or FLUX for flux.

  • magtype (MagType) – magnitude type if data are in magnitude unit. Must either be AB or VEGA.

  • tformat (TableFormat) – format of the table. Must either be MEME if data and error columns are intertwined or MMEE if columns are first data and then errors.

  • ttype (TableType) – data type. Must either be SHORT or LONG.

Returns:

a LePhare catalogue instance

Return type:

LePhareCat

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 = True to get the indices of the non-NaN pixels in the 1D array (before NaN values are removed).

Parameters:

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:

(ndarray, ndarray) or (ndarray, ndarray, ndarray [int])

Raises:

TypeError

  • if data or var are not list

  • if 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

  • If method is ZERO, negative values in the data and error maps are set to 0

  • If method is MIN, negative values in the data and error maps are set to the minimum value in the array

Parameters:
  • data (ndarray) – data map

  • var (ndarray) – variance map

  • mask (ndarray [bool]) – mask used to apply NaN values

Keyword arguments

Parameters:

method (CleanMethod) – method to deal with negative values. Possible values are: ZERO or MIN.

Returns:

cleaned data and variance maps

Return type:

(ndarray, ndarray)

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 0 or texp is None, no Poisson noise is added to the variance map

Parameters:
  • data (ndarray) – data map

  • data2 (ndarray) – data map convolved by the square of the PSF used to add Poisson noise

  • var (ndarray) – variance map

  • mask (ndarray [bool]) – mask map

Keyword arguments

Parameters:
  • cleanMethod (CleanMethod) – method used for the cleaning process

  • texp (int or float) – exposition time

  • texpFac (int) – factor used to divide the exposition time

  • verbose (bool) – whether to print info text or not

Returns:

cleaned data and cleaned variance map (with potentially Poisson noise added)

Return type:

(ndarray, ndarray)

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

Parameters:

maskVal (int or float) – value to put into masked pixels

Returns:

averaged data and averaged error map

Return type:

(ndarray, ndarray)

Raises:

TypeError – if maskVal is neither int nor float

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 ZERO or MIN.

  • scaleFactor (int or float) – 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 of 0 means no Poisson noise is added to the variance map.

Returns:

an output table

Return type:

Astropy Table

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 (int or float) – exposure time in seconds

  • texpFac (int or float) – exposure factor

Raises:
  • TypeError – if texp or texpFac are not both int or float

  • ValueError

    • if texp <= 0

    • if 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:
  • data (ndarray) – data map

  • var (ndarray) – variance map

  • norm (ndarray) – normalisation map which divides data and error maps

Keyword arguments

Parameters:

factor (int or float) – scale factor which multiplies the output array

Returns:

scaled data and variance maps

Return type:

(ndarray, ndarray)

Raises:

ValueError – if data and norm do not have the same shapes

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)                             
Parameters:

code (SEDcode) – code used for SED fitting. Acceptable values are CIGALE and LEPHARE.

Raises:

TypeError – if code is not of type SEDcode

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