Core* Classes¶
Each of these classes is a version-specific, in-memory, non-redundant data structure to represent and manipulate an FCS file.
These can be regarded as database-like entities that encode a hierarchical ‘schema’, maintain an internally-consistent state, and update this state atomically.
Each class corresponds to an FCS version. When applicable, keywords are stored
in a “native” datatype (int, float, tuple,
etc) corresponding to its version specification, rather than a raw string as
written in the TEXT of an FCS file. CoreDataset* classes additionally store
DATA (as a polars DataFrame), ANALYSIS, and OTHER segments (as
bytes).
Each Core* class is further composed of other version-specific classes as
follows:
Version |
CoreTEXT* |
CoreDataset* |
Optical* |
Temporal* |
|---|---|---|---|---|
FCS2.0 |
||||
FCS3.0 |
||||
FCS3.1 |
||||
FCS3.2 |
Some keywords are redundant and therefore not stored in any Core*
classes:
$TOT since this implied by the length of the dataframe
$PAR since this is implied by the length of the measurement vector
any offsets ($(BEGIN|END)(DATA|ANALYSIS|STEXT) and $NEXTDATA), since these can be computed by serializing the class’s contents
any pseudostandard keywords since this would allow the FCS standard to be violated when writing to a new file
CoreTEXT*¶
Represents HEADER and TEXT.
These can be created by:
calling
pyreflow.api.fcs_read_std_text()calling
from_kws(described below)calling
__new__
In general, the following manipulations are possible:
modifying the values of all keywords (within the constraints of the FCS standards)
adding/removing measurements
converting measurements to/from temporal and optical types
upgrading/downgrading the FCS version
converting to CoreDataset* by supplying a
DataFrameand/or byte segments for ANALYSIS and OTHER.writing to disk; the file will be an “empty” FCS file with a single dataset and no events (ie only HEADER and TEXT).
- class pyreflow.CoreTEXT2_0(measurements, layout, mode='L', cyt='', comp=None, btim=None, etim=None, date=None, abrt=None, com='', cells='', exp='', fil='', inst='', lost=None, op='', proj='', smno='', src='', sys='', tr=None, applied_gates=([], {}, None), nonstandard_keywords={})¶
Represents TEXT for an FCS 2.0 file.
- Parameters:
measurements (
tuple[str| None,Optical2_0|Temporal2_0]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.- Variables:
layout (
FixedAsciiLayout|DelimAsciiLayout|OrderedUint08Layout|OrderedUint16Layout|OrderedUint24Layout|OrderedUint32Layout|OrderedUint40Layout|OrderedUint48Layout|OrderedUint56Layout|OrderedUint64Layout|OrderedF32Layout|OrderedF64Layout) – (read-write) Layout to describe data encoding. Represents $PnB, $PnR, $BYTEORD, and $DATATYPE.mode (
Literal[“L”, “U”, “C”]) – (read-write) Value of $MODE. Defaults to"L".cyt (
str) – (read-write) Value of $CYT. Defaults to"".comp (
ndarray| None) – (read-write) The compensation matrix. Must be a square array with number of rows/columns equal to the number of measurements. Non-zero entries will produce a $DFCmTOn keyword. Defaults toNone.btim (
time| None) – (read-write) Value of $BTIM. Defaults toNone.etim (
time| None) – (read-write) Value of $ETIM. Defaults toNone.date (
date| None) – (read-write) Value of $DATE. Defaults toNone.abrt (
int| None) – (read-write) Value of $ABRT. Defaults toNone.com (
str) – (read-write) Value of $COM. Defaults to"".cells (
str) – (read-write) Value of $CELLS. Defaults to"".exp (
str) – (read-write) Value of $EXP. Defaults to"".fil (
str) – (read-write) Value of $FIL. Defaults to"".inst (
str) – (read-write) Value of $INST. Defaults to"".lost (
int| None) – (read-write) Value of $LOST. Defaults toNone.op (
str) – (read-write) Value of $OP. Defaults to"".proj (
str) – (read-write) Value of $PROJ. Defaults to"".smno (
str) – (read-write) Value of $SMNO. Defaults to"".src (
str) – (read-write) Value of $SRC. Defaults to"".sys (
str) – (read-write) Value of $SYS. Defaults to"".tr (
tuple[int,str] | None) – (read-write) Value for $TR. First member of tuple is threshold and second is the measurement name which must match a $PnN. Defaults toNone.applied_gates (
tuple[list[GatedMeasurement],dict[int,UnivariateRegion2_0|BivariateRegion2_0],str| None]) – (read-write) Value for $Gm/$RnI/$RnW/$GATING/$GATE* keywords. The first member of the tuple corresponds to the $Gm* keywords, where m is given by position in the list. The second member corresponds to the $RnI and $RnW keywords and is a mapping of regions and windows to be used in gating scheme. Keys in dictionary are the region indices (the n in $RnI and $RnW). The values in the dictionary are either univariate or bivariate gates and must correspond to an index in the list in the first element. The third member corresponds to the $GATING keyword. All ‘Rn’ in this string must reference a key in the dict of the second member. Defaults to([], {}, None).nonstandard_keywords (
dict[str,str]) – (read-write) Pairs of non-standard keyword values. Keys must not start with $. Defaults to{}.
- Raises:
OverflowError – if
abrtorlostis less than0or greater than2**32-1OverflowError – if field 1 in
tris less than0or greater than2**32-1ParseKeywordValueError – if field 1 in
measurementsis""or contains commasParseKeywordValueError – if field 2 in
tris""or contains commasParseKeyError – if dict key in
nonstandard_keywordsis empty or starts with"$"
- all_detector_types¶
Value of $PnT for all measurements (read-write).
()will be returned for time since $PnT is not defined for temporal measurements.
- all_detector_voltages¶
Value of $PnV for all measurements (read-write).
()will be returned for time since $PnV is not defined for temporal measurements.
- all_filters¶
Value of $PnF for all measurements (read-write).
()will be returned for time since $PnF is not defined for temporal measurements.
- all_meas_nonstandard_keywords¶
The non-standard keywords for each measurement (read-write).
- all_percents_emitted¶
Value of $PnP for all measurements (read-write).
()will be returned for time since $PnP is not defined for temporal measurements.
- all_powers¶
Value of $PnO for all measurements (read-write).
()will be returned for time since $PnO is not defined for temporal measurements.
- all_scales¶
The value for $PnE for all measurements (read-write).
Will be
()for linear scaling (0,0in FCS encoding), a 2-tuple for log scaling, orNoneif missing.The temporal measurement must always be
(). Setting it to another value will raiseRelationalError.
- all_shortnames¶
Value of $PnN for all measurements (read-write).
Strings are unique and cannot contain commas.
- all_shortnames_maybe¶
The possibly-empty values of $PnN for all measurements (read-write).
$PnN is optional for this FCS version so values may be
None.
- all_wavelengths¶
Value of $PnL for all measurements (read-write).
()will be returned for time since $PnL is not defined for temporal measurements.
- classmethod from_kws(std, nonstd, trim_intra_value_whitespace=False, time_meas_pattern='^(TIME|Time)$', allow_missing_time=False, force_time_linear=False, ignore_time_optical_keys=[], date_pattern=None, time_pattern=None, allow_pseudostandard=False, allow_unused_standard=False, disallow_deprecated=False, fix_log_scale_offsets=False, nonstandard_measurement_pattern=None, allow_optional_dropping=False, transfer_dropped_optional=False, integer_widths_from_byteord=False, integer_byteord_override=None, disallow_range_truncation=False, warnings_are_errors=False, hide_warnings=False)¶
Make new instance from keywords.
- Parameters:
std (
dict[str,str]) – Standard keywords. Must not contain any $Pn* keywords not indexed by $PAR or $TOT.trim_intra_value_whitespace (
bool) – IfTrue, trim whitespace between delimiters such as,and;within keyword value strings. Defaults toFalse.time_meas_pattern (
str| None) – A pattern to match the $PnN of the time measurement. IfNone, do not try to find a time measurement. Defaults to"^(TIME|Time)$".allow_missing_time (
bool) – IfTrueallow time measurement to be missing. Defaults toFalse.force_time_linear (
bool) – IfTrueforce time measurement to be linear independent of $PnE. Defaults toFalse.ignore_time_optical_keys (
list[Literal[“F”, “L”, “O”, “T”, “P”, “V”, “CALIBRATION”, “DET”, “TAG”, “FEATURE”, “ANALYTE”]]) – Ignore optical keys in temporal measurement. These keys are nonsensical for time measurements but are not explicitly forbidden in the the standard. Provided keys are the string after the “Pn” in the “PnX” keywords. Defaults to[].date_pattern (
str| None) – If supplied, will be used as an alternative pattern when parsing $DATE. If not supplied, $DATE will be parsed according to the standard pattern which is%d-%b-%Y. Defaults toNone.time_pattern (
str| None) – If supplied, will be used as an alternative pattern when parsing $BTIM and $ETIM. The values"%!"or"%@"may be used to match 1/60 seconds or centiseconds respectively. If not supplied, $BTIM and $ETIM will be parsed according to the standard pattern which is"%H:%M:%S". Defaults toNone.allow_pseudostandard (
bool) – IfTrueallow non-standard keywords with a leading $. The presence of such keywords often means the version in HEADER is incorrect. Defaults toFalse.allow_unused_standard (
bool) – IfTrueallow unused standard keywords to be present. Defaults toFalse.disallow_deprecated (
bool) – IfTruethrow error if a deprecated key is encountered. Defaults toFalse.fix_log_scale_offsets (
bool) – IfTruefix log-scale PnE and keywords which have zero offset (ieX,0.0whereXis non-zero). Defaults toFalse.nonstandard_measurement_pattern (
str| None) – Pattern to use when matching nonstandard measurement keys. Must be a regular expression pattern with%nwhich will represent the measurement index and should not start with $. Otherwise should be a normal regular expression as defined in regexp-syntax. Defaults toNone.allow_optional_dropping (
bool) – IfTruedrop optional keys that cause an error and emit warning instead. Defaults toFalse.transfer_dropped_optional (
bool) – IfTruetransfer optional keys to non-standard dict if dropped. Defaults toFalse.integer_widths_from_byteord (
bool) – IfTrueset all $PnB to the number of bytes from $BYTEORD. Only has an effect for FCS 2.0/3.0 where $DATATYPE isI. Defaults toFalse.integer_byteord_override (
list[int] | None) – Override $BYTEORD for integer layouts. Defaults toNone.disallow_range_truncation (
bool) – IfTruethrow error if $PnR values need to be truncated to match the number of bytes specified by $PnB and $DATATYPE. Defaults toFalse.warnings_are_errors (
bool) – IfTrueall warnings will be regarded as errors. Defaults toFalse.hide_warnings (
bool) – IfTruehide all warnings. Defaults toFalse.
- Return type:
- Raises:
ConfigError – if
nonstandard_measurement_patterndoes not have"%n"ConfigError – if
time_patterndoes not have specifiers for hours, minutes, seconds, and optionally sub-seconds (where"%!"and"%@"correspond to 1/60 seconds and centiseconds respectively) as outlined in chronoConfigError – if
date_patterndoes not have year, month, and day specifiers as outlined in chronoConfigError – if
time_meas_patternis not a valid regular expression as described in regexp-syntaxInvalidKeywordValueError – if
integer_byteord_overrideis not a list of integers including all from 1 toNwhereNis the length of the list (up to 8)ParseKeyError – if dict key in
nonstdis empty or starts with"$"ParseKeyError – if dict key in
stdis empty, does not start with"$", or is only a"$"ParseKeywordValueError – If any keyword values could not be read from their string encoding
RelationalError – If keywords that are referenced by other keywords do not exist
ExtraKeywordError – If any standard keys are unused and
allow_pseudostandardorallow_unused_standardareFalse
- insert_optical(index, name, meas, range, disallow_trunc=False)¶
Insert optical measurement at position in measurement vector.
- Parameters:
index (
int) – Position at which to insert new measurement.name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Optical2_0) – The measurement to insert.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- insert_temporal(index, name, meas, range, disallow_trunc=False)¶
Insert temporal measurement at position in measurement vector.
- Parameters:
index (
int) – Position at which to insert new measurement.name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Temporal2_0) – The measurement to insert.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- measurement_at(index)¶
Return measurement at index.
- Parameters:
index (
int) – Index to retrieve.- Return type:
- Raises:
IndexError – If
indexnot found
- measurement_named(name)¶
Return measurement with name.
- Parameters:
name (
str) – Name to retrieve. Corresponds to $PnN.- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namenot found
- measurements¶
All measurements (read-write).
- Return type:
- push_optical(name, meas, range, disallow_trunc=False)¶
Push optical measurement to end of measurement vector.
- Parameters:
name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Optical2_0) – The measurement to push.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- push_temporal(name, meas, range, disallow_trunc=False)¶
Push temporal measurement to end of measurement vector.
- Parameters:
name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Temporal2_0) – The measurement to push.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- remove_measurement_by_index(index)¶
Remove a measurement with a given index.
- Parameters:
index (
int) – Index to remove.- Returns:
Name and measurement object.
- Return type:
tuple[str| None,Optical2_0|Temporal2_0,Decimal]- Raises:
IndexError – If
indexnot found
- remove_measurement_by_name(name)¶
Remove a measurement with a given name.
- Parameters:
name (
str) – Name to remove. Corresponds to $PnN.- Returns:
Index and measurement object.
- Return type:
tuple[int,Optical2_0|Temporal2_0,Decimal]- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namenot found
- rename_temporal(name)¶
Rename temporal measurement if present.
- Parameters:
name (
str) – New name to assign. Corresponds to $PnN.- Returns:
Previous name if present.
- Return type:
str| None- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- replace_optical_at(index, meas)¶
Replace measurement at index with given optical measurement.
- Parameters:
index (
int) – Index to replace.meas (
Optical2_0) – Optical measurement to replace measurement atindex.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
IndexError – If
indexdoes not exist.
- replace_optical_named(name, meas)¶
Replace named measurement with given optical measurement.
- Parameters:
name (
str) – Name to replace. Corresponds to $PnN.meas (
Optical2_0) – Optical measurement to replace measurement atname.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namedoes not exist.
- replace_temporal_at(index, meas)¶
Replace measurement at index with given temporal measurement.
- Parameters:
index (
int) – Index to replace.meas (
Temporal2_0) – Temporal measurement to replace measurement atindex.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
IndexError – If
indexdoes not existRelationalError – If a temporal measurement already exists at a different position
- replace_temporal_named(name, meas)¶
Replace named measurement with given temporal measurement.
- Parameters:
name (
str) – Name to replace. Corresponds to $PnN.meas (
Temporal2_0) – Temporal measurement to replace measurement atname.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namedoes not existRelationalError – If a temporal measurement already exists at a different position
- set_measurements_and_layout(measurements, layout)¶
Set all measurements and layout at once.
Length of
measurementsmust match number of columns inlayout.- Parameters:
measurements (
list[Optical2_0|Temporal2_0]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.layout (
FixedAsciiLayout|DelimAsciiLayout|OrderedUint08Layout|OrderedUint16Layout|OrderedUint24Layout|OrderedUint32Layout|OrderedUint40Layout|OrderedUint48Layout|OrderedUint56Layout|OrderedUint64Layout|OrderedF32Layout|OrderedF64Layout) – The new layout.
- set_named_measurements(measurements, allow_shared_names=False, skip_index_check=False)¶
Set all measurements at once.
Length of
measurementsmust match number of columns in existing layout.- Parameters:
measurements (
tuple[str| None,Optical2_0|Temporal2_0]) – The new measurements. The first member of the tuple corresponds to the measurement name and the second is the measurement object.allow_shared_names (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keywords reference any $PnN keywords. IfTrueraiseRelationalErrorif any non-measurement keywords reference a $PnN which is not present inmeasurements. In other words,Falseforbids named references to exist, andTrueallows named references to be updated. References cannot be broken in either case. Defaults toFalse.skip_index_check (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keyword have an index reference to the current measurements. IfTrueallow such references to exist as long as they do not break (which really means that the length ofmeasurementsis such that existing indices are satisfied). Defaults toFalse.
- Raises:
ParseKeywordValueError – if field 1 in
measurementsis""or contains commas
- set_named_measurements_and_layout(measurements, layout, allow_shared_names=False, skip_index_check=False)¶
Set all measurements, names, and layout at once.
Length of
measurementsmust match number of columns inlayout.- Parameters:
measurements (
tuple[str| None,Optical2_0|Temporal2_0]) – The new measurements. The first member of the tuple corresponds to the measurement name and the second is the measurement object.layout (
FixedAsciiLayout|DelimAsciiLayout|OrderedUint08Layout|OrderedUint16Layout|OrderedUint24Layout|OrderedUint32Layout|OrderedUint40Layout|OrderedUint48Layout|OrderedUint56Layout|OrderedUint64Layout|OrderedF32Layout|OrderedF64Layout) – The new layout.allow_shared_names (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keywords reference any $PnN keywords. IfTrueraiseRelationalErrorif any non-measurement keywords reference a $PnN which is not present inmeasurements. In other words,Falseforbids named references to exist, andTrueallows named references to be updated. References cannot be broken in either case. Defaults toFalse.skip_index_check (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keyword have an index reference to the current measurements. IfTrueallow such references to exist as long as they do not break (which really means that the length ofmeasurementsis such that existing indices are satisfied). Defaults toFalse.
- Raises:
ParseKeywordValueError – if field 1 in
measurementsis""or contains commas
- set_temporal(name, allow_loss=False)¶
Set the temporal measurement to a given name.
- Parameters:
name (
str) – Name to set to temporal. Corresponds to $PnN.allow_loss (
bool) – IfTrueremove any optical-specific metadata (detectors, lasers, etc) without raising anConversionErrorif an optical measurement must be converted. Defaults toFalse.
- Returns:
Trueif temporal measurement was set, which will happen for all cases except when the time measurement is already set toname.- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- set_temporal_at(index, allow_loss=False)¶
Set the temporal measurement to a given index.
- Parameters:
index (
int) – Index to set.allow_loss (
bool) – IfTrueremove any optical-specific metadata (detectors, lasers, etc) without raising anConversionErrorif an optical measurement must be converted. Defaults toFalse.
- Returns:
Trueif temporal measurement was set, which will happen for all cases except when the time measurement is already set toindex.- Return type:
- set_trigger_threshold(threshold)¶
Set the threshold for $TR.
- standard_keywords(req_or_opt, root_or_meas)¶
Return standard keywords as string pairs.
Each key will be prefixed with $.
This will not include $TOT, $NEXTDATA, or any of the offset keywords since these only matter if the dataset is written.
- Parameters:
- Returns:
A list of standard keywords.
- Return type:
- temporal¶
The temporal measurement if it exists (read-only).
- Returns:
Index, name, and measurement or
None.- Return type:
tuple[int,str,Temporal2_0] | None
- to_dataset(data, analysis=b'', others=[])¶
Convert to a dataset object.
This will fully represent an FCS file, as opposed to just representing HEADER and TEXT.
- Parameters:
data (
polars.DataFrame) – A dataframe encoding the contents of DATA. Number of columns must match number of measurements. May be empty. Types do not necessarily need to correspond to those in the data layout but mismatches may result in truncation.analysis (
bytes) – Contents of the ANALYSIS segment. Defaults tob"".others (
list[bytes]) – A list of byte strings encoding the OTHER segments. Defaults to[].
- Return type:
- Raises:
EventDataError – If
datacontains columns which are not unsigned 8/16/32/64-bit integers or 32/64-bit floats
- to_version_3_0(allow_loss=False)¶
Convert to FCS 3.0.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 3.0.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 3.0 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 3.0
- to_version_3_1(allow_loss=False)¶
Convert to FCS 3.1.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 3.1.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 3.1 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 3.1
- to_version_3_2(allow_loss=False)¶
Convert to FCS 3.2.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 3.2.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 3.2 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 3.2
- unset_measurements()¶
Remove measurements and clear the layout.
This is equivalent to deleting all $Pn* keywords and setting $PAR to
0.- Return type:
tuple[()]- Raises:
RelationalError – If keywords are set which refer to measurements and would be invalidated if measurements were removed
- unset_temporal()¶
Convert the temporal measurement to an optical measurement.
- Returns:
Trueif temporal measurement was present and converted,Falseif there was not a temporal measurement.- Return type:
- version¶
Show the FCS version (read-only).
- Return type:
Literal[“FCS2.0”, “FCS3.0”, “FCS3.1”, “FCS3.2”]
- write_text(path, delim=30, big_other=False, appendable=False, append=False)¶
Write data to path.
Resulting FCS file will include HEADER and TEXT.
- Parameters:
path (
Path) – Path to be written.delim (
int) – Delimiter to use when writing TEXT. Defaults to30.big_other (
bool) – IfTrueuse 20 chars for OTHER segment offsets, and 8 otherwise. Defaults toFalse.appendable (
bool) – IfTrue, set $NEXTDATA in written dataset so it points to the next dataset. This obviously assumes the next dataset is actually written, which will require another call to this method withappendset toTrue. Defaults toFalse.append (
bool) – IfTrue, append this dataset to the end of the file if it exists and already has at least one dataset in it. This assumes that the previous dataset was written withappendableset toTrueso that $NEXTDATA is properly set. Defaults toFalse.
- Returns:
the value of $NEXTDATA as written to the dataset
- Return type:
- Raises:
ConfigError – if
delimis not between 1 and 126OverflowError – If TEXT, DATA, or ANALYSIS offsets are greater than 99,999,999
OverflowError – If any OTHER offsets are greater than 99,999,999 and
big_otherisFalse
- classmethod write_texts(path, datasets, delim=30, big_other=False)¶
Write multiple datasets to path.
The resulting file will have HEADER and TEXT from each object
- Parameters:
path (
Path) – Path to be written.datasets (
list[CoreTEXT2_0]) – datasets to writedelim (
int) – Delimiter to use when writing TEXT. Defaults to30.big_other (
bool) – IfTrueuse 20 chars for OTHER segment offsets, and 8 otherwise. Defaults toFalse.
- Returns:
the value of $NEXTDATA as written in the last dataset
- Return type:
int| None- Raises:
ConfigError – if
delimis not between 1 and 126OverflowError – If TEXT, DATA, or ANALYSIS offsets are greater than 99,999,999
OverflowError – If any OTHER offsets are greater than 99,999,999 and
big_otherisFalse
- class pyreflow.CoreTEXT3_0(measurements, layout, mode='L', cyt='', comp=None, btim=None, etim=None, date=None, cytsn='', unicode=None, csvbits=0, cstot=0, csvflags=[], abrt=None, com='', cells='', exp='', fil='', inst='', lost=None, op='', proj='', smno='', src='', sys='', tr=None, applied_gates=([], {}, None), nonstandard_keywords={})¶
Represents TEXT for an FCS 3.0 file.
- Parameters:
measurements (
tuple[str| None,Optical3_0|Temporal3_0]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.- Variables:
layout (
FixedAsciiLayout|DelimAsciiLayout|OrderedUint08Layout|OrderedUint16Layout|OrderedUint24Layout|OrderedUint32Layout|OrderedUint40Layout|OrderedUint48Layout|OrderedUint56Layout|OrderedUint64Layout|OrderedF32Layout|OrderedF64Layout) – (read-write) Layout to describe data encoding. Represents $PnB, $PnR, $BYTEORD, and $DATATYPE.mode (
Literal[“L”, “U”, “C”]) – (read-write) Value of $MODE. Defaults to"L".cyt (
str) – (read-write) Value of $CYT. Defaults to"".comp (
ndarray| None) – (read-write) The value of $COMP. Must be a square array with number of rows/columns equal to the number of measurements. Defaults toNone.btim (
time| None) – (read-write) Value of $BTIM. Defaults toNone.etim (
time| None) – (read-write) Value of $ETIM. Defaults toNone.date (
date| None) – (read-write) Value of $DATE. Defaults toNone.cytsn (
str) – (read-write) Value of $CYTSN. Defaults to"".unicode (
tuple[int,list[str]] | None) – (read-write) Value of $UNICODE. Defaults toNone.csvbits (
int) – (read-write) Value of $CSVBITS. Defaults to0.cstot (
int) – (read-write) Value of $CSTOT. Defaults to0.csvflags (
list[int| None]) – (read-write) Subset flags. Each element in the list corresponds to $CSVnFLAG and the length of the list corresponds to $CSMODE. Defaults to[].abrt (
int| None) – (read-write) Value of $ABRT. Defaults toNone.com (
str) – (read-write) Value of $COM. Defaults to"".cells (
str) – (read-write) Value of $CELLS. Defaults to"".exp (
str) – (read-write) Value of $EXP. Defaults to"".fil (
str) – (read-write) Value of $FIL. Defaults to"".inst (
str) – (read-write) Value of $INST. Defaults to"".lost (
int| None) – (read-write) Value of $LOST. Defaults toNone.op (
str) – (read-write) Value of $OP. Defaults to"".proj (
str) – (read-write) Value of $PROJ. Defaults to"".smno (
str) – (read-write) Value of $SMNO. Defaults to"".src (
str) – (read-write) Value of $SRC. Defaults to"".sys (
str) – (read-write) Value of $SYS. Defaults to"".tr (
tuple[int,str] | None) – (read-write) Value for $TR. First member of tuple is threshold and second is the measurement name which must match a $PnN. Defaults toNone.applied_gates (
tuple[list[GatedMeasurement],dict[int,UnivariateRegion3_0|BivariateRegion3_0],str| None]) – (read-write) Value for $Gm/$RnI/$RnW/$GATING/$GATE* keywords. The first member of the tuple corresponds to the $Gm* keywords, where m is given by position in the list. The second member corresponds to the $RnI and $RnW keywords and is a mapping of regions and windows to be used in gating scheme. Keys in dictionary are the region indices (the n in $RnI and $RnW). The values in the dictionary are either univariate or bivariate gates and must correspond to an index in the list in the first element or a physical measurement. The third member corresponds to the $GATING keyword. All ‘Rn’ in this string must reference a key in the dict of the second member. Defaults to([], {}, None).nonstandard_keywords (
dict[str,str]) – (read-write) Pairs of non-standard keyword values. Keys must not start with $. Defaults to{}.
- Raises:
OverflowError – if
abrt,cstot,csvbits, orlostis less than0or greater than2**32-1OverflowError – if field 1 in
tris less than0or greater than2**32-1ParseKeywordValueError – if field 1 in
measurementsis""or contains commasParseKeywordValueError – if field 2 in
tris""or contains commasOverflowError – if any in
csvflagsis less than0or greater than2**32-1ParseKeyError – if dict key in
nonstandard_keywordsis empty or starts with"$"
- all_detector_types¶
Value of $PnT for all measurements (read-write).
()will be returned for time since $PnT is not defined for temporal measurements.
- all_detector_voltages¶
Value of $PnV for all measurements (read-write).
()will be returned for time since $PnV is not defined for temporal measurements.
- all_filters¶
Value of $PnF for all measurements (read-write).
()will be returned for time since $PnF is not defined for temporal measurements.
- all_meas_nonstandard_keywords¶
The non-standard keywords for each measurement (read-write).
- all_percents_emitted¶
Value of $PnP for all measurements (read-write).
()will be returned for time since $PnP is not defined for temporal measurements.
- all_powers¶
Value of $PnO for all measurements (read-write).
()will be returned for time since $PnO is not defined for temporal measurements.
- all_scale_transforms¶
The value for $PnE and/or $PnG for all measurements (read-write).
Collectively these keywords correspond to scale transforms.
If scaling is linear, return a float which corresponds to the value of $PnG when $PnE is
0,0. If scaling is logarithmic, return a pair of floats, corresponding to unset $PnG and the non-0,0value of $PnE.The FCS standards disallow any other combinations.
The temporal measurement will always be
1.0, corresponding to an identity transform. Setting it to another value will raiseRelationalError.
- all_shortnames¶
Value of $PnN for all measurements (read-write).
Strings are unique and cannot contain commas.
- all_shortnames_maybe¶
The possibly-empty values of $PnN for all measurements (read-write).
$PnN is optional for this FCS version so values may be
None.
- all_wavelengths¶
Value of $PnL for all measurements (read-write).
()will be returned for time since $PnL is not defined for temporal measurements.
- classmethod from_kws(std, nonstd, trim_intra_value_whitespace=False, time_meas_pattern='^(TIME|Time)$', allow_missing_time=False, force_time_linear=False, ignore_time_optical_keys=[], date_pattern=None, time_pattern=None, allow_pseudostandard=False, allow_unused_standard=False, disallow_deprecated=False, fix_log_scale_offsets=False, nonstandard_measurement_pattern=None, ignore_time_gain=False, allow_optional_dropping=False, transfer_dropped_optional=False, integer_widths_from_byteord=False, integer_byteord_override=None, disallow_range_truncation=False, warnings_are_errors=False, hide_warnings=False)¶
Make new instance from keywords.
- Parameters:
std (
dict[str,str]) – Standard keywords. Must not contain any $Pn* keywords not indexed by $PAR or $TOT, $BEGINDATA, $ENDDATA, $BEGINANALYSIS, $ENDANALYSIS, or $TIMESTEP (if time measurement not included).trim_intra_value_whitespace (
bool) – IfTrue, trim whitespace between delimiters such as,and;within keyword value strings. Defaults toFalse.time_meas_pattern (
str| None) – A pattern to match the $PnN of the time measurement. IfNone, do not try to find a time measurement. Defaults to"^(TIME|Time)$".allow_missing_time (
bool) – IfTrueallow time measurement to be missing. Defaults toFalse.force_time_linear (
bool) – IfTrueforce time measurement to be linear independent of $PnE. Defaults toFalse.ignore_time_optical_keys (
list[Literal[“F”, “L”, “O”, “T”, “P”, “V”, “CALIBRATION”, “DET”, “TAG”, “FEATURE”, “ANALYTE”]]) – Ignore optical keys in temporal measurement. These keys are nonsensical for time measurements but are not explicitly forbidden in the the standard. Provided keys are the string after the “Pn” in the “PnX” keywords. Defaults to[].date_pattern (
str| None) – If supplied, will be used as an alternative pattern when parsing $DATE. If not supplied, $DATE will be parsed according to the standard pattern which is%d-%b-%Y. Defaults toNone.time_pattern (
str| None) – If supplied, will be used as an alternative pattern when parsing $BTIM and $ETIM. The values"%!"or"%@"may be used to match 1/60 seconds or centiseconds respectively. If not supplied, $BTIM and $ETIM will be parsed according to the standard pattern which is"%H:%M:%S:%!". Defaults toNone.allow_pseudostandard (
bool) – IfTrueallow non-standard keywords with a leading $. The presence of such keywords often means the version in HEADER is incorrect. Defaults toFalse.allow_unused_standard (
bool) – IfTrueallow unused standard keywords to be present. Defaults toFalse.disallow_deprecated (
bool) – IfTruethrow error if a deprecated key is encountered. Defaults toFalse.fix_log_scale_offsets (
bool) – IfTruefix log-scale PnE and keywords which have zero offset (ieX,0.0whereXis non-zero). Defaults toFalse.nonstandard_measurement_pattern (
str| None) – Pattern to use when matching nonstandard measurement keys. Must be a regular expression pattern with%nwhich will represent the measurement index and should not start with $. Otherwise should be a normal regular expression as defined in regexp-syntax. Defaults toNone.ignore_time_gain (
bool) – IfTrueignore the $PnG (gain) keyword. This keyword should not be set according to the standard} however, this library will allow gain to be 1.0 since this equates to identity. If gain is not 1.0, this is nonsense and it can be ignored with this flag. Defaults toFalse.allow_optional_dropping (
bool) – IfTruedrop optional keys that cause an error and emit warning instead. Defaults toFalse.transfer_dropped_optional (
bool) – IfTruetransfer optional keys to non-standard dict if dropped. Defaults toFalse.integer_widths_from_byteord (
bool) – IfTrueset all $PnB to the number of bytes from $BYTEORD. Only has an effect for FCS 2.0/3.0 where $DATATYPE isI. Defaults toFalse.integer_byteord_override (
list[int] | None) – Override $BYTEORD for integer layouts. Defaults toNone.disallow_range_truncation (
bool) – IfTruethrow error if $PnR values need to be truncated to match the number of bytes specified by $PnB and $DATATYPE. Defaults toFalse.warnings_are_errors (
bool) – IfTrueall warnings will be regarded as errors. Defaults toFalse.hide_warnings (
bool) – IfTruehide all warnings. Defaults toFalse.
- Return type:
- Raises:
ConfigError – if
nonstandard_measurement_patterndoes not have"%n"ConfigError – if
time_patterndoes not have specifiers for hours, minutes, seconds, and optionally sub-seconds (where"%!"and"%@"correspond to 1/60 seconds and centiseconds respectively) as outlined in chronoConfigError – if
date_patterndoes not have year, month, and day specifiers as outlined in chronoConfigError – if
time_meas_patternis not a valid regular expression as described in regexp-syntaxInvalidKeywordValueError – if
integer_byteord_overrideis not a list of integers including all from 1 toNwhereNis the length of the list (up to 8)ParseKeyError – if dict key in
nonstdis empty or starts with"$"ParseKeyError – if dict key in
stdis empty, does not start with"$", or is only a"$"ParseKeywordValueError – If any keyword values could not be read from their string encoding
RelationalError – If keywords that are referenced by other keywords do not exist
ExtraKeywordError – If any standard keys are unused and
allow_pseudostandardorallow_unused_standardareFalse
- insert_optical(index, name, meas, range, disallow_trunc=False)¶
Insert optical measurement at position in measurement vector.
- Parameters:
index (
int) – Position at which to insert new measurement.name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Optical3_0) – The measurement to insert.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- insert_temporal(index, name, meas, range, disallow_trunc=False)¶
Insert temporal measurement at position in measurement vector.
- Parameters:
index (
int) – Position at which to insert new measurement.name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Temporal3_0) – The measurement to insert.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- measurement_at(index)¶
Return measurement at index.
- Parameters:
index (
int) – Index to retrieve.- Return type:
- Raises:
IndexError – If
indexnot found
- measurement_named(name)¶
Return measurement with name.
- Parameters:
name (
str) – Name to retrieve. Corresponds to $PnN.- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namenot found
- measurements¶
All measurements (read-write).
- Return type:
- push_optical(name, meas, range, disallow_trunc=False)¶
Push optical measurement to end of measurement vector.
- Parameters:
name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Optical3_0) – The measurement to push.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- push_temporal(name, meas, range, disallow_trunc=False)¶
Push temporal measurement to end of measurement vector.
- Parameters:
name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Temporal3_0) – The measurement to push.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- remove_measurement_by_index(index)¶
Remove a measurement with a given index.
- Parameters:
index (
int) – Index to remove.- Returns:
Name and measurement object.
- Return type:
tuple[str| None,Optical3_0|Temporal3_0,Decimal]- Raises:
IndexError – If
indexnot found
- remove_measurement_by_name(name)¶
Remove a measurement with a given name.
- Parameters:
name (
str) – Name to remove. Corresponds to $PnN.- Returns:
Index and measurement object.
- Return type:
tuple[int,Optical3_0|Temporal3_0,Decimal]- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namenot found
- rename_temporal(name)¶
Rename temporal measurement if present.
- Parameters:
name (
str) – New name to assign. Corresponds to $PnN.- Returns:
Previous name if present.
- Return type:
str| None- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- replace_optical_at(index, meas)¶
Replace measurement at index with given optical measurement.
- Parameters:
index (
int) – Index to replace.meas (
Optical3_0) – Optical measurement to replace measurement atindex.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
IndexError – If
indexdoes not exist.
- replace_optical_named(name, meas)¶
Replace named measurement with given optical measurement.
- Parameters:
name (
str) – Name to replace. Corresponds to $PnN.meas (
Optical3_0) – Optical measurement to replace measurement atname.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namedoes not exist.
- replace_temporal_at(index, meas)¶
Replace measurement at index with given temporal measurement.
- Parameters:
index (
int) – Index to replace.meas (
Temporal3_0) – Temporal measurement to replace measurement atindex.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
IndexError – If
indexdoes not existRelationalError – If a temporal measurement already exists at a different position
- replace_temporal_named(name, meas)¶
Replace named measurement with given temporal measurement.
- Parameters:
name (
str) – Name to replace. Corresponds to $PnN.meas (
Temporal3_0) – Temporal measurement to replace measurement atname.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namedoes not existRelationalError – If a temporal measurement already exists at a different position
- set_measurements_and_layout(measurements, layout)¶
Set all measurements and layout at once.
Length of
measurementsmust match number of columns inlayout.- Parameters:
measurements (
list[Optical3_0|Temporal3_0]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.layout (
FixedAsciiLayout|DelimAsciiLayout|OrderedUint08Layout|OrderedUint16Layout|OrderedUint24Layout|OrderedUint32Layout|OrderedUint40Layout|OrderedUint48Layout|OrderedUint56Layout|OrderedUint64Layout|OrderedF32Layout|OrderedF64Layout) – The new layout.
- set_named_measurements(measurements, allow_shared_names=False, skip_index_check=False)¶
Set all measurements at once.
Length of
measurementsmust match number of columns in existing layout.- Parameters:
measurements (
tuple[str| None,Optical3_0|Temporal3_0]) – The new measurements. The first member of the tuple corresponds to the measurement name and the second is the measurement object.allow_shared_names (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keywords reference any $PnN keywords. IfTrueraiseRelationalErrorif any non-measurement keywords reference a $PnN which is not present inmeasurements. In other words,Falseforbids named references to exist, andTrueallows named references to be updated. References cannot be broken in either case. Defaults toFalse.skip_index_check (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keyword have an index reference to the current measurements. IfTrueallow such references to exist as long as they do not break (which really means that the length ofmeasurementsis such that existing indices are satisfied). Defaults toFalse.
- Raises:
ParseKeywordValueError – if field 1 in
measurementsis""or contains commas
- set_named_measurements_and_layout(measurements, layout, allow_shared_names=False, skip_index_check=False)¶
Set all measurements, names, and layout at once.
Length of
measurementsmust match number of columns inlayout.- Parameters:
measurements (
tuple[str| None,Optical3_0|Temporal3_0]) – The new measurements. The first member of the tuple corresponds to the measurement name and the second is the measurement object.layout (
FixedAsciiLayout|DelimAsciiLayout|OrderedUint08Layout|OrderedUint16Layout|OrderedUint24Layout|OrderedUint32Layout|OrderedUint40Layout|OrderedUint48Layout|OrderedUint56Layout|OrderedUint64Layout|OrderedF32Layout|OrderedF64Layout) – The new layout.allow_shared_names (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keywords reference any $PnN keywords. IfTrueraiseRelationalErrorif any non-measurement keywords reference a $PnN which is not present inmeasurements. In other words,Falseforbids named references to exist, andTrueallows named references to be updated. References cannot be broken in either case. Defaults toFalse.skip_index_check (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keyword have an index reference to the current measurements. IfTrueallow such references to exist as long as they do not break (which really means that the length ofmeasurementsis such that existing indices are satisfied). Defaults toFalse.
- Raises:
ParseKeywordValueError – if field 1 in
measurementsis""or contains commas
- set_temporal(name, timestep, allow_loss=False)¶
Set the temporal measurement to a given name.
- Parameters:
name (
str) – Name to set to temporal. Corresponds to $PnN.timestep (
float) – The value of $TIMESTEP to use.allow_loss (
bool) – IfTrueremove any optical-specific metadata (detectors, lasers, etc) without raising anConversionErrorif an optical measurement must be converted. Defaults toFalse.
- Returns:
Trueif temporal measurement was set, which will happen for all cases except when the time measurement is already set toname.- Return type:
- Raises:
InvalidKeywordValueError – if
timestepis negative,0.0,NaN,inf, or-infParseKeywordValueError – if
nameis""or contains commas
- set_temporal_at(index, timestep, allow_loss=False)¶
Set the temporal measurement to a given index.
- Parameters:
index (
int) – Index to set.timestep (
float) – The value of $TIMESTEP to use.allow_loss (
bool) – IfTrueremove any optical-specific metadata (detectors, lasers, etc) without raising anConversionErrorif an optical measurement must be converted. Defaults toFalse.
- Returns:
Trueif temporal measurement was set, which will happen for all cases except when the time measurement is already set toindex.- Return type:
- Raises:
InvalidKeywordValueError – if
timestepis negative,0.0,NaN,inf, or-inf
- set_timestep(timestep)¶
Set the $TIMESTEP if time measurement is present.
- Parameters:
timestep (
float) – The timestep to set. Must be greater than zero.- Returns:
Previous $TIMESTEP if present.
- Return type:
float| None- Raises:
InvalidKeywordValueError – if
timestepis negative,0.0,NaN,inf, or-inf
- set_trigger_threshold(threshold)¶
Set the threshold for $TR.
- standard_keywords(req_or_opt, root_or_meas)¶
Return standard keywords as string pairs.
Each key will be prefixed with $.
This will not include $TOT, $NEXTDATA, or any of the offset keywords since these only matter if the dataset is written.
- Parameters:
- Returns:
A list of standard keywords.
- Return type:
- temporal¶
The temporal measurement if it exists (read-only).
- Returns:
Index, name, and measurement or
None.- Return type:
tuple[int,str,Temporal3_0] | None
- to_dataset(data, analysis=b'', others=[])¶
Convert to a dataset object.
This will fully represent an FCS file, as opposed to just representing HEADER and TEXT.
- Parameters:
data (
polars.DataFrame) – A dataframe encoding the contents of DATA. Number of columns must match number of measurements. May be empty. Types do not necessarily need to correspond to those in the data layout but mismatches may result in truncation.analysis (
bytes) – Contents of the ANALYSIS segment. Defaults tob"".others (
list[bytes]) – A list of byte strings encoding the OTHER segments. Defaults to[].
- Return type:
- Raises:
EventDataError – If
datacontains columns which are not unsigned 8/16/32/64-bit integers or 32/64-bit floats
- to_version_2_0(allow_loss=False)¶
Convert to FCS 2.0.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 2.0.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 2.0 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 2.0
- to_version_3_1(allow_loss=False)¶
Convert to FCS 3.1.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 3.1.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 3.1 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 3.1
- to_version_3_2(allow_loss=False)¶
Convert to FCS 3.2.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 3.2.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 3.2 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 3.2
- unset_measurements()¶
Remove measurements and clear the layout.
This is equivalent to deleting all $Pn* keywords and setting $PAR to
0.- Return type:
tuple[()]- Raises:
RelationalError – If keywords are set which refer to measurements and would be invalidated if measurements were removed
- unset_temporal()¶
Convert the temporal measurement to an optical measurement.
- Returns:
Value of $TIMESTEP if time measurement was present.
- Return type:
float| None
- version¶
Show the FCS version (read-only).
- Return type:
Literal[“FCS2.0”, “FCS3.0”, “FCS3.1”, “FCS3.2”]
- write_text(path, delim=30, big_other=False, appendable=False, append=False)¶
Write data to path.
Resulting FCS file will include HEADER and TEXT.
- Parameters:
path (
Path) – Path to be written.delim (
int) – Delimiter to use when writing TEXT. Defaults to30.big_other (
bool) – IfTrueuse 20 chars for OTHER segment offsets, and 8 otherwise. Defaults toFalse.appendable (
bool) – IfTrue, set $NEXTDATA in written dataset so it points to the next dataset. This obviously assumes the next dataset is actually written, which will require another call to this method withappendset toTrue. Defaults toFalse.append (
bool) – IfTrue, append this dataset to the end of the file if it exists and already has at least one dataset in it. This assumes that the previous dataset was written withappendableset toTrueso that $NEXTDATA is properly set. Defaults toFalse.
- Returns:
the value of $NEXTDATA as written to the dataset
- Return type:
- Raises:
ConfigError – if
delimis not between 1 and 126OverflowError – If TEXT offsets are greater than 99,999,999 bytes
OverflowError – If any OTHER offsets are greater than 99,999,999 and
big_otherisFalse
- classmethod write_texts(path, datasets, delim=30, big_other=False)¶
Write multiple datasets to path.
The resulting file will have HEADER and TEXT from each object
- Parameters:
path (
Path) – Path to be written.datasets (
list[CoreTEXT3_0]) – datasets to writedelim (
int) – Delimiter to use when writing TEXT. Defaults to30.big_other (
bool) – IfTrueuse 20 chars for OTHER segment offsets, and 8 otherwise. Defaults toFalse.
- Returns:
the value of $NEXTDATA as written in the last dataset
- Return type:
int| None- Raises:
ConfigError – if
delimis not between 1 and 126OverflowError – If TEXT offsets are greater than 99,999,999 bytes
OverflowError – If any OTHER offsets are greater than 99,999,999 and
big_otherisFalse
- class pyreflow.CoreTEXT3_1(measurements, layout, mode='L', cyt='', btim=None, etim=None, date=None, cytsn='', spillover=None, last_modifier='', last_modified=None, originality=None, plateid='', platename='', wellid='', vol=None, csvbits=0, cstot=0, csvflags=[], abrt=None, com='', cells='', exp='', fil='', inst='', lost=None, op='', proj='', smno='', src='', sys='', tr=None, applied_gates=([], {}, None), nonstandard_keywords={})¶
Represents TEXT for an FCS 3.1 file.
- Parameters:
measurements (
tuple[str,Optical3_1|Temporal3_1]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.- Variables:
layout (
FixedAsciiLayout|DelimAsciiLayout|EndianUintLayout|EndianF32Layout|EndianF64Layout) – (read-write) Layout to describe data encoding. Represents $PnB, $PnR, $BYTEORD, and $DATATYPE.mode (
Literal[“L”, “U”, “C”]) – (read-write) Value of $MODE. Defaults to"L".cyt (
str) – (read-write) Value of $CYT. Defaults to"".btim (
time| None) – (read-write) Value of $BTIM. Defaults toNone.etim (
time| None) – (read-write) Value of $ETIM. Defaults toNone.date (
date| None) – (read-write) Value of $DATE. Defaults toNone.cytsn (
str) – (read-write) Value of $CYTSN. Defaults to"".spillover (
tuple[list[str],ndarray] | None) – (read-write) Value for $SPILLOVER. First element of tuple the list of measurement names and the second is the matrix. Each measurement name must correspond to a $PnN, must be unique, and the length of this list must match the number of rows and columns of the matrix. The matrix must be at least 2x2. Defaults toNone.last_modifier (
str) – (read-write) Value of $LAST_MODIFIER. Defaults to"".last_modified (
datetime| None) – (read-write) Value of $LAST_MODIFIED. Defaults toNone.originality (
Literal[“Original”, “NonDataModified”, “Appended”, “DataModified”] | None) – (read-write) Value of $ORIGINALITY. Defaults toNone.plateid (
str) – (read-write) Value of $PLATEID. Defaults to"".platename (
str) – (read-write) Value of $PLATENAME. Defaults to"".wellid (
str) – (read-write) Value of $WELLID. Defaults to"".vol (
float| None) – (read-write) Value of $VOL. Defaults toNone.csvbits (
int) – (read-write) Value of $CSVBITS. Defaults to0.cstot (
int) – (read-write) Value of $CSTOT. Defaults to0.csvflags (
list[int| None]) – (read-write) Subset flags. Each element in the list corresponds to $CSVnFLAG and the length of the list corresponds to $CSMODE. Defaults to[].abrt (
int| None) – (read-write) Value of $ABRT. Defaults toNone.com (
str) – (read-write) Value of $COM. Defaults to"".cells (
str) – (read-write) Value of $CELLS. Defaults to"".exp (
str) – (read-write) Value of $EXP. Defaults to"".fil (
str) – (read-write) Value of $FIL. Defaults to"".inst (
str) – (read-write) Value of $INST. Defaults to"".lost (
int| None) – (read-write) Value of $LOST. Defaults toNone.op (
str) – (read-write) Value of $OP. Defaults to"".proj (
str) – (read-write) Value of $PROJ. Defaults to"".smno (
str) – (read-write) Value of $SMNO. Defaults to"".src (
str) – (read-write) Value of $SRC. Defaults to"".sys (
str) – (read-write) Value of $SYS. Defaults to"".tr (
tuple[int,str] | None) – (read-write) Value for $TR. First member of tuple is threshold and second is the measurement name which must match a $PnN. Defaults toNone.applied_gates (
tuple[list[GatedMeasurement],dict[int,UnivariateRegion3_0|BivariateRegion3_0],str| None]) – (read-write) Value for $Gm/$RnI/$RnW/$GATING/$GATE* keywords. The first member of the tuple corresponds to the $Gm* keywords, where m is given by position in the list. The second member corresponds to the $RnI and $RnW keywords and is a mapping of regions and windows to be used in gating scheme. Keys in dictionary are the region indices (the n in $RnI and $RnW). The values in the dictionary are either univariate or bivariate gates and must correspond to an index in the list in the first element or a physical measurement. The third member corresponds to the $GATING keyword. All ‘Rn’ in this string must reference a key in the dict of the second member. Defaults to([], {}, None).nonstandard_keywords (
dict[str,str]) – (read-write) Pairs of non-standard keyword values. Keys must not start with $. Defaults to{}.
- Raises:
OverflowError – if
abrt,cstot,csvbits, orlostis less than0or greater than2**32-1InvalidKeywordValueError – if
volis negative,NaN,inf, or-infInvalidKeywordValueError – if matrix in
spilloverdoes not have the same number of rows and columns as the measurement vectorOverflowError – if field 1 in
tris less than0or greater than2**32-1ParseKeywordValueError – if field 1 in
measurementsis""or contains commasInvalidKeywordValueError – if field 2 in
spilloveris not a square matrix that is 2x2 or largerParseKeywordValueError – if field 2 in
tris""or contains commasOverflowError – if any in
csvflagsis less than0or greater than2**32-1ParseKeywordValueError – if any in field 1 in
spilloveris""or contains commasParseKeyError – if dict key in
nonstandard_keywordsis empty or starts with"$"
- all_calibrations¶
Value of $PnCALIBRATION for all measurements (read-write).
()will be returned for time since $PnCALIBRATION is not defined for temporal measurements.
- all_detector_types¶
Value of $PnT for all measurements (read-write).
()will be returned for time since $PnT is not defined for temporal measurements.
- all_detector_voltages¶
Value of $PnV for all measurements (read-write).
()will be returned for time since $PnV is not defined for temporal measurements.
- all_displays¶
Value of $PnD for all measurements (read-write).
- all_filters¶
Value of $PnF for all measurements (read-write).
()will be returned for time since $PnF is not defined for temporal measurements.
- all_meas_nonstandard_keywords¶
The non-standard keywords for each measurement (read-write).
- all_percents_emitted¶
Value of $PnP for all measurements (read-write).
()will be returned for time since $PnP is not defined for temporal measurements.
- all_powers¶
Value of $PnO for all measurements (read-write).
()will be returned for time since $PnO is not defined for temporal measurements.
- all_scale_transforms¶
The value for $PnE and/or $PnG for all measurements (read-write).
Collectively these keywords correspond to scale transforms.
If scaling is linear, return a float which corresponds to the value of $PnG when $PnE is
0,0. If scaling is logarithmic, return a pair of floats, corresponding to unset $PnG and the non-0,0value of $PnE.The FCS standards disallow any other combinations.
The temporal measurement will always be
1.0, corresponding to an identity transform. Setting it to another value will raiseRelationalError.
- all_shortnames¶
Value of $PnN for all measurements (read-write).
Strings are unique and cannot contain commas.
- all_wavelengths¶
Value of $PnL for all measurements (read-write).
()will be returned for time since $PnL is not defined for temporal measurements.
- classmethod from_kws(std, nonstd, trim_intra_value_whitespace=False, time_meas_pattern='^(TIME|Time)$', allow_missing_time=False, force_time_linear=False, ignore_time_optical_keys=[], date_pattern=None, time_pattern=None, allow_pseudostandard=False, allow_unused_standard=False, disallow_deprecated=False, fix_log_scale_offsets=False, nonstandard_measurement_pattern=None, ignore_time_gain=False, parse_indexed_spillover=False, allow_optional_dropping=False, transfer_dropped_optional=False, disallow_range_truncation=False, warnings_are_errors=False, hide_warnings=False)¶
Make new instance from keywords.
- Parameters:
std (
dict[str,str]) – Standard keywords. Must not contain any $Pn* keywords not indexed by $PAR or $TOT, $BEGINDATA, $ENDDATA, $BEGINANALYSIS, $ENDANALYSIS, or $TIMESTEP (if time measurement not included).trim_intra_value_whitespace (
bool) – IfTrue, trim whitespace between delimiters such as,and;within keyword value strings. Defaults toFalse.time_meas_pattern (
str| None) – A pattern to match the $PnN of the time measurement. IfNone, do not try to find a time measurement. Defaults to"^(TIME|Time)$".allow_missing_time (
bool) – IfTrueallow time measurement to be missing. Defaults toFalse.force_time_linear (
bool) – IfTrueforce time measurement to be linear independent of $PnE. Defaults toFalse.ignore_time_optical_keys (
list[Literal[“F”, “L”, “O”, “T”, “P”, “V”, “CALIBRATION”, “DET”, “TAG”, “FEATURE”, “ANALYTE”]]) – Ignore optical keys in temporal measurement. These keys are nonsensical for time measurements but are not explicitly forbidden in the the standard. Provided keys are the string after the “Pn” in the “PnX” keywords. Defaults to[].date_pattern (
str| None) – If supplied, will be used as an alternative pattern when parsing $DATE. If not supplied, $DATE will be parsed according to the standard pattern which is%d-%b-%Y. Defaults toNone.time_pattern (
str| None) – If supplied, will be used as an alternative pattern when parsing $BTIM and $ETIM. The values"%!"or"%@"may be used to match 1/60 seconds or centiseconds respectively. If not supplied, $BTIM and $ETIM will be parsed according to the standard pattern which is"%H:%M:%S.%@". Defaults toNone.allow_pseudostandard (
bool) – IfTrueallow non-standard keywords with a leading $. The presence of such keywords often means the version in HEADER is incorrect. Defaults toFalse.allow_unused_standard (
bool) – IfTrueallow unused standard keywords to be present. Defaults toFalse.disallow_deprecated (
bool) – IfTruethrow error if a deprecated key is encountered. Defaults toFalse.fix_log_scale_offsets (
bool) – IfTruefix log-scale PnE and keywords which have zero offset (ieX,0.0whereXis non-zero). Defaults toFalse.nonstandard_measurement_pattern (
str| None) – Pattern to use when matching nonstandard measurement keys. Must be a regular expression pattern with%nwhich will represent the measurement index and should not start with $. Otherwise should be a normal regular expression as defined in regexp-syntax. Defaults toNone.ignore_time_gain (
bool) – IfTrueignore the $PnG (gain) keyword. This keyword should not be set according to the standard} however, this library will allow gain to be 1.0 since this equates to identity. If gain is not 1.0, this is nonsense and it can be ignored with this flag. Defaults toFalse.parse_indexed_spillover (
bool) – Parse $SPILLOVER with numeric indices rather than strings (ie names or $PnN) Defaults toFalse.allow_optional_dropping (
bool) – IfTruedrop optional keys that cause an error and emit warning instead. Defaults toFalse.transfer_dropped_optional (
bool) – IfTruetransfer optional keys to non-standard dict if dropped. Defaults toFalse.disallow_range_truncation (
bool) – IfTruethrow error if $PnR values need to be truncated to match the number of bytes specified by $PnB and $DATATYPE. Defaults toFalse.warnings_are_errors (
bool) – IfTrueall warnings will be regarded as errors. Defaults toFalse.hide_warnings (
bool) – IfTruehide all warnings. Defaults toFalse.
- Return type:
- Raises:
ConfigError – if
nonstandard_measurement_patterndoes not have"%n"ConfigError – if
time_patterndoes not have specifiers for hours, minutes, seconds, and optionally sub-seconds (where"%!"and"%@"correspond to 1/60 seconds and centiseconds respectively) as outlined in chronoConfigError – if
date_patterndoes not have year, month, and day specifiers as outlined in chronoConfigError – if
time_meas_patternis not a valid regular expression as described in regexp-syntaxParseKeyError – if dict key in
nonstdis empty or starts with"$"ParseKeyError – if dict key in
stdis empty, does not start with"$", or is only a"$"ParseKeywordValueError – If any keyword values could not be read from their string encoding
RelationalError – If keywords that are referenced by other keywords do not exist
ExtraKeywordError – If any standard keys are unused and
allow_pseudostandardorallow_unused_standardareFalse
- insert_optical(index, name, meas, range, disallow_trunc=False)¶
Insert optical measurement at position in measurement vector.
- Parameters:
index (
int) – Position at which to insert new measurement.name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Optical3_1) – The measurement to insert.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- insert_temporal(index, name, meas, range, disallow_trunc=False)¶
Insert temporal measurement at position in measurement vector.
- Parameters:
index (
int) – Position at which to insert new measurement.name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Temporal3_1) – The measurement to insert.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- measurement_at(index)¶
Return measurement at index.
- Parameters:
index (
int) – Index to retrieve.- Return type:
- Raises:
IndexError – If
indexnot found
- measurement_named(name)¶
Return measurement with name.
- Parameters:
name (
str) – Name to retrieve. Corresponds to $PnN.- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namenot found
- measurements¶
All measurements (read-write).
- Return type:
- push_optical(name, meas, range, disallow_trunc=False)¶
Push optical measurement to end of measurement vector.
- Parameters:
name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Optical3_1) – The measurement to push.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- push_temporal(name, meas, range, disallow_trunc=False)¶
Push temporal measurement to end of measurement vector.
- Parameters:
name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Temporal3_1) – The measurement to push.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- remove_measurement_by_index(index)¶
Remove a measurement with a given index.
- Parameters:
index (
int) – Index to remove.- Returns:
Name and measurement object.
- Return type:
tuple[str,Optical3_1|Temporal3_1,Decimal]- Raises:
IndexError – If
indexnot found
- remove_measurement_by_name(name)¶
Remove a measurement with a given name.
- Parameters:
name (
str) – Name to remove. Corresponds to $PnN.- Returns:
Index and measurement object.
- Return type:
tuple[int,Optical3_1|Temporal3_1,Decimal]- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namenot found
- rename_temporal(name)¶
Rename temporal measurement if present.
- Parameters:
name (
str) – New name to assign. Corresponds to $PnN.- Returns:
Previous name if present.
- Return type:
str| None- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- replace_optical_at(index, meas)¶
Replace measurement at index with given optical measurement.
- Parameters:
index (
int) – Index to replace.meas (
Optical3_1) – Optical measurement to replace measurement atindex.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
IndexError – If
indexdoes not exist.
- replace_optical_named(name, meas)¶
Replace named measurement with given optical measurement.
- Parameters:
name (
str) – Name to replace. Corresponds to $PnN.meas (
Optical3_1) – Optical measurement to replace measurement atname.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namedoes not exist.
- replace_temporal_at(index, meas)¶
Replace measurement at index with given temporal measurement.
- Parameters:
index (
int) – Index to replace.meas (
Temporal3_1) – Temporal measurement to replace measurement atindex.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
IndexError – If
indexdoes not existRelationalError – If a temporal measurement already exists at a different position
- replace_temporal_named(name, meas)¶
Replace named measurement with given temporal measurement.
- Parameters:
name (
str) – Name to replace. Corresponds to $PnN.meas (
Temporal3_1) – Temporal measurement to replace measurement atname.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namedoes not existRelationalError – If a temporal measurement already exists at a different position
- set_measurements_and_layout(measurements, layout)¶
Set all measurements and layout at once.
Length of
measurementsmust match number of columns inlayout.- Parameters:
measurements (
list[Optical3_1|Temporal3_1]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.layout (
FixedAsciiLayout|DelimAsciiLayout|EndianUintLayout|EndianF32Layout|EndianF64Layout) – The new layout.
- set_named_measurements(measurements, allow_shared_names=False, skip_index_check=False)¶
Set all measurements at once.
Length of
measurementsmust match number of columns in existing layout.- Parameters:
measurements (
tuple[str,Optical3_1|Temporal3_1]) – The new measurements. The first member of the tuple corresponds to the measurement name and the second is the measurement object.allow_shared_names (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keywords reference any $PnN keywords. IfTrueraiseRelationalErrorif any non-measurement keywords reference a $PnN which is not present inmeasurements. In other words,Falseforbids named references to exist, andTrueallows named references to be updated. References cannot be broken in either case. Defaults toFalse.skip_index_check (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keyword have an index reference to the current measurements. IfTrueallow such references to exist as long as they do not break (which really means that the length ofmeasurementsis such that existing indices are satisfied). Defaults toFalse.
- Raises:
ParseKeywordValueError – if field 1 in
measurementsis""or contains commas
- set_named_measurements_and_layout(measurements, layout, allow_shared_names=False, skip_index_check=False)¶
Set all measurements, names, and layout at once.
Length of
measurementsmust match number of columns inlayout.- Parameters:
measurements (
tuple[str,Optical3_1|Temporal3_1]) – The new measurements. The first member of the tuple corresponds to the measurement name and the second is the measurement object.layout (
FixedAsciiLayout|DelimAsciiLayout|EndianUintLayout|EndianF32Layout|EndianF64Layout) – The new layout.allow_shared_names (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keywords reference any $PnN keywords. IfTrueraiseRelationalErrorif any non-measurement keywords reference a $PnN which is not present inmeasurements. In other words,Falseforbids named references to exist, andTrueallows named references to be updated. References cannot be broken in either case. Defaults toFalse.skip_index_check (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keyword have an index reference to the current measurements. IfTrueallow such references to exist as long as they do not break (which really means that the length ofmeasurementsis such that existing indices are satisfied). Defaults toFalse.
- Raises:
ParseKeywordValueError – if field 1 in
measurementsis""or contains commas
- set_temporal(name, timestep, allow_loss=False)¶
Set the temporal measurement to a given name.
- Parameters:
name (
str) – Name to set to temporal. Corresponds to $PnN.timestep (
float) – The value of $TIMESTEP to use.allow_loss (
bool) – IfTrueremove any optical-specific metadata (detectors, lasers, etc) without raising anConversionErrorif an optical measurement must be converted. Defaults toFalse.
- Returns:
Trueif temporal measurement was set, which will happen for all cases except when the time measurement is already set toname.- Return type:
- Raises:
InvalidKeywordValueError – if
timestepis negative,0.0,NaN,inf, or-infParseKeywordValueError – if
nameis""or contains commas
- set_temporal_at(index, timestep, allow_loss=False)¶
Set the temporal measurement to a given index.
- Parameters:
index (
int) – Index to set.timestep (
float) – The value of $TIMESTEP to use.allow_loss (
bool) – IfTrueremove any optical-specific metadata (detectors, lasers, etc) without raising anConversionErrorif an optical measurement must be converted. Defaults toFalse.
- Returns:
Trueif temporal measurement was set, which will happen for all cases except when the time measurement is already set toindex.- Return type:
- Raises:
InvalidKeywordValueError – if
timestepis negative,0.0,NaN,inf, or-inf
- set_timestep(timestep)¶
Set the $TIMESTEP if time measurement is present.
- Parameters:
timestep (
float) – The timestep to set. Must be greater than zero.- Returns:
Previous $TIMESTEP if present.
- Return type:
float| None- Raises:
InvalidKeywordValueError – if
timestepis negative,0.0,NaN,inf, or-inf
- set_trigger_threshold(threshold)¶
Set the threshold for $TR.
- standard_keywords(req_or_opt, root_or_meas)¶
Return standard keywords as string pairs.
Each key will be prefixed with $.
This will not include $TOT, $NEXTDATA, or any of the offset keywords since these only matter if the dataset is written.
- Parameters:
- Returns:
A list of standard keywords.
- Return type:
- temporal¶
The temporal measurement if it exists (read-only).
- Returns:
Index, name, and measurement or
None.- Return type:
tuple[int,str,Temporal3_1] | None
- to_dataset(data, analysis=b'', others=[])¶
Convert to a dataset object.
This will fully represent an FCS file, as opposed to just representing HEADER and TEXT.
- Parameters:
data (
polars.DataFrame) – A dataframe encoding the contents of DATA. Number of columns must match number of measurements. May be empty. Types do not necessarily need to correspond to those in the data layout but mismatches may result in truncation.analysis (
bytes) – Contents of the ANALYSIS segment. Defaults tob"".others (
list[bytes]) – A list of byte strings encoding the OTHER segments. Defaults to[].
- Return type:
- Raises:
EventDataError – If
datacontains columns which are not unsigned 8/16/32/64-bit integers or 32/64-bit floats
- to_version_2_0(allow_loss=False)¶
Convert to FCS 2.0.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 2.0.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 2.0 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 2.0
- to_version_3_0(allow_loss=False)¶
Convert to FCS 3.0.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 3.0.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 3.0 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 3.0
- to_version_3_2(allow_loss=False)¶
Convert to FCS 3.2.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 3.2.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 3.2 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 3.2
- unset_measurements()¶
Remove measurements and clear the layout.
This is equivalent to deleting all $Pn* keywords and setting $PAR to
0.- Return type:
tuple[()]- Raises:
RelationalError – If keywords are set which refer to measurements and would be invalidated if measurements were removed
- unset_temporal()¶
Convert the temporal measurement to an optical measurement.
- Returns:
Value of $TIMESTEP if time measurement was present.
- Return type:
float| None
- version¶
Show the FCS version (read-only).
- Return type:
Literal[“FCS2.0”, “FCS3.0”, “FCS3.1”, “FCS3.2”]
- write_text(path, delim=30, big_other=False, appendable=False, append=False)¶
Write data to path.
Resulting FCS file will include HEADER and TEXT.
- Parameters:
path (
Path) – Path to be written.delim (
int) – Delimiter to use when writing TEXT. Defaults to30.big_other (
bool) – IfTrueuse 20 chars for OTHER segment offsets, and 8 otherwise. Defaults toFalse.appendable (
bool) – IfTrue, set $NEXTDATA in written dataset so it points to the next dataset. This obviously assumes the next dataset is actually written, which will require another call to this method withappendset toTrue. Defaults toFalse.append (
bool) – IfTrue, append this dataset to the end of the file if it exists and already has at least one dataset in it. This assumes that the previous dataset was written withappendableset toTrueso that $NEXTDATA is properly set. Defaults toFalse.
- Returns:
the value of $NEXTDATA as written to the dataset
- Return type:
- Raises:
ConfigError – if
delimis not between 1 and 126OverflowError – If TEXT offsets are greater than 99,999,999 bytes
OverflowError – If any OTHER offsets are greater than 99,999,999 and
big_otherisFalse
- classmethod write_texts(path, datasets, delim=30, big_other=False)¶
Write multiple datasets to path.
The resulting file will have HEADER and TEXT from each object
- Parameters:
path (
Path) – Path to be written.datasets (
list[CoreTEXT3_1]) – datasets to writedelim (
int) – Delimiter to use when writing TEXT. Defaults to30.big_other (
bool) – IfTrueuse 20 chars for OTHER segment offsets, and 8 otherwise. Defaults toFalse.
- Returns:
the value of $NEXTDATA as written in the last dataset
- Return type:
int| None- Raises:
ConfigError – if
delimis not between 1 and 126OverflowError – If TEXT offsets are greater than 99,999,999 bytes
OverflowError – If any OTHER offsets are greater than 99,999,999 and
big_otherisFalse
- class pyreflow.CoreTEXT3_2(measurements, layout, cyt, mode=None, btim=None, etim=None, date=None, begindatetime=None, enddatetime=None, cytsn='', spillover=None, last_modifier='', last_modified=None, originality=None, plateid='', platename='', wellid='', vol=None, carrierid='', carriertype='', locationid='', unstainedinfo='', unstainedcenters={}, flowrate='', abrt=None, com='', cells='', exp='', fil='', inst='', lost=None, op='', proj='', smno='', src='', sys='', tr=None, applied_gates=({}, None), nonstandard_keywords={})¶
Represents TEXT for an FCS 3.2 file.
- Parameters:
measurements (
tuple[str,Optical3_2|Temporal3_2]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.- Variables:
layout (
FixedAsciiLayout|DelimAsciiLayout|EndianUintLayout|EndianF32Layout|EndianF64Layout|MixedLayout) – (read-write) Layout to describe data encoding. Represents $PnB, $PnR, $BYTEORD, $DATATYPE, and $PnDATATYPE.cyt (
str) – (read-write) Value of $CYT.mode (
Literal[“L”] | None) – (read-write) Value of $MODE. Defaults toNone.btim (
time| None) – (read-write) Value of $BTIM. Defaults toNone.etim (
time| None) – (read-write) Value of $ETIM. Defaults toNone.date (
date| None) – (read-write) Value of $DATE. Defaults toNone.begindatetime (
datetime| None) – (read-write) Value for $BEGINDATETIME. Defaults toNone.enddatetime (
datetime| None) – (read-write) Value for $ENDDATETIME. Defaults toNone.cytsn (
str) – (read-write) Value of $CYTSN. Defaults to"".spillover (
tuple[list[str],ndarray] | None) – (read-write) Value for $SPILLOVER. First element of tuple the list of measurement names and the second is the matrix. Each measurement name must correspond to a $PnN, must be unique, and the length of this list must match the number of rows and columns of the matrix. The matrix must be at least 2x2. Defaults toNone.last_modifier (
str) – (read-write) Value of $LAST_MODIFIER. Defaults to"".last_modified (
datetime| None) – (read-write) Value of $LAST_MODIFIED. Defaults toNone.originality (
Literal[“Original”, “NonDataModified”, “Appended”, “DataModified”] | None) – (read-write) Value of $ORIGINALITY. Defaults toNone.plateid (
str) – (read-write) Value of $PLATEID. Defaults to"".platename (
str) – (read-write) Value of $PLATENAME. Defaults to"".wellid (
str) – (read-write) Value of $WELLID. Defaults to"".vol (
float| None) – (read-write) Value of $VOL. Defaults toNone.carrierid (
str) – (read-write) Value of $CARRIERID. Defaults to"".carriertype (
str) – (read-write) Value of $CARRIERTYPE. Defaults to"".locationid (
str) – (read-write) Value of $LOCATIONID. Defaults to"".unstainedinfo (
str) – (read-write) Value of $UNSTAINEDINFO. Defaults to"".unstainedcenters (
dict[str,float]) – (read-write) Value for $UNSTAINEDCENTERS. Each key must match a *$PnN. Defaults to{}.flowrate (
str) – (read-write) Value of $FLOWRATE. Defaults to"".abrt (
int| None) – (read-write) Value of $ABRT. Defaults toNone.com (
str) – (read-write) Value of $COM. Defaults to"".cells (
str) – (read-write) Value of $CELLS. Defaults to"".exp (
str) – (read-write) Value of $EXP. Defaults to"".fil (
str) – (read-write) Value of $FIL. Defaults to"".inst (
str) – (read-write) Value of $INST. Defaults to"".lost (
int| None) – (read-write) Value of $LOST. Defaults toNone.op (
str) – (read-write) Value of $OP. Defaults to"".proj (
str) – (read-write) Value of $PROJ. Defaults to"".smno (
str) – (read-write) Value of $SMNO. Defaults to"".src (
str) – (read-write) Value of $SRC. Defaults to"".sys (
str) – (read-write) Value of $SYS. Defaults to"".tr (
tuple[int,str] | None) – (read-write) Value for $TR. First member of tuple is threshold and second is the measurement name which must match a $PnN. Defaults toNone.applied_gates (
tuple[dict[int,UnivariateRegion3_2|BivariateRegion3_2],str| None]) – (read-write) Value for $RnI/$RnW/$GATING keywords. The first member corresponds to the $RnI and $RnW keywords and is a mapping of regions and windows to be used in gating scheme. Keys in dictionary are the region indices (the n in $RnI and $RnW). The values in the dictionary are either univariate or bivariate gates and must correspond to a physical measurement. The second member corresponds to the $GATING keyword. All ‘Rn’ in this string must reference a key in the dict of the first member. Defaults to({}, None).nonstandard_keywords (
dict[str,str]) – (read-write) Pairs of non-standard keyword values. Keys must not start with $. Defaults to{}.
- Raises:
OverflowError – if
abrtorlostis less than0or greater than2**32-1InvalidKeywordValueError – if
cytis emptyInvalidKeywordValueError – if
volis negative,NaN,inf, or-infInvalidKeywordValueError – if matrix in
spilloverdoes not have the same number of rows and columns as the measurement vectorOverflowError – if field 1 in
tris less than0or greater than2**32-1ParseKeywordValueError – if field 1 in
measurementsis""or contains commasInvalidKeywordValueError – if field 2 in
spilloveris not a square matrix that is 2x2 or largerParseKeywordValueError – if field 2 in
tris""or contains commasParseKeywordValueError – if any in field 1 in
spilloveris""or contains commasParseKeyError – if dict key in
nonstandard_keywordsis empty or starts with"$"ParseKeywordValueError – if dict key in
unstainedcentersis""or contains commas
- all_analytes¶
Value of $PnANALYTE for all measurements (read-write).
()will be returned for time since $PnANALYTE is not defined for temporal measurements.
- all_calibrations¶
Value of $PnCALIBRATION for all measurements (read-write).
()will be returned for time since $PnCALIBRATION is not defined for temporal measurements.
- all_detector_names¶
Value of $PnDET for all measurements (read-write).
()will be returned for time since $PnDET is not defined for temporal measurements.
- all_detector_types¶
Value of $PnT for all measurements (read-write).
()will be returned for time since $PnT is not defined for temporal measurements.
- all_detector_voltages¶
Value of $PnV for all measurements (read-write).
()will be returned for time since $PnV is not defined for temporal measurements.
- all_displays¶
Value of $PnD for all measurements (read-write).
- all_features¶
Value of $PnFEATURE for all measurements (read-write).
()will be returned for time since $PnFEATURE is not defined for temporal measurements.
- all_filters¶
Value of $PnF for all measurements (read-write).
()will be returned for time since $PnF is not defined for temporal measurements.
- all_meas_nonstandard_keywords¶
The non-standard keywords for each measurement (read-write).
- all_measurement_types¶
Value of $PnTYPE for all measurements (read-write).
A bool will be returned for the time measurement where
Trueindicates it is set to"Time".
- all_percents_emitted¶
Value of $PnP for all measurements (read-write).
()will be returned for time since $PnP is not defined for temporal measurements.
- all_powers¶
Value of $PnO for all measurements (read-write).
()will be returned for time since $PnO is not defined for temporal measurements.
- all_scale_transforms¶
The value for $PnE and/or $PnG for all measurements (read-write).
Collectively these keywords correspond to scale transforms.
If scaling is linear, return a float which corresponds to the value of $PnG when $PnE is
0,0. If scaling is logarithmic, return a pair of floats, corresponding to unset $PnG and the non-0,0value of $PnE.The FCS standards disallow any other combinations.
The temporal measurement will always be
1.0, corresponding to an identity transform. Setting it to another value will raiseRelationalError.
- all_shortnames¶
Value of $PnN for all measurements (read-write).
Strings are unique and cannot contain commas.
- all_tags¶
Value of $PnTAG for all measurements (read-write).
()will be returned for time since $PnTAG is not defined for temporal measurements.
- all_wavelengths¶
Value of $PnL for all measurements (read-write).
()will be returned for time since $PnL is not defined for temporal measurements.
- classmethod from_kws(std, nonstd, trim_intra_value_whitespace=False, time_meas_pattern='^(TIME|Time)$', allow_missing_time=False, force_time_linear=False, ignore_time_optical_keys=[], date_pattern=None, time_pattern=None, allow_pseudostandard=False, allow_unused_standard=False, disallow_deprecated=False, fix_log_scale_offsets=False, nonstandard_measurement_pattern=None, ignore_time_gain=False, parse_indexed_spillover=False, disallow_localtime=False, allow_optional_dropping=False, transfer_dropped_optional=False, disallow_range_truncation=False, warnings_are_errors=False, hide_warnings=False)¶
Make new instance from keywords.
- Parameters:
std (
dict[str,str]) – Standard keywords. Must not contain any $Pn* keywords not indexed by $PAR or $TOT, $BEGINDATA, $ENDDATA, $BEGINANALYSIS, $ENDANALYSIS, or $TIMESTEP (if time measurement not included).trim_intra_value_whitespace (
bool) – IfTrue, trim whitespace between delimiters such as,and;within keyword value strings. Defaults toFalse.time_meas_pattern (
str| None) – A pattern to match the $PnN of the time measurement. IfNone, do not try to find a time measurement. Defaults to"^(TIME|Time)$".allow_missing_time (
bool) – IfTrueallow time measurement to be missing. Defaults toFalse.force_time_linear (
bool) – IfTrueforce time measurement to be linear independent of $PnE. Defaults toFalse.ignore_time_optical_keys (
list[Literal[“F”, “L”, “O”, “T”, “P”, “V”, “CALIBRATION”, “DET”, “TAG”, “FEATURE”, “ANALYTE”]]) – Ignore optical keys in temporal measurement. These keys are nonsensical for time measurements but are not explicitly forbidden in the the standard. Provided keys are the string after the “Pn” in the “PnX” keywords. Defaults to[].date_pattern (
str| None) – If supplied, will be used as an alternative pattern when parsing $DATE. If not supplied, $DATE will be parsed according to the standard pattern which is%d-%b-%Y. Defaults toNone.time_pattern (
str| None) – If supplied, will be used as an alternative pattern when parsing $BTIM and $ETIM. The values"%!"or"%@"may be used to match 1/60 seconds or centiseconds respectively. If not supplied, $BTIM and $ETIM will be parsed according to the standard pattern which is"%H:%M:%S.%@". Defaults toNone.allow_pseudostandard (
bool) – IfTrueallow non-standard keywords with a leading $. The presence of such keywords often means the version in HEADER is incorrect. Defaults toFalse.allow_unused_standard (
bool) – IfTrueallow unused standard keywords to be present. Defaults toFalse.disallow_deprecated (
bool) – IfTruethrow error if a deprecated key is encountered. Defaults toFalse.fix_log_scale_offsets (
bool) – IfTruefix log-scale PnE and keywords which have zero offset (ieX,0.0whereXis non-zero). Defaults toFalse.nonstandard_measurement_pattern (
str| None) – Pattern to use when matching nonstandard measurement keys. Must be a regular expression pattern with%nwhich will represent the measurement index and should not start with $. Otherwise should be a normal regular expression as defined in regexp-syntax. Defaults toNone.ignore_time_gain (
bool) – IfTrueignore the $PnG (gain) keyword. This keyword should not be set according to the standard} however, this library will allow gain to be 1.0 since this equates to identity. If gain is not 1.0, this is nonsense and it can be ignored with this flag. Defaults toFalse.parse_indexed_spillover (
bool) – Parse $SPILLOVER with numeric indices rather than strings (ie names or $PnN) Defaults toFalse.disallow_localtime (
bool) – Iftrue, require that $BEGINDATETIME and $ENDDATETIME have a timezone if provided. This is not required by the standard, but not having a timezone is ambiguous since the absolute value of the timestamp is dependent on localtime and therefore is location-dependent. Only affects FCS 3.2. Defaults toFalse.allow_optional_dropping (
bool) – IfTruedrop optional keys that cause an error and emit warning instead. Defaults toFalse.transfer_dropped_optional (
bool) – IfTruetransfer optional keys to non-standard dict if dropped. Defaults toFalse.disallow_range_truncation (
bool) – IfTruethrow error if $PnR values need to be truncated to match the number of bytes specified by $PnB and $DATATYPE. Defaults toFalse.warnings_are_errors (
bool) – IfTrueall warnings will be regarded as errors. Defaults toFalse.hide_warnings (
bool) – IfTruehide all warnings. Defaults toFalse.
- Return type:
- Raises:
ConfigError – if
nonstandard_measurement_patterndoes not have"%n"ConfigError – if
time_patterndoes not have specifiers for hours, minutes, seconds, and optionally sub-seconds (where"%!"and"%@"correspond to 1/60 seconds and centiseconds respectively) as outlined in chronoConfigError – if
date_patterndoes not have year, month, and day specifiers as outlined in chronoConfigError – if
time_meas_patternis not a valid regular expression as described in regexp-syntaxParseKeyError – if dict key in
nonstdis empty or starts with"$"ParseKeyError – if dict key in
stdis empty, does not start with"$", or is only a"$"ParseKeywordValueError – If any keyword values could not be read from their string encoding
RelationalError – If keywords that are referenced by other keywords do not exist
ExtraKeywordError – If any standard keys are unused and
allow_pseudostandardorallow_unused_standardareFalse
- insert_optical(index, name, meas, range, disallow_trunc=False)¶
Insert optical measurement at position in measurement vector.
- Parameters:
index (
int) – Position at which to insert new measurement.name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Optical3_2) – The measurement to insert.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- insert_temporal(index, name, meas, range, disallow_trunc=False)¶
Insert temporal measurement at position in measurement vector.
- Parameters:
index (
int) – Position at which to insert new measurement.name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Temporal3_2) – The measurement to insert.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- measurement_at(index)¶
Return measurement at index.
- Parameters:
index (
int) – Index to retrieve.- Return type:
- Raises:
IndexError – If
indexnot found
- measurement_named(name)¶
Return measurement with name.
- Parameters:
name (
str) – Name to retrieve. Corresponds to $PnN.- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namenot found
- measurements¶
All measurements (read-write).
- Return type:
- push_optical(name, meas, range, disallow_trunc=False)¶
Push optical measurement to end of measurement vector.
- Parameters:
name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Optical3_2) – The measurement to push.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- push_temporal(name, meas, range, disallow_trunc=False)¶
Push temporal measurement to end of measurement vector.
- Parameters:
name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Temporal3_2) – The measurement to push.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- remove_measurement_by_index(index)¶
Remove a measurement with a given index.
- Parameters:
index (
int) – Index to remove.- Returns:
Name and measurement object.
- Return type:
tuple[str,Optical3_2|Temporal3_2,Decimal]- Raises:
IndexError – If
indexnot found
- remove_measurement_by_name(name)¶
Remove a measurement with a given name.
- Parameters:
name (
str) – Name to remove. Corresponds to $PnN.- Returns:
Index and measurement object.
- Return type:
tuple[int,Optical3_2|Temporal3_2,Decimal]- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namenot found
- rename_temporal(name)¶
Rename temporal measurement if present.
- Parameters:
name (
str) – New name to assign. Corresponds to $PnN.- Returns:
Previous name if present.
- Return type:
str| None- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- replace_optical_at(index, meas)¶
Replace measurement at index with given optical measurement.
- Parameters:
index (
int) – Index to replace.meas (
Optical3_2) – Optical measurement to replace measurement atindex.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
IndexError – If
indexdoes not exist.
- replace_optical_named(name, meas)¶
Replace named measurement with given optical measurement.
- Parameters:
name (
str) – Name to replace. Corresponds to $PnN.meas (
Optical3_2) – Optical measurement to replace measurement atname.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namedoes not exist.
- replace_temporal_at(index, meas, allow_loss=False)¶
Replace measurement at index with given temporal measurement.
- Parameters:
index (
int) – Index to replace.meas (
Temporal3_2) – Temporal measurement to replace measurement atindex.allow_loss (
bool) – IfFalse, raiseConversionErrorif conversion from temporal measurement to optical measurement is necessary and data keywords must be dropped. Defaults toFalse.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
IndexError – If
indexdoes not existRelationalError – If a temporal measurement already exists at a different position
- replace_temporal_named(name, meas, allow_loss=False)¶
Replace named measurement with given temporal measurement.
- Parameters:
name (
str) – Name to replace. Corresponds to $PnN.meas (
Temporal3_2) – Temporal measurement to replace measurement atname.allow_loss (
bool) – IfFalse, raiseConversionErrorif conversion from temporal measurement to optical measurement is necessary and data keywords must be dropped. Defaults toFalse.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namedoes not existRelationalError – If a temporal measurement already exists at a different position
- set_measurements_and_layout(measurements, layout)¶
Set all measurements and layout at once.
Length of
measurementsmust match number of columns inlayout.- Parameters:
measurements (
list[Optical3_2|Temporal3_2]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.layout (
FixedAsciiLayout|DelimAsciiLayout|EndianUintLayout|EndianF32Layout|EndianF64Layout|MixedLayout) – The new layout.
- set_named_measurements(measurements, allow_shared_names=False, skip_index_check=False)¶
Set all measurements at once.
Length of
measurementsmust match number of columns in existing layout.- Parameters:
measurements (
tuple[str,Optical3_2|Temporal3_2]) – The new measurements. The first member of the tuple corresponds to the measurement name and the second is the measurement object.allow_shared_names (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keywords reference any $PnN keywords. IfTrueraiseRelationalErrorif any non-measurement keywords reference a $PnN which is not present inmeasurements. In other words,Falseforbids named references to exist, andTrueallows named references to be updated. References cannot be broken in either case. Defaults toFalse.skip_index_check (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keyword have an index reference to the current measurements. IfTrueallow such references to exist as long as they do not break (which really means that the length ofmeasurementsis such that existing indices are satisfied). Defaults toFalse.
- Raises:
ParseKeywordValueError – if field 1 in
measurementsis""or contains commas
- set_named_measurements_and_layout(measurements, layout, allow_shared_names=False, skip_index_check=False)¶
Set all measurements, names, and layout at once.
Length of
measurementsmust match number of columns inlayout.- Parameters:
measurements (
tuple[str,Optical3_2|Temporal3_2]) – The new measurements. The first member of the tuple corresponds to the measurement name and the second is the measurement object.layout (
FixedAsciiLayout|DelimAsciiLayout|EndianUintLayout|EndianF32Layout|EndianF64Layout|MixedLayout) – The new layout.allow_shared_names (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keywords reference any $PnN keywords. IfTrueraiseRelationalErrorif any non-measurement keywords reference a $PnN which is not present inmeasurements. In other words,Falseforbids named references to exist, andTrueallows named references to be updated. References cannot be broken in either case. Defaults toFalse.skip_index_check (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keyword have an index reference to the current measurements. IfTrueallow such references to exist as long as they do not break (which really means that the length ofmeasurementsis such that existing indices are satisfied). Defaults toFalse.
- Raises:
ParseKeywordValueError – if field 1 in
measurementsis""or contains commas
- set_temporal(name, timestep, allow_loss=False)¶
Set the temporal measurement to a given name.
- Parameters:
name (
str) – Name to set to temporal. Corresponds to $PnN.timestep (
float) – The value of $TIMESTEP to use.allow_loss (
bool) – IfTrueremove any optical-specific metadata (detectors, lasers, etc) without raising anConversionErrorif an optical measurement must be converted. Defaults toFalse.
- Returns:
Trueif temporal measurement was set, which will happen for all cases except when the time measurement is already set toname.- Return type:
- Raises:
InvalidKeywordValueError – if
timestepis negative,0.0,NaN,inf, or-infParseKeywordValueError – if
nameis""or contains commas
- set_temporal_at(index, timestep, allow_loss=False)¶
Set the temporal measurement to a given index.
- Parameters:
index (
int) – Index to set.timestep (
float) – The value of $TIMESTEP to use.allow_loss (
bool) – IfTrueremove any optical-specific metadata (detectors, lasers, etc) without raising anConversionErrorif an optical measurement must be converted. Defaults toFalse.
- Returns:
Trueif temporal measurement was set, which will happen for all cases except when the time measurement is already set toindex.- Return type:
- Raises:
InvalidKeywordValueError – if
timestepis negative,0.0,NaN,inf, or-inf
- set_timestep(timestep)¶
Set the $TIMESTEP if time measurement is present.
- Parameters:
timestep (
float) – The timestep to set. Must be greater than zero.- Returns:
Previous $TIMESTEP if present.
- Return type:
float| None- Raises:
InvalidKeywordValueError – if
timestepis negative,0.0,NaN,inf, or-inf
- set_trigger_threshold(threshold)¶
Set the threshold for $TR.
- standard_keywords(req_or_opt, root_or_meas)¶
Return standard keywords as string pairs.
Each key will be prefixed with $.
This will not include $TOT, $NEXTDATA, or any of the offset keywords since these only matter if the dataset is written.
- Parameters:
- Returns:
A list of standard keywords.
- Return type:
- temporal¶
The temporal measurement if it exists (read-only).
- Returns:
Index, name, and measurement or
None.- Return type:
tuple[int,str,Temporal3_2] | None
- to_dataset(data, analysis=b'', others=[])¶
Convert to a dataset object.
This will fully represent an FCS file, as opposed to just representing HEADER and TEXT.
- Parameters:
data (
polars.DataFrame) – A dataframe encoding the contents of DATA. Number of columns must match number of measurements. May be empty. Types do not necessarily need to correspond to those in the data layout but mismatches may result in truncation.analysis (
bytes) – Contents of the ANALYSIS segment. Defaults tob"".others (
list[bytes]) – A list of byte strings encoding the OTHER segments. Defaults to[].
- Return type:
- Raises:
EventDataError – If
datacontains columns which are not unsigned 8/16/32/64-bit integers or 32/64-bit floats
- to_version_2_0(allow_loss=False)¶
Convert to FCS 2.0.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 2.0.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 2.0 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 2.0
- to_version_3_0(allow_loss=False)¶
Convert to FCS 3.0.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 3.0.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 3.0 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 3.0
- to_version_3_1(allow_loss=False)¶
Convert to FCS 3.1.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 3.1.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 3.1 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 3.1
- unset_measurements()¶
Remove measurements and clear the layout.
This is equivalent to deleting all $Pn* keywords and setting $PAR to
0.- Return type:
tuple[()]- Raises:
RelationalError – If keywords are set which refer to measurements and would be invalidated if measurements were removed
- unset_temporal(allow_loss=False)¶
Convert the temporal measurement to an optical measurement.
- Parameters:
allow_loss (
bool) – IfTrueand current time measurement has data which cannot be converted to optical, force the conversion anyways. Otherwise raiseConversionError. Defaults toFalse.- Returns:
Value of $TIMESTEP if time measurement was present.
- Return type:
float| None
- version¶
Show the FCS version (read-only).
- Return type:
Literal[“FCS2.0”, “FCS3.0”, “FCS3.1”, “FCS3.2”]
- write_text(path, delim=30, big_other=False, appendable=False, append=False)¶
Write data to path.
Resulting FCS file will include HEADER and TEXT.
- Parameters:
path (
Path) – Path to be written.delim (
int) – Delimiter to use when writing TEXT. Defaults to30.big_other (
bool) – IfTrueuse 20 chars for OTHER segment offsets, and 8 otherwise. Defaults toFalse.appendable (
bool) – IfTrue, set $NEXTDATA in written dataset so it points to the next dataset. This obviously assumes the next dataset is actually written, which will require another call to this method withappendset toTrue. Defaults toFalse.append (
bool) – IfTrue, append this dataset to the end of the file if it exists and already has at least one dataset in it. This assumes that the previous dataset was written withappendableset toTrueso that $NEXTDATA is properly set. Defaults toFalse.
- Returns:
the value of $NEXTDATA as written to the dataset
- Return type:
- Raises:
ConfigError – if
delimis not between 1 and 126OverflowError – If TEXT offsets are greater than 99,999,999 bytes
OverflowError – If any OTHER offsets are greater than 99,999,999 and
big_otherisFalse
- classmethod write_texts(path, datasets, delim=30, big_other=False)¶
Write multiple datasets to path.
The resulting file will have HEADER and TEXT from each object
- Parameters:
path (
Path) – Path to be written.datasets (
list[CoreTEXT3_2]) – datasets to writedelim (
int) – Delimiter to use when writing TEXT. Defaults to30.big_other (
bool) – IfTrueuse 20 chars for OTHER segment offsets, and 8 otherwise. Defaults toFalse.
- Returns:
the value of $NEXTDATA as written in the last dataset
- Return type:
int| None- Raises:
ConfigError – if
delimis not between 1 and 126OverflowError – If TEXT offsets are greater than 99,999,999 bytes
OverflowError – If any OTHER offsets are greater than 99,999,999 and
big_otherisFalse
CoreDataset*¶
Represents one dataset from an FCS file (HEADER + TEXT + DATA + ANALYSIS + OTHER).
These can be created by:
calling
pyreflow.api.fcs_read_std_dataset_with_keywords()calling
from_kws(described below)calling
__new__
In addition to all the minipulations offered by CoreTEXT*, these
additionally allow:
modifying the
DataFramecorresponding to DATAmodifying the byte segments corresponding to ANALYSIS and/or *OTHER
removing all data by converting to CoreTEXT*
When written, these will result in an FCS file a single dataset reflecting its contents.
- class pyreflow.CoreDataset2_0(measurements, layout, data, mode='L', cyt='', comp=None, btim=None, etim=None, date=None, abrt=None, com='', cells='', exp='', fil='', inst='', lost=None, op='', proj='', smno='', src='', sys='', tr=None, applied_gates=([], {}, None), nonstandard_keywords={}, analysis=b'', others=[])¶
Represents one dataset in an FCS 2.0 file.
- Parameters:
measurements (
tuple[str| None,Optical2_0|Temporal2_0]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.- Variables:
layout (
FixedAsciiLayout|DelimAsciiLayout|OrderedUint08Layout|OrderedUint16Layout|OrderedUint24Layout|OrderedUint32Layout|OrderedUint40Layout|OrderedUint48Layout|OrderedUint56Layout|OrderedUint64Layout|OrderedF32Layout|OrderedF64Layout) – (read-write) Layout to describe data encoding. Represents $PnB, $PnR, $BYTEORD, and $DATATYPE.data (
polars.DataFrame) – (read-write) A dataframe encoding the contents of DATA. Number of columns must match number of measurements. May be empty. Types do not necessarily need to correspond to those in the data layout but mismatches may result in truncation.mode (
Literal[“L”, “U”, “C”]) – (read-write) Value of $MODE. Defaults to"L".cyt (
str) – (read-write) Value of $CYT. Defaults to"".comp (
ndarray| None) – (read-write) The compensation matrix. Must be a square array with number of rows/columns equal to the number of measurements. Non-zero entries will produce a $DFCmTOn keyword. Defaults toNone.btim (
time| None) – (read-write) Value of $BTIM. Defaults toNone.etim (
time| None) – (read-write) Value of $ETIM. Defaults toNone.date (
date| None) – (read-write) Value of $DATE. Defaults toNone.abrt (
int| None) – (read-write) Value of $ABRT. Defaults toNone.com (
str) – (read-write) Value of $COM. Defaults to"".cells (
str) – (read-write) Value of $CELLS. Defaults to"".exp (
str) – (read-write) Value of $EXP. Defaults to"".fil (
str) – (read-write) Value of $FIL. Defaults to"".inst (
str) – (read-write) Value of $INST. Defaults to"".lost (
int| None) – (read-write) Value of $LOST. Defaults toNone.op (
str) – (read-write) Value of $OP. Defaults to"".proj (
str) – (read-write) Value of $PROJ. Defaults to"".smno (
str) – (read-write) Value of $SMNO. Defaults to"".src (
str) – (read-write) Value of $SRC. Defaults to"".sys (
str) – (read-write) Value of $SYS. Defaults to"".tr (
tuple[int,str] | None) – (read-write) Value for $TR. First member of tuple is threshold and second is the measurement name which must match a $PnN. Defaults toNone.applied_gates (
tuple[list[GatedMeasurement],dict[int,UnivariateRegion2_0|BivariateRegion2_0],str| None]) – (read-write) Value for $Gm/$RnI/$RnW/$GATING/$GATE* keywords. The first member of the tuple corresponds to the $Gm* keywords, where m is given by position in the list. The second member corresponds to the $RnI and $RnW keywords and is a mapping of regions and windows to be used in gating scheme. Keys in dictionary are the region indices (the n in $RnI and $RnW). The values in the dictionary are either univariate or bivariate gates and must correspond to an index in the list in the first element. The third member corresponds to the $GATING keyword. All ‘Rn’ in this string must reference a key in the dict of the second member. Defaults to([], {}, None).nonstandard_keywords (
dict[str,str]) – (read-write) Pairs of non-standard keyword values. Keys must not start with $. Defaults to{}.analysis (
bytes) – (read-write) Contents of the ANALYSIS segment. Defaults tob"".others (
list[bytes]) – (read-write) A list of byte strings encoding the OTHER segments. Defaults to[].
- Raises:
OverflowError – if
abrtorlostis less than0or greater than2**32-1EventDataError – If
datacontains columns which are not unsigned 8/16/32/64-bit integers or 32/64-bit floatsOverflowError – if field 1 in
tris less than0or greater than2**32-1ParseKeywordValueError – if field 1 in
measurementsis""or contains commasParseKeywordValueError – if field 2 in
tris""or contains commasParseKeyError – if dict key in
nonstandard_keywordsis empty or starts with"$"
- all_detector_types¶
Value of $PnT for all measurements (read-write).
()will be returned for time since $PnT is not defined for temporal measurements.
- all_detector_voltages¶
Value of $PnV for all measurements (read-write).
()will be returned for time since $PnV is not defined for temporal measurements.
- all_filters¶
Value of $PnF for all measurements (read-write).
()will be returned for time since $PnF is not defined for temporal measurements.
- all_meas_nonstandard_keywords¶
The non-standard keywords for each measurement (read-write).
- all_percents_emitted¶
Value of $PnP for all measurements (read-write).
()will be returned for time since $PnP is not defined for temporal measurements.
- all_powers¶
Value of $PnO for all measurements (read-write).
()will be returned for time since $PnO is not defined for temporal measurements.
- all_scales¶
The value for $PnE for all measurements (read-write).
Will be
()for linear scaling (0,0in FCS encoding), a 2-tuple for log scaling, orNoneif missing.The temporal measurement must always be
(). Setting it to another value will raiseRelationalError.
- all_shortnames¶
Value of $PnN for all measurements (read-write).
Strings are unique and cannot contain commas.
- all_shortnames_maybe¶
The possibly-empty values of $PnN for all measurements (read-write).
$PnN is optional for this FCS version so values may be
None.
- all_wavelengths¶
Value of $PnL for all measurements (read-write).
()will be returned for time since $PnL is not defined for temporal measurements.
- classmethod from_kws(path, std, nonstd, data_seg, analysis_seg=(0, 0), other_segs=[], trim_intra_value_whitespace=False, time_meas_pattern='^(TIME|Time)$', allow_missing_time=False, force_time_linear=False, ignore_time_optical_keys=[], date_pattern=None, time_pattern=None, allow_pseudostandard=False, allow_unused_standard=False, disallow_deprecated=False, fix_log_scale_offsets=False, nonstandard_measurement_pattern=None, allow_optional_dropping=False, transfer_dropped_optional=False, integer_widths_from_byteord=False, integer_byteord_override=None, disallow_range_truncation=False, allow_uneven_event_width=False, allow_tot_mismatch=False, warnings_are_errors=False, hide_warnings=False, dataset_offset=0)¶
Make new instance from keywords.
- Parameters:
path (
Path) – Path to be read.analysis_seg (
tuple[int,int]) – The DATA segment from HEADER. Defaults to(0, 0).other_segs (
list[tuple[int,int]]) – The OTHER segments from HEADER. Defaults to[].trim_intra_value_whitespace (
bool) – IfTrue, trim whitespace between delimiters such as,and;within keyword value strings. Defaults toFalse.time_meas_pattern (
str| None) – A pattern to match the $PnN of the time measurement. IfNone, do not try to find a time measurement. Defaults to"^(TIME|Time)$".allow_missing_time (
bool) – IfTrueallow time measurement to be missing. Defaults toFalse.force_time_linear (
bool) – IfTrueforce time measurement to be linear independent of $PnE. Defaults toFalse.ignore_time_optical_keys (
list[Literal[“F”, “L”, “O”, “T”, “P”, “V”, “CALIBRATION”, “DET”, “TAG”, “FEATURE”, “ANALYTE”]]) – Ignore optical keys in temporal measurement. These keys are nonsensical for time measurements but are not explicitly forbidden in the the standard. Provided keys are the string after the “Pn” in the “PnX” keywords. Defaults to[].date_pattern (
str| None) – If supplied, will be used as an alternative pattern when parsing $DATE. If not supplied, $DATE will be parsed according to the standard pattern which is%d-%b-%Y. Defaults toNone.time_pattern (
str| None) – If supplied, will be used as an alternative pattern when parsing $BTIM and $ETIM. The values"%!"or"%@"may be used to match 1/60 seconds or centiseconds respectively. If not supplied, $BTIM and $ETIM will be parsed according to the standard pattern which is"%H:%M:%S". Defaults toNone.allow_pseudostandard (
bool) – IfTrueallow non-standard keywords with a leading $. The presence of such keywords often means the version in HEADER is incorrect. Defaults toFalse.allow_unused_standard (
bool) – IfTrueallow unused standard keywords to be present. Defaults toFalse.disallow_deprecated (
bool) – IfTruethrow error if a deprecated key is encountered. Defaults toFalse.fix_log_scale_offsets (
bool) – IfTruefix log-scale PnE and keywords which have zero offset (ieX,0.0whereXis non-zero). Defaults toFalse.nonstandard_measurement_pattern (
str| None) – Pattern to use when matching nonstandard measurement keys. Must be a regular expression pattern with%nwhich will represent the measurement index and should not start with $. Otherwise should be a normal regular expression as defined in regexp-syntax. Defaults toNone.allow_optional_dropping (
bool) – IfTruedrop optional keys that cause an error and emit warning instead. Defaults toFalse.transfer_dropped_optional (
bool) – IfTruetransfer optional keys to non-standard dict if dropped. Defaults toFalse.integer_widths_from_byteord (
bool) – IfTrueset all $PnB to the number of bytes from $BYTEORD. Only has an effect for FCS 2.0/3.0 where $DATATYPE isI. Defaults toFalse.integer_byteord_override (
list[int] | None) – Override $BYTEORD for integer layouts. Defaults toNone.disallow_range_truncation (
bool) – IfTruethrow error if $PnR values need to be truncated to match the number of bytes specified by $PnB and $DATATYPE. Defaults toFalse.allow_uneven_event_width (
bool) – IfTrueallow event width to not perfectly divide length of DATA. Does not apply to delimited ASCII layouts. Defaults toFalse.allow_tot_mismatch (
bool) – IfTrueallow $TOT to not match number of events as computed by the event width and length of DATA. Does not apply to delimited ASCII layouts. Defaults toFalse.warnings_are_errors (
bool) – IfTrueall warnings will be regarded as errors. Defaults toFalse.hide_warnings (
bool) – IfTruehide all warnings. Defaults toFalse.dataset_offset (
int) – Starting position in the file of the dataset to be read Defaults to0.
- Return type:
- Raises:
ValueError – if
analysis_segordata_seghas offsets which exceed the end of the file, are inverted (begin after end), or are either negative or greater than2**64-1ConfigError – if
nonstandard_measurement_patterndoes not have"%n"ConfigError – if
time_patterndoes not have specifiers for hours, minutes, seconds, and optionally sub-seconds (where"%!"and"%@"correspond to 1/60 seconds and centiseconds respectively) as outlined in chronoConfigError – if
date_patterndoes not have year, month, and day specifiers as outlined in chronoConfigError – if
time_meas_patternis not a valid regular expression as described in regexp-syntaxInvalidKeywordValueError – if
integer_byteord_overrideis not a list of integers including all from 1 toNwhereNis the length of the list (up to 8)ValueError – if any in
other_segshas offsets which exceed the end of the file, are inverted (begin after end), or are either negative or greater than2**64-1ParseKeyError – if dict key in
nonstdis empty or starts with"$"ParseKeyError – if dict key in
stdis empty, does not start with"$", or is only a"$"FCSDeprecatedError – If any keywords or their values are deprecated and
disallow_deprecatedisTrueParseKeywordValueError – If any keyword values could not be read from their string encoding
RelationalError – If keywords are incompatible with indicated layout of DATA or if keywords that are referenced by other keywords do not exist
EventDataError – If values in DATA cannot be read
ExtraKeywordError – If any standard keys are unused and
allow_pseudostandardorallow_unused_standardareFalse
- insert_optical(index, name, meas, col, range, disallow_trunc=False)¶
Insert optical measurement at position in measurement vector.
- Parameters:
index (
int) – Position at which to insert new measurement.name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Optical2_0) – The measurement to insert.col (
polars.Series) – Data for measurement. Must be same length as existing columns.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- insert_temporal(index, name, meas, col, range, disallow_trunc=False)¶
Insert temporal measurement at position in measurement vector.
- Parameters:
index (
int) – Position at which to insert new measurement.name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Temporal2_0) – The measurement to insert.col (
polars.Series) – Data for measurement. Must be same length as existing columns.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- measurement_at(index)¶
Return measurement at index.
- Parameters:
index (
int) – Index to retrieve.- Return type:
- Raises:
IndexError – If
indexnot found
- measurement_named(name)¶
Return measurement with name.
- Parameters:
name (
str) – Name to retrieve. Corresponds to $PnN.- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namenot found
- measurements¶
All measurements (read-write).
- Return type:
- push_optical(name, meas, col, range, disallow_trunc=False)¶
Push optical measurement to end of measurement vector.
- Parameters:
name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Optical2_0) – The measurement to push.col (
polars.Series) – Data for measurement. Must be same length as existing columns.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- push_temporal(name, meas, col, range, disallow_trunc=False)¶
Push temporal measurement to end of measurement vector.
- Parameters:
name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Temporal2_0) – The measurement to push.col (
polars.Series) – Data for measurement. Must be same length as existing columns.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- remove_measurement_by_index(index)¶
Remove a measurement with a given index.
- Parameters:
index (
int) – Index to remove.- Returns:
Name and measurement object.
- Return type:
tuple[str| None,Optical2_0|Temporal2_0,Decimal]- Raises:
IndexError – If
indexnot found
- remove_measurement_by_name(name)¶
Remove a measurement with a given name.
- Parameters:
name (
str) – Name to remove. Corresponds to $PnN.- Returns:
Index and measurement object.
- Return type:
tuple[int,Optical2_0|Temporal2_0,Decimal]- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namenot found
- rename_temporal(name)¶
Rename temporal measurement if present.
- Parameters:
name (
str) – New name to assign. Corresponds to $PnN.- Returns:
Previous name if present.
- Return type:
str| None- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- replace_optical_at(index, meas)¶
Replace measurement at index with given optical measurement.
- Parameters:
index (
int) – Index to replace.meas (
Optical2_0) – Optical measurement to replace measurement atindex.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
IndexError – If
indexdoes not exist.
- replace_optical_named(name, meas)¶
Replace named measurement with given optical measurement.
- Parameters:
name (
str) – Name to replace. Corresponds to $PnN.meas (
Optical2_0) – Optical measurement to replace measurement atname.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namedoes not exist.
- replace_temporal_at(index, meas)¶
Replace measurement at index with given temporal measurement.
- Parameters:
index (
int) – Index to replace.meas (
Temporal2_0) – Temporal measurement to replace measurement atindex.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
IndexError – If
indexdoes not existRelationalError – If a temporal measurement already exists at a different position
- replace_temporal_named(name, meas)¶
Replace named measurement with given temporal measurement.
- Parameters:
name (
str) – Name to replace. Corresponds to $PnN.meas (
Temporal2_0) – Temporal measurement to replace measurement atname.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namedoes not existRelationalError – If a temporal measurement already exists at a different position
- set_measurements_and_data(measurements, data)¶
Set measurements and data at once.
Length of
measurementsmust match number of columns indata.- Parameters:
measurements (
list[Optical2_0|Temporal2_0]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.data (
polars.DataFrame) – The new data.
- set_measurements_and_layout(measurements, layout)¶
Set all measurements and layout at once.
Length of
measurementsmust match number of columns inlayoutand both must match number of columns in existing dataframe.- Parameters:
measurements (
list[Optical2_0|Temporal2_0]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.layout (
FixedAsciiLayout|DelimAsciiLayout|OrderedUint08Layout|OrderedUint16Layout|OrderedUint24Layout|OrderedUint32Layout|OrderedUint40Layout|OrderedUint48Layout|OrderedUint56Layout|OrderedUint64Layout|OrderedF32Layout|OrderedF64Layout) – The new layout.
- set_measurements_layout_and_data(measurements, layout, data)¶
Set measurements, layout, and data at once.
Length of
measurementsandlayoutmust match number of columns indata.- Parameters:
measurements (
list[Optical2_0|Temporal2_0]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.layout (
FixedAsciiLayout|DelimAsciiLayout|OrderedUint08Layout|OrderedUint16Layout|OrderedUint24Layout|OrderedUint32Layout|OrderedUint40Layout|OrderedUint48Layout|OrderedUint56Layout|OrderedUint64Layout|OrderedF32Layout|OrderedF64Layout) – The new layout.data (
polars.DataFrame) – The new data.
- set_named_measurements(measurements, allow_shared_names=False, skip_index_check=False)¶
Set all measurements at once.
Length of
measurementsmust match number of columns in existing layout and dataframe.- Parameters:
measurements (
tuple[str| None,Optical2_0|Temporal2_0]) – The new measurements. The first member of the tuple corresponds to the measurement name and the second is the measurement object.allow_shared_names (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keywords reference any $PnN keywords. IfTrueraiseRelationalErrorif any non-measurement keywords reference a $PnN which is not present inmeasurements. In other words,Falseforbids named references to exist, andTrueallows named references to be updated. References cannot be broken in either case. Defaults toFalse.skip_index_check (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keyword have an index reference to the current measurements. IfTrueallow such references to exist as long as they do not break (which really means that the length ofmeasurementsis such that existing indices are satisfied). Defaults toFalse.
- Raises:
ParseKeywordValueError – if field 1 in
measurementsis""or contains commas
- set_named_measurements_and_data(measurements, data, allow_shared_names=False, skip_index_check=False)¶
Set measurements, names, and data at once.
Length of
measurementsmust match number of columns indata.- Parameters:
measurements (
tuple[str| None,Optical2_0|Temporal2_0]) – The new measurements. The first member of the tuple corresponds to the measurement name and the second is the measurement object.data (
polars.DataFrame) – The new data.allow_shared_names (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keywords reference any $PnN keywords. IfTrueraiseRelationalErrorif any non-measurement keywords reference a $PnN which is not present inmeasurements. In other words,Falseforbids named references to exist, andTrueallows named references to be updated. References cannot be broken in either case. Defaults toFalse.skip_index_check (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keyword have an index reference to the current measurements. IfTrueallow such references to exist as long as they do not break (which really means that the length ofmeasurementsis such that existing indices are satisfied). Defaults toFalse.
- Raises:
ParseKeywordValueError – if field 1 in
measurementsis""or contains commas
- set_named_measurements_and_layout(measurements, layout, allow_shared_names=False, skip_index_check=False)¶
Set all measurements, names, and layout at once.
Length of
measurementsmust match number of columns inlayoutand both must match number of columns in existing dataframe.- Parameters:
measurements (
tuple[str| None,Optical2_0|Temporal2_0]) – The new measurements. The first member of the tuple corresponds to the measurement name and the second is the measurement object.layout (
FixedAsciiLayout|DelimAsciiLayout|OrderedUint08Layout|OrderedUint16Layout|OrderedUint24Layout|OrderedUint32Layout|OrderedUint40Layout|OrderedUint48Layout|OrderedUint56Layout|OrderedUint64Layout|OrderedF32Layout|OrderedF64Layout) – The new layout.allow_shared_names (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keywords reference any $PnN keywords. IfTrueraiseRelationalErrorif any non-measurement keywords reference a $PnN which is not present inmeasurements. In other words,Falseforbids named references to exist, andTrueallows named references to be updated. References cannot be broken in either case. Defaults toFalse.skip_index_check (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keyword have an index reference to the current measurements. IfTrueallow such references to exist as long as they do not break (which really means that the length ofmeasurementsis such that existing indices are satisfied). Defaults toFalse.
- Raises:
ParseKeywordValueError – if field 1 in
measurementsis""or contains commas
- set_temporal(name, allow_loss=False)¶
Set the temporal measurement to a given name.
- Parameters:
name (
str) – Name to set to temporal. Corresponds to $PnN.allow_loss (
bool) – IfTrueremove any optical-specific metadata (detectors, lasers, etc) without raising anConversionErrorif an optical measurement must be converted. Defaults toFalse.
- Returns:
Trueif temporal measurement was set, which will happen for all cases except when the time measurement is already set toname.- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- set_temporal_at(index, allow_loss=False)¶
Set the temporal measurement to a given index.
- Parameters:
index (
int) – Index to set.allow_loss (
bool) – IfTrueremove any optical-specific metadata (detectors, lasers, etc) without raising anConversionErrorif an optical measurement must be converted. Defaults toFalse.
- Returns:
Trueif temporal measurement was set, which will happen for all cases except when the time measurement is already set toindex.- Return type:
- set_trigger_threshold(threshold)¶
Set the threshold for $TR.
- standard_keywords(req_or_opt, root_or_meas)¶
Return standard keywords as string pairs.
Each key will be prefixed with $.
This will not include $TOT, $NEXTDATA, or any of the offset keywords since these only matter if the dataset is written.
- Parameters:
- Returns:
A list of standard keywords.
- Return type:
- temporal¶
The temporal measurement if it exists (read-only).
- Returns:
Index, name, and measurement or
None.- Return type:
tuple[int,str,Temporal2_0] | None
- to_version_3_0(allow_loss=False)¶
Convert to FCS 3.0.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 3.0.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 3.0 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 3.0
- to_version_3_1(allow_loss=False)¶
Convert to FCS 3.1.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 3.1.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 3.1 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 3.1
- to_version_3_2(allow_loss=False)¶
Convert to FCS 3.2.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 3.2.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 3.2 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 3.2
- truncate_data(skip_conv_check=False)¶
Coerce all values in DATA to fit within types specified in layout.
This will always create a new copy of DATA in-place.
- Parameters:
skip_conv_check (
bool) – IfTrue, silently truncate data; otherwise return warnings when truncation is performed. Defaults toFalse.- Return type:
tuple[()]- Raises:
DataLossError – If any values in DATA segment need to be truncated to fit layout and
skip_conversion_checkisFalse
- unset_data()¶
Remove all measurements and their data.
- Return type:
tuple[()]- Raises:
RelationalError – If keywords are set which refer to measurements and would be invalidated if measurements were removed
- unset_temporal()¶
Convert the temporal measurement to an optical measurement.
- Returns:
Trueif temporal measurement was present and converted,Falseif there was not a temporal measurement.- Return type:
- version¶
Show the FCS version (read-only).
- Return type:
Literal[“FCS2.0”, “FCS3.0”, “FCS3.1”, “FCS3.2”]
- write_dataset(path, delim=30, big_other=False, skip_conversion_check=False, appendable=False, append=False)¶
Write data as an FCS file.
The resulting file will include HEADER, TEXT, DATA, ANALYSIS, and OTHER as they present from this class.
- Parameters:
path (
Path) – Path to be written.delim (
int) – Delimiter to use when writing TEXT. Defaults to30.big_other (
bool) – IfTrueuse 20 chars for OTHER segment offsets, and 8 otherwise. Defaults toFalse.skip_conversion_check (
bool) – Skip check to ensure that types of the dataframe match the columns ($PnB, $DATATYPE, etc). If this isFalse, perform this check before writing, and raiseDataLossErroron failure. IfTrue, raise warnings as file is being written. Skipping this is faster since the data needs to be traversed twice to perform the conversion check, but may result in loss of precision and/or truncation. Defaults toFalse.appendable (
bool) – IfTrue, set $NEXTDATA in written dataset so it points to the next dataset. This obviously assumes the next dataset is actually written, which will require another call to this method withappendset toTrue. Defaults toFalse.append (
bool) – IfTrue, append this dataset to the end of the file if it exists and already has at least one dataset in it. This assumes that the previous dataset was written withappendableset toTrueso that $NEXTDATA is properly set. Defaults toFalse.
- Returns:
the value of $NEXTDATA which would point to next dataset if written
- Return type:
- Raises:
ConfigError – if
delimis not between 1 and 126OverflowError – If TEXT, DATA, or ANALYSIS offsets are greater than 99,999,999
OverflowError – If any OTHER offsets are greater than 99,999,999 and
big_otherisFalse
- classmethod write_datasets(path, datasets, delim=30, big_other=False, skip_conversion_check=False)¶
Write multiple datasets to path.
The resulting file will include HEADER, TEXT, DATA, ANALYSIS, and OTHER as they present from this class.
- Parameters:
path (
Path) – Path to be written.datasets (
list[CoreDataset2_0]) – datasets to writedelim (
int) – Delimiter to use when writing TEXT. Defaults to30.big_other (
bool) – IfTrueuse 20 chars for OTHER segment offsets, and 8 otherwise. Defaults toFalse.skip_conversion_check (
bool) – Skip check to ensure that types of the dataframe match the columns ($PnB, $DATATYPE, etc). If this isFalse, perform this check before writing, and raiseDataLossErroron failure. IfTrue, raise warnings as file is being written. Skipping this is faster since the data needs to be traversed twice to perform the conversion check, but may result in loss of precision and/or truncation. Defaults toFalse.
- Returns:
the value of $NEXTDATA as written in the last dataset if written
- Return type:
int| None- Raises:
ConfigError – if
delimis not between 1 and 126OverflowError – If TEXT, DATA, or ANALYSIS offsets are greater than 99,999,999
OverflowError – If any OTHER offsets are greater than 99,999,999 and
big_otherisFalse
- write_text(path, delim=30, big_other=False, appendable=False, append=False)¶
Write data to path.
Resulting FCS file will include HEADER and TEXT.
- Parameters:
path (
Path) – Path to be written.delim (
int) – Delimiter to use when writing TEXT. Defaults to30.big_other (
bool) – IfTrueuse 20 chars for OTHER segment offsets, and 8 otherwise. Defaults toFalse.appendable (
bool) – IfTrue, set $NEXTDATA in written dataset so it points to the next dataset. This obviously assumes the next dataset is actually written, which will require another call to this method withappendset toTrue. Defaults toFalse.append (
bool) – IfTrue, append this dataset to the end of the file if it exists and already has at least one dataset in it. This assumes that the previous dataset was written withappendableset toTrueso that $NEXTDATA is properly set. Defaults toFalse.
- Returns:
the value of $NEXTDATA as written to the dataset
- Return type:
- Raises:
ConfigError – if
delimis not between 1 and 126OverflowError – If TEXT, DATA, or ANALYSIS offsets are greater than 99,999,999
OverflowError – If any OTHER offsets are greater than 99,999,999 and
big_otherisFalse
- class pyreflow.CoreDataset3_0(measurements, layout, data, mode='L', cyt='', comp=None, btim=None, etim=None, date=None, cytsn='', unicode=None, csvbits=0, cstot=0, csvflags=[], abrt=None, com='', cells='', exp='', fil='', inst='', lost=None, op='', proj='', smno='', src='', sys='', tr=None, applied_gates=([], {}, None), nonstandard_keywords={}, analysis=b'', others=[])¶
Represents one dataset in an FCS 3.0 file.
- Parameters:
measurements (
tuple[str| None,Optical3_0|Temporal3_0]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.- Variables:
layout (
FixedAsciiLayout|DelimAsciiLayout|OrderedUint08Layout|OrderedUint16Layout|OrderedUint24Layout|OrderedUint32Layout|OrderedUint40Layout|OrderedUint48Layout|OrderedUint56Layout|OrderedUint64Layout|OrderedF32Layout|OrderedF64Layout) – (read-write) Layout to describe data encoding. Represents $PnB, $PnR, $BYTEORD, and $DATATYPE.data (
polars.DataFrame) – (read-write) A dataframe encoding the contents of DATA. Number of columns must match number of measurements. May be empty. Types do not necessarily need to correspond to those in the data layout but mismatches may result in truncation.mode (
Literal[“L”, “U”, “C”]) – (read-write) Value of $MODE. Defaults to"L".cyt (
str) – (read-write) Value of $CYT. Defaults to"".comp (
ndarray| None) – (read-write) The value of $COMP. Must be a square array with number of rows/columns equal to the number of measurements. Defaults toNone.btim (
time| None) – (read-write) Value of $BTIM. Defaults toNone.etim (
time| None) – (read-write) Value of $ETIM. Defaults toNone.date (
date| None) – (read-write) Value of $DATE. Defaults toNone.cytsn (
str) – (read-write) Value of $CYTSN. Defaults to"".unicode (
tuple[int,list[str]] | None) – (read-write) Value of $UNICODE. Defaults toNone.csvbits (
int) – (read-write) Value of $CSVBITS. Defaults to0.cstot (
int) – (read-write) Value of $CSTOT. Defaults to0.csvflags (
list[int| None]) – (read-write) Subset flags. Each element in the list corresponds to $CSVnFLAG and the length of the list corresponds to $CSMODE. Defaults to[].abrt (
int| None) – (read-write) Value of $ABRT. Defaults toNone.com (
str) – (read-write) Value of $COM. Defaults to"".cells (
str) – (read-write) Value of $CELLS. Defaults to"".exp (
str) – (read-write) Value of $EXP. Defaults to"".fil (
str) – (read-write) Value of $FIL. Defaults to"".inst (
str) – (read-write) Value of $INST. Defaults to"".lost (
int| None) – (read-write) Value of $LOST. Defaults toNone.op (
str) – (read-write) Value of $OP. Defaults to"".proj (
str) – (read-write) Value of $PROJ. Defaults to"".smno (
str) – (read-write) Value of $SMNO. Defaults to"".src (
str) – (read-write) Value of $SRC. Defaults to"".sys (
str) – (read-write) Value of $SYS. Defaults to"".tr (
tuple[int,str] | None) – (read-write) Value for $TR. First member of tuple is threshold and second is the measurement name which must match a $PnN. Defaults toNone.applied_gates (
tuple[list[GatedMeasurement],dict[int,UnivariateRegion3_0|BivariateRegion3_0],str| None]) – (read-write) Value for $Gm/$RnI/$RnW/$GATING/$GATE* keywords. The first member of the tuple corresponds to the $Gm* keywords, where m is given by position in the list. The second member corresponds to the $RnI and $RnW keywords and is a mapping of regions and windows to be used in gating scheme. Keys in dictionary are the region indices (the n in $RnI and $RnW). The values in the dictionary are either univariate or bivariate gates and must correspond to an index in the list in the first element or a physical measurement. The third member corresponds to the $GATING keyword. All ‘Rn’ in this string must reference a key in the dict of the second member. Defaults to([], {}, None).nonstandard_keywords (
dict[str,str]) – (read-write) Pairs of non-standard keyword values. Keys must not start with $. Defaults to{}.analysis (
bytes) – (read-write) Contents of the ANALYSIS segment. Defaults tob"".others (
list[bytes]) – (read-write) A list of byte strings encoding the OTHER segments. Defaults to[].
- Raises:
OverflowError – if
abrt,cstot,csvbits, orlostis less than0or greater than2**32-1EventDataError – If
datacontains columns which are not unsigned 8/16/32/64-bit integers or 32/64-bit floatsOverflowError – if field 1 in
tris less than0or greater than2**32-1ParseKeywordValueError – if field 1 in
measurementsis""or contains commasParseKeywordValueError – if field 2 in
tris""or contains commasOverflowError – if any in
csvflagsis less than0or greater than2**32-1ParseKeyError – if dict key in
nonstandard_keywordsis empty or starts with"$"
- all_detector_types¶
Value of $PnT for all measurements (read-write).
()will be returned for time since $PnT is not defined for temporal measurements.
- all_detector_voltages¶
Value of $PnV for all measurements (read-write).
()will be returned for time since $PnV is not defined for temporal measurements.
- all_filters¶
Value of $PnF for all measurements (read-write).
()will be returned for time since $PnF is not defined for temporal measurements.
- all_meas_nonstandard_keywords¶
The non-standard keywords for each measurement (read-write).
- all_percents_emitted¶
Value of $PnP for all measurements (read-write).
()will be returned for time since $PnP is not defined for temporal measurements.
- all_powers¶
Value of $PnO for all measurements (read-write).
()will be returned for time since $PnO is not defined for temporal measurements.
- all_scale_transforms¶
The value for $PnE and/or $PnG for all measurements (read-write).
Collectively these keywords correspond to scale transforms.
If scaling is linear, return a float which corresponds to the value of $PnG when $PnE is
0,0. If scaling is logarithmic, return a pair of floats, corresponding to unset $PnG and the non-0,0value of $PnE.The FCS standards disallow any other combinations.
The temporal measurement will always be
1.0, corresponding to an identity transform. Setting it to another value will raiseRelationalError.
- all_shortnames¶
Value of $PnN for all measurements (read-write).
Strings are unique and cannot contain commas.
- all_shortnames_maybe¶
The possibly-empty values of $PnN for all measurements (read-write).
$PnN is optional for this FCS version so values may be
None.
- all_wavelengths¶
Value of $PnL for all measurements (read-write).
()will be returned for time since $PnL is not defined for temporal measurements.
- classmethod from_kws(path, std, nonstd, data_seg, analysis_seg=(0, 0), other_segs=[], trim_intra_value_whitespace=False, time_meas_pattern='^(TIME|Time)$', allow_missing_time=False, force_time_linear=False, ignore_time_optical_keys=[], date_pattern=None, time_pattern=None, allow_pseudostandard=False, allow_unused_standard=False, disallow_deprecated=False, fix_log_scale_offsets=False, nonstandard_measurement_pattern=None, ignore_time_gain=False, allow_optional_dropping=False, transfer_dropped_optional=False, integer_widths_from_byteord=False, integer_byteord_override=None, disallow_range_truncation=False, text_data_correction=(0, 0), text_analysis_correction=(0, 0), ignore_text_data_offsets=False, ignore_text_analysis_offsets=False, allow_header_text_offset_mismatch=False, allow_missing_required_offsets=False, truncate_text_offsets=False, allow_uneven_event_width=False, allow_tot_mismatch=False, warnings_are_errors=False, hide_warnings=False, dataset_offset=0)¶
Make new instance from keywords.
- Parameters:
path (
Path) – Path to be read.analysis_seg (
tuple[int,int]) – The DATA segment from HEADER. Defaults to(0, 0).other_segs (
list[tuple[int,int]]) – The OTHER segments from HEADER. Defaults to[].trim_intra_value_whitespace (
bool) – IfTrue, trim whitespace between delimiters such as,and;within keyword value strings. Defaults toFalse.time_meas_pattern (
str| None) – A pattern to match the $PnN of the time measurement. IfNone, do not try to find a time measurement. Defaults to"^(TIME|Time)$".allow_missing_time (
bool) – IfTrueallow time measurement to be missing. Defaults toFalse.force_time_linear (
bool) – IfTrueforce time measurement to be linear independent of $PnE. Defaults toFalse.ignore_time_optical_keys (
list[Literal[“F”, “L”, “O”, “T”, “P”, “V”, “CALIBRATION”, “DET”, “TAG”, “FEATURE”, “ANALYTE”]]) – Ignore optical keys in temporal measurement. These keys are nonsensical for time measurements but are not explicitly forbidden in the the standard. Provided keys are the string after the “Pn” in the “PnX” keywords. Defaults to[].date_pattern (
str| None) – If supplied, will be used as an alternative pattern when parsing $DATE. If not supplied, $DATE will be parsed according to the standard pattern which is%d-%b-%Y. Defaults toNone.time_pattern (
str| None) – If supplied, will be used as an alternative pattern when parsing $BTIM and $ETIM. The values"%!"or"%@"may be used to match 1/60 seconds or centiseconds respectively. If not supplied, $BTIM and $ETIM will be parsed according to the standard pattern which is"%H:%M:%S:%!". Defaults toNone.allow_pseudostandard (
bool) – IfTrueallow non-standard keywords with a leading $. The presence of such keywords often means the version in HEADER is incorrect. Defaults toFalse.allow_unused_standard (
bool) – IfTrueallow unused standard keywords to be present. Defaults toFalse.disallow_deprecated (
bool) – IfTruethrow error if a deprecated key is encountered. Defaults toFalse.fix_log_scale_offsets (
bool) – IfTruefix log-scale PnE and keywords which have zero offset (ieX,0.0whereXis non-zero). Defaults toFalse.nonstandard_measurement_pattern (
str| None) – Pattern to use when matching nonstandard measurement keys. Must be a regular expression pattern with%nwhich will represent the measurement index and should not start with $. Otherwise should be a normal regular expression as defined in regexp-syntax. Defaults toNone.ignore_time_gain (
bool) – IfTrueignore the $PnG (gain) keyword. This keyword should not be set according to the standard} however, this library will allow gain to be 1.0 since this equates to identity. If gain is not 1.0, this is nonsense and it can be ignored with this flag. Defaults toFalse.allow_optional_dropping (
bool) – IfTruedrop optional keys that cause an error and emit warning instead. Defaults toFalse.transfer_dropped_optional (
bool) – IfTruetransfer optional keys to non-standard dict if dropped. Defaults toFalse.integer_widths_from_byteord (
bool) – IfTrueset all $PnB to the number of bytes from $BYTEORD. Only has an effect for FCS 2.0/3.0 where $DATATYPE isI. Defaults toFalse.integer_byteord_override (
list[int] | None) – Override $BYTEORD for integer layouts. Defaults toNone.disallow_range_truncation (
bool) – IfTruethrow error if $PnR values need to be truncated to match the number of bytes specified by $PnB and $DATATYPE. Defaults toFalse.text_data_correction (
tuple[int,int]) – Corrections for DATA offsets in TEXT. Defaults to(0, 0).text_analysis_correction (
tuple[int,int]) – Corrections for ANALYSIS offsets in TEXT. Defaults to(0, 0).ignore_text_data_offsets (
bool) – IfTrueignore DATA offsets in TEXT Defaults toFalse.ignore_text_analysis_offsets (
bool) – IfTrueignore ANALYSIS offsets in TEXT Defaults toFalse.allow_header_text_offset_mismatch (
bool) – IfTrueallow TEXT and HEADER offsets to mismatch. Defaults toFalse.allow_missing_required_offsets (
bool) – IfTrueallow required DATA and ANALYSIS offsets in TEXT to be missing. If missing, fall back to offsets from HEADER. Defaults toFalse.truncate_text_offsets (
bool) – IfTruetruncate offsets that exceed end of file. Defaults toFalse.allow_uneven_event_width (
bool) – IfTrueallow event width to not perfectly divide length of DATA. Does not apply to delimited ASCII layouts. Defaults toFalse.allow_tot_mismatch (
bool) – IfTrueallow $TOT to not match number of events as computed by the event width and length of DATA. Does not apply to delimited ASCII layouts. Defaults toFalse.warnings_are_errors (
bool) – IfTrueall warnings will be regarded as errors. Defaults toFalse.hide_warnings (
bool) – IfTruehide all warnings. Defaults toFalse.dataset_offset (
int) – Starting position in the file of the dataset to be read Defaults to0.
- Return type:
- Raises:
ValueError – if
analysis_segordata_seghas offsets which exceed the end of the file, are inverted (begin after end), or are either negative or greater than2**64-1ConfigError – if
nonstandard_measurement_patterndoes not have"%n"ConfigError – if
time_patterndoes not have specifiers for hours, minutes, seconds, and optionally sub-seconds (where"%!"and"%@"correspond to 1/60 seconds and centiseconds respectively) as outlined in chronoConfigError – if
date_patterndoes not have year, month, and day specifiers as outlined in chronoConfigError – if
time_meas_patternis not a valid regular expression as described in regexp-syntaxInvalidKeywordValueError – if
integer_byteord_overrideis not a list of integers including all from 1 toNwhereNis the length of the list (up to 8)OverflowError – if field 1 or 2 in
text_analysis_correctionortext_data_correctionis less than-2**31or greater than2**31-1ValueError – if any in
other_segshas offsets which exceed the end of the file, are inverted (begin after end), or are either negative or greater than2**64-1ParseKeyError – if dict key in
nonstdis empty or starts with"$"ParseKeyError – if dict key in
stdis empty, does not start with"$", or is only a"$"FCSDeprecatedError – If any keywords or their values are deprecated and
disallow_deprecatedisTrueParseKeywordValueError – If any keyword values could not be read from their string encoding
RelationalError – If keywords are incompatible with indicated layout of DATA or if keywords that are referenced by other keywords do not exist
EventDataError – If values in DATA cannot be read
ExtraKeywordError – If any standard keys are unused and
allow_pseudostandardorallow_unused_standardareFalse
- insert_optical(index, name, meas, col, range, disallow_trunc=False)¶
Insert optical measurement at position in measurement vector.
- Parameters:
index (
int) – Position at which to insert new measurement.name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Optical3_0) – The measurement to insert.col (
polars.Series) – Data for measurement. Must be same length as existing columns.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- insert_temporal(index, name, meas, col, range, disallow_trunc=False)¶
Insert temporal measurement at position in measurement vector.
- Parameters:
index (
int) – Position at which to insert new measurement.name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Temporal3_0) – The measurement to insert.col (
polars.Series) – Data for measurement. Must be same length as existing columns.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- measurement_at(index)¶
Return measurement at index.
- Parameters:
index (
int) – Index to retrieve.- Return type:
- Raises:
IndexError – If
indexnot found
- measurement_named(name)¶
Return measurement with name.
- Parameters:
name (
str) – Name to retrieve. Corresponds to $PnN.- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namenot found
- measurements¶
All measurements (read-write).
- Return type:
- push_optical(name, meas, col, range, disallow_trunc=False)¶
Push optical measurement to end of measurement vector.
- Parameters:
name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Optical3_0) – The measurement to push.col (
polars.Series) – Data for measurement. Must be same length as existing columns.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- push_temporal(name, meas, col, range, disallow_trunc=False)¶
Push temporal measurement to end of measurement vector.
- Parameters:
name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Temporal3_0) – The measurement to push.col (
polars.Series) – Data for measurement. Must be same length as existing columns.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- remove_measurement_by_index(index)¶
Remove a measurement with a given index.
- Parameters:
index (
int) – Index to remove.- Returns:
Name and measurement object.
- Return type:
tuple[str| None,Optical3_0|Temporal3_0,Decimal]- Raises:
IndexError – If
indexnot found
- remove_measurement_by_name(name)¶
Remove a measurement with a given name.
- Parameters:
name (
str) – Name to remove. Corresponds to $PnN.- Returns:
Index and measurement object.
- Return type:
tuple[int,Optical3_0|Temporal3_0,Decimal]- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namenot found
- rename_temporal(name)¶
Rename temporal measurement if present.
- Parameters:
name (
str) – New name to assign. Corresponds to $PnN.- Returns:
Previous name if present.
- Return type:
str| None- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- replace_optical_at(index, meas)¶
Replace measurement at index with given optical measurement.
- Parameters:
index (
int) – Index to replace.meas (
Optical3_0) – Optical measurement to replace measurement atindex.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
IndexError – If
indexdoes not exist.
- replace_optical_named(name, meas)¶
Replace named measurement with given optical measurement.
- Parameters:
name (
str) – Name to replace. Corresponds to $PnN.meas (
Optical3_0) – Optical measurement to replace measurement atname.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namedoes not exist.
- replace_temporal_at(index, meas)¶
Replace measurement at index with given temporal measurement.
- Parameters:
index (
int) – Index to replace.meas (
Temporal3_0) – Temporal measurement to replace measurement atindex.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
IndexError – If
indexdoes not existRelationalError – If a temporal measurement already exists at a different position
- replace_temporal_named(name, meas)¶
Replace named measurement with given temporal measurement.
- Parameters:
name (
str) – Name to replace. Corresponds to $PnN.meas (
Temporal3_0) – Temporal measurement to replace measurement atname.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namedoes not existRelationalError – If a temporal measurement already exists at a different position
- set_measurements_and_data(measurements, data)¶
Set measurements and data at once.
Length of
measurementsmust match number of columns indata.- Parameters:
measurements (
list[Optical3_0|Temporal3_0]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.data (
polars.DataFrame) – The new data.
- set_measurements_and_layout(measurements, layout)¶
Set all measurements and layout at once.
Length of
measurementsmust match number of columns inlayoutand both must match number of columns in existing dataframe.- Parameters:
measurements (
list[Optical3_0|Temporal3_0]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.layout (
FixedAsciiLayout|DelimAsciiLayout|OrderedUint08Layout|OrderedUint16Layout|OrderedUint24Layout|OrderedUint32Layout|OrderedUint40Layout|OrderedUint48Layout|OrderedUint56Layout|OrderedUint64Layout|OrderedF32Layout|OrderedF64Layout) – The new layout.
- set_measurements_layout_and_data(measurements, layout, data)¶
Set measurements, layout, and data at once.
Length of
measurementsandlayoutmust match number of columns indata.- Parameters:
measurements (
list[Optical3_0|Temporal3_0]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.layout (
FixedAsciiLayout|DelimAsciiLayout|OrderedUint08Layout|OrderedUint16Layout|OrderedUint24Layout|OrderedUint32Layout|OrderedUint40Layout|OrderedUint48Layout|OrderedUint56Layout|OrderedUint64Layout|OrderedF32Layout|OrderedF64Layout) – The new layout.data (
polars.DataFrame) – The new data.
- set_named_measurements(measurements, allow_shared_names=False, skip_index_check=False)¶
Set all measurements at once.
Length of
measurementsmust match number of columns in existing layout and dataframe.- Parameters:
measurements (
tuple[str| None,Optical3_0|Temporal3_0]) – The new measurements. The first member of the tuple corresponds to the measurement name and the second is the measurement object.allow_shared_names (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keywords reference any $PnN keywords. IfTrueraiseRelationalErrorif any non-measurement keywords reference a $PnN which is not present inmeasurements. In other words,Falseforbids named references to exist, andTrueallows named references to be updated. References cannot be broken in either case. Defaults toFalse.skip_index_check (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keyword have an index reference to the current measurements. IfTrueallow such references to exist as long as they do not break (which really means that the length ofmeasurementsis such that existing indices are satisfied). Defaults toFalse.
- Raises:
ParseKeywordValueError – if field 1 in
measurementsis""or contains commas
- set_named_measurements_and_data(measurements, data, allow_shared_names=False, skip_index_check=False)¶
Set measurements, names, and data at once.
Length of
measurementsmust match number of columns indata.- Parameters:
measurements (
tuple[str| None,Optical3_0|Temporal3_0]) – The new measurements. The first member of the tuple corresponds to the measurement name and the second is the measurement object.data (
polars.DataFrame) – The new data.allow_shared_names (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keywords reference any $PnN keywords. IfTrueraiseRelationalErrorif any non-measurement keywords reference a $PnN which is not present inmeasurements. In other words,Falseforbids named references to exist, andTrueallows named references to be updated. References cannot be broken in either case. Defaults toFalse.skip_index_check (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keyword have an index reference to the current measurements. IfTrueallow such references to exist as long as they do not break (which really means that the length ofmeasurementsis such that existing indices are satisfied). Defaults toFalse.
- Raises:
ParseKeywordValueError – if field 1 in
measurementsis""or contains commas
- set_named_measurements_and_layout(measurements, layout, allow_shared_names=False, skip_index_check=False)¶
Set all measurements, names, and layout at once.
Length of
measurementsmust match number of columns inlayoutand both must match number of columns in existing dataframe.- Parameters:
measurements (
tuple[str| None,Optical3_0|Temporal3_0]) – The new measurements. The first member of the tuple corresponds to the measurement name and the second is the measurement object.layout (
FixedAsciiLayout|DelimAsciiLayout|OrderedUint08Layout|OrderedUint16Layout|OrderedUint24Layout|OrderedUint32Layout|OrderedUint40Layout|OrderedUint48Layout|OrderedUint56Layout|OrderedUint64Layout|OrderedF32Layout|OrderedF64Layout) – The new layout.allow_shared_names (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keywords reference any $PnN keywords. IfTrueraiseRelationalErrorif any non-measurement keywords reference a $PnN which is not present inmeasurements. In other words,Falseforbids named references to exist, andTrueallows named references to be updated. References cannot be broken in either case. Defaults toFalse.skip_index_check (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keyword have an index reference to the current measurements. IfTrueallow such references to exist as long as they do not break (which really means that the length ofmeasurementsis such that existing indices are satisfied). Defaults toFalse.
- Raises:
ParseKeywordValueError – if field 1 in
measurementsis""or contains commas
- set_temporal(name, timestep, allow_loss=False)¶
Set the temporal measurement to a given name.
- Parameters:
name (
str) – Name to set to temporal. Corresponds to $PnN.timestep (
float) – The value of $TIMESTEP to use.allow_loss (
bool) – IfTrueremove any optical-specific metadata (detectors, lasers, etc) without raising anConversionErrorif an optical measurement must be converted. Defaults toFalse.
- Returns:
Trueif temporal measurement was set, which will happen for all cases except when the time measurement is already set toname.- Return type:
- Raises:
InvalidKeywordValueError – if
timestepis negative,0.0,NaN,inf, or-infParseKeywordValueError – if
nameis""or contains commas
- set_temporal_at(index, timestep, allow_loss=False)¶
Set the temporal measurement to a given index.
- Parameters:
index (
int) – Index to set.timestep (
float) – The value of $TIMESTEP to use.allow_loss (
bool) – IfTrueremove any optical-specific metadata (detectors, lasers, etc) without raising anConversionErrorif an optical measurement must be converted. Defaults toFalse.
- Returns:
Trueif temporal measurement was set, which will happen for all cases except when the time measurement is already set toindex.- Return type:
- Raises:
InvalidKeywordValueError – if
timestepis negative,0.0,NaN,inf, or-inf
- set_timestep(timestep)¶
Set the $TIMESTEP if time measurement is present.
- Parameters:
timestep (
float) – The timestep to set. Must be greater than zero.- Returns:
Previous $TIMESTEP if present.
- Return type:
float| None- Raises:
InvalidKeywordValueError – if
timestepis negative,0.0,NaN,inf, or-inf
- set_trigger_threshold(threshold)¶
Set the threshold for $TR.
- standard_keywords(req_or_opt, root_or_meas)¶
Return standard keywords as string pairs.
Each key will be prefixed with $.
This will not include $TOT, $NEXTDATA, or any of the offset keywords since these only matter if the dataset is written.
- Parameters:
- Returns:
A list of standard keywords.
- Return type:
- temporal¶
The temporal measurement if it exists (read-only).
- Returns:
Index, name, and measurement or
None.- Return type:
tuple[int,str,Temporal3_0] | None
- to_version_2_0(allow_loss=False)¶
Convert to FCS 2.0.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 2.0.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 2.0 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 2.0
- to_version_3_1(allow_loss=False)¶
Convert to FCS 3.1.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 3.1.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 3.1 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 3.1
- to_version_3_2(allow_loss=False)¶
Convert to FCS 3.2.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 3.2.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 3.2 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 3.2
- truncate_data(skip_conv_check=False)¶
Coerce all values in DATA to fit within types specified in layout.
This will always create a new copy of DATA in-place.
- Parameters:
skip_conv_check (
bool) – IfTrue, silently truncate data; otherwise return warnings when truncation is performed. Defaults toFalse.- Return type:
tuple[()]- Raises:
DataLossError – If any values in DATA segment need to be truncated to fit layout and
skip_conversion_checkisFalse
- unset_data()¶
Remove all measurements and their data.
- Return type:
tuple[()]- Raises:
RelationalError – If keywords are set which refer to measurements and would be invalidated if measurements were removed
- unset_temporal()¶
Convert the temporal measurement to an optical measurement.
- Returns:
Value of $TIMESTEP if time measurement was present.
- Return type:
float| None
- version¶
Show the FCS version (read-only).
- Return type:
Literal[“FCS2.0”, “FCS3.0”, “FCS3.1”, “FCS3.2”]
- write_dataset(path, delim=30, big_other=False, skip_conversion_check=False, appendable=False, append=False)¶
Write data as an FCS file.
The resulting file will include HEADER, TEXT, DATA, ANALYSIS, and OTHER as they present from this class.
- Parameters:
path (
Path) – Path to be written.delim (
int) – Delimiter to use when writing TEXT. Defaults to30.big_other (
bool) – IfTrueuse 20 chars for OTHER segment offsets, and 8 otherwise. Defaults toFalse.skip_conversion_check (
bool) – Skip check to ensure that types of the dataframe match the columns ($PnB, $DATATYPE, etc). If this isFalse, perform this check before writing, and raiseDataLossErroron failure. IfTrue, raise warnings as file is being written. Skipping this is faster since the data needs to be traversed twice to perform the conversion check, but may result in loss of precision and/or truncation. Defaults toFalse.appendable (
bool) – IfTrue, set $NEXTDATA in written dataset so it points to the next dataset. This obviously assumes the next dataset is actually written, which will require another call to this method withappendset toTrue. Defaults toFalse.append (
bool) – IfTrue, append this dataset to the end of the file if it exists and already has at least one dataset in it. This assumes that the previous dataset was written withappendableset toTrueso that $NEXTDATA is properly set. Defaults toFalse.
- Returns:
the value of $NEXTDATA which would point to next dataset if written
- Return type:
- Raises:
ConfigError – if
delimis not between 1 and 126OverflowError – If TEXT offsets are greater than 99,999,999 bytes
OverflowError – If any OTHER offsets are greater than 99,999,999 and
big_otherisFalse
- classmethod write_datasets(path, datasets, delim=30, big_other=False, skip_conversion_check=False)¶
Write multiple datasets to path.
The resulting file will include HEADER, TEXT, DATA, ANALYSIS, and OTHER as they present from this class.
- Parameters:
path (
Path) – Path to be written.datasets (
list[CoreDataset3_0]) – datasets to writedelim (
int) – Delimiter to use when writing TEXT. Defaults to30.big_other (
bool) – IfTrueuse 20 chars for OTHER segment offsets, and 8 otherwise. Defaults toFalse.skip_conversion_check (
bool) – Skip check to ensure that types of the dataframe match the columns ($PnB, $DATATYPE, etc). If this isFalse, perform this check before writing, and raiseDataLossErroron failure. IfTrue, raise warnings as file is being written. Skipping this is faster since the data needs to be traversed twice to perform the conversion check, but may result in loss of precision and/or truncation. Defaults toFalse.
- Returns:
the value of $NEXTDATA as written in the last dataset if written
- Return type:
int| None- Raises:
ConfigError – if
delimis not between 1 and 126OverflowError – If TEXT offsets are greater than 99,999,999 bytes
OverflowError – If any OTHER offsets are greater than 99,999,999 and
big_otherisFalse
- write_text(path, delim=30, big_other=False, appendable=False, append=False)¶
Write data to path.
Resulting FCS file will include HEADER and TEXT.
- Parameters:
path (
Path) – Path to be written.delim (
int) – Delimiter to use when writing TEXT. Defaults to30.big_other (
bool) – IfTrueuse 20 chars for OTHER segment offsets, and 8 otherwise. Defaults toFalse.appendable (
bool) – IfTrue, set $NEXTDATA in written dataset so it points to the next dataset. This obviously assumes the next dataset is actually written, which will require another call to this method withappendset toTrue. Defaults toFalse.append (
bool) – IfTrue, append this dataset to the end of the file if it exists and already has at least one dataset in it. This assumes that the previous dataset was written withappendableset toTrueso that $NEXTDATA is properly set. Defaults toFalse.
- Returns:
the value of $NEXTDATA as written to the dataset
- Return type:
- Raises:
ConfigError – if
delimis not between 1 and 126OverflowError – If TEXT offsets are greater than 99,999,999 bytes
OverflowError – If any OTHER offsets are greater than 99,999,999 and
big_otherisFalse
- class pyreflow.CoreDataset3_1(measurements, layout, data, mode='L', cyt='', btim=None, etim=None, date=None, cytsn='', spillover=None, last_modifier='', last_modified=None, originality=None, plateid='', platename='', wellid='', vol=None, csvbits=0, cstot=0, csvflags=[], abrt=None, com='', cells='', exp='', fil='', inst='', lost=None, op='', proj='', smno='', src='', sys='', tr=None, applied_gates=([], {}, None), nonstandard_keywords={}, analysis=b'', others=[])¶
Represents one dataset in an FCS 3.1 file.
- Parameters:
measurements (
tuple[str,Optical3_1|Temporal3_1]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.- Variables:
layout (
FixedAsciiLayout|DelimAsciiLayout|EndianUintLayout|EndianF32Layout|EndianF64Layout) – (read-write) Layout to describe data encoding. Represents $PnB, $PnR, $BYTEORD, and $DATATYPE.data (
polars.DataFrame) – (read-write) A dataframe encoding the contents of DATA. Number of columns must match number of measurements. May be empty. Types do not necessarily need to correspond to those in the data layout but mismatches may result in truncation.mode (
Literal[“L”, “U”, “C”]) – (read-write) Value of $MODE. Defaults to"L".cyt (
str) – (read-write) Value of $CYT. Defaults to"".btim (
time| None) – (read-write) Value of $BTIM. Defaults toNone.etim (
time| None) – (read-write) Value of $ETIM. Defaults toNone.date (
date| None) – (read-write) Value of $DATE. Defaults toNone.cytsn (
str) – (read-write) Value of $CYTSN. Defaults to"".spillover (
tuple[list[str],ndarray] | None) – (read-write) Value for $SPILLOVER. First element of tuple the list of measurement names and the second is the matrix. Each measurement name must correspond to a $PnN, must be unique, and the length of this list must match the number of rows and columns of the matrix. The matrix must be at least 2x2. Defaults toNone.last_modifier (
str) – (read-write) Value of $LAST_MODIFIER. Defaults to"".last_modified (
datetime| None) – (read-write) Value of $LAST_MODIFIED. Defaults toNone.originality (
Literal[“Original”, “NonDataModified”, “Appended”, “DataModified”] | None) – (read-write) Value of $ORIGINALITY. Defaults toNone.plateid (
str) – (read-write) Value of $PLATEID. Defaults to"".platename (
str) – (read-write) Value of $PLATENAME. Defaults to"".wellid (
str) – (read-write) Value of $WELLID. Defaults to"".vol (
float| None) – (read-write) Value of $VOL. Defaults toNone.csvbits (
int) – (read-write) Value of $CSVBITS. Defaults to0.cstot (
int) – (read-write) Value of $CSTOT. Defaults to0.csvflags (
list[int| None]) – (read-write) Subset flags. Each element in the list corresponds to $CSVnFLAG and the length of the list corresponds to $CSMODE. Defaults to[].abrt (
int| None) – (read-write) Value of $ABRT. Defaults toNone.com (
str) – (read-write) Value of $COM. Defaults to"".cells (
str) – (read-write) Value of $CELLS. Defaults to"".exp (
str) – (read-write) Value of $EXP. Defaults to"".fil (
str) – (read-write) Value of $FIL. Defaults to"".inst (
str) – (read-write) Value of $INST. Defaults to"".lost (
int| None) – (read-write) Value of $LOST. Defaults toNone.op (
str) – (read-write) Value of $OP. Defaults to"".proj (
str) – (read-write) Value of $PROJ. Defaults to"".smno (
str) – (read-write) Value of $SMNO. Defaults to"".src (
str) – (read-write) Value of $SRC. Defaults to"".sys (
str) – (read-write) Value of $SYS. Defaults to"".tr (
tuple[int,str] | None) – (read-write) Value for $TR. First member of tuple is threshold and second is the measurement name which must match a $PnN. Defaults toNone.applied_gates (
tuple[list[GatedMeasurement],dict[int,UnivariateRegion3_0|BivariateRegion3_0],str| None]) – (read-write) Value for $Gm/$RnI/$RnW/$GATING/$GATE* keywords. The first member of the tuple corresponds to the $Gm* keywords, where m is given by position in the list. The second member corresponds to the $RnI and $RnW keywords and is a mapping of regions and windows to be used in gating scheme. Keys in dictionary are the region indices (the n in $RnI and $RnW). The values in the dictionary are either univariate or bivariate gates and must correspond to an index in the list in the first element or a physical measurement. The third member corresponds to the $GATING keyword. All ‘Rn’ in this string must reference a key in the dict of the second member. Defaults to([], {}, None).nonstandard_keywords (
dict[str,str]) – (read-write) Pairs of non-standard keyword values. Keys must not start with $. Defaults to{}.analysis (
bytes) – (read-write) Contents of the ANALYSIS segment. Defaults tob"".others (
list[bytes]) – (read-write) A list of byte strings encoding the OTHER segments. Defaults to[].
- Raises:
OverflowError – if
abrt,cstot,csvbits, orlostis less than0or greater than2**32-1EventDataError – If
datacontains columns which are not unsigned 8/16/32/64-bit integers or 32/64-bit floatsInvalidKeywordValueError – if
volis negative,NaN,inf, or-infInvalidKeywordValueError – if matrix in
spilloverdoes not have the same number of rows and columns as the measurement vectorOverflowError – if field 1 in
tris less than0or greater than2**32-1ParseKeywordValueError – if field 1 in
measurementsis""or contains commasInvalidKeywordValueError – if field 2 in
spilloveris not a square matrix that is 2x2 or largerParseKeywordValueError – if field 2 in
tris""or contains commasOverflowError – if any in
csvflagsis less than0or greater than2**32-1ParseKeywordValueError – if any in field 1 in
spilloveris""or contains commasParseKeyError – if dict key in
nonstandard_keywordsis empty or starts with"$"
- all_calibrations¶
Value of $PnCALIBRATION for all measurements (read-write).
()will be returned for time since $PnCALIBRATION is not defined for temporal measurements.
- all_detector_types¶
Value of $PnT for all measurements (read-write).
()will be returned for time since $PnT is not defined for temporal measurements.
- all_detector_voltages¶
Value of $PnV for all measurements (read-write).
()will be returned for time since $PnV is not defined for temporal measurements.
- all_displays¶
Value of $PnD for all measurements (read-write).
- all_filters¶
Value of $PnF for all measurements (read-write).
()will be returned for time since $PnF is not defined for temporal measurements.
- all_meas_nonstandard_keywords¶
The non-standard keywords for each measurement (read-write).
- all_percents_emitted¶
Value of $PnP for all measurements (read-write).
()will be returned for time since $PnP is not defined for temporal measurements.
- all_powers¶
Value of $PnO for all measurements (read-write).
()will be returned for time since $PnO is not defined for temporal measurements.
- all_scale_transforms¶
The value for $PnE and/or $PnG for all measurements (read-write).
Collectively these keywords correspond to scale transforms.
If scaling is linear, return a float which corresponds to the value of $PnG when $PnE is
0,0. If scaling is logarithmic, return a pair of floats, corresponding to unset $PnG and the non-0,0value of $PnE.The FCS standards disallow any other combinations.
The temporal measurement will always be
1.0, corresponding to an identity transform. Setting it to another value will raiseRelationalError.
- all_shortnames¶
Value of $PnN for all measurements (read-write).
Strings are unique and cannot contain commas.
- all_wavelengths¶
Value of $PnL for all measurements (read-write).
()will be returned for time since $PnL is not defined for temporal measurements.
- classmethod from_kws(path, std, nonstd, data_seg, analysis_seg=(0, 0), other_segs=[], trim_intra_value_whitespace=False, time_meas_pattern='^(TIME|Time)$', allow_missing_time=False, force_time_linear=False, ignore_time_optical_keys=[], date_pattern=None, time_pattern=None, allow_pseudostandard=False, allow_unused_standard=False, disallow_deprecated=False, fix_log_scale_offsets=False, nonstandard_measurement_pattern=None, ignore_time_gain=False, parse_indexed_spillover=False, allow_optional_dropping=False, transfer_dropped_optional=False, disallow_range_truncation=False, text_data_correction=(0, 0), text_analysis_correction=(0, 0), ignore_text_data_offsets=False, ignore_text_analysis_offsets=False, allow_header_text_offset_mismatch=False, allow_missing_required_offsets=False, truncate_text_offsets=False, allow_uneven_event_width=False, allow_tot_mismatch=False, warnings_are_errors=False, hide_warnings=False, dataset_offset=0)¶
Make new instance from keywords.
- Parameters:
path (
Path) – Path to be read.analysis_seg (
tuple[int,int]) – The DATA segment from HEADER. Defaults to(0, 0).other_segs (
list[tuple[int,int]]) – The OTHER segments from HEADER. Defaults to[].trim_intra_value_whitespace (
bool) – IfTrue, trim whitespace between delimiters such as,and;within keyword value strings. Defaults toFalse.time_meas_pattern (
str| None) – A pattern to match the $PnN of the time measurement. IfNone, do not try to find a time measurement. Defaults to"^(TIME|Time)$".allow_missing_time (
bool) – IfTrueallow time measurement to be missing. Defaults toFalse.force_time_linear (
bool) – IfTrueforce time measurement to be linear independent of $PnE. Defaults toFalse.ignore_time_optical_keys (
list[Literal[“F”, “L”, “O”, “T”, “P”, “V”, “CALIBRATION”, “DET”, “TAG”, “FEATURE”, “ANALYTE”]]) – Ignore optical keys in temporal measurement. These keys are nonsensical for time measurements but are not explicitly forbidden in the the standard. Provided keys are the string after the “Pn” in the “PnX” keywords. Defaults to[].date_pattern (
str| None) – If supplied, will be used as an alternative pattern when parsing $DATE. If not supplied, $DATE will be parsed according to the standard pattern which is%d-%b-%Y. Defaults toNone.time_pattern (
str| None) – If supplied, will be used as an alternative pattern when parsing $BTIM and $ETIM. The values"%!"or"%@"may be used to match 1/60 seconds or centiseconds respectively. If not supplied, $BTIM and $ETIM will be parsed according to the standard pattern which is"%H:%M:%S.%@". Defaults toNone.allow_pseudostandard (
bool) – IfTrueallow non-standard keywords with a leading $. The presence of such keywords often means the version in HEADER is incorrect. Defaults toFalse.allow_unused_standard (
bool) – IfTrueallow unused standard keywords to be present. Defaults toFalse.disallow_deprecated (
bool) – IfTruethrow error if a deprecated key is encountered. Defaults toFalse.fix_log_scale_offsets (
bool) – IfTruefix log-scale PnE and keywords which have zero offset (ieX,0.0whereXis non-zero). Defaults toFalse.nonstandard_measurement_pattern (
str| None) – Pattern to use when matching nonstandard measurement keys. Must be a regular expression pattern with%nwhich will represent the measurement index and should not start with $. Otherwise should be a normal regular expression as defined in regexp-syntax. Defaults toNone.ignore_time_gain (
bool) – IfTrueignore the $PnG (gain) keyword. This keyword should not be set according to the standard} however, this library will allow gain to be 1.0 since this equates to identity. If gain is not 1.0, this is nonsense and it can be ignored with this flag. Defaults toFalse.parse_indexed_spillover (
bool) – Parse $SPILLOVER with numeric indices rather than strings (ie names or $PnN) Defaults toFalse.allow_optional_dropping (
bool) – IfTruedrop optional keys that cause an error and emit warning instead. Defaults toFalse.transfer_dropped_optional (
bool) – IfTruetransfer optional keys to non-standard dict if dropped. Defaults toFalse.disallow_range_truncation (
bool) – IfTruethrow error if $PnR values need to be truncated to match the number of bytes specified by $PnB and $DATATYPE. Defaults toFalse.text_data_correction (
tuple[int,int]) – Corrections for DATA offsets in TEXT. Defaults to(0, 0).text_analysis_correction (
tuple[int,int]) – Corrections for ANALYSIS offsets in TEXT. Defaults to(0, 0).ignore_text_data_offsets (
bool) – IfTrueignore DATA offsets in TEXT Defaults toFalse.ignore_text_analysis_offsets (
bool) – IfTrueignore ANALYSIS offsets in TEXT Defaults toFalse.allow_header_text_offset_mismatch (
bool) – IfTrueallow TEXT and HEADER offsets to mismatch. Defaults toFalse.allow_missing_required_offsets (
bool) – IfTrueallow required DATA and ANALYSIS offsets in TEXT to be missing. If missing, fall back to offsets from HEADER. Defaults toFalse.truncate_text_offsets (
bool) – IfTruetruncate offsets that exceed end of file. Defaults toFalse.allow_uneven_event_width (
bool) – IfTrueallow event width to not perfectly divide length of DATA. Does not apply to delimited ASCII layouts. Defaults toFalse.allow_tot_mismatch (
bool) – IfTrueallow $TOT to not match number of events as computed by the event width and length of DATA. Does not apply to delimited ASCII layouts. Defaults toFalse.warnings_are_errors (
bool) – IfTrueall warnings will be regarded as errors. Defaults toFalse.hide_warnings (
bool) – IfTruehide all warnings. Defaults toFalse.dataset_offset (
int) – Starting position in the file of the dataset to be read Defaults to0.
- Return type:
- Raises:
ValueError – if
analysis_segordata_seghas offsets which exceed the end of the file, are inverted (begin after end), or are either negative or greater than2**64-1ConfigError – if
nonstandard_measurement_patterndoes not have"%n"ConfigError – if
time_patterndoes not have specifiers for hours, minutes, seconds, and optionally sub-seconds (where"%!"and"%@"correspond to 1/60 seconds and centiseconds respectively) as outlined in chronoConfigError – if
date_patterndoes not have year, month, and day specifiers as outlined in chronoConfigError – if
time_meas_patternis not a valid regular expression as described in regexp-syntaxOverflowError – if field 1 or 2 in
text_analysis_correctionortext_data_correctionis less than-2**31or greater than2**31-1ValueError – if any in
other_segshas offsets which exceed the end of the file, are inverted (begin after end), or are either negative or greater than2**64-1ParseKeyError – if dict key in
nonstdis empty or starts with"$"ParseKeyError – if dict key in
stdis empty, does not start with"$", or is only a"$"FCSDeprecatedError – If any keywords or their values are deprecated and
disallow_deprecatedisTrueParseKeywordValueError – If any keyword values could not be read from their string encoding
RelationalError – If keywords are incompatible with indicated layout of DATA or if keywords that are referenced by other keywords do not exist
EventDataError – If values in DATA cannot be read
ExtraKeywordError – If any standard keys are unused and
allow_pseudostandardorallow_unused_standardareFalse
- insert_optical(index, name, meas, col, range, disallow_trunc=False)¶
Insert optical measurement at position in measurement vector.
- Parameters:
index (
int) – Position at which to insert new measurement.name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Optical3_1) – The measurement to insert.col (
polars.Series) – Data for measurement. Must be same length as existing columns.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- insert_temporal(index, name, meas, col, range, disallow_trunc=False)¶
Insert temporal measurement at position in measurement vector.
- Parameters:
index (
int) – Position at which to insert new measurement.name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Temporal3_1) – The measurement to insert.col (
polars.Series) – Data for measurement. Must be same length as existing columns.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- measurement_at(index)¶
Return measurement at index.
- Parameters:
index (
int) – Index to retrieve.- Return type:
- Raises:
IndexError – If
indexnot found
- measurement_named(name)¶
Return measurement with name.
- Parameters:
name (
str) – Name to retrieve. Corresponds to $PnN.- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namenot found
- measurements¶
All measurements (read-write).
- Return type:
- push_optical(name, meas, col, range, disallow_trunc=False)¶
Push optical measurement to end of measurement vector.
- Parameters:
name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Optical3_1) – The measurement to push.col (
polars.Series) – Data for measurement. Must be same length as existing columns.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- push_temporal(name, meas, col, range, disallow_trunc=False)¶
Push temporal measurement to end of measurement vector.
- Parameters:
name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Temporal3_1) – The measurement to push.col (
polars.Series) – Data for measurement. Must be same length as existing columns.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- remove_measurement_by_index(index)¶
Remove a measurement with a given index.
- Parameters:
index (
int) – Index to remove.- Returns:
Name and measurement object.
- Return type:
tuple[str,Optical3_1|Temporal3_1,Decimal]- Raises:
IndexError – If
indexnot found
- remove_measurement_by_name(name)¶
Remove a measurement with a given name.
- Parameters:
name (
str) – Name to remove. Corresponds to $PnN.- Returns:
Index and measurement object.
- Return type:
tuple[int,Optical3_1|Temporal3_1,Decimal]- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namenot found
- rename_temporal(name)¶
Rename temporal measurement if present.
- Parameters:
name (
str) – New name to assign. Corresponds to $PnN.- Returns:
Previous name if present.
- Return type:
str| None- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- replace_optical_at(index, meas)¶
Replace measurement at index with given optical measurement.
- Parameters:
index (
int) – Index to replace.meas (
Optical3_1) – Optical measurement to replace measurement atindex.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
IndexError – If
indexdoes not exist.
- replace_optical_named(name, meas)¶
Replace named measurement with given optical measurement.
- Parameters:
name (
str) – Name to replace. Corresponds to $PnN.meas (
Optical3_1) – Optical measurement to replace measurement atname.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namedoes not exist.
- replace_temporal_at(index, meas)¶
Replace measurement at index with given temporal measurement.
- Parameters:
index (
int) – Index to replace.meas (
Temporal3_1) – Temporal measurement to replace measurement atindex.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
IndexError – If
indexdoes not existRelationalError – If a temporal measurement already exists at a different position
- replace_temporal_named(name, meas)¶
Replace named measurement with given temporal measurement.
- Parameters:
name (
str) – Name to replace. Corresponds to $PnN.meas (
Temporal3_1) – Temporal measurement to replace measurement atname.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namedoes not existRelationalError – If a temporal measurement already exists at a different position
- set_measurements_and_data(measurements, data)¶
Set measurements and data at once.
Length of
measurementsmust match number of columns indata.- Parameters:
measurements (
list[Optical3_1|Temporal3_1]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.data (
polars.DataFrame) – The new data.
- set_measurements_and_layout(measurements, layout)¶
Set all measurements and layout at once.
Length of
measurementsmust match number of columns inlayoutand both must match number of columns in existing dataframe.- Parameters:
measurements (
list[Optical3_1|Temporal3_1]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.layout (
FixedAsciiLayout|DelimAsciiLayout|EndianUintLayout|EndianF32Layout|EndianF64Layout) – The new layout.
- set_measurements_layout_and_data(measurements, layout, data)¶
Set measurements, layout, and data at once.
Length of
measurementsandlayoutmust match number of columns indata.- Parameters:
measurements (
list[Optical3_1|Temporal3_1]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.layout (
FixedAsciiLayout|DelimAsciiLayout|EndianUintLayout|EndianF32Layout|EndianF64Layout) – The new layout.data (
polars.DataFrame) – The new data.
- set_named_measurements(measurements, allow_shared_names=False, skip_index_check=False)¶
Set all measurements at once.
Length of
measurementsmust match number of columns in existing layout and dataframe.- Parameters:
measurements (
tuple[str,Optical3_1|Temporal3_1]) – The new measurements. The first member of the tuple corresponds to the measurement name and the second is the measurement object.allow_shared_names (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keywords reference any $PnN keywords. IfTrueraiseRelationalErrorif any non-measurement keywords reference a $PnN which is not present inmeasurements. In other words,Falseforbids named references to exist, andTrueallows named references to be updated. References cannot be broken in either case. Defaults toFalse.skip_index_check (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keyword have an index reference to the current measurements. IfTrueallow such references to exist as long as they do not break (which really means that the length ofmeasurementsis such that existing indices are satisfied). Defaults toFalse.
- Raises:
ParseKeywordValueError – if field 1 in
measurementsis""or contains commas
- set_named_measurements_and_data(measurements, data, allow_shared_names=False, skip_index_check=False)¶
Set measurements, names, and data at once.
Length of
measurementsmust match number of columns indata.- Parameters:
measurements (
tuple[str,Optical3_1|Temporal3_1]) – The new measurements. The first member of the tuple corresponds to the measurement name and the second is the measurement object.data (
polars.DataFrame) – The new data.allow_shared_names (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keywords reference any $PnN keywords. IfTrueraiseRelationalErrorif any non-measurement keywords reference a $PnN which is not present inmeasurements. In other words,Falseforbids named references to exist, andTrueallows named references to be updated. References cannot be broken in either case. Defaults toFalse.skip_index_check (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keyword have an index reference to the current measurements. IfTrueallow such references to exist as long as they do not break (which really means that the length ofmeasurementsis such that existing indices are satisfied). Defaults toFalse.
- Raises:
ParseKeywordValueError – if field 1 in
measurementsis""or contains commas
- set_named_measurements_and_layout(measurements, layout, allow_shared_names=False, skip_index_check=False)¶
Set all measurements, names, and layout at once.
Length of
measurementsmust match number of columns inlayoutand both must match number of columns in existing dataframe.- Parameters:
measurements (
tuple[str,Optical3_1|Temporal3_1]) – The new measurements. The first member of the tuple corresponds to the measurement name and the second is the measurement object.layout (
FixedAsciiLayout|DelimAsciiLayout|EndianUintLayout|EndianF32Layout|EndianF64Layout) – The new layout.allow_shared_names (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keywords reference any $PnN keywords. IfTrueraiseRelationalErrorif any non-measurement keywords reference a $PnN which is not present inmeasurements. In other words,Falseforbids named references to exist, andTrueallows named references to be updated. References cannot be broken in either case. Defaults toFalse.skip_index_check (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keyword have an index reference to the current measurements. IfTrueallow such references to exist as long as they do not break (which really means that the length ofmeasurementsis such that existing indices are satisfied). Defaults toFalse.
- Raises:
ParseKeywordValueError – if field 1 in
measurementsis""or contains commas
- set_temporal(name, timestep, allow_loss=False)¶
Set the temporal measurement to a given name.
- Parameters:
name (
str) – Name to set to temporal. Corresponds to $PnN.timestep (
float) – The value of $TIMESTEP to use.allow_loss (
bool) – IfTrueremove any optical-specific metadata (detectors, lasers, etc) without raising anConversionErrorif an optical measurement must be converted. Defaults toFalse.
- Returns:
Trueif temporal measurement was set, which will happen for all cases except when the time measurement is already set toname.- Return type:
- Raises:
InvalidKeywordValueError – if
timestepis negative,0.0,NaN,inf, or-infParseKeywordValueError – if
nameis""or contains commas
- set_temporal_at(index, timestep, allow_loss=False)¶
Set the temporal measurement to a given index.
- Parameters:
index (
int) – Index to set.timestep (
float) – The value of $TIMESTEP to use.allow_loss (
bool) – IfTrueremove any optical-specific metadata (detectors, lasers, etc) without raising anConversionErrorif an optical measurement must be converted. Defaults toFalse.
- Returns:
Trueif temporal measurement was set, which will happen for all cases except when the time measurement is already set toindex.- Return type:
- Raises:
InvalidKeywordValueError – if
timestepis negative,0.0,NaN,inf, or-inf
- set_timestep(timestep)¶
Set the $TIMESTEP if time measurement is present.
- Parameters:
timestep (
float) – The timestep to set. Must be greater than zero.- Returns:
Previous $TIMESTEP if present.
- Return type:
float| None- Raises:
InvalidKeywordValueError – if
timestepis negative,0.0,NaN,inf, or-inf
- set_trigger_threshold(threshold)¶
Set the threshold for $TR.
- standard_keywords(req_or_opt, root_or_meas)¶
Return standard keywords as string pairs.
Each key will be prefixed with $.
This will not include $TOT, $NEXTDATA, or any of the offset keywords since these only matter if the dataset is written.
- Parameters:
- Returns:
A list of standard keywords.
- Return type:
- temporal¶
The temporal measurement if it exists (read-only).
- Returns:
Index, name, and measurement or
None.- Return type:
tuple[int,str,Temporal3_1] | None
- to_version_2_0(allow_loss=False)¶
Convert to FCS 2.0.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 2.0.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 2.0 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 2.0
- to_version_3_0(allow_loss=False)¶
Convert to FCS 3.0.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 3.0.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 3.0 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 3.0
- to_version_3_2(allow_loss=False)¶
Convert to FCS 3.2.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 3.2.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 3.2 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 3.2
- truncate_data(skip_conv_check=False)¶
Coerce all values in DATA to fit within types specified in layout.
This will always create a new copy of DATA in-place.
- Parameters:
skip_conv_check (
bool) – IfTrue, silently truncate data; otherwise return warnings when truncation is performed. Defaults toFalse.- Return type:
tuple[()]- Raises:
DataLossError – If any values in DATA segment need to be truncated to fit layout and
skip_conversion_checkisFalse
- unset_data()¶
Remove all measurements and their data.
- Return type:
tuple[()]- Raises:
RelationalError – If keywords are set which refer to measurements and would be invalidated if measurements were removed
- unset_temporal()¶
Convert the temporal measurement to an optical measurement.
- Returns:
Value of $TIMESTEP if time measurement was present.
- Return type:
float| None
- version¶
Show the FCS version (read-only).
- Return type:
Literal[“FCS2.0”, “FCS3.0”, “FCS3.1”, “FCS3.2”]
- write_dataset(path, delim=30, big_other=False, skip_conversion_check=False, appendable=False, append=False)¶
Write data as an FCS file.
The resulting file will include HEADER, TEXT, DATA, ANALYSIS, and OTHER as they present from this class.
- Parameters:
path (
Path) – Path to be written.delim (
int) – Delimiter to use when writing TEXT. Defaults to30.big_other (
bool) – IfTrueuse 20 chars for OTHER segment offsets, and 8 otherwise. Defaults toFalse.skip_conversion_check (
bool) – Skip check to ensure that types of the dataframe match the columns ($PnB, $DATATYPE, etc). If this isFalse, perform this check before writing, and raiseDataLossErroron failure. IfTrue, raise warnings as file is being written. Skipping this is faster since the data needs to be traversed twice to perform the conversion check, but may result in loss of precision and/or truncation. Defaults toFalse.appendable (
bool) – IfTrue, set $NEXTDATA in written dataset so it points to the next dataset. This obviously assumes the next dataset is actually written, which will require another call to this method withappendset toTrue. Defaults toFalse.append (
bool) – IfTrue, append this dataset to the end of the file if it exists and already has at least one dataset in it. This assumes that the previous dataset was written withappendableset toTrueso that $NEXTDATA is properly set. Defaults toFalse.
- Returns:
the value of $NEXTDATA which would point to next dataset if written
- Return type:
- Raises:
ConfigError – if
delimis not between 1 and 126OverflowError – If TEXT offsets are greater than 99,999,999 bytes
OverflowError – If any OTHER offsets are greater than 99,999,999 and
big_otherisFalse
- classmethod write_datasets(path, datasets, delim=30, big_other=False, skip_conversion_check=False)¶
Write multiple datasets to path.
The resulting file will include HEADER, TEXT, DATA, ANALYSIS, and OTHER as they present from this class.
- Parameters:
path (
Path) – Path to be written.datasets (
list[CoreDataset3_1]) – datasets to writedelim (
int) – Delimiter to use when writing TEXT. Defaults to30.big_other (
bool) – IfTrueuse 20 chars for OTHER segment offsets, and 8 otherwise. Defaults toFalse.skip_conversion_check (
bool) – Skip check to ensure that types of the dataframe match the columns ($PnB, $DATATYPE, etc). If this isFalse, perform this check before writing, and raiseDataLossErroron failure. IfTrue, raise warnings as file is being written. Skipping this is faster since the data needs to be traversed twice to perform the conversion check, but may result in loss of precision and/or truncation. Defaults toFalse.
- Returns:
the value of $NEXTDATA as written in the last dataset if written
- Return type:
int| None- Raises:
ConfigError – if
delimis not between 1 and 126OverflowError – If TEXT offsets are greater than 99,999,999 bytes
OverflowError – If any OTHER offsets are greater than 99,999,999 and
big_otherisFalse
- write_text(path, delim=30, big_other=False, appendable=False, append=False)¶
Write data to path.
Resulting FCS file will include HEADER and TEXT.
- Parameters:
path (
Path) – Path to be written.delim (
int) – Delimiter to use when writing TEXT. Defaults to30.big_other (
bool) – IfTrueuse 20 chars for OTHER segment offsets, and 8 otherwise. Defaults toFalse.appendable (
bool) – IfTrue, set $NEXTDATA in written dataset so it points to the next dataset. This obviously assumes the next dataset is actually written, which will require another call to this method withappendset toTrue. Defaults toFalse.append (
bool) – IfTrue, append this dataset to the end of the file if it exists and already has at least one dataset in it. This assumes that the previous dataset was written withappendableset toTrueso that $NEXTDATA is properly set. Defaults toFalse.
- Returns:
the value of $NEXTDATA as written to the dataset
- Return type:
- Raises:
ConfigError – if
delimis not between 1 and 126OverflowError – If TEXT offsets are greater than 99,999,999 bytes
OverflowError – If any OTHER offsets are greater than 99,999,999 and
big_otherisFalse
- class pyreflow.CoreDataset3_2(measurements, layout, data, cyt, mode=None, btim=None, etim=None, date=None, begindatetime=None, enddatetime=None, cytsn='', spillover=None, last_modifier='', last_modified=None, originality=None, plateid='', platename='', wellid='', vol=None, carrierid='', carriertype='', locationid='', unstainedinfo='', unstainedcenters={}, flowrate='', abrt=None, com='', cells='', exp='', fil='', inst='', lost=None, op='', proj='', smno='', src='', sys='', tr=None, applied_gates=({}, None), nonstandard_keywords={}, analysis=b'', others=[])¶
Represents one dataset in an FCS 3.2 file.
- Parameters:
measurements (
tuple[str,Optical3_2|Temporal3_2]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.- Variables:
layout (
FixedAsciiLayout|DelimAsciiLayout|EndianUintLayout|EndianF32Layout|EndianF64Layout|MixedLayout) – (read-write) Layout to describe data encoding. Represents $PnB, $PnR, $BYTEORD, $DATATYPE, and $PnDATATYPE.data (
polars.DataFrame) – (read-write) A dataframe encoding the contents of DATA. Number of columns must match number of measurements. May be empty. Types do not necessarily need to correspond to those in the data layout but mismatches may result in truncation.cyt (
str) – (read-write) Value of $CYT.mode (
Literal[“L”] | None) – (read-write) Value of $MODE. Defaults toNone.btim (
time| None) – (read-write) Value of $BTIM. Defaults toNone.etim (
time| None) – (read-write) Value of $ETIM. Defaults toNone.date (
date| None) – (read-write) Value of $DATE. Defaults toNone.begindatetime (
datetime| None) – (read-write) Value for $BEGINDATETIME. Defaults toNone.enddatetime (
datetime| None) – (read-write) Value for $ENDDATETIME. Defaults toNone.cytsn (
str) – (read-write) Value of $CYTSN. Defaults to"".spillover (
tuple[list[str],ndarray] | None) – (read-write) Value for $SPILLOVER. First element of tuple the list of measurement names and the second is the matrix. Each measurement name must correspond to a $PnN, must be unique, and the length of this list must match the number of rows and columns of the matrix. The matrix must be at least 2x2. Defaults toNone.last_modifier (
str) – (read-write) Value of $LAST_MODIFIER. Defaults to"".last_modified (
datetime| None) – (read-write) Value of $LAST_MODIFIED. Defaults toNone.originality (
Literal[“Original”, “NonDataModified”, “Appended”, “DataModified”] | None) – (read-write) Value of $ORIGINALITY. Defaults toNone.plateid (
str) – (read-write) Value of $PLATEID. Defaults to"".platename (
str) – (read-write) Value of $PLATENAME. Defaults to"".wellid (
str) – (read-write) Value of $WELLID. Defaults to"".vol (
float| None) – (read-write) Value of $VOL. Defaults toNone.carrierid (
str) – (read-write) Value of $CARRIERID. Defaults to"".carriertype (
str) – (read-write) Value of $CARRIERTYPE. Defaults to"".locationid (
str) – (read-write) Value of $LOCATIONID. Defaults to"".unstainedinfo (
str) – (read-write) Value of $UNSTAINEDINFO. Defaults to"".unstainedcenters (
dict[str,float]) – (read-write) Value for $UNSTAINEDCENTERS. Each key must match a *$PnN. Defaults to{}.flowrate (
str) – (read-write) Value of $FLOWRATE. Defaults to"".abrt (
int| None) – (read-write) Value of $ABRT. Defaults toNone.com (
str) – (read-write) Value of $COM. Defaults to"".cells (
str) – (read-write) Value of $CELLS. Defaults to"".exp (
str) – (read-write) Value of $EXP. Defaults to"".fil (
str) – (read-write) Value of $FIL. Defaults to"".inst (
str) – (read-write) Value of $INST. Defaults to"".lost (
int| None) – (read-write) Value of $LOST. Defaults toNone.op (
str) – (read-write) Value of $OP. Defaults to"".proj (
str) – (read-write) Value of $PROJ. Defaults to"".smno (
str) – (read-write) Value of $SMNO. Defaults to"".src (
str) – (read-write) Value of $SRC. Defaults to"".sys (
str) – (read-write) Value of $SYS. Defaults to"".tr (
tuple[int,str] | None) – (read-write) Value for $TR. First member of tuple is threshold and second is the measurement name which must match a $PnN. Defaults toNone.applied_gates (
tuple[dict[int,UnivariateRegion3_2|BivariateRegion3_2],str| None]) – (read-write) Value for $RnI/$RnW/$GATING keywords. The first member corresponds to the $RnI and $RnW keywords and is a mapping of regions and windows to be used in gating scheme. Keys in dictionary are the region indices (the n in $RnI and $RnW). The values in the dictionary are either univariate or bivariate gates and must correspond to a physical measurement. The second member corresponds to the $GATING keyword. All ‘Rn’ in this string must reference a key in the dict of the first member. Defaults to({}, None).nonstandard_keywords (
dict[str,str]) – (read-write) Pairs of non-standard keyword values. Keys must not start with $. Defaults to{}.analysis (
bytes) – (read-write) Contents of the ANALYSIS segment. Defaults tob"".others (
list[bytes]) – (read-write) A list of byte strings encoding the OTHER segments. Defaults to[].
- Raises:
OverflowError – if
abrtorlostis less than0or greater than2**32-1EventDataError – If
datacontains columns which are not unsigned 8/16/32/64-bit integers or 32/64-bit floatsInvalidKeywordValueError – if
cytis emptyInvalidKeywordValueError – if
volis negative,NaN,inf, or-infInvalidKeywordValueError – if matrix in
spilloverdoes not have the same number of rows and columns as the measurement vectorOverflowError – if field 1 in
tris less than0or greater than2**32-1ParseKeywordValueError – if field 1 in
measurementsis""or contains commasInvalidKeywordValueError – if field 2 in
spilloveris not a square matrix that is 2x2 or largerParseKeywordValueError – if field 2 in
tris""or contains commasParseKeywordValueError – if any in field 1 in
spilloveris""or contains commasParseKeyError – if dict key in
nonstandard_keywordsis empty or starts with"$"ParseKeywordValueError – if dict key in
unstainedcentersis""or contains commas
- all_analytes¶
Value of $PnANALYTE for all measurements (read-write).
()will be returned for time since $PnANALYTE is not defined for temporal measurements.
- all_calibrations¶
Value of $PnCALIBRATION for all measurements (read-write).
()will be returned for time since $PnCALIBRATION is not defined for temporal measurements.
- all_detector_names¶
Value of $PnDET for all measurements (read-write).
()will be returned for time since $PnDET is not defined for temporal measurements.
- all_detector_types¶
Value of $PnT for all measurements (read-write).
()will be returned for time since $PnT is not defined for temporal measurements.
- all_detector_voltages¶
Value of $PnV for all measurements (read-write).
()will be returned for time since $PnV is not defined for temporal measurements.
- all_displays¶
Value of $PnD for all measurements (read-write).
- all_features¶
Value of $PnFEATURE for all measurements (read-write).
()will be returned for time since $PnFEATURE is not defined for temporal measurements.
- all_filters¶
Value of $PnF for all measurements (read-write).
()will be returned for time since $PnF is not defined for temporal measurements.
- all_meas_nonstandard_keywords¶
The non-standard keywords for each measurement (read-write).
- all_measurement_types¶
Value of $PnTYPE for all measurements (read-write).
A bool will be returned for the time measurement where
Trueindicates it is set to"Time".
- all_percents_emitted¶
Value of $PnP for all measurements (read-write).
()will be returned for time since $PnP is not defined for temporal measurements.
- all_powers¶
Value of $PnO for all measurements (read-write).
()will be returned for time since $PnO is not defined for temporal measurements.
- all_scale_transforms¶
The value for $PnE and/or $PnG for all measurements (read-write).
Collectively these keywords correspond to scale transforms.
If scaling is linear, return a float which corresponds to the value of $PnG when $PnE is
0,0. If scaling is logarithmic, return a pair of floats, corresponding to unset $PnG and the non-0,0value of $PnE.The FCS standards disallow any other combinations.
The temporal measurement will always be
1.0, corresponding to an identity transform. Setting it to another value will raiseRelationalError.
- all_shortnames¶
Value of $PnN for all measurements (read-write).
Strings are unique and cannot contain commas.
- all_tags¶
Value of $PnTAG for all measurements (read-write).
()will be returned for time since $PnTAG is not defined for temporal measurements.
- all_wavelengths¶
Value of $PnL for all measurements (read-write).
()will be returned for time since $PnL is not defined for temporal measurements.
- classmethod from_kws(path, std, nonstd, data_seg, analysis_seg=(0, 0), other_segs=[], trim_intra_value_whitespace=False, time_meas_pattern='^(TIME|Time)$', allow_missing_time=False, force_time_linear=False, ignore_time_optical_keys=[], date_pattern=None, time_pattern=None, allow_pseudostandard=False, allow_unused_standard=False, disallow_deprecated=False, fix_log_scale_offsets=False, nonstandard_measurement_pattern=None, ignore_time_gain=False, parse_indexed_spillover=False, disallow_localtime=False, allow_optional_dropping=False, transfer_dropped_optional=False, disallow_range_truncation=False, text_data_correction=(0, 0), text_analysis_correction=(0, 0), ignore_text_data_offsets=False, ignore_text_analysis_offsets=False, allow_header_text_offset_mismatch=False, allow_missing_required_offsets=False, truncate_text_offsets=False, allow_uneven_event_width=False, allow_tot_mismatch=False, warnings_are_errors=False, hide_warnings=False, dataset_offset=0)¶
Make new instance from keywords.
- Parameters:
path (
Path) – Path to be read.analysis_seg (
tuple[int,int]) – The DATA segment from HEADER. Defaults to(0, 0).other_segs (
list[tuple[int,int]]) – The OTHER segments from HEADER. Defaults to[].trim_intra_value_whitespace (
bool) – IfTrue, trim whitespace between delimiters such as,and;within keyword value strings. Defaults toFalse.time_meas_pattern (
str| None) – A pattern to match the $PnN of the time measurement. IfNone, do not try to find a time measurement. Defaults to"^(TIME|Time)$".allow_missing_time (
bool) – IfTrueallow time measurement to be missing. Defaults toFalse.force_time_linear (
bool) – IfTrueforce time measurement to be linear independent of $PnE. Defaults toFalse.ignore_time_optical_keys (
list[Literal[“F”, “L”, “O”, “T”, “P”, “V”, “CALIBRATION”, “DET”, “TAG”, “FEATURE”, “ANALYTE”]]) – Ignore optical keys in temporal measurement. These keys are nonsensical for time measurements but are not explicitly forbidden in the the standard. Provided keys are the string after the “Pn” in the “PnX” keywords. Defaults to[].date_pattern (
str| None) – If supplied, will be used as an alternative pattern when parsing $DATE. If not supplied, $DATE will be parsed according to the standard pattern which is%d-%b-%Y. Defaults toNone.time_pattern (
str| None) – If supplied, will be used as an alternative pattern when parsing $BTIM and $ETIM. The values"%!"or"%@"may be used to match 1/60 seconds or centiseconds respectively. If not supplied, $BTIM and $ETIM will be parsed according to the standard pattern which is"%H:%M:%S.%@". Defaults toNone.allow_pseudostandard (
bool) – IfTrueallow non-standard keywords with a leading $. The presence of such keywords often means the version in HEADER is incorrect. Defaults toFalse.allow_unused_standard (
bool) – IfTrueallow unused standard keywords to be present. Defaults toFalse.disallow_deprecated (
bool) – IfTruethrow error if a deprecated key is encountered. Defaults toFalse.fix_log_scale_offsets (
bool) – IfTruefix log-scale PnE and keywords which have zero offset (ieX,0.0whereXis non-zero). Defaults toFalse.nonstandard_measurement_pattern (
str| None) – Pattern to use when matching nonstandard measurement keys. Must be a regular expression pattern with%nwhich will represent the measurement index and should not start with $. Otherwise should be a normal regular expression as defined in regexp-syntax. Defaults toNone.ignore_time_gain (
bool) – IfTrueignore the $PnG (gain) keyword. This keyword should not be set according to the standard} however, this library will allow gain to be 1.0 since this equates to identity. If gain is not 1.0, this is nonsense and it can be ignored with this flag. Defaults toFalse.parse_indexed_spillover (
bool) – Parse $SPILLOVER with numeric indices rather than strings (ie names or $PnN) Defaults toFalse.disallow_localtime (
bool) – Iftrue, require that $BEGINDATETIME and $ENDDATETIME have a timezone if provided. This is not required by the standard, but not having a timezone is ambiguous since the absolute value of the timestamp is dependent on localtime and therefore is location-dependent. Only affects FCS 3.2. Defaults toFalse.allow_optional_dropping (
bool) – IfTruedrop optional keys that cause an error and emit warning instead. Defaults toFalse.transfer_dropped_optional (
bool) – IfTruetransfer optional keys to non-standard dict if dropped. Defaults toFalse.disallow_range_truncation (
bool) – IfTruethrow error if $PnR values need to be truncated to match the number of bytes specified by $PnB and $DATATYPE. Defaults toFalse.text_data_correction (
tuple[int,int]) – Corrections for DATA offsets in TEXT. Defaults to(0, 0).text_analysis_correction (
tuple[int,int]) – Corrections for ANALYSIS offsets in TEXT. Defaults to(0, 0).ignore_text_data_offsets (
bool) – IfTrueignore DATA offsets in TEXT Defaults toFalse.ignore_text_analysis_offsets (
bool) – IfTrueignore ANALYSIS offsets in TEXT Defaults toFalse.allow_header_text_offset_mismatch (
bool) – IfTrueallow TEXT and HEADER offsets to mismatch. Defaults toFalse.allow_missing_required_offsets (
bool) – IfTrueallow required DATA offsets in TEXT to be missing. If missing, fall back to offsets from HEADER. Defaults toFalse.truncate_text_offsets (
bool) – IfTruetruncate offsets that exceed end of file. Defaults toFalse.allow_uneven_event_width (
bool) – IfTrueallow event width to not perfectly divide length of DATA. Does not apply to delimited ASCII layouts. Defaults toFalse.allow_tot_mismatch (
bool) – IfTrueallow $TOT to not match number of events as computed by the event width and length of DATA. Does not apply to delimited ASCII layouts. Defaults toFalse.warnings_are_errors (
bool) – IfTrueall warnings will be regarded as errors. Defaults toFalse.hide_warnings (
bool) – IfTruehide all warnings. Defaults toFalse.dataset_offset (
int) – Starting position in the file of the dataset to be read Defaults to0.
- Return type:
- Raises:
ValueError – if
analysis_segordata_seghas offsets which exceed the end of the file, are inverted (begin after end), or are either negative or greater than2**64-1ConfigError – if
nonstandard_measurement_patterndoes not have"%n"ConfigError – if
time_patterndoes not have specifiers for hours, minutes, seconds, and optionally sub-seconds (where"%!"and"%@"correspond to 1/60 seconds and centiseconds respectively) as outlined in chronoConfigError – if
date_patterndoes not have year, month, and day specifiers as outlined in chronoConfigError – if
time_meas_patternis not a valid regular expression as described in regexp-syntaxOverflowError – if field 1 or 2 in
text_analysis_correctionortext_data_correctionis less than-2**31or greater than2**31-1ValueError – if any in
other_segshas offsets which exceed the end of the file, are inverted (begin after end), or are either negative or greater than2**64-1ParseKeyError – if dict key in
nonstdis empty or starts with"$"ParseKeyError – if dict key in
stdis empty, does not start with"$", or is only a"$"FCSDeprecatedError – If any keywords or their values are deprecated and
disallow_deprecatedisTrueParseKeywordValueError – If any keyword values could not be read from their string encoding
RelationalError – If keywords are incompatible with indicated layout of DATA or if keywords that are referenced by other keywords do not exist
EventDataError – If values in DATA cannot be read
ExtraKeywordError – If any standard keys are unused and
allow_pseudostandardorallow_unused_standardareFalse
- insert_optical(index, name, meas, col, range, disallow_trunc=False)¶
Insert optical measurement at position in measurement vector.
- Parameters:
index (
int) – Position at which to insert new measurement.name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Optical3_2) – The measurement to insert.col (
polars.Series) – Data for measurement. Must be same length as existing columns.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- insert_temporal(index, name, meas, col, range, disallow_trunc=False)¶
Insert temporal measurement at position in measurement vector.
- Parameters:
index (
int) – Position at which to insert new measurement.name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Temporal3_2) – The measurement to insert.col (
polars.Series) – Data for measurement. Must be same length as existing columns.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- measurement_at(index)¶
Return measurement at index.
- Parameters:
index (
int) – Index to retrieve.- Return type:
- Raises:
IndexError – If
indexnot found
- measurement_named(name)¶
Return measurement with name.
- Parameters:
name (
str) – Name to retrieve. Corresponds to $PnN.- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namenot found
- measurements¶
All measurements (read-write).
- Return type:
- push_optical(name, meas, col, range, disallow_trunc=False)¶
Push optical measurement to end of measurement vector.
- Parameters:
name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Optical3_2) – The measurement to push.col (
polars.Series) – Data for measurement. Must be same length as existing columns.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- push_temporal(name, meas, col, range, disallow_trunc=False)¶
Push temporal measurement to end of measurement vector.
- Parameters:
name (
str) – Name of new measurement. Corresponds to $PnN.meas (
Temporal3_2) – The measurement to push.col (
polars.Series) – Data for measurement. Must be same length as existing columns.range (
Decimal) – Range of measurement. Corresponds to $PnR.disallow_trunc (
bool) – IfFalse, raiseRelationalErrorifrangemust be truncated to fit into measurement type. Defaults toFalse.
- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- remove_measurement_by_index(index)¶
Remove a measurement with a given index.
- Parameters:
index (
int) – Index to remove.- Returns:
Name and measurement object.
- Return type:
tuple[str,Optical3_2|Temporal3_2,Decimal]- Raises:
IndexError – If
indexnot found
- remove_measurement_by_name(name)¶
Remove a measurement with a given name.
- Parameters:
name (
str) – Name to remove. Corresponds to $PnN.- Returns:
Index and measurement object.
- Return type:
tuple[int,Optical3_2|Temporal3_2,Decimal]- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namenot found
- rename_temporal(name)¶
Rename temporal measurement if present.
- Parameters:
name (
str) – New name to assign. Corresponds to $PnN.- Returns:
Previous name if present.
- Return type:
str| None- Raises:
ParseKeywordValueError – if
nameis""or contains commas
- replace_optical_at(index, meas)¶
Replace measurement at index with given optical measurement.
- Parameters:
index (
int) – Index to replace.meas (
Optical3_2) – Optical measurement to replace measurement atindex.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
IndexError – If
indexdoes not exist.
- replace_optical_named(name, meas)¶
Replace named measurement with given optical measurement.
- Parameters:
name (
str) – Name to replace. Corresponds to $PnN.meas (
Optical3_2) – Optical measurement to replace measurement atname.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namedoes not exist.
- replace_temporal_at(index, meas, allow_loss=False)¶
Replace measurement at index with given temporal measurement.
- Parameters:
index (
int) – Index to replace.meas (
Temporal3_2) – Temporal measurement to replace measurement atindex.allow_loss (
bool) – IfFalse, raiseConversionErrorif conversion from temporal measurement to optical measurement is necessary and data keywords must be dropped. Defaults toFalse.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
IndexError – If
indexdoes not existRelationalError – If a temporal measurement already exists at a different position
- replace_temporal_named(name, meas, allow_loss=False)¶
Replace named measurement with given temporal measurement.
- Parameters:
name (
str) – Name to replace. Corresponds to $PnN.meas (
Temporal3_2) – Temporal measurement to replace measurement atname.allow_loss (
bool) – IfFalse, raiseConversionErrorif conversion from temporal measurement to optical measurement is necessary and data keywords must be dropped. Defaults toFalse.
- Returns:
Replaced measurement object.
- Return type:
- Raises:
ParseKeywordValueError – if
nameis""or contains commasKeyError – If
namedoes not existRelationalError – If a temporal measurement already exists at a different position
- set_measurements_and_data(measurements, data)¶
Set measurements and data at once.
Length of
measurementsmust match number of columns indata.- Parameters:
measurements (
list[Optical3_2|Temporal3_2]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.data (
polars.DataFrame) – The new data.
- set_measurements_and_layout(measurements, layout)¶
Set all measurements and layout at once.
Length of
measurementsmust match number of columns inlayoutand both must match number of columns in existing dataframe.- Parameters:
measurements (
list[Optical3_2|Temporal3_2]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.layout (
FixedAsciiLayout|DelimAsciiLayout|EndianUintLayout|EndianF32Layout|EndianF64Layout|MixedLayout) – The new layout.
- set_measurements_layout_and_data(measurements, layout, data)¶
Set measurements, layout, and data at once.
Length of
measurementsandlayoutmust match number of columns indata.- Parameters:
measurements (
list[Optical3_2|Temporal3_2]) – Measurements corresponding to columns in FCS file. Temporal must be given zero or one times.layout (
FixedAsciiLayout|DelimAsciiLayout|EndianUintLayout|EndianF32Layout|EndianF64Layout|MixedLayout) – The new layout.data (
polars.DataFrame) – The new data.
- set_named_measurements(measurements, allow_shared_names=False, skip_index_check=False)¶
Set all measurements at once.
Length of
measurementsmust match number of columns in existing layout and dataframe.- Parameters:
measurements (
tuple[str,Optical3_2|Temporal3_2]) – The new measurements. The first member of the tuple corresponds to the measurement name and the second is the measurement object.allow_shared_names (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keywords reference any $PnN keywords. IfTrueraiseRelationalErrorif any non-measurement keywords reference a $PnN which is not present inmeasurements. In other words,Falseforbids named references to exist, andTrueallows named references to be updated. References cannot be broken in either case. Defaults toFalse.skip_index_check (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keyword have an index reference to the current measurements. IfTrueallow such references to exist as long as they do not break (which really means that the length ofmeasurementsis such that existing indices are satisfied). Defaults toFalse.
- Raises:
ParseKeywordValueError – if field 1 in
measurementsis""or contains commas
- set_named_measurements_and_data(measurements, data, allow_shared_names=False, skip_index_check=False)¶
Set measurements, names, and data at once.
Length of
measurementsmust match number of columns indata.- Parameters:
measurements (
tuple[str,Optical3_2|Temporal3_2]) – The new measurements. The first member of the tuple corresponds to the measurement name and the second is the measurement object.data (
polars.DataFrame) – The new data.allow_shared_names (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keywords reference any $PnN keywords. IfTrueraiseRelationalErrorif any non-measurement keywords reference a $PnN which is not present inmeasurements. In other words,Falseforbids named references to exist, andTrueallows named references to be updated. References cannot be broken in either case. Defaults toFalse.skip_index_check (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keyword have an index reference to the current measurements. IfTrueallow such references to exist as long as they do not break (which really means that the length ofmeasurementsis such that existing indices are satisfied). Defaults toFalse.
- Raises:
ParseKeywordValueError – if field 1 in
measurementsis""or contains commas
- set_named_measurements_and_layout(measurements, layout, allow_shared_names=False, skip_index_check=False)¶
Set all measurements, names, and layout at once.
Length of
measurementsmust match number of columns inlayoutand both must match number of columns in existing dataframe.- Parameters:
measurements (
tuple[str,Optical3_2|Temporal3_2]) – The new measurements. The first member of the tuple corresponds to the measurement name and the second is the measurement object.layout (
FixedAsciiLayout|DelimAsciiLayout|EndianUintLayout|EndianF32Layout|EndianF64Layout|MixedLayout) – The new layout.allow_shared_names (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keywords reference any $PnN keywords. IfTrueraiseRelationalErrorif any non-measurement keywords reference a $PnN which is not present inmeasurements. In other words,Falseforbids named references to exist, andTrueallows named references to be updated. References cannot be broken in either case. Defaults toFalse.skip_index_check (
bool) – IfFalse, raiseRelationalErrorif any non-measurement keyword have an index reference to the current measurements. IfTrueallow such references to exist as long as they do not break (which really means that the length ofmeasurementsis such that existing indices are satisfied). Defaults toFalse.
- Raises:
ParseKeywordValueError – if field 1 in
measurementsis""or contains commas
- set_temporal(name, timestep, allow_loss=False)¶
Set the temporal measurement to a given name.
- Parameters:
name (
str) – Name to set to temporal. Corresponds to $PnN.timestep (
float) – The value of $TIMESTEP to use.allow_loss (
bool) – IfTrueremove any optical-specific metadata (detectors, lasers, etc) without raising anConversionErrorif an optical measurement must be converted. Defaults toFalse.
- Returns:
Trueif temporal measurement was set, which will happen for all cases except when the time measurement is already set toname.- Return type:
- Raises:
InvalidKeywordValueError – if
timestepis negative,0.0,NaN,inf, or-infParseKeywordValueError – if
nameis""or contains commas
- set_temporal_at(index, timestep, allow_loss=False)¶
Set the temporal measurement to a given index.
- Parameters:
index (
int) – Index to set.timestep (
float) – The value of $TIMESTEP to use.allow_loss (
bool) – IfTrueremove any optical-specific metadata (detectors, lasers, etc) without raising anConversionErrorif an optical measurement must be converted. Defaults toFalse.
- Returns:
Trueif temporal measurement was set, which will happen for all cases except when the time measurement is already set toindex.- Return type:
- Raises:
InvalidKeywordValueError – if
timestepis negative,0.0,NaN,inf, or-inf
- set_timestep(timestep)¶
Set the $TIMESTEP if time measurement is present.
- Parameters:
timestep (
float) – The timestep to set. Must be greater than zero.- Returns:
Previous $TIMESTEP if present.
- Return type:
float| None- Raises:
InvalidKeywordValueError – if
timestepis negative,0.0,NaN,inf, or-inf
- set_trigger_threshold(threshold)¶
Set the threshold for $TR.
- standard_keywords(req_or_opt, root_or_meas)¶
Return standard keywords as string pairs.
Each key will be prefixed with $.
This will not include $TOT, $NEXTDATA, or any of the offset keywords since these only matter if the dataset is written.
- Parameters:
- Returns:
A list of standard keywords.
- Return type:
- temporal¶
The temporal measurement if it exists (read-only).
- Returns:
Index, name, and measurement or
None.- Return type:
tuple[int,str,Temporal3_2] | None
- to_version_2_0(allow_loss=False)¶
Convert to FCS 2.0.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 2.0.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 2.0 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 2.0
- to_version_3_0(allow_loss=False)¶
Convert to FCS 3.0.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 3.0.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 3.0 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 3.0
- to_version_3_1(allow_loss=False)¶
Convert to FCS 3.1.
- Parameters:
allow_loss (
bool) – IfFalse, do not proceed with conversion if it would result in data loss. This is most likely to happen when converting from a later to an earlier version, as many keywords from the later version may not exist in the earlier version. There is no place to keep these values so they must be discarded. Set toTrueto perform the conversion with such discarding; otherwise, remove the keywords manually before converting. Defaults toFalse.- Returns:
A new class conforming to FCS 3.1.
- Return type:
- Raises:
ConversionError – If keywords which are unsupported in FCS 3.1 exist in current data and
allow_lossisFalseConversionError – If optional keywords are that are missing in current version are required in FCS 3.1
- truncate_data(skip_conv_check=False)¶
Coerce all values in DATA to fit within types specified in layout.
This will always create a new copy of DATA in-place.
- Parameters:
skip_conv_check (
bool) – IfTrue, silently truncate data; otherwise return warnings when truncation is performed. Defaults toFalse.- Return type:
tuple[()]- Raises:
DataLossError – If any values in DATA segment need to be truncated to fit layout and
skip_conversion_checkisFalse
- unset_data()¶
Remove all measurements and their data.
- Return type:
tuple[()]- Raises:
RelationalError – If keywords are set which refer to measurements and would be invalidated if measurements were removed
- unset_temporal(allow_loss=False)¶
Convert the temporal measurement to an optical measurement.
- Parameters:
allow_loss (
bool) – IfTrueand current time measurement has data which cannot be converted to optical, force the conversion anyways. Otherwise raiseConversionError. Defaults toFalse.- Returns:
Value of $TIMESTEP if time measurement was present.
- Return type:
float| None
- version¶
Show the FCS version (read-only).
- Return type:
Literal[“FCS2.0”, “FCS3.0”, “FCS3.1”, “FCS3.2”]
- write_dataset(path, delim=30, big_other=False, skip_conversion_check=False, appendable=False, append=False)¶
Write data as an FCS file.
The resulting file will include HEADER, TEXT, DATA, ANALYSIS, and OTHER as they present from this class.
- Parameters:
path (
Path) – Path to be written.delim (
int) – Delimiter to use when writing TEXT. Defaults to30.big_other (
bool) – IfTrueuse 20 chars for OTHER segment offsets, and 8 otherwise. Defaults toFalse.skip_conversion_check (
bool) – Skip check to ensure that types of the dataframe match the columns ($PnB, $DATATYPE, etc). If this isFalse, perform this check before writing, and raiseDataLossErroron failure. IfTrue, raise warnings as file is being written. Skipping this is faster since the data needs to be traversed twice to perform the conversion check, but may result in loss of precision and/or truncation. Defaults toFalse.appendable (
bool) – IfTrue, set $NEXTDATA in written dataset so it points to the next dataset. This obviously assumes the next dataset is actually written, which will require another call to this method withappendset toTrue. Defaults toFalse.append (
bool) – IfTrue, append this dataset to the end of the file if it exists and already has at least one dataset in it. This assumes that the previous dataset was written withappendableset toTrueso that $NEXTDATA is properly set. Defaults toFalse.
- Returns:
the value of $NEXTDATA which would point to next dataset if written
- Return type:
- Raises:
ConfigError – if
delimis not between 1 and 126OverflowError – If TEXT offsets are greater than 99,999,999 bytes
OverflowError – If any OTHER offsets are greater than 99,999,999 and
big_otherisFalse
- classmethod write_datasets(path, datasets, delim=30, big_other=False, skip_conversion_check=False)¶
Write multiple datasets to path.
The resulting file will include HEADER, TEXT, DATA, ANALYSIS, and OTHER as they present from this class.
- Parameters:
path (
Path) – Path to be written.datasets (
list[CoreDataset3_2]) – datasets to writedelim (
int) – Delimiter to use when writing TEXT. Defaults to30.big_other (
bool) – IfTrueuse 20 chars for OTHER segment offsets, and 8 otherwise. Defaults toFalse.skip_conversion_check (
bool) – Skip check to ensure that types of the dataframe match the columns ($PnB, $DATATYPE, etc). If this isFalse, perform this check before writing, and raiseDataLossErroron failure. IfTrue, raise warnings as file is being written. Skipping this is faster since the data needs to be traversed twice to perform the conversion check, but may result in loss of precision and/or truncation. Defaults toFalse.
- Returns:
the value of $NEXTDATA as written in the last dataset if written
- Return type:
int| None- Raises:
ConfigError – if
delimis not between 1 and 126OverflowError – If TEXT offsets are greater than 99,999,999 bytes
OverflowError – If any OTHER offsets are greater than 99,999,999 and
big_otherisFalse
- write_text(path, delim=30, big_other=False, appendable=False, append=False)¶
Write data to path.
Resulting FCS file will include HEADER and TEXT.
- Parameters:
path (
Path) – Path to be written.delim (
int) – Delimiter to use when writing TEXT. Defaults to30.big_other (
bool) – IfTrueuse 20 chars for OTHER segment offsets, and 8 otherwise. Defaults toFalse.appendable (
bool) – IfTrue, set $NEXTDATA in written dataset so it points to the next dataset. This obviously assumes the next dataset is actually written, which will require another call to this method withappendset toTrue. Defaults toFalse.append (
bool) – IfTrue, append this dataset to the end of the file if it exists and already has at least one dataset in it. This assumes that the previous dataset was written withappendableset toTrueso that $NEXTDATA is properly set. Defaults toFalse.
- Returns:
the value of $NEXTDATA as written to the dataset
- Return type:
- Raises:
ConfigError – if
delimis not between 1 and 126OverflowError – If TEXT offsets are greater than 99,999,999 bytes
OverflowError – If any OTHER offsets are greater than 99,999,999 and
big_otherisFalse