Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add read tests for TimeSeries , VectorData, Data, ElementIdentifers, Device` #124

Merged
merged 25 commits into from
Jan 11, 2025
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
134fb4b
Add missing offset attriubte for TimeSeries.data
oruebel Jan 9, 2025
d07e053
Add basic unit test for TimeSeries read
oruebel Jan 9, 2025
b91dd24
Add more REQUIRE checks
oruebel Jan 9, 2025
03577da
Add missing TimeSerires.conitnuity field for write. Move timeseries-s…
oruebel Jan 9, 2025
675a8db
Fix spellcheck errors
oruebel Jan 9, 2025
2408a08
Add read test for timestamps.unit and timestamps.interval
oruebel Jan 9, 2025
f88a83d
Support using starting_time and rate with TimeSeries
oruebel Jan 9, 2025
de1f220
Add missing timeseries control and control description. Fix chunking …
oruebel Jan 9, 2025
66e85fd
Move neurodata_type and namespace attributes to Container
oruebel Jan 9, 2025
b3039b3
Merge branch 'add_read' into add_read_field_read_tests
oruebel Jan 10, 2025
f320535
Fix #126 Initiallization of VectorData
oruebel Jan 10, 2025
af9a420
Renamed testBase to testTimeSeries
oruebel Jan 10, 2025
eee8df1
Add initial unit tests for VectorData
oruebel Jan 10, 2025
e6807e2
Add additional unit tests for VectorData
oruebel Jan 10, 2025
aa30d36
Add write/read test for Data
oruebel Jan 10, 2025
e65b6c5
Add write/read test for ElementIdentifiers
oruebel Jan 10, 2025
220bcfa
Add unit test for Device
oruebel Jan 10, 2025
9e5562d
Remove extra comment
oruebel Jan 10, 2025
ec93a96
Remove extra comments
oruebel Jan 10, 2025
324ca6f
Update src/io/hdf5/HDF5IO.cpp
oruebel Jan 10, 2025
cb94d61
Update tests/testTimeSeries.cpp
oruebel Jan 10, 2025
a5b6909
Move test to RegisteredType
oruebel Jan 10, 2025
7c484be
Update writing of control_description
oruebel Jan 10, 2025
f72ca7c
Fix code linting
oruebel Jan 10, 2025
231af52
Add pass-through for control to RecordingContainers::write.. methods
oruebel Jan 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add basic unit test for TimeSeries read
oruebel committed Jan 9, 2025
commit d07e0532560e3937979c06cd2930754f5506fcde
85 changes: 85 additions & 0 deletions tests/testBase.cpp
Original file line number Diff line number Diff line change
@@ -87,4 +87,89 @@ TEST_CASE("TimeSeries", "[base]")
std::string readTSType = readContainer->getTypeName();
REQUIRE(readTSType == "TimeSeries");
}

SECTION("test reading timeseries data")
{
// setup timeseries object
std::shared_ptr<BaseIO> io = createIO("HDF5", path);
io->open();
NWB::TimeSeries ts = NWB::TimeSeries(dataPath, io);
std::string descripton = "Test TimeSeries";
std::string comments = "Test comment";
std::string unit = "volts";
float conversion = 10.0;
float resolution = 9.0;
float offset = 8.0;
ts.initialize(dataType,
unit,
descripton,
comments,
SizeArray {0},
SizeArray {1},
conversion,
resolution,
offset);

// Write data to file
Status writeStatus =
ts.writeData(dataShape, positionOffset, data.data(), timestamps.data());
REQUIRE(writeStatus == Status::Success);
io->flush();
io->close();

// Read data back from file
std::shared_ptr<BaseIO> readio = createIO("HDF5", path);
readio->open(FileMode::ReadOnly);

// Read all fields using the standard read methods
auto readRegisteredType = NWB::RegisteredType::create(dataPath, readio);
auto readTimeSeries =
std::dynamic_pointer_cast<NWB::TimeSeries>(readRegisteredType);

// Read the data
auto readDataWrapper = readTimeSeries->readData<float>();
REQUIRE(readDataWrapper->exists());
REQUIRE(readDataWrapper->getStorageObjectType()
== StorageObjectType::Dataset);
REQUIRE(readDataWrapper->getPath() == "/tsdata/data");
auto readDataValues = readDataWrapper->values();
REQUIRE_THAT(readDataValues.data, Catch::Matchers::Approx(data).margin(1));

// Read the timestamps
auto readTimestampsWrapper = readTimeSeries->readTimestamps();
auto readTimestampsValues = readTimestampsWrapper->values();
REQUIRE(readDataWrapper->getStorageObjectType()
== StorageObjectType::Dataset);
REQUIRE(readTimestampsValues.data == timestamps);

// Read the description
auto readDescriptionWrapper = readTimeSeries->readDescription();
auto readDescriptionValues = readDescriptionWrapper->values().data[0];
REQUIRE(readDescriptionValues == descripton);

// Read the comments
auto readCommentsWrapper = readTimeSeries->readComments();
auto readCommentsValues = readCommentsWrapper->values().data[0];
REQUIRE(readCommentsValues == comments);

// Read the data conversion
auto readDataConversionWrapper = readTimeSeries->readDataConversion();
auto readDataConversionValue = readDataConversionWrapper->values().data[0];
REQUIRE(readDataConversionValue == Catch::Approx(conversion));

// Read the data resolution
auto readDataResolutionWrapper = readTimeSeries->readDataResolution();
auto readDataResolutionValues = readDataResolutionWrapper->values().data[0];
REQUIRE(readDataResolutionValues == Catch::Approx(resolution));

// Read the data offset
auto readDataOffsetWrapper = readTimeSeries->readDataOffset();
auto readDataOffsetValue = readDataOffsetWrapper->values().data[0];
REQUIRE(readDataOffsetValue == Catch::Approx(offset));

// TODO Read missing readDataContinuity, readControlDescription,
// readControl, readTimestampsUnit, readTimestampsInterval,
// readStartingTimeUnit, readStartingTimeRate, readStartingTime. Some of
// these may not be written yet.
}
}