From 0422cfbab1692c57eea3743bdac7b88ee0d4a7dc Mon Sep 17 00:00:00 2001 From: Pierre Yger Date: Fri, 5 Jul 2024 14:31:18 +0200 Subject: [PATCH] Mcsh5 offsets and proper scaling in uV for return_scaled (#2988) Mcsh5 offsets and proper scaling in uV for return_scaled --- src/spikeinterface/extractors/mcsh5extractors.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/spikeinterface/extractors/mcsh5extractors.py b/src/spikeinterface/extractors/mcsh5extractors.py index f419b7e64d..9485536d97 100644 --- a/src/spikeinterface/extractors/mcsh5extractors.py +++ b/src/spikeinterface/extractors/mcsh5extractors.py @@ -61,6 +61,9 @@ def __init__(self, file_path, stream_id=0): # set gain self.set_channel_gains(mcs_info["gain"]) + # set offsets + self.set_channel_offsets(mcs_info["offset"]) + # set other properties self.set_property("electrode_labels", mcs_info["electrode_labels"]) @@ -100,7 +103,11 @@ def get_traces(self, start_frame=None, end_frame=None, channel_indices=None): def openMCSH5File(filename, stream_id): - """Open an MCS hdf5 file, read and return the recording info.""" + """Open an MCS hdf5 file, read and return the recording info. + Specs can be found online + https://www.multichannelsystems.com/downloads/documentation?page=3 + """ + import h5py rf = h5py.File(filename, "r") @@ -121,7 +128,8 @@ def openMCSH5File(filename, stream_id): Tick = info["Tick"][0] / 1e6 exponent = info["Exponent"][0] convFact = info["ConversionFactor"][0] - gain = convFact.astype(float) * (10.0**exponent) + gain_uV = 1e6 * (convFact.astype(float) * (10.0**exponent)) + offset_uV = -1e6 * (info["ADZero"].astype(float) * (10.0**exponent)) * gain_uV nRecCh, nFrames = data.shape channel_ids = [f"Ch{ch}" for ch in info["ChannelID"]] @@ -149,8 +157,9 @@ def openMCSH5File(filename, stream_id): "num_channels": nRecCh, "channel_ids": channel_ids, "electrode_labels": electrodeLabels, - "gain": gain, + "gain": gain_uV, "dtype": dtype, + "offset": offset_uV, } return mcs_info