Skip to content

Commit 19d2be8

Browse files
committed
implemented getAcquisition time, refined variables test
1 parent 5a223e2 commit 19d2be8

File tree

4 files changed

+101
-6
lines changed

4 files changed

+101
-6
lines changed

core/src/main/java/com/bc/fiduceo/reader/netcdf/NetCDFReader.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ protected Array acquisitionTimeFromTimeLocator(int y, Interval interval) throws
181181
lineTimeInSeconds = acquisitionTimeFillValue;
182182
} else {
183183
final long lineTime = timeLocator.getTimeFor(0, yRead);
184-
lineTimeInSeconds = (int) (lineTime / 1000);
184+
if (lineTime < 0) {
185+
lineTimeInSeconds = acquisitionTimeFillValue;
186+
} else {
187+
lineTimeInSeconds = (int) (lineTime / 1000);
188+
}
185189
}
186190

187191
for (int xa = 0; xa < width; xa++) {

core/src/main/java/com/bc/fiduceo/reader/smos/SmosL1CDailyGriddedReader.java

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
1616
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
1717
import org.esa.snap.core.util.io.FileUtils;
18-
import ucar.ma2.Array;
19-
import ucar.ma2.ArrayInt;
20-
import ucar.ma2.DataType;
21-
import ucar.ma2.InvalidRangeException;
18+
import ucar.ma2.*;
2219
import ucar.nc2.Variable;
2320

2421
import java.awt.geom.Rectangle2D;
@@ -29,6 +26,8 @@
2926
import java.util.Date;
3027
import java.util.List;
3128

29+
import static com.bc.fiduceo.util.NetCDFUtils.getDefaultFillValue;
30+
3231
class SmosL1CDailyGriddedReader extends NetCDFReader {
3332

3433
private final ReaderContext readerContext;
@@ -180,7 +179,45 @@ public Array readScaled(int centerX, int centerY, Interval interval, String vari
180179

181180
@Override
182181
public ArrayInt.D2 readAcquisitionTime(int x, int y, Interval interval) throws IOException, InvalidRangeException {
183-
throw new IllegalStateException("not implemented");
182+
final int height = interval.getY();
183+
final int width = interval.getX();
184+
final int x_offset = x - width / 2;
185+
final int y_offset = y - height / 2;
186+
int[] shape = new int[]{height, width};
187+
188+
final Dimension productSize = getProductSize();
189+
final int pWidth = productSize.getNx();
190+
final int pHeight = productSize.getNy();
191+
192+
final TimeLocator timeLocator = getTimeLocator();
193+
final int acquisitionTimeFillValue = getDefaultFillValue(int.class).intValue();
194+
195+
final ArrayInt.D2 acquisitionTime = (ArrayInt.D2) Array.factory(DataType.INT, shape);
196+
final Index index = acquisitionTime.getIndex();
197+
198+
for (int ya = 0; ya < height; ya++) {
199+
final int yRead = y_offset + ya;
200+
201+
for (int xa = 0; xa < width; xa++) {
202+
final int xRead = x_offset + xa;
203+
204+
int acTime;
205+
if (xRead < 0 || xRead >= pWidth || yRead < 0 || yRead >= pHeight) {
206+
acTime = acquisitionTimeFillValue;
207+
} else {
208+
final long pxTime = timeLocator.getTimeFor(xRead, yRead);
209+
if (pxTime < 0) {
210+
acTime = acquisitionTimeFillValue;
211+
} else {
212+
acTime = (int) (pxTime / 1000);
213+
}
214+
}
215+
index.set(ya, xa);
216+
acquisitionTime.setInt(index, acTime);
217+
}
218+
}
219+
220+
return acquisitionTime;
184221
}
185222

186223
@Override

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ public static void assertAttribute(Variable variable, String attributeName, Stri
152152
assertEquals(expected, attribute.getStringValue());
153153
} else if (dataType == DataType.FLOAT) {
154154
assertEquals(Float.parseFloat(expected), attribute.getNumericValue().floatValue(), 1e-8);
155+
}else if (dataType == DataType.DOUBLE) {
156+
assertEquals(Double.parseDouble(expected), attribute.getNumericValue().doubleValue(), 1e-8);
155157
} else if (dataType == DataType.INT) {
156158
assertEquals(Integer.parseInt(expected), attribute.getNumericValue().intValue(), 1e-8);
157159
} else if (dataType == DataType.SHORT) {

core/src/test/java/com/bc/fiduceo/reader/smos/SmosL1CDailyGriddedReader_IO_Test.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.bc.fiduceo.NCTestUtils;
55
import com.bc.fiduceo.TestUtil;
66
import com.bc.fiduceo.core.Dimension;
7+
import com.bc.fiduceo.core.Interval;
78
import com.bc.fiduceo.core.NodeType;
89
import com.bc.fiduceo.geometry.*;
910
import com.bc.fiduceo.location.PixelLocator;
@@ -15,6 +16,8 @@
1516
import org.junit.Before;
1617
import org.junit.Test;
1718
import org.junit.runner.RunWith;
19+
import ucar.ma2.ArrayInt;
20+
import ucar.ma2.DataType;
1821
import ucar.ma2.InvalidRangeException;
1922
import ucar.nc2.Variable;
2023

@@ -188,31 +191,60 @@ public void testGetVariables_CDF3TD() throws IOException, InvalidRangeException
188191

189192
Variable variable = variables.get(0);
190193
assertEquals("X_Swath", variable.getShortName());
194+
assertEquals(DataType.FLOAT, variable.getDataType());
191195
NCTestUtils.assertAttribute(variable, "_FillValue", "9.96921E36");
196+
NCTestUtils.assertAttribute(variable, "units", "m");
197+
NCTestUtils.assertAttribute(variable, "long_name", "Minimum distance of grid point to the sub satellite point track");
192198

193199
variable = variables.get(3);
194200
assertEquals("BT_H_ch02", variable.getShortName());
201+
assertEquals(DataType.SHORT, variable.getDataType());
195202
NCTestUtils.assertAttribute(variable, "_FillValue", "-32768");
203+
NCTestUtils.assertAttribute(variable, "units", "K");
204+
NCTestUtils.assertAttribute(variable, "long_name", "Angle class averaged Brightness temperature in H-pol over current Earth fixed grid point, obtained by polarisation rotation from L1c data");
205+
NCTestUtils.assertAttribute(variable, "add_offset", "200.0");
206+
NCTestUtils.assertAttribute(variable, "scale_factor", "0.0061037018951994385");
196207

197208
variable = variables.get(38);
198209
assertEquals("BT_3_ch07", variable.getShortName());
210+
assertEquals(DataType.SHORT, variable.getDataType());
199211
NCTestUtils.assertAttribute(variable, "_FillValue", "-32768");
212+
NCTestUtils.assertAttribute(variable, "units", "K");
213+
NCTestUtils.assertAttribute(variable, "long_name", "Angle class averaged Brightness temperature 3rd Stokes parameter over current Earth fixed grid point, obtained by polarisation rotation from L1c data");
214+
NCTestUtils.assertAttribute(variable, "add_offset", "0.0");
215+
NCTestUtils.assertAttribute(variable, "scale_factor", "0.0015259254737998596");
200216

201217
variable = variables.get(175);
202218
assertEquals("Pixel_BT_Standard_Deviation_4_ch09", variable.getShortName());
219+
assertEquals(DataType.SHORT, variable.getDataType());
203220
NCTestUtils.assertAttribute(variable, "_FillValue", "-32768");
221+
NCTestUtils.assertAttribute(variable, "units", "K");
222+
NCTestUtils.assertAttribute(variable, "long_name", "Angle class BT standard deviation in the Brightness Temperature presented in the previous field, extracted in the direction of the pixel ");
223+
NCTestUtils.assertAttribute(variable, "add_offset", "25.0");
224+
NCTestUtils.assertAttribute(variable, "scale_factor", "7.629627368999298E-4");
204225

205226
variable = variables.get(219);
206227
assertEquals("Footprint_Axis1_ch08", variable.getShortName());
228+
assertEquals(DataType.SHORT, variable.getDataType());
207229
NCTestUtils.assertAttribute(variable, "_FillValue", "-32768");
230+
NCTestUtils.assertAttribute(variable, "units", "km");
231+
NCTestUtils.assertAttribute(variable, "long_name", "Angle class averaged Elliptical footprint major semi-axis value");
232+
NCTestUtils.assertAttribute(variable, "add_offset", "50.0");
233+
NCTestUtils.assertAttribute(variable, "scale_factor", "0.0015259254737998596");
208234

209235
variable = variables.get(305);
210236
assertEquals("Nb_SUN_Flags_ch04", variable.getShortName());
237+
assertEquals(DataType.SHORT, variable.getDataType());
211238
NCTestUtils.assertAttribute(variable, "_FillValue", "-32768");
239+
NCTestUtils.assertAttribute(variable, "units", "NA");
240+
NCTestUtils.assertAttribute(variable, "long_name", "Number of views flagged as potentially contaminated by Sun used to compute Angle class averages");
212241

213242
variable = variables.get(361);
214243
assertEquals("UTC_Microseconds_ch15", variable.getShortName());
244+
assertEquals(DataType.INT, variable.getDataType());
215245
NCTestUtils.assertAttribute(variable, "_FillValue", "-2147483647");
246+
NCTestUtils.assertAttribute(variable, "units", "10-6s");
247+
NCTestUtils.assertAttribute(variable, "long_name", "UTC Time at which the averaged BT was taken, in EE CFI transport time format. Microseconds");
216248
} finally {
217249
reader.close();
218250
}
@@ -256,6 +288,26 @@ public void testGetTimeLocator_CDF3TA() throws IOException {
256288
}
257289
}
258290

291+
@Test
292+
public void testReadAcquisitionTime_CDF3TD() throws IOException, InvalidRangeException {
293+
final File file = getCDF3TDFile();
294+
295+
try {
296+
reader.open(file);
297+
final ArrayInt.D2 acquisitionTime = reader.readAcquisitionTime(166, 67, new Interval(5, 3));
298+
assertEquals(15, acquisitionTime.getSize());
299+
300+
// run over a section that covers a swath border tb 2022-10-13
301+
NCTestUtils.assertValueAt(-2147483647, 0, 1, acquisitionTime);
302+
NCTestUtils.assertValueAt(-2147483647, 1, 1, acquisitionTime);
303+
NCTestUtils.assertValueAt(1511142933, 2, 1, acquisitionTime);
304+
NCTestUtils.assertValueAt(1511142929, 3, 1, acquisitionTime);
305+
NCTestUtils.assertValueAt(1511142923, 4, 1, acquisitionTime);
306+
} finally {
307+
reader.close();
308+
}
309+
}
310+
259311
private File getCDF3TAFile() throws IOException {
260312
final String testFilePath = TestUtil.assembleFileSystemPath(new String[]{"miras-smos-CDF3TA", "re07", "2016", "162", "SM_RE07_MIR_CDF3TA_20160610T000000_20160610T235959_330_001_7.tgz"}, false);
261313
return TestUtil.getTestDataFileAsserted(testFilePath);

0 commit comments

Comments
 (0)