Skip to content

Commit

Permalink
Add getTimes inside SpikeReader::Population (#169)
Browse files Browse the repository at this point in the history
* Add getTimes inside SpikeReader::Population
* Add bindings and tests
  • Loading branch information
Nicolas Cornu authored Nov 26, 2021
1 parent 60f1643 commit 0776f58
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions include/bbp/sonata/report_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class SONATA_API SpikeReader
by_time = 2,
};

/**
* Return (tstart, tstop) of the population
*/
std::tuple<double, double> getTimes() const;

/**
* Return reports for this population.
*/
Expand Down
5 changes: 4 additions & 1 deletion python/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,10 @@ PYBIND11_MODULE(_libsonata, m) {
return "by_time";
return "none";
},
DOC_SPIKEREADER_POP(getSorting));
DOC_SPIKEREADER_POP(getSorting))
.def_property_readonly("times",
&SpikeReader::Population::getTimes,
DOC_SPIKEREADER_POP(getTimes));
py::class_<SpikeReader>(m, "SpikeReader", "Used to read spike files")
.def(py::init([](py::object h5_filepath) { return SpikeReader(py::str(h5_filepath)); }),
"h5_filepath"_a)
Expand Down
2 changes: 2 additions & 0 deletions python/generated/docstrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ static const char *__doc_bbp_sonata_SpikeReader_Population_get = R"doc(Return re

static const char *__doc_bbp_sonata_SpikeReader_Population_getSorting = R"doc(Return the way data are sorted ('none', 'by_id', 'by_time'))doc";

static const char *__doc_bbp_sonata_SpikeReader_Population_getTimes = R"doc(Return (tstart, tstop) of the population)doc";

static const char *__doc_bbp_sonata_SpikeReader_Population_sorting = R"doc()doc";

static const char *__doc_bbp_sonata_SpikeReader_Population_spikes = R"doc()doc";
Expand Down
3 changes: 3 additions & 0 deletions python/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ def test_get_spikes_from_population(self):

self.assertEqual(len(self.test_obj['All'].get(node_ids=[])), 0)

def test_getTimes_from_population(self):
self.assertEqual(self.test_obj['All'].times, (0.1, 1.3))

class TestSomaReportPopulation(unittest.TestCase):
def setUp(self):
path = os.path.join(PATH, "somas.h5")
Expand Down
4 changes: 4 additions & 0 deletions src/report_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ auto SpikeReader::openPopulation(const std::string& populationName) const -> con
return populations_.at(populationName);
}

std::tuple<double, double> SpikeReader::Population::getTimes() const {
return std::tie(tstart_, tstop_);
}

Spikes SpikeReader::Population::get(const nonstd::optional<Selection>& node_ids,
const nonstd::optional<double>& tstart,
const nonstd::optional<double>& tstop) const {
Expand Down
2 changes: 2 additions & 0 deletions tests/test_report_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ TEST_CASE("SpikeReader", "[base]") {
REQUIRE(reader.openPopulation("All").get(Selection({{5, 6}}), 0.1, 0.1) ==
std::vector<std::pair<uint64_t, double>>{{5, 0.1}});
REQUIRE(reader.openPopulation("empty").get() == std::vector<std::pair<uint64_t, double>>{});

REQUIRE(reader.openPopulation("All").getTimes() == std::make_tuple(0.1, 1.3));
}

TEST_CASE("SomaReportReader limits", "[base]") {
Expand Down

0 comments on commit 0776f58

Please sign in to comment.