Skip to content

Commit

Permalink
MIR-665 Interpolation from matrix file, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaciel committed Jun 12, 2024
1 parent 9de8f1e commit 644bcbb
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
2 changes: 2 additions & 0 deletions tests/unit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git_ignore
*.mat
71 changes: 67 additions & 4 deletions tests/unit/raw_memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
#include <sstream>
#include <vector>

#include "eckit/filesystem/PathName.h"
#include "eckit/system/Library.h"
#include "eckit/testing/Test.h"

#include "mir/api/MIRJob.h"
#include "mir/data/MIRField.h"
#include "mir/input/RawInput.h"
#include "mir/method/WeightMatrix.h"
#include "mir/output/RawOutput.h"
#include "mir/output/ResizableOutput.h"
#include "mir/param/SimpleParametrisation.h"
Expand Down Expand Up @@ -201,7 +203,7 @@ CASE("Example 1") {

std::ostringstream ss;
ss << meta2;
EXPECT(ss.str() == "{\"area\":[1,-1,-1,1],\"grid\":[2,2]}");
EXPECT(ss.str() == R"({"area":[1,-1,-1,1],"grid":[2,2]})");
}


Expand All @@ -226,7 +228,7 @@ CASE("Example 1") {

std::ostringstream ss;
ss << meta2;
EXPECT(ss.str() == "{\"area\":[1,-1,-1,1],\"grid\":[2,2]}");
EXPECT(ss.str() == R"({"area":[1,-1,-1,1],"grid":[2,2]})");
}
}

Expand Down Expand Up @@ -273,7 +275,7 @@ CASE("Example 2") {

std::ostringstream ss;
ss << meta2;
EXPECT(ss.str() == "{\"area\":[1,-1,-1,1],\"grid\":[2,2]}");
EXPECT(ss.str() == R"({"area":[1,-1,-1,1],"grid":[2,2]})");
}


Expand All @@ -298,7 +300,68 @@ CASE("Example 2") {

std::ostringstream ss;
ss << meta2;
EXPECT(ss.str() == "{\"area\":[1,-1,-1,1],\"grid\":[2,2]}");
EXPECT(ss.str() == R"({"area":[1,-1,-1,1],"grid":[2,2]})");
}
}


CASE("Example 3"){
auto& log = Log::info();


SECTION("grid=unstructured regridded") {
// input metadata & data (latitudes/longitudes aren't strictly necessary except for UnstructuredGrid construction)
param::SimpleParametrisation meta1;

meta1.set("gridded", true);
meta1.set("gridType", "unstructured_grid");
meta1.set("latitudes", std::vector<double>{1., 2., 3.});
meta1.set("longitudes", std::vector<double>{3., 2., 1.});
meta1.set("missing_value", 42.);

std::vector<double> values1(3, 1.);
std::unique_ptr<input::MIRInput> input(new input::RawInput(values1.data(), values1.size(), meta1));


// output metadata (empty) & data (resizable)
param::SimpleParametrisation meta2;
std::vector<double> values2;
std::unique_ptr<output::MIROutput> output(new output::ResizableOutput(values2, meta2));


// matrix
{
method::WeightMatrix W(4, 3);
W.setFromTriplets({{0, 0, 1.}, {0, 1, 1.}, {0, 2, 1.}, {1, 0, 2.}, {1, 1, 1.}, {1, 2, -1.}, {2, 2, 1.}});
W.save("raw_memory_example_3.mat");
}


// job
api::MIRJob job;
job.set("grid", std::vector<double>{2., 2.});
job.set("area", std::vector<double>{1., -1., -1., 1.});
job.set("interpolation", "matrix");
job.set("interpolation-matrix", "raw_memory_example_3.mat");

log << job << std::endl;


// process
job.execute(*input, *output);

EXPECT(values2.size() == 4);

EXPECT_EQUAL(values2[0], 3.);
EXPECT_EQUAL(values2[1], 2.);
EXPECT_EQUAL(values2[2], 1.);
EXPECT_EQUAL(values2[3], 42.);

log << "output metadata: " << meta2 << std::endl;

std::ostringstream ss;
ss << meta2;
EXPECT(ss.str() == R"({"area":[1,-1,-1,1],"grid":[2,2],"missing_value":42})");
}
}

Expand Down

0 comments on commit 644bcbb

Please sign in to comment.