Skip to content

Commit

Permalink
Start refactor containers for read
Browse files Browse the repository at this point in the history
  • Loading branch information
oruebel committed Aug 31, 2024
1 parent 140809e commit 4d7b1ea
Show file tree
Hide file tree
Showing 18 changed files with 154 additions and 233 deletions.
16 changes: 8 additions & 8 deletions src/nwb/NWBFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ constexpr SizeType CHUNK_XSIZE = 2048;

// NWBFile

NWBFile::NWBFile(const std::string& idText, std::shared_ptr<BaseIO> io)
: identifierText(idText)
, io(io)
NWBFile::NWBFile(std::shared_ptr<BaseIO> io)
: Container("/", io)
{
}

NWBFile::~NWBFile() {}

Status NWBFile::initialize()
Status NWBFile::initialize(const std::string& idText)
{
this->identifierText = idText;
if (std::filesystem::exists(io->getFileName())) {
return io->open(false);
} else {
Expand Down Expand Up @@ -114,8 +114,8 @@ Status NWBFile::createElectricalSeries(
std::string electrodePath = "/general/extracellular_ephys/" + groupName;
std::string electricalSeriesPath = rootPath + groupName;

Device device = Device(devicePath, io, "description", "unknown");
device.initialize();
Device device = Device(devicePath, io);
device.initialize("description", "unknown");

ElectrodeGroup elecGroup =
ElectrodeGroup(electrodePath, io, "description", "unknown", device);
Expand All @@ -124,14 +124,14 @@ Status NWBFile::createElectricalSeries(
// Setup electrical series datasets
auto electricalSeries = std::make_unique<ElectricalSeries>(
electricalSeriesPath,
io,
io);
electricalSeries->initialize(
dataType,
channelVector,
"Stores continuously sampled voltage data from an "
"extracellular ephys recording",
SizeArray {0, channelVector.size()},
SizeArray {CHUNK_XSIZE, 0});
electricalSeries->initialize();
recordingContainers->addData(std::move(electricalSeries));

// Add electrode information to electrode table (does not write to datasets
Expand Down
9 changes: 4 additions & 5 deletions src/nwb/NWBFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ class RecordingContainers; // declare here because gets used in NWBFile class
* @brief The NWBFile class provides an interface for setting up and managing
* the NWB file.
*/
class NWBFile
class NWBFile : public Container
{
public:
/**
* @brief Constructor for NWBFile class.
* @param idText The identifier text for the NWBFile.
* @param io The shared pointer to the IO object.
*/
NWBFile(const std::string& idText, std::shared_ptr<BaseIO> io);
NWBFile(std::shared_ptr<BaseIO> io);

/**
* @brief Deleted copy constructor to prevent construction-copying.
Expand All @@ -53,7 +53,7 @@ class NWBFile
* @brief Initializes the NWB file by opening and setting up the file
* structure.
*/
Status initialize();
Status initialize(const std::string& idText);

/**
* @brief Finalizes the NWB file by closing it.
Expand Down Expand Up @@ -140,8 +140,7 @@ class NWBFile
std::unique_ptr<RecordingContainers> recordingContainers =
std::make_unique<RecordingContainers>("RecordingContainers");

const std::string identifierText;
std::shared_ptr<BaseIO> io;
std::string identifierText; // TODO Remove this for read
};

/**
Expand Down
5 changes: 2 additions & 3 deletions src/nwb/NWBRecording.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ Status NWBRecording::openFile(const std::string& filename,
}

// initialize nwbfile object and create base structure
nwbfile = std::make_unique<NWB::NWBFile>(generateUuid(),
createIO(IOType, filename));
nwbfile->initialize();
nwbfile = std::make_unique<NWB::NWBFile>(createIO(IOType, filename));
nwbfile->initialize(generateUuid());

// create the datasets
nwbfile->createElectricalSeries(recordingArrays);
Expand Down
32 changes: 12 additions & 20 deletions src/nwb/base/TimeSeries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,28 @@ using namespace AQNWB::NWB;

/** Constructor */
TimeSeries::TimeSeries(const std::string& path,
std::shared_ptr<BaseIO> io,
const BaseDataType& dataType,
const std::string& unit,
const std::string& description,
const std::string& comments,
const SizeArray& dsetSize,
const SizeArray& chunkSize,
const float& conversion,
const float& resolution,
const float& offset)
std::shared_ptr<BaseIO> io)
: Container(path, io)
, dataType(dataType)
, unit(unit)
, description(description)
, comments(comments)
, dsetSize(dsetSize)
, chunkSize(chunkSize)
, conversion(conversion)
, resolution(resolution)
, offset(offset)
{
}

/** Destructor */
TimeSeries::~TimeSeries() {}

void TimeSeries::initialize()
void TimeSeries::initialize(const BaseDataType& dataType,
const std::string& unit,
const std::string& description,
const std::string& comments,
const SizeArray& dsetSize,
const SizeArray& chunkSize,
const float& conversion,
const float& resolution,
const float& offset)
{
Container::initialize();

this->dataType = dataType;

// setup attributes
io->createCommonNWBAttributes(path, "core", neurodataType, description);
io->createAttribute(comments, path, "comments");
Expand Down
97 changes: 23 additions & 74 deletions src/nwb/base/TimeSeries.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,9 @@ class TimeSeries : public Container
* @brief Constructor.
* @param path The location of the TimeSeries in the file.
* @param io A shared pointer to the IO object.
* @param dataType The data type to use for storing the recorded signal
* @param unit Unit for the electrical signal. Must be "volts"
* @param description The description of the TimeSeries.
* @param comments Human-readable comments about the TimeSeries
* @param dsetSize Initial size of the main dataset
* @param chunkSize Chunk size to use
* @param conversion Scalar to multiply each element in data to convert it to
* the specified ‘unit’
* @param resolution Smallest meaningful difference between values in data,
* stored in the specified by unit
* @param offset Scalar to add to the data after scaling by ‘conversion’ to
* finalize its coercion to the specified ‘unit'
*/
TimeSeries(const std::string& path,
std::shared_ptr<BaseIO> io,
const BaseDataType& dataType,
const std::string& unit,
const std::string& description = "no description",
const std::string& comments = "no comments",
const SizeArray& dsetSize = SizeArray {0},
const SizeArray& chunkSize = SizeArray {1},
const float& conversion = 1.0f,
const float& resolution = -1.0f,
const float& offset = 0.0f);
std::shared_ptr<BaseIO> io);

/**
* @brief Destructor
Expand All @@ -65,8 +44,29 @@ class TimeSeries : public Container
/**
* @brief Initializes the TimeSeries by creating NWB related attributes and
* writing the description and comment metadata.
*
* @param dataType The data type to use for storing the recorded signal
* @param unit Unit for the electrical signal. Must be "volts"
* @param description The description of the TimeSeries.
* @param comments Human-readable comments about the TimeSeries
* @param dsetSize Initial size of the main dataset
* @param chunkSize Chunk size to use
* @param conversion Scalar to multiply each element in data to convert it to
* the specified ‘unit’
* @param resolution Smallest meaningful difference between values in data,
* stored in the specified by unit
* @param offset Scalar to add to the data after scaling by ‘conversion’ to
* finalize its coercion to the specified ‘unit'
*/
void initialize();
void initialize(const BaseDataType& dataType,
const std::string& unit,
const std::string& description = "no description",
const std::string& comments = "no comments",
const SizeArray& dsetSize = SizeArray {0},
const SizeArray& chunkSize = SizeArray {1},
const float& conversion = 1.0f,
const float& resolution = -1.0f,
const float& offset = 0.0f);

/**
* @brief Pointer to data values.
Expand All @@ -88,57 +88,6 @@ class TimeSeries : public Container
*/
BaseDataType timestampsType = BaseDataType::F64;

/**
* @brief Base unit of measurement for working with the data. Actual stored
* values are not necessarily stored in these units. To access the data in
* these units, multiply ‘data’ by ‘conversion’ and add ‘offset’.
*/
std::string unit;

/**
* @brief The description of the TimeSeries.
*/
std::string description;

/**
* @brief Human-readable comments about the TimeSeries.
*/
std::string comments;

/**
* @brief Size used in dataset creation. Can be expanded when writing if
* needed.
*/
SizeArray dsetSize;

/**
* @brief Chunking size used in dataset creation.
*/
SizeArray chunkSize;

/**
* @brief Scalar to multiply each element in data to convert it to the
* specified ‘unit’.
*/
float conversion;

/**
* @brief Smallest meaningful difference between values in data, stored in the
* specified by unit.
*/
float resolution;

/**
* @brief Scalar to add to the data after scaling by ‘conversion’ to finalize
* its coercion to the specified ‘unit’.
*/
float offset;

/**
* @brief The starting time of the TimeSeries.
*/
float startingTime = 0.0;

private:
/**
* @brief The neurodataType of the TimeSeries.
Expand Down
21 changes: 3 additions & 18 deletions src/nwb/device/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,19 @@ using namespace AQNWB::NWB;
// Device
/** Constructor */
Device::Device(const std::string& path,
std::shared_ptr<BaseIO> io,
const std::string& description,
const std::string& manufacturer)
std::shared_ptr<BaseIO> io)
: Container(path, io)
, description(description)
, manufacturer(manufacturer)
{
}

/** Destructor */
Device::~Device() {}

void Device::initialize()
void Device::initialize(const std::string& description,
const std::string& manufacturer)
{
Container::initialize();

io->createCommonNWBAttributes(path, "core", "Device", description);
io->createAttribute(manufacturer, path, "manufacturer");
}

// Getter for manufacturer
std::string Device::getManufacturer() const
{
return manufacturer;
}

// Getter for description
std::string Device::getDescription() const
{
return description;
}
22 changes: 6 additions & 16 deletions src/nwb/device/Device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ class Device : public Container
* @brief Constructor.
* @param path The location of the device in the file.
* @param io A shared pointer to the IO object.
* @param description The description of the device.
* @param manufacturer The manufacturer of the device.
*/
Device(const std::string& path,
std::shared_ptr<BaseIO> io,
const std::string& description,
const std::string& manufacturer);
std::shared_ptr<BaseIO> io);

/**
* @brief Destructor
Expand All @@ -34,8 +30,12 @@ class Device : public Container
/**
* @brief Initializes the device by creating NWB related attributes and
* writing the manufactor and description metadata.
*
* @param description The description of the device.
* @param manufacturer The manufacturer of the device.
*/
void initialize();
void initialize(const std::string& description,
const std::string& manufacturer);

/**
* @brief Gets the manufacturer of the device.
Expand All @@ -49,15 +49,5 @@ class Device : public Container
*/
std::string getDescription() const;

private:
/**
* @brief The description of the device.
*/
std::string description;

/**
* @brief The manufacturer of the device.
*/
std::string manufacturer;
};
} // namespace AQNWB::NWB
Loading

0 comments on commit 4d7b1ea

Please sign in to comment.