8 #ifndef TEST_UFO_LOCATIONS_H_
9 #define TEST_UFO_LOCATIONS_H_
15 #define ECKIT_TESTING_SELF_REGISTER_CASES 0
17 #include "eckit/config/LocalConfiguration.h"
18 #include "eckit/testing/Test.h"
19 #include "ioda/ObsSpace.h"
20 #include "oops/mpi/mpi.h"
21 #include "oops/runs/Test.h"
22 #include "oops/util/DateTime.h"
23 #include "oops/util/FloatCompare.h"
24 #include "oops/util/Logger.h"
25 #include "oops/util/parameters/Parameters.h"
26 #include "oops/util/parameters/RequiredParameter.h"
27 #include "test/TestEnvironment.h"
28 #include "ufo/Locations.h"
38 oops::RequiredParameter<util::DateTime>
t1{
"t1",
this};
39 oops::RequiredParameter<util::DateTime>
t2{
"t2",
this};
41 oops::RequiredParameter<std::vector<bool>>
refTimeMask{
"reference mask",
this};
49 oops::RequiredParameter<std::vector<float>>
refLons{
"reference lons",
this};
51 oops::RequiredParameter<std::vector<float>>
refLats{
"reference lats",
this};
53 oops::RequiredParameter<std::vector<LocationsTimeTestParameters>>
67 return theLocationsTestFixture;
71 const eckit::Configuration & conf = ::test::TestEnvironment::config();
72 util::DateTime bgn(conf.getString(
"window begin"));
73 util::DateTime end(conf.getString(
"window end"));
74 const eckit::LocalConfiguration obsconf(conf,
"obs space");
75 ioda::ObsTopLevelParameters obsparams;
76 obsparams.validateAndDeserialize(obsconf);
77 obsspace_.reset(
new ioda::ObsSpace(obsparams, oops::mpi::world(), bgn, end,
78 oops::mpi::myself()));
79 testconfig_ = conf.getSubConfiguration(
"locations test");
93 const size_t nlocs = Test_::obsspace().nlocs();
96 const eckit::LocalConfiguration conf(::test::TestEnvironment::config());
97 Locations locs1(conf, oops::mpi::world());
98 EXPECT(locs1.size() ==
nlocs);
99 oops::Log::test() <<
"Locations(configuration, eckit mpi communicator): " << locs1 << std::endl;
112 const eckit::LocalConfiguration conf(::test::TestEnvironment::config());
113 Locations locs(conf, oops::mpi::world());
116 const float abstol = 1.0e-8;
117 EXPECT(oops::are_all_close_absolute(params.
refLons.value(), locs.lons(), abstol));
118 EXPECT(oops::are_all_close_absolute(params.
refLats.value(), locs.lats(), abstol));
132 const eckit::LocalConfiguration conf(::test::TestEnvironment::config());
133 Locations locs(conf, oops::mpi::world());
143 const eckit::LocalConfiguration conf(::test::TestEnvironment::config());
144 Locations locs(conf, oops::mpi::world());
148 EXPECT_EQUAL(test.refTimeMask.value(), locs.isInTimeWindow(test.t1, test.t2));
163 const eckit::LocalConfiguration conf(::test::TestEnvironment::config());
164 Locations locs(conf, oops::mpi::world());
174 const eckit::LocalConfiguration conf(::test::TestEnvironment::config());
175 Locations locs1(conf, oops::mpi::world());
176 Locations locs2(conf, oops::mpi::world());
177 const size_t nlocs = locs1.size();
181 EXPECT_EQUAL(locs1.size(), 2*
nlocs);
183 const float abstol = 1.0e-8;
186 const std::vector<float> & lons = locs1.lons();
187 std::vector<float> lons1(lons.begin(), lons.begin() +
nlocs);
188 std::vector<float> lons2(lons.begin() +
nlocs, lons.end());
189 EXPECT(oops::are_all_close_absolute(lons1, lons2, abstol));
190 EXPECT(oops::are_all_close_absolute(lons1, locs2.lons(), abstol));
193 const std::vector<float> & lats = locs1.lats();
194 std::vector<float> lats1(lats.begin(), lats.begin() +
nlocs);
195 std::vector<float> lats2(lats.begin() +
nlocs, lats.end());
196 EXPECT(oops::are_all_close_absolute(lats1, lats2, abstol));
197 EXPECT(oops::are_all_close_absolute(lats1, locs2.lats(), abstol));
208 std::string
testid()
const override {
return "ufo::test::Locations";}
211 std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
213 ts.emplace_back(
CASE(
"ufo/Locations/testLocations")
215 ts.emplace_back(
CASE(
"ufo/Locations/testLonsLats")
217 ts.emplace_back(
CASE(
"ufo/Locations/testFortranLonsLats")
219 ts.emplace_back(
CASE(
"ufo/Locations/testTimeMask")
221 ts.emplace_back(
CASE(
"ufo/Locations/testFortranTimeMask")
223 ts.emplace_back(
CASE(
"ufo/Locations/testConcatenation")
void register_tests() const override
virtual ~Locations()=default
std::string testid() const override
void clear() const override
Code shared by all Locations tests.
static const LocationsTestParameters & testparams()
static const ioda::ObsSpace & obsspace()
static const eckit::LocalConfiguration & testconfig()
LocationsTestParameters testparams_
eckit::LocalConfiguration testconfig_
static LocationsTestFixture & getInstance()
std::shared_ptr< ioda::ObsSpace > obsspace_
Parameters describing Locations test.
oops::RequiredParameter< std::vector< float > > refLats
reference latitudes
oops::RequiredParameter< std::vector< LocationsTimeTestParameters > > timeMaskTests
set of tests for time masks
oops::RequiredParameter< std::vector< float > > refLons
reference longitudes
Parameters describing Locations/TimeMask test.
oops::RequiredParameter< util::DateTime > t1
t1 & t2 for subsetting locations
oops::RequiredParameter< std::vector< bool > > refTimeMask
reference mask
oops::RequiredParameter< util::DateTime > t2
void testLonsLats()
Tests Locations accessors lons() and lats()
void testFortranLonsLats()
Tests Locations accessors lons() and lats() from Fortran.
int test_locations_timemask_f90(const Locations &, const eckit::Configuration &)
void testLocations()
Tests Locations constructors and method size()
void testTimeMask()
Tests Locations::isInTimeWindow method.
void testConcatenate()
Tests operator+= (concatenation of two Locations)
CASE("ufo/DataExtractor/bilinearinterp/float_linear")
int test_locations_lonslats_f90(const Locations &, const eckit::Configuration &)
void testFortranTimeMask()
Tests Locations::isInTimeWindow method from Fortran.
integer function nlocs(this)
Return the number of observational locations in this Locations object.