padre_meddea.util.util#

Provides general utility functions.

Functions

parse_science_filename(filepath)

Parses a science filename into its constituent properties.

parse_raw_meddea_filename(filename)

Parse a raw meddea filename

create_science_filename(instrument, time, ...)

Return a compliant filename.

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

Generate the MEDDEA filename based on the provided parameters.

get_filename_version_base()

Get the two most significant bits of the version number based on the current version of the software.

increment_filename_version(file_path[, ...])

Given a filename, increment the version number by one.

calc_time(pkt_time_s[, pkt_time_clk, ph_clk])

Convert times to a Time object

has_baseline(filename[, packet_count])

Given a stream of photon packets, check whether the baseline measurement is included.

is_consecutive(arr)

Return True if the packet sequence numbers are all consecutive integers, has no missing numbers.

padre_meddea.util.util.calc_time(pkt_time_s, pkt_time_clk=0, ph_clk=0) Time[source]#

Convert times to a Time object

padre_meddea.util.util.create_meddea_filename(time: Time, level: str, descriptor: str, test: str, 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_meddea.util.util.create_science_filename(instrument: str, time: str, level: str, version: str, mode: str = '', descriptor: str = '', test: bool = False)[source]#

Return a compliant filename. The format is defined as

{mission}_{inst}_{mode}_{level}{test}_{descriptor}_{time}_v{version}.cdf

This format is only appropriate for data level >= 1.

Parameters:
  • instrument (str) – The instrument name. Must be one of the following “eea”, “nemesis”, “merit”, “spani”

  • time (str (in isot format) or ~astropy.time) – The time

  • level (str) – The data level. Must be one of the following “l0”, “l1”, “l2”, “l3”, “l4”, “ql”

  • version (str) – The file version which must be given as X.Y.Z

  • descriptor (str) – An optional file descriptor.

  • mode (str) – An optional instrument mode.

  • test (bool) – Selects whether the file is a test file.

Returns:

filename (str) – A CDF file name including the given parameters that matches the mission’s file naming conventions

Raises:
  • ValueError – If the instrument is not recognized as one of the mission’s instruments:

  • ValueError – If the data level is not recognized as one of the mission’s valid data levels:

  • ValueError – If the data version does not match the mission’s data version formatting conventions:

  • ValueError – If the data product descriptor or instrument mode do not match the mission’s formatting conventions:

padre_meddea.util.util.get_filename_version_base() str[source]#

Get the two most significant bits of the version number based on the current version of the software.

Returns:

str – The base version string for the filename. For example, “1.0”.

padre_meddea.util.util.has_baseline(filename: Path, packet_count=10) bool[source]#

Given a stream of photon packets, check whether the baseline measurement is included. Baseline packets have one extra word per photon for a total of 4 words (8 bytes).

This function calculates the number of hits in the packet assuming 4 words per photon. If the resultant is not an integer number then returns False.

Parameters:

packet_bytes (byte string) – Photon packet bytes, must be an integer number of whole packets and greaterh

Returns:

result (bool)

padre_meddea.util.util.increment_filename_version(file_path: Path, version_index=0)[source]#

Given a filename, increment the version number by one.

Parameter#

version_index: int

The version index to increment. Index 0 is least significant version.

returns:

filename (str)

padre_meddea.util.util.is_consecutive(arr: array) bool[source]#

Return True if the packet sequence numbers are all consecutive integers, has no missing numbers.

padre_meddea.util.util.parse_raw_meddea_filename(filename: str)[source]#

Parse a raw meddea filename

Parameters:

filename (str)

Returns:

tokens (dict)

padre_meddea.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.