Skip to content

Commit 88c4486

Browse files
committed
corrected fill-value handling
1 parent 2397d6f commit 88c4486

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

core/src/main/java/com/bc/fiduceo/reader/windsat/WindsatReader.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public PixelLocator getSubScenePixelLocator(Polygon sceneGeometry) throws IOExce
135135
public TimeLocator getTimeLocator() throws IOException {
136136
if (timeLocator == null) {
137137
final Array timeArray = arrayCache.get("time");
138-
final Number fillValue = arrayCache.getNumberAttributeValue("_FillValue", "time");
138+
final Number fillValue = getFillValue("time", timeArray);
139139
final int[] origin = {0, 0, 0, 2}; // select layer for "fore" and 18 GHz tb 2022-11-28
140140
final int[] shape = timeArray.getShape();
141141
shape[2] = 1; // one view layer tb 2022-11-28
@@ -166,7 +166,7 @@ public Array readRaw(int centerX, int centerY, Interval interval, String variabl
166166
// read x section and fill in y-direction
167167
final Array array = arrayCache.get(variableName);
168168
final int[] shape = array.getShape();
169-
final Number fillValue = NetCDFUtils.getDefaultFillValue(DataType.DOUBLE, true);
169+
final double fillValue = NetCDFUtils.getDefaultFillValue(DataType.DOUBLE, true).doubleValue();
170170

171171
final int sectionWidth = interval.getX();
172172
final int sectionHeight = interval.getY();
@@ -181,7 +181,7 @@ public Array readRaw(int centerX, int centerY, Interval interval, String variabl
181181
if (x >= 0 && x < shape[0]) {
182182
value = array.getDouble(x);
183183
} else {
184-
value = fillValue.doubleValue();
184+
value = fillValue;
185185
}
186186

187187
for (int y = 0; y < sectionHeight; y++) {
@@ -194,14 +194,14 @@ public Array readRaw(int centerX, int centerY, Interval interval, String variabl
194194
return resultArray;
195195
} else if (variables2D.contains(variableName)) {
196196
final Array array = arrayCache.get(variableName);
197-
final Number fillValue = arrayCache.getNumberAttributeValue(NetCDFUtils.CF_FILL_VALUE_NAME, variableName);
197+
final Number fillValue = getFillValue(variableName, array);
198198
return RawDataReader.read(centerX, centerY, interval, fillValue, array, getProductSize());
199199
} else {
200200
// extract layer indices and NetCDF file variable name from variable name
201201
final ArrayInfo arrayInfo = extractArrayInfo(variableName);
202202

203203
final Array array = arrayCache.get(arrayInfo.ncVarName);
204-
final Number fillValue = arrayCache.getNumberAttributeValue(NetCDFUtils.CF_FILL_VALUE_NAME, arrayInfo.ncVarName);
204+
final Number fillValue = getFillValue(arrayInfo.ncVarName, array);
205205

206206
final int[] origin;
207207
final int[] shape;
@@ -228,6 +228,14 @@ public Array readRaw(int centerX, int centerY, Interval interval, String variabl
228228
}
229229
}
230230

231+
private Number getFillValue(String variableName, Array array) throws IOException {
232+
Number fillValue = arrayCache.getNumberAttributeValue(NetCDFUtils.CF_FILL_VALUE_NAME, variableName);
233+
if (fillValue == null) {
234+
fillValue = NetCDFUtils.getDefaultFillValue(array);
235+
}
236+
return fillValue;
237+
}
238+
231239
@Override
232240
public Array readScaled(int centerX, int centerY, Interval interval, String variableName) throws IOException, InvalidRangeException {
233241
final Array rawArray = readRaw(centerX, centerY, interval, variableName);

matchup-tool/src/test/java/com/bc/fiduceo/matchup/MatchupToolIntegrationTest_Windsat_sic_cci.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.bc.fiduceo.db.DbAndIOTestRunner;
1010
import com.bc.fiduceo.util.NetCDFUtils;
1111
import org.apache.commons.cli.ParseException;
12-
import org.junit.Ignore;
1312
import org.junit.Test;
1413
import org.junit.runner.RunWith;
1514
import ucar.ma2.InvalidRangeException;
@@ -91,27 +90,18 @@ public void testMatchup() throws IOException, SQLException, ParseException, Inva
9190
}
9291

9392
@Test
94-
@Ignore
9593
public void test_oome_crash() throws IOException, SQLException, ParseException {
96-
final UseCaseConfig useCaseConfig = createUseCaseConfigBuilder("DTUSIC1-sic-cci")
94+
final UseCaseConfig useCaseConfig = createUseCaseConfigBuilder("ANTXXXI-sic-cci")
9795
.withTimeDeltaSeconds(86400, null)
9896
.withMaxPixelDistanceKm(14, null)
9997
.createConfig();
10098
final File useCaseConfigFile = storeUseCaseConfig(useCaseConfig, "usecase-45.xml");
10199

102-
insert_DTU_SIC_CCI("ASCAT-vs-AMSR2-vs-ERA5-vs-DTUSIC1-2018-S.text");
103-
insert_DTU_SIC_CCI("ASCAT-vs-AMSR2-vs-ERA5-vs-DTUSIC1-2018-N.text");
100+
insert_Polarstern();
104101

105-
insert_windsat_MD("09", "30", "RSS_WindSat_TB_L1C_r81462_20180930T055123_2018273_V08.0.nc");
106-
insert_windsat_MD("09", "30", "RSS_WindSat_TB_L1C_r81465_20180930T105600_2018273_V08.0.nc");
107-
insert_windsat_MD("09", "30", "RSS_WindSat_TB_L1C_r81466_20180930T123732_2018273_V08.0.nc");
108-
insert_windsat_MD("09", "30", "RSS_WindSat_TB_L1C_r81467_20180930T141905_2018273_V08.0.nc");
109-
insert_windsat_MD("09", "30", "RSS_WindSat_TB_L1C_r81468_20180930T160038_2018273_V08.0.nc");
110-
insert_windsat_MD("09", "30", "RSS_WindSat_TB_L1C_r81469_20180930T174209_2018273_V08.0.nc");
111-
insert_windsat_MD("09", "30", "RSS_WindSat_TB_L1C_r81470_20180930T192342_2018273_V08.0.nc");
112-
insert_windsat_MD("09", "30", "RSS_WindSat_TB_L1C_r81471_20180930T210513_2018273_V08.0.nc");
102+
insert_windsat_MD("2016", "01", "15", "RSS_WindSat_TB_L1C_r67435_20160115T031230_2016015_V08.0.nc");
113103

114-
final String[] args = new String[]{"-c", configDir.getAbsolutePath(), "-u", useCaseConfigFile.getName(), "-start", "2018-274", "-end", "2018-274"};
104+
final String[] args = new String[]{"-c", configDir.getAbsolutePath(), "-u", useCaseConfigFile.getName(), "-start", "2016-015", "-end", "2016-015"};
115105
MatchupToolMain.main(args);
116106
}
117107

@@ -139,9 +129,17 @@ private void insert_DTU_SIC_CCI(String fileName) throws IOException, SQLExceptio
139129
storage.insert(satelliteObservation);
140130
}
141131

142-
private void insert_windsat_MD(String month, String day, String filename) throws IOException, SQLException {
132+
private void insert_Polarstern() throws IOException, SQLException {
133+
final String sensorKey = "ANTXXXI-sic-cci";
134+
final String relativeArchivePath = TestUtil.assembleFileSystemPath(new String[]{"insitu", "sic-cci", sensorKey, "v3", "ASCAT-vs-AMSR2-vs-ERA-vs-ANTXXXI_2_FROSN_SeaIceObservations_reformatted.txt"}, true);
135+
136+
final SatelliteObservation satelliteObservation = readSatelliteObservation(sensorKey, relativeArchivePath, "v3");
137+
storage.insert(satelliteObservation);
138+
}
139+
140+
private void insert_windsat_MD(String year, String month, String day, String filename) throws IOException, SQLException {
143141
final String sensorKey = "windsat-coriolis";
144-
final String relativeArchivePath = TestUtil.assembleFileSystemPath(new String[]{sensorKey, "v1.0", "2018", month, day, filename}, true);
142+
final String relativeArchivePath = TestUtil.assembleFileSystemPath(new String[]{sensorKey, "v1.0", year, month, day, filename}, true);
145143

146144
final SatelliteObservation satelliteObservation = readSatelliteObservation(sensorKey, relativeArchivePath, "v1.0");
147145
storage.insert(satelliteObservation);

0 commit comments

Comments
 (0)