Configuration API¶
DataConfig holds every setting for preparing data for fitting: which wavelengths and sky
region to keep, which data to exclude, and how to normalise the flux and coordinates.
It is exported from the top-level lvm_tools namespace.
from lvm_tools import DataConfig
config = DataConfig.from_tiles(tile, λ_range=(6500.0, 6800.0)) # computed from the data
config = DataConfig.default() # all defaults
d = config.to_dict()
config = DataConfig.from_dict(d)
DataConfig¶
lvm_tools.DataConfig
dataclass
¶
Settings for preparing LVM data for fitting: what to select, what to exclude, and how to normalise it.
A DataConfig is immutable. Usually it is made with DataConfig.from_tiles, which works
out the RA/Dec ranges and the normalisation offsets and scales from the data, and then
passed with the tiles to FitDataBuilder.
The strategies, F_range, fibre_status_include, apply_mask and the normalisation
offsets and scales are checked when the config is created, raising ValueError (or
TypeError for a value of the wrong type). The wavelength, RA and Dec ranges are
checked when the data are clipped.
Attributes:
| Name | Type | Description |
|---|---|---|
λ_range |
Range | Ranges
|
Wavelength range(s) to keep, in Angstrom. A single range |
α_range |
Range
|
Right ascension range |
δ_range |
Range
|
Declination range |
nans_strategy |
ExcludeStrategy
|
How to exclude NaN fluxes. |
F_bad_strategy |
ExcludeStrategy
|
How to exclude bad fluxes using |
F_range |
Range
|
Range |
fibre_status_include |
tuple[FibreStatus]
|
Fibre status values to keep (each 0, 1, 2 or 3); spaxels
with any other status are excluded. Default |
apply_mask |
bool
|
Whether to exclude the pixels flagged in the DRP mask. Default |
normalise_F_strategy |
NormaliseStrategy
|
How |
normalise_F_offset |
float
|
Offset of the flux normalisation; the normalised flux is
|
normalise_F_scale |
float
|
Scale of the flux normalisation. Must be a positive, finite
float. The inverse variance is multiplied by |
normalise_αδ_strategy |
NormaliseStrategy
|
How |
normalise_α_offset |
float
|
Offset of the RA normalisation, in degrees. Default |
normalise_α_scale |
float
|
Scale of the RA normalisation, in degrees. Default |
normalise_δ_offset |
float
|
Offset of the Dec normalisation, in degrees. Default |
normalise_δ_scale |
float
|
Scale of the Dec normalisation, in degrees. Default |
Example
default()
staticmethod
¶
A config with every setting at its default.
Returns:
| Type | Description |
|---|---|
DataConfig
|
The default config, the same as |
from_tiles(tiles, λ_range=(-np.inf, np.inf), **overrides)
staticmethod
¶
A config with the RA/Dec ranges and normalisations computed from the data.
The steps are:
- Set
α_rangeandδ_rangeto a square around all the spaxels oftiles(seeget_αδ_ranges). - Clip and filter the data with that config,
λ_rangeand anyoverrides. - Compute the flux, RA and Dec normalisations of what is left, using the normalisation strategies. RA and Dec get the larger of their two scales, so the normalised coordinates keep the sky's aspect ratio.
- Apply
overridesagain, so they take precedence over the computed values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tiles
|
LVMTileLike
|
The data to configure for. |
required |
λ_range
|
Range | Ranges
|
Wavelength range(s) to keep, in Angstrom (see the |
(-inf, inf)
|
**overrides
|
Any
|
Any other attributes, by name, e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
DataConfig
|
The config. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an override is not an attribute of |
TypeError
|
If a setting has the wrong type. |
from_dict(config)
staticmethod
¶
A config from a dictionary of all its attributes, as made by to_dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict
|
Every attribute of |
required |
Returns:
| Type | Description |
|---|---|
DataConfig
|
The config. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
TypeError
|
If a key is not an attribute name, or a value has the wrong type. |
to_dict()
¶
The config as a dictionary of its attributes, by name.
Returns:
| Type | Description |
|---|---|
dict
|
The attributes, suitable for |
Type aliases¶
lvm_tools.fit_data.clipping.Range = tuple[float, float]
module-attribute
¶
A (min, max) range.
lvm_tools.fit_data.clipping.Ranges = tuple[Range, ...]
module-attribute
¶
Several (min, max) ranges, e.g. ((6500.0, 6600.0), (6700.0, 6800.0)).
lvm_tools.fit_data.filtering.ExcludeStrategy = Literal['pixel', 'spaxel', 'spaxel_max']
module-attribute
¶
How to exclude bad data: "pixel", "spaxel" or "spaxel_max". nans_strategy accepts
"pixel" and "spaxel"; F_bad_strategy all three (see DataConfig).
lvm_tools.fit_data.filtering.FibreStatus = Literal[0, 1, 2, 3]
module-attribute
¶
A fibre status value from the DRP slitmap: 0, 1, 2 or 3.
lvm_tools.fit_data.normalisation.NormaliseStrategy = Literal[None, 'max only', '98 only', 'extrema', '1σ', '2σ', '3σ', 'padded']
module-attribute
¶
How to compute a normalisation offset and scale from data; see calc_normalisation.
Validation functions¶
DataConfig uses these to check its settings when it is created.
lvm_tools.config.validation.validate_range(x_range)
¶
Check that a range is a (min, max) pair with max >= min.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_range
|
Range
|
The range. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If it doesn't have two values, or if |
lvm_tools.config.validation.validate_excl_strategy(strategy, allowed=F_BAD_STRATEGIES)
¶
Check that an exclusion strategy is one of the allowed values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategy
|
ExcludeStrategy
|
The strategy. |
required |
allowed
|
tuple[str, ...]
|
The values accepted: |
F_BAD_STRATEGIES
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If it is not one of them. |
lvm_tools.config.validation.validate_norm_strategy(strategy)
¶
Check that a value is one of the NormaliseStrategy options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategy
|
NormaliseStrategy
|
The strategy. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If it is not an option. |
lvm_tools.config.validation.validate_fib_status_incl(fibre_status_include)
¶
Check that every fibre status is one of the FibreStatus values (0, 1, 2 or 3).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fibre_status_include
|
tuple[FibreStatus]
|
The fibre status values. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a value is not a known status. |
lvm_tools.config.validation.validate_offset(offset)
¶
Check that a normalisation offset is a finite float.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
offset
|
float
|
The offset. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If it is not a Python or NumPy float (an |
ValueError
|
If it is NaN or infinite. |
lvm_tools.config.validation.validate_scale(scale)
¶
Check that a normalisation scale is a positive, finite float.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
float
|
The scale. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If it is not a Python or NumPy float (an |
ValueError
|
If it is NaN, infinite, or not positive. |
lvm_tools.config.validation.validate_apply_mask(apply_mask)
¶
Check that apply_mask is a bool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
apply_mask
|
bool
|
The value. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If it is not a |