hispecdrp.calibrations.run_caldb

Sync calibration metadata from KOA and download missing calibration files.

This script uses the HISPECCalibrationStore to sync calibration records from the remote Keck Observatory Archive (KOA) into the local SQLite database, download any calibration files that are in the DB but missing from the local cache, and register calibration files that exist in the cache but are not yet in the DB. At the end of each run it prints a summary of all files in the local calibration store.

The calibration cache and local database path is taken from the KOA_CALIBRATION_CACHE environment variable. If unset, it defaults to <astropy cache>/hispecdrp_calibration_cache/.

See docs/source/installation.rst and https://oirlab.github.io/KOA_Middleware/installation.html for setup and authentication.

Functions

_ensure_cache_env()

Set KOA_CALIBRATION_CACHE to a default if not already set.

_print_local_store_summary(store)

Print a summary of each file in the local calibration store.

get_master_calibrations([meta, ...])

Fetch master calibration models from the calibration store for the given meta.

main()

Parse command-line arguments and run the calibration DB sync.

run(*[, instrument_name, connect_remote, ...])

Sync the calibration store from remote, download missing files, and print a summary.

get_master_calibrations(meta=None, *, instrument_name=None, instrument_era='0.0.1', spectrograph='RSPEC', mjd_start=None, datetime_obs=None, connect_remote=True, sync_first=True)[source]

Fetch master calibration models from the calibration store for the given meta.

Uses the same store and selectors as run(): syncs from remote (if sync_first), then selects and downloads the appropriate DQ, saturation, gain, detector flat, bias, dark, and read noise calibrations for the observation time and spectrograph. Each calibration file is downloaded if not already in the cache.

Parameters:
  • meta (dict or None, optional) – Metadata dict with keys instrument_era, spectrograph, mjd_start (used by selectors). If None, built from the keyword arguments below. Default is None.

  • instrument_name (str or None, optional) – Instrument name for the store. Used when meta is None. Default is None.

  • instrument_era (str, optional) – Instrument era for selection. Used when meta is None. Default is “0.0.1”.

  • spectrograph (str, optional) – Spectrograph (e.g. ‘RSPEC’, ‘BSPEC’). Used when meta is None. Default is “RSPEC”.

  • mjd_start (float or None, optional) – MJD start time for selection. Used when meta is None. If both mjd_start and datetime_obs are None, uses current time. Default is None.

  • datetime_obs (str or None, optional) – ISO datetime for observation. Used when meta is None to set mjd_start if mjd_start is not provided. Default is None.

  • connect_remote (bool, optional) – Whether to connect to remote KOA. Default is True.

  • sync_first (bool, optional) – If True, sync records from remote and add local cache files to the DB before selecting. Default is True.

Returns:

dict – Dictionary with keys: dq, saturation, gain, detflat, bias, dark, rn. Each value is the corresponding calibration data model (opened from the store).

Raises:

ValueError – If a required calibration has no candidate in the store.

main()[source]

Parse command-line arguments and run the calibration DB sync.

Configures logging via hispecdrp.utils.logging.setup_default_logging(), then calls run() with the parsed options. See the script help (e.g. python -m hispecdrp.calibrations.run_caldb --help) for available arguments.

Returns:

None

run(*, instrument_name=None, connect_remote=True, sync_only=False, download_missing=True, cal_type=None, sync_mode='id', dry_run=False)[source]

Sync the calibration store from remote, download missing files, and print a summary.

Ensures KOA_CALIBRATION_CACHE is set, then opens a HISPECCalibrationStore and (1) optionally syncs calibration metadata from the remote KOA into the local DB, (2) optionally downloads calibration files that are in the DB but not in the cache, (3) registers any FITS files in the cache that are not yet in the DB, (4) prints a summary of all calibrations in the local store.

Parameters:
  • instrument_name (str or None, optional) – Instrument name (e.g. ‘hispec’). If None, uses HISPECDRP_INSTRUMENT_NAME or the package default.

  • connect_remote (bool, optional) – Whether to connect to the remote KOA. If True, sync from remote is attempted when remote_db is available. Default is True.

  • sync_only (bool, optional) – If True, only sync metadata from remote and skip downloading missing files. Default is False.

  • download_missing (bool, optional) – If True (and not sync_only), download calibrations that are in the local DB but missing from the cache. Default is True.

  • cal_type (str or None, optional) – If set, restrict downloads to this calibration type (e.g. ‘dark’, ‘flat’). Default is None (all types).

  • sync_mode (str, optional) – Mode for sync_records_from_remote: ‘id’ or ‘last_updated’. Default is ‘id’.

  • dry_run (bool, optional) – If True, log intended actions without syncing or downloading. Default is False.

Returns:

None