From 8eb6ea70749f00bec2be5301a9f0198e4dbba1da Mon Sep 17 00:00:00 2001 From: hugo pendlebury Date: Thu, 14 Mar 2024 11:42:13 +0000 Subject: [PATCH] filtering option --- pythonApi/grib_to_arrow.cpp | 7 +++++++ src/gribreader.cpp | 9 +++++++++ src/gribreader.hpp | 2 ++ 3 files changed, 18 insertions(+) diff --git a/pythonApi/grib_to_arrow.cpp b/pythonApi/grib_to_arrow.cpp index 200030f..185b5a5 100644 --- a/pythonApi/grib_to_arrow.cpp +++ b/pythonApi/grib_to_arrow.cpp @@ -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(), 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>(&GribReader::withLocations), pybind11::call_guard(), R"EOL( Adds locations which will be filtered in each message. diff --git a/src/gribreader.cpp b/src/gribreader.cpp index 1a3c9b6..feeaca8 100644 --- a/src/gribreader.cpp +++ b/src/gribreader.cpp @@ -106,6 +106,11 @@ std::shared_ptr GribReader::enrichLocationsWithSurrogateKey(std::s } +GribReader GribReader::withEnabledStationFiltering(bool enableFiltering) { + this->filteringEnabled = enableFiltering; + return *this; +} + GribReader GribReader::withRepeatableIterator(bool repeatable) { this->isRepeatable = repeatable; @@ -383,6 +388,10 @@ GribLocationData* GribReader::addLocationDataToCache(std::unique_ptr& std::shared_ptr GribReader::getLocations(std::unique_ptr& area) { + if (!filteringEnabled) { + return shared_locations; + } + auto ga = *area.get(); if (auto search = locations_in_area.find(ga); search != locations_in_area.end()) { diff --git a/src/gribreader.hpp b/src/gribreader.hpp index eaebfca..23e9506 100644 --- a/src/gribreader.hpp +++ b/src/gribreader.hpp @@ -34,6 +34,7 @@ class GribReader GribReader withConversions(std::shared_ptr conversions); GribReader withConversions(std::string path); GribReader withRepeatableIterator(bool repeatable); + GribReader withEnabledStationFiltering(bool enableFiltering); Iterator begin(); Iterator end(); @@ -54,6 +55,7 @@ class GribReader string filepath; int err = 0; bool isRepeatable = false; + bool filteringEnabled = true; bool isExhausted = false; std::shared_ptr shared_locations; std::unordered_map> locations_in_area;