IODA
LocalObsSpace.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2020 UCAR
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
8 #ifndef TEST_IODA_LOCALOBSSPACE_H_
9 #define TEST_IODA_LOCALOBSSPACE_H_
10 
11 #include <algorithm>
12 #include <string>
13 #include <vector>
14 
15 #define ECKIT_TESTING_SELF_REGISTER_CASES 0
16 
17 #include <boost/shared_ptr.hpp>
18 
19 #include "eckit/config/LocalConfiguration.h"
20 #include "eckit/testing/Test.h"
21 
22 #include "oops/mpi/mpi.h"
23 #include "oops/runs/Test.h"
24 #include "oops/test/TestEnvironment.h"
25 
26 #include "ioda/IodaTrait.h"
27 #include "ioda/ObsSpace.h"
29 
30 namespace ioda {
31 namespace test {
32 
33 // -----------------------------------------------------------------------------
34 
36  typedef ObsSpaceTestFixture Test_;
37 
38  std::vector<eckit::LocalConfiguration> conf;
39  ::test::TestEnvironment::config().get("observations", conf);
40 
41 
42  for (std::size_t jj = 0; jj < Test_::size(); ++jj) {
43  double lonpt = conf[jj].getDouble("obs space.localization.lon ref point");
44  double latpt = conf[jj].getDouble("obs space.localization.lat ref point");
45  eckit::geometry::Point2 refPoint(lonpt, latpt);
46 
47  // Create local obsspace object
48  eckit::LocalConfiguration locconf(conf[jj], "obs space.localization");
49  std::string searchMethods[2] = {"brute_force", "kd_tree"};
50  // Loop through search methods
51  for (const std::string &searchMethod : searchMethods) {
52  locconf.set("search method", searchMethod);
53  oops::Log::debug() << "Using " << searchMethod << " for search method" << std::endl;
54  ioda::ObsSpace obsspace_local(Test_::obspace(jj), refPoint, locconf);
55  // Get the numbers of locations (nlocs) from the local obspace object
56  std::size_t Nlocs = obsspace_local.nlocs();
57  oops::Log::debug() << "Nlocs_local = " << Nlocs << std::endl;
58  obsspace_local.comm().allReduceInPlace(Nlocs, eckit::mpi::sum());
59  // Get the expected nlocs from the obspace object's configuration
60  std::size_t ExpectedNlocs =
61  conf[jj].getUnsigned("obs space.test data.expected local nlocs");
62  oops::Log::debug() << "Expected Nlocs_local = " << ExpectedNlocs << std::endl;
63  EXPECT(Nlocs == ExpectedNlocs);
64  // test localization distances
65  std::vector<double> obsdist = obsspace_local.obsdist();
66  double distance = conf[jj].getDouble("obs space.localization.lengthscale");
67  oops::Log::debug() << "loc_ dist" << distance << std::endl;
68  if (!obsdist.empty()) {
69  oops::Log::debug() << "loc_obs_dist(min,max) = " <<
70  *std::min_element(obsdist.begin(), obsdist.end()) << " "<<
71  *std::max_element(obsdist.begin(), obsdist.end()) << std::endl;
72  EXPECT(*std::max_element(obsdist.begin(), obsdist.end()) <= distance);
73  EXPECT(*std::min_element(obsdist.begin(), obsdist.end()) > 0.0);
74  }
75  }
76  }
77 }
78 
79 // -----------------------------------------------------------------------------
80 
81 class LocalObsSpace : public oops::Test {
82  public:
84  virtual ~LocalObsSpace() {}
85  private:
86  std::string testid() const override {return "test::LocalObsSpace<ioda::IodaTrait>";}
87 
88  void register_tests() const override {
89  std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
90 
91  ts.emplace_back(CASE("ioda/LocalObsSpace/testConstructor_local")
92  { testConstructor_local(); });
93  }
94 
95  void clear() const override {}
96 };
97 
98 // -----------------------------------------------------------------------------
99 
100 } // namespace test
101 } // namespace ioda
102 
103 #endif // TEST_IODA_LOCALOBSSPACE_H_
ObsSpace.h
ioda::ObsSpace::comm
const eckit::mpi::Comm & comm() const
Definition: src/ObsSpace.h:103
ioda::test::LocalObsSpace::register_tests
void register_tests() const override
Definition: LocalObsSpace.h:88
ioda::test::LocalObsSpace::testid
std::string testid() const override
Definition: LocalObsSpace.h:86
ioda::test::ObsSpaceTestFixture
Definition: test/ioda/ObsSpace.h:35
ioda
Definition: IodaUtils.cc:13
ioda::test::LocalObsSpace::~LocalObsSpace
virtual ~LocalObsSpace()
Definition: LocalObsSpace.h:84
ioda::ObsSpace::nlocs
std::size_t nlocs() const
Definition: ObsSpace.cc:344
ioda::test::LocalObsSpace::clear
void clear() const override
Definition: LocalObsSpace.h:95
ioda::test::testConstructor_local
void testConstructor_local()
Definition: LocalObsSpace.h:35
ioda::test::LocalObsSpace::LocalObsSpace
LocalObsSpace()
Definition: LocalObsSpace.h:83
ioda::test::LocalObsSpace
Definition: LocalObsSpace.h:81
ioda::ObsSpace
Observation Space View.
Definition: src/ObsSpace.h:35
ioda::ObsSpace::obsdist
const std::vector< double > & obsdist() const
Definition: src/ObsSpace.h:108