Skip to content

Commit

Permalink
filtering option
Browse files Browse the repository at this point in the history
  • Loading branch information
hugopendlebury committed Mar 14, 2024
1 parent d8e44b0 commit 8eb6ea7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pythonApi/grib_to_arrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ PYBIND11_MODULE(gribtoarrow, m)
----------
filepath (str): A string containing the full path of the grib file
)EOL") // constructor
.def("withEnabledStationFiltering", &GribReader::withEnabledStationFiltering, pybind11::call_guard<pybind11::gil_scoped_release>(), R"EOL(
Enables location data filtering to be disabled
Parameters
----------
bool - If True filtering will be done based on the location data and the coorindates of the message
)EOL")
.def("withLocations", py::overload_cast<std::shared_ptr<arrow::Table>>(&GribReader::withLocations), pybind11::call_guard<pybind11::gil_scoped_release>(), R"EOL(
Adds locations which will be filtered in each message.
Expand Down
9 changes: 9 additions & 0 deletions src/gribreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ std::shared_ptr<arrow::Table> GribReader::enrichLocationsWithSurrogateKey(std::s

}

GribReader GribReader::withEnabledStationFiltering(bool enableFiltering) {
this->filteringEnabled = enableFiltering;
return *this;
}


GribReader GribReader::withRepeatableIterator(bool repeatable) {
this->isRepeatable = repeatable;
Expand Down Expand Up @@ -383,6 +388,10 @@ GribLocationData* GribReader::addLocationDataToCache(std::unique_ptr<GridArea>&

std::shared_ptr<arrow::Table> GribReader::getLocations(std::unique_ptr<GridArea>& area) {

if (!filteringEnabled) {
return shared_locations;
}

auto ga = *area.get();

if (auto search = locations_in_area.find(ga); search != locations_in_area.end()) {
Expand Down
2 changes: 2 additions & 0 deletions src/gribreader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class GribReader
GribReader withConversions(std::shared_ptr<arrow::Table> conversions);
GribReader withConversions(std::string path);
GribReader withRepeatableIterator(bool repeatable);
GribReader withEnabledStationFiltering(bool enableFiltering);

Iterator begin();
Iterator end();
Expand All @@ -54,6 +55,7 @@ class GribReader
string filepath;
int err = 0;
bool isRepeatable = false;
bool filteringEnabled = true;
bool isExhausted = false;
std::shared_ptr<arrow::Table> shared_locations;
std::unordered_map<GridArea, std::shared_ptr<arrow::Table>> locations_in_area;
Expand Down

0 comments on commit 8eb6ea7

Please sign in to comment.