Miscellaneous API#

Time miscellaneous module.

majis.misc.time.fmt_datetime(*times: str | datetime64, ref: str | dict | tuple | None = None) str | list[str][source]#

Format relative datetime for a time or a list of times.

majis.misc.time.fmt_timedelta(dt: timedelta64) str[source]#

Format time delta.

majis.misc.time.get_datetime(time: str, refs: dict | str | list | None = None) datetime64[source]#

Datetime getter.

Events module.

majis.misc.events.concatenate(*events: EventsList | EventsDict, flat: bool = False, overlap: bool = False) EventsList | EventsDict[source]#

Concatenate ITL events.

Note

By default, concatenated blocks must not overlap each other. This can be disable with overlap=True.

majis.misc.events.flatten(events: tuple | list | EventsList | EventsDict | AbstractEvent) EventsList[source]#

Flatten multi events object.

majis.misc.events.group(events: tuple | list | EventsList | EventsDict) EventsDict[source]#

Group events by observation name.

Event file miscellaneous module.

majis.misc.evf.read_evf(fname: Path | str | list | None, comment: str = '#') dict | None[source]#

Read and extract EVF references and times.

majis.misc.evf.ref_count(key: str) tuple[str, int][source]#

Extract reference name and count from EVF key.

majis.misc.evf.ref_key(ref: str | dict | tuple) tuple[str, datetime][source]#

Format relative datetime reference key.

CSV miscellaneous module.

majis.misc.csv.fmt_csv(blocks: dict | EventsList | EventsDict, ref: str | None = None, sep: str = ';') str[source]#

Format CSV format.

majis.misc.csv.get_header(blocks: list[list | dict] | EventsList | EventsDict, ref: str | dict | None = None) list[source]#

Get CSV header.

The keys are unique and ordered with the following rules:

  • If OBS_NAME is present, it will be placed first.

  • t_start and t_end are required and replaced by OBS_START

    and OBS_END and placed after OBS_NAME (if present).

  • if ref time is provided OBS_START_REL and OBS_END_REL

    are appended after OBS_START and OBS_END.

  • COMMENTS is present, it will always put last.

majis.misc.csv.get_value(block: dict | Event | EventWindow, key: str, ref: str | None = None) str[source]#

Format block value.

This method extract the block value for a given property and re-format the datetime if necessary.

Comments values are escaped with double quotes (”â€Ļ”).