Skip to content

Commit

Permalink
plumb into collections, various cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeplf committed Jan 5, 2024
1 parent e3a2026 commit c77f70f
Show file tree
Hide file tree
Showing 20 changed files with 180 additions and 133 deletions.
26 changes: 16 additions & 10 deletions binds/python/bind_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,36 +182,42 @@ void bind_misc(py::module& m) {
[](morphio::Collection* collection,
const std::string& morph_name,
unsigned int options,
bool is_mutable) -> py::object {
bool is_mutable,
std::shared_ptr<morphio::WarningHandler> warning_handler) -> py::object {
if (is_mutable) {
return py::cast(
collection->load<morphio::mut::Morphology>(morph_name, options));
return py::cast(collection->load<morphio::mut::Morphology>(morph_name,
options,
warning_handler));
} else {
return py::cast(collection->load<morphio::Morphology>(morph_name, options));
return py::cast(collection->load<morphio::Morphology>(morph_name,
options,
warning_handler));
}
},
"morph_name"_a,
"options"_a = morphio::enums::Option::NO_MODIFIER,
"mutable"_a = false,
"warning_handler"_a = std::shared_ptr<morphio::WarningHandler>(nullptr),
"Load the morphology named 'morph_name' form the collection.")
.def(
"load_unordered",
[](morphio::Collection* collection,
std::vector<std::string> morphology_names,
unsigned int options,
bool is_mutable) -> py::object {
bool is_mutable,
std::shared_ptr<morphio::WarningHandler> warning_handler) -> py::object {
if (is_mutable) {
return py::cast(
collection->load_unordered<morphio::mut::Morphology>(morphology_names,
options));
return py::cast(collection->load_unordered<morphio::mut::Morphology>(
morphology_names, options, warning_handler));
} else {
return py::cast(
collection->load_unordered<morphio::Morphology>(morphology_names, options));
return py::cast(collection->load_unordered<morphio::Morphology>(
morphology_names, options, warning_handler));
}
},
"morphology_names"_a,
"options"_a = morphio::enums::Option::NO_MODIFIER,
"mutable"_a = false,
"warning_handler"_a = std::shared_ptr<morphio::WarningHandler>(nullptr),
R"(Create an iterable of loop index and morphology.
When reading from containers, the order in which morphologies are read can
Expand Down
8 changes: 3 additions & 5 deletions binds/python/generated/docstrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -1243,10 +1243,10 @@ static const char *mkd_doc_morphio_enums_operator_lshift = R"doc()doc";

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

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

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

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

static const char *mkd_doc_morphio_isRoot = R"doc(Return true if this section is a root section (parent ID == -1))doc";

static const char *mkd_doc_morphio_mut_DendriticSpine = R"doc(Mutable(editable) morphio::DendriticSpine)doc";
Expand Down Expand Up @@ -1528,7 +1528,7 @@ static const char *mkd_doc_morphio_mut_Morphology_endoplasmicReticulum_3 = R"doc

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

static const char *mkd_doc_morphio_mut_Morphology_getHandler = R"doc()doc";
static const char *mkd_doc_morphio_mut_Morphology_getWarningHandler = R"doc()doc";

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

Expand Down Expand Up @@ -1561,8 +1561,6 @@ static const char *mkd_doc_morphio_mut_Morphology_sections = R"doc(Returns the d

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

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

static const char *mkd_doc_morphio_mut_Morphology_soma =
R"doc(Returns a shared pointer on the Soma
Expand Down
2 changes: 1 addition & 1 deletion binds/python/morphio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace py = pybind11;

PYBIND11_MODULE(_morphio, m) {
bind_enums(m);
bind_misc(m);
bind_warnings_exceptions(m);
bind_misc(m);

bind_immutable(m);

Expand Down
34 changes: 24 additions & 10 deletions include/morphio/collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,30 @@ class Collection
* Load the morphology as an immutable morphology.
*/
template <class M>
typename enable_if_mutable<M, M>::type load(const std::string& morph_name,
unsigned int options = NO_MODIFIER) const;
typename enable_if_mutable<M, M>::type load(
const std::string& morph_name,
unsigned int options = NO_MODIFIER,
std::shared_ptr<WarningHandler> warning_handler = nullptr) const;

/**
* Load the morphology as a mutable morphology.
*/
template <class M>
typename enable_if_immutable<M, M>::type load(const std::string& morph_name,
unsigned int options = NO_MODIFIER) const;
typename enable_if_immutable<M, M>::type load(
const std::string& morph_name,
unsigned int options = NO_MODIFIER,
std::shared_ptr<WarningHandler> warning_handler = nullptr) const;

/**
* Returns an iterable of loop index, morphology pairs.
*
* See `LoadUnordered` for details.
*/
template <class M>
LoadUnordered<M> load_unordered(std::vector<std::string> morphology_names,
unsigned int options = NO_MODIFIER) const;
LoadUnordered<M> load_unordered(
std::vector<std::string> morphology_names,
unsigned int options = NO_MODIFIER,
std::shared_ptr<WarningHandler> warning_handler = nullptr) const;

/**
* Returns the reordered loop indices.
Expand Down Expand Up @@ -183,15 +189,23 @@ extern template
LoadUnordered<mut::Morphology>::Iterator::operator*<mut::Morphology>() const;

extern template typename enable_if_mutable<mut::Morphology, mut::Morphology>::type
Collection::load<mut::Morphology>(const std::string& morph_name, unsigned int options) const;
Collection::load<mut::Morphology>(const std::string& morph_name,
unsigned int options,
std::shared_ptr<WarningHandler> warning_handler) const;

extern template typename enable_if_immutable<Morphology, Morphology>::type
Collection::load<Morphology>(const std::string& morph_name, unsigned int options) const;
Collection::load<Morphology>(const std::string& morph_name,
unsigned int options,
std::shared_ptr<WarningHandler> warning_handler) const;

extern template LoadUnordered<Morphology> Collection::load_unordered<Morphology>(
std::vector<std::string> morphology_names, unsigned int options) const;
std::vector<std::string> morphology_names,
unsigned int options,
std::shared_ptr<WarningHandler> warning_handler) const;

extern template LoadUnordered<mut::Morphology> Collection::load_unordered<mut::Morphology>(
std::vector<std::string> morphology_names, unsigned int options) const;
std::vector<std::string> morphology_names,
unsigned int options,
std::shared_ptr<WarningHandler> warning_handler) const;

} // namespace morphio
2 changes: 1 addition & 1 deletion include/morphio/errorMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ void set_ignored_warning(enums::Warning warning, bool ignore = true);
/** Set an array of warnings to ignore **/
void set_ignored_warning(const std::vector<enums::Warning>& warning, bool ignore = true);

std::shared_ptr<WarningHandler> getErrorHandler();
std::shared_ptr<WarningHandler> getWarningHandler();

} // namespace morphio
8 changes: 3 additions & 5 deletions include/morphio/morphology.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@ class Morphology
unsigned int options = NO_MODIFIER,
std::shared_ptr<WarningHandler> = nullptr);

/** Constructor from an already parsed file */
explicit Morphology(const HighFive::Group& group, unsigned int options = NO_MODIFIER);

/** Constructor from an already parsed file */
// explicit Morphology(const HighFive::Group& group,
// unsigned int options = NO_MODIFIER,
// std::shared_ptr<WarningHandler> = nullptr);
explicit Morphology(const HighFive::Group& group,
unsigned int options = NO_MODIFIER,
std::shared_ptr<WarningHandler> = nullptr);

/** Constructor from an instance of morphio::mut::Morphology */
explicit Morphology(const mut::Morphology&);
Expand Down
33 changes: 14 additions & 19 deletions include/morphio/mut/morphology.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ bool _checkDuplicatePoint(const std::shared_ptr<Section>& parent,
class Morphology
{
public:
Morphology()
Morphology(std::shared_ptr<WarningHandler> warning_handler = nullptr)
: _soma(std::make_shared<Soma>())
, _cellProperties(
std::make_shared<morphio::Property::CellLevel>(morphio::Property::CellLevel()))
, _handler(getErrorHandler()) {}
, _cellProperties(std::make_shared<Property::CellLevel>())
, _handler(warning_handler ? warning_handler : morphio::getWarningHandler()) {}

/**
Build a mutable Morphology from an on-disk morphology
Expand All @@ -52,10 +51,12 @@ class Morphology
std::shared_ptr<WarningHandler> warning_handler = nullptr);

/// Build a mutable Morphology from an HighFive::Group
explicit Morphology(const HighFive::Group& group, unsigned int options = NO_MODIFIER);
explicit Morphology(const HighFive::Group& group,
unsigned int options = NO_MODIFIER,
std::shared_ptr<WarningHandler> warning_handler = nullptr);

/// Build a mutable Morphology from a mutable morphology
Morphology(const morphio::mut::Morphology& morphology,
Morphology(const mut::Morphology& morphology,
unsigned int options = NO_MODIFIER,
std::shared_ptr<WarningHandler> warning_handler = nullptr);

Expand Down Expand Up @@ -199,11 +200,11 @@ class Morphology
/// Write file to H5, SWC, ASC format depending on filename extension
void write(const std::string& filename) const;

void addAnnotation(const morphio::Property::Annotation& annotation) {
void addAnnotation(const Property::Annotation& annotation) {
_cellProperties->_annotations.push_back(annotation);
}

void addMarker(const morphio::Property::Marker& marker) {
void addMarker(const Property::Marker& marker) {
_cellProperties->_markers.push_back(marker);
}

Expand All @@ -223,18 +224,14 @@ class Morphology
**/
void removeUnifurcations();

std::shared_ptr<WarningHandler> getHandler() const {
std::shared_ptr<WarningHandler> getWarningHandler() const {
return _handler;
}

void setErrorHandler(std::shared_ptr<WarningHandler> h) {
_handler = h;
}

std::shared_ptr<Soma> _soma;
std::shared_ptr<morphio::Property::CellLevel> _cellProperties;
std::shared_ptr<Property::CellLevel> _cellProperties;
EndoplasmicReticulum _endoplasmicReticulum;
morphio::Property::DendriticSpine::Level _dendriticSpineLevel;
Property::DendriticSpine::Level _dendriticSpineLevel;

private:
std::vector<std::shared_ptr<Section>> _rootSections;
Expand All @@ -256,10 +253,8 @@ class Morphology
std::string _uri;

friend class Section;
friend void modifiers::nrn_order(morphio::mut::Morphology& morpho);
friend bool diff(const Morphology& left,
const Morphology& right,
morphio::enums::LogLevel verbose);
friend void modifiers::nrn_order(mut::Morphology& morpho);
friend bool diff(const Morphology& left, const Morphology& right, enums::LogLevel verbose);
};

} // namespace mut
Expand Down
Loading

0 comments on commit c77f70f

Please sign in to comment.