From e3cfa592ded16bf90558f172c397eb3526ceed8a Mon Sep 17 00:00:00 2001 From: Pedro Maciel Date: Fri, 25 Aug 2023 12:27:13 +0100 Subject: [PATCH] eckit::geometry --- src/eckit/geometry/PointLonLat.cc | 9 +++++++++ src/eckit/geometry/PointLonLat.h | 2 ++ src/eckit/geometry/grid/HEALPix.cc | 4 ++-- src/eckit/geometry/grid/ORCA.cc | 2 +- src/eckit/geometry/grid/UnstructuredGrid.cc | 19 +++++++++++++++++++ src/eckit/geometry/grid/UnstructuredGrid.h | 3 ++- 6 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/eckit/geometry/PointLonLat.cc b/src/eckit/geometry/PointLonLat.cc index 6ef284aba..068a52540 100644 --- a/src/eckit/geometry/PointLonLat.cc +++ b/src/eckit/geometry/PointLonLat.cc @@ -46,4 +46,13 @@ double PointLonLat::normalise_angle_to_maximum(double a, double maximum) { } +bool operator<(const PointLonLat& a, const PointLonLat& b) { + if (types::is_approximately_equal(a.lon, b.lon) || types::is_approximately_equal(a.lat, b.lat)) { + return false; + } + + return a.lon < b.lon && a.lat < b.lat; +} + + } // namespace eckit::geometry diff --git a/src/eckit/geometry/PointLonLat.h b/src/eckit/geometry/PointLonLat.h index e1edd6f94..2cf4917b4 100644 --- a/src/eckit/geometry/PointLonLat.h +++ b/src/eckit/geometry/PointLonLat.h @@ -111,4 +111,6 @@ class PointLonLat final : protected std::array { bool points_equal(const PointLonLat&, const PointLonLat&); +bool operator<(const PointLonLat&, const PointLonLat&); + } // namespace eckit::geometry diff --git a/src/eckit/geometry/grid/HEALPix.cc b/src/eckit/geometry/grid/HEALPix.cc index f021d8153..e3ff6298e 100644 --- a/src/eckit/geometry/grid/HEALPix.cc +++ b/src/eckit/geometry/grid/HEALPix.cc @@ -131,7 +131,7 @@ HEALPix::HEALPix(size_t Nside, Ordering ordering) : Configuration* HEALPix::config(const std::string& name) { auto Nside = Translator{}(name.substr(1)); - return new MappedConfiguration({{"type", "healpix"}, {"Nside", Nside}, {"orderingConvention", "ring"}}); + return new MappedConfiguration({{"type", "HEALPix"}, {"Nside", Nside}, {"orderingConvention", "ring"}}); } @@ -217,7 +217,7 @@ std::pair, std::vector> HEALPix::to_latlon() const { } -static const GridRegisterType __grid_type("healpix"); +static const GridRegisterType __grid_type("HEALPix"); static const GridRegisterName __grid_pattern("[hH][1-9][0-9]*"); diff --git a/src/eckit/geometry/grid/ORCA.cc b/src/eckit/geometry/grid/ORCA.cc index e858d0540..ac44c470c 100644 --- a/src/eckit/geometry/grid/ORCA.cc +++ b/src/eckit/geometry/grid/ORCA.cc @@ -148,9 +148,9 @@ ORCA::ORCA(const Configuration& config) : PathName::rename(tmp, path); Log::info() << "ORCA: download of " << Bytes(static_cast(length)) << " took " << timer.elapsed() << " s." << std::endl; } +#endif ASSERT_MSG(path.exists(), "ORCA: file '" + path + "' not found"); -#endif // read and check against metadata (if present) read(path); diff --git a/src/eckit/geometry/grid/UnstructuredGrid.cc b/src/eckit/geometry/grid/UnstructuredGrid.cc index 9656a43b5..4f18ec24a 100644 --- a/src/eckit/geometry/grid/UnstructuredGrid.cc +++ b/src/eckit/geometry/grid/UnstructuredGrid.cc @@ -12,6 +12,8 @@ #include "eckit/geometry/grid/UnstructuredGrid.h" +#include + #include "eckit/config/Configuration.h" #include "eckit/exception/Exceptions.h" #include "eckit/geometry/iterator/ListI.h" @@ -36,8 +38,25 @@ UnstructuredGrid::UnstructuredGrid(const std::vector& latitudes, const s } +Renumber UnstructuredGrid::list_duplicates() const { + std::vector dupes; + + std::set seen; + + for (auto i = cbegin(); i != cend(); ++i) { + if (!seen.insert(std::get(*i)).second) { + dupes.push_back(i->index()); + } + } + + return dupes; +} + + UnstructuredGrid::UnstructuredGrid(std::pair, std::vector>&& latlon) : Grid(area::BoundingBox::make_global_prime()), latitudes_(std::move(latlon.first)), longitudes_(std::move(latlon.second)) { + ASSERT(!latitudes_.empty()); + ASSERT(latitudes_.size() == longitudes_.size()); } diff --git a/src/eckit/geometry/grid/UnstructuredGrid.h b/src/eckit/geometry/grid/UnstructuredGrid.h index ae43a45c5..083686ee6 100644 --- a/src/eckit/geometry/grid/UnstructuredGrid.h +++ b/src/eckit/geometry/grid/UnstructuredGrid.h @@ -47,7 +47,8 @@ class UnstructuredGrid : public Grid { // None // -- Methods - // None + + Renumber list_duplicates() const; // -- Overridden methods // None