Skip to content

Commit 26a20d6

Browse files
committed
Merge branch 'feature/MIR-673' into develop
2 parents 8bc2dae + 400aa7a commit 26a20d6

24 files changed

+142
-28
lines changed

src/mir/repres/regular/PolarStereographic.cc

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ PolarStereographic::PolarStereographic(const param::MIRParametrisation& param) :
3333
LaDInDegrees_(0),
3434
orientationOfTheGridInDegrees_(0),
3535
southPoleOnProjectionPlane_(false) {
36+
long edition = 0;
37+
param.get("edition", edition);
38+
39+
// GRIB1 cannot write LaD
40+
writeLaDInDegrees_ = edition == 2;
41+
param.get("writeLaDInDegrees", writeLaDInDegrees_);
42+
43+
// GRIB2 cannot write negative longitude values
44+
writeLonPositive_ = edition == 2;
45+
param.get("writeLonPositive", writeLonPositive_);
46+
47+
// Details
3648
ASSERT(param.get("proj", proj_) && !proj_.empty());
3749

3850
param.get("LaDInDegrees", LaDInDegrees_);
@@ -41,30 +53,35 @@ PolarStereographic::PolarStereographic(const param::MIRParametrisation& param) :
4153
long south = 0;
4254
param.get("southPoleOnProjectionPlane", south);
4355
southPoleOnProjectionPlane_ = south != 0;
56+
57+
long uvRelativeToGrid = 0;
58+
uvRelativeToGrid_ = param.get("uvRelativeToGrid", uvRelativeToGrid) && uvRelativeToGrid != 0;
4459
}
4560

4661

4762
void PolarStereographic::fillGrib(grib_info& info) const {
4863
info.grid.grid_type = CODES_UTIL_GRID_SPEC_POLAR_STEREOGRAPHIC;
49-
info.extra_set("edition", 2L); // write LaDInDegrees
5064

5165
Point2 first = {x().front(), y().front()};
5266
Point2 firstLL = grid().projection().lonlat(first);
5367

54-
info.grid.latitudeOfFirstGridPointInDegrees = firstLL[LLCOORDS::LAT];
55-
info.grid.longitudeOfFirstGridPointInDegrees = util::normalise_longitude(firstLL[LLCOORDS::LON], 0);
68+
info.grid.latitudeOfFirstGridPointInDegrees = firstLL[LLCOORDS::LAT];
69+
info.grid.longitudeOfFirstGridPointInDegrees =
70+
writeLonPositive_ ? util::normalise_longitude(firstLL[LLCOORDS::LON], 0) : firstLL[LLCOORDS::LON];
5671

5772
info.grid.Ni = static_cast<long>(x().size());
5873
info.grid.Nj = static_cast<long>(y().size());
5974

60-
info.grid.iScansNegatively = x().front() < x().back() ? 0L : 1L;
61-
info.grid.jScansPositively = y().front() < y().back() ? 1L : 0L;
75+
info.grid.uvRelativeToGrid = uvRelativeToGrid_ ? 1 : 0;
6276

6377
info.extra_set("DxInMetres", std::abs(x().step()));
6478
info.extra_set("DyInMetres", std::abs(y().step()));
65-
info.extra_set("LaDInDegrees", LaDInDegrees_);
6679
info.extra_set("orientationOfTheGridInDegrees", util::normalise_longitude(orientationOfTheGridInDegrees_, 0));
6780

81+
if (writeLaDInDegrees_) {
82+
info.extra_set("LaDInDegrees", LaDInDegrees_);
83+
}
84+
6885
// some extra keys are edition-specific, so parent call is here
6986
RegularGrid::fillGrib(info);
7087
}

src/mir/repres/regular/PolarStereographic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class PolarStereographic final : public RegularGrid {
5959
double LaDInDegrees_;
6060
double orientationOfTheGridInDegrees_;
6161
bool southPoleOnProjectionPlane_;
62+
bool writeLaDInDegrees_;
63+
bool writeLonPositive_;
64+
bool uvRelativeToGrid_;
6265

6366
// -- Methods
6467
// None

src/mir/util/Shape.cc

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616

1717
#include "mir/api/MIRJob.h"
1818
#include "mir/param/MIRParametrisation.h"
19+
#include "mir/util/Grib.h"
1920

2021

2122
namespace mir::util {
2223

2324

2425
Shape::Shape(const param::MIRParametrisation& param) {
25-
param.get("edition", edition = 0);
26-
2726
provided = param.get("shapeOfTheEarth", code = 6);
2827

2928
bool isOblate = false;
@@ -33,7 +32,7 @@ Shape::Shape(const param::MIRParametrisation& param) {
3332
}
3433

3534

36-
Shape::Shape(const Projection::Spec& spec) : edition(0) {
35+
Shape::Shape(const Projection::Spec& spec) {
3736
if (spec.has("radius")) {
3837
code = 1L;
3938
a = b = spec.getDouble("radius");
@@ -54,7 +53,19 @@ Shape::Shape(const Projection::Spec& spec) : edition(0) {
5453

5554

5655
void Shape::fillGrib(grib_info& info, const Projection::Spec& spec) const {
56+
const static std::string EDITION{"edition"};
57+
5758
// GRIB2 encoding of user-provided shape
59+
auto edition = info.packing.editionNumber;
60+
61+
for (long j = 0; j < info.packing.extra_settings_count; ++j) {
62+
const auto& set = info.packing.extra_settings[j];
63+
if (set.name == EDITION && set.type == CODES_TYPE_LONG) {
64+
edition = set.long_value;
65+
break;
66+
}
67+
}
68+
5869
if (edition != 2) {
5970
return;
6071
}
@@ -91,11 +102,7 @@ void Shape::fillGrib(grib_info& info, const Projection::Spec& spec) const {
91102

92103

93104
void Shape::fillJob(api::MIRJob& job, const Projection::Spec& spec) const {
94-
// GRIB2 encoding of user-provided shape
95-
if (edition != 2) {
96-
return;
97-
}
98-
105+
// MIRJob encoding of user-provided shape
99106
std::ostringstream shape;
100107

101108
// shape given by radius or semi-major/minor axis
@@ -130,7 +137,7 @@ void Shape::fillJob(api::MIRJob& job, const Projection::Spec& spec) const {
130137
std::string grid;
131138
ASSERT(job.get("grid", grid) && !grid.empty());
132139

133-
job.set("grid", grid + ";" + shape.str());
140+
job.set("grid", grid + shape.str());
134141
}
135142

136143

src/mir/util/Shape.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ struct Shape {
5050
long code;
5151
double a;
5252
double b;
53-
long edition;
5453
bool provided;
5554
};
5655

tests/assertions/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ if(MARS_SCRIPT)
2323
ENVIRONMENT ${_testEnvironment})
2424
if((_t MATCHES "[.]fail[.]") OR
2525
(_t MATCHES "[.]lsm[.]" AND NOT HAVE_MIR_DOWNLOAD_MASKS) OR
26-
(NOT mir_HAVE_ATLAS AND NOT (_t MATCHES "[.]core[.]")))
26+
(NOT mir_HAVE_ATLAS AND NOT (_t MATCHES "[.]core[.]")) OR
27+
(NOT atlas_HAVE_PROJ AND (_t MATCHES "[.]proj[.]")))
2728
set_tests_properties(${_t} PROPERTIES WILL_FAIL TRUE)
2829
endif()
2930
endforeach()

tests/assertions/MIR-673.001.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ gridType=polar_stereographic.grib2
44
--grid=gridType=polar_stereographic
55
# grib_get
66
gridType=polar_stereographic
7+
edition=2
78
Ni=2869
89
Nj=2869
910
Dx=2500000

tests/assertions/MIR-673.002.test renamed to tests/assertions/MIR-673.002.proj.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ gridType=polar_stereographic.grib2
44
--area=66.5/-24.5/63.4/-13.5
55
# grib_get
66
gridType=polar_stereographic
7+
edition=2
78
Ni=2869
89
Nj=2869
910
Dx=2500000
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# input
2+
gridType=polar_stereographic.grib2
3+
# mir
4+
--grid=1/1
5+
# grib_get
6+
gridType=regular_ll

tests/assertions/MIR-673.005.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# input
2+
gridType=polar_stereographic.grib1
3+
# mir
4+
--grid=gridType=polar_stereographic
5+
# grib_get
6+
gridType=polar_stereographic
7+
edition=1
8+
Ni=1121
9+
Nj=881
10+
Dx=4763
11+
Dy=4763
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# input
2+
gridType=polar_stereographic.grib1
3+
# mir
4+
--area=49/-92/41/-76
5+
# grib_get
6+
gridType=polar_stereographic
7+
edition=1
8+
Ni=1121
9+
Nj=881
10+
Dx=4763
11+
Dy=4763
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# input
2+
gridType=polar_stereographic.grib1
3+
# mir
4+
--area=49/-92/41/-76 --area-mode=crop
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# input
2+
gridType=polar_stereographic.grib1
3+
# mir
4+
--grid=1/1
5+
# grib_get
6+
gridType=regular_ll
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../data/gridType=polar_stereographic.grib1
84 Bytes
Binary file not shown.

tests/plans/CMakeLists.txt

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,24 @@ find_program(MARS_SCRIPT NAMES "mars" "false")
33

44
ecbuild_configure_file(mir-test.sh.in mir-test.sh @ONLY)
55

6-
file(GLOB_RECURSE test_files LIST_DIRECTORIES false *.test)
7-
foreach(_t ${test_files})
8-
ecbuild_add_test(
9-
TARGET ${_t}
10-
CONDITION MARS_SCRIPT
11-
COMMAND mir-test.sh
12-
ARGS ${_t}
13-
ENVIRONMENT ${_testEnvironment})
14-
endforeach()
6+
if(MARS_SCRIPT)
7+
file(GLOB_RECURSE test_files LIST_DIRECTORIES false *.test)
8+
9+
foreach(_t ${test_files})
10+
ecbuild_add_test(
11+
TARGET ${_t}
12+
CONDITION MARS_SCRIPT
13+
COMMAND mir-test.sh
14+
ARGS ${_t}
15+
ENVIRONMENT ${_testEnvironment})
16+
if((_t MATCHES "[.]fail[.]") OR
17+
(_t MATCHES "[.]lsm[.]" AND NOT HAVE_MIR_DOWNLOAD_MASKS) OR
18+
(NOT mir_HAVE_ATLAS AND NOT (_t MATCHES "[.]core[.]")) OR
19+
(NOT atlas_HAVE_PROJ AND (_t MATCHES "[.]proj[.]")))
20+
set_tests_properties(${_t} PROPERTIES WILL_FAIL TRUE)
21+
endif()
22+
endforeach()
23+
endif()
1524

1625
if(EXISTS ${CMAKE_BINARY_DIR}/share/plugins/atlas-orca.yml)
1726
file(GLOB_RECURSE test_files LIST_DIRECTORIES false *.test.atlas-orca)

tests/plans/MIR-673.004.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# input
22
gridType=polar_stereographic.grib2
33
# mir
4-
--same=data.in.MIR-673.003.test
4+
--grid=1/1
55
# plan
6-
Gridded2TypedGrid[grid={"LaDInDegrees":"90","Ni":"2869","Nj":"2869","grid":"2500/2500","gridType":"polar_stereographic","iScansNegatively":"0","jScansPositively":"1","latitudeOfFirstGridPointInDegrees":"42.1138","longitudeOfFirstGridPointInDegrees":"-71.6168","orientationOfTheGridInDegrees":"-30","proj":"+proj=stere +lat_ts=90.000003 +lat_0=90 +lon_0=-30.000001 +k_0=1 +x_0=0 +y_0=0 +R=6371229.000000","shapeOfTheEarth":"6","southPoleOnProjectionPlane":"0"},interpolation=linear,method=FiniteElement[name=linear,nonLinear[MissingIfHeaviestMissing[]],solver=Multiply[],cropping=none,lsmWeightAdjustment=0.2,pruneEpsilon=1e-10,poleDisplacement=0,validateMesh=0,projectionFail=missing-value]]|Save[output=...]
6+
Gridded2RegularLL[increments=Increments[west_east=1,south_north=1],bbox=BoundingBox[north=90,west=0,south=-90,east=359],interpolation=linear,method=FiniteElement[name=linear,nonLinear[MissingIfHeaviestMissing[]],solver=Multiply[],cropping=none,lsmWeightAdjustment=0.2,pruneEpsilon=1e-10,poleDisplacement=0,validateMesh=0,projectionFail=missing-value]]|Save[output=...]

tests/plans/MIR-673.005.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# input
2+
gridType=polar_stereographic.grib1
3+
# mir
4+
--grid=gridType=polar_stereographic
5+
# plan
6+
Copy[]

tests/plans/MIR-673.006.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# input
2+
gridType=polar_stereographic.grib1
3+
# mir
4+
--area=49/-92/41/-76
5+
# plan
6+
AreaMasker[bbox=BoundingBox[north=49,west=-92,south=41,east=-76]]|Save[output=...]

tests/plans/MIR-673.007.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# input
2+
gridType=polar_stereographic.grib1
3+
# mir
4+
--area=49/-92/41/-76 --area-mode=crop
5+
# plan
6+
AreaCropper[bbox=BoundingBox[north=49,west=-92,south=41,east=-76]]|Save[output=...]

tests/plans/MIR-673.008.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# input
2+
gridType=polar_stereographic.grib1
3+
# mir
4+
--grid=1/1
5+
# plan
6+
Gridded2RegularLL[increments=Increments[west_east=1,south_north=1],bbox=BoundingBox[north=90,west=0,south=-90,east=359],interpolation=linear,method=FiniteElement[name=linear,nonLinear[MissingIfHeaviestMissing[]],solver=Multiply[],cropping=none,lsmWeightAdjustment=0.2,pruneEpsilon=1e-10,poleDisplacement=0,validateMesh=0,projectionFail=missing-value]]|Save[output=...]

tests/plans/MIR-673.009.proj.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# input
2+
gridType=polar_stereographic.grib2
3+
# mir
4+
--same=data.in.MIR-673.009.proj.test
5+
# plan
6+
Gridded2TypedGrid[grid={"LaDInDegrees":"90","Ni":"2869","Nj":"2869","grid":"2500/2500","gridType":"polar_stereographic","iScansNegatively":"0","jScansPositively":"1","latitudeOfFirstGridPointInDegrees":"42.1138","longitudeOfFirstGridPointInDegrees":"-71.6168","orientationOfTheGridInDegrees":"-30","proj":"+proj=stere +lat_ts=90.000003 +lat_0=90 +lon_0=-30.000001 +k_0=1 +x_0=0 +y_0=0 +R=6371229.000000","shapeOfTheEarth":"6","southPoleOnProjectionPlane":"0"},interpolation=linear,method=FiniteElement[name=linear,nonLinear[MissingIfHeaviestMissing[]],solver=Multiply[],cropping=none,lsmWeightAdjustment=0.2,pruneEpsilon=1e-10,poleDisplacement=0,validateMesh=0,projectionFail=missing-value]]|Save[output=...]

tests/plans/MIR-673.010.proj.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# input
2+
gridType=polar_stereographic.grib1
3+
# mir
4+
--same=data.in.MIR-673.010.proj.test
5+
# plan
6+
Gridded2TypedGrid[grid={"LaDInDegrees":"60","Ni":"1121","Nj":"881","grid":"4763/4763","gridType":"polar_stereographic","iScansNegatively":"0","jScansPositively":"1","latitudeOfFirstGridPointInDegrees":"23.117","longitudeOfFirstGridPointInDegrees":"-119.023","orientationOfTheGridInDegrees":"-105","proj":"+proj=stere +lat_ts=60.000000 +lat_0=90 +lon_0=-105.000000 +k_0=1 +x_0=0 +y_0=0 +R=6367470.000000","shapeOfTheEarth":"0","southPoleOnProjectionPlane":"0"},interpolation=linear,method=FiniteElement[name=linear,nonLinear[MissingIfHeaviestMissing[]],solver=Multiply[],cropping=none,lsmWeightAdjustment=0.2,pruneEpsilon=1e-10,poleDisplacement=0,validateMesh=0,projectionFail=missing-value]]|Save[output=...]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../data/gridType=polar_stereographic.grib1

0 commit comments

Comments
 (0)