| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,62 +10,124 @@ namespace py = pybind11; | |||
| 10 | 10 | //https://pybind11.readthedocs.io/en/stable/classes.html | |
| 11 | 11 | //http://people.duke.edu/~ccc14/sta-663-2016/18G_C++_Python_pybind11.html | |
| 12 | 12 | ||
| 13 | - std::vector<std::string> getListOfScores() { | ||
| 14 | - return complib::score_names; | ||
| 15 | - } | ||
| 16 | - | ||
| 17 | - std::string getScoresForGeoJSON(const std::string &geojson, const std::string id, const std::vector<std::string> &score_list){ | ||
| 13 | + std::string getUnboundedScoresForGeoJSON(const std::string &geojson, const std::string id, const std::vector<std::string> &score_list){ | ||
| 18 | 14 | auto gc = complib::ReadGeoJSON(geojson); | |
| 19 | - complib::CalculateListOfScores(gc, score_list); | ||
| 15 | + complib::CalculateListOfUnboundedScores(gc, score_list); | ||
| 20 | 16 | return complib::OutScoreJSON(gc, id); | |
| 21 | 17 | } | |
| 22 | 18 | ||
| 23 | - void augmentShapefileWithScores(const std::string filename, const std::vector<std::string> &score_list){ | ||
| 19 | + void augmentShapefileWithUnboundedScores(const std::string filename, const std::vector<std::string> &score_list){ | ||
| 24 | 20 | auto gc = complib::ReadShapefile(filename); | |
| 25 | - complib::CalculateListOfScores(gc, score_list); | ||
| 21 | + complib::CalculateListOfUnboundedScores(gc, score_list); | ||
| 26 | 22 | complib::WriteShapeScores(gc, filename); | |
| 27 | 23 | } | |
| 28 | 24 | ||
| 29 | - void addScoresToNewShapefile(const std::string in_filename, const std::string out_filename, const std::vector<std::string> &score_list){ | ||
| 25 | + void addUnboundedScoresToNewShapefile(const std::string in_filename, const std::string out_filename, const std::vector<std::string> &score_list){ | ||
| 30 | 26 | auto gc = complib::ReadShapefile(in_filename); | |
| 31 | - complib::CalculateListOfScores(gc, score_list); | ||
| 27 | + complib::CalculateListOfUnboundedScores(gc, score_list); | ||
| 32 | 28 | complib::WriteShapefile(gc,out_filename); | |
| 33 | 29 | } | |
| 34 | 30 | ||
| 35 | 31 | ||
| 32 | + std::string getBoundedScoresForGeoJSON( | ||
| 33 | + const std::string &gj_subunit, | ||
| 34 | + const std::string &gj_superunit, | ||
| 35 | + const std::string id, | ||
| 36 | + const std::string join_on, | ||
| 37 | + const std::vector<std::string> &score_list | ||
| 38 | + ){ | ||
| 39 | + auto gc_sub = complib::ReadGeoJSON(gj_subunit); | ||
| 40 | + auto gc_sup = complib::ReadGeoJSON(gj_superunit); | ||
| 41 | + complib::CalculateListOfBoundedScores(gc_sub, gc_sup, join_on, score_list); | ||
| 42 | + return complib::OutScoreJSON(gc_sub, id); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + void augmentShapefileWithBoundedScores( | ||
| 46 | + const std::string subunit_filename, | ||
| 47 | + const std::string superunit_filename, | ||
| 48 | + const std::string join_on, | ||
| 49 | + const std::vector<std::string> &score_list | ||
| 50 | + ){ | ||
| 51 | + auto gc_sub = complib::ReadShapefile(subunit_filename); | ||
| 52 | + auto gc_sup = complib::ReadShapefile(superunit_filename); | ||
| 53 | + complib::CalculateListOfBoundedScores(gc_sub, gc_sup, join_on, score_list); | ||
| 54 | + complib::CalculateListOfUnboundedScores(gc_sub, score_list); | ||
| 55 | + complib::WriteShapeScores(gc_sub, subunit_filename); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + void addBoundedScoresToNewShapefile( | ||
| 59 | + const std::string in_subunit_filename, | ||
| 60 | + const std::string in_superunit_filename, | ||
| 61 | + const std::string out_filename, | ||
| 62 | + const std::string join_on, | ||
| 63 | + const std::vector<std::string> &score_list | ||
| 64 | + ){ | ||
| 65 | + auto gc_sub = complib::ReadShapefile(in_subunit_filename); | ||
| 66 | + auto gc_sup = complib::ReadShapefile(in_superunit_filename); | ||
| 67 | + complib::CalculateListOfBoundedScores(gc_sub, gc_sup, join_on, score_list); | ||
| 68 | + complib::CalculateListOfUnboundedScores(gc_sub, score_list); | ||
| 69 | + complib::WriteShapefile(gc_sub,out_filename); | ||
| 70 | + } | ||
| 36 | 71 | ||
| 37 | 72 | PYBIND11_PLUGIN(_mander) { | |
| 38 | 73 | py::module m("_mander", "Internal library used by python-mander to calculate scores"); | |
| 39 | 74 | ||
| 40 | 75 | m.def( | |
| 41 | - "getListOfScores", | ||
| 42 | - &getListOfScores, | ||
| 43 | - "Returns a list of compactness scores." | ||
| 76 | + "prepGeoJSON", | ||
| 77 | + &complib::PrepGeoJSON, | ||
| 78 | + "Load GeoJSON into memory for quick retrieval later." | ||
| 79 | + ); | ||
| 80 | + | ||
| 81 | + m.def( | ||
| 82 | + "getListOfUnboundedScores", | ||
| 83 | + &complib::getListOfUnboundedScores, | ||
| 84 | + "Returns a list of unbounded compactness scores." | ||
| 44 | 85 | ); | |
| 45 | 86 | ||
| 46 | 87 | m.def( | |
| 47 | - "getScoresForGeoJSON", | ||
| 48 | - &getScoresForGeoJSON, | ||
| 88 | + "getListOfBoundedScores", | ||
| 89 | + &complib::getListOfBoundedScores, | ||
| 90 | + "Returns a list of bounded compactness scores." | ||
| 91 | + ); | ||
| 92 | + | ||
| 93 | + m.def( | ||
| 94 | + "getUnboundedScoresForGeoJSON", | ||
| 95 | + &getUnboundedScoresForGeoJSON, | ||
| 49 | 96 | "Takes a GeoJSON string as input, calculates all scores, return a JSON dictionary of the scores keyed to values identified 'id' which are expected to be properties of the GeoJSON objects. If id='', then the object's 0-indexed order is used.", | |
| 50 | 97 | py::arg("geojson"), | |
| 51 | 98 | py::arg("id")="", | |
| 52 | 99 | py::arg("score_list")="" | |
| 53 | 100 | ); | |
| 54 | 101 | ||
| 55 | 102 | m.def( | |
| 56 | - "augmentShapefileWithScores", | ||
| 57 | - &augmentShapefileWithScores, | ||
| 58 | - "Given the filename of a shapefile, this function calculates the scores of its shapes and adds them to the file.", | ||
| 59 | - py::arg("filename"), | ||
| 103 | + "getBoundedScoresForGeoJSON", | ||
| 104 | + &getBoundedScoresForGeoJSON, | ||
| 105 | + "Takes a GeoJSON string as input, calculates all scores, return a JSON dictionary of the scores keyed to values identified 'id' which are expected to be properties of the GeoJSON objects. If id='', then the object's 0-indexed order is used.", | ||
| 106 | + py::arg("gj_subunit"), | ||
| 107 | + py::arg("gj_superunit"), | ||
| 108 | + py::arg("join_on")="", | ||
| 109 | + py::arg("join_id")="", | ||
| 110 | + py::arg("score_list")="" | ||
| 111 | + ); | ||
| 112 | + | ||
| 113 | + m.def( | ||
| 114 | + "augmentShapefileWithBoundedScores", | ||
| 115 | + &augmentShapefileWithBoundedScores, | ||
| 116 | + "Given the filename of a shapefile containing subunits, and another of superunits, this function calculates the scores of its shapes and adds them to the file.", | ||
| 117 | + py::arg("subunit_filename"), | ||
| 118 | + py::arg("superunit_filename"), | ||
| 119 | + py::arg("join_id")="", | ||
| 60 | 120 | py::arg("score_list")="" | |
| 61 | 121 | ); | |
| 62 | 122 | ||
| 63 | 123 | m.def( | |
| 64 | - "addScoresToNewShapefile", | ||
| 65 | - &addScoresToNewShapefile, | ||
| 124 | + "addBoundedScoresToNewShapefile", | ||
| 125 | + &addBoundedScoresToNewShapefile, | ||
| 66 | 126 | "Reads a shapefile, calculates its scores, and outputs a new shapefile.", | |
| 67 | - py::arg("in_filename"), | ||
| 68 | - py::arg("out_filename"), | ||
| 127 | + py::arg("in_subunit_filename")="", | ||
| 128 | + py::arg("in_superunit_filename")="", | ||
| 129 | + py::arg("out_filename")="", | ||
| 130 | + py::arg("join_on")="", | ||
| 69 | 131 | py::arg("score_list")="" | |
| 70 | 132 | ); | |
| 71 | 133 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments