padre_craft.util.util#

Functions

filename_to_datatype(filename)

Convert a filename to its corresponding data type descriptor.

create_craft_filename(time, level, ...[, ...])

Generate the MEDDEA filename based on the provided parameters.

parse_science_filename(filepath)

Parses a science filename into its constituent properties.

convert_meddea_colnames(ts)

Convert MeDDEA column names from OBC standard to padre_meddea standard.

padre_craft.util.util.convert_meddea_colnames(ts: TimeSeries) TimeSeries[source]#

Convert MeDDEA column names from OBC standard to padre_meddea standard. This function renames columns in a TimeSeries object from the OBC (Onboard Computer) MeDDEA housekeeping naming convention to the PADRE MeDDEA housekeeping naming convention. Only columns that exist in the input TimeSeries will be renamed.

Parameters:

ts (TimeSeries) – A TimeSeries object containing MeDDEA data with OBC standard column names.

Returns:

TimeSeries – The same TimeSeries object with renamed columns following the padre_meddea standard. Columns not listed in the mapping dictionary remain unchanged.

padre_craft.util.util.create_craft_filename(time: Time, level: str, descriptor: str, version: str, test: bool = False, overwrite: bool = False) str[source]#

Generate the MEDDEA filename based on the provided parameters.

Parameters:
  • time (Time) – The time associated with the data.

  • level (str) – The data level (e.g., “L1”, “L2”).

  • descriptor (str) – The data descriptor (e.g., “SCI”, “CAL”).

  • test (str) – The test identifier (e.g., “TEST1”, “TEST2”).

  • overwrite (bool) – Whether to overwrite existing files.

Returns:

str – The generated MEDDEA filename.

padre_craft.util.util.filename_to_datatype(filename: Path) str[source]#

Convert a filename to its corresponding data type descriptor.

This function extracts the data type from a filename by parsing tokens between ‘get_’ and ‘_Data’ in the filename, then matches it against known data type mappings in TOKEN_TO_DATATYPE.

Parameters:

filename (Path or str) – The path to the file whose data type needs to be determined. If a string is provided, it will be converted to a Path object.

Returns:

str – The data type corresponding to the filename if found in TOKEN_TO_DATATYPE, otherwise returns the parsed token with a warning logged.

Examples

>>> filename_to_datatype(Path("padre_get_MEDDEA_HOUSE_KEEPING_Data_1762493454480_1762611866270.csv"))
'meddea'

Notes

The function expects filenames to follow the pattern: get_<descriptor>_Data where <descriptor> contains the data type identifier that can be mapped to a known data type via TOKEN_TO_DATATYPE dictionary.

Warning

If no matching data type is found in TOKEN_TO_DATATYPE, a warning is logged and the raw parsed token is returned.

padre_craft.util.util.parse_science_filename(filepath: str) dict[source]#

Parses a science filename into its constituent properties.

Parameters:

filepath (str) – Fully qualified filepath of an input file.

Returns:

dict – Parsed fields such as instrument, mode, test, time, level, version, and descriptor.

Raises:

ValueError – If mission name or instrument is not recognized, or time format is invalid.