cima.parsers package
Submodules
cima.parsers.parser_csv module
- class cima.parsers.parser_csv.CSVParser
Bases:
objectA class to read CSV localisation files
- static read_CSV_file(filename: str, metadata: dict = {}, sep: str = ',', chromosomes: bool = False, subsample: bool = False, ksub: int = 10000, content_type: str = 'srx', verbose: bool = False)
Reads a CSV file and returns its contents as a Segment object.
This function reads a CSV file with specific formatting and optional metadata. The function can selectively rename columns based on the content_type, validate headers, and subsample data if requested. It supports various content types, each of which may have specific column requirements. Raises errors if the file format or headers do not match expectations.
- Parameters:
filename (str) – Path to the CSV file to read.
metadata (dict, optional) – Additional metadata to attach to the output Segment object. Defaults to an empty dictionary.
sep (str, optional) – The separator used in the CSV file. Defaults to “,”.
chromosomes (bool, optional) – If True, includes chromosome identifiers in the output. Defaults to False.
subsample (bool, optional) – If True, reads only a subset of the file. Defaults to False.
ksub (int, optional) – Number of lines to read if subsample is True. Defaults to 10,000.
content_type (str, optional) – Specifies the expected content type in the file. Options are ‘srx’, ‘thunderstorm’, ‘xyztimepoint’, or ‘free’. Determines required columns and renames. Defaults to ‘srx’.
verbose (bool, optional) – If True, prints additional information for debugging. Defaults to False.
- Returns:
A Segment object containing the parsed data.
- Return type:
- Raises:
ValueError – If the content type is not supported, or if required columns are missing.
- static read_step_from_CSV_file(filename: str, metadata: dict = {}, sep: str = ',', chromosomes: bool = False, timestep: int = 0, chunk_size: int = 1000, content_type: str = 'free') Segment | None
Reads a specific time step from a CSV file in chunks and returns it as a Segment object.
This function reads data from a CSV file containing time series data, filtering for a specific time step. It processes the file in chunks to manage memory usage, especially useful for large files. The function supports various content types, renames columns as specified, and includes optional chromosome identifiers.
- Parameters:
filename (str) – Path to the CSV file to read.
metadata (dict, optional) – Additional metadata to attach to the output Segment object. Defaults to an empty dictionary.
sep (str, optional) – Separator used in the CSV file. Defaults to “,”.
chromosomes (bool, optional) – If True, includes chromosome identifiers in the output. Defaults to False.
timestep (int, optional) – The specific time step to read from the file. Defaults to 0.
chunk_size (int, optional) – Number of lines to read at once. Defaults to 1000.
assume_sequentiality (bool, optional) – If True, assumes time points are stored in ascending order to improve efficiency. Defaults to False.
content_type (str, optional) – Specifies the expected content type in the file (e.g., ‘srx’, ‘thunderstorm’, ‘xyztimepoint’, ‘free’), which affects required columns and renaming rules. Defaults to ‘free’.
- Returns:
A Segment object containing data for the specified time step, or None if no data for the time step is found.
- Return type:
Segment or None
- Raises:
ValueError – If the content type is unsupported, or if required columns are missing in the header.
- static write_CSV_file(structure: Segment, pathout: str, sep: str = ',', content_type: str = 'srx')
Writes a Segment object to a CSV file with optional column renaming based on content type.
This function saves the data from a Segment object to a CSV file. Columns in the data can be renamed based on the specified content_type, supporting various output formats. If necessary, the function creates the output directory path before writing.
- Parameters:
structure (Segment) – The Segment object containing data to write to the CSV file.
pathout (str) – Path to the output CSV file.
sep (str, optional) – Separator to use in the CSV file. Defaults to “,”.
content_type (str, optional) – Specifies the output format, which determines how columns are renamed. Options are ‘srx’, ‘thunderstorm’, ‘xyztimepoint’, ‘free’, and ‘unchanged’. Defaults to ‘srx’.
- Return type:
None
- Raises:
ValueError – If the content type is unsupported.:
cima.parsers.parser_h5py module
- class cima.parsers.parser_h5py.h5pyParser
Bases:
objectA class to read h5py localisation files
- static readH5File(filename: str, pxcamera: float = 65.0, metadata: dict = {}, content_type: str = 'free', verbose: bool = False)
Reads an HDF5 file containing localization data and returns it as a SegmentH5 object.
This function reads data from an HDF5 file (filename) containing localization information. It converts the data into real-world coordinates using the specified pixel size (pxcamera). Based on the provided content_type, it renames columns and checks for required fields to ensure compatibility with different data formats.
- Parameters:
filename (str) – Path to the HDF5 file to read.
pxcamera (float, optional) – Size of the pixel, used to convert microscope coordinates to real-world coordinates. Defaults to 65.0.
metadata (dict, optional) – Additional metadata to attach to the output SegmentH5 object. Defaults to an empty dictionary.
content_type (str, optional) – Specifies the expected content type in the file (e.g., ‘srx’, ‘thunderstorm’, ‘xyztimepoint’, ‘free’). This affects required columns and renaming rules. Defaults to ‘free’.
verbose (bool, optional) – If True, prints additional information for debugging. Defaults to False.
- Returns:
SegmentH5
A SegmentH5 object containing the localization data and metadata.
- Raises:
ValueError –
If the content type is unsupported or if required columns are missing. –
- static writeToH5SingleDataset(structure_id: SegmentH5, filename: str, pathout: str, content_type: str = 'srx') None
Writes a Segment object to a single-dataset HDF5 file.
This function saves data from a Segment object (structure_id) to a single dataset in an HDF5 file. It renames columns based on the specified content_type, scales x and y coordinates by pxcamera, and removes columns with only null values. The output file is saved at pathout + filename + “.h5”.
- Parameters:
structure_id (Segment) – The Segment object containing data to write to the HDF5 file.
filename (str) – The name of the output file (without extension).
pathout (str) – The directory path where the file will be saved.
content_type (str, optional) – Specifies how columns are renamed based on content type. Options are ‘srx’, ‘thunderstorm’, ‘xyztimepoint’, ‘free’ and ‘unchanged’. Defaults to ‘srx’.
- Return type:
None
- Raises:
ValueError – If the content type is unsupported.