Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 24 additions & 8 deletions python/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,12 @@ py::class_<Population, std::shared_ptr<Population>> bindPopulationClass(py::modu
return fmt::format(msg, fmt::arg("element", Population::ELEMENT));
};
return py::class_<Population, std::shared_ptr<Population>>(m, clsName, docString)
.def(py::init<const std::string&, const std::string&, const std::string&>())
.def(py::init([](py::object h5_filepath, py::object csv_filepath, std::string name) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought these methods did not need a docstring

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought you wanted them :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I approved already :D)

return Population(py::str(h5_filepath), py::str(csv_filepath), name);
}),
"h5_filepath"_a,
"csv_filepath"_a,
"name"_a)
.def_property_readonly("name", &Population::name, DOC_POP(name))
.def_property_readonly("size", &Population::size, imbueElementName(DOC_POP(size)).c_str())
.def_property_readonly("attribute_names",
Expand Down Expand Up @@ -541,8 +546,11 @@ PYBIND11_MODULE(_libsonata, m) {
bindStorageClass<NodeStorage>(m, "NodeStorage", "NodePopulation");

py::class_<NodeSets>(m, "NodeSets", "NodeSets")
.def(py::init<const std::string&>())
.def_static("from_file", [](py::object path) { return NodeSets::fromFile(py::str(path)); })
.def(py::init<const std::string&>(), "string of NodeSets JSON"_a)
.def_static(
"from_file",
[](py::object path) { return NodeSets::fromFile(py::str(path)); },
"path"_a)
.def_property_readonly("names", &NodeSets::names, DOC_NODESETS(names))
.def("materialize", &NodeSets::materialize, DOC_NODESETS(materialize))
.def("update", &NodeSets::update, "other"_a, DOC_NODESETS(update))
Expand Down Expand Up @@ -571,7 +579,7 @@ PYBIND11_MODULE(_libsonata, m) {
.def_readonly("offset", &CompartmentLocation::offset, DOC_COMPARTMENTLOCATION(offset));

py::class_<CompartmentSet>(m, "CompartmentSet")
.def(py::init<const std::string&>())
.def(py::init<const std::string&>(), "string of CompartmentSet JSON"_a)
.def_property_readonly("population",
&CompartmentSet::population,
DOC_COMPARTMENTSET(population))
Expand Down Expand Up @@ -635,8 +643,11 @@ PYBIND11_MODULE(_libsonata, m) {
[](const CompartmentSet& self) { return py::str(py::repr(py::cast(self))); });

py::class_<CompartmentSets>(m, "CompartmentSets")
.def(py::init<const std::string&>())
.def_static("from_file", &CompartmentSets::fromFile, py::arg("path"))
.def(py::init<const std::string&>(), "string of CompartmentSets JSON"_a)
.def_static(
"from_file",
[](py::object path) { return CompartmentSets::fromFile(py::str(path)); },
"path"_a)
.def("__contains__",
&CompartmentSets::contains,
py::arg("key"),
Expand Down Expand Up @@ -724,7 +735,9 @@ PYBIND11_MODULE(_libsonata, m) {
.value("partial", CircuitConfig::ConfigStatus::partial);

py::class_<CircuitConfig>(m, "CircuitConfig", "Circuit Configuration")
.def(py::init<const std::string&, const std::string&>())
.def(py::init<const std::string&, const std::string&>(),
"string of CircuitConfig JSON"_a,
"base_path"_a)
.def_static("from_file",
[](py::object path) { return CircuitConfig::fromFile(py::str(path)); })
.def_property_readonly("config_status", &CircuitConfig::getCircuitConfigStatus, "ibid")
Expand Down Expand Up @@ -1252,7 +1265,10 @@ PYBIND11_MODULE(_libsonata, m) {
&SimulationConfig::ConnectionOverride::neuromodulationStrength,
DOC_SIMULATIONCONFIG(ConnectionOverride, neuromodulationStrength));

simConf.def(py::init<const std::string&, const std::string&>())
simConf
.def(py::init<const std::string&, const std::string&>(),
"string of SimulationConfig JSON"_a,
"base_path"_a)
.def_static(
"from_file",
[](py::object path) { return SimulationConfig::fromFile(py::str(path)); },
Expand Down
29 changes: 18 additions & 11 deletions python/tests/test_population.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@

import numpy as np

from libsonata import (CircuitConfig,
ElementReportReader,
NodeSets,
NodeStorage,
Selection,
SimulationConfig,
SomaReportReader,
SonataError,
SpikeReader,
EdgeStorage,
)
from libsonata import (
CircuitConfig,
CompartmentSets,
EdgePopulation,
EdgeStorage,
ElementReportReader,
NodePopulation,
NodeSets,
NodeStorage,
Selection,
SimulationConfig,
SomaReportReader,
SonataError,
SpikeReader,
)


PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)),
Expand Down Expand Up @@ -296,3 +300,6 @@ def test_path_ctor(self):
NodeSets.from_file(path / 'node_sets.json')
CircuitConfig.from_file(path / 'config/circuit_config.json')
SimulationConfig.from_file(path / 'config/simulation_config.json')
NodePopulation(path / 'nodes1.h5', csv_filepath="", name="nodes-A")
EdgePopulation(path / 'edges1.h5', csv_filepath="", name="edges-AB")
CompartmentSets.from_file(path / 'compartment_sets.json')
Loading