lcms2.CGATS¶
- class CGATS[source]¶
Bases:
objectA CGATS.17 / IT8.7 file: one or more tables of named columns and patch rows.
All accessors act on the current table; change it with
select()or thetableproperty. Create one withCGATS()(empty),load(),from_bytes()orfrom_columns().Examples
>>> import numpy as np >>> from lcms2.cgats import CGATS >>> it8 = CGATS.from_columns({"SAMPLE_ID": ["A1", "A2"], "LAB_L": [10.0, 20.0]}) >>> it8.columns ['SAMPLE_ID', 'LAB_L'] >>> it8.column("LAB_L").tolist() [10.0, 20.0] >>> CGATS.from_bytes(it8.to_bytes())["A2", "LAB_L"] 20.0
Methods
__init__()Append an empty table, make it current and return its index.
column(name)One column: a
float64array if every cell is numeric, else an array of strings.define_table(columns, n_rows)Declare the column names and row count of the (empty) current table.
from_bytes(data)Parse CGATS text.
from_columns(data[, sheet_type, properties])Build a single-table CGATS from a mapping of column name to values.
get(patch, column)Value of one cell: a
floatwhen it is numeric, otherwise a string (Noneif empty).load(path)Read a CGATS file from
path(the file is read in Python and then closed).save(path)Write the file to
path.select(n)Make table
ncurrent and returnself.set(patch, column, value)Set one cell from a number or string; see
get()for the addressing.to_bytes()Serialise every table to CGATS text.
to_dict()Plain-Python snapshot of the whole file (JSON friendly).
Attributes
Column names (the DATA_FORMAT) of the current table.
All columns of the current table as
{name: array}(seecolumn()).Number of patches (rows) of the current table.
Patch names, from the
SAMPLE_IDcolumn (or the first column when absent).Sheet type of the current table (for example
"CGATS.17"or"IT8.7/2").Index of the current table.
- classmethod from_bytes(data: bytes) CGATS[source]¶
Parse CGATS text.
- Raises:
CMSError – If the data is not valid CGATS (the message names the offending line).
- classmethod load(path: str | PathLike) CGATS[source]¶
Read a CGATS file from
path(the file is read in Python and then closed).
- classmethod from_columns(data: Mapping[str, Sequence[Any]], sheet_type: str | None = None, properties: Mapping[str, str | float] | None = None) CGATS[source]¶
Build a single-table CGATS from a mapping of column name to values.
- Parameters:
data (mapping of str to sequence) – Columns of equal length; numbers are stored as numbers, anything else as text.
sheet_type (str, optional) – Sheet type (the first line of the file); defaults to
"CGATS.17".properties (mapping, optional) – Header properties to set.
- select(n: int) CGATS[source]¶
Make table
ncurrent and returnself.- Raises:
IndexError – If
nis not a table of the file (0 <= n < len(self)).
- property sheet_type: str | None¶
Sheet type of the current table (for example
"CGATS.17"or"IT8.7/2").
- define_table(columns: Iterable[str], n_rows: int) None[source]¶
Declare the column names and row count of the (empty) current table.
- Raises:
CMSError – If the table already has columns; call
add_table()first.
- property patches: list[str]¶
Patch names, from the
SAMPLE_IDcolumn (or the first column when absent).
- get(patch: str | int, column: str | int) float | str | None[source]¶
Value of one cell: a
floatwhen it is numeric, otherwise a string (Noneif empty).
- set(patch: str | int, column: str | int, value: str | float) None[source]¶
Set one cell from a number or string; see
get()for the addressing.
- column(name: str | int) ndarray[source]¶
One column: a
float64array if every cell is numeric, else an array of strings.Empty numeric cells become
nan.