Source code for hispecdrp.datamodels.hispec_config
import importlib.resources
import logging
from astropy.units import Hz
from .base_model import DataModel
from .meta_data import read_meta_schema
import scipy.constants
from typing import ClassVar
logger = logging.getLogger(__name__)
__all__ = ['HISPECConfig']
[docs]
class HISPECConfig:
# hispec_metadata_schema.yaml
instrument_name : ClassVar[str] = 'HISPEC'
instrument_aliases : ClassVar[dict[str, str]] = {'BSPEC': 'HB', 'RSPEC': 'HR'}
num_fibers : ClassVar[int] = 3
# (ny, nx) of the detector plane. Read by DataModel.default_detector_size
# (the base implementation just returns config.DETECTOR_SIZE) to resolve
# the DETECTOR_SIZE_Y/DETECTOR_SIZE_X symbols in an IMAGE_HDU `shape=`
# spec (see DataModel._resolve_shape_axis), as a last resort when no
# extension's already-set real data and no explicit `shape=` constructor
# override provide it instead. HISPEC has one detector, so this default
# is all that's needed; an instrument with multiple, differently sized
# detectors would instead give this config class one attribute per
# detector (e.g. IFS_DETECTOR_SIZE, IMG_DETECTOR_SIZE) and override
# `default_detector_size` on the relevant model classes to pick between
# them from instance state (e.g. self.meta.instrument_mode).
DETECTOR_SIZE : ClassVar[tuple[int, int]] = (4096, 4160)
# TODO: Move LFC params to the calibration DB.
# Mode spacings per HISPEC.DRP.DDD.001 (2024-12-05): the BSPEC
# Menlo/KPF comb is Fabry-Perot filtered to 20 GHz (Sec. 2.4.5.1) and
# the RSPEC electro-optic astrocomb runs at 16 GHz (Sec. 2.4.5.2).
# The DDD does not specify the absolute offset frequency, so ``nu0``
# is unchanged.
lfc_params : ClassVar[dict[str, float]] = {
# NOTE: From https://github.com/Keck-DataReductionPipelines/KPF-Pipeline/blob/master/docs/source/info/data_format.rst
# LFCFRREF 20000000000.0 LFC filtered Offset Freq RR Filter setpoint(Hz)
# LFCCEOFR 5220000000.0 LFC CEO Filtered Setpoint Freq (Hz)
'LFC-B' : {
'nu0' : 5.22E9, # Hz
'delta_nu' : 20E9, # Hz
},
'LFC-R' : {
'nu0' : scipy.constants.c / (1559.91370 * 1E-9), # Hz
'delta_nu' : 16E9, # Hz
},
}
echelle_orders : dict[str, dict[str, int]] = {
'BSPEC': {
'order_start' : 110,
'order_end' : 148
},
'RSPEC': {
'order_start' : 60,
'order_end' : 97
}
}
[docs]
@classmethod
def get_order_list(cls, spectrograph: str) -> list[int]:
"""
Return the list of echelle order numbers for a spectrograph (single source of truth).
Used by benchmarks and trace finding so order count and indices match model meta.
"""
sp = (spectrograph or "").strip().upper()
if sp not in cls.echelle_orders:
return []
o = cls.echelle_orders[sp]
start, end = o['order_start'], o['order_end']
step = 1 if end >= start else -1
return list(range(start, end + step, step))
[docs]
@classmethod
def sync_echelle_orders_for_spectrograph(cls, model: 'DataModel', spectrograph: str) -> None:
"""
Set ``meta.spectrograph``, ``meta.order_start``, and ``meta.order_end`` from
:attr:`echelle_orders` for the given spectrograph.
Use this when constructing or reloading simulated data so echelle order labels
match :meth:`get_order_list` and primitives that rely on ``make_order_vec()``
(e.g. spectral extraction, stellar RV), including after FITS headers carried
stale ORDERST/ORDEREND from an older run.
"""
sp = (spectrograph or "").strip().upper()
if sp not in cls.echelle_orders:
logger.warning(
"Unknown spectrograph %r; leaving echelle order metadata unchanged on model.",
spectrograph,
)
return
o = cls.echelle_orders[sp]
model.meta.spectrograph = sp
model.meta.order_start = o["order_start"]
model.meta.order_end = o["order_end"]
metadata_schema_filename : ClassVar[str] = 'hispec_metadata_schema.yaml'
[docs]
@classmethod
def get_instrument_alias(
cls,
model : DataModel | None = None,
spectrograph : str | None = None
) -> str:
if spectrograph is not None:
instrument_alias = cls.instrument_aliases.get(spectrograph.upper())
return instrument_alias
if model is not None:
spectrograph = model.meta.spectrograph
instrument_alias = cls.instrument_aliases.get(spectrograph.upper())
return instrument_alias