Skip to content

Commit

Permalink
eckit::geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaciel committed Aug 25, 2023
1 parent 0bc78bb commit e3cfa59
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/eckit/geometry/PointLonLat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/eckit/geometry/PointLonLat.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,6 @@ class PointLonLat final : protected std::array<double, 2> {

bool points_equal(const PointLonLat&, const PointLonLat&);

bool operator<(const PointLonLat&, const PointLonLat&);

} // namespace eckit::geometry
4 changes: 2 additions & 2 deletions src/eckit/geometry/grid/HEALPix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ HEALPix::HEALPix(size_t Nside, Ordering ordering) :

Configuration* HEALPix::config(const std::string& name) {
auto Nside = Translator<std::string, size_t>{}(name.substr(1));
return new MappedConfiguration({{"type", "healpix"}, {"Nside", Nside}, {"orderingConvention", "ring"}});
return new MappedConfiguration({{"type", "HEALPix"}, {"Nside", Nside}, {"orderingConvention", "ring"}});
}


Expand Down Expand Up @@ -217,7 +217,7 @@ std::pair<std::vector<double>, std::vector<double>> HEALPix::to_latlon() const {
}


static const GridRegisterType<HEALPix> __grid_type("healpix");
static const GridRegisterType<HEALPix> __grid_type("HEALPix");
static const GridRegisterName<HEALPix> __grid_pattern("[hH][1-9][0-9]*");


Expand Down
2 changes: 1 addition & 1 deletion src/eckit/geometry/grid/ORCA.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ ORCA::ORCA(const Configuration& config) :
PathName::rename(tmp, path);
Log::info() << "ORCA: download of " << Bytes(static_cast<double>(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);
Expand Down
19 changes: 19 additions & 0 deletions src/eckit/geometry/grid/UnstructuredGrid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include "eckit/geometry/grid/UnstructuredGrid.h"

#include <set>

#include "eckit/config/Configuration.h"
#include "eckit/exception/Exceptions.h"
#include "eckit/geometry/iterator/ListI.h"
Expand All @@ -36,8 +38,25 @@ UnstructuredGrid::UnstructuredGrid(const std::vector<double>& latitudes, const s
}


Renumber UnstructuredGrid::list_duplicates() const {
std::vector<size_t> dupes;

std::set<PointLonLat> seen;

for (auto i = cbegin(); i != cend(); ++i) {
if (!seen.insert(std::get<PointLonLat>(*i)).second) {
dupes.push_back(i->index());
}
}

return dupes;
}


UnstructuredGrid::UnstructuredGrid(std::pair<std::vector<double>, std::vector<double>>&& 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());
}


Expand Down
3 changes: 2 additions & 1 deletion src/eckit/geometry/grid/UnstructuredGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class UnstructuredGrid : public Grid {
// None

// -- Methods
// None

Renumber list_duplicates() const;

// -- Overridden methods
// None
Expand Down

0 comments on commit e3cfa59

Please sign in to comment.