Skip to content

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 xarray.Dataset.

Data variables, each of shape (1, n_spaxels, n_wavelengths) with dimensions (tile, spaxel, wavelength), held as Dask arrays:

  • flux: flux, in erg cm⁻² s⁻¹ Å⁻¹ (FLUX_UNIT).
  • i_var: inverse variance of the flux, in FLUX_UNIT**-2.
  • lsf_sigma: Gaussian standard deviation of the line spread function, in Angstrom (converted from the FWHM stored in the file).
  • mask: the DRP pixel mask; 1 marks a bad pixel.

Coordinates (NumPy arrays):

  • tile: the exposure number (length 1).
  • spaxel: spaxel index, 0 .. n_spaxels - 1.
  • wavelength: wavelength grid, in Angstrom.
  • mjd: Modified Julian Date of the exposure midpoint, along tile.
  • ra, dec: right ascension and declination of each spaxel, in degrees, shape (1, n_spaxels).
  • fibre_id: fibre identifier from the slitmap, shape (1, n_spaxels).
  • ifu_label: IFU bundle label ("Sci1", "Sci2" or "Sci3").
  • fibre_status: fibre status flag from the slitmap; 0 marks a good fibre.
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 drp_file does not exist.

ValueError

If the primary header lacks the INTSTART and INTEND keywords.

Example
from pathlib import Path
from lvm_tools import LVMTile

tile = LVMTile.from_file(Path("/data/lvm-drp-12345-00001.fits"))

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 (flux, i_var, mask, lsf), each of shape (n_spaxels, n_wavelengths), with the LSF still as a FWHM. The second holds the NumPy arrays (wave, ra, dec, fibre_id, fibre_status, ifu_label), all in native byte order.

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 (tile_id, exp_num, drp_ver, mjd): the tile identifier (an int, or the OBJECT keyword's string if it isn't a number), the exposure number, the DRP version, and the MJD of the exposure midpoint.

Raises:

Type Description
ValueError

If the header lacks the INTSTART and INTEND keywords.

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 OBJECT header keyword. An int when the keyword holds a number (either "...=<id>" or a bare number), otherwise the keyword's string.

exp_num int

Exposure number, from the EXPOSURE keyword.

drp_ver str

Version of the Data Reduction Pipeline, from the DRPVER keyword.

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 LVMTile.data, with the tile dimension as long as the number of exposures; the tile coordinate holds their exposure numbers.

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.

Example
from lvm_tools import LVMTile, LVMTileCollection

tiles = [LVMTile.from_file(p) for p in paths]
collection = LVMTileCollection.from_tiles(tiles)
print(f"Combined shape: {collection.data['flux'].shape}")

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 targettype is "science".

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 INTSTART and INTEND keywords (ISO times of the start and end of the integration).

required

Returns:

Type Description
float

The MJD halfway between INTSTART and INTEND.

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. "LCO".

Raises:

Type Description
ValueError

If the code is missing or not a known observatory (only "LCO" is known).

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 "LCO" (Las Campanas Observatory) is supported.

required

Returns:

Type Description
EarthLocation

The observatory's location, from astropy's site registry.

Raises:

Type Description
ValueError

If the observatory is unknown.