koa_middleware.utils
Functions
Convert a datetime object to an ISO 8601 string with millisecond precision. |
|
|
Generate a KOA filehandle. |
|
Generate the MD5 checksum of a FITS file. |
|
Return the boolean value of an environment variable. |
Get the KOA ID from a datetime string. |
|
|
Checks if a given string is a valid UUID v4. |
|
Convert an ISO 8601 datetime string to Modified Julian Date (MJD). |
|
Convert Modified Julian Date (MJD) to an ISO 8601 datetime string. |
|
Return datetime as: |
- koa_middleware.utils.datetime_to_isot_ms(dt: datetime) str[source]
Convert a datetime object to an ISO 8601 string with millisecond precision.
- Parameters:
dt (datetime) – The input datetime object.
- Returns:
The corresponding datetime string in ISO 8601 format with millisecond precision.
- Return type:
str
- koa_middleware.utils.generate_koa_filehandle(instrument_name: str, datetime_obs: str, koa_id: str) str[source]
Generate a KOA filehandle.
Format:
/{instrument_name}/YYYY/YYMMDD/{koa_id}- where:
instrument_nameis the instrument name.YYYYis the 4-digit year of the observation.YYMMDDis the date of the observation in year-month-day format.koa_idis the KOA ID (same as the filename for HISPEC and PARVI).
- Parameters:
instrument_name (str) – The instrument name.
datetime_obs (str) – The observation date in ISO format.
koa_id (str) – The KOA ID.
- Returns:
The KOA filehandle.
- Return type:
str
- koa_middleware.utils.generate_md5_file(filepath: str) str[source]
Generate the MD5 checksum of a FITS file.
- Parameters:
filepath (str) – The path to the file for which to compute the MD5 checksum.
- Returns:
The MD5 checksum of the file.
- Return type:
str
- koa_middleware.utils.get_env_var_bool(name: str, default: bool | None = None) bool | None[source]
Return the boolean value of an environment variable.
- Parameters:
name (str) – The name of the environment variable.
default (bool | None, optional) – The default value to return if the environment variable is not set. Default is None.
- Returns:
The boolean value of the environment variable, or the default if not set.
- Return type:
bool | None
- koa_middleware.utils.get_koa_id_timestamp_from_datetime(dt: str)[source]
Get the KOA ID from a datetime string.
- Parameters:
dt (str) – The datetime string in ISO format.
- Returns:
koa_id – The KOA ID timestamp in the format ‘YYYYMMDD.SSSSS.ss’.
- Return type:
str
- koa_middleware.utils.is_valid_uuid(value: str) bool[source]
Checks if a given string is a valid UUID v4.
- Parameters:
value (str) – The string to check.
- Returns:
True if the string is a valid UUID v4, False otherwise.
- Return type:
bool
- koa_middleware.utils.isot_to_mjd(isot: str) float[source]
Convert an ISO 8601 datetime string to Modified Julian Date (MJD).
- Parameters:
isot (str) – The input datetime string in ISO 8601 format.
- Returns:
The corresponding Modified Julian Date (MJD).
- Return type:
float
- koa_middleware.utils.mjd_to_isot_ms(mjd: float) str[source]
Convert Modified Julian Date (MJD) to an ISO 8601 datetime string.
- Parameters:
mjd (float) – The input Modified Julian Date (MJD).
- Returns:
The corresponding datetime string in ISO 8601 format.
- Return type:
str
- koa_middleware.utils.postgres_http_date_to_iso(date_str: str) str[source]
- Return datetime as:
YYYY-MM-DDTHH:MM:SS.SSS
- Parameters:
date_str (str) –
The input date string, which can be in one of the following formats:
ISO 8601 strings
Postgres HTTP-date strings like:
’Thu, 12 Feb 2026 00:00:00 GMT’
- Returns:
The datetime string in ISO format.
- Return type:
str