Weights¶
Classes inheriting form Weight
create weights arrays for spectra. They work very
similar to Masks, but instead of returning a boolean mask they return a float array, containing a weight
for every pixel in a spectrum.
spexxy comes with a few pre-defined weight classes:
WeightFromSigma
creates weights from the spectrum’s SIGMA array.WeightRanges
creates weigths from the given ranges.
Weight¶
-
class
spexxy.weight.
Weight
(*args, **kwargs)¶ Weight is the base class for all objects that can create a weight array for spectra.
-
__call__
(spectrum: spexxy.data.spectrum.Spectrum, filename: str) → numpy.ndarray¶ Creates a new weight for a spectrum.
Parameters: - spectrum – Spectrum to create weight for.
- filename – Name of file containing spectrum to create weight for.
Returns: Array containing weight for given spectrum.
-
__init__
(*args, **kwargs)¶ Initialize a new weight.
-
WeightFromSigma¶
-
class
spexxy.weight.
WeightFromSigma
(squared: bool = False, *args, **kwargs)¶ Reads the SIGMA extension from the given file and creates weights from it as 1/SIGMA.
This class, when called, loads the SIGMA extension from the given file and returns the weights as 1/SIGMA.
-
__call__
(spectrum: spexxy.data.spectrum.Spectrum, filename: str) → numpy.ndarray¶ Creates a new weight for a spectrum from its SIGMA extension.
Parameters: - spectrum – Spectrum to create weight for.
- filename – Name of file containing spectrum to create weight for.
Returns: Array containing weight for given spectrum.
-
__init__
(squared: bool = False, *args, **kwargs)¶ Initializes a new weight.
Parameters: squared – Return 1/SIGMA**2 instead of 1/SIGMA.
-
WeightRanges¶
-
class
spexxy.weight.
WeightRanges
(ranges: List[Tuple[float, float, float]] = None, initial: float = 1.0, *args, **kwargs)¶ Creates a weights array from given ranges.
This class, when called, creates a weights array from the given wavelength ranges.
-
__call__
(spectrum: spexxy.data.spectrum.Spectrum, filename: str) → numpy.ndarray¶ Creates a new weight for a spectrum from the ranges given in the configuration.
Parameters: - spectrum – Spectrum to create weight for.
- filename – Name of file containing spectrum to create weight for.
Returns: Array containing weight for given spectrum.
-
__init__
(ranges: List[Tuple[float, float, float]] = None, initial: float = 1.0, *args, **kwargs)¶ Initializes a new weight.
Parameters: - ranges – List of tuples of (wave start, wave end, weight).
- initial – Initial value for whole array.
-
WeightFromSNR¶
-
class
spexxy.weight.
WeightFromSNR
(keyword: str = 'HIERARCH SPECTRUM SNRATIO', *args, **kwargs)¶ Reads the S/N ratio from the given file and creates weights from it as 1/SQRT(FLUX/SNR).
This class, when called, loads the SNR from the given file and returns weights from it as 1/SQRT(FLUX/SNR).
-
__call__
(spectrum: spexxy.data.spectrum.Spectrum, filename: str) → numpy.ndarray¶ Creates a new weight for a spectrum from its S/N.
Parameters: - spectrum – Spectrum to create weight for.
- filename – Name of file containing spectrum to create weight for.
Returns: Array containing weight for given spectrum.
-
__init__
(keyword: str = 'HIERARCH SPECTRUM SNRATIO', *args, **kwargs)¶ Initializes a new weight.
Parameters: keyword – FITS header keyword containing S/N.
-
WeightFromGrid¶
-
class
spexxy.weight.
WeightFromGrid
(filename, initial: float = 0.0, max_line_depth: float = 0.5, center_weight: float = 1.0, max_step: int = 1, mask_lines: Union[bool, str, List[T]] = True, max_change=(300, 0.3), *args, **kwargs)¶ This class loads the weights from a grid depending on the initial values of the fit parameters by linear interpolation. It returns an array containing the weights.
-
__call__
(spectrum: spexxy.data.spectrum.Spectrum, filename: str) → numpy.ndarray¶ Creates and returns weight array.
Parameters: - spectrum – Spectrum to create weight for.
- filename – Name of spectrum file.
Returns: Array containing the weight for given spectrum.
-
__init__
(filename, initial: float = 0.0, max_line_depth: float = 0.5, center_weight: float = 1.0, max_step: int = 1, mask_lines: Union[bool, str, List[T]] = True, max_change=(300, 0.3), *args, **kwargs)¶ Initializes a new weight.
Parameters: - filename – Name of grid file.
- initial – Initial value for the whole weight array.
- max_line_depth – Central pixel for lines with larger line depth are masked out.
- center_weight – Factor that increases the weight of the central pixel of each line.
- max_step – In iteration steps <= max_step new weights are loaded from the grid.
- mask_lines – List of absorption lines that are always masked out in their centers.
-
WeightFromGridNearest¶
-
class
spexxy.weight.
WeightFromGridNearest
(filename, initial: float = 0.0, max_line_depth: float = 0.5, center_weight: float = 1.0, max_step: int = 1, mask_lines: Union[bool, str, List[T]] = True, max_change=(300, 0.3), *args, **kwargs)¶ - This class loads the weights from a grid depending on the initial values of the fit parameters by choosing the
- nearest neighbour in the grid. It returns an array containing the weights.
-
__call__
(spectrum: spexxy.data.spectrum.Spectrum, filename: str) → numpy.ndarray¶ Creates and returns weight array.
Parameters: - spectrum – Spectrum to create weight for.
- filename – Name of spectrum file.
Returns: Array containing the weight for given spectrum.
-
__init__
(filename, initial: float = 0.0, max_line_depth: float = 0.5, center_weight: float = 1.0, max_step: int = 1, mask_lines: Union[bool, str, List[T]] = True, max_change=(300, 0.3), *args, **kwargs)¶ Initializes a new weight.
Parameters: - filename – Name of grid file.
- initial – Initial value for the whole weight array.
- max_line_depth – Central pixel for lines with larger line depth are masked out.
- center_weight – Factor that increases the weight of the central pixel of each line.
- max_step – In iteration steps <= max_step new weights are loaded from the grid.
- mask_lines – List of absorption lines that are always masked out in their centers.