Skip to content

Commit 37dd05f

Browse files
committed
updated to support PIRATA and RAMA SSS data, added tests
1 parent 9f2754b commit 37dd05f

File tree

7 files changed

+229
-8
lines changed

7 files changed

+229
-8
lines changed

core/src/main/java/com/bc/fiduceo/reader/insitu/tao/TaoReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
class TaoReader implements Reader {
3434

35-
private final static String REG_EX = "(?:TAO|TRITON)_\\w+_\\w+(-\\w+)??\\d{4}-\\d{2}.txt";
35+
private final static String REG_EX = "(?:TAO|TRITON|RAMA|PIRATA)_\\w+_\\w+(-\\w+)??\\d{4}-\\d{2}.txt";
3636
private static final String TIME = "time";
3737
private static final String LONGITUDE = "longitude";
3838
private static final String LATITUDE = "latitude";

core/src/main/java/com/bc/fiduceo/reader/insitu/tao/TaoReaderPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
public class TaoReaderPlugin implements ReaderPlugin {
99

10-
private final static String[] SENSOR_KEYS = {"tao-sss"};
10+
private final static String[] SENSOR_KEYS = {"tao-sss", "pirata-sss", "rama-sss"};
1111

1212
@Override
1313
public Reader createReader(ReaderContext readerContext) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public static void writeSystemConfig(File configDir, File archiveRoot) throws IO
161161
" <rule sensors=\"ndbc-sm-cb, ndbc-sm-cs\">\n" +
162162
" insitu/ndbc/SENSOR/VERSION/YEAR\n" +
163163
" </rule>" +
164-
" <rule sensors=\"tao-sss\">\n" +
164+
" <rule sensors=\"tao-sss, pirata-sss\">\n" +
165165
" insitu/SENSOR/VERSION/YEAR/MONTH\n" +
166166
" </rule>" +
167167
" </archive>" +

core/src/test/java/com/bc/fiduceo/reader/insitu/tao/TaoReaderPluginTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void setUp() {
1818

1919
@Test
2020
public void testGetSupportedKeys() {
21-
final String[] expected = {"tao-sss"};
21+
final String[] expected = {"tao-sss", "pirata-sss", "rama-sss"};
2222

2323
assertArrayEquals(expected, plugin.getSupportedSensorKeys());
2424
}

core/src/test/java/com/bc/fiduceo/reader/insitu/tao/TaoReaderTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void setUp() {
2929

3030
@Test
3131
public void testGetRegEx() {
32-
final String expected = "(?:TAO|TRITON)_\\w+_\\w+(-\\w+)??\\d{4}-\\d{2}.txt";
32+
final String expected = "(?:TAO|TRITON|RAMA|PIRATA)_\\w+_\\w+(-\\w+)??\\d{4}-\\d{2}.txt";
3333

3434
assertEquals(expected, reader.getRegEx());
3535
final Pattern pattern = java.util.regex.Pattern.compile(expected);
@@ -42,6 +42,15 @@ public void testGetRegEx() {
4242

4343
matcher = pattern.matcher("TAO_T2S110W_DM233A-20170608_2018-02.txt");
4444
assertTrue(matcher.matches());
45+
46+
matcher = pattern.matcher("PIRATA_0N35W_sss_2017-08.txt");
47+
assertTrue(matcher.matches());
48+
49+
matcher = pattern.matcher("RAMA_4S805E_sss_2017-10.txt");
50+
assertTrue(matcher.matches());
51+
52+
matcher = pattern.matcher("PIRATA_0N35W_sss_2016-10.txt");
53+
assertTrue(matcher.matches());
4554
}
4655

4756
@Test

core/src/test/java/com/bc/fiduceo/reader/insitu/tao/TaoReader_IO_Test.java

Lines changed: 189 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ public void testReadAcquisitionInfo_TRITON() throws Exception {
6767
assertNull(info.getBoundingGeometry());
6868
}
6969

70+
@Test
71+
public void testReadAcquisitionInfo_PIRATA() throws Exception {
72+
final File insituDataFile = getPirataProduct();
73+
74+
reader.open(insituDataFile);
75+
76+
final AcquisitionInfo info = reader.read();
77+
TestUtil.assertCorrectUTCDate(2016, 10, 1, 0, 0, 0, 0, info.getSensingStart());
78+
TestUtil.assertCorrectUTCDate(2016, 10, 31, 23, 0, 0, 0, info.getSensingStop());
79+
80+
assertEquals(NodeType.UNDEFINED, info.getNodeType());
81+
82+
assertNull(info.getBoundingGeometry());
83+
}
84+
7085
@Test
7186
public void testGetProductSize_TAO() throws IOException {
7287
final File insituDataFile = getTAOProduct();
@@ -95,6 +110,20 @@ public void testGetProductSize_TRITON() throws IOException {
95110
assertEquals(31, productSize.getNy());
96111
}
97112

113+
@Test
114+
public void testGetProductSize_RAMA() throws IOException {
115+
final File insituDataFile = getRamaProduct();
116+
117+
reader.open(insituDataFile);
118+
119+
final Dimension productSize = reader.getProductSize();
120+
121+
assertNotNull(productSize);
122+
assertEquals("product_size", productSize.getName());
123+
assertEquals(1, productSize.getNx());
124+
assertEquals(720, productSize.getNy());
125+
}
126+
98127
@Test
99128
public void testGetTimeLocator_TAO() throws IOException {
100129
final File insituDataFile = getTAOProduct();
@@ -125,6 +154,21 @@ public void testGetTimeLocator_TRITON() throws IOException {
125154
assertEquals(-1L, timeLocator.getTimeFor(20, 45));
126155
}
127156

157+
@Test
158+
public void testGetTimeLocator_PIRATA() throws IOException {
159+
final File insituDataFile = getPirataProduct();
160+
161+
reader.open(insituDataFile);
162+
163+
final TimeLocator timeLocator = reader.getTimeLocator();
164+
assertEquals(1475280000000L, timeLocator.getTimeFor(0, 0));
165+
assertEquals(1475337600000L, timeLocator.getTimeFor(10, 16));
166+
assertEquals(1475391600000L, timeLocator.getTimeFor(20, 31));
167+
168+
assertEquals(-1L, timeLocator.getTimeFor(20, -1));
169+
assertEquals(-1L, timeLocator.getTimeFor(20, 1734));
170+
}
171+
128172
@Test
129173
public void testReadRaw_TAO() throws IOException, InvalidRangeException {
130174
final File insituDataFile = getTAOProduct();
@@ -201,7 +245,69 @@ public void testReadRaw_TRITON_3x3() throws IOException, InvalidRangeException {
201245
}
202246

203247
@Test
204-
public void testReadScale_TRITON() throws IOException, InvalidRangeException {
248+
public void testReadRaw_RAMA() throws IOException, InvalidRangeException {
249+
final File insituDataFile = getRamaProduct();
250+
251+
reader.open(insituDataFile);
252+
253+
final Interval singlePx = new Interval(1, 1);
254+
255+
// x is ignored
256+
Array array = reader.readRaw(8, 452, singlePx, "time");
257+
assertEquals(DataType.INT, array.getDataType());
258+
assertEquals(1524168000, array.getInt(0));
259+
260+
array = reader.readRaw(9, 453, singlePx, "longitude");
261+
assertEquals(DataType.FLOAT, array.getDataType());
262+
assertEquals(80.5f, array.getFloat(0), 1e-8);
263+
264+
array = reader.readRaw(9, 454, singlePx, "latitude");
265+
assertEquals(DataType.FLOAT, array.getDataType());
266+
assertEquals(-8.f, array.getFloat(0), 1e-8);
267+
268+
array = reader.readRaw(9, 455, singlePx, "SSS");
269+
assertEquals(DataType.FLOAT, array.getDataType());
270+
assertEquals(34.251f, array.getFloat(0), 1e-8);
271+
272+
array = reader.readRaw(9, 456, singlePx, "SST");
273+
assertEquals(DataType.FLOAT, array.getDataType());
274+
assertEquals(28.6f, array.getFloat(0), 1e-8);
275+
276+
array = reader.readRaw(9, 457, singlePx, "AIRT");
277+
assertEquals(DataType.FLOAT, array.getDataType());
278+
assertEquals(27.6f, array.getFloat(0), 1e-8);
279+
280+
array = reader.readRaw(9, 458, singlePx, "RH");
281+
assertEquals(DataType.FLOAT, array.getDataType());
282+
assertEquals(84.1f, array.getFloat(0), 1e-8);
283+
284+
array = reader.readRaw(9, 459, singlePx, "WSPD");
285+
assertEquals(DataType.FLOAT, array.getDataType());
286+
assertEquals(6.6f, array.getFloat(0), 1e-8);
287+
288+
array = reader.readRaw(9, 460, singlePx, "WDIR");
289+
assertEquals(DataType.FLOAT, array.getDataType());
290+
assertEquals(295.4f, array.getFloat(0), 1e-8);
291+
292+
array = reader.readRaw(9, 461, singlePx, "BARO");
293+
assertEquals(DataType.FLOAT, array.getDataType());
294+
assertEquals(1010.6f, array.getFloat(0), 1e-8);
295+
296+
array = reader.readRaw(9, 462, singlePx, "RAIN");
297+
assertEquals(DataType.FLOAT, array.getDataType());
298+
assertEquals(0.f, array.getFloat(0), 1e-8);
299+
300+
array = reader.readRaw(9, 463, singlePx, "Q");
301+
assertEquals(DataType.INT, array.getDataType());
302+
assertEquals(22222222, array.getInt(0));
303+
304+
array = reader.readRaw(9, 464, singlePx, "M");
305+
assertEquals(DataType.STRING, array.getDataType());
306+
assertEquals("11111111", array.getObject(0));
307+
}
308+
309+
@Test
310+
public void testReadScaled_TRITON() throws IOException, InvalidRangeException {
205311
final File insituDataFile = getTritonProduct();
206312

207313
reader.open(insituDataFile);
@@ -262,6 +368,68 @@ public void testReadScale_TRITON() throws IOException, InvalidRangeException {
262368
assertEquals("MMMMMMMM", array.getObject(0));
263369
}
264370

371+
@Test
372+
public void testReadScaled_PIRATA() throws IOException, InvalidRangeException {
373+
final File insituDataFile = getPirataProduct();
374+
375+
reader.open(insituDataFile);
376+
377+
final Interval singlePx = new Interval(1, 1);
378+
379+
// x is ignored
380+
Array array = reader.readScaled(8, 6, singlePx, "time");
381+
assertEquals(DataType.INT, array.getDataType());
382+
assertEquals(1475301600, array.getInt(0));
383+
384+
array = reader.readScaled(9, 7, singlePx, "longitude");
385+
assertEquals(DataType.FLOAT, array.getDataType());
386+
assertEquals(-35.f, array.getFloat(0), 1e-8);
387+
388+
array = reader.readScaled(9, 8, singlePx, "latitude");
389+
assertEquals(DataType.FLOAT, array.getDataType());
390+
assertEquals(0.f, array.getFloat(0), 1e-8);
391+
392+
array = reader.readScaled(9, 9, singlePx, "SSS");
393+
assertEquals(DataType.FLOAT, array.getDataType());
394+
assertEquals(35.649f, array.getFloat(0), 1e-8);
395+
396+
array = reader.readScaled(9, 10, singlePx, "SST");
397+
assertEquals(DataType.FLOAT, array.getDataType());
398+
assertEquals(-9.999f, array.getFloat(0), 1e-8);
399+
400+
array = reader.readScaled(9, 11, singlePx, "AIRT");
401+
assertEquals(DataType.FLOAT, array.getDataType());
402+
assertEquals(-9.99f, array.getFloat(0), 1e-8);
403+
404+
array = reader.readScaled(9, 12, singlePx, "RH");
405+
assertEquals(DataType.FLOAT, array.getDataType());
406+
assertEquals(-9.99f, array.getFloat(0), 1e-8);
407+
408+
array = reader.readScaled(9, 13, singlePx, "WSPD");
409+
assertEquals(DataType.FLOAT, array.getDataType());
410+
assertEquals(-99.9f, array.getFloat(0), 1e-8);
411+
412+
array = reader.readScaled(9, 14, singlePx, "WDIR");
413+
assertEquals(DataType.FLOAT, array.getDataType());
414+
assertEquals(-99.9f, array.getFloat(0), 1e-8);
415+
416+
array = reader.readScaled(9, 15, singlePx, "BARO");
417+
assertEquals(DataType.FLOAT, array.getDataType());
418+
assertEquals(-9.9f, array.getFloat(0), 1e-8);
419+
420+
array = reader.readScaled(9, 16, singlePx, "RAIN");
421+
assertEquals(DataType.FLOAT, array.getDataType());
422+
assertEquals(-9.99f, array.getFloat(0), 1e-8);
423+
424+
array = reader.readRaw(9, 17, singlePx, "Q");
425+
assertEquals(DataType.INT, array.getDataType());
426+
assertEquals(39999999, array.getInt(0));
427+
428+
array = reader.readScaled(9, 18, singlePx, "M");
429+
assertEquals(DataType.STRING, array.getDataType());
430+
assertEquals("5DDDDDDD", array.getObject(0));
431+
}
432+
265433
@Test
266434
public void testReadAcquisitionTime_TAO() throws IOException, InvalidRangeException {
267435
final File insituDataFile = getTAOProduct();
@@ -272,6 +440,16 @@ public void testReadAcquisitionTime_TAO() throws IOException, InvalidRangeExcept
272440
assertEquals(1467262800, acquisitionTime.getInt(0));
273441
}
274442

443+
@Test
444+
public void testReadAcquisitionTime_RAMA() throws IOException, InvalidRangeException {
445+
final File insituDataFile = getRamaProduct();
446+
447+
reader.open(insituDataFile);
448+
449+
ArrayInt.D2 acquisitionTime = reader.readAcquisitionTime(3, 702, new Interval(1, 1));
450+
assertEquals(1525068000, acquisitionTime.getInt(0));
451+
}
452+
275453
private static File getTAOProduct() throws IOException {
276454
final String testFilePath = TestUtil.assembleFileSystemPath(new String[]{"insitu", "tao-sss", "v1", "2016", "06", "TAO_T2S140W_DM167A-20160228_2016-06.txt"}, false);
277455
return TestUtil.getTestDataFileAsserted(testFilePath);
@@ -281,4 +459,14 @@ private static File getTritonProduct() throws IOException {
281459
final String testFilePath = TestUtil.assembleFileSystemPath(new String[]{"insitu", "tao-sss", "v1", "2017", "10", "TRITON_TR0N156E_1998_2017-10.txt"}, false);
282460
return TestUtil.getTestDataFileAsserted(testFilePath);
283461
}
462+
463+
private static File getPirataProduct() throws IOException {
464+
final String testFilePath = TestUtil.assembleFileSystemPath(new String[]{"insitu", "pirata-sss", "v1", "2016", "10", "PIRATA_0N35W_sss_2016-10.txt"}, false);
465+
return TestUtil.getTestDataFileAsserted(testFilePath);
466+
}
467+
468+
private static File getRamaProduct() throws IOException {
469+
final String testFilePath = TestUtil.assembleFileSystemPath(new String[]{"insitu", "rama-sss", "v1", "2018", "04", "RAMA_8S805E_sss_2018-04.txt"}, false);
470+
return TestUtil.getTestDataFileAsserted(testFilePath);
471+
}
284472
}

ingestion-tool/src/test/java/com/bc/fiduceo/ingest/IngestionToolIntegrationTest.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ public void setUp() throws SQLException, IOException {
8383

8484
@After
8585
public void tearDown() throws SQLException {
86-
storage.clear();
87-
storage.close();
86+
if (storage != null) {
87+
storage.clear();
88+
storage.close();
89+
storage = null;
90+
}
8891
TestUtil.deleteTestDirectory();
8992
}
9093

@@ -1140,6 +1143,27 @@ public void testIngest_TAO() throws SQLException, ParseException {
11401143
assertNull(observation.getTimeAxes());
11411144
}
11421145

1146+
@Test
1147+
public void testIngest_PIRATA() throws SQLException, ParseException {
1148+
final String[] args = new String[]{"-c", configDir.getAbsolutePath(), "-s", "pirata-sss", "-start", "2016-275", "-end", "2016-275", "-v", "v1"};
1149+
1150+
IngestionToolMain.main(args);
1151+
1152+
final List<SatelliteObservation> observations = storage.get();
1153+
assertEquals(1, observations.size());
1154+
1155+
final SatelliteObservation observation = getSatelliteObservation("PIRATA_0N35W_sss_2016-10.txt", observations);
1156+
TestUtil.assertCorrectUTCDate(2016, 10, 1, 0, 0, 0, observation.getStartTime());
1157+
TestUtil.assertCorrectUTCDate(2016, 10, 31, 23, 0, 0, observation.getStopTime());
1158+
1159+
assertEquals("pirata-sss", observation.getSensor().getName());
1160+
assertEquals("v1", observation.getVersion());
1161+
assertEquals(NodeType.UNDEFINED, observation.getNodeType());
1162+
1163+
assertNull(observation.getGeoBounds());
1164+
assertNull(observation.getTimeAxes());
1165+
}
1166+
11431167
private void callMainAndValidateSystemOutput(String[] args, boolean errorOutputExpected) throws ParseException {
11441168
final ByteArrayOutputStream expected = new ByteArrayOutputStream();
11451169
new IngestionTool().printUsageTo(expected);

0 commit comments

Comments
 (0)