18 #include "atlas/array.h"
19 #include "atlas/field.h"
20 #include "eckit/config/Configuration.h"
21 #include "eckit/exception/Exceptions.h"
22 #include "eckit/geometry/Sphere.h"
24 #include "oops/util/abor1_cpp.h"
25 #include "oops/util/DateTime.h"
26 #include "oops/util/Duration.h"
27 #include "oops/util/Logger.h"
31 using atlas::array::make_view;
42 const util::DateTime & bgn,
const util::DateTime & end,
43 const eckit::mpi::Comm & timeComm)
44 :
oops::ObsSpaceBase(config, comm, bgn, end), obsname_(config.getString(
"obs type")),
45 winbgn_(bgn), winend_(end), obsvars_(), isLocal_(false), comm_(comm)
47 typedef std::map< std::string, F90odb >::iterator otiter;
49 eckit::LocalConfiguration fileconf(config);
50 std::string ofin(
"-");
51 if (config.has(
"obsdatain")) {
52 ofin = config.getString(
"obsdatain.obsfile");
54 std::string ofout(
"-");
55 if (config.has(
"obsdataout")) {
56 ofout = config.getString(
"obsdataout.obsfile");
57 if (timeComm.size() > 1) {
58 std::ostringstream ss;
59 ss <<
"_" << timeComm.rank();
60 std::size_t found = ofout.find_last_of(
".");
61 if (found == std::string::npos) found = ofout.length();
62 std::string fileout = ofout.insert(found, ss.str());
63 fileconf.set(
"obsdataout.obsfile", fileout);
66 oops::Log::trace() <<
"ObsSpaceQG: Obs files are: " << ofin <<
" and " << ofout << std::endl;
67 std::string ref = ofin + ofout;
69 ABORT(
"Underspecified observation files.");
75 oops::Log::trace() <<
"ObsSpaceQG::getHelper: " <<
"Opening " << ref << std::endl;
80 oops::Log::trace() <<
"ObsSpaceQG::getHelper: " << ref <<
" already opened." << std::endl;
94 if (config.has(
"generate")) {
95 const eckit::LocalConfiguration gconf(config,
"generate");
96 const util::Duration first(gconf.getString(
"begin"));
97 const util::DateTime start(
winbgn_ + first);
98 const util::Duration freq(gconf.getString(
"obs_period"));
100 util::DateTime now(start);
107 start, freq, nobstimes, iobs);
114 const eckit::geometry::Point2 & refPoint,
115 const eckit::Configuration & conf)
116 :
oops::ObsSpaceBase(
eckit::LocalConfiguration(), obsdb.comm_,
117 obsdb.windowStart(), obsdb.windowEnd()),
118 key_(obsdb.key_), obsname_(obsdb.obsname_),
119 winbgn_(obsdb.winbgn_), winend_(obsdb.winend_), obsvars_(obsdb.obsvars_),
120 localobs_(), isLocal_(true), comm_(obsdb.comm_)
122 oops::Log::trace() <<
"ObsSpaceQG for LocalObs starting" << std::endl;
123 const double dist = conf.getDouble(
"lengthscale");
128 atlas::Field field_lonlat = locs->lonlat();
129 auto lonlat = make_view<double, 2>(field_lonlat);
131 for (
int jj = 0; jj < locs->size(); ++jj) {
132 eckit::geometry::Point2 obsPoint(lonlat(jj, 0), lonlat(jj, 1));
133 double localDist = eckit::geometry::Sphere::distance(6.371e6, refPoint, obsPoint);
134 if (localDist < dist)
localobs_.push_back(jj);
137 oops::Log::trace() <<
"ObsSpaceQG for LocalObs done" << std::endl;
183 const util::DateTime & t2)
const {
184 atlas::FieldSet fields;
185 std::vector<util::DateTime> times;
187 fields.get(), times);
188 return std::unique_ptr<LocationsQG>(
new LocationsQG(fields, std::move(times)));
194 oops::Log::info() <<
"ObsSpaceQG::printJo not implemented" << std::endl;
211 os <<
"ObsSpace for " <<
obsname_ <<
", " << this->
nobs() <<
" obs" << std::endl;