Skip to content

Commit

Permalink
Refactoring/cleanup for event exports
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkrause committed Apr 8, 2021
1 parent c16e107 commit 703bd90
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions NEVExtract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ std::string toString(std::shared_ptr<WavePacket> wp, const NEVFile &file,

void saveStimText(const NEVConfig &config, const NEVFile &file, const std::vector<std::shared_ptr<StimPacket>> &sp) {

const double stampToSec = 1.0 / static_cast<double>(file.timestampFS());
const double stampToSec = 1.0 / static_cast<double>(file.get_timestampFS());

std::string filename = config.stimFilename(OutputFormat::TEXT);
std::ofstream out(filename);
Expand Down Expand Up @@ -216,7 +216,7 @@ void saveStimText(const NEVConfig &config, const NEVFile &file, const std::vecto

void saveStimCSV(const NEVConfig &config, const NEVFile &file, const std::vector<std::shared_ptr<StimPacket>> &sp) {

const double stampToSec = 1.0 / static_cast<double>(file.timestampFS());
const double stampToSec = 1.0 / static_cast<double>(file.get_timestampFS());

std::string filename = config.stimFilename(OutputFormat::CSV);
std::ofstream out(filename);
Expand Down Expand Up @@ -269,7 +269,7 @@ void saveStimMatlab(const NEVConfig &config, const NEVFile &f, const std::vector
MW::mxArray* eventdata = MW::mxCreateStructArray(2, event_dims,
n_event_fields, event_fieldnames);

const double stampToSec = 1.0 / static_cast<double>(f.timestampFS());
const double stampToSec = 1.0 / static_cast<double>(f.get_timestampFS());


/* We're going to cache the amp digitization factor and the bytes per sample so we don't
Expand Down
9 changes: 5 additions & 4 deletions NEVFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ std::shared_ptr<Packet> NEVFile::readPacket(bool digital, bool stim, bool spike)
}


std::shared_ptr<Packet> NEVFile::readPacketOrNull(bool digital, bool stim, bool spike) {
std::shared_ptr<Packet> NEVFile::readPacketOrNull(bool keep_digital, bool keep_stim, bool keep_spike) {
/* Read the next packet. If the corresponding type (digital, stim,
or spike) is true, parse it and return a shared_ptr. Otherwise,
return nullptr.
Expand All @@ -187,11 +187,11 @@ std::shared_ptr<Packet> NEVFile::readPacketOrNull(bool digital, bool stim, bool

std::shared_ptr<Packet> p = nullptr;

if(packetID == 0 && digital) {
if(packetID == 0 && keep_digital) {
p = parseCurrentAsDigital();
} else if(packetID <= 512 && spike) {
} else if(packetID <= 512 && keep_spike) {
p = parseCurrentAsSpike();
} else if (packetID > 512 && stim) {
} else if (packetID > 512 && keep_stim) {
p = parseCurrentAsStim();
}

Expand All @@ -205,6 +205,7 @@ std::shared_ptr<Packet> NEVFile::readPacketOrNull(bool digital, bool stim, bool
else
refillBuffer();
}

start = buffer + buffer_pos;
std::copy(start, start+sizeof(timestamp),
reinterpret_cast<char*>(&timestamp));
Expand Down
6 changes: 3 additions & 3 deletions saveNEVEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void saveEventsCSV(const NEVConfig &config, const NEVFile &file, const EventSOA
throw(std::runtime_error("Unable to open " + filename + " for writing"));
}

double stampToSec = 1.0 / static_cast<double>(file.timestampFS());
double stampToSec = 1.0 / static_cast<double>(file.get_timestampFS());

out << "timestamp,tic,reason,parallel,sma1,sma2,sma3,sma4\n";

Expand Down Expand Up @@ -43,7 +43,7 @@ void saveEventsMatlab(const NEVConfig &config, const NEVFile &f, const EventSOA
MW::mwSize dim[2] = { static_cast<MW::mwSize>(ev.ts.size()), 1};

std::vector<double> time(ev.ts.size());
const double ticToSec = 1.0 / static_cast<double>(f.timestampFS());
const double ticToSec = 1.0 / static_cast<double>(f.get_timestampFS());
for(size_t i=0; i<ev.ts.size(); i++) {
time[i] = double(ev.ts[i]) * ticToSec;
}
Expand All @@ -66,7 +66,7 @@ void saveEventsMatlab(const NEVConfig &config, const NEVFile &f, const EventSOA

void saveEventsText(const NEVConfig &config, const NEVFile &file, const EventSOA &ev) {

const double stampToSec = 1.0 / static_cast<double>(file.timestampFS());
const double stampToSec = 1.0 / static_cast<double>(file.get_timestampFS());

std::string filename = config.eventFilename(OutputFormat::TEXT);
std::ofstream out(filename);
Expand Down

0 comments on commit 703bd90

Please sign in to comment.