Skip to content

Commit aa521e8

Browse files
committed
intermediate, added stations
1 parent ba919f1 commit aa521e8

File tree

5 files changed

+127
-7
lines changed

5 files changed

+127
-7
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ public List<Variable> getVariables() throws InvalidRangeException, IOException {
231231
final ArrayList<Variable> variables = new ArrayList<>();
232232

233233
List<Attribute> attributes = new ArrayList<>();
234+
// station variables
234235
attributes.add(new Attribute(CF_LONG_NAME, "Station identifier"));
235236
variables.add(new VariableProxy(STATION_ID, DataType.STRING, attributes));
236237

@@ -284,7 +285,7 @@ public List<Variable> getVariables() throws InvalidRangeException, IOException {
284285
attributes.add(new Attribute(CF_STANDARD_NAME, "time"));
285286
variables.add(new VariableProxy(TIME, DataType.INT, attributes));
286287

287-
// @todo 1 tb/tb check CF standard names for the measurement data 2023-02027
288+
// measurement record variables
288289
attributes = new ArrayList<>();
289290
attributes.add(new Attribute(CF_UNITS_NAME, "degT"));
290291
attributes.add(new Attribute(CF_FILL_VALUE_NAME, 999));
@@ -355,8 +356,8 @@ CwRecord parseLine(String line, Calendar calendar) {
355356
calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(tokens[2]));
356357
calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(tokens[3]));
357358
calendar.set(Calendar.MINUTE, Integer.parseInt(tokens[4]));
358-
359359
cwRecord.utc = (int) (calendar.getTimeInMillis() * 0.001);
360+
360361
cwRecord.windDir = Short.parseShort(tokens[5]);
361362
cwRecord.windSpeed = Float.parseFloat(tokens[6]);
362363
cwRecord.gustDir = Short.parseShort(tokens[7]);

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
import com.bc.fiduceo.location.PixelLocator;
77
import com.bc.fiduceo.reader.AcquisitionInfo;
88
import com.bc.fiduceo.reader.time.TimeLocator;
9+
import org.esa.snap.core.util.StringUtils;
910
import ucar.ma2.Array;
1011
import ucar.ma2.ArrayInt;
1112
import ucar.ma2.InvalidRangeException;
1213
import ucar.nc2.Variable;
1314

1415
import java.io.File;
1516
import java.io.IOException;
17+
import java.util.ArrayList;
18+
import java.util.Calendar;
1619
import java.util.List;
1720

1821
class NdbcSMReader extends NdbcReader {
@@ -81,7 +84,9 @@ public ArrayInt.D2 readAcquisitionTime(int x, int y, Interval interval) throws I
8184

8285
@Override
8386
public List<Variable> getVariables() throws InvalidRangeException, IOException {
84-
throw new RuntimeException("not implemented");
87+
final ArrayList<Variable> variables = new ArrayList<>();
88+
89+
return variables;
8590
}
8691

8792
@Override
@@ -104,4 +109,35 @@ private void ensureStationDatabase() throws IOException {
104109
stationDatabase = parseStationDatabase("buoy_locations_sm.txt");
105110
}
106111
}
112+
113+
SmRecord parseLine(String line, Calendar calendar) {
114+
final SmRecord record = new SmRecord();
115+
116+
line = line.replaceAll(" +", " "); // some fields are separated by two or more blanks (sigh) tb 2023-02-27
117+
final String[] tokens = StringUtils.split(line, new char[]{' '}, true);
118+
119+
calendar.setTimeInMillis(0);
120+
calendar.set(Calendar.YEAR, Integer.parseInt(tokens[0]));
121+
calendar.set(Calendar.MONTH, Integer.parseInt(tokens[1]) - 1); // calendar wants month zero-based tb 2023-02-27
122+
calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(tokens[2]));
123+
calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(tokens[3]));
124+
calendar.set(Calendar.MINUTE, Integer.parseInt(tokens[4]));
125+
record.utc = (int) (calendar.getTimeInMillis() * 0.001);
126+
127+
record.windDir = Short.parseShort(tokens[5]);
128+
record.windSpeed = Float.parseFloat(tokens[6]);
129+
record.gustSpeed = Float.parseFloat(tokens[7]);
130+
record.waveHeight = Float.parseFloat(tokens[8]);
131+
record.domWavePeriod = Float.parseFloat(tokens[9]);
132+
record.avgWavePeriod = Float.parseFloat(tokens[10]);
133+
record.waveDir = Short.parseShort(tokens[11]);
134+
record.seaLevelPressure = Float.parseFloat(tokens[12]);
135+
record.airTemp = Float.parseFloat(tokens[13]);
136+
record.seaSurfTemp = Float.parseFloat(tokens[14]);
137+
record.dewPointTemp = Float.parseFloat(tokens[15]);
138+
record.visibility = Float.parseFloat(tokens[16]);
139+
record.tideLevel = Float.parseFloat(tokens[17]);
140+
141+
return record;
142+
}
107143
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,17 @@
33
class SmRecord {
44

55
int utc;
6-
6+
short windDir;
7+
float windSpeed;
8+
float gustSpeed;
9+
float waveHeight;
10+
float domWavePeriod;
11+
float avgWavePeriod;
12+
short waveDir;
13+
float seaLevelPressure;
14+
float airTemp;
15+
float seaSurfTemp;
16+
float dewPointTemp;
17+
float visibility;
18+
float tideLevel;
719
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,4 +417,11 @@ SJSN4 | 39.305 | -75.377 | COAST_STATION | 14.8 | 3.0
417417
SMKF1 | 24.628 | -81.109 | OCEAN_STATION | 7.2 | 7.0 | 6.0 | NaN
418418
SPGF1 | 26.704 | -78.995 | COAST_STATION | 6.6 | 6.1 | 2.7 | NaN
419419
SPLL1 | 26.704 | -78.995 | OCEAN_STATION | 10.0 | 10.0 | 3.0 | 1.0
420-
SRLM4 | 45.773 | -84.137 | LAKE_STATION | 30.0 | NaN | NaN | NaN
420+
SRLM4 | 45.773 | -84.137 | LAKE_STATION | 30.0 | NaN | NaN | NaN
421+
STDM4 | 47.184 | -87.225 | LAKE_STATION | 35.2 | 35.2 | 211.2 | NaN
422+
STXA2 | 57.116 | -135.391 | COAST_STATION | 9.4 | 9.4 | 20.1 | NaN
423+
SVNM4 | 42.401 | -86.288 | LAKE_STATION | 16.8 | 13.7 | NaN | NaN
424+
SXHW3 | 46.563 | -90.437 | LAKE_STATION | 10.0 | 2.7 | 187.0 | NaN
425+
TAWM4 | 44.254 | -83.449 | LAKE_STATION | 10.0 | 1.8 | 185.3 | NaN
426+
TBIM4 | 44.254 | -83.449 | LAKE_STATION | 10.7 | 6.1 | NaN | NaN
427+
THLO1 | 41.826 | -83.194 | LAKE_STATION | 14.9 | 14.0 | NaN | NaN

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

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

3+
import com.bc.fiduceo.util.TimeUtils;
4+
import org.junit.Before;
35
import org.junit.Test;
6+
import ucar.ma2.DataType;
7+
import ucar.ma2.InvalidRangeException;
8+
import ucar.nc2.Variable;
49

10+
import java.io.IOException;
11+
import java.util.Calendar;
12+
import java.util.List;
513
import java.util.regex.Matcher;
614
import java.util.regex.Pattern;
715

@@ -10,12 +18,18 @@
1018
@SuppressWarnings("resource")
1119
public class NdbcSMReaderTest {
1220

21+
private NdbcSMReader reader;
22+
23+
@Before
24+
public void setUp() {
25+
reader = new NdbcSMReader();
26+
}
27+
1328
@Test
1429
public void testGetRegEx() {
15-
final NdbcSMReader insituReader = new NdbcSMReader();
1630
final String expected = "\\w{5}h\\d{4}.txt";
1731

18-
assertEquals(expected, insituReader.getRegEx());
32+
assertEquals(expected, reader.getRegEx());
1933
final Pattern pattern = Pattern.compile(expected);
2034

2135
Matcher matcher = pattern.matcher("41009h2016.txt");
@@ -30,4 +44,54 @@ public void testGetRegEx() {
3044
matcher = pattern.matcher("insitu_2_WMOID_DBBH_19780118_20151025.nc");
3145
assertFalse(matcher.matches());
3246
}
47+
48+
@Test
49+
public void testParseLine() {
50+
final Calendar calendar = TimeUtils.getUTCCalendar();
51+
52+
String line = "2018 05 19 01 36 80 7.3 8.6 99.00 99.00 99.00 999 1017.1 13.6 999.0 10.8 99.0 99.00\n";
53+
54+
SmRecord record = reader.parseLine(line, calendar);
55+
assertEquals(1526693760, record.utc);
56+
assertEquals(80, record.windDir);
57+
assertEquals(7.3f, record.windSpeed, 1e-8);
58+
assertEquals(8.6f, record.gustSpeed, 1e-8);
59+
assertEquals(99.f, record.waveHeight, 1e-8);
60+
assertEquals(99.f, record.domWavePeriod, 1e-8);
61+
assertEquals(99.f, record.avgWavePeriod, 1e-8);
62+
assertEquals(999, record.waveDir);
63+
assertEquals(1017.1f, record.seaLevelPressure, 1e-8);
64+
assertEquals(13.6f, record.airTemp, 1e-8);
65+
assertEquals(999.f, record.seaSurfTemp, 1e-8);
66+
assertEquals(10.8f, record.dewPointTemp, 1e-8);
67+
assertEquals(99.f, record.visibility, 1e-8);
68+
assertEquals(99.f, record.tideLevel, 1e-8);
69+
70+
71+
line = "2018 09 06 12 20 23 4.8 6.0 99.00 99.00 99.00 999 9999.0 999.0 999.0 999.0 99.0 99.00\n";
72+
record = reader.parseLine(line, calendar);
73+
assertEquals(1536236400, record.utc);
74+
assertEquals(23, record.windDir);
75+
assertEquals(4.8f, record.windSpeed, 1e-8);
76+
assertEquals(6.f, record.gustSpeed, 1e-8);
77+
assertEquals(99.f, record.waveHeight, 1e-8);
78+
assertEquals(99.f, record.domWavePeriod, 1e-8);
79+
assertEquals(99.f, record.avgWavePeriod, 1e-8);
80+
assertEquals(999, record.waveDir);
81+
assertEquals(9999.f, record.seaLevelPressure, 1e-8);
82+
assertEquals(999.f, record.airTemp, 1e-8);
83+
assertEquals(999.f, record.seaSurfTemp, 1e-8);
84+
assertEquals(999.f, record.dewPointTemp, 1e-8);
85+
assertEquals(99.f, record.visibility, 1e-8);
86+
assertEquals(99.f, record.tideLevel, 1e-8);
87+
}
88+
89+
@Test
90+
public void testGetVariables() throws InvalidRangeException, IOException {
91+
final List<Variable> variables = reader.getVariables();
92+
93+
assertEquals(0, variables.size());
94+
// @todo 1 tb/tb continue here 2023-02-28
95+
96+
}
3397
}

0 commit comments

Comments
 (0)