Skip to content

Commit 4fbf60a

Browse files
committed
corrected raster position calculations
1 parent becea8a commit 4fbf60a

File tree

5 files changed

+80
-49
lines changed

5 files changed

+80
-49
lines changed

CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### Updates from version 1.5.4 to 1.5.5
22
* added shutdown hook for resource cleanup on hard shutdowns
3-
* corrected fill value handling for time-variable
3+
* corrected fill value handling for time-variable in ERA-5 post processing
4+
* corrected ERA-5 raster position calculations
45

56
### Updates from version 1.5.3 to 1.5.4
67
* updated to use SNAP version 8.0.5 / S3TBX version 8.0.3

post-processing-tool/src/main/java/com/bc/fiduceo/post/plugin/era5/BilinearInterpolator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ int getYMin() {
2828
return yMin;
2929
}
3030

31+
double getA() {return a;}
32+
33+
double getB() {return b;}
34+
3135
private static double lerp(double c0, double c1, double t) {
3236
return c0 + (c1 - c0) * t;
3337
}

post-processing-tool/src/main/java/com/bc/fiduceo/post/plugin/era5/Era5PostProcessing.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ static int getEra5LatMin(float latMax) {
3737
}
3838

3939
static int getEra5LonMin(float lonMin) {
40-
final double shiftedLon = lonMin - EPS;
41-
final double normLonMin = shiftedLon + 180.0;
40+
final double normLonMin = (lonMin + 360.0) % 360.0;
4241
final double scaledLonMin = Math.floor(normLonMin * 4) / 4;
4342
return (int) (scaledLonMin * 4);
4443
}
@@ -108,7 +107,10 @@ private static InterpolationContext createInterpolationContext_2D(Array lonArray
108107
}
109108

110109
static BilinearInterpolator createInterpolator(float lon, float lat, int era5_X_min, int era5_Y_min) {
111-
final double era5LonMin = era5_X_min * 0.25 - 180.0;
110+
double era5LonMin = era5_X_min * 0.25;
111+
if (era5LonMin >= 180) {
112+
era5LonMin -= 360.0;
113+
}
112114
final double era5LatMin = 90.0 - era5_Y_min * 0.25;
113115

114116
// we have a quarter degree raster and need to normalize the distance tb 2020-11-20

post-processing-tool/src/test/java/com/bc/fiduceo/post/PostProcessingToolIntegrationTest_Era5.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,21 @@ public void testAddEra5Variables_mmd15() throws IOException, InvalidRangeExcepti
9696

9797
variable = NCTestUtils.getVariable("nwp_lnsp", mmd);
9898
NCTestUtils.assertAttribute(variable, "long_name", "Logarithm of surface pressure");
99-
NCTestUtils.assert3DValueDouble(3, 1, 1, 11.514025688171387, variable);
100-
NCTestUtils.assert3DValueDouble(3, 2, 1, 11.513952255249023, variable);
101-
NCTestUtils.assert3DValueDouble(3, 3, 1, 11.513876914978027, variable);
99+
NCTestUtils.assert3DValueDouble(3, 1, 1, 11.53063678741455, variable);
100+
NCTestUtils.assert3DValueDouble(3, 2, 1, 11.530539512634277, variable);
101+
NCTestUtils.assert3DValueDouble(3, 3, 1, 11.530522346496582, variable);
102102

103103
variable = NCTestUtils.getVariable("nwp_v10", mmd);
104104
assertNull(variable.findAttribute("standard_name"));
105-
NCTestUtils.assert3DValueDouble(4, 2, 2, 3.7464919090270996, variable);
106-
NCTestUtils.assert3DValueDouble(4, 3, 2, 3.842674493789673, variable);
107-
NCTestUtils.assert3DValueDouble(4, 4, 2, 3.5886740684509277, variable);
105+
NCTestUtils.assert3DValueDouble(4, 2, 2, 0.9060587882995605, variable);
106+
NCTestUtils.assert3DValueDouble(4, 3, 2, 1.063584566116333, variable);
107+
NCTestUtils.assert3DValueDouble(4, 4, 2, 1.2027971744537354, variable);
108108

109109
variable = NCTestUtils.getVariable("nwp_sst", mmd);
110110
NCTestUtils.assertAttribute(variable, "_FillValue", "9.969209968386869E36");
111-
NCTestUtils.assert3DValueDouble(0, 3, 3, 271.46014404296875, variable);
112-
NCTestUtils.assert3DValueDouble(0, 4, 3, 271.46014404296875, variable);
113-
NCTestUtils.assert3DValueDouble(0, 5, 3, 271.46014404296875, variable);
111+
NCTestUtils.assert3DValueDouble(0, 3, 3, 275.75360107421875, variable);
112+
NCTestUtils.assert3DValueDouble(0, 4, 3, 275.5603942871094, variable);
113+
NCTestUtils.assert3DValueDouble(0, 5, 3, 275.3390808105469, variable);
114114

115115
variable = NCTestUtils.getVariable("era5-time", mmd);
116116
NCTestUtils.assertAttribute(variable, "units", "seconds since 1970-01-01");
@@ -128,27 +128,27 @@ public void testAddEra5Variables_mmd15() throws IOException, InvalidRangeExcepti
128128

129129
variable = NCTestUtils.getVariable("nwp_mu_u10", mmd);
130130
NCTestUtils.assertAttribute(variable, "units", "m s**-1");
131-
NCTestUtils.assert2DValueFloat(4, 3, -2.598637819290161f, variable);
132-
NCTestUtils.assert2DValueFloat(5, 3, -2.281101942062378f, variable);
133-
NCTestUtils.assert2DValueFloat(6, 3, -2.125869035720825f, variable);
131+
NCTestUtils.assert2DValueFloat(4, 3, 1.5901726484298706f, variable);
132+
NCTestUtils.assert2DValueFloat(5, 3, 1.4782710075378418f, variable);
133+
NCTestUtils.assert2DValueFloat(6, 3, 1.315316915512085f, variable);
134134

135135
variable = NCTestUtils.getVariable("nwp_mu_sst", mmd);
136136
NCTestUtils.assertAttribute(variable, "long_name", "Sea surface temperature");
137-
NCTestUtils.assert2DValueFloat(7, 4, 271.46014404296875f, variable);
138-
NCTestUtils.assert2DValueFloat(8, 4, 271.4603576660156f, variable);
139-
NCTestUtils.assert2DValueFloat(9, 4, 271.4601745605469f, variable);
137+
NCTestUtils.assert2DValueFloat(7, 4, 275.3016662597656f, variable);
138+
NCTestUtils.assert2DValueFloat(8, 4, 275.30181884765625f, variable);
139+
NCTestUtils.assert2DValueFloat(9, 4, 275.30181884765625f, variable);
140140

141141
variable = NCTestUtils.getVariable("nwp_mu_mslhf", mmd);
142142
assertNull(variable.findAttribute("standard_name"));
143-
NCTestUtils.assert2DValueFloat(10, 5, -26.741840362548828f, variable);
144-
NCTestUtils.assert2DValueFloat(11, 5, -21.49241065979004f, variable);
145-
NCTestUtils.assert2DValueFloat(12, 5, -17.586181640625f, variable);
143+
NCTestUtils.assert2DValueFloat(10, 5, -28.066068649291992f, variable);
144+
NCTestUtils.assert2DValueFloat(11, 5, -25.100168228149414f, variable);
145+
NCTestUtils.assert2DValueFloat(12, 5, -23.159440994262695f, variable);
146146

147147
variable = NCTestUtils.getVariable("nwp_mu_msshf", mmd);
148148
NCTestUtils.assertAttribute(variable, "_FillValue", "9.969209968386869E36");
149-
NCTestUtils.assert2DValueFloat(13, 6, 1.9936094284057617f, variable);
150-
NCTestUtils.assert2DValueFloat(14, 6, 2.673461437225342f, variable);
151-
NCTestUtils.assert2DValueFloat(15, 6, 3.422379732131958f, variable);
149+
NCTestUtils.assert2DValueFloat(13, 6, 12.113265037536621f, variable);
150+
NCTestUtils.assert2DValueFloat(14, 6, 13.183022499084473f, variable);
151+
NCTestUtils.assert2DValueFloat(15, 6, 13.555000305175781f, variable);
152152
}
153153
}
154154

@@ -182,25 +182,25 @@ public void testAddEra5Variables_coo1() throws IOException, InvalidRangeExceptio
182182

183183
variable = NCTestUtils.getVariable("nwp_lnsp", mmd);
184184
NCTestUtils.assertAttribute(variable, "units", "~");
185-
NCTestUtils.assert3DVariable(variable.getFullName(), 0, 0, 0, 11.523458480834961, mmd);
185+
NCTestUtils.assert3DVariable(variable.getFullName(), 0, 0, 0, 11.525834083557129, mmd);
186186

187187
variable = NCTestUtils.getVariable("nwp_o3", mmd);
188188
NCTestUtils.assertAttribute(variable, "units", "kg kg**-1");
189-
NCTestUtils.assert4DVariable(variable.getFullName(), 0, 0, 0, 0, 1.87434608278636E-7, mmd);
190-
NCTestUtils.assert4DVariable(variable.getFullName(), 0, 0, 10, 0, 3.5533055324776797E-6, mmd);
191-
NCTestUtils.assert4DVariable(variable.getFullName(), 0, 0, 20, 0, 1.0266540812153835E-5, mmd);
189+
NCTestUtils.assert4DVariable(variable.getFullName(), 0, 0, 0, 0, 1.9407424645123683E-7, mmd);
190+
NCTestUtils.assert4DVariable(variable.getFullName(), 0, 0, 10, 0, 3.718567541000084E-6, mmd);
191+
NCTestUtils.assert4DVariable(variable.getFullName(), 0, 0, 20, 0, 9.952551408787258E-6, mmd);
192192

193193
variable = NCTestUtils.getVariable("nwp_u10", mmd);
194194
assertNull(variable.findAttribute("standard_name"));
195-
NCTestUtils.assert3DValueDouble(0, 0, 0, -6.019900798797607, variable);
195+
NCTestUtils.assert3DValueDouble(0, 0, 0, -0.9531255960464478, variable);
196196

197197
variable = NCTestUtils.getVariable("nwp_skt", mmd);
198198
NCTestUtils.assertAttribute(variable, "long_name", "Skin temperature");
199-
NCTestUtils.assert3DValueDouble(0, 0, 0, 302.07879638671875, variable);
199+
NCTestUtils.assert3DValueDouble(0, 0, 0, 301.2060852050781, variable);
200200

201201
variable = NCTestUtils.getVariable("slstr.s3a.blowVert", mmd);
202202
NCTestUtils.assertAttribute(variable, "long_name", "10 metre V wind component");
203-
NCTestUtils.assert3DValueDouble(0, 0, 0, 0.32230889797210693, variable);
203+
NCTestUtils.assert3DValueDouble(0, 0, 0, 3.41879940032959, variable);
204204
}
205205
}
206206

post-processing-tool/src/test/java/com/bc/fiduceo/post/plugin/era5/Era5PostProcessingTest.java

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ public void testGetInterpolationContext() {
3030
assertNotNull(context);
3131

3232
BilinearInterpolator interpolator = context.get(0, 0);
33-
assertEquals(115, interpolator.getXMin());
33+
assertEquals(835, interpolator.getXMin());
3434
assertEquals(247, interpolator.getYMin());
3535

3636
interpolator = context.get(2, 1);
37-
assertEquals(114, interpolator.getXMin());
37+
assertEquals(834, interpolator.getXMin());
3838
assertEquals(247, interpolator.getYMin());
3939

4040
final Rectangle era5Region = context.getEra5Region();
41-
assertEquals(114, era5Region.x);
41+
assertEquals(834, era5Region.x);
4242
assertEquals(247, era5Region.y);
4343
assertEquals(3, era5Region.width);
4444
assertEquals(3, era5Region.height);
@@ -56,11 +56,11 @@ public void testGetInterpolationContext_singlePixel() {
5656
assertNotNull(context);
5757

5858
BilinearInterpolator interpolator = context.get(0, 0);
59-
assertEquals(115, interpolator.getXMin());
59+
assertEquals(835, interpolator.getXMin());
6060
assertEquals(247, interpolator.getYMin());
6161

6262
final Rectangle era5Region = context.getEra5Region();
63-
assertEquals(115, era5Region.x);
63+
assertEquals(835, era5Region.x);
6464
assertEquals(247, era5Region.y);
6565
assertEquals(2, era5Region.width);
6666
assertEquals(2, era5Region.height);
@@ -113,18 +113,19 @@ public void testGetEra5Collection_fromPath() {
113113

114114
@Test
115115
public void testGetLonMin() {
116-
assertEquals(0, Era5PostProcessing.getEra5LonMin(-179.99f));
117-
assertEquals(0, Era5PostProcessing.getEra5LonMin(-179.84f));
118-
assertEquals(1, Era5PostProcessing.getEra5LonMin(-179.67f));
119-
assertEquals(405, Era5PostProcessing.getEra5LonMin(-78.54f));
120-
assertEquals(624, Era5PostProcessing.getEra5LonMin(-23.8f));
121-
assertEquals(718, Era5PostProcessing.getEra5LonMin(-0.26f));
122-
assertEquals(719, Era5PostProcessing.getEra5LonMin(0.f));
123-
assertEquals(893, Era5PostProcessing.getEra5LonMin(43.32f));
124-
assertEquals(1438, Era5PostProcessing.getEra5LonMin(179.58f));
125-
assertEquals(1438, Era5PostProcessing.getEra5LonMin(179.72f));
126-
assertEquals(1439, Era5PostProcessing.getEra5LonMin(179.98f));
127-
assertEquals(1439, Era5PostProcessing.getEra5LonMin(179.99f));
116+
assertEquals(720, Era5PostProcessing.getEra5LonMin(-179.99f));
117+
assertEquals(720, Era5PostProcessing.getEra5LonMin(-179.84f));
118+
assertEquals(721, Era5PostProcessing.getEra5LonMin(-179.67f));
119+
assertEquals(1125, Era5PostProcessing.getEra5LonMin(-78.54f));
120+
assertEquals(1344, Era5PostProcessing.getEra5LonMin(-23.8f));
121+
assertEquals(1438, Era5PostProcessing.getEra5LonMin(-0.26f));
122+
assertEquals(1439, Era5PostProcessing.getEra5LonMin(-0.18f));
123+
assertEquals(0, Era5PostProcessing.getEra5LonMin(0.f));
124+
assertEquals(173, Era5PostProcessing.getEra5LonMin(43.32f));
125+
assertEquals(718, Era5PostProcessing.getEra5LonMin(179.58f));
126+
assertEquals(718, Era5PostProcessing.getEra5LonMin(179.72f));
127+
assertEquals(719, Era5PostProcessing.getEra5LonMin(179.98f));
128+
assertEquals(719, Era5PostProcessing.getEra5LonMin(179.99f));
128129
}
129130

130131
@Test
@@ -155,4 +156,27 @@ public void testIsValidLat() {
155156
assertFalse(Era5PostProcessing.isValidLat(9.96921E36f));
156157
assertFalse(Era5PostProcessing.isValidLat(Float.NaN));
157158
}
159+
160+
@Test
161+
public void testCreateInterpolator() {
162+
BilinearInterpolator interpolator = Era5PostProcessing.createInterpolator(-179.99f, 89.95f, 720, 0);
163+
assertEquals(0.03997802734375, interpolator.getA(), 1e-8);
164+
assertEquals(0.20001220703125, interpolator.getB(), 1e-8);
165+
166+
interpolator = Era5PostProcessing.createInterpolator(-78.54f, 67.87f, 1125, 88);
167+
assertEquals(0.839996337890625, interpolator.getA(), 1e-8);
168+
assertEquals(0.519989013671875, interpolator.getB(), 1e-8);
169+
170+
interpolator = Era5PostProcessing.createInterpolator(-0.18f, 0.f, 1439, 359);
171+
assertEquals(0.2799999713897705, interpolator.getA(), 1e-8);
172+
assertEquals(1.0, interpolator.getB(), 1e-8);
173+
174+
interpolator = Era5PostProcessing.createInterpolator(43.32f, -22.19f, 173, 448);
175+
assertEquals(0.279998779296875, interpolator.getA(), 1e-8);
176+
assertEquals(0.7600021362304688, interpolator.getB(), 1e-8);
177+
178+
interpolator = Era5PostProcessing.createInterpolator(179.98f, -89.95f, 719, 719);
179+
assertEquals(0.91998291015625, interpolator.getA(), 1e-8);
180+
assertEquals(0.79998779296875, interpolator.getB(), 1e-8);
181+
}
158182
}

0 commit comments

Comments
 (0)