Skip to content

Commit

Permalink
Merge pull request NeuralEnsemble#1448 from gkBCCN/extract_gain
Browse files Browse the repository at this point in the history
Read gain scaling from .rec header.
alejoe91 authored Apr 9, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents fa3ebe4 + 83a84b2 commit e9b57b0
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions neo/rawio/spikegadgetsrawio.py
Original file line number Diff line number Diff line change
@@ -55,10 +55,13 @@ def __init__(self, filename="", selected_streams=None):
Notes
-----
This file format has multiple version. New versions include the gain for scaling.
The current implementation does not contain this feature because we don't have
files to test this. So now the gain is "hardcoded" to 1, and so units are
not handled correctly.
This file format has multiple versions:
- Newer versions include the gain for scaling to microvolts [uV].
- If the scaling is not found in the header, the gain will be "hardcoded" to 1,
in which case the units are not handled correctly.
This will not affect functions that do not rely on the data having physical units,
e.g., _get_analogsignal_chunk, but functions such as rescale_signal_raw_to_float
will be inaccurate.
Examples
--------
@@ -172,13 +175,22 @@ def _parse_header(self):
self._mask_channels_bytes[stream_id] = []

chan_ind = 0
self.is_scaleable = "spikeScalingToUv" in sconf[0].attrib
if not self.is_scaleable:
self.logger.warning("Unable to read channel gain scaling (to uV) from .rec header. Data has no physical units!")

for trode in sconf:
if "spikeScalingToUv" in trode.attrib:
gain = float(trode.attrib["spikeScalingToUv"])
units = "uV"
else:
gain = 1 # revert to hardcoded gain
units = ""

for schan in trode:
name = "trode" + trode.attrib["id"] + "chan" + schan.attrib["hwChan"]
chan_id = schan.attrib["hwChan"]
# TODO LATER : handle gain correctly according the file version
units = ""
gain = 1.0

offset = 0.0
signal_channels.append(
(name, chan_id, self._sampling_rate, "int16", units, gain, offset, stream_id)

0 comments on commit e9b57b0

Please sign in to comment.