Module for reading, writing and validating SNIRF files.
SNIRF files are HDF5 files designed to facilitate the sharing of near-infrared spectrocopy data. Their specification is defined at https://github.com/fNIRS/snirf.
This library wraps each HDF5 Group and offers a Pythonic interface on lists of like-Groups which the SNIRF specification calls "indexed Groups".
Example: Load a file:
from snirf import Snirf
>>> with Snirf() as s:
...
Maintained by the Boston University Neurophotonics Center
loadSnirf(
path: str,
dynamic_loading: bool = False,
enable_logging: bool = False
) → Snirf
Load a SNIRF file from disk.
Returns a Snirf
object loaded from path if a SNIRF file exists there. Takes the same kwargs as the Snirf object constructor
Args:
path
(str): Path to a SNIRF file on disk.dynamic_loading
(bool): If True, Datasets will not be read from the SNIRF file unless accessed with a property, conserving memory and loading time with larger datasets. Default False.enable_logging
(bool): If True, theSnirf
instance will write to a log file which shares its name. Default False.
Returns:
Snirf
: aSnirf
instance loaded from the SNIRF file.
Raises:
FileNotFoundError
:path
was not found on disk.
saveSnirf(path: str, snirf: Snirf)
Saves a SNIRF file to disk.
Args:
path
(str): Path to save the file.snirf
(Snirf):Snirf
instance to write to disk.
validateSnirf(path: str) → ValidationResult
Validate a SNIRF file on disk.
Returns truthy ValidationResult instance which holds detailed results of validation
Raised when SNIRF-specific error prevents file from loading properly.
Information about the validity of a given SNIRF file location.
Properties: location: A relative HDF5 name corresponding to the location of the issue name: A string describing the issue. Must be predefined in _CODES
id: An integer corresponding to the predefined error type severity: An integer ranking the serverity level of the issue. 0 OK, Nothing remarkable 1 Potentially useful INFO
2 WARNING
, the file is valid but exhibits undefined behavior or features marked deprecation 3 FATAL
, The file is invalid. message: A string containing a more verbose description of the issue
__init__(name: str, location: str)
dictize()
Return dictionary representation of Issue.
The result of Snirf file validation routines.
Validation results in a list of issues. Each issue records information about the validity of each location (each named Dataset and Group) in a SNIRF file. ValidationResult organizes the issues catalogued during validation and affords interfaces to retrieve and display them.
<ValidationResult> = <Snirf instance>.validate()
<ValidationResult> = validateSnirf(<path>)
__init__()
ValidationResult
should only be created by a Snirf
instance's validate
method.
A list of each unique code name associated with all catalogued issues.
A list of the FATAL
issues catalogued during validation.
A list of the INFO
issues catalogued during validation.
A comprehensive list of all ValidationIssue
instances for the result.
A list of the HDF5 location associated with each issue.
A list of the WARNING
issues catalogued during validation.
display(severity=2)
Reads the contents of an h5py.Dataset
to an array of dtype=str
.
Args:
severity
: Anint
which sets the minimum severity message to display. Default is 2. severity=0 All messages will be shown, includingOK
severity=1 PrintsINFO
,WARNING
, andFATAL
messages severity=2 PrintsWARNING
andFATAL
messages severity=3 Prints onlyFATAL
error messages
is_valid() → bool
Returns True if no FATAL
issues were catalogued during validation.
serialize(indent=4)
Render serialized JSON ValidationResult.
Structure containing Snirf-wide data and settings.
Properties: logger (logging.Logger): The logger that the Snirf instance writes to dynamic_loading (bool): If True, data is loaded from the HDF5 file only on access via property
__init__()
__init__(varg, cfg: SnirfConfig)
Wrapper for an HDF5 Group element defined by SNIRF.
Base class for an HDF5 Group element defined by SNIRF. Must be created with a Group ID or string specifying a complete path relative to file root--in the latter case, the wrapper will not correspond to a real HDF5 group on disk until _save()
(with no arguments) is executed for the first time
Args:
varg
(h5py.h5g.GroupID or str): Either a string which maps to a future Group location or an ID corresponding to a current one on diskcfg
(SnirfConfig): Injected configuration of parentSnirf
instance
The filename the Snirf object was loaded from and will save to.
None if not associated with a Group on disk.
The HDF5 relative location indentifier.
None if not associataed with a Group on disk.
is_empty()
If the Group has no member Groups or Datasets.
Returns:
bool
: True if empty, False if not
save(*args)
Group level save to a SNIRF file on disk.
Args:
args
(str or h5py.File): A path to a closed SNIRF file on disk or an openh5py.File
instance
Examples:
save can be called on a Group already on disk to overwrite the current contents: mysnirf.nirs[0].probe.save()
or using a new filename to write the Group there:
>>> mysnirf.nirs[0].probe.save(<new destination>)
__init__(parent: Group, cfg: SnirfConfig)
Represents several Groups which share a name, an "indexed group".
Represents the "indexed group" which is defined by v1.0 of the SNIRF specification as: If a data element is an HDF5 group and contains multiple sub-groups, it is referred to as an indexed group. Each element of the sub-group is uniquely identified by appending a string-formatted index (starting from 1, with no preceding zeros) in the name, for example, /.../name1 denotes the first sub-group of data element name, and /.../name2 denotes the 2nd element, and so on.
Because the indexed group is not a true HDF5 group but rather an iterable list of HDF5 groups, it takes a base group or file and searches its keys, appending the appropriate elements to itself in order.
The appropriate elements are identified using the _name
attribute: if a key begins with _name
and ends with a number, or is equal to _name
.
Args:
parent
(h5py.h5g.Group): An HDF5 group which is the parent of the indexed groupscfg
(SnirfConfig): Injected configuration of parentSnirf
instance
The filename the Snirf object was loaded from and will save to.
append(item)
Append a new Group to the IndexedGroup.
Args:
item
: must be of type _element
appendGroup()
Insert a new Group at the end of the Indexed Group.
Creates an empty Group with the appropriate name at the end of the list of Groups managed by the IndexedGroup.
insert(i, item)
Insert a new Group into the IndexedGroup.
Args:
i
(int): an indexitem
: must be of type _element
insertGroup(i)
Insert a new Group following the index given.
Creates an empty Group with a placeholder name within the list of Groups managed by the IndexedGroup. The placeholder name will be replaced with a name with the correct order once save
is called.
Args:
i
(int): the position at which to insert the new Group
is_empty()
Returns True if the Indexed Group has no member Groups with contents.
Returns:
bool
: True if empty, False if not
save(*args)
Save the groups to a SNIRF file on disk.
When saving, the naming convention defined by the SNIRF spec is enforced: groups are named /<name>1
, /<name>2
, /<name>3
, and so on.
Args:
args
(str or h5py.File): A path to a closed SNIRF file on disk or an openh5py.File
instance
Examples:
save can be called on an Indexed Group already on disk to overwrite the current contents: mysnirf.nirs[0].stim.save()
or using a new filename to write the Indexed Group there:
>>> mysnirf.nirs[0].stim.save(<new destination>)
__init__(var, cfg: SnirfConfig)
SNIRF field FrequencyUnit
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This record stores the case-sensitive SI frequency unit used in this measurement. Sample frequency units "Hz", "MHz" and "GHz". Please note that "mHz" is milli-Hz while "MHz" denotes "mega-Hz" according to SI unit system.
We do not limit the total number of metadata records in the metaDataTags
. Users can add additional customized metadata records; no duplicated metadata record names are allowed.
Additional metadata record samples can be found in the below table.
| Metadata Key Name | Metadata value | |-------------------|----------------| |ManufacturerName | "Company Name" | |Model | "Model Name" | |SubjectName | "LastName, FirstName" | |DateOfBirth | "YYYY-MM-DD" | |AcquisitionStartTime | "1569465620" | |StudyID | "Infant Brain Development" | |StudyDescription | "In this study, we measure ...." | |AccessionNumber | "##########################" | |InstanceNumber | 2 | |CalibrationFileName | "phantomcal_121015.snirf" | |UnixTime | "1569465667" |
The metadata records "StudyID"
and "AccessionNumber"
are unique strings that can be used to link the current dataset to a particular study and a particular procedure, respectively. The "StudyID"
tag is similar to the DICOM tag "Study ID" (0020,0010) and "AccessionNumber"
is similar to the DICOM tag "Accession Number"(0008,0050), as defined in the DICOM standard (ISO 12052).
The metadata record "InstanceNumber"
is defined similarly to the DICOM tag "Instance Number" (0020,0013), and can be used as the sequence number to group multiple datasets into a larger dataset - for example, concatenating streamed data segments during a long measurement session.
The metadata record "UnixTime"
defines the Unix Epoch Time, i.e. the total elapse time in seconds since 1970-01-01T00:00:00Z (UTC) minus the leap seconds.
SNIRF field LengthUnit
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This record stores the case-sensitive SI length unit used in this measurement. Sample length units include "mm", "cm", and "m". A value of "um" is the same as "mm", i.e. micrometer.
SNIRF field MeasurementDate
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This record stores the date of the measurement as a string. The format of the date string must either be "unknown"
, or follow the ISO 8601 date string format YYYY-MM-DD
, where
YYYY
is the 4-digit yearMM
is the 2-digit month (padding zero if a single digit)DD
is the 2-digit date (padding zero if a single digit)
SNIRF field MeasurementTime
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This record stores the time of the measurement as a string. The format of the time string must either be "unknown"
or follow the ISO 8601 time string format hh:mm:ss.sTZD
, where
hh
is the 2-digit hourmm
is the 2-digit minutess
is the 2-digit second.s
is 1 or more digit representing a decimal fraction of a second (optional)TZD
is the time zone designator (Z
or+hh:mm
or-hh:mm
)
SNIRF field SubjectID
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This record stores the string-valued ID of the study subject or experiment.
SNIRF field TimeUnit
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This record stores the case-sensitive SI time unit used in this measurement. Sample time units include "s", and "ms". A value of "us" is the same as "ms", i.e. microsecond.
The filename the Snirf object was loaded from and will save to.
None if not associated with a Group on disk.
The HDF5 relative location indentifier.
None if not associataed with a Group on disk.
add(name, value)
Add a new tag to the list.
Args:
name
(str): The name of the tag to add (will be added as an attribute of thisMetaDataTags
instance)value
: The value of the new tag
is_empty()
If the Group has no member Groups or Datasets.
Returns:
bool
: True if empty, False if not
remove(name)
Remove a tag from the list. You cannot remove a required tag.
Args:
name
(str): The name of the tag to remove.
save(*args)
Group level save to a SNIRF file on disk.
Args:
args
(str or h5py.File): A path to a closed SNIRF file on disk or an openh5py.File
instance
Examples:
save can be called on a Group already on disk to overwrite the current contents: mysnirf.nirs[0].probe.save()
or using a new filename to write the Group there:
>>> mysnirf.nirs[0].probe.save(<new destination>)
__init__(var, cfg: SnirfConfig)
SNIRF field coordinateSystem
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
Defines the coordinate system for sensor positions. The string must be one of the coordinate systems listed in the BIDS specification (Appendix VII) such as "MNI152NLin2009bAsym", "CapTrak" or "Other". If the value "Other" is specified, then a defition of the coordinate system must be provided in /nirs(i)/probe/coordinateSystemDescription
. See the FieldTrip toolbox web page for detailed descriptions of different coordinate systems.
SNIRF field coordinateSystemDescription
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
Free-form text description of the coordinate system. May also include a link to a documentation page or paper describing the system in greater detail. This field is required if the coordinateSystem
field is set to "Other".
SNIRF field correlationTimeDelayWidths
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This field describes the time delay widths (in TimeUnit
units) used for diffuse correlation spectroscopy measurements. This field is only required for gated time domain data types, and is indexed by measurementList(k).dataTypeIndex
. The indexing of this field is paired with the indexing of probe.correlationTimeDelays
.
SNIRF field correlationTimeDelays
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This field describes the time delays (in TimeUnit
units) used for diffuse correlation spectroscopy measurements. This field is only required for diffuse correlation spectroscopy data types, and is indexed by measurementList(k).dataTypeIndex
. The indexing of this field is paired with the indexing of probe.correlationTimeDelayWidths
.
SNIRF field detectorLabels
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This is a string array providing user friendly or instrument specific labels for each detector. Each element of the array must be a unique string among both probe.sourceLabels
and probe.detectorLabels
. This is indexed by measurementList(k).detectorIndex
.
SNIRF field detectorPos2D
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
Same as probe.sourcePos2D
, but describing the detector positions in a flattened 2D probe layout.
SNIRF field detectorPos3D
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This field describes the position (in LengthUnit
units) of each detector optode in 3D, defined similarly to sourcePos3D
.
The filename the Snirf object was loaded from and will save to.
None if not associated with a Group on disk.
SNIRF field frequencies
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This field describes the frequencies used (in FrequencyUnit
units) for frequency domain measurements. This field is only required for frequency domain data types, and is indexed by measurementList(k).dataTypeIndex
.
SNIRF field landmarkLabels
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This string array stores the names of the landmarks. The first string denotes the name of the landmarks with an index of 1 in the 4th column of probe.landmark
, and so on. One can adopt the commonly used 10-20 landmark names, such as "Nasion", "Inion", "Cz" etc, or use user-defined landmark labels. The landmark label can also use the unique source and detector labels defined in probe.sourceLabels
and probe.detectorLabels
, respectively, to associate the given landmark to a specific source or detector. All strings are ASCII encoded char arrays.
SNIRF field landmarkPos2D
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This is a 2-D array storing the neurological landmark positions projected along the 2-D (flattened) probe plane in order to map optical data from the flattened optode positions to brain anatomy. This array should contain a minimum of 2 columns, representing the x and y coordinates (in LengthUnit
units) of the 2-D projected landmark positions. If a 3rd column presents, it stores the index to the labels of the given landmark. Label names are stored in the probe.landmarkLabels
subfield. An label index of 0 refers to an undefined landmark.
SNIRF field landmarkPos3D
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This is a 2-D array storing the neurological landmark positions measurement from 3-D digitization and tracking systems to facilitate the registration and mapping of optical data to brain anatomy. This array should contain a minimum of 3 columns, representing the x, y and z coordinates (in LengthUnit
units) of the digitized landmark positions. If a 4th column presents, it stores the index to the labels of the given landmark. Label names are stored in the probe.landmarkLabels
subfield. An label index of 0 refers to an undefined landmark.
The HDF5 relative location indentifier.
None if not associataed with a Group on disk.
SNIRF field momentOrders
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This field describes the moment orders of the temporal point spread function (TPSF) or the distribution of time-of-flight (DTOF) for moment time domain measurements. This field is only required for moment time domain data types, and is indexed by measurementList(k).dataTypeIndex
. Note that the numeric value in this array is the exponent in the integral used for calculating the moments. For detailed/specific definitions of moments, see Wabnitz et al, 2020; for general definitions of moments see here.
In brief, given a TPSF or DTOF N(t) (photon counts vs. photon arrival time at the detector): / momentOrder = 0: total counts: N_total = /intergral N(t)dt
/ momentOrder = 1: mean time of flight: m = <t> = (1/N_total) /integral t N(t) dt
/ momentOrder = 2: variance/second central moment: V = (1/N_total) /integral (t - <t>)^2 N(t) dt
/ Please note that all moments (for orders >=1) are expected to be normalized by the total counts (i.e. n=0); Additionally all moments (for orders >= 2) are expected to be centralized.
SNIRF field sourceLabels
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This is a string array providing user friendly or instrument specific labels for each source. Each element of the array must be a unique string among both probe.sourceLabels
and probe.detectorLabels
.This can be of size <number of sources>x 1
or <number of sources> x <number of wavelengths>
. This is indexed by measurementList(k).sourceIndex
and measurementList(k).wavelengthIndex
.
SNIRF field sourcePos2D
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This field describes the position (in LengthUnit
units) of each source optode. The positions are coordinates in a flattened 2D probe layout. This field has size <number of sources> x 2
. For example, probe.sourcePos2D(1,:) = [1.4 1]
, and LengthUnit='cm'
places source number 1 at x=1.4 cm and y=1 cm.
SNIRF field sourcePos3D
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This field describes the position (in LengthUnit
units) of each source optode in 3D. This field has size <number of sources> x 3
.
SNIRF field timeDelayWidths
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This field describes the time delay widths (in TimeUnit
units) used for gated time domain measurements. This field is only required for gated time domain data types, and is indexed by measurementList(k).dataTypeIndex
. The indexing of this field is paired with the indexing of probe.timeDelays
.
SNIRF field timeDelays
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This field describes the time delays (in TimeUnit
units) used for gated time domain measurements. This field is only required for gated time domain data types, and is indexed by measurementList(k).dataTypeIndex
. The indexing of this field is paired with the indexing of probe.timeDelayWidths
.
SNIRF field useLocalIndex
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
For modular NIRS systems, setting this flag to a non-zero integer indicates that measurementList(k).sourceIndex
and measurementList(k).detectorIndex
are module-specific local-indices. One must also include measurementList(k).moduleIndex
, or when cross-module channels present, both measurementList(k).sourceModuleIndex
and measurementList(k).detectorModuleIndex
in the measurementList
structure in order to restore the global indices of the sources/detectors.
SNIRF field wavelengths
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This field describes the "nominal" wavelengths used (in nm
unit). This is indexed by the wavelengthIndex
of the measurementList variable. For example, probe.wavelengths
= [690, 780, 830]; implies that the measurements were taken at three wavelengths (690 nm, 780 nm, and 830 nm). The wavelength index of measurementList(k).wavelengthIndex
variable refers to this field. measurementList(k).wavelengthIndex
= 2 means the kth measurement was at 780 nm.
Please note that this field stores the "nominal" wavelengths. If the precise (measured) wavelengths differ from the nominal wavelengths, one can store those in the measurementList.wavelengthActual
field in a per-channel fashion.
The number of wavelengths is not limited (except that at least two are needed to calculate the two forms of hemoglobin). Each source-detector pair would generally have measurements at all wavelengths.
This field must present, but can be empty, for example, in the case that the stored data are processed data (dataType=99999
, see Appendix).
SNIRF field wavelengthsEmission
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This field is required only for fluorescence data types, and describes the "nominal" emission wavelengths used (in nm
unit). The indexing of this variable is the same wavelength index in measurementList used for probe.wavelengths
such that the excitation wavelength is paired with this emission wavelength for a given measurement.
Please note that this field stores the "nominal" emission wavelengths. If the precise (measured) emission wavelengths differ from the nominal ones, one can store those in the measurementList.wavelengthEmissionActual
field in a per-channel fashion.
is_empty()
If the Group has no member Groups or Datasets.
Returns:
bool
: True if empty, False if not
save(*args)
Group level save to a SNIRF file on disk.
Args:
args
(str or h5py.File): A path to a closed SNIRF file on disk or an openh5py.File
instance
Examples:
save can be called on a Group already on disk to overwrite the current contents: mysnirf.nirs[0].probe.save()
or using a new filename to write the Group there:
>>> mysnirf.nirs[0].probe.save(<new destination>)
Wrapper for an element of indexed group Nirs
.
__init__(gid: GroupID, cfg: SnirfConfig)
SNIRF field aux
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This optional array specifies any recorded auxiliary data. Each element of aux
has the following required fields:
SNIRF field data
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This group stores one block of NIRS data. This can be extended adding the count number (e.g. data1
, data2
,...) to the group name. This is intended to allow the storage of 1 or more blocks of NIRS data from within the same /nirs
entry * /nirs/data1
= data block 1 * /nirs/data2
= data block 2
The filename the Snirf object was loaded from and will save to.
None if not associated with a Group on disk.
The HDF5 relative location indentifier.
None if not associataed with a Group on disk.
SNIRF field metaDataTags
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
The metaDataTags
group contains the metadata associated with the measurements. Each metadata record is represented as a dataset under this group - with the name of the record, i.e. the key, as the dataset's name, and the value of the record as the actual data stored in the dataset. Each metadata record can potentially have different data types. Sub-groups should not be used to organize metadata records: a member of the metaDataTags
Group must be a Dataset.
The below five metadata records are minimally required in a SNIRF file
SNIRF field probe
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This is a structured variable that describes the probe (source-detector) geometry. This variable has a number of required fields.
SNIRF field stim
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This is an array describing any stimulus conditions. Each element of the array has the following required fields.
is_empty()
If the Group has no member Groups or Datasets.
Returns:
bool
: True if empty, False if not
save(*args)
Group level save to a SNIRF file on disk.
Args:
args
(str or h5py.File): A path to a closed SNIRF file on disk or an openh5py.File
instance
Examples:
save can be called on a Group already on disk to overwrite the current contents: mysnirf.nirs[0].probe.save()
or using a new filename to write the Group there:
>>> mysnirf.nirs[0].probe.save(<new destination>)
Interface for indexed group Nirs
.
Can be indexed like a list to retrieve Nirs
elements.
To add or remove an element from the list, use the appendGroup
method and the del
operator, respectively.
This group stores one set of NIRS data. This can be extended by adding the count number (e.g. /nirs1
, /nirs2
,...) to the group name. This is intended to allow the storage of 1 or more complete NIRS datasets inside a single SNIRF document. For example, a two-subject hyperscanning can be stored using the notation * /nirs1
= first subject's data * /nirs2
= second subject's data The use of a non-indexed (e.g. /nirs
) entry is allowed when only one entry is present and is assumed to be entry 1.
__init__(h: File, cfg: SnirfConfig)
The filename the Snirf object was loaded from and will save to.
append(item)
Append a new Group to the IndexedGroup.
Args:
item
: must be of type _element
appendGroup()
Insert a new Group at the end of the Indexed Group.
Creates an empty Group with the appropriate name at the end of the list of Groups managed by the IndexedGroup.
insert(i, item)
Insert a new Group into the IndexedGroup.
Args:
i
(int): an indexitem
: must be of type _element
insertGroup(i)
Insert a new Group following the index given.
Creates an empty Group with a placeholder name within the list of Groups managed by the IndexedGroup. The placeholder name will be replaced with a name with the correct order once save
is called.
Args:
i
(int): the position at which to insert the new Group
is_empty()
Returns True if the Indexed Group has no member Groups with contents.
Returns:
bool
: True if empty, False if not
save(*args)
Save the groups to a SNIRF file on disk.
When saving, the naming convention defined by the SNIRF spec is enforced: groups are named /<name>1
, /<name>2
, /<name>3
, and so on.
Args:
args
(str or h5py.File): A path to a closed SNIRF file on disk or an openh5py.File
instance
Examples:
save can be called on an Indexed Group already on disk to overwrite the current contents: mysnirf.nirs[0].stim.save()
or using a new filename to write the Indexed Group there:
>>> mysnirf.nirs[0].stim.save(<new destination>)
__init__(gid: GroupID, cfg: SnirfConfig)
SNIRF field dataTimeSeries
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This is the actual raw or processed data variable. This variable has dimensions of <number of time points> x <number of channels>
. Columns in dataTimeSeries
are mapped to the measurement list (measurementList
variable described below).
dataTimeSeries
can be compressed using the HDF5 filter (using the built-in deflate
filter or 3rd party filters such as 305-LZO
or 307-bzip2
Chunked data is allowed to support real-time streaming of data in this array.
The filename the Snirf object was loaded from and will save to.
None if not associated with a Group on disk.
The HDF5 relative location indentifier.
None if not associataed with a Group on disk.
SNIRF field measurementList
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
The measurement list. This variable serves to map the data array onto the probe geometry (sources and detectors), data type, and wavelength. This variable is an array structure that has the size <number of channels>
that describes the corresponding column in the data matrix. For example, the measurementList3
describes the third column of the data matrix (i.e. dataTimeSeries(:,3)
).
Each element of the array is a structure which describes the measurement conditions for this data with the following fields:
SNIRF field time
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
The time
variable. This provides the acquisition time of the measurement relative to the time origin. This will usually be a straight line with slope equal to the acquisition frequency, but does not need to be equal spacing. For the special case of equal sample spacing an array of length <2>
is allowed where the first entry is the start time and the second entry is the sample time spacing in TimeUnit
specified in the metaDataTags
. The default time unit is in second ("s"). For example, a time spacing of 0.2 (s) indicates a sampling rate of 5 Hz.
- Option 1 - The size of this variable is
<number of time points>
and corresponds to the sample time of every data point * Option 2- The size of this variable is<2>
and corresponds to the start time and sample spacing.
Chunked data is allowed to support real-time streaming of data in this array.
is_empty()
If the Group has no member Groups or Datasets.
Returns:
bool
: True if empty, False if not
save(*args)
Group level save to a SNIRF file on disk.
Args:
args
(str or h5py.File): A path to a closed SNIRF file on disk or an openh5py.File
instance
Examples:
save can be called on a Group already on disk to overwrite the current contents: mysnirf.nirs[0].probe.save()
or using a new filename to write the Group there:
>>> mysnirf.nirs[0].probe.save(<new destination>)
__init__(h: File, cfg: SnirfConfig)
The filename the Snirf object was loaded from and will save to.
append(item)
Append a new Group to the IndexedGroup.
Args:
item
: must be of type _element
appendGroup()
Insert a new Group at the end of the Indexed Group.
Creates an empty Group with the appropriate name at the end of the list of Groups managed by the IndexedGroup.
insert(i, item)
Insert a new Group into the IndexedGroup.
Args:
i
(int): an indexitem
: must be of type _element
insertGroup(i)
Insert a new Group following the index given.
Creates an empty Group with a placeholder name within the list of Groups managed by the IndexedGroup. The placeholder name will be replaced with a name with the correct order once save
is called.
Args:
i
(int): the position at which to insert the new Group
is_empty()
Returns True if the Indexed Group has no member Groups with contents.
Returns:
bool
: True if empty, False if not
save(*args)
Save the groups to a SNIRF file on disk.
When saving, the naming convention defined by the SNIRF spec is enforced: groups are named /<name>1
, /<name>2
, /<name>3
, and so on.
Args:
args
(str or h5py.File): A path to a closed SNIRF file on disk or an openh5py.File
instance
Examples:
save can be called on an Indexed Group already on disk to overwrite the current contents: mysnirf.nirs[0].stim.save()
or using a new filename to write the Indexed Group there:
>>> mysnirf.nirs[0].stim.save(<new destination>)
Wrapper for an element of indexed group MeasurementList
.
__init__(gid: GroupID, cfg: SnirfConfig)
SNIRF field dataType
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
Data-type identifier. See Appendix for list possible values.
SNIRF field dataTypeIndex
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
Data-type specific parameter indices. The data type index specifies additional data type specific parameters that are further elaborated by other fields in the probe structure, as detailed below. Note that the Time Domain and Diffuse Correlation Spectroscopy data types have two additional parameters and so the data type index must be a vector with 2 elements that index the additional parameters. One use of this parameter is as a stimulus condition index when measurementList(k).dataType = 99999
(i.e, processed
and measurementList(k).dataTypeLabel = 'HRF ...'
.
SNIRF field dataTypeLabel
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
Data-type label. Only required if dataType is "processed" (99999
). See Appendix for list of possible values.
SNIRF field dataUnit
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
International System of Units (SI units) identifier for the given channel. Encoding should follow the CMIXF-12 standard, avoiding special unicode symbols like U+03BC (m) or U+00B5 (u) and using '/' rather than 'per' for units such as V/us
. The recommended export format is in unscaled units such as V, s, Mole.
SNIRF field detectorGain
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
Detector gain
SNIRF field detectorIndex
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
Index of the detector.
SNIRF field detectorModuleIndex
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
Index of the module that contains the detector of the channel. This index must be used together with sourceModuleIndex
, and can not be used when moduleIndex
presents.
For example, if measurementList5
is a structure with sourceIndex=2
, detectorIndex=3
, wavelengthIndex=1
, dataType=1
, dataTypeIndex=1
would imply that the data in the 5th column of the dataTimeSeries
variable was measured with source #2 and detector #3 at wavelength #1. Wavelengths (in nanometers) are described in the probe.wavelengths
variable (described later). The data type in this case is 1, implying that it was a continuous wave measurement. The complete list of currently supported data types is found in the Appendix. The data type index specifies additional data type specific parameters that are further elaborated by other fields in the probe
structure, as detailed below. Note that the Time Domain and Diffuse Correlation Spectroscopy data types have two additional parameters and so the data type index must be a vector with 2 elements that index the additional parameters.
sourcePower
provides the option for information about the source power for that channel to be saved along with the data. The units are not defined, unless the user takes the option of using a metaDataTag
described below to define, for instance, sourcePowerUnit
. detectorGain
provides the option for information about the detector gain for that channel to be saved along with the data.
Note: The source indices generally refer to the optode naming (probe positions) and not necessarily the physical laser numbers on the instrument. The same is true for the detector indices. Each source optode would generally, but not necessarily, have 2 or more wavelengths (hence lasers) plugged into it in order to calculate deoxy- and oxy-hemoglobin concentrations. The data from these two wavelengths will be indexed by the same source, detector, and data type values, but have different wavelength indices. Using the same source index for lasers at the same location but with different wavelengths simplifies the bookkeeping for converting intensity measurements into concentration changes. As described below, optional variables probe.sourceLabels
and probe.detectorLabels
are provided for indicating the instrument specific label for sources and detectors.
The filename the Snirf object was loaded from and will save to.
None if not associated with a Group on disk.
The HDF5 relative location indentifier.
None if not associataed with a Group on disk.
SNIRF field moduleIndex
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
Index of a repeating module. If moduleIndex
is provided while useLocalIndex
is set to true
, then, both measurementList(k).sourceIndex
and measurementList(k).detectorIndex
are assumed to be the local indices of the same module specified by moduleIndex
. If the source and detector are located on different modules, one must use sourceModuleIndex
and detectorModuleIndex
instead to specify separate parent module indices. See below.
SNIRF field sourceIndex
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
Index of the source.
SNIRF field sourceModuleIndex
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
Index of the module that contains the source of the channel. This index must be used together with detectorModuleIndex
, and can not be used when moduleIndex
presents.
SNIRF field sourcePower
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
The units are not defined, unless the user takes the option of using a metaDataTag
as described below.
SNIRF field wavelengthActual
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
Actual (measured) wavelength in nm, if available, for the source in a given channel.
SNIRF field wavelengthEmissionActual
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
Actual (measured) emission wavelength in nm, if available, for the source in a given channel.
SNIRF field wavelengthIndex
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
Index of the "nominal" wavelength (in probe.wavelengths
).
is_empty()
If the Group has no member Groups or Datasets.
Returns:
bool
: True if empty, False if not
save(*args)
Group level save to a SNIRF file on disk.
Args:
args
(str or h5py.File): A path to a closed SNIRF file on disk or an openh5py.File
instance
Examples:
save can be called on a Group already on disk to overwrite the current contents: mysnirf.nirs[0].probe.save()
or using a new filename to write the Group there:
>>> mysnirf.nirs[0].probe.save(<new destination>)
Interface for indexed group MeasurementList
.
Can be indexed like a list to retrieve MeasurementList
elements.
To add or remove an element from the list, use the appendGroup
method and the del
operator, respectively.
The measurement list. This variable serves to map the data array onto the probe geometry (sources and detectors), data type, and wavelength. This variable is an array structure that has the size <number of channels>
that describes the corresponding column in the data matrix. For example, the measurementList3
describes the third column of the data matrix (i.e. dataTimeSeries(:,3)
).
Each element of the array is a structure which describes the measurement conditions for this data with the following fields:
__init__(h: File, cfg: SnirfConfig)
The filename the Snirf object was loaded from and will save to.
append(item)
Append a new Group to the IndexedGroup.
Args:
item
: must be of type _element
appendGroup()
Insert a new Group at the end of the Indexed Group.
Creates an empty Group with the appropriate name at the end of the list of Groups managed by the IndexedGroup.
insert(i, item)
Insert a new Group into the IndexedGroup.
Args:
i
(int): an indexitem
: must be of type _element
insertGroup(i)
Insert a new Group following the index given.
Creates an empty Group with a placeholder name within the list of Groups managed by the IndexedGroup. The placeholder name will be replaced with a name with the correct order once save
is called.
Args:
i
(int): the position at which to insert the new Group
is_empty()
Returns True if the Indexed Group has no member Groups with contents.
Returns:
bool
: True if empty, False if not
save(*args)
Save the groups to a SNIRF file on disk.
When saving, the naming convention defined by the SNIRF spec is enforced: groups are named /<name>1
, /<name>2
, /<name>3
, and so on.
Args:
args
(str or h5py.File): A path to a closed SNIRF file on disk or an openh5py.File
instance
Examples:
save can be called on an Indexed Group already on disk to overwrite the current contents: mysnirf.nirs[0].stim.save()
or using a new filename to write the Indexed Group there:
>>> mysnirf.nirs[0].stim.save(<new destination>)
__init__(gid: GroupID, cfg: SnirfConfig)
SNIRF field data
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
- Allowed attribute:
names
This is a numeric 2-D array with at least 3 columns, specifying the stimulus time course for the jth condition. Each row corresponds to a specific stimulus trial. The first three columns indicate [starttime duration value]
. The starttime, in seconds, is the time relative to the time origin when the stimulus takes on a value; the duration is the time in seconds that the stimulus value continues, and value is the stimulus amplitude. The number of rows is not constrained. (see examples in the appendix).
Additional columns can be used to store user-specified data associated with each stimulus trial. An optional record /nirs(i)/stim(j)/dataLabels
can be used to annotate the meanings of each data column.
SNIRF field dataLabels
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This is a string array providing annotations for each data column in /nirs(i)/stim(j)/data
. Each element of the array must be a string; the total length of this array must be the same as the column number of /nirs(i)/stim(j)/data
, including the first 3 required columns.
The filename the Snirf object was loaded from and will save to.
None if not associated with a Group on disk.
The HDF5 relative location indentifier.
None if not associataed with a Group on disk.
SNIRF field name
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This is a string describing the jth stimulus condition.
is_empty()
If the Group has no member Groups or Datasets.
Returns:
bool
: True if empty, False if not
save(*args)
Group level save to a SNIRF file on disk.
Args:
args
(str or h5py.File): A path to a closed SNIRF file on disk or an openh5py.File
instance
Examples:
save can be called on a Group already on disk to overwrite the current contents: mysnirf.nirs[0].probe.save()
or using a new filename to write the Group there:
>>> mysnirf.nirs[0].probe.save(<new destination>)
__init__(h: File, cfg: SnirfConfig)
The filename the Snirf object was loaded from and will save to.
append(item)
Append a new Group to the IndexedGroup.
Args:
item
: must be of type _element
appendGroup()
Insert a new Group at the end of the Indexed Group.
Creates an empty Group with the appropriate name at the end of the list of Groups managed by the IndexedGroup.
insert(i, item)
Insert a new Group into the IndexedGroup.
Args:
i
(int): an indexitem
: must be of type _element
insertGroup(i)
Insert a new Group following the index given.
Creates an empty Group with a placeholder name within the list of Groups managed by the IndexedGroup. The placeholder name will be replaced with a name with the correct order once save
is called.
Args:
i
(int): the position at which to insert the new Group
is_empty()
Returns True if the Indexed Group has no member Groups with contents.
Returns:
bool
: True if empty, False if not
save(*args)
Save the groups to a SNIRF file on disk.
When saving, the naming convention defined by the SNIRF spec is enforced: groups are named /<name>1
, /<name>2
, /<name>3
, and so on.
Args:
args
(str or h5py.File): A path to a closed SNIRF file on disk or an openh5py.File
instance
Examples:
save can be called on an Indexed Group already on disk to overwrite the current contents: mysnirf.nirs[0].stim.save()
or using a new filename to write the Indexed Group there:
>>> mysnirf.nirs[0].stim.save(<new destination>)
__init__(gid: GroupID, cfg: SnirfConfig)
SNIRF field dataTimeSeries
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This is the aux data variable. This variable has dimensions of <number of time points> x <number of channels>
. If multiple channels of related data are generated by a system, they may be encoded in the multiple columns of the time series (i.e. complex numbers). For example, a system containing more than one accelerometer may output this data as a set of ACCEL_X
/ACCEL_Y
/ACCEL_Z
auxiliary time series, where each has the dimension of <number of time points> x <number of accelerometers>
. Note that it is NOT recommended to encode the various accelerometer dimensions as multiple channels of the same aux
Group: instead follow the "ACCEL_X"
, "ACCEL_Y"
, "ACCEL_Z"
naming conventions described in the appendix. Chunked data is allowed to support real-time data streaming.
SNIRF field dataUnit
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
International System of Units (SI units) identifier for the given channel. Encoding should follow the CMIXF-12 standard, avoiding special unicode symbols like U+03BC (m) or U+00B5 (u) and using '/' rather than 'per' for units such as V/us
. The recommended export format is in unscaled units such as V, s, Mole.
The filename the Snirf object was loaded from and will save to.
None if not associated with a Group on disk.
The HDF5 relative location indentifier.
None if not associataed with a Group on disk.
SNIRF field name
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This is string describing the jth auxiliary data timecourse. While auxiliary data can be given any title, standard names for commonly used auxiliary channels (i.e. accelerometer data) are specified in the appendix.
SNIRF field time
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
The time variable. This provides the acquisition time (in TimeUnit
units) of the aux measurement relative to the time origin. This will usually be a straight line with slope equal to the acquisition frequency, but does not need to be equal spacing. The size of this variable is <number of time points>
or <2>
similar to definition of the /nirs(i)/data(j)/time
field.
Chunked data is allowed to support real-time data streaming
SNIRF field timeOffset
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This variable specifies the offset of the file time origin relative to absolute (clock) time in TimeUnit
units.
is_empty()
If the Group has no member Groups or Datasets.
Returns:
bool
: True if empty, False if not
save(*args)
Group level save to a SNIRF file on disk.
Args:
args
(str or h5py.File): A path to a closed SNIRF file on disk or an openh5py.File
instance
Examples:
save can be called on a Group already on disk to overwrite the current contents: mysnirf.nirs[0].probe.save()
or using a new filename to write the Group there:
>>> mysnirf.nirs[0].probe.save(<new destination>)
__init__(h: File, cfg: SnirfConfig)
The filename the Snirf object was loaded from and will save to.
append(item)
Append a new Group to the IndexedGroup.
Args:
item
: must be of type _element
appendGroup()
Insert a new Group at the end of the Indexed Group.
Creates an empty Group with the appropriate name at the end of the list of Groups managed by the IndexedGroup.
insert(i, item)
Insert a new Group into the IndexedGroup.
Args:
i
(int): an indexitem
: must be of type _element
insertGroup(i)
Insert a new Group following the index given.
Creates an empty Group with a placeholder name within the list of Groups managed by the IndexedGroup. The placeholder name will be replaced with a name with the correct order once save
is called.
Args:
i
(int): the position at which to insert the new Group
is_empty()
Returns True if the Indexed Group has no member Groups with contents.
Returns:
bool
: True if empty, False if not
save(*args)
Save the groups to a SNIRF file on disk.
When saving, the naming convention defined by the SNIRF spec is enforced: groups are named /<name>1
, /<name>2
, /<name>3
, and so on.
Args:
args
(str or h5py.File): A path to a closed SNIRF file on disk or an openh5py.File
instance
Examples:
save can be called on an Indexed Group already on disk to overwrite the current contents: mysnirf.nirs[0].stim.save()
or using a new filename to write the Indexed Group there:
>>> mysnirf.nirs[0].stim.save(<new destination>)
__init__(*args, dynamic_loading: bool = False, enable_logging: bool = False)
The filename the Snirf object was loaded from and will save to.
SNIRF field formatVersion
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This is a string that specifies the version of the file format. This document describes format version "1.0"
The HDF5 relative location indentifier.
None if not associataed with a Group on disk.
SNIRF field nirs
.
If dynamic_loading=True, the data is loaded from the SNIRF file only when accessed through the getter
This group stores one set of NIRS data. This can be extended by adding the count number (e.g. /nirs1
, /nirs2
,...) to the group name. This is intended to allow the storage of 1 or more complete NIRS datasets inside a single SNIRF document. For example, a two-subject hyperscanning can be stored using the notation * /nirs1
= first subject's data * /nirs2
= second subject's data The use of a non-indexed (e.g. /nirs
) entry is allowed when only one entry is present and is assumed to be entry 1.
close()
Close the file underlying a Snirf
instance.
After closing, the underlying SNIRF file cannot be accessed from this interface again. Use close
if you need to open a new interface on the same HDF5 file.
close
is called automatically by the destructor.
copy() → Snirf
Return a copy of the Snirf instance.
A copy of a Snirf instance is a brand new HDF5 file in memory. This can be expensive to create. Note that in lieu of copying you can make assignments between Snirf instances.
is_empty()
If the Group has no member Groups or Datasets.
Returns:
bool
: True if empty, False if not
save(*args)
Save a SNIRF file to disk.
Args:
args
(str or h5py.File or file-like): A path to a closed or nonexistant SNIRF file on disk or an openh5py.File
instance
Examples:
save can overwrite the current contents of a Snirf file: mysnirf.save()
or take a new filename to write the file there:
>>> mysnirf.save(<new destination>)
or write to an IO stream:
>>> mysnirf.save(<io.BytesIO stream>)
validate() → ValidationResult
Validate a Snirf
instance.
Returns the validity of the current state of a Snirf
object, including modifications made in memory to a loaded SNIRF file.
Returns:
ValidationResult
: truthy structure containing detailed validation results
This file was automatically generated via lazydocs.