Skip to content

Commit 0f760ef

Browse files
committed
Initial attempt to implement an increment interpolator unit test.
1 parent a197c85 commit 0f760ef

File tree

4 files changed

+83
-13
lines changed

4 files changed

+83
-13
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
with:
3838
path: ci/saber
3939
repository: JCSDA-internal/saber
40-
token: ${{ secrets.GH_PAT }}
40+
token: ${{ secrets.GHCR_PAT }}
4141

4242
- name: checkout ioda
4343
uses: actions/checkout@v3

src/orca-jedi/increment/Increment.cc

+12
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
#include "atlas/mesh.h"
3838
#include "atlas-orca/grid/OrcaGrid.h"
3939

40+
#include <boost/uuid/uuid.hpp> // uuid class DJL
41+
#include <boost/uuid/uuid_generators.hpp> // generators DJL
42+
#include <boost/uuid/uuid_io.hpp> // streaming operators etc. DJL
43+
44+
4045
namespace orcamodel {
4146

4247
// -----------------------------------------------------------------------------
@@ -264,10 +269,17 @@ void Increment::setval(const double & val) {
264269
if (!has_mv || (has_mv && !mv(field_view(j, k)))) {
265270
field_view(j, k) = val;
266271
}
272+
} else {
273+
field_view(j, k) = -99; /// DJL
267274
}
268275
}
269276
}
270277
}
278+
279+
// DJL write debug fields to file
280+
boost::uuids::uuid uuid = boost::uuids::random_generator()();
281+
writeFieldsToFile("incsetval"+ boost::uuids::to_string(uuid) +".nc", *geom_, validTime(), incrementFields_);
282+
271283

272284
oops::Log::trace() << "Increment(ORCA)::setval done" << std::endl;
273285
}

src/orca-jedi/interpolator/Interpolator.cc

+29-12
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131

3232
#include "orca-jedi/interpolator/Interpolator.h"
3333

34+
#include <boost/uuid/uuid.hpp> // uuid class DJL
35+
#include <boost/uuid/uuid_generators.hpp> // generators DJL
36+
#include <boost/uuid/uuid_io.hpp> // streaming operators etc. DJL
37+
38+
#include "orca-jedi/utilities/IOUtils.h" // DJL
39+
40+
3441
namespace eckit {
3542
class Configuration;
3643
}
@@ -178,6 +185,11 @@ template void Interpolator::executeInterpolation<float>(
178185
const std::vector<bool> & mask,
179186
std::vector<double>::iterator& iter) const;
180187

188+
/// \brief Interpolate from model space to observation space
189+
/// \param vars Oops variables
190+
/// \param inc Increment object (input)
191+
/// \param mask Mask vector in observation space
192+
/// \param result Result (output) vector in observation space
181193
void Interpolator::apply(const oops::Variables& vars, const Increment& inc,
182194
const std::vector<bool> & mask,
183195
std::vector<double>& result) const {
@@ -230,6 +242,11 @@ void Interpolator::apply(const oops::Variables& vars, const Increment& inc,
230242
}
231243
}
232244

245+
/// \brief Interpolate from observation space to model space
246+
/// \param vars Oops variables
247+
/// \param inc Increment object (output)
248+
/// \param mask Mask (observation space) vector
249+
/// \param resultin Values (observation space) vector (input)
233250
void Interpolator::applyAD(const oops::Variables& vars, Increment& inc,
234251
const std::vector<bool> & mask,
235252
const std::vector<double> & resultin) const
@@ -242,7 +259,7 @@ void Interpolator::applyAD(const oops::Variables& vars, Increment& inc,
242259

243260
oops::Log::debug() << "DJL ** Interpolator::applyAD this needs checking **" << std::endl;
244261

245-
// ** Not sure what I'm doing yet - Just trying to do the opposite of applyAD
262+
// ** Trying to do the opposite of apply DJL
246263

247264
const size_t nvars = vars.size();
248265

@@ -263,13 +280,15 @@ void Interpolator::applyAD(const oops::Variables& vars, Increment& inc,
263280
inc.geometry()->variableSizes(vars);
264281
size_t nvals = 0;
265282

266-
// boost::uuids::uuid uuid = boost::uuids::random_generator()();
267-
// std::shared_ptr<const Geometry> geom = inc.geometry();
268-
// writeGenFieldsToFile("applyADpre"+ boost::uuids::to_string(uuid) +".nc", *geom, inc.validTime(), inc.incrementFields());
283+
// DJL write debug fields to file
284+
boost::uuids::uuid uuid = boost::uuids::random_generator()();
285+
std::shared_ptr<const Geometry> geom = inc.geometry();
286+
writeFieldsToFile("applyADpre"+ boost::uuids::to_string(uuid) +".nc", *geom, inc.validTime(), inc.incrementFields());
269287

270288
for (size_t jvar=0; jvar < nvars; ++jvar) nvals += nlocs_ * varSizes[jvar];
271289
// result.resize(nvals);
272290

291+
273292
std::size_t out_idx = 0;
274293
for (size_t jvar=0; jvar < nvars; ++jvar) {
275294
oops::Log::debug() << "DJL ** jvar " << jvar << " " << nvars
@@ -301,21 +320,19 @@ void Interpolator::applyAD(const oops::Variables& vars, Increment& inc,
301320
}
302321
}
303322

323+
// halo exchange update ghost points DJL
324+
geom->functionSpace().haloExchange(inc.incrementFields()[gv_varname]);
304325

305326
// atlas::field::MissingValue mv(inc.incrementFields()[gv_varname]);
306327
// bool has_mv = static_cast<bool>(mv);
307328
interpolator_.execute_adjoint(inc.incrementFields()[gv_varname], tgt_field);
308329

309330
} // jvar
310331

311-
// DJL write to file
312-
313-
// boost::uuids::uuid uuid = boost::uuids::random_generator()();
314-
// std::shared_ptr<const Geometry> geom = inc.geometry();
315-
// std::ostringstream out;
316-
// out << std::setfill('0') << std::setw(6) << uuid;
317-
// writeGenFieldsToFile("applyAD"+ boost::uuids::to_string(uuid) +".nc", *geom, inc.validTime(), inc.incrementFields());
318-
// fileCounter_++;
332+
// DJL write debug fields to file
333+
// boost::uuids::uuid uuid = boost::uuids::random_generator()();
334+
// std::shared_ptr<const Geometry> geom = inc.geometry();
335+
writeFieldsToFile("applyAD"+ boost::uuids::to_string(uuid) +".nc", *geom, inc.validTime(), inc.incrementFields());
319336

320337
oops::Log::trace() << "orcamodel::Interpolator::applyAD done "
321338
<< std::endl;

src/tests/orca-jedi/test_interpolator.cc

+41
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct InterpTestSettingsFixture {
3434
public:
3535
eckit::LocalConfiguration geometry_config;
3636
eckit::LocalConfiguration state_config;
37+
eckit::LocalConfiguration increment_config;
3738
eckit::LocalConfiguration interpolator_config;
3839
size_t nlocs, nlevs;
3940
std::vector<double> lons;
@@ -87,6 +88,9 @@ CASE("test interpolator") {
8788
settings_map["ORCA2_T"].state_config.set("nemo field file", "../Data/orca2_t_nemo.nc");
8889
settings_map["ORCA2_T"].state_config.set("variance field file", "../Data/orca2_t_bkg_var.nc");
8990

91+
settings_map["ORCA2_T"].increment_config.set("date", "2021-06-30T00:00:00Z");
92+
settings_map["ORCA2_T"].increment_config.set("output path", "../testoutput/orca2_t_increment_interptest.nc");
93+
9094
settings_map["ORCA2_T"].lons = std::vector<double>{0, 120, 270};
9195
settings_map["ORCA2_T"].lats = std::vector<double>{88, 0, 30};
9296

@@ -137,6 +141,9 @@ CASE("test interpolator") {
137141
settings_map["AMM1"].state_config.set("nemo field file", "../Data/amm1_nemo.nc");
138142
settings_map["AMM1"].state_config.set("variance field file", "../Data/amm1_nemo.nc");
139143

144+
settings_map["AMM1"].increment_config.set("date", "2021-06-30T00:00:00Z");
145+
settings_map["AMM1"].increment_config.set("output path", "../testoutput/amm1_t_increment_interptest.nc");
146+
140147
settings_map["AMM1"].lons = std::vector<double>{-17.5, -6.78, -16.1};
141148
settings_map["AMM1"].lats = std::vector<double>{58.16, 58.91, 63.55};
142149

@@ -209,6 +216,40 @@ CASE("test interpolator") {
209216
EXPECT(std::abs(vals[i] - settings.vol_values[i]) < ATOL);
210217
}
211218
}
219+
220+
221+
SECTION("test " + key + " interpolator.apply/applyAD with increment") {
222+
223+
OrcaIncrementParameters incrementParams;
224+
incrementParams.validateAndDeserialize(settings.increment_config);
225+
226+
Increment increment(geometry, settings.surf_vars, incrementParams.date);
227+
increment.ones();
228+
229+
// two variables at n locations
230+
std::vector<double> vals(2*settings.nlocs);
231+
std::vector<bool> mask(settings.nlocs, true);
232+
233+
// increment -> observation space
234+
interpolator.apply(settings.surf_vars, increment, mask, vals);
235+
236+
for (size_t i=0; i < settings.surf_values.size(); ++i) {
237+
std::cout << "vals[" << i << "] " << std::setprecision(12) << vals[i]
238+
<< " kgo_values[" << i << "] " << settings.surf_values[i] << std::endl;
239+
}
240+
//for (size_t i=0; i < settings.surf_values.size(); ++i) {
241+
// EXPECT(std::abs(vals[i] - settings.surf_values[i]) < ATOL);
242+
//}
243+
244+
Increment incrementout(geometry, settings.surf_vars, incrementParams.date);
245+
// observation space -> increment
246+
interpolator.applyAD(settings.surf_vars, incrementout, mask, vals);
247+
248+
incrementout.write(incrementParams);
249+
250+
}
251+
252+
212253
}
213254
}
214255

0 commit comments

Comments
 (0)