cedalion.io package

Submodules

cedalion.io.anatomy module

cedalion.io.anatomy.cell_coordinates(mask, affine, units='mm')
cedalion.io.anatomy.read_segmentation_masks(basedir, mask_files={'csf': 'csf.nii', 'gm': 'gm.nii', 'scalp': 'scalp.nii', 'skull': 'skull.nii', 'wm': 'wm.nii'})
Return type:

DataArray

cedalion.io.bids module

cedalion.io.bids.read_events_from_tsv(fname)

cedalion.io.forward_model module

cedalion.io.forward_model.load_Adot(fn)

Load Adot from a netCDF file.

Parameters:

fn (str) – str File name to load the data from.

Returns:

xr.DataArray

Data loaded from the file.

Return type:

Adot

cedalion.io.forward_model.save_Adot(fn, Adot)

Save Adot to a netCDF file.

Parameters:

fn: str

File name to save the data to.

Adot: xr.DataArray

Data to save.

Returns:

:

None

cedalion.io.photogrammetry module

cedalion.io.photogrammetry.opt_fid_to_xr(fiducials, optodes)

Convert OrderedDicts fiducials and optodes to cedalion LabeledPoints objects.

Parameters:
  • fiducials – OrderedDict The fiducials as an OrderedDict.

  • optodes – OrderedDict The optodes as an OrderedDict.

Returns:

cedalion.LabeledPoints

The fiducials as a cedalion LabeledPoints object.

optodescedalion.LabeledPoints

The optodes as a cedalion LabeledPoints object.

Return type:

fiducials

cedalion.io.photogrammetry.read_einstar(fn)

Read optodes and fiducials from einstar devices.

Parameters:

fn – The filename of the einstar photogrammatry output file.

Returns:

OrderedDict

The fiducials as an OrderedDict.

optodesOrderedDict

The optodes as an OrderedDict.

Return type:

fiducials

cedalion.io.photogrammetry.read_photogrammetry_einstar(fn)

Read optodes and fiducials from photogrammetry pipeline.

This method reads the output file as returned by the photogrammetry pipeline using an einstar device.

Parameters:

fn – the filename of the einstar photogrammatry output file

Returns:

cedalion.LabeledPoints

The fiducials as a cedalion LabeledPoints object.

optodescedalion.LabeledPoints

The optodes as a cedalion LabeledPoints object.

Return type:

fiducials

cedalion.io.probe_geometry module

cedalion.io.probe_geometry.read_digpts(fname, units='mm')
Return type:

DataArray

cedalion.io.probe_geometry.read_einstar_obj(fname)

Read a textured triangle mesh generated by Einstar devices.

Return type:

TrimeshSurface

cedalion.io.probe_geometry.read_mrk_json(fname, crs)
Return type:

DataArray

cedalion.io.snirf module

class cedalion.io.snirf.DataType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

CW_AMPLITUDE = 1
CW_FLUORESCENCE_AMPLITUDE = 51
DCS_BFI = 410
DCS_G2 = 401
FD_AC_AMPLITUDE = 101
FD_FLUORESCENCE_AMPLITUDE = 151
FD_FLUORESCENCE_PHASE = 152
FD_PHASE = 102
PROCESSED = 99999
TDG_AMPLITUDE = 201
TDG_FLUORESCENCE_AMPLITUDE = 251
TDM_AMPLITUDE = 301
TDM_FLUORESCENCE_AMPLITUDE = 351
class cedalion.io.snirf.DataTypeLabel(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: StrEnum

BFI = 'BFi'
DMEAN = 'dMean'
DOD = 'dOD'
DSKEW = 'dSkew'
DVAR = 'dVar'
H2O = 'H2O'
HBO = 'HbO'
HBR = 'HbR'
HBT = 'HbT'
HRF_BFI = 'HRF BFi'
HRF_DMEAN = 'HRF dMean'
HRF_DOD = 'HRF dOD'
HRF_DSKEW = 'HRF dSkew'
HRF_DVAR = 'HRF dVar'
HRF_HBO = 'HRF HbO'
HRF_HBR = 'HRF HbR'
HRF_HBT = 'HRF HbT'
LIPID = 'Lipid'
MUA = 'mua'
MUSP = 'musp'
RAW_NIRX = 'raw-DC'
RAW_SATORI = 'RAW'
cedalion.io.snirf.add_number_to_name(name, keys)

Changes name to name_<number>.

Number appended to name is the smallest number that makes the new name unique with respect to the list of keys.

Parameters:
  • name (str) – Name to which a number should be added.

  • keys (list[str]) – List of keys to which the new name should be compared.

Returns:

New name with number added.

Return type:

str

cedalion.io.snirf.denormalize_measurement_list(df_ml, nirs_element)

Enriches measurement list DataFrame with additional information.

Parameters:
  • df_ml (pd.DataFrame) – DataFrame containing the measurement list information.

  • nirs_element (NirsElement) – Nirs data element as specified in the snirf documentation.

Returns:

DataFrame containing the measurement list information with

additional columns for channel, source, detector, wavelength and chromo.

Return type:

pd.DataFrame

cedalion.io.snirf.geometry_from_probe(nirs_element, dim=3)

Extract 3D coordinates of optodes and landmarks from probe information.

Parameters:
  • nirs_element (NirsElement) – Nirs data element as specified in the snirf documentation.

  • dim (int) – must be either 2 or 3.

Returns:

A DataArray containing the 3D coordinates

of optodes and landmarks, with dimensions ‘label’ and ‘pos’ and coordinates ‘label’ and ‘type’.

Return type:

result (xr.DataArray, (label, pos))

cedalion.io.snirf.labels_and_positions(probe, dim=3)

Extract 3D coordinates of optodes and landmarks from a nirs probe variable.

Parameters:
  • probe – Nirs probe geometry variable, see snirf documentation.

  • dim (int) – must be either 2 or 3.

Returns:

Tuple containing the source, detector and landmark labels/positions.

Return type:

Tuple(np.ndarray, np.ndarray, np.ndarray, np.ndarray, np.ndarray, np.ndarray)

cedalion.io.snirf.measurement_list_from_stacked(stacked_array, data_type, trial_types, stacked_channel='snirf_channel', source_labels=None, detector_labels=None, wavelengths=None)
cedalion.io.snirf.measurement_list_to_dataframe(measurement_list, drop_none=False)

Converts a snirf MeasurementList object to a pandas DataFrame.

Parameters:
  • measurement_list (MeasurementList) – MeasurementList object from the snirf file.

  • drop_none (bool) – If True, drop columns that are None for all rows.

Returns:

DataFrame containing the measurement list information.

Return type:

pd.DataFrame

cedalion.io.snirf.meta_data_tags_to_dict(nirs_element)

Converts the metaDataTags of a nirs element to a dictionary.

Parameters:

nirs_element (NirsElement) – Nirs data element as specified in the snirf documentation.

Returns:

Dictionary containing the metaDataTags information.

Return type:

OrderedDict[str, Any]

cedalion.io.snirf.parse_data_type(value)
cedalion.io.snirf.parse_data_type_label(value)
cedalion.io.snirf.read_aux(nirs_element, opts)

Reads the aux data from a nirs element into a dictionary of DataArrays.

Parameters:
  • nirs_element (NirsElement) – Nirs data element as specified in the snirf documentation.

  • opts (dict[str, Any]) –

    Options for reading the aux data. The following options are supported: - squeeze_aux (bool): If True, squeeze the aux data to remove

    dimensions of size 1.

Returns:

Dictionary containing the aux data

Return type:

result (OrderedDict[str, xr.DataArray])

cedalion.io.snirf.read_data_elements(data_element, nirs_element, stim)

Reads the data elements from a nirs element into a list of DataArrays.

Parameters:
  • data_element (DataElement) – DataElement obj. from the snirf file.

  • nirs_element (NirsElement) – Nirs data element as specified in the snirf documentation.

  • stim (pd.DataFrame) – DataFrame containing the stimulus information.

Returns:

List of tuples containing the canonical name

of the data element and the DataArray.

Return type:

list[tuple[str, NDTimeSeries]]

cedalion.io.snirf.read_nirs_element(nirs_element, opts)

Reads a single nirs element from a .snirf file into a Recording object.

Parameters:
  • nirs_element (NirsElement) – Nirs data element as specified in the snirf documentation

  • opts (dict[str, Any]) –

    Options for reading the data element. The following options are supported: - squeeze_aux (bool): If True, squeeze the aux data to remove

    dimensions of size 1.

Returns:

Recording object containing the data from the nirs element.

Return type:

rec (Recording)

cedalion.io.snirf.read_snirf(fname, squeeze_aux=False)

Reads a .snirf file into a list of Recording objects.

Parameters:
  • fname (Path | str) – Path to .snirf file

  • squeeze_aux (Bool) – If True, squeeze the aux data to remove dimensions of size 1.

Returns:

List of Recording objects containing the data from the nirs elements in the .snirf file.

Return type:

list[Recording]

cedalion.io.snirf.reduce_ndim_sourceLabels(sourceLabels)

Deal with multidimensional source labels.

snirf supports multidimensional source labels but we don’t. This function tries to reduce n-dimensional source labels to a unique common prefix to obtain only one label per source

Return type:

list

cedalion.io.snirf.stim_to_dataframe(stim)

Converts a snirf Stim object to a pandas DataFrame.

Parameters:

stim (Stim) – Stim object as specified in the snirf documentation.

Returns:

DataFrame containing the stimulus information.

Return type:

pd.DataFrame

cedalion.io.snirf.write_snirf(fname, recordings)

Module contents