aqnwb 0.4.0
Loading...
Searching...
No Matches
NWBFile.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cstdint>
5#include <memory>
6#include <optional>
7#include <string>
8#include <string_view>
9#include <vector>
10
11#include "Types.hpp"
12#include "Utils.hpp"
13#include "io/BaseIO.hpp"
14#include "io/ReadIO.hpp"
21#include "nwb/file/Subject.hpp"
22#include "spec/core.hpp"
23
28namespace AQNWB::NWB
29{
30
44class NWBFile : public NWBContainer
45{
46public:
47 // Register the NWBFile as a subclass of NWBContainer
49
50 // Static paths for NWB file structure
52 inline const static std::string ACQUISITION_PATH = "/acquisition";
54 inline const static std::string SPECIFICATIONS_PATH = "/specifications";
56 inline const static std::string PROCESSING_PATH = "/processing";
58 inline const static std::string STIMULUS_PATH = "/stimulus";
60 inline const static std::string GENERAL_PATH = "/general";
62 inline const static std::string ANALYSIS_PATH = "/analysis";
64 inline const static std::string EVENTS_PATH = "/events";
66 inline const static std::string INTERVALS_PATH = "/intervals";
67
73 static std::shared_ptr<NWBFile> create(std::shared_ptr<IO::BaseIO> io)
74 {
75 return RegisteredType::create<NWBFile>("/", io);
76 }
77
78protected:
83 explicit NWBFile(std::shared_ptr<IO::BaseIO> io);
84
88 NWBFile(const std::string& path, std::shared_ptr<IO::BaseIO> io);
89
90public:
94 NWBFile(const NWBFile&) = delete;
95
99 NWBFile& operator=(const NWBFile&) = delete;
100
104 ~NWBFile() override;
105
123 Status initialize(const std::string& identifierText,
124 const std::string& description = "a recording session",
125 const std::string& dataCollection = "",
126 const std::string& sessionStartTime = "",
127 const std::string& timestampsReferenceTime = "",
128 const std::optional<AQNWB::NWB::Subject::SubjectSpec>&
129 subjectSpec = std::nullopt);
130
138 bool isInitialized() const;
139
156 std::shared_ptr<ElectrodesTable> createElectrodesTable(
157 std::vector<Types::ChannelVector> recordingArrays,
158 bool finalizeTable = true,
159 const SizeType rowChunkSize = 100);
160
171 static Status requireEventsGroup(std::shared_ptr<IO::BaseIO> io);
172
183 static Status requireIntervalsGroup(std::shared_ptr<IO::BaseIO> io);
184
209 std::shared_ptr<EventsTable> createEventsTable(
210 const std::string& name,
211 const std::string& description,
212 const std::optional<std::string>& sourceDescription = std::nullopt,
213 std::optional<float> timestampResolution = std::nullopt,
214 bool createDurationColumn = false,
215 std::optional<float> durationResolution = std::nullopt,
216 const bool createAnnotationColumn = false,
217 const SizeType rowChunkSize = 100);
218
240 std::shared_ptr<EventsTable> createEventsTable(
241 const std::string& name,
242 const std::string& description,
243 const std::string& sourceDescription,
244 const std::vector<NWB::DynamicTable::DataSpecPtr>& columnSpecs);
245
252 std::shared_ptr<TimeIntervals> createEpochs(
253 const bool createTagsColumn = false, const SizeType rowChunkSize = 100);
254
261 std::shared_ptr<TimeIntervals> createTrials(
262 const bool createTagsColumn = false, const SizeType rowChunkSize = 100);
263
270 std::shared_ptr<TimeIntervals> createInvalidTimes(
271 const bool createTagsColumn = false, const SizeType rowChunkSize = 100);
272
285 std::shared_ptr<TimeIntervals> createTimeIntervals(
286 const std::string& name,
287 const std::string& description,
288 const bool createTagsColumn = false,
289 const SizeType rowChunkSize = 100);
290
307 std::shared_ptr<TimeIntervals> createTimeIntervals(
308 const std::string& name,
309 const std::string& description,
310 const std::vector<NWB::DynamicTable::DataSpecPtr>& columnSpecs);
311
329 std::vector<Types::ChannelVector> recordingArrays,
330 std::vector<std::string> recordingNames,
331 const IO::BaseDataType& dataType,
332 std::vector<SizeType>& containerIndexes);
333
348 std::vector<Types::ChannelVector> recordingArrays,
349 std::vector<std::string> recordingNames,
350 const IO::BaseDataType& dataType,
351 std::vector<SizeType>& containerIndexes);
352
361 Status createAnnotationSeries(const std::vector<std::string>& recordingNames,
362 std::vector<SizeType>& containerIndexes);
363
366 "intervals/epochs",
367 "Table of experimental epochs.")
368
371 "intervals/trials",
372 "Table of experimental trials.")
373
376 "intervals/invalid_times",
377 "Table of invalid times.")
378
381 ElectrodesTable::electrodesTablePath,
382 "table with the extracellular electrodes")
383
385 std::string,
386 "nwb_version",
387 File version string)
388
391 std::string,
392 "file_create_date",
393 A record of the date the file was created and of
394 subsequent modifications)
395
398 std::string,
399 "identifier",
400 A unique text identifier for the file)
401
404 std::string,
405 "session_description",
406 A description of the experimental session and data in the
407 file)
408
411 std::string,
412 "session_start_time",
413 Date and time of the experiment or session start)
414
417 std::string,
418 "timestamps_reference_time",
419 Date and time corresponding to time zero of all
420 timestamps)
421
425 "acquisition",
426 Get a TimeSeries stored in the acquisition
427 group)
428
432 "processing",
433 Get a ProcessingModule stored in the
434 processing group)
435
439 "intervals",
440 Get a TimeIntervals object stored in the
441 intervals group)
442
446 "events",
447 Get an EventsTable stored in the events group)
448
449protected:
465 Status createFileStructure(const std::string& identifierText,
466 const std::string& description,
467 const std::string& dataCollection,
468 const std::string& sessionStartTime,
469 const std::string& timestampsReferenceTime);
470
471private:
478 void cacheSpecifications(const Types::NamespaceInfo& namespaceInfo);
479
484};
485
486} // namespace AQNWB::NWB
AQNWB::Types::Status Status
Definition BaseIO.hpp:21
AQNWB::Types::SizeType SizeType
Definition Channel.hpp:8
#define REGISTER_SUBCLASS(T, BASE, NAMESPACE)
Macro to register a subclass with the RegisteredType class registry.
Definition RegisteredType.hpp:547
#define DEFINE_ATTRIBUTE_FIELD(name, default_type, fieldPath, description)
Defines a lazy-loaded attribute field accessor function.
Definition RegisteredType.hpp:580
#define DEFINE_DATASET_FIELD(readName, writeName, default_type, fieldPath, description)
Defines a lazy-loaded dataset field accessor function.
Definition RegisteredType.hpp:619
#define DEFINE_UNNAMED_REGISTERED_FIELD(readName, writeName, registeredType, fieldPrefixPath, description)
Defines a lazy-loaded accessor function for reading fields that are RegisteredTypes that do not have ...
Definition RegisteredType.hpp:711
#define DEFINE_REGISTERED_FIELD(name, registeredType, fieldPath, description)
Defines a lazy-loaded accessor function for reading fields that are RegisteredTypes.
Definition RegisteredType.hpp:672
Represents a base data type.
Definition BaseIO.hpp:47
Represents a table containing electrode metadata.
Definition ElectrodesTable.hpp:17
A column-based table to store information about events, one event per row. Use EventsTable when each ...
Definition EventsTable.hpp:35
Status initialize()
Initialize the object.
Definition NWBContainer.cpp:17
NWBContainer(const std::string &path, std::shared_ptr< AQNWB::IO::BaseIO > io)
Constructor.
Definition NWBContainer.cpp:11
static const std::string STIMULUS_PATH
The path to the stimulus group in the NWB file.
Definition NWBFile.hpp:58
std::shared_ptr< AQNWB::IO::BaseRecordingData > recordTimestampsReferenceTime(bool reset=false)
Status createSpikeEventSeries(std::vector< Types::ChannelVector > recordingArrays, std::vector< std::string > recordingNames, const IO::BaseDataType &dataType, std::vector< SizeType > &containerIndexes)
Create SpikeEventSeries objects to record data into. Created objects are automatically added to the I...
Definition NWBFile.cpp:590
std::unique_ptr< RTYPE > createAquisitionSeries(std::string &objectName) const
std::unique_ptr< RTYPE > createProcessingModule(std::string &objectName) const
std::shared_ptr< AQNWB::IO::BaseRecordingData > recordFileCreateDate(bool reset=false)
static Status requireIntervalsGroup(std::shared_ptr< IO::BaseIO > io)
Ensure that the intervals group exists in the NWB file.
Definition NWBFile.cpp:317
std::shared_ptr< RTYPE > readInvalidTimes() const
NWBFile(std::shared_ptr< IO::BaseIO > io)
Constructor for NWBFile class.
Definition NWBFile.cpp:37
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::DatasetField, VTYPE > > readTimestampsReferenceTime() const
std::unique_ptr< RTYPE > createEventsTableInstance(std::string &objectName) const
std::shared_ptr< TimeIntervals > createInvalidTimes(const bool createTagsColumn=false, const SizeType rowChunkSize=100)
Create the Invalid Times table in the INTERVALS_PATH group.
Definition NWBFile.cpp:442
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::DatasetField, VTYPE > > readSessionDescription() const
std::unique_ptr< RTYPE > createTimeIntervalsInstance(std::string &objectName) const
NWBFile(const NWBFile &)=delete
Deleted copy constructor to prevent construction-copying.
static const std::string ACQUISITION_PATH
The path to the acquisition group in the NWB file.
Definition NWBFile.hpp:52
std::shared_ptr< AQNWB::IO::BaseRecordingData > recordIdentifier(bool reset=false)
std::shared_ptr< RTYPE > readTimeIntervals(std::string &objectName) const
std::shared_ptr< RTYPE > readAquisitionSeries(std::string &objectName) const
static Status requireEventsGroup(std::shared_ptr< IO::BaseIO > io)
Ensure that the events group exists in the NWB file.
Definition NWBFile.cpp:303
std::shared_ptr< TimeIntervals > createEpochs(const bool createTagsColumn=false, const SizeType rowChunkSize=100)
Create the Epochs table in the INTERVALS_PATH group.
Definition NWBFile.cpp:420
std::shared_ptr< RTYPE > readElectrodesTable() const
std::shared_ptr< TimeIntervals > createTimeIntervals(const std::string &name, const std::string &description, const bool createTagsColumn=false, const SizeType rowChunkSize=100)
Create a TimeIntervals table in the INTERVALS_PATH group. Note, this function will fail if the file i...
Definition NWBFile.cpp:451
static const std::string EVENTS_PATH
The path to the root events group in the NWB file.
Definition NWBFile.hpp:64
Status createFileStructure(const std::string &identifierText, const std::string &description, const std::string &dataCollection, const std::string &sessionStartTime, const std::string &timestampsReferenceTime)
Creates the default file structure. Note, this function will fail if the file is in a mode where new ...
Definition NWBFile.cpp:167
std::shared_ptr< AQNWB::IO::BaseRecordingData > recordSessionStartTime(bool reset=false)
std::shared_ptr< RTYPE > readProcessingModule(std::string &objectName) const
static std::shared_ptr< NWBFile > create(const std::string &path, std::shared_ptr< AQNWB::IO::BaseIO > io)
std::shared_ptr< TimeIntervals > createTrials(const bool createTagsColumn=false, const SizeType rowChunkSize=100)
Create the Trials table in the INTERVALS_PATH group.
Definition NWBFile.cpp:431
NWBFile & operator=(const NWBFile &)=delete
Deleted copy assignment operator to prevent copying.
std::shared_ptr< RTYPE > readEpochs() const
std::shared_ptr< RTYPE > readTrials() const
std::unique_ptr< ElectrodesTable > m_electrodeTable
The ElectrodesTable for the file.
Definition NWBFile.hpp:483
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::DatasetField, VTYPE > > readIdentifier() const
Status createAnnotationSeries(const std::vector< std::string > &recordingNames, std::vector< SizeType > &containerIndexes)
Create AnnotationSeries objects to record data into. Created objects are automatically added to the I...
Definition NWBFile.cpp:665
void cacheSpecifications(const Types::NamespaceInfo &namespaceInfo)
Saves the specification files for the schema.
Definition NWBFile.cpp:701
static const std::string GENERAL_PATH
The path to the general group in the NWB file.
Definition NWBFile.hpp:60
bool isInitialized() const
Check if the NWB file is initialized.
Definition NWBFile.cpp:127
~NWBFile() override
Destructor for NWBFile class.
Definition NWBFile.cpp:52
std::shared_ptr< RTYPE > readEventsTable(std::string &objectName) const
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::AttributeField, VTYPE > > readNWBVersion() const
static const std::string PROCESSING_PATH
The path to the processing group in the NWB file.
Definition NWBFile.hpp:56
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::DatasetField, VTYPE > > readFileCreateDate() const
std::shared_ptr< ElectrodesTable > createElectrodesTable(std::vector< Types::ChannelVector > recordingArrays, bool finalizeTable=true, const SizeType rowChunkSize=100)
Create ElectrodesTable. Note, this function will fail if the file is in a mode where new objects cann...
Definition NWBFile.cpp:230
std::shared_ptr< EventsTable > createEventsTable(const std::string &name, const std::string &description, const std::optional< std::string > &sourceDescription=std::nullopt, std::optional< float > timestampResolution=std::nullopt, bool createDurationColumn=false, std::optional< float > durationResolution=std::nullopt, const bool createAnnotationColumn=false, const SizeType rowChunkSize=100)
Create an EventsTable in the EVENTS_PATH group. Note, this function will fail if the file is in a mod...
Definition NWBFile.cpp:331
Status createElectricalSeries(std::vector< Types::ChannelVector > recordingArrays, std::vector< std::string > recordingNames, const IO::BaseDataType &dataType, std::vector< SizeType > &containerIndexes)
Create ElectricalSeries objects to record data into. Created objects are automatically added to the I...
Definition NWBFile.cpp:532
static const std::string SPECIFICATIONS_PATH
The path to the specification group in the NWB file.
Definition NWBFile.hpp:54
static const std::string ANALYSIS_PATH
The path to the analysis group in the NWB file.
Definition NWBFile.hpp:62
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::DatasetField, VTYPE > > readSessionStartTime() const
static const std::string INTERVALS_PATH
The path to the root intervals group in the NWB file.
Definition NWBFile.hpp:66
std::shared_ptr< AQNWB::IO::BaseRecordingData > recordSessionDescription(bool reset=false)
A collection of processed data.
Definition ProcessingModule.hpp:27
static std::shared_ptr< RegisteredType > create(const std::string &fullClassName, const std::string &path, std::shared_ptr< IO::BaseIO > io, bool fallbackToBase=false)
Create or retrieve the canonical instance of a registered subclass.
Definition RegisteredType.cpp:87
A container for aggregating epoch data and the TimeSeries that each epoch applies to.
Definition TimeIntervals.hpp:30
General purpose time series.
Definition TimeSeries.hpp:19
The namespace for IO components of AqNWB.
Namespace for all classes related to the NWB data standard.
const std::string namespaceName
Definition core.hpp:21
Provides definitions for various types used in the project.
Definition Types.hpp:24