File Formats
flexlib
supports several file formats for storing measurement data.
Supported Formats
RSF V1
: A legacy binary format. It’s compact but less flexible. Supports annotations.RSF V2
: The current standard binary format. It offers a good balance of size and flexibility. Supports annotations.CSV
: A standard comma-separated value text format. It’s human-readable and easy to parse with other tools, but files are larger. Note: This format does not support annotations.
Reading Data with FlexReader
The FlexReader
is the recommended and easiest way to read data, regardless of the file format. It automatically detects the format and parses the file accordingly.
parse(path)
path
(str
): The path to the file.- Returns: An
AnnotatedRecording
object.
Usage Example
from flexlib.models.flex_reader import FlexReader
# FlexReader can open any of the supported file types automatically
recording_from_rsf1 = FlexReader.parse('data.rsf')
recording_from_rsf2 = FlexReader.parse('data.rsf2')
recording_from_csv = FlexReader.parse('data.csv')
print(f"Read {len(recording_from_csv.measurements)} measurements from CSV.")
Writing Data
To write data, you must use the specific writer for the desired format.
RSFV1Writer
RSFV2Writer
CSVWriter
Each writer has a write
method.
write(path, recording)
path
(str
): The path to the file to be written.recording
(AnnotatedRecording
): The recording data to write.
Usage Example
from flexlib.models.flex_reader import FlexReader
from flexlib.models.writers.csv_writer import CSVWriter
from flexlib.models.writers.rsf_v2_writer import RSFV2Writer
# Load a recording
recording = FlexReader.parse('input_data.csv')
# Write it back out in different formats
CSVWriter.write('output_data.csv', recording)
RSFV2Writer.write('output_data.rsf2', recording)
print("Data has been written to CSV and RSFv2 formats.")