compensate Module

Utility functions related to compensation tasks

flowutils.compensate.get_spill(text)

Extracts spillover matrix from FCS text entry.

Parameters:

text – Text value from the $SPILL or $SPILLOVER metadata keyword in an FCS file

Returns:

A tuple containing: (spillover matrix new_spill, column headers)

flowutils.compensate.parse_compensation_matrix(compensation, channel_labels, null_channels=None)

Returns a NumPy array with the compensation matrix, where the first row contains the indices of the fluorescent channels

Parameters:
  • compensation – Compensation matrix: may be a NumPy array, a CSV file path, a pathlib Path object to a CSV or TSV file or a string of CSV text. If a string, both multi-line, traditional CSV, and the single line FCS spill formats are supported. If a NumPy array, we assume the columns are in the same order as the channel labels

  • channel_labels – Channel labels from the FCS file’s PnN fields, must be in the same order as they appear in the FCS file

  • null_channels – Specify any empty channels that were collected and present in the channel_labels argument. These will be ignored when validating and creating the compensation matrix

Returns:

Compensation matrix as NumPy array where header contains the channel numbers (not indices!)

flowutils.compensate.compensate(event_data, spill_matrix, fluoro_indices=None)

Compensate NumPy event data ‘npy’ given spillover matrix ‘spill’ and marker indices to compensate.

Parameters:
  • event_data – NumPy array of the event data

  • spill_matrix – Compensation matrix as a NumPy array (without headers)

  • fluoro_indices – Optional list of indices of the fluorescent channels (only these will be extracted & compensated). If None (default), all columns will be compensated.

Returns:

NumPy array of compensated event data. If fluoro_indices were given, the data is returned with the column order given, with the non-fluorescent columns unmodified.

flowutils.compensate.inverse_compensate(event_data, spill_matrix, fluoro_indices=None)

Inverse the compensation on NumPy event data ‘npy’ given spillover matrix ‘spill’ and marker indices to “un-compensate”.

Parameters:
  • event_data – NumPy array of the event data

  • spill_matrix – Compensation matrix as a NumPy array (without headers)

  • fluoro_indices – Optional list of indices of the fluorescent channels (only these will be extracted & un-compensated). If None (default), all columns will be un-compensated.

Returns:

NumPy array of un-compensated event data. If fluoro_indices were given, the data is returned with the column order given, with the non-fluorescent columns unmodified.