Skip to content
Snippets Groups Projects
Select Git revision
  • b01aa58bf949ab0ba0e3b88e26636506b74e8c3d
  • master default protected
  • tut_ring_allen
  • docs_furo
  • docs_reorder_cable_cell
  • docs_graphviz
  • docs_rtd_dev
  • ebrains_mirror
  • doc_recat
  • docs_spike_source
  • docs_sim_sample_clar
  • docs_pip_warn
  • github_template_updates
  • docs_fix_link
  • cv_default_and_doc_clarification
  • docs_add_numpy_req
  • readme_zenodo_05
  • install_python_fix
  • install_require_numpy
  • typofix_propetries
  • docs_recipe_lookup
  • v0.10.0
  • v0.10.1
  • v0.10.0-rc5
  • v0.10.0-rc4
  • v0.10.0-rc3
  • v0.10.0-rc2
  • v0.10.0-rc
  • v0.9.0
  • v0.9.0-rc
  • v0.8.1
  • v0.8
  • v0.8-rc
  • v0.7
  • v0.6
  • v0.5.2
  • v0.5.1
  • v0.5
  • v0.4
  • v0.3
  • v0.2.2
41 results

cable_cell_io.cpp

Blame
  • cable_cell_io.cpp 3.94 KiB
    #include <pybind11/pybind11.h>
    #include <pybind11/stl.h>
    
    #include <fstream>
    #include <iomanip>
    
    #include <arbor/cable_cell.hpp>
    
    #include <arborio/cableio.hpp>
    
    #include "error.hpp"
    #include "strprintf.hpp"
    
    namespace pyarb {
    
    arborio::cable_cell_component load_component(const std::string& fname) {
        std::ifstream fid{fname};
        if (!fid.good()) {
            throw pyarb_error("Can't open file '{}'" + fname);
        }
        auto component = arborio::parse_component(fid);
        if (!component) {
            throw pyarb_error("Error while trying to load component from \"" + fname + "\": " + component.error().what());
        }
        return component.value();
    };
    
    template<typename T>
    void write_component(const T& component, const std::string& fname) {
        std::ofstream fid(fname);
        arborio::write_component(fid, component, arborio::meta_data{});
    }
    
    void write_component(const arborio::cable_cell_component& component, const std::string& fname) {
        std::ofstream fid(fname);
        arborio::write_component(fid, component);
    }
    
    void register_cable_loader(pybind11::module& m) {
        m.def("load_component",
              &load_component,
              pybind11::arg_v("filename", "the name of the file."),
              "Load arbor-component (decor, morphology, label_dict, cable_cell) from file.");
    
        m.def("write_component",
              [](const arborio::cable_cell_component& d, const std::string& fname) {
                return write_component(d, fname);
              },
              pybind11::arg_v("object", "the cable_component object."),
              pybind11::arg_v("filename", "the name of the file."),
              "Write cable_component to file.");
    
        m.def("write_component",
              [](const arb::decor& d, const std::string& fname) {
                return write_component<arb::decor>(d, fname);
              },
              pybind11::arg_v("object", "the decor object."),
              pybind11::arg_v("filename", "the name of the file."),
              "Write decor to file.");
    
        m.def("write_component",
              [](const arb::label_dict& d, const std::string& fname) {
                return write_component<arb::label_dict>(d, fname);
              },
              pybind11::arg_v("object", "the label_dict object."),
              pybind11::arg_v("filename", "the name of the file."),
              "Write label_dict to file.");
    
        m.def("write_component",
              [](const arb::morphology& d, const std::string& fname) {