8 #ifndef TEST_INTERFACE_OBSLOCALIZATION_H_
9 #define TEST_INTERFACE_OBSLOCALIZATION_H_
16 #define ECKIT_TESTING_SELF_REGISTER_CASES 0
18 #include <boost/noncopyable.hpp>
20 #include "eckit/config/LocalConfiguration.h"
21 #include "eckit/testing/Test.h"
53 for (
size_t jj = 0; jj < Test_::obspace().size(); ++jj) {
54 const ObsSpace_ & obspace = Test_::obspace()[jj];
56 eckit::LocalConfiguration locconf(Test_::config(jj),
"obs localization");
59 const std::vector<double> lons = locconf.getDoubleVector(
"reference gridpoints.lons");
60 const std::vector<double> lats = locconf.getDoubleVector(
"reference gridpoints.lats");
61 const std::vector<size_t> nobs_local_ref = locconf.getUnsignedVector(
"reference local nobs");
62 ASSERT(lons.size() == lats.size());
63 ASSERT(lons.size() == nobs_local_ref.size());
64 ASSERT(lons.size() > 0);
65 std::vector<eckit::geometry::Point2> reference_points;
66 for (
size_t jpoint = 0; jpoint < lons.size(); ++jpoint) {
67 reference_points.emplace_back(lons[jpoint], lats[jpoint]);
69 std::unique_ptr<ObsLocalization_> obsloc =
71 oops::Log::test() <<
"Testing obs-space localization: " << *obsloc << std::endl;
73 ObsVector_ locvector(obspace);
74 ObsVector_ obsvector(obspace);
76 size_t total_tested = 0;
77 std::vector<size_t> nobs_local(nobs_local_ref.size(), 0);
78 std::vector<double> locvector_rms(nobs_local_ref.size(), 0);
80 for (GeometryIterator_ ii = geometry.begin(); ii != geometry.end(); ++ii) {
83 if (locconf.getBool(
"print iterator",
false)) {
84 oops::Log::debug() <<
"Iterating over " << std::setprecision(9) << ii <<
": "
89 const auto & it = std::find_if(reference_points.begin(), reference_points.end(),
90 [ii] (
const eckit::geometry::Point2 & point) {return point.distance(*ii) < 1e-5;});
91 if (it != reference_points.end()) {
93 size_t index = it - reference_points.begin();
95 obsloc->computeLocalization(ii, locvector);
96 oops::Log::test() <<
"Obs localization with geometry iterator: " << ii <<
": "
98 oops::Log::test() <<
"Localization values: " << locvector << std::endl;
99 oops::Log::test() <<
"Local vector nobs and reference: " << locvector.nobs() <<
", "
100 << nobs_local_ref[index] << std::endl;
101 oops::Log::debug() <<
"Local vector stats lat,lon,nobs,rms: " << *ii <<
", "
102 << locvector.nobs() <<
", " << locvector.rms() << std::endl;
105 nobs_local[index] = locvector.nobs();
109 obsvector *= locvector;
110 oops::Log::test() <<
"Localization applied to local ObsVector of ones: " <<
111 obsvector << std::endl;
113 locvector_rms[index] = obsvector.rms();
118 Test_::comm().allReduceInPlace(total_tested, eckit::mpi::sum());
119 Test_::comm().allReduceInPlace(nobs_local.begin(), nobs_local.end(), eckit::mpi::sum());
120 Test_::comm().allReduceInPlace(locvector_rms.begin(), locvector_rms.end(), eckit::mpi::sum());
122 EXPECT_EQUAL(total_tested, lons.size());
124 EXPECT_EQUAL(nobs_local_ref, nobs_local);
126 const std::vector<double> ref_locvector_rms = locconf.getDoubleVector(
"reference rms");
127 ASSERT(lons.size() == ref_locvector_rms.size());
128 oops::Log::debug() <<
"reference RMS" << ref_locvector_rms << std::endl;
129 oops::Log::debug() <<
"computed RMS" << locvector_rms << std::endl;
130 for (
size_t jpoint = 0; jpoint < nobs_local.size(); ++jpoint) {
131 if (nobs_local[jpoint] > 0) {
132 EXPECT(std::abs(locvector_rms[jpoint]-ref_locvector_rms[jpoint]) < 1.e-5);
148 std::string
testid()
const override {
return "test::ObsLocalization<" + MODEL::name() +
","
149 + OBS::name() +
">";}
152 std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
154 ts.emplace_back(
CASE(
"interface/ObsLocalization/testObsLocalization")
155 { testObsLocalization<MODEL, OBS>(); });
Geometry class used in oops; subclass of interface class interface::Geometry.
static std::unique_ptr< ObsLocalizationBase< MODEL, OBS > > create(const eckit::Configuration &, const ObsSpace_ &)
ObsVector class used in oops; subclass of interface class interface::ObsVector.
ObsLocalization()=default
virtual ~ObsLocalization()=default
void register_tests() const override
ObsTestsFixture< OBS > Test_
std::string testid() const override
void clear() const override
static const eckit::Configuration & config()
const eckit::mpi::Comm & world()
Default communicator with all MPI tasks (ie MPI_COMM_WORLD)
void testObsLocalization()
Tests ObsLocalization::computeLocalization method.
CASE("test_linearmodelparameterswrapper_valid_name")