Skip to content

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 (min, max), or several ranges ((min1, max1), (min2, max2), ...) in increasing order and not overlapping, whose selections are joined along wavelength. Each range needs min < max. Default (-inf, inf).

α_range Range

Right ascension range (min, max) to keep, in degrees. Default (-inf, inf).

δ_range Range

Declination range (min, max) to keep, in degrees. Default (-inf, inf).

nans_strategy ExcludeStrategy

How to exclude NaN fluxes. "pixel" leaves them as individual NaN pixels; "spaxel" excludes every spaxel with any NaN flux. Default "pixel".

F_bad_strategy ExcludeStrategy

How to exclude bad fluxes using F_range. "pixel" excludes each pixel whose flux is at or below F_range[0] or above F_range[1]; "spaxel" excludes spaxels whose median flux over wavelength is outside F_range; "spaxel_max" excludes spaxels whose maximum flux is outside F_range. Both spaxel strategies also exclude spaxels whose fluxes are all NaN. Default "spaxel".

F_range Range

Range (min, max) of acceptable flux, in erg cm⁻² s⁻¹ Å⁻¹, used by F_bad_strategy. Default (BAD_FLUX_THRESHOLD, inf), i.e. (-1e-14, inf).

fibre_status_include tuple[FibreStatus]

Fibre status values to keep (each 0, 1, 2 or 3); spaxels with any other status are excluded. Default (0,).

apply_mask bool

Whether to exclude the pixels flagged in the DRP mask. Default True.

normalise_F_strategy NormaliseStrategy

How from_tiles computes the flux normalisation (see NormaliseStrategy and calc_normalisation). Default "max only".

normalise_F_offset float

Offset of the flux normalisation; the normalised flux is (flux - offset) / scale. Must be a finite float. Default 0.0.

normalise_F_scale float

Scale of the flux normalisation. Must be a positive, finite float. The inverse variance is multiplied by scale**2. Default 1.0.

normalise_αδ_strategy NormaliseStrategy

How from_tiles computes the RA and Dec normalisations (same options as normalise_F_strategy). Default "padded".

normalise_α_offset float

Offset of the RA normalisation, in degrees. Default 0.0.

normalise_α_scale float

Scale of the RA normalisation, in degrees. Default 1.0.

normalise_δ_offset float

Offset of the Dec normalisation, in degrees. Default 0.0.

normalise_δ_scale float

Scale of the Dec normalisation, in degrees. Default 1.0.

Example
from lvm_tools import DataConfig

config = DataConfig.from_tiles(tile, λ_range=(6500.0, 6800.0))
config = DataConfig.from_dict(config.to_dict() | {"apply_mask": False})

default() staticmethod

A config with every setting at its default.

Returns:

Type Description
DataConfig

The default config, the same as DataConfig().

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:

  1. Set α_range and δ_range to a square around all the spaxels of tiles (see get_αδ_ranges).
  2. Clip and filter the data with that config, λ_range and any overrides.
  3. 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.
  4. Apply overrides again, 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 λ_range attribute). It is not computed from the data.

(-inf, inf)
**overrides Any

Any other attributes, by name, e.g. nans_strategy="spaxel".

{}

Returns:

Type Description
DataConfig

The config.

Raises:

Type Description
ValueError

If an override is not an attribute of DataConfig, if a setting is invalid, or if no data are left after clipping or filtering.

TypeError

If a setting has the wrong type.

Example
config = DataConfig.from_tiles(
    tile,
    λ_range=(6500.0, 6800.0),
    normalise_F_strategy="98 only",
)

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 DataConfig, by name.

required

Returns:

Type Description
DataConfig

The config.

Raises:

Type Description
ValueError

If config doesn't have exactly as many entries as DataConfig has attributes, or if a setting is invalid.

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 from_dict.

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 max < min.

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: NANS_STRATEGIES for nans_strategy, F_BAD_STRATEGIES (the default) for F_bad_strategy.

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 int is rejected).

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 int is rejected).

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 bool.