Skip to content

Commit bbebbb8

Browse files
committed
prevent valid range attribute from being split
1 parent 1dbaee4 commit bbebbb8

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

core/src/main/java/com/bc/fiduceo/reader/modis/MxD021KM_Reader.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ private void ensureMod03File() throws IOException {
449449
}
450450

451451
if (mxD03Reader == null) {
452-
throw new IOException("associated MxD03 file not found in: " + productPath.toString());
452+
throw new IOException("associated MxD03 file not found in: " + productPath);
453453
}
454454
}
455455
}
@@ -492,11 +492,12 @@ protected void splitAttributes(Variable channelVariable, int index, int numChann
492492
toRemove.add(attribute);
493493

494494
final DataType dataType = attribute.getDataType();
495+
final String attributeName = attribute.getShortName();
495496
if (dataType.isString()) {
496497
final String stringValue = attribute.getStringValue();
497498
final String[] tokens = StringUtils.split(stringValue, new char[]{','}, true);
498-
if (tokens.length == numChannels) {
499-
final Attribute newAttribute = new Attribute(attribute.getShortName(), tokens[index]);
499+
if (tokens.length == numChannels && !attributeName.contains("valid_range")) {
500+
final Attribute newAttribute = new Attribute(attributeName, tokens[index]);
500501
toAdd.add(newAttribute);
501502
} else {
502503
toAdd.add(attribute);
@@ -505,7 +506,7 @@ protected void splitAttributes(Variable channelVariable, int index, int numChann
505506
final int length = attribute.getLength();
506507
if (length == numChannels) {
507508
final Number numericValue = attribute.getNumericValue(index);
508-
final Attribute newAttribute = new Attribute(attribute.getShortName(), numericValue);
509+
final Attribute newAttribute = new Attribute(attributeName, numericValue);
509510
toAdd.add(newAttribute);
510511
} else {
511512
toAdd.add(attribute);

core/src/test/java/com/bc/fiduceo/NCTestUtils.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
package com.bc.fiduceo;
2222

23-
import com.bc.fiduceo.reader.netcdf.NetCDFReader;
2423
import com.bc.fiduceo.util.NetCDFUtils;
2524
import ucar.ma2.Array;
2625
import ucar.ma2.DataType;
@@ -32,8 +31,7 @@
3231

3332
import java.io.IOException;
3433

35-
import static org.junit.Assert.assertEquals;
36-
import static org.junit.Assert.assertNotNull;
34+
import static org.junit.Assert.*;
3735

3836
public class NCTestUtils {
3937

@@ -154,6 +152,32 @@ public static void assertAttribute(Variable variable, String attributeName, Stri
154152
assertEquals(expected, attribute.getStringValue());
155153
} else if (dataType == DataType.FLOAT) {
156154
assertEquals(Float.parseFloat(expected), attribute.getNumericValue().floatValue(), 1e-8);
155+
} else if (dataType == DataType.SHORT) {
156+
if (attribute.isArray()) {
157+
final String[] segments = expected.split(",");
158+
final Array values = attribute.getValues();
159+
int i = 0;
160+
for (final String segment : segments) {
161+
assertEquals(Short.parseShort(segment), values.getShort(i));
162+
++i;
163+
}
164+
} else {
165+
assertEquals(Short.parseShort(expected), attribute.getNumericValue());
166+
}
167+
} else if (dataType == DataType.BYTE) {
168+
if (attribute.isArray()) {
169+
final String[] segments = expected.split(",");
170+
final Array values = attribute.getValues();
171+
int i = 0;
172+
for (final String segment : segments) {
173+
assertEquals(Byte.parseByte(segment), values.getByte(i));
174+
++i;
175+
}
176+
} else {
177+
assertEquals(Byte.parseByte(expected), attribute.getNumericValue());
178+
}
179+
} else {
180+
fail("unsupported");
157181
}
158182
}
159183

core/src/test/java/com/bc/fiduceo/reader/modis/MxD021KM_Reader_IO_Test.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ public void testGetVariables_Terra() throws IOException, InvalidRangeException {
205205
assertEquals("EV_1KM_RefSB_ch10", variable.getShortName());
206206
assertEquals(DataType.USHORT, variable.getDataType());
207207
NCTestUtils.assertAttribute(variable, "radiance_scales", "0.0036217605");
208+
NCTestUtils.assertAttribute(variable, "valid_range", "0,32767");
208209

209210
variable = variables.get(34);
210211
assertEquals("EV_1KM_RefSB_Uncert_Indexes_ch11", variable.getShortName());
@@ -291,11 +292,13 @@ public void testGetVariables_Aqua() throws IOException, InvalidRangeException {
291292
assertEquals("EV_1KM_RefSB_ch11", variable.getShortName());
292293
assertEquals(DataType.USHORT, variable.getDataType());
293294
NCTestUtils.assertAttribute(variable, "band_names", "11");
295+
NCTestUtils.assertAttribute(variable, "valid_range", "0,32767");
294296

295297
variable = variables.get(35);
296298
assertEquals("EV_1KM_RefSB_Uncert_Indexes_ch12", variable.getShortName());
297299
assertEquals(DataType.UBYTE, variable.getDataType());
298300
NCTestUtils.assertAttribute(variable, "specified_uncertainty", "1.5");
301+
NCTestUtils.assertAttribute(variable, "valid_range", "0,15");
299302

300303
variable = variables.get(49);
301304
assertEquals("EV_1KM_Emissive_ch23", variable.getShortName());
@@ -335,6 +338,7 @@ public void testGetVariables_Aqua() throws IOException, InvalidRangeException {
335338
variable = variables.get(94);
336339
assertEquals("EV_500_Aggr1km_RefSB_Samples_Used_ch03", variable.getShortName());
337340
assertEquals(DataType.BYTE, variable.getDataType());
341+
NCTestUtils.assertAttribute(variable, "valid_range", "0,6");
338342

339343
variable = variables.get(99);
340344
assertEquals("EV_Band26", variable.getShortName());

0 commit comments

Comments
 (0)