Skip to content

Commit bd9a789

Browse files
committed
read variables, finished stations
1 parent aa521e8 commit bd9a789

File tree

8 files changed

+294
-120
lines changed

8 files changed

+294
-120
lines changed

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

Lines changed: 7 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,9 @@
3333

3434
class NdbcCWReader extends NdbcReader {
3535

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";
4136
private static final String GTIME = "GTIME";
4237
private static final String REG_EX_CW = "\\w{5}c\\d{4}.txt";
43-
private static final String STATION_ID = "station_id";
44-
private static final String STATION_TYPE = "station_type";
45-
private static final String LONGITUDE = "longitude";
46-
private static final String LATITUDE = "latitude";
47-
private static final String BAROMETER_HEIGHT = "barometer_height";
48-
private static final String WDIR = "WDIR";
49-
private static final String AIR_TEMP_HEIGHT = "air_temp_height";
50-
private static final String TIME = "time";
38+
5139
private static final String GDR = "GDR";
5240

5341
private static StationDatabase stationDatabase;
@@ -191,12 +179,6 @@ public Array readRaw(int centerX, int centerY, Interval interval, String variabl
191179
return createResultArray(station.getLat(), Float.NaN, DataType.FLOAT, interval);
192180
case ANEMOMETER_HEIGHT:
193181
return createResultArray(station.getAnemometerHeight(), Float.NaN, DataType.FLOAT, interval);
194-
case AIR_TEMP_HEIGHT:
195-
return createResultArray(station.getAirTemperatureHeight(), Float.NaN, DataType.FLOAT, interval);
196-
case BAROMETER_HEIGHT:
197-
return createResultArray(station.getBarometerHeight(), Float.NaN, DataType.FLOAT, interval);
198-
case SST_DEPTH:
199-
return createResultArray(station.getSSTDepth(), Float.NaN, DataType.FLOAT, interval);
200182
case TIME:
201183
return createResultArray(record.utc, NetCDFUtils.getDefaultFillValue(int.class), DataType.INT, interval);
202184
case WDIR:
@@ -231,74 +213,13 @@ public List<Variable> getVariables() throws InvalidRangeException, IOException {
231213
final ArrayList<Variable> variables = new ArrayList<>();
232214

233215
List<Attribute> attributes = new ArrayList<>();
234-
// station variables
235-
attributes.add(new Attribute(CF_LONG_NAME, "Station identifier"));
236-
variables.add(new VariableProxy(STATION_ID, DataType.STRING, attributes));
237-
238-
attributes = new ArrayList<>();
239-
attributes.add(new Attribute(CF_LONG_NAME, "Station type. 0: OCEAN_BUOY, 1: COAST_BUOY, 2: LAKE_BUOY, 3: OCEAN_STATION, 4: COAST_STATION, 5: LAKE_STATION"));
240-
variables.add(new VariableProxy(STATION_TYPE, DataType.BYTE, attributes));
241-
242-
attributes = new ArrayList<>();
243-
attributes.add(new Attribute(CF_LONG_NAME, "Measurement type. 0: CONSTANT_WIND, 1: STANDARD_METEOROLOGICAL"));
244-
variables.add(new VariableProxy(MEASUREMENT_TYPE, DataType.BYTE, attributes));
245-
246-
attributes = new ArrayList<>();
247-
attributes.add(new Attribute(CF_UNITS_NAME, "degree_east"));
248-
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
249-
attributes.add(new Attribute(CF_STANDARD_NAME, "longitude"));
250-
variables.add(new VariableProxy(LONGITUDE, DataType.FLOAT, attributes));
251-
252-
attributes = new ArrayList<>();
253-
attributes.add(new Attribute(CF_UNITS_NAME, "degree_north"));
254-
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
255-
attributes.add(new Attribute(CF_STANDARD_NAME, "latitude"));
256-
variables.add(new VariableProxy(LATITUDE, DataType.FLOAT, attributes));
257-
258-
attributes = new ArrayList<>();
259-
attributes.add(new Attribute(CF_UNITS_NAME, "m"));
260-
attributes.add(new Attribute(CF_FILL_VALUE_NAME, Float.NaN));
261-
attributes.add(new Attribute(CF_LONG_NAME, "Height of instrument above site elevation"));
262-
variables.add(new VariableProxy(ANEMOMETER_HEIGHT, DataType.FLOAT, attributes));
263-
264-
attributes = new ArrayList<>();
265-
attributes.add(new Attribute(CF_UNITS_NAME, "m"));
266-
attributes.add(new Attribute(CF_FILL_VALUE_NAME, Float.NaN));
267-
attributes.add(new Attribute(CF_LONG_NAME, "Height of instrument above site elevation"));
268-
variables.add(new VariableProxy(AIR_TEMP_HEIGHT, DataType.FLOAT, attributes));
269-
270-
attributes = new ArrayList<>();
271-
attributes.add(new Attribute(CF_UNITS_NAME, "m"));
272-
attributes.add(new Attribute(CF_FILL_VALUE_NAME, Float.NaN));
273-
attributes.add(new Attribute(CF_LONG_NAME, "Height of instrument above above mean sea level"));
274-
variables.add(new VariableProxy(BAROMETER_HEIGHT, DataType.FLOAT, attributes));
275-
276-
attributes = new ArrayList<>();
277-
attributes.add(new Attribute(CF_UNITS_NAME, "m"));
278-
attributes.add(new Attribute(CF_FILL_VALUE_NAME, Float.NaN));
279-
attributes.add(new Attribute(CF_LONG_NAME, "Depth of instrument below water line"));
280-
variables.add(new VariableProxy(SST_DEPTH, DataType.FLOAT, attributes));
281-
282-
attributes = new ArrayList<>();
283-
attributes.add(new Attribute(CF_UNITS_NAME, "seconds since 1970-01-01"));
284-
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(int.class)));
285-
attributes.add(new Attribute(CF_STANDARD_NAME, "time"));
286-
variables.add(new VariableProxy(TIME, DataType.INT, attributes));
287216

288-
// measurement record variables
289-
attributes = new ArrayList<>();
290-
attributes.add(new Attribute(CF_UNITS_NAME, "degT"));
291-
attributes.add(new Attribute(CF_FILL_VALUE_NAME, 999));
292-
attributes.add(new Attribute(CF_STANDARD_NAME, "wind_from_direction"));
293-
attributes.add(new Attribute(CF_LONG_NAME, "Ten-minute average wind direction measurements in degrees clockwise from true North."));
294-
variables.add(new VariableProxy(WDIR, DataType.SHORT, attributes));
217+
createBasicStationVariables(variables, attributes);
295218

296-
attributes = new ArrayList<>();
297-
attributes.add(new Attribute(CF_UNITS_NAME, "m/s"));
298-
attributes.add(new Attribute(CF_FILL_VALUE_NAME, 99.f));
299-
attributes.add(new Attribute(CF_STANDARD_NAME, "wind_speed"));
300-
attributes.add(new Attribute(CF_LONG_NAME, "Ten-minute average wind speed values in m/s."));
301-
variables.add(new VariableProxy(WSPD, DataType.FLOAT, attributes));
219+
// measurement record variables ----------------------------------
220+
createMeasurementTimeVariable(variables);
221+
createWindDirectionVariable(variables);
222+
createWindSpeedVariable(variables);
302223

303224
attributes = new ArrayList<>();
304225
attributes.add(new Attribute(CF_UNITS_NAME, "degT"));
@@ -307,12 +228,7 @@ public List<Variable> getVariables() throws InvalidRangeException, IOException {
307228
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."));
308229
variables.add(new VariableProxy(GDR, DataType.SHORT, attributes));
309230

310-
attributes = new ArrayList<>();
311-
attributes.add(new Attribute(CF_UNITS_NAME, "m/s"));
312-
attributes.add(new Attribute(CF_FILL_VALUE_NAME, 99.f));
313-
attributes.add(new Attribute(CF_STANDARD_NAME, "wind_gust_speed"));
314-
attributes.add(new Attribute(CF_LONG_NAME, "Maximum 5-second peak gust during the measurement hour, reported at the last hourly 10-minute segment."));
315-
variables.add(new VariableProxy(GST, DataType.FLOAT, attributes));
231+
createGustSpeedVariable(variables, "Maximum 5-second peak gust during the measurement hour, reported at the last hourly 10-minute segment.");
316232

317233
attributes = new ArrayList<>();
318234
attributes.add(new Attribute(CF_UNITS_NAME, "hhmm"));

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

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,37 @@
33
import com.bc.fiduceo.core.Interval;
44
import com.bc.fiduceo.reader.Reader;
55
import com.bc.fiduceo.util.NetCDFUtils;
6+
import com.bc.fiduceo.util.VariableProxy;
67
import ucar.ma2.Array;
78
import ucar.ma2.DataType;
9+
import ucar.nc2.Attribute;
10+
import ucar.nc2.Variable;
811

912
import java.io.IOException;
1013
import java.io.InputStream;
14+
import java.util.ArrayList;
15+
import java.util.List;
16+
17+
import static com.bc.fiduceo.util.NetCDFUtils.*;
18+
import static com.bc.fiduceo.util.NetCDFUtils.CF_LONG_NAME;
1119

1220
abstract class NdbcReader implements Reader {
1321

22+
static final String STATION_ID = "station_id";
23+
static final String STATION_TYPE = "station_type";
24+
static final String MEASUREMENT_TYPE = "measurement_type";
25+
static final String LONGITUDE = "longitude";
26+
static final String LATITUDE = "latitude";
27+
static final String ANEMOMETER_HEIGHT = "anemometer_height";
28+
static final String AIR_TEMP_HEIGHT = "air_temp_height";
29+
static final String BAROMETER_HEIGHT = "barometer_height";
30+
static final String SST_DEPTH = "sst_depth";
31+
32+
static final String TIME = "time";
33+
static final String WDIR = "WDIR";
34+
static final String WSPD = "WSPD";
35+
static final String GST = "GST";
36+
1437
StationDatabase parseStationDatabase(String resourceName) throws IOException {
1538
final InputStream is = getClass().getResourceAsStream(resourceName);
1639
if (is == null) {
@@ -55,6 +78,77 @@ static byte toByte(MeasurementType measurementType) {
5578
}
5679
}
5780

81+
static void createBasicStationVariables(ArrayList<Variable> variables, List<Attribute> attributes) {
82+
attributes.add(new Attribute(CF_LONG_NAME, "Station identifier"));
83+
variables.add(new VariableProxy(STATION_ID, DataType.STRING, attributes));
84+
85+
attributes = new ArrayList<>();
86+
attributes.add(new Attribute(CF_LONG_NAME, "Station type. 0: OCEAN_BUOY, 1: COAST_BUOY, 2: LAKE_BUOY, 3: OCEAN_STATION, 4: COAST_STATION, 5: LAKE_STATION"));
87+
variables.add(new VariableProxy(STATION_TYPE, DataType.BYTE, attributes));
88+
89+
attributes = new ArrayList<>();
90+
attributes.add(new Attribute(CF_LONG_NAME, "Measurement type. 0: CONSTANT_WIND, 1: STANDARD_METEOROLOGICAL"));
91+
variables.add(new VariableProxy(MEASUREMENT_TYPE, DataType.BYTE, attributes));
92+
93+
attributes = new ArrayList<>();
94+
attributes.add(new Attribute(CF_UNITS_NAME, "degree_east"));
95+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
96+
attributes.add(new Attribute(CF_STANDARD_NAME, "longitude"));
97+
variables.add(new VariableProxy(LONGITUDE, DataType.FLOAT, attributes));
98+
99+
attributes = new ArrayList<>();
100+
attributes.add(new Attribute(CF_UNITS_NAME, "degree_north"));
101+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
102+
attributes.add(new Attribute(CF_STANDARD_NAME, "latitude"));
103+
variables.add(new VariableProxy(LATITUDE, DataType.FLOAT, attributes));
104+
105+
attributes = new ArrayList<>();
106+
attributes.add(new Attribute(CF_UNITS_NAME, "m"));
107+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, Float.NaN));
108+
attributes.add(new Attribute(CF_LONG_NAME, "Height of instrument above site elevation"));
109+
variables.add(new VariableProxy(ANEMOMETER_HEIGHT, DataType.FLOAT, attributes));
110+
}
111+
112+
static void createMeasurementTimeVariable(ArrayList<Variable> variables) {
113+
List<Attribute> attributes;
114+
attributes = new ArrayList<>();
115+
attributes.add(new Attribute(CF_UNITS_NAME, "seconds since 1970-01-01"));
116+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(int.class)));
117+
attributes.add(new Attribute(CF_STANDARD_NAME, "time"));
118+
variables.add(new VariableProxy(TIME, DataType.INT, attributes));
119+
}
120+
121+
static void createWindDirectionVariable(ArrayList<Variable> variables) {
122+
List<Attribute> attributes;
123+
attributes = new ArrayList<>();
124+
attributes.add(new Attribute(CF_UNITS_NAME, "degT"));
125+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, 999));
126+
attributes.add(new Attribute(CF_STANDARD_NAME, "wind_from_direction"));
127+
attributes.add(new Attribute(CF_LONG_NAME, "Ten-minute average wind direction measurements in degrees clockwise from true North."));
128+
variables.add(new VariableProxy(WDIR, DataType.SHORT, attributes));
129+
}
130+
131+
static void createWindSpeedVariable(ArrayList<Variable> variables) {
132+
List<Attribute> attributes;
133+
attributes = new ArrayList<>();
134+
attributes.add(new Attribute(CF_UNITS_NAME, "m/s"));
135+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, 99.f));
136+
attributes.add(new Attribute(CF_STANDARD_NAME, "wind_speed"));
137+
attributes.add(new Attribute(CF_LONG_NAME, "Ten-minute average wind speed values in m/s."));
138+
variables.add(new VariableProxy(WSPD, DataType.FLOAT, attributes));
139+
}
140+
141+
static void createGustSpeedVariable(ArrayList<Variable> variables, String longName) {
142+
List<Attribute> attributes;
143+
attributes = new ArrayList<>();
144+
attributes.add(new Attribute(CF_UNITS_NAME, "m/s"));
145+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, 99.f));
146+
attributes.add(new Attribute(CF_STANDARD_NAME, "wind_gust_speed"));
147+
attributes.add(new Attribute(CF_LONG_NAME, longName));
148+
variables.add(new VariableProxy(GST, DataType.FLOAT, attributes));
149+
}
150+
151+
58152
protected Array createResultArray(Number value, Number fillValue, DataType dataType, Interval interval) {
59153
final int windowHeight = interval.getY();
60154
final int windowWidth = interval.getX();

0 commit comments

Comments
 (0)