hispecdrp.datamodels.utils

Functions

_as_model_list(other)

_set_datetime_meta(model)

_set_koa_meta(model)

_set_target_meta(model[, gaia_id])

append_ancestors(target, other)

append_calibrations(target, other)

append_receipts(target, other)

get_first_model(dataset, **kwargs)

get_instrument_alias(instrument_name[, ...])

Get the instrument alias for a given instrument name.

get_instrument_config([input, instrument_name])

Get the instrument configuration class from either a FITS filename or an HDUList.

get_instrument_name(input)

Get the instrument name from either a FITS filename or an HDUList.

get_model_type(input)

Get the data model class from a FITS file path, HDUList, or model name string.

group_by_fiber_combination(input)

Group input models by like-objects in each fiber.

group_by_illuminated_fiber(input)

Associate input models by fiber.

meta_to_csv(output_path)

migrate_receipt_table(table)

Upgrade a RECEIPT table to the current schema by adding any missing columns.

open(init[, copy, config])

Creates a DataModel from a FITS file.

set_instrument(instrument_name)

Set the process-wide default instrument.

_as_model_list(other)[source]
_set_datetime_meta(model)[source]
_set_koa_meta(model)[source]
_set_target_meta(model, gaia_id=None)[source]
append_ancestors(target, other)[source]
append_calibrations(target, other)[source]
append_receipts(target, other)[source]
get_first_model(dataset, **kwargs)[source]
get_instrument_alias(instrument_name, spectrograph=None)[source]

Get the instrument alias for a given instrument name.

Parameters:

instrument_name (str) – The instrument name.

Returns:

instrument_alias (str) – The instrument alias.

get_instrument_config(input=None, instrument_name=None)[source]

Get the instrument configuration class from either a FITS filename or an HDUList.

Parameters:
  • input (str or fits.HDUList, optional) – Either a FITS filename path or an already-opened HDUList object. The INSTRUME keyword will be read from the primary header.

  • instrument_name (str, optional) – The instrument name. If provided, this will be used instead of reading the instrument name from the FITS header.

Returns:

config_class (type) – The instrument config class if found.

Raises:
  • TypeError – If input is neither a string nor an HDUList.

  • ValueError – If no INSTRUME keyword is found in the header, or if the instrument config is not found in INSTRUMENT_CONFIGS.

get_instrument_name(input)[source]

Get the instrument name from either a FITS filename or an HDUList.

Parameters:

input (str or fits.HDUList) – Either a FITS filename path or an already-opened HDUList object. The INSTRUME keyword will be read from the primary header.

Returns:

instrument_name (str) – The instrument name if found.

Raises:
  • TypeError – If input is neither a string nor an HDUList.

  • ValueError – If no INSTRUME keyword is found in the header.

get_model_type(input)[source]

Get the data model class from a FITS file path, HDUList, or model name string.

Parameters:

input (str or fits.HDUList) –

  • FITS HDUList: extracts DATAMODL from primary header

  • str ending in ‘.fits’ or ‘.fit’: interpreted as FITS file path

  • Other str: interpreted as model name

Returns:

model_class (type) – The DataModel class.

Raises:
  • ValueError – If DATAMODL key is missing in the FITS header, or model name not found.

  • TypeError – If source is not HDUList or str.

group_by_fiber_combination(input)[source]

Group input models by like-objects in each fiber.

Parameters:

input (list[str | DataModel]) – List of file paths or DataModel instances.

Returns:

inputs_grouped (dict[tuple[str, …], list[data]]) – Dictionary with keys as tuples of object names per fiber and values as lists of corresponding input models. Example:

>>> inputs_grouped = {
    ('SCIENCE', 'SKY', 'BLOCKED'): [model1, model2],
    ('BLOCKED', 'SCIENCE', 'SKY') : [model3, model4]
}
group_by_illuminated_fiber(input)[source]

Associate input models by fiber.

Parameters:

input (list[str | DataModel]) – List of file paths or DataModel instances.

Returns:

fiber_map (dict[str, object]) – Dictionary mapping fiber identifiers to DataModel instances.

meta_to_csv(output_path)[source]
migrate_receipt_table(table)[source]

Upgrade a RECEIPT table to the current schema by adding any missing columns.

open(init, copy=False, config=None, **kwargs)[source]

Creates a DataModel from a FITS file. Automatically select the right DataModel class based on the ‘DATAMODL’ header keyword.

Parameters:
  • init – filepath (str): Full path to FITS file. DataModel: Return the given DataModel instance or make a copy if copy=True.

  • copy (bool) – If True, return a copy of the DataModel instance. If init is a filepath, this is ignored.

  • config (type, optional) – The instrument configuration class to use for the DataModel.

  • kwargs – Additional keyword arguments for the DataModel constructor.

Returns:

DataModel – The specific DataModel instance.

set_instrument(instrument_name)[source]

Set the process-wide default instrument.

Sets the HISPECDRP_INSTRUMENT_NAME environment variable, so that any newly constructed model with no more specific instrument source (instrument_name=, meta, or filepath) resolves self.config to this instrument’s config class – see DataModel._get_instrument_config. Also sets DataModel._config (the config classproperty’s backing attribute), so that SomeModel.config / cls.config – accessible with no instance at all, e.g. from a classmethod – resolves to it too.

Parameters:

instrument_name (str) – The instrument name (e.g. 'HISPEC', 'PARVI').

Returns:

config_class (type) – The instrument config class that was set.