utils.kpf_utils

Obs-id, datecode, and timestamp parsing plus UTC/HST and EPRV conversions.

kpfpipe.utils.kpf_utils.get_datecode(s)

Extract the datecode (e.g. ‘20230708’) from an obs_id or filename; raises ValueError if no valid obs_id is found.

kpfpipe.utils.kpf_utils.get_obs_id(fn)

Extract the obs_id (e.g. ‘KP.20240113.23249.10’) from a filename or path; raises ValueError if none is found.

kpfpipe.utils.kpf_utils.get_timestamp(s)

Extract the KPF timestamp (e.g. ‘20240113.23249.10’) from an obs_id, filename, or path; raises ValueError if none is found.

kpfpipe.utils.kpf_utils.hst_to_utc(timestamp)

Convert a KPF HST timestamp (‘YYYYMMDD.SSSSS.FF’) to UTC, in the same KPF format. The inverse of utc_to_hst, kept as its symmetric counterpart: the pipeline only calls utc_to_hst (the data tree is UTC-keyed), so this backs round-trip tests and any future HST-keyed input.

kpfpipe.utils.kpf_utils.is_datecode(s)

Return True if s is a valid 8-digit datecode that parses as a real calendar date, e.g. ‘20240405’.

kpfpipe.utils.kpf_utils.is_obs_id(s)

Return True if s is a valid KPF observation ID, e.g. ‘KP.20240113.23249.10’. Both the format and the embedded date/seconds are checked.

kpfpipe.utils.kpf_utils.is_timestamp(s)

Return True if s is a valid KPF timestamp, e.g. ‘20240113.23249.10’.

Checks all three: the ‘YYYYMMDD.SSSSS.FF’ format, that YYYYMMDD is a real calendar date, and that SSSSS (seconds past midnight) is in [0, 86399]; the sub-second frame field FF is format-checked only. The module’s single source of timestamp validity – every other predicate and raising converter validates through it.

kpfpipe.utils.kpf_utils.kpf_timestamp_to_datetime(timestamp)

Parse a KPF UTC timestamp (‘YYYYMMDD.SSSSS.FF’, sub-second field ignored) into a naive UTC datetime, e.g. ‘20240405.40113.57’ -> datetime(2024, 4, 5, 11, 8, 33).

kpfpipe.utils.kpf_utils.kpf_timestamp_to_eprv_timestamp(timestamp)

Convert a KPF timestamp to EPRV format (‘YYYYMMDDTHHMMSS’, 1-second resolution, sub-second field dropped), e.g. ‘20240405.40113.57’ -> ‘20240405T110833’.

kpfpipe.utils.kpf_utils.utc_to_hst(timestamp)

Convert a KPF UTC timestamp (‘YYYYMMDD.SSSSS.FF’) to HST (Hawaii Standard Time, UTC-10), returned in the same KPF format.