FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Added bounded scores · PibeG/python-mander@76d82de · GitHub

Commit 76d82de

Browse files
committed
Added bounded scores
1 parent 7c634c4 commit 76d82de

1 file changed

Lines changed: 85 additions & 23 deletions

File tree

‎src/pywrapper.cpp‎

Lines changed: 85 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,62 +10,124 @@ namespace py = pybind11;
1010
//https://pybind11.readthedocs.io/en/stable/classes.html
1111
//http://people.duke.edu/~ccc14/sta-663-2016/18G_C++_Python_pybind11.html
1212

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){
1814
auto gc = complib::ReadGeoJSON(geojson);
19-
complib::CalculateListOfScores(gc, score_list);
15+
complib::CalculateListOfUnboundedScores(gc, score_list);
2016
return complib::OutScoreJSON(gc, id);
2117
}
2218

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){
2420
auto gc = complib::ReadShapefile(filename);
25-
complib::CalculateListOfScores(gc, score_list);
21+
complib::CalculateListOfUnboundedScores(gc, score_list);
2622
complib::WriteShapeScores(gc, filename);
2723
}
2824

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){
3026
auto gc = complib::ReadShapefile(in_filename);
31-
complib::CalculateListOfScores(gc, score_list);
27+
complib::CalculateListOfUnboundedScores(gc, score_list);
3228
complib::WriteShapefile(gc,out_filename);
3329
}
3430

3531

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+
}
3671

3772
PYBIND11_PLUGIN(_mander) {
3873
py::module m("_mander", "Internal library used by python-mander to calculate scores");
3974

4075
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."
4485
);
4586

4687
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,
4996
"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.",
5097
py::arg("geojson"),
5198
py::arg("id")="",
5299
py::arg("score_list")=""
53100
);
54101

55102
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")="",
60120
py::arg("score_list")=""
61121
);
62122

63123
m.def(
64-
"addScoresToNewShapefile",
65-
&addScoresToNewShapefile,
124+
"addBoundedScoresToNewShapefile",
125+
&addBoundedScoresToNewShapefile,
66126
"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")="",
69131
py::arg("score_list")=""
70132
);
71133

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL