Skip to content

Commit 5be60f4

Browse files
committed
added station database
1 parent ffe122f commit 5be60f4

File tree

6 files changed

+207
-13
lines changed

6 files changed

+207
-13
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ class NdbcInsituReader implements Reader {
2525
private static final String REG_EX_CW = "\\w{5}c\\d{4}.txt";
2626
private static final String REG_EX_SM = "\\w{5}h\\d{4}.txt";
2727

28-
private final HashMap<String, GeoPos> buoyLocations;
28+
private static StationDatabase stationDatabase;
29+
2930
private final MeasurementType type;
3031

3132
public NdbcInsituReader(MeasurementType type) {
3233
this.type = type;
33-
this.buoyLocations = new HashMap<>();
3434
}
3535

3636
@Override
@@ -111,4 +111,10 @@ public String getLongitudeVariableName() {
111111
public String getLatitudeVariableName() {
112112
throw new RuntimeException("not implemented");
113113
}
114+
115+
private void ensureStationDatabase() {
116+
if (stationDatabase == null) {
117+
118+
}
119+
}
114120
}

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

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,88 @@
33
class Station {
44

55
private final String id;
6+
private final MeasurementType measurementType;
67
private float lon;
78
private float lat;
89
private float anHeight;
10+
private float airTempHeight;
11+
private float barHeight;
12+
private float sstDepth;
913
private StationType type;
1014

11-
Station(String id) {
15+
public Station(String id, MeasurementType measurementType) {
1216
this.id = id;
17+
this.measurementType = measurementType;
1318

1419
lon = Float.NaN;
1520
lat = Float.NaN;
1621
anHeight = Float.NaN;
22+
airTempHeight = Float.NaN;
23+
barHeight = Float.NaN;
24+
sstDepth = Float.NaN;
1725
}
1826

1927
String getId() {
2028
return id;
2129
}
2230

23-
float getLon() {
31+
float getLon() {
2432
return lon;
2533
}
2634

27-
float getLat() {
35+
void setLon(float lon) {
36+
this.lon = lon;
37+
}
38+
39+
float getLat() {
2840
return lat;
2941
}
3042

31-
public StationType getType() {
43+
void setLat(float lat) {
44+
this.lat = lat;
45+
}
46+
47+
StationType getType() {
3248
return type;
3349
}
3450

35-
public float getAnemometerHeight() {
51+
void setType(StationType stationType) {
52+
this.type = stationType;
53+
}
54+
55+
float getAnemometerHeight() {
3656
return anHeight;
3757
}
58+
59+
void setAnemometerHeight(float anHeight) {
60+
this.anHeight = anHeight;
61+
}
62+
63+
float getAirTemperatureHeight() {
64+
return airTempHeight;
65+
}
66+
67+
void setAirTemperatureHeight(float airTempHeight) {
68+
this.airTempHeight = airTempHeight;
69+
}
70+
71+
float getBarometerHeight() {
72+
return barHeight;
73+
}
74+
75+
void setBarometerHeight(float barHeight) {
76+
this.barHeight = barHeight;
77+
}
78+
79+
float getSSTDepth() {
80+
return sstDepth;
81+
}
82+
83+
void setSSTDepth(float sstDepth) {
84+
this.sstDepth = sstDepth;
85+
}
86+
87+
MeasurementType getMeasurementType() {
88+
return measurementType;
89+
}
3890
}

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import java.util.ArrayList;
1010
import java.util.HashMap;
1111

12+
import static com.bc.fiduceo.reader.insitu.ndbc.MeasurementType.CONSTANT_WIND;
13+
import static com.bc.fiduceo.reader.insitu.ndbc.MeasurementType.STANDARD_METEOROLOGICAL;
14+
1215
class StationDatabase {
1316

1417
private static final int CW_STATION_TOKENS = 5;
@@ -36,11 +39,41 @@ void load(InputStream inputStream) throws IOException {
3639
}
3740

3841
private void parseSmStations(ArrayList<String> lineList) {
42+
for (final String line : lineList) {
43+
final String[] tokens = StringUtils.split(line, new char[]{'|'}, true);
44+
final String stationId = tokens[0];
45+
46+
final Station station = new Station(stationId, STANDARD_METEOROLOGICAL);
47+
parseBasicProperties(tokens, station);
48+
49+
station.setAirTemperatureHeight(Float.parseFloat(tokens[5]));
50+
station.setBarometerHeight(Float.parseFloat(tokens[6]));
51+
station.setSSTDepth(Float.parseFloat(tokens[7]));
3952

53+
stationMap.put(stationId, station);
54+
}
4055
}
4156

4257
private void parseCwStation(ArrayList<String> lineList) {
58+
for (final String line : lineList) {
59+
final String[] tokens = StringUtils.split(line, new char[]{'|'}, true);
60+
final String stationId = tokens[0];
61+
62+
final Station station = new Station(stationId, CONSTANT_WIND);
63+
parseBasicProperties(tokens, station);
64+
65+
stationMap.put(tokens[0], station);
66+
}
67+
}
68+
69+
private static void parseBasicProperties(String[] tokens, Station station) {
70+
station.setLat(Float.parseFloat(tokens[1]));
71+
station.setLon(Float.parseFloat(tokens[2]));
72+
73+
final StationType stationType = StationType.valueOf(tokens[3]);
74+
station.setType(stationType);
4375

76+
station.setAnemometerHeight(Float.parseFloat(tokens[4]));
4477
}
4578

4679
private static ArrayList<String> readInputLines(InputStream inputStream) throws IOException {
@@ -58,6 +91,6 @@ private static ArrayList<String> readInputLines(InputStream inputStream) throws
5891
}
5992

6093
Station get(String id) {
61-
return new Station(id);
94+
return stationMap.get(id);
6295
}
6396
}

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,4 +379,15 @@ PILA2 | 59.742 | -149.47 | COAST_STATION | 6.6 | 6.4
379379
PILM4 | 48.223 | -88.366 | LAKE_STATION | 15.5 | 9.8 | 230.4 | NaN
380380
PLSF1 | 24.693 | -82.773 | OCEAN_STATION | 17.7 | 17.4 | 15.8 | 1.5
381381
PLXA2 | 56.247 | -134.647 | COAST_STATION | 8.5 | 7.9 | 5.6 | 4.0
382-
PMOA2 | 55.99 | -160.562 | COAST_STATION | 13.2 | 7.3 | 5.4 | 1.9
382+
PMOA2 | 55.99 | -160.562 | COAST_STATION | 13.2 | 7.3 | 5.4 | 1.9
383+
PNGW3 | 46.792 | -91.386 | LAKE_STATION | 10.0 | 3.0 | 185.9 | NaN
384+
PNLM4 | 45.968 | -85.869 | LAKE_STATION | 10.3 | 6.5 | 180.2 | 4.6
385+
PORO3 | 42.739 | -124.498 | COAST_STATION | 9.1 | 8.7 | 8.0 | 1.3
386+
PRDA2 | 70.4 | -148.527 | COAST_STATION | NaN | 23.68 | 4.8 | 3.3
387+
PSCM4 | 43.42 | -82.54 | LAKE_STATION | 10.0 | 3.3 | 191.8 | NaN
388+
PSLC1 | 35.169 | -120.754 | COAST_STATION | 13.6 | 12.7 | 11.6 | 3.5
389+
PSTL1 | 28.932 | -89.407 | COAST_STATION | 20.3 | 2.5 | 4.7 | 5.7
390+
PTAT2 | 27.826 | -97.051 | COAST_STATION | 14.9 | 9.1 | 6.4 | 1.0
391+
PTAW1 | 48.125 | -123.441 | COAST_STATION | 12.2 | 4.6 | 5.5 | 2.9
392+
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

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

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import java.io.ByteArrayInputStream;
66
import java.io.IOException;
77

8+
import static com.bc.fiduceo.reader.insitu.ndbc.MeasurementType.CONSTANT_WIND;
9+
import static com.bc.fiduceo.reader.insitu.ndbc.MeasurementType.STANDARD_METEOROLOGICAL;
10+
import static com.bc.fiduceo.reader.insitu.ndbc.StationType.COAST_STATION;
11+
import static com.bc.fiduceo.reader.insitu.ndbc.StationType.OCEAN_BUOY;
812
import static org.junit.Assert.assertEquals;
913

1014
public class StationDatabaseTest {
@@ -24,10 +28,44 @@ public void testLoadAndGet_CW() throws IOException {
2428

2529
Station station = stationDatabase.get("41002");
2630
assertEquals("41002", station.getId());
27-
// @todo 1 tb/tb continue here 2023-02-22
28-
//assertEquals(31.759f, station.getLat(), 1e-8);
31+
assertEquals(31.759f, station.getLat(), 1e-8);
32+
assertEquals(-74.936f, station.getLon(), 1e-8);
33+
assertEquals(OCEAN_BUOY, station.getType());
34+
assertEquals(CONSTANT_WIND, station.getMeasurementType());
35+
assertEquals(4.1f, station.getAnemometerHeight(), 1e-8);
2936

3037
station = stationDatabase.get("41004");
3138
assertEquals("41004", station.getId());
39+
assertEquals(32.502f, station.getLat(), 1e-8);
40+
assertEquals(-79.099f, station.getLon(), 1e-8);
41+
assertEquals(OCEAN_BUOY, station.getType());
42+
assertEquals(CONSTANT_WIND, station.getMeasurementType());
43+
assertEquals(4.1f, station.getAnemometerHeight(), 1e-8);
44+
}
45+
46+
@Test
47+
public void testLoadANdGet_SM() throws IOException {
48+
final String resourceFile = "AAMC1 | 37.772 | -122.3 | COAST_STATION | 6.9 | 4.3 | 5.3 | 1.2\n" +
49+
"ADKA2 | 51.861 | -176.637 | COAST_STATION | 7.0 | 6.3 | 7.0 | 2.8\n" +
50+
"AGMW3 | 44.608 | -87.433 | LAKE_STATION | 9.0 | 9.0 | NaN | NaN\n" +
51+
"AGXC1 | 33.716 | -118.246 | COAST_STATION | 20.0 | NaN | NaN | NaN\n" +
52+
"AJXA2 | 58.287 | -134.398 | COAST_STATION | 3.0 | 3.0 | 7.6 | NaN\n" +
53+
"ALIA2 | 56.898 | -154.247 | COAST_STATION | 10.3 | 9.7 | 6.5 | 2.2";
54+
55+
final ByteArrayInputStream inputStream = new ByteArrayInputStream(resourceFile.getBytes());
56+
57+
final StationDatabase stationDatabase = new StationDatabase();
58+
stationDatabase.load(inputStream);
59+
60+
Station station = stationDatabase.get("ADKA2");
61+
assertEquals("ADKA2", station.getId());
62+
assertEquals(51.861f, station.getLat(), 1e-8);
63+
assertEquals(-176.637f, station.getLon(), 1e-8);
64+
assertEquals(COAST_STATION, station.getType());
65+
assertEquals(STANDARD_METEOROLOGICAL, station.getMeasurementType());
66+
assertEquals(7.0f, station.getAnemometerHeight(), 1e-8);
67+
assertEquals(6.3f, station.getAirTemperatureHeight(), 1e-8);
68+
assertEquals(7.0f, station.getBarometerHeight(), 1e-8);
69+
assertEquals(2.8f, station.getSSTDepth(), 1e-8);
3270
}
3371
}
Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,74 @@
11
package com.bc.fiduceo.reader.insitu.ndbc;
22

3+
import org.junit.Before;
34
import org.junit.Test;
45

6+
import static com.bc.fiduceo.reader.insitu.ndbc.MeasurementType.STANDARD_METEOROLOGICAL;
7+
import static com.bc.fiduceo.reader.insitu.ndbc.StationType.OCEAN_STATION;
58
import static org.junit.Assert.assertEquals;
69
import static org.junit.Assert.assertNull;
710

811
public class StationTest {
912

13+
private Station station;
14+
15+
@Before
16+
public void setUp() {
17+
station = new Station("abgdzt", STANDARD_METEOROLOGICAL);
18+
}
19+
1020
@Test
1121
public void testConstruction() {
12-
final Station station = new Station("abgdzt");
13-
1422
assertEquals("abgdzt", station.getId());
1523
assertEquals(Float.NaN, station.getLon(), 1e-8);
1624
assertEquals(Float.NaN, station.getLat(), 1e-8);
1725
assertNull(station.getType());
26+
assertEquals(STANDARD_METEOROLOGICAL, station.getMeasurementType());
1827
assertEquals(Float.NaN, station.getAnemometerHeight(), 1e-8);
28+
assertEquals(Float.NaN, station.getAirTemperatureHeight(), 1e-8);
29+
assertEquals(Float.NaN, station.getBarometerHeight(), 1e-8);
30+
assertEquals(Float.NaN, station.getSSTDepth(), 1e-8);
31+
}
32+
33+
@Test
34+
public void testSetGetLat() {
35+
station.setLat(23.56f);
36+
assertEquals(23.56f, station.getLat(), 1e-8);
37+
}
38+
39+
@Test
40+
public void testSetGetLon() {
41+
station.setLon(34.56f);
42+
assertEquals(34.56f, station.getLon(), 1e-8);
43+
}
44+
45+
@Test
46+
public void testSetGetType() {
47+
station.setType(OCEAN_STATION);
48+
assertEquals(OCEAN_STATION, station.getType());
49+
}
50+
51+
@Test
52+
public void testSetGetAnemometerHeight() {
53+
station.setAnemometerHeight(2.8f);
54+
assertEquals(2.8f, station.getAnemometerHeight(), 1e-8);
55+
}
56+
57+
@Test
58+
public void testSetGetAirTemperatureHeight() {
59+
station.setAirTemperatureHeight(3.9f);
60+
assertEquals(3.9f, station.getAirTemperatureHeight(), 1e-8);
61+
}
62+
63+
@Test
64+
public void testSetGetBarometerHeight() {
65+
station.setBarometerHeight(4.0f);
66+
assertEquals(4.0f, station.getBarometerHeight(), 1e-8);
67+
}
68+
69+
@Test
70+
public void testSetGetSSTDepth() {
71+
station.setSSTDepth(5.1f);
72+
assertEquals(5.1f, station.getSSTDepth(), 1e-8);
1973
}
2074
}

0 commit comments

Comments
 (0)