Skip to content

Commit a1cc144

Browse files
committed
started parsing
1 parent 5be60f4 commit a1cc144

File tree

16 files changed

+368
-90
lines changed

16 files changed

+368
-90
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.bc.fiduceo.reader.insitu.ndbc;
2+
3+
class CwRecord {
4+
5+
int utc;
6+
short windDir;
7+
float windSpeed;
8+
short gustDir;
9+
float gustSpeed;
10+
short gustTime;
11+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package com.bc.fiduceo.reader.insitu.ndbc;
2+
3+
import com.bc.fiduceo.core.Dimension;
4+
import com.bc.fiduceo.core.Interval;
5+
import com.bc.fiduceo.geometry.Polygon;
6+
import com.bc.fiduceo.location.PixelLocator;
7+
import com.bc.fiduceo.reader.AcquisitionInfo;
8+
import com.bc.fiduceo.reader.time.TimeLocator;
9+
import org.esa.snap.core.util.StringUtils;
10+
import ucar.ma2.Array;
11+
import ucar.ma2.ArrayInt;
12+
import ucar.ma2.InvalidRangeException;
13+
import ucar.nc2.Variable;
14+
15+
import java.io.File;
16+
import java.io.IOException;
17+
import java.util.Calendar;
18+
import java.util.List;
19+
20+
class NdbcCWReader extends NdbcReader {
21+
22+
private static final String REG_EX_CW = "\\w{5}c\\d{4}.txt";
23+
24+
private static StationDatabase stationDatabase;
25+
26+
27+
NdbcCWReader() {
28+
}
29+
30+
@Override
31+
public void open(File file) throws IOException {
32+
ensureStationDatabase();
33+
}
34+
35+
@Override
36+
public void close() throws IOException {
37+
}
38+
39+
@Override
40+
public AcquisitionInfo read() throws IOException {
41+
final AcquisitionInfo acquisitionInfo = new AcquisitionInfo();
42+
43+
return acquisitionInfo;
44+
}
45+
46+
@Override
47+
public String getRegEx() {
48+
return REG_EX_CW;
49+
}
50+
51+
@Override
52+
public PixelLocator getPixelLocator() throws IOException {
53+
throw new RuntimeException("not implemented");
54+
}
55+
56+
@Override
57+
public PixelLocator getSubScenePixelLocator(Polygon sceneGeometry) throws IOException {
58+
throw new RuntimeException("not implemented");
59+
}
60+
61+
@Override
62+
public TimeLocator getTimeLocator() throws IOException {
63+
throw new RuntimeException("not implemented");
64+
}
65+
66+
@Override
67+
public int[] extractYearMonthDayFromFilename(String fileName) {
68+
throw new RuntimeException("not implemented");
69+
}
70+
71+
@Override
72+
public Array readRaw(int centerX, int centerY, Interval interval, String variableName) throws IOException, InvalidRangeException {
73+
throw new RuntimeException("not implemented");
74+
}
75+
76+
@Override
77+
public Array readScaled(int centerX, int centerY, Interval interval, String variableName) throws IOException, InvalidRangeException {
78+
throw new RuntimeException("not implemented");
79+
}
80+
81+
@Override
82+
public ArrayInt.D2 readAcquisitionTime(int x, int y, Interval interval) throws IOException, InvalidRangeException {
83+
throw new RuntimeException("not implemented");
84+
}
85+
86+
@Override
87+
public List<Variable> getVariables() throws InvalidRangeException, IOException {
88+
throw new RuntimeException("not implemented");
89+
}
90+
91+
@Override
92+
public Dimension getProductSize() throws IOException {
93+
throw new RuntimeException("not implemented");
94+
}
95+
96+
@Override
97+
public String getLongitudeVariableName() {
98+
throw new RuntimeException("not implemented");
99+
}
100+
101+
@Override
102+
public String getLatitudeVariableName() {
103+
throw new RuntimeException("not implemented");
104+
}
105+
106+
private void ensureStationDatabase() throws IOException {
107+
if (stationDatabase == null) {
108+
stationDatabase = parseStationDatabase("buoy_locations_cw.txt");
109+
}
110+
}
111+
112+
public CwRecord parseLine(String line, Calendar calendar) {
113+
final CwRecord cwRecord = new CwRecord();
114+
115+
line = line.replace(" ", " "); // some fields are separated by two blanks (sigh) tb 2023-02-24
116+
final String[] tokens = StringUtils.split(line, new char[]{' '}, true);
117+
118+
calendar.setTimeInMillis(0);
119+
calendar.set(Calendar.YEAR, Integer.parseInt(tokens[0]));
120+
calendar.set(Calendar.MONTH, Integer.parseInt(tokens[1]) - 1);
121+
calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(tokens[2]));
122+
calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(tokens[3]));
123+
calendar.set(Calendar.MINUTE, Integer.parseInt(tokens[4]));
124+
125+
cwRecord.utc = (int) (calendar.getTimeInMillis() * 0.001);
126+
cwRecord.windDir = Short.parseShort(tokens[5]);
127+
cwRecord.windSpeed = Float.parseFloat(tokens[6]);
128+
cwRecord.gustDir = Short.parseShort(tokens[7]);
129+
cwRecord.gustSpeed = Float.parseFloat(tokens[8]);
130+
cwRecord.gustTime = Short.parseShort(tokens[9]);
131+
132+
return cwRecord;
133+
}
134+
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
import com.bc.fiduceo.reader.ReaderContext;
66
import com.bc.fiduceo.reader.ReaderPlugin;
77

8-
import static com.bc.fiduceo.reader.insitu.ndbc.MeasurementType.CONSTANT_WIND;
9-
108
public class NdbcCWReaderPlugin implements ReaderPlugin {
119

12-
private final String[] SUPPORTED_KEYS = {"ndbc-cw"};
10+
private final String[] SUPPORTED_KEYS = {"ndbc-cw-ob", "ndbc-cw-cb", "ndbc-cw-lb", "ndbc-cw-os", "ndbc-cw-cs", "ndbc-cw-ls"};
1311

1412
@Override
1513
public Reader createReader(ReaderContext readerContext) {
16-
return new NdbcInsituReader(CONSTANT_WIND);
14+
return new NdbcCWReader();
1715
}
1816

1917
@Override
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.bc.fiduceo.reader.insitu.ndbc;
2+
3+
import com.bc.fiduceo.reader.Reader;
4+
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
8+
abstract class NdbcReader implements Reader {
9+
10+
StationDatabase parseStationDatabase(String resourceName) throws IOException {
11+
final InputStream is = getClass().getResourceAsStream(resourceName);
12+
if (is == null) {
13+
throw new IllegalStateException("The internal resource file could not be read.");
14+
}
15+
16+
final StationDatabase sdb = new StationDatabase();
17+
sdb.load(is);
18+
19+
is.close();
20+
21+
return sdb;
22+
}
23+
}

core/src/main/java/com/bc/fiduceo/reader/insitu/ndbc/NdbcInsituReader.java renamed to core/src/main/java/com/bc/fiduceo/reader/insitu/ndbc/NdbcSMReader.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,33 @@
55
import com.bc.fiduceo.geometry.Polygon;
66
import com.bc.fiduceo.location.PixelLocator;
77
import com.bc.fiduceo.reader.AcquisitionInfo;
8-
import com.bc.fiduceo.reader.Reader;
98
import com.bc.fiduceo.reader.time.TimeLocator;
10-
import org.esa.snap.core.datamodel.GeoPos;
119
import ucar.ma2.Array;
1210
import ucar.ma2.ArrayInt;
1311
import ucar.ma2.InvalidRangeException;
1412
import ucar.nc2.Variable;
1513

1614
import java.io.File;
1715
import java.io.IOException;
18-
import java.util.HashMap;
1916
import java.util.List;
2017

21-
import static com.bc.fiduceo.reader.insitu.ndbc.MeasurementType.CONSTANT_WIND;
18+
class NdbcSMReader extends NdbcReader {
2219

23-
class NdbcInsituReader implements Reader {
24-
25-
private static final String REG_EX_CW = "\\w{5}c\\d{4}.txt";
2620
private static final String REG_EX_SM = "\\w{5}h\\d{4}.txt";
2721

2822
private static StationDatabase stationDatabase;
2923

30-
private final MeasurementType type;
3124

32-
public NdbcInsituReader(MeasurementType type) {
33-
this.type = type;
25+
NdbcSMReader() {
3426
}
3527

3628
@Override
3729
public void open(File file) throws IOException {
38-
throw new RuntimeException("not implemented");
30+
ensureStationDatabase();
3931
}
4032

4133
@Override
4234
public void close() throws IOException {
43-
throw new RuntimeException("not implemented");
4435
}
4536

4637
@Override
@@ -50,11 +41,7 @@ public AcquisitionInfo read() throws IOException {
5041

5142
@Override
5243
public String getRegEx() {
53-
if (type == CONSTANT_WIND) {
54-
return REG_EX_CW;
55-
} else {
56-
return REG_EX_SM;
57-
}
44+
return REG_EX_SM;
5845
}
5946

6047
@Override
@@ -112,9 +99,9 @@ public String getLatitudeVariableName() {
11299
throw new RuntimeException("not implemented");
113100
}
114101

115-
private void ensureStationDatabase() {
102+
private void ensureStationDatabase() throws IOException {
116103
if (stationDatabase == null) {
117-
104+
stationDatabase = parseStationDatabase("buoy_locations_sm.txt");
118105
}
119106
}
120107
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
import com.bc.fiduceo.reader.ReaderContext;
66
import com.bc.fiduceo.reader.ReaderPlugin;
77

8-
import static com.bc.fiduceo.reader.insitu.ndbc.MeasurementType.STANDARD_METEOROLOGICAL;
9-
108
public class NdbcSMReaderPlugin implements ReaderPlugin {
119

12-
private final String[] SUPPORTED_KEYS = {"ndbc-sm"};
10+
private final String[] SUPPORTED_KEYS = {"ndbc-sm-ob", "ndbc-sm-cb", "ndbc-sm-lb", "ndbc-sm-os", "ndbc-sm-cs", "ndbc-sm-ls"};
1311

1412
@Override
1513
public Reader createReader(ReaderContext readerContext) {
16-
return new NdbcInsituReader(STANDARD_METEOROLOGICAL);
14+
return new NdbcCWReader();
1715
}
1816

1917
@Override

core/src/main/java/com/bc/fiduceo/reader/slstr_subset/NcCache.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ private void parseDDDB() throws IOException {
8181
for (String[] record : recordList) {
8282
dddBMap.put(record[0], record[1]);
8383
}
84+
inputStream.close();
8485
}
8586

8687
List<String> getVariableNames() {

core/src/main/resources/com/bc/fiduceo/reader.nbdc/buoy_locations_cw.txt renamed to core/src/main/resources/com/bc/fiduceo/reader/insitu/ndbc/buoy_locations_cw.txt

File renamed without changes.

core/src/main/resources/com/bc/fiduceo/reader.nbdc/buoy_locations_sm.txt renamed to core/src/main/resources/com/bc/fiduceo/reader/insitu/ndbc/buoy_locations_sm.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,4 +390,13 @@ PSTL1 | 28.932 | -89.407 | COAST_STATION | 20.3 | 2.5
390390
PTAT2 | 27.826 | -97.051 | COAST_STATION | 14.9 | 9.1 | 6.4 | 1.0
391391
PTAW1 | 48.125 | -123.441 | COAST_STATION | 12.2 | 4.6 | 5.5 | 2.9
392392
PTBM6 | 30.213 | -88.505 | COAST_STATION | 4.6 | 2.5 | 1.5 | NaN
393-
PTGC1 | 34.577 | -120.648 | COAST_STATION | 9.4 | 9.1 | 33.5 | NaN
393+
PTGC1 | 34.577 | -120.648 | COAST_STATION | 9.4 | 9.1 | 33.5 | NaN
394+
PTIM4 | 46.485 | -84.631 | LAKE_STATION | 8.9 | 6.6 | 186.5 | NaN
395+
PTRP4 | 18.367 | -67.251 | COAST_STATION | 15.0 | NaN | NaN | NaN
396+
PTWW1 | 48.111 | -122.76 | COAST_STATION | 8.9 | 2.4 | 5.1 | 2.8
397+
PVGF1 | 26.092 | -80.109 | COAST_STATION | 3.5 | 3.5 | 3.5 | 1.65
398+
PWAW3 | 43.388 | -87.867 | LAKE_STATION | 10.0 | 2.1 | 179.8 | NaN
399+
RDDA2 | 67.575 | -164.067 | COAST_STATION | 12.7 | 9.3 | 15.6 | 3.1
400+
RIXA2 | 58.177 | -135.052 | COAST_STATION | 2.7 | 2.7 | 16.5 | NaN
401+
ROAM4 | 47.867 | -89.313 | LAKE_STATION | 46.9 | 46.5 | 222.7 | NaN
402+
SACV4 | 19.174 | -96.093 | COAST_STATION | 9.0 | 9.0 | 0.0 | NaN

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void setUp() {
1919

2020
@Test
2121
public void testGetSupportedSensorKeys() throws Exception {
22-
final String[] expected = {"ndbc-cw"};
22+
final String[] expected = {"ndbc-cw-ob", "ndbc-cw-cb", "ndbc-cw-lb", "ndbc-cw-os", "ndbc-cw-cs", "ndbc-cw-ls"};
2323

2424
final String[] sensorKeys = plugin.getSupportedSensorKeys();
2525
assertArrayEquals(expected, sensorKeys);
@@ -34,6 +34,6 @@ public void testGetDataType() {
3434
public void testCreateReader() {
3535
final Reader reader = plugin.createReader(null);
3636
assertNotNull(reader);
37-
assertTrue(reader instanceof NdbcInsituReader);
37+
assertTrue(reader instanceof NdbcCWReader);
3838
}
3939
}

0 commit comments

Comments
 (0)