Skip to content

Commit ba919f1

Browse files
committed
done CW reader
1 parent a5e3ffc commit ba919f1

File tree

3 files changed

+78
-17
lines changed

3 files changed

+78
-17
lines changed

core/src/main/java/com/bc/fiduceo/reader/insitu/ndbc/NdbcCWReader.java

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,29 @@
3333

3434
class NdbcCWReader extends NdbcReader {
3535

36-
public static final String GST = "GST";
37-
public static final String MEASUREMENT_TYPE = "measurement_type";
38-
public static final String ANEMOMETER_HEIGHT = "anemometer_height";
39-
public static final String SST_DEPTH = "sst_depth";
40-
public static final String WSPD = "WSPD";
41-
public static final String GTIME = "GTIME";
36+
private static final String GST = "GST";
37+
private static final String MEASUREMENT_TYPE = "measurement_type";
38+
private static final String ANEMOMETER_HEIGHT = "anemometer_height";
39+
private static final String SST_DEPTH = "sst_depth";
40+
private static final String WSPD = "WSPD";
41+
private static final String GTIME = "GTIME";
4242
private static final String REG_EX_CW = "\\w{5}c\\d{4}.txt";
4343
private static final String STATION_ID = "station_id";
4444
private static final String STATION_TYPE = "station_type";
45+
private static final String LONGITUDE = "longitude";
4546
private static final String LATITUDE = "latitude";
4647
private static final String BAROMETER_HEIGHT = "barometer_height";
4748
private static final String WDIR = "WDIR";
48-
public static final String LONGITUDE = "longitude";
49-
public static final String AIR_TEMP_HEIGHT = "air_temp_height";
50-
public static final String TIME = "time";
51-
public static final String GDR = "GDR";
49+
private static final String AIR_TEMP_HEIGHT = "air_temp_height";
50+
private static final String TIME = "time";
51+
private static final String GDR = "GDR";
52+
5253
private static StationDatabase stationDatabase;
5354

5455
private ArrayList<CwRecord> records;
5556
private TimeLocator timeLocator;
5657
private Station station;
5758

58-
NdbcCWReader() {
59-
}
60-
6159
@Override
6260
public void open(File file) throws IOException {
6361
ensureStationDatabase();
@@ -163,7 +161,13 @@ private void createTimeLocator() {
163161

164162
@Override
165163
public int[] extractYearMonthDayFromFilename(String fileName) {
166-
throw new RuntimeException("not implemented");
164+
int[] ymd = new int[3];
165+
final int dotIndex = fileName.indexOf('.');
166+
final String yearString = fileName.substring(dotIndex - 4, dotIndex);
167+
ymd[0] = Integer.parseInt(yearString);
168+
ymd[1] = 1;
169+
ymd[2] = 1;
170+
return ymd;
167171
}
168172

169173
@Override
@@ -217,7 +221,9 @@ public Array readScaled(int centerX, int centerY, Interval interval, String vari
217221

218222
@Override
219223
public ArrayInt.D2 readAcquisitionTime(int x, int y, Interval interval) throws IOException, InvalidRangeException {
220-
throw new RuntimeException("not implemented");
224+
final Array timeArray = readRaw(x, y, interval, TIME);
225+
226+
return (ArrayInt.D2) timeArray;
221227
}
222228

223229
@Override
@@ -282,24 +288,28 @@ public List<Variable> getVariables() throws InvalidRangeException, IOException {
282288
attributes = new ArrayList<>();
283289
attributes.add(new Attribute(CF_UNITS_NAME, "degT"));
284290
attributes.add(new Attribute(CF_FILL_VALUE_NAME, 999));
291+
attributes.add(new Attribute(CF_STANDARD_NAME, "wind_from_direction"));
285292
attributes.add(new Attribute(CF_LONG_NAME, "Ten-minute average wind direction measurements in degrees clockwise from true North."));
286293
variables.add(new VariableProxy(WDIR, DataType.SHORT, attributes));
287294

288295
attributes = new ArrayList<>();
289296
attributes.add(new Attribute(CF_UNITS_NAME, "m/s"));
290297
attributes.add(new Attribute(CF_FILL_VALUE_NAME, 99.f));
298+
attributes.add(new Attribute(CF_STANDARD_NAME, "wind_speed"));
291299
attributes.add(new Attribute(CF_LONG_NAME, "Ten-minute average wind speed values in m/s."));
292300
variables.add(new VariableProxy(WSPD, DataType.FLOAT, attributes));
293301

294302
attributes = new ArrayList<>();
295303
attributes.add(new Attribute(CF_UNITS_NAME, "degT"));
296304
attributes.add(new Attribute(CF_FILL_VALUE_NAME, 999));
305+
attributes.add(new Attribute(CF_STANDARD_NAME, "wind_gust_from_direction"));
297306
attributes.add(new Attribute(CF_LONG_NAME, "Direction, in degrees clockwise from true North, of the GST, reported at the last hourly 10-minute segment."));
298307
variables.add(new VariableProxy(GDR, DataType.SHORT, attributes));
299308

300309
attributes = new ArrayList<>();
301310
attributes.add(new Attribute(CF_UNITS_NAME, "m/s"));
302311
attributes.add(new Attribute(CF_FILL_VALUE_NAME, 99.f));
312+
attributes.add(new Attribute(CF_STANDARD_NAME, "wind_gust_speed"));
303313
attributes.add(new Attribute(CF_LONG_NAME, "Maximum 5-second peak gust during the measurement hour, reported at the last hourly 10-minute segment."));
304314
variables.add(new VariableProxy(GST, DataType.FLOAT, attributes));
305315

@@ -319,12 +329,12 @@ public Dimension getProductSize() throws IOException {
319329

320330
@Override
321331
public String getLongitudeVariableName() {
322-
throw new RuntimeException("not implemented");
332+
return LONGITUDE;
323333
}
324334

325335
@Override
326336
public String getLatitudeVariableName() {
327-
throw new RuntimeException("not implemented");
337+
return LATITUDE;
328338
}
329339

330340
private void ensureStationDatabase() throws IOException {

core/src/test/java/com/bc/fiduceo/reader/insitu/ndbc/NdbcCWReaderTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,23 @@ public void testGetVariables() throws InvalidRangeException, IOException {
9595
assertEquals("GDR", variable.getShortName());
9696
assertEquals(DataType.SHORT, variable.getDataType());
9797
}
98+
99+
@Test
100+
public void testExtractYearMonthDayFromFilename() {
101+
int[] ymd = reader.extractYearMonthDayFromFilename("45008c2018.txt");
102+
assertEquals(3, ymd.length);
103+
assertEquals(2018, ymd[0]);
104+
assertEquals(1, ymd[1]);
105+
assertEquals(1, ymd[2]);
106+
}
107+
108+
@Test
109+
public void testGetLongitudeVariableName() {
110+
assertEquals("longitude", reader.getLongitudeVariableName());
111+
}
112+
113+
@Test
114+
public void testGetLatitudeVariableName() {
115+
assertEquals("latitude", reader.getLatitudeVariableName());
116+
}
98117
}

core/src/test/java/com/bc/fiduceo/reader/insitu/ndbc/NdbcCWReader_IO_Test.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.bc.fiduceo.reader.insitu.ndbc;
22

33
import com.bc.fiduceo.IOTestRunner;
4+
import com.bc.fiduceo.NCTestUtils;
45
import com.bc.fiduceo.TestUtil;
56
import com.bc.fiduceo.core.Dimension;
67
import com.bc.fiduceo.core.Interval;
@@ -13,6 +14,7 @@
1314
import org.junit.Test;
1415
import org.junit.runner.RunWith;
1516
import ucar.ma2.Array;
17+
import ucar.ma2.ArrayInt;
1618
import ucar.ma2.DataType;
1719
import ucar.ma2.InvalidRangeException;
1820

@@ -303,6 +305,36 @@ public void testReadRaw_String() throws IOException, InvalidRangeException {
303305
}
304306
}
305307

308+
@Test
309+
public void testReadAcquisitionTime_1x1_lakeBouy() throws IOException, InvalidRangeException {
310+
final File testFile = getLAKE_BUOY();
311+
312+
try {
313+
reader.open(testFile);
314+
315+
final ArrayInt.D2 acquisitionTime = reader.readAcquisitionTime(13, 35, new Interval(1, 1));
316+
NCTestUtils.assertValueAt(1493999400, 0, 0, acquisitionTime);
317+
} finally {
318+
reader.close();
319+
}
320+
}
321+
322+
@Test
323+
public void testReadAcquisitionTime_3x1_oceanBuoy() throws IOException, InvalidRangeException {
324+
final File testFile = getOCEAN_BUOY();
325+
326+
try {
327+
reader.open(testFile);
328+
329+
final ArrayInt.D2 acquisitionTime = reader.readAcquisitionTime(14, 36, new Interval(3, 1));
330+
NCTestUtils.assertValueAt(-2147483647, 0, 0, acquisitionTime);
331+
NCTestUtils.assertValueAt(1464757200, 1, 0, acquisitionTime);
332+
NCTestUtils.assertValueAt(-2147483647, 2, 0, acquisitionTime);
333+
} finally {
334+
reader.close();
335+
}
336+
}
337+
306338
private static File getOCEAN_BUOY() throws IOException {
307339
final String relativePath = TestUtil.assembleFileSystemPath(new String[]{"insitu", "ndbc", "ndbc-cw-ob", "v1", "2016", "42002c2016.txt"}, false);
308340
return TestUtil.getTestDataFileAsserted(relativePath);

0 commit comments

Comments
 (0)