Skip to content

Commit 37e9cda

Browse files
committed
refactoring
1 parent a295e69 commit 37e9cda

File tree

6 files changed

+80
-45
lines changed

6 files changed

+80
-45
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.bc.fiduceo.reader.insitu;
2+
3+
import com.bc.fiduceo.core.Interval;
4+
import ucar.ma2.Array;
5+
6+
public class InsituUtils {
7+
8+
public static Array getResultArray(int centerY, Interval interval, Array sourceArray, Number fillValue) {
9+
final int windowWidth = interval.getX();
10+
final int windowHeight = interval.getY();
11+
final int windowCenterX = windowWidth / 2;
12+
final int windowCenterY = windowHeight / 2;
13+
14+
final int[] shape = {windowWidth, windowHeight};
15+
final Array windowArray = Array.factory(sourceArray.getDataType(), shape);
16+
for (int y = 0; y < windowHeight; y++) {
17+
for (int x = 0; x < windowWidth; x++) {
18+
windowArray.setObject(windowWidth * y + x, fillValue);
19+
}
20+
}
21+
windowArray.setObject(windowWidth * windowCenterY + windowCenterX, sourceArray.getObject(centerY));
22+
return windowArray;
23+
}
24+
}

core/src/main/java/com/bc/fiduceo/reader/insitu/sirds_sst/SirdsInsituReader.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.util.Calendar;
2323
import java.util.List;
2424

25-
import static com.bc.fiduceo.util.TimeUtils.millisSince1978;
25+
import static com.bc.fiduceo.reader.insitu.InsituUtils.getResultArray;
2626

2727
public class SirdsInsituReader extends NetCDFReader {
2828

@@ -123,20 +123,7 @@ public Array readRaw(int centerX, int centerY, Interval interval, String variabl
123123
fillValue = getFillValue(variableName);
124124
}
125125

126-
final int windowWidth = interval.getX();
127-
final int windowHeight = interval.getY();
128-
final int windowCenterX = windowWidth / 2;
129-
final int windowCenterY = windowHeight / 2;
130-
131-
final int[] shape = {windowWidth, windowHeight};
132-
final Array windowArray = Array.factory(sourceArray.getDataType(), shape);
133-
for (int y = 0; y < windowHeight; y++) {
134-
for (int x = 0; x < windowWidth; x++) {
135-
windowArray.setObject(windowWidth * y + x, fillValue);
136-
}
137-
}
138-
windowArray.setObject(windowWidth * windowCenterY + windowCenterX, sourceArray.getObject(centerY));
139-
return windowArray;
126+
return getResultArray(centerY, interval, sourceArray, fillValue);
140127
}
141128

142129
@Override

core/src/main/java/com/bc/fiduceo/reader/insitu/sst_cci/SSTInsituReader.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.List;
4444
import java.util.Map;
4545

46+
import static com.bc.fiduceo.reader.insitu.InsituUtils.getResultArray;
4647
import static com.bc.fiduceo.util.NetCDFUtils.CF_FILL_VALUE_NAME;
4748
import static com.bc.fiduceo.util.TimeUtils.millisSince1978;
4849
import static com.bc.fiduceo.util.TimeUtils.secondsSince1978;
@@ -71,14 +72,12 @@ public void open(File file) throws IOException {
7172

7273
@Override
7374
public void close() throws IOException {
74-
if (netcdfFile != null) {
75-
netcdfFile.close();
76-
netcdfFile = null;
77-
}
7875
variables = null;
7976

8077
arrayMap.clear();
8178
fillValueMap.clear();
79+
80+
super.close();
8281
}
8382

8483
@Override
@@ -136,20 +135,7 @@ public Array readRaw(int centerX, int centerY, Interval interval, String variabl
136135
final Array sourceArray = arrayMap.get(variableName);
137136
final Number fillValue = fillValueMap.get(variableName);
138137

139-
final int windowWidth = interval.getX();
140-
final int windowHeight = interval.getY();
141-
final int windowCenterX = windowWidth / 2;
142-
final int windowCenterY = windowHeight / 2;
143-
144-
final int[] shape = {windowWidth, windowHeight};
145-
final Array windowArray = Array.factory(sourceArray.getDataType(), shape);
146-
for (int y = 0; y < windowHeight; y++) {
147-
for (int x = 0; x < windowWidth; x++) {
148-
windowArray.setObject(windowWidth * y + x, fillValue);
149-
}
150-
}
151-
windowArray.setObject(windowWidth * windowCenterY + windowCenterX, sourceArray.getObject(centerY));
152-
return windowArray;
138+
return getResultArray(centerY, interval, sourceArray, fillValue);
153139
}
154140

155141
public Array getSourceArray(String variableName) {

core/src/main/resources/META-INF/services/com.bc.fiduceo.reader.ReaderPlugin

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ com.bc.fiduceo.reader.fiduceo_fcdr.AVHRR_FCDR_ReaderPlugin
1919
com.bc.fiduceo.reader.fiduceo_fcdr.HIRS_FCDR_ReaderPlugin
2020
com.bc.fiduceo.reader.slstr.SlstrReaderPlugin
2121
com.bc.fiduceo.reader.slstr.SlstrNRReaderPlugin
22-
com.bc.fiduceo.reader.slstr.SlstrNTReaderPlugin
22+
com.bc.fiduceo.reader.slstr.SlstrNTReaderPlugin
23+
com.bc.fiduceo.reader.insitu.sirds_sst.SirdsInsituReaderPlugin

core/src/test/java/com/bc/fiduceo/reader/ReaderFactoryTest.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.bc.fiduceo.reader.avhrr_gac.AVHRR_GAC_Reader;
2828
import com.bc.fiduceo.reader.hirs.ForReaderFactoryTest_HIRS_L1C_Reader;
2929
import com.bc.fiduceo.reader.iasi.IASI_Reader;
30+
import com.bc.fiduceo.reader.insitu.sirds_sst.SirdsInsituReader;
3031
import com.bc.fiduceo.reader.insitu.sst_cci.SSTInsituReader;
3132
import com.bc.fiduceo.reader.modis.MxD06_Reader;
3233
import org.junit.Before;
@@ -94,6 +95,14 @@ public void testGetSstInsituReader() {
9495
assertTrue(reader instanceof SSTInsituReader);
9596
}
9697

98+
@Test
99+
public void testGetSirdsInsituReader() {
100+
final Reader reader = readerFactory.getReader("bottle-sirds");
101+
102+
assertNotNull(reader);
103+
assertTrue(reader instanceof SirdsInsituReader);
104+
}
105+
97106
@Test
98107
public void testGetModisCloudReader() {
99108
final Reader reader = readerFactory.getReader("myd06-aq");
@@ -178,15 +187,13 @@ public void testGet() {
178187

179188
@SuppressWarnings("ResultOfMethodCallIgnored")
180189
@Test
181-
public void testGet_throwsWehnNotCreated() {
190+
public void testGet_throwsWhenNotCreated() {
182191
ReaderFactory.clear();
183192

184193
try {
185194
ReaderFactory.get();
186195
fail("RuntimeException expected");
187196
} catch (RuntimeException expected) {
188197
}
189-
190-
191198
}
192199
}

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

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848
import java.sql.SQLException;
4949
import java.util.List;
5050

51-
import static org.hamcrest.CoreMatchers.equalTo;
52-
import static org.hamcrest.CoreMatchers.is;
5351
import static org.junit.Assert.*;
5452
import static org.mockito.Mockito.mock;
5553
import static org.mockito.Mockito.when;
@@ -118,8 +116,8 @@ public void testIngest_errorStopDateBeforeStartDate() throws ParseException, IOE
118116
ingestionTool.run(commandLine);
119117
fail("RuntimeException expected");
120118
} catch (RuntimeException expected) {
121-
assertThat(expected.getClass().getTypeName(), is(equalTo("java.lang.RuntimeException")));
122-
assertThat(expected.getMessage(), is(equalTo("End date before start date")));
119+
assertEquals("java.lang.RuntimeException", expected.getClass().getTypeName());
120+
assertEquals("End date before start date", expected.getMessage());
123121
}
124122
}
125123

@@ -780,6 +778,38 @@ public void testIngest_insitu_SST_Drifter_v40() throws SQLException, IOException
780778
}
781779
}
782780

781+
// @todo 1 tb/tb implement this test 2021-07-23
782+
// @Test
783+
// public void testIngest_insitu_Sirds_mooring() throws SQLException, IOException, ParseException {
784+
// final String[] args = new String[]{"-c", configDir.getAbsolutePath(), "-s", "mooring-sirds", "-start", "2016-032", "-end", "2016-061", "-v", "v1.0"};
785+
//
786+
// try {
787+
// IngestionToolMain.main(args);
788+
//
789+
// final List<SatelliteObservation> satelliteObservations = storage.get();
790+
// assertEquals(1, satelliteObservations.size());
791+
//
792+
// final SatelliteObservation observation = getSatelliteObservation("insitu_0_WMOID_42531_19960904_19960909.nc", satelliteObservations);
793+
// TestUtil.assertCorrectUTCDate(1996, 9, 4, 22, 0, 0, 0, observation.getStartTime());
794+
// TestUtil.assertCorrectUTCDate(1996, 9, 9, 13, 19, 47, 0, observation.getStopTime());
795+
//
796+
// assertEquals("drifter-sst", observation.getSensor().getName());
797+
//
798+
// final String testFilePath = TestUtil.assembleFileSystemPath(new String[]{"insitu", "drifter-sst", "v04.0", "insitu_0_WMOID_42531_19960904_19960909.nc"}, true);
799+
// final String expectedPath = TestUtil.getTestDataDirectory().getAbsolutePath() + testFilePath;
800+
// assertEquals(expectedPath, observation.getDataFilePath().toString());
801+
//
802+
// assertEquals(NodeType.UNDEFINED, observation.getNodeType());
803+
// assertEquals("v04.0", observation.getVersion());
804+
//
805+
// assertNull(observation.getGeoBounds());
806+
// assertNull(observation.getTimeAxes());
807+
// } finally {
808+
// storage.clear();
809+
// storage.close();
810+
// }
811+
// }
812+
783813
@Test
784814
public void testIngest_IASI_MA() throws SQLException, IOException, ParseException {
785815
final String[] args = new String[]{"-c", configDir.getAbsolutePath(), "-s", "iasi-ma", "-start", "2016-001", "-end", "2016-001", "-v", "v3-6N"};
@@ -1095,11 +1125,11 @@ private void callMainAndValidateSystemOutput(String[] args, boolean errorOutputE
10951125
psO.flush();
10961126
psE.flush();
10971127
if (errorOutputExpected) {
1098-
assertThat(out.toString(), is(equalTo("")));
1099-
assertThat(err.toString(), is(equalTo(expected.toString())));
1128+
assertEquals("", out.toString());
1129+
assertEquals(expected.toString(), err.toString());
11001130
} else {
1101-
assertThat(out.toString(), is(equalTo(expected.toString())));
1102-
assertThat(err.toString(), is(equalTo("")));
1131+
assertEquals(expected.toString(), out.toString());
1132+
assertEquals("", err.toString());
11031133
}
11041134
} finally {
11051135
System.setErr(_err);

0 commit comments

Comments
 (0)