Skip to content

Commit

Permalink
Merge branch 'develop' into release/1.20.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaciel committed Mar 25, 2024
2 parents 0a2fcd9 + 40557f8 commit 423c9d1
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 77 deletions.
49 changes: 25 additions & 24 deletions src/mir/method/MethodWeighted.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,30 +249,6 @@ const WeightMatrix& MethodWeighted::getMatrix(context::Context& ctx, const repre
}
}

if (reorderRows_ || reorderCols_) {
std::unique_ptr<const reorder::Reorder> identity(reorder::ReorderFactory::build("identity"));

auto rows = (reorderRows_ ? reorderRows_ : identity)->reorder(out.numberOfPoints());
ASSERT(rows.size() == W.rows());

auto cols = (reorderCols_ ? reorderCols_ : identity)->reorder(in.numberOfPoints());
ASSERT(cols.size() == W.cols());

// expand triplets, renumbering directly
std::vector<eckit::linalg::Triplet> trips;
trips.reserve(W.nonZeros());

for (auto i = W.begin(), end = W.end(); i != end; ++i) {
trips.emplace_back(rows.at(i.row()), cols.at(i.col()), *i);
}

// compress triplets, replace matrix
std::sort(trips.begin(), trips.end());

eckit::linalg::SparseMatrix w(W.rows(), W.cols(), trips);
W.swap(w);
}


log << "MethodWeighted::getMatrix create weights matrix: " << timer.elapsedSeconds(here) << std::endl;
log << "MethodWeighted::getMatrix matrix W " << W << std::endl;
Expand Down Expand Up @@ -546,6 +522,31 @@ void MethodWeighted::computeMatrixWeights(context::Context& ctx, const repres::R
trace::Timer timer("Assemble matrix");
assemble(ctx.statistics(), W, in, out);
W.cleanup(pruneEpsilon_);

if (reorderRows_ || reorderCols_) {
std::unique_ptr<const reorder::Reorder> identity(
reorderRows_ && reorderCols_ ? nullptr : reorder::ReorderFactory::build("identity"));

auto rows = (reorderRows_ ? reorderRows_ : identity)->reorder(out.numberOfPoints());
ASSERT(rows.size() == W.rows());

auto cols = (reorderCols_ ? reorderCols_ : identity)->reorder(in.numberOfPoints());
ASSERT(cols.size() == W.cols());

// expand triplets, renumbering directly
std::vector<eckit::linalg::Triplet> trips;
trips.reserve(W.nonZeros());

for (auto i = W.begin(), end = W.end(); i != end; ++i) {
trips.emplace_back(rows.at(i.row()), cols.at(i.col()), *i);
}

// compress triplets, replace matrix
std::sort(trips.begin(), trips.end());

eckit::linalg::SparseMatrix w(W.rows(), W.cols(), trips);
W.swap(w);
}
}

// matrix validation always happens after creation, because the matrix can/will be cached
Expand Down
18 changes: 9 additions & 9 deletions tests/assertions/0010.core.test
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Mars request (found in Portugese requirements)
# mars
param=2t,levtype=sfc
# Mir tool options
--dont-compress-plan --grid=0.1/0.1 --area=60/180/-56/-180
# grib_get assertions
Ni = 3600
Nj = 1161
iDirectionIncrementInDegrees = 0.1
jDirectionIncrementInDegrees = 0.1
# mir
--dont-compress-plan --grid=1/1 --area=60/180/-56/-180
# grib_get
Ni = 360
Nj = 117
iDirectionIncrementInDegrees = 1
jDirectionIncrementInDegrees = 1
latitudeOfFirstGridPointInDegrees = 60
longitudeOfFirstGridPointInDegrees = 180
latitudeOfLastGridPointInDegrees = -56
longitudeOfLastGridPointInDegrees = 539.9
longitudeOfLastGridPointInDegrees = 539
6 changes: 6 additions & 0 deletions tests/assertions/MIR-583.001.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# MIR-583 interpolation=linear failure on low parametricEpsilon
MIR-583.grib1
# mir
--grid=0.04/0.04 --interpolation=linear --finite-element-projection-fail=missing-value
# grib_get
# (none)
File renamed without changes.
2 changes: 2 additions & 0 deletions tests/assertions/MIR-647.001.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# mars
gridType=healpix,Nside=2,orderingConvention=nested.grib2
# mir
$MIR_CACHING=1
$MIR_CACHE_PATH=cache.MIR-647
--grid=H2 --interpolation=linear
# grib_get assertions
gridType=healpix
Expand Down
31 changes: 31 additions & 0 deletions tests/assertions/MIR-647.002.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# mars
gridType=healpix,Nside=2,orderingConvention=ring.grib2
# mir
$MIR_CACHING=1
$MIR_CACHE_PATH=cache.MIR-647
--grid=H2 --interpolation=linear
# grib_get assertions
gridType=healpix
gridName=H2
orderingConvention=ring
Nside=2
numberOfDataPoints=48
longitudeOfFirstGridPointInDegrees=45
values[0]=0
values[1]=1
values[2]=2
values[3]=3

values[20]=20
values[21]=21
values[22]=22
values[23]=23
values[24]=24
values[25]=25
values[26]=26
values[27]=27

values[44]=44
values[45]=45
values[46]=46
values[47]=47
Binary file not shown.
Binary file modified tests/data/multi-format.grib
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/plans/MIR-647.002.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# mars
gridType=healpix,Nside=2,orderingConvention=ring.grib2
# mir
--grid=H2 --interpolation=linear
# plan
Copy[]
53 changes: 9 additions & 44 deletions tests/unit/interpolations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,27 @@ namespace mir::tests::unit {


CASE("interpolations") {
api::MIRJob jobs[7]; // jobs[0]: no post-processing
api::MIRJob jobs[3]; // jobs[0]: no post-processing

jobs[1].set("caching", false);
jobs[1].set("grid", "2/2");

jobs[2].set("caching", false);
jobs[2].set("grid", "3/3");
jobs[0].set("caching", false);
jobs[0].set("grid", "3/3");

jobs[3].set("caching", false);
jobs[3].set("grid", "1/1");
jobs[3].set("area", "40/20/20/40");

jobs[4].set("caching", false);
jobs[4].set("grid", "1/1");
jobs[4].set("area", "40/20/20/40");
jobs[4].set("frame", 2);
jobs[1].set("caching", false);
jobs[1].set("grid", "1/1");
jobs[1].set("area", "40/20/20/40");
jobs[1].set("frame", 2);

#if mir_HAVE_ATLAS
jobs[5].set("caching", false);
jobs[5].set("rotation", "-90/0");

jobs[6].set("caching", false);
jobs[6].set("rotation", "-89/10");
jobs[2].set("caching", false);
jobs[2].set("rotation", "-89/10");
#endif


SECTION("gridded to gridded (GRIB)") {
param::SimpleParametrisation args;

for (const std::string& in : {
"../data/param=2t,levtype=sfc,grid=F640",
"../data/param=2t,levtype=sfc,grid=N640",
"../data/param=2t,levtype=sfc,grid=O640",
"../data/regular_ll.2-2.grib2",
"../data/regular_ll.2-4.grib1",
}) {
for (const auto& job : jobs) {
Expand Down Expand Up @@ -130,28 +117,6 @@ CASE("interpolations") {
}


#if mir_HAVE_ATLAS
CASE("MIR-583") {
// interpolation=linear failure on low parametricEpsilon

api::MIRJob job;
job.set("caching", false);
job.set("grid", "0.04/0.04");
job.set("interpolation", "linear");
job.set("finite-element-missing-value-on-projection-fail", false);

param::SimpleParametrisation args;
std::unique_ptr<input::MIRInput> input(input::MIRInputFactory::build("MIR-583.grib1", args));

output::EmptyOutput output;

while (input->next()) {
job.execute(*input, output);
}
}
#endif


} // namespace mir::tests::unit


Expand Down

0 comments on commit 423c9d1

Please sign in to comment.