From 0756f09ed0ed476efc4f466c2d8e6e7e4a65ae2a Mon Sep 17 00:00:00 2001 From: Pavel Kulik Date: Tue, 13 Dec 2022 13:26:35 -0800 Subject: [PATCH] Update sample rate computation --- Source/FileSource/NWBFileSource.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Source/FileSource/NWBFileSource.cpp b/Source/FileSource/NWBFileSource.cpp index d6e476f..5bd8714 100644 --- a/Source/FileSource/NWBFileSource.cpp +++ b/Source/FileSource/NWBFileSource.cpp @@ -120,16 +120,30 @@ void NWBFileSource::fillRecordInfo() attr = data.openAttribute("conversion"); attr.read(PredType::NATIVE_FLOAT, &bitVolts); - //Compute sample rate from first few timestamps data = dataSource.openDataSet("timestamps"); - dSpace = data.getSpace(); - dSpace.getSimpleExtentDims(dims); + info.sampleRate = -1.0f; - HeapBlock tsArray(dims[0]); - data.read(tsArray.getData(), PredType::NATIVE_DOUBLE); + if (data.attrExists("interval")) + { + attr = data.openAttribute("interval"); + double interval; + attr.read(PredType::NATIVE_DOUBLE, &interval); + double sampleRate = 1.0f / interval; - info.sampleRate = 2 / (tsArray[2] - tsArray[0]); + info.sampleRate = sampleRate; + } + else + { + dSpace = data.getSpace(); + dSpace.getSimpleExtentDims(dims); + + HeapBlock tsArray(dims[0]); + data.read(tsArray.getData(), PredType::NATIVE_DOUBLE); + + if (tsArray[2] > 0 && tsArray[0] > 0) + info.sampleRate = 2 / (tsArray[2] - tsArray[0]); + } //Get the first sample number to align events data = dataSource.openDataSet("sync");