3Utility functions for Luna ODiSI 6100 TSV files.
15from .
import filereader
20 list_of_time_intervals: list,
23 Extracts the parts of the measurement data into smaller `.tsv` files.
24 The parts are given by time intervals.
25 The file header is copied as is.
26 A measurement line is copied to the `output_file` if its timestamp
27 \f$t\f$ falls within at least one of the given time intervals:
28 \f$t_{\mathrm{s}} \leq t \leq t_{\mathrm{e}}\f$.
29 Overlapping intervals are supported.
31 \warning The `output_file` is overwritten without asking for confirmation!
33 \param input_file String with the path of the input file (.tsv)
34 \param output_file String with the path of the output file (.tsv)
35 \param list_of_time_intervals List of time intervals.
36 Each interval is given as tuple of its the limits
37 (start time \f$t_{\mathrm{s}}\f$, end time \f$t_{\mathrm{e}}\f$).
38 Both limits can be either `datetime.datetime` or `None`.
39 Setting one or both of the limits to `None` results in an (half) unlimited open interval.
40 It is not necessary that the exact interval boundaries appear in the data.
42 with open(input_file,
"r")
as infile, open(output_file,
"w")
as outfile:
44 entries = line.split(
"\t")
46 timestamp = datetime.datetime.fromisoformat(entries[0].strip())
47 for start_time, end_time
in list_of_time_intervals:
48 if (start_time
is None or timestamp >= start_time)
and (end_time
is None or timestamp <= end_time):
57 keys: list = [
"Channel",
"Sensor Name",
"Sensor Serial Number",
"Length (m)",
"Date"],
58 table_style: str =
"Markdown",
61 Read the metadata from all files matching the `pattern` in a given
62 directory `root_dir`, extract selected metadata entries (`keys`) and
63 display them in a nicely formatted table.
64 Use this function to quickly gain an overview over the content of a
65 directory with measurement files exported to TSV format by Luna ODiSI.
66 The file filtering is done with Python built-in module `glob`.
67 The table formatting is done with `brplotviz`.
68 \param root_dir Directory to scan for TSV files matching the `pattern`.
69 \param pattern File name pattern to select TSV files, according to
70 the specification of the Python `glob` module.
71 \param keys List of dictionary keys to extract.
72 These are the description texts in the file header.
73 \param table_style Table output style supported by `brplotviz`.
74 Please consider the `brplotviz` documentation for available options.
77 for file
in glob.glob(pattern, root_dir=root_dir):
78 file_path = os.path.join(root_dir, file)
80 metadata = reader._read_metadata()
83 row.append(metadata.get(key,
""))
85 head_row = [
"File"] + keys
86 brplotviz.table.print_table(table,
File reader class for the .tsv measurement files exported by the ODiSI 6100 series interrogators by L...
None tsv_extract_time_intervals(str input_file, str output_file, list list_of_time_intervals)
Extracts the parts of the measurement data into smaller .tsv files.
tsv_print_metadata_table(str root_dir, str pattern="*", list keys=["Channel", "Sensor Name", "Sensor Serial Number", "Length (m)", "Date"], str table_style="Markdown")
Read the metadata from all files matching the pattern in a given directory root_dir,...