Skip to content

Commit

Permalink
eckit::geo test_projspec
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaciel committed Oct 8, 2023
1 parent 7a2da20 commit 5f47af0
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 68 deletions.
9 changes: 7 additions & 2 deletions src/eckit/geo/Projection.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

namespace eckit {
class Configuration;
}
class MappedConfiguration;
} // namespace eckit


namespace eckit::geo {
Expand All @@ -34,6 +35,8 @@ class Projection {
using builder_t = BuilderT1<Projection>;
using ARG1 = const Configuration&;

using Spec = MappedConfiguration;

// -- Exceptions
// None

Expand All @@ -57,10 +60,12 @@ class Projection {

// -- Methods

static std::string className() { return "projection"; }

virtual Point fwd(const Point&) const = 0;
virtual Point inv(const Point&) const = 0;

static std::string className() { return "projection"; }
virtual Spec spec() const = 0;

// -- Overridden methods
// None
Expand Down
12 changes: 9 additions & 3 deletions src/eckit/geo/projection/LonLatToXYZ.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include "eckit/geo/projection/LonLatToXYZ.h"

#include "eckit/config/Configuration.h"
#include "eckit/config/MappedConfiguration.h"
#include "eckit/geo/EllipsoidOfRevolution.h"
#include "eckit/geo/Sphere.h"
#include "eckit/types/FloatCompare.h"
Expand All @@ -25,8 +25,7 @@ static ProjectionBuilder<LonLatToXYZ> __projection("ll_to_xyz");


LonLatToXYZ::LonLatToXYZ(double a, double b) {
ASSERT(0. < a);
ASSERT(0. < b);
ASSERT_MSG(types::is_strictly_greater(b, 0.) && b <= a, "LonLatToXYZ requires 0 < b <= a");

struct LonLatToSphereXYZ final : Implementation {
using S = Sphere;
Expand All @@ -36,6 +35,7 @@ LonLatToXYZ::LonLatToXYZ(double a, double b) {
R_(R) {}
Point3 operator()(const PointLonLat& p) const override { return S::convertSphericalToCartesian(R_, p, 0.); }
PointLonLat operator()(const Point3& q) const override { return S::convertCartesianToSpherical(R_, q); }
Spec spec() const override { return Spec{{{"R", R_}}}; }
};

struct LonLatToSpheroidXYZ final : Implementation {
Expand All @@ -47,6 +47,7 @@ LonLatToXYZ::LonLatToXYZ(double a, double b) {
a_(a), b_(b) {}
Point3 operator()(const PointLonLat& p) const override { return S::convertSphericalToCartesian(a_, b_, p, 0.); }
PointLonLat operator()(const Point3& q) const override { NOTIMP; }
Spec spec() const override { return Spec{{{"a", a_}, {"b", b_}}}; }
};

impl_.reset(types::is_approximately_equal(a, b) ? static_cast<Implementation*>(new LonLatToSphereXYZ(a))
Expand All @@ -62,4 +63,9 @@ LonLatToXYZ::LonLatToXYZ(const Configuration& config) :
LonLatToXYZ(config.getDouble("a", config.getDouble("R", 1.)), config.getDouble("b", config.getDouble("R", 1.))) {}


Projection::Spec LonLatToXYZ::spec() const {
return impl_->spec();
}


} // namespace eckit::geo::projection
4 changes: 3 additions & 1 deletion src/eckit/geo/projection/LonLatToXYZ.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class LonLatToXYZ final : public Projection {
PointLonLat inv(const Point3& q) const { return (*impl_)(q); }

// -- Overridden methods
// None

Spec spec() const override;

// -- Class members
// None
Expand All @@ -69,6 +70,7 @@ class LonLatToXYZ final : public Projection {

virtual Point3 operator()(const PointLonLat&) const = 0;
virtual PointLonLat operator()(const Point3&) const = 0;
virtual Spec spec() const = 0;
};

// -- Members
Expand Down
7 changes: 7 additions & 0 deletions src/eckit/geo/projection/None.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include "eckit/geo/projection/None.h"

#include "eckit/config/MappedConfiguration.h"


namespace eckit::geo::projection {

Expand All @@ -25,4 +27,9 @@ static ProjectionBuilder<None> __projection4("plate-carree");
None::None(const Configuration&) {}


Projection::Spec None::spec() const {
return Spec{};
}


} // namespace eckit::geo::projection
3 changes: 2 additions & 1 deletion src/eckit/geo/projection/None.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class None final : public Projection {
// None

// -- Overridden methods
// None

Spec spec() const override;

// -- Class members
// None
Expand Down
7 changes: 6 additions & 1 deletion src/eckit/geo/projection/PROJ.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include "eckit/geo/projection/PROJ.h"

#include "eckit/config/Configuration.h"
#include "eckit/config/MappedConfiguration.h"
#include "eckit/exception/Exceptions.h"


Expand Down Expand Up @@ -123,4 +123,9 @@ Point PROJ::inv(const Point& q) const {
}


Projection::Spec PROJ::spec() const {
return Spec{{{"source", source_}, {"target", target_}}};
}


} // namespace eckit::geo::projection
2 changes: 2 additions & 0 deletions src/eckit/geo/projection/PROJ.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class PROJ final : public Projection {
Point fwd(const Point&) const override;
Point inv(const Point&) const override;

Spec spec() const override;

// -- Class members
// None

Expand Down
19 changes: 17 additions & 2 deletions src/eckit/geo/projection/Rotation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <cmath>
#include <utility>

#include "eckit/config/Configuration.h"
#include "eckit/config/MappedConfiguration.h"
#include "eckit/geo/UnitSphere.h"
#include "eckit/geo/util.h"
#include "eckit/maths/Matrix3.h"
Expand All @@ -38,22 +38,32 @@ Rotation::Rotation(double south_pole_lon, double south_pole_lat, double angle) :

struct NonRotated final : Rotate {
PointLonLat operator()(const PointLonLat& p) const override { return p; }
Spec spec() const override { return Spec{}; }
};

struct RotationAngle final : Rotate {
explicit RotationAngle(double angle) :
angle_(angle) {}
PointLonLat operator()(const PointLonLat& p) const override { return {p.lon + angle_, p.lat}; }
Spec spec() const override { return Spec{{{"angle", angle_}}}; }
const double angle_;
};

struct RotationMatrix final : Rotate {
explicit RotationMatrix(M&& R) :
R_(R) {}
RotationMatrix(std::move(R), 0, 0, 0) {}
RotationMatrix(M&& R, double south_pole_lon, double south_pole_lat, double angle) :
R_(R), south_pole_lon_(south_pole_lon), south_pole_lat_(south_pole_lat), angle_(angle) {}
PointLonLat operator()(const PointLonLat& p) const override {
return UnitSphere::convertCartesianToSpherical(R_ * UnitSphere::convertSphericalToCartesian(p));
}
Spec spec() const override {
return Spec{{{"south_pole_lon", south_pole_lon_}, {"south_pole_lat", south_pole_lat_}, {"angle", angle_}}};
}
const M R_;
const double south_pole_lon_;
const double south_pole_lat_;
const double angle_;
};

const auto alpha = util::degree_to_radian * angle;
Expand Down Expand Up @@ -114,4 +124,9 @@ Rotation::Rotation(const Configuration& config) :
Rotation(config.getDouble("south_pole_lon"), config.getDouble("south_pole_lat"), config.getDouble("angle", 0)) {}


Projection::Spec Rotation::spec() const {
return fwd_->spec();
}


} // namespace eckit::geo::projection
4 changes: 3 additions & 1 deletion src/eckit/geo/projection/Rotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class Rotation final : public Projection {
PointLonLat inv(const PointLonLat& q) const { return (*inv_)(q); }

// -- Overridden methods
// None

Spec spec() const override;

// -- Class members
// None
Expand All @@ -69,6 +70,7 @@ class Rotation final : public Projection {
void operator=(Rotate&&) = delete;

virtual PointLonLat operator()(const PointLonLat&) const = 0;
virtual Spec spec() const = 0;
};

// -- Members
Expand Down
Loading

0 comments on commit 5f47af0

Please sign in to comment.