Data Loading API¶
Classes for reading LVM DRP files lazily and combining exposures. LVMTile and
LVMTileCollection are exported from the top-level lvm_tools namespace; the rest lives
in lvm_tools.data.
LVMTile¶
lvm_tools.LVMTile
dataclass
¶
One LVM exposure: its science-fibre spectra and metadata, read lazily from a DRP file.
Create one with LVMTile.from_file. The cubes are Dask arrays, so nothing is read from
disk until values are computed, and selecting part of the data (for example a wavelength
window) only reads that part.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
Dataset
|
The exposure as an Data variables, each of shape
Coordinates (NumPy arrays):
|
meta |
LVMTileMeta
|
The exposure's metadata. |
from_file(drp_file)
classmethod
¶
Read an exposure from a DRP FITS file.
Only the science fibres are kept. The flux, inverse variance, mask and LSF cubes are
wrapped lazily as Dask arrays (chunked by CHUNKSIZE); the wavelength grid and the
per-fibre coordinates are read immediately.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drp_file
|
Path | str
|
Path to the DRP FITS file. |
required |
Returns:
| Type | Description |
|---|---|
LVMTile
|
The tile. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If |
ValueError
|
If the primary header lacks the |
get_science_data(drp_hdulist)
staticmethod
¶
Read the science fibres' cubes and coordinates from an open DRP file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drp_hdulist
|
HDUList
|
The open DRP file. |
required |
Returns:
| Type | Description |
|---|---|
tuple[tuple, tuple]
|
Two tuples. The first holds the lazy Dask cubes |
get_metadata(drp_hdulist)
staticmethod
¶
Read the metadata of an exposure from the primary header of an open DRP file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drp_hdulist
|
HDUList
|
The open DRP file. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int | str, int, str, float]
|
The four values |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the header lacks the |
LVMTileMeta¶
lvm_tools.data.tile.LVMTileMeta
dataclass
¶
Metadata of one LVM exposure, read from the primary header of its DRP file.
Attributes:
| Name | Type | Description |
|---|---|---|
filename |
str
|
Name of the DRP FITS file (without its directory). |
tile_id |
int | str
|
LVM tile identifier, from the |
exp_num |
int
|
Exposure number, from the |
drp_ver |
str
|
Version of the Data Reduction Pipeline, from the |
LVMTileCollection¶
lvm_tools.LVMTileCollection
dataclass
¶
Several LVM exposures, combined along the tile dimension.
Create one with LVMTileCollection.from_tiles. It can be used wherever an LVMTile can
(see LVMTileLike).
Attributes:
| Name | Type | Description |
|---|---|---|
data |
Dataset
|
The combined data. It has the same variables and coordinates as |
meta |
Mapping[int, LVMTileMeta]
|
The metadata of each exposure, keyed by exposure number. |
from_tiles(tiles)
classmethod
¶
Combine tiles into a collection.
The tiles' datasets are concatenated along tile with xarray.concat, which aligns
the other coordinates (e.g. spaxel and wavelength) between them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tiles
|
list[LVMTile]
|
The tiles to combine. |
required |
Returns:
| Type | Description |
|---|---|
LVMTileCollection
|
The collection. |
Type aliases¶
lvm_tools.data.tile.LVMTileLike = LVMTile | LVMTileCollection
module-attribute
¶
Either an LVMTile or an LVMTileCollection. Functions that take one work the same way on a
single exposure and on several.
Constants¶
These are defined in lvm_tools.data.tile.
lvm_tools.data.tile.SIGMA_TO_FWHM = 2.0 * np.sqrt(2.0 * np.log(2))
module-attribute
¶
Ratio of a Gaussian's FWHM to its standard deviation, 2 * sqrt(2 * ln 2) (about 2.355).
lvm_tools.data.tile.FWHM_TO_SIGMA = 1.0 / SIGMA_TO_FWHM
module-attribute
¶
Ratio of a Gaussian's standard deviation to its FWHM, 1 / SIGMA_TO_FWHM (about 0.4247).
lvm_tools.data.tile.FLUX_UNIT = u.erg * u.cm ** -2 * u.s ** -1 * u.angstrom ** -1
module-attribute
¶
Unit of the flux: erg cm⁻² s⁻¹ Å⁻¹. The inverse variance is in FLUX_UNIT**-2.
lvm_tools.data.tile.SPECTRAL_UNIT = u.angstrom
module-attribute
¶
Unit of the wavelengths and of the LSF width: Angstrom.
lvm_tools.data.tile.SPATIAL_UNIT = u.degree
module-attribute
¶
Unit of the spaxel coordinates (RA and Dec): degree.
lvm_tools.data.tile.CHUNKSIZE = (-1, 512)
module-attribute
¶
Dask chunks of the (fibre, wavelength) cubes read by LVMTile.from_file: all fibres, and
512 pixels in wavelength.
Reading DRP files¶
lvm_tools.data.tile.get_science_inds(slitmap)
¶
Indices of the science fibres in a DRP slitmap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slitmap
|
FITS_rec
|
The slitmap table (the last HDU of a DRP file). |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
The row indices whose |
lvm_tools.data.coordinates.get_mjd(header)
¶
The Modified Julian Date of the midpoint of an exposure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
header
|
Header
|
A DRP primary header with the |
required |
Returns:
| Type | Description |
|---|---|
float
|
The MJD halfway between |
Raises:
| Type | Description |
|---|---|
ValueError
|
If either keyword is missing. |
lvm_tools.data.coordinates.get_observatory_code(header)
¶
The observatory code in a FITS header's OBSERVAT keyword.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
header
|
Header
|
A DRP primary header. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The code, e.g. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the code is missing or not a known observatory (only |
lvm_tools.data.coordinates.get_observatory_location(observatory)
¶
The location on Earth of an observatory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observatory
|
str
|
Observatory code. Only |
required |
Returns:
| Type | Description |
|---|---|
EarthLocation
|
The observatory's location, from astropy's site registry. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the observatory is unknown. |