Skip to content

Commit efb77a0

Browse files
committed
added plat_id string variable
1 parent 253229a commit efb77a0

File tree

3 files changed

+79
-26
lines changed

3 files changed

+79
-26
lines changed

core/src/main/java/com/bc/fiduceo/reader/insitu/sirds_sst/SirdsInsituReader.java

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.ArrayList;
2222
import java.util.Calendar;
2323
import java.util.List;
24+
import java.util.Locale;
2425

2526
import static com.bc.fiduceo.reader.insitu.InsituUtils.getResultArray;
2627

@@ -29,6 +30,7 @@ public class SirdsInsituReader extends NetCDFReader {
2930
private static final String REGEX_1 = "SSTCCI2_refdata_";
3031
private static final String REGEX_2 = "_\\d{6}.nc";
3132
private static final String UNIQUE_ID = "unique_id";
33+
private static final String PLAT_ID = "plat_id";
3234

3335
private final String sensorKey;
3436
private int[] timeMinMax;
@@ -120,13 +122,27 @@ public int[] extractYearMonthDayFromFilename(String fileName) {
120122
public Array readRaw(int centerX, int centerY, Interval interval, String variableName) throws IOException, InvalidRangeException {
121123
final Array sourceArray;
122124
final Number fillValue;
125+
123126
if (variableName.equals(UNIQUE_ID)) {
124127
ensureUniqueIdData();
125128
sourceArray = uniqueIdData;
126129
fillValue = UniqueIdVariable.FILL_VALUE;
130+
} else if (variableName.equals(PLAT_ID)) {
131+
final int windowHeight = interval.getY();
132+
final int windowCenterY = windowHeight / 2;
133+
134+
sourceArray = arrayCache.get(toFileName(PLAT_ID));
135+
final int[] shape = sourceArray.getShape();
136+
final int[] offsets = new int[]{windowCenterY, 0};
137+
138+
final Array section = sourceArray.section(offsets, new int[]{1, shape[1]});
139+
final char[] platIdVector = (char[]) section.copyTo1DJavaArray();
140+
141+
return NetCDFUtils.create(platIdVector);
127142
} else {
128-
sourceArray = arrayCache.get(variableName);
129-
fillValue = getFillValue(variableName);
143+
final String fileVariableName = toFileName(variableName);
144+
sourceArray = arrayCache.get(fileVariableName);
145+
fillValue = getFillValue(fileVariableName);
130146
}
131147

132148
return getResultArray(centerY, interval, sourceArray, fillValue);
@@ -170,11 +186,12 @@ public List<Variable> getVariables() throws InvalidRangeException, IOException {
170186
"MINUTE".equals(variableName) ||
171187
"MONTH".equals(variableName) ||
172188
"OB_ID".equals(variableName) ||
173-
"PLAT_ID".equals(variableName) ||
174189
"SECOND".equals(variableName) ||
175190
"YEAR".equals(variableName)) {
176191
continue;
177192
} else {
193+
final String mmsName = toMMSName(variableName);
194+
variable.setShortName(mmsName);
178195
listVariables.add(variable);
179196
}
180197
}
@@ -193,12 +210,12 @@ public Dimension getProductSize() throws IOException {
193210

194211
@Override
195212
public String getLongitudeVariableName() {
196-
return "LONGITUDE";
213+
return "longitude";
197214
}
198215

199216
@Override
200217
public String getLatitudeVariableName() {
201-
return "LATITUDE";
218+
return "latitude";
202219
}
203220

204221
// package access for testing only tb 2021-07-21
@@ -244,6 +261,16 @@ static String toRegExPart(String sensorKey) {
244261
}
245262
}
246263

264+
// package access for testing only tb 2021-07-26
265+
static String toFileName(String variableName) {
266+
return variableName.toUpperCase(Locale.ROOT);
267+
}
268+
269+
// package access for testing only tb 2021-07-26
270+
static String toMMSName(String variableName) {
271+
return variableName.toLowerCase(Locale.ROOT);
272+
}
273+
247274
private void ensureUniqueIdData() throws IOException {
248275
if (uniqueIdData != null) {
249276
return;

core/src/test/java/com/bc/fiduceo/reader/insitu/sirds_sst/SirdsInsituReaderTest.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.bc.fiduceo.reader.insitu.sirds_sst;
22

3-
import com.bc.fiduceo.reader.insitu.sst_cci.SSTInsituReader;
4-
import org.junit.Before;
53
import org.junit.Test;
64

75
import java.util.regex.Matcher;
@@ -57,14 +55,14 @@ public void testGetRegEx_argosurf() {
5755
public void testGetLongitudeVariableName() {
5856
final SirdsInsituReader insituReader = new SirdsInsituReader("whatever");
5957

60-
assertEquals("LONGITUDE", insituReader.getLongitudeVariableName());
58+
assertEquals("longitude", insituReader.getLongitudeVariableName());
6159
}
6260

6361
@Test
6462
public void testGetLatitudeVariableName() {
6563
final SirdsInsituReader insituReader = new SirdsInsituReader("whatever");
6664

67-
assertEquals("LATITUDE", insituReader.getLatitudeVariableName());
65+
assertEquals("latitude", insituReader.getLatitudeVariableName());
6866
}
6967

7068
@Test
@@ -91,4 +89,18 @@ public void testToRegExPart() {
9189
assertEquals("drifter", SirdsInsituReader.toRegExPart("drifter-sirds"));
9290
assertEquals("drifter_cmems", SirdsInsituReader.toRegExPart("driftercmems-sirds"));
9391
}
92+
93+
@Test
94+
public void testToFileName() {
95+
assertEquals("DEPTH", SirdsInsituReader.toFileName("depth"));
96+
assertEquals("DEPTH_CORR", SirdsInsituReader.toFileName("depth_corr"));
97+
assertEquals("QC1", SirdsInsituReader.toFileName("qc1"));
98+
}
99+
100+
@Test
101+
public void testToMMSName() {
102+
assertEquals("latitude", SirdsInsituReader.toMMSName("LATITUDE"));
103+
assertEquals("ob_id", SirdsInsituReader.toMMSName("OB_ID"));
104+
assertEquals("qc2", SirdsInsituReader.toMMSName("QC2"));
105+
}
94106
}

core/src/test/java/com/bc/fiduceo/reader/insitu/sirds_sst/SirdsInsituReader_IO_Test.java

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,24 @@ public void testGetVariables_drifter() throws Exception {
9898
final List<Variable> variables = insituReader.getVariables();
9999

100100
assertNotNull(variables);
101-
assertEquals(18, variables.size());
102-
assertEquals("SUBCOL1", variables.get(1).getShortName());
103-
assertEquals("PROF_ID", variables.get(3).getShortName());
104-
assertEquals("LATITUDE", variables.get(5).getShortName());
105-
assertEquals("DEPTH_CORR", variables.get(7).getShortName());
106-
assertEquals("SST_TYPE_CORR", variables.get(9).getShortName());
107-
assertEquals("SST_PLAT_CORR", variables.get(11).getShortName());
108-
assertEquals("SST_RAND_UNC", variables.get(13).getShortName());
109-
assertEquals("QC1", variables.get(15).getShortName());
110-
assertEquals("unique_id", variables.get(17).getShortName());
101+
assertEquals(19, variables.size());
102+
assertEquals("subcol1", variables.get(1).getShortName());
103+
assertEquals("prof_id", variables.get(3).getShortName());
104+
assertEquals("longitude", variables.get(5).getShortName());
105+
assertEquals("depth", variables.get(7).getShortName());
106+
assertEquals("sst", variables.get(9).getShortName());
107+
assertEquals("sst_type_corr_unc", variables.get(11).getShortName());
108+
assertEquals("sst_plat_corr_unc", variables.get(13).getShortName());
109+
assertEquals("sst_comb_unc", variables.get(15).getShortName());
110+
assertEquals("qc2", variables.get(17).getShortName());
111+
assertEquals("unique_id", variables.get(18).getShortName());
111112
}
112113

113114
@Test
114115
public void testReadRaw_drifter() throws Exception {
115116
insituReader = new SirdsInsituReader("drifter");
116117
openFile("SSTCCI2_refdata_drifter_201304.nc");
117-
final Array array = insituReader.readRaw(0, 0, new Interval(1, 1), "DEPTH");
118+
final Array array = insituReader.readRaw(0, 0, new Interval(1, 1), "depth");
118119

119120
assertNotNull(array);
120121
assertArrayEquals(new int[]{1, 1}, array.getShape());
@@ -126,7 +127,7 @@ public void testReadRaw_drifter() throws Exception {
126127
public void testReadRaw_mooring() throws Exception {
127128
insituReader = new SirdsInsituReader("mooring");
128129
openFile("SSTCCI2_refdata_mooring_201602.nc");
129-
final Array array = insituReader.readRaw(0, 1, new Interval(1, 1), "DEPTH_CORR");
130+
final Array array = insituReader.readRaw(0, 1, new Interval(1, 1), "depth_corr");
130131

131132
assertNotNull(array);
132133
assertArrayEquals(new int[]{1, 1}, array.getShape());
@@ -138,7 +139,7 @@ public void testReadRaw_mooring() throws Exception {
138139
public void testReadRaw_xbt() throws Exception {
139140
insituReader = new SirdsInsituReader("xbt");
140141
openFile("SSTCCI2_refdata_xbt_200204.nc");
141-
final Array array = insituReader.readRaw(0, 2, new Interval(1, 1), "LATITUDE");
142+
final Array array = insituReader.readRaw(0, 2, new Interval(1, 1), "latitude");
142143

143144
assertNotNull(array);
144145
assertArrayEquals(new int[]{1, 1}, array.getShape());
@@ -150,7 +151,7 @@ public void testReadRaw_xbt() throws Exception {
150151
public void testReadRaw_drifter_3x3() throws Exception {
151152
insituReader = new SirdsInsituReader("drifter");
152153
openFile("SSTCCI2_refdata_drifter_201304.nc");
153-
final Array array = insituReader.readRaw(0, 3, new Interval(3, 3), "LONGITUDE");
154+
final Array array = insituReader.readRaw(0, 3, new Interval(3, 3), "longitude");
154155

155156
assertNotNull(array);
156157
assertArrayEquals(new int[]{3, 3}, array.getShape());
@@ -166,11 +167,24 @@ public void testReadRaw_drifter_3x3() throws Exception {
166167
assertEquals(-9999.0, array.getFloat(8), 1e-8);
167168
}
168169

170+
@Test
171+
public void testReadRaw_drifter_3x3_plat_id() throws Exception {
172+
insituReader = new SirdsInsituReader("drifter");
173+
openFile("SSTCCI2_refdata_drifter_201304.nc");
174+
final Array array = insituReader.readRaw(0, 4, new Interval(3, 3), "plat_id");
175+
176+
final int[] shape = array.getShape();
177+
assertEquals(9, shape[0]);
178+
final char[] dataVector = (char[]) array.get1DJavaArray(DataType.CHAR);
179+
180+
assertEquals("63552 ", new String(dataVector));
181+
}
182+
169183
@Test
170184
public void testReadRaw_mooring_3x3() throws Exception {
171185
insituReader = new SirdsInsituReader("mooring");
172186
openFile("SSTCCI2_refdata_mooring_201602.nc");
173-
final Array array = insituReader.readRaw(0, 4, new Interval(3, 3), "SST");
187+
final Array array = insituReader.readRaw(0, 4, new Interval(3, 3), "sst");
174188

175189
assertNotNull(array);
176190
assertArrayEquals(new int[]{3, 3}, array.getShape());
@@ -190,7 +204,7 @@ public void testReadRaw_mooring_3x3() throws Exception {
190204
public void testReadScaled_xbt() throws Exception {
191205
insituReader = new SirdsInsituReader("xbt");
192206
openFile("SSTCCI2_refdata_xbt_200204.nc");
193-
final Array array = insituReader.readScaled(0, 5, new Interval(1, 1), "SST_COMB_UNC");
207+
final Array array = insituReader.readScaled(0, 5, new Interval(1, 1), "sst_comb_unc");
194208

195209
assertNotNull(array);
196210
assertArrayEquals(new int[]{1, 1}, array.getShape());
@@ -202,7 +216,7 @@ public void testReadScaled_xbt() throws Exception {
202216
public void testReadScaled_drifter_3x3() throws Exception {
203217
insituReader = new SirdsInsituReader("drifter");
204218
openFile("SSTCCI2_refdata_drifter_201304.nc");
205-
final Array array = insituReader.readScaled(0, 6, new Interval(3, 3), "SST_RAND_UNC");
219+
final Array array = insituReader.readScaled(0, 6, new Interval(3, 3), "sst_rand_unc");
206220

207221
assertNotNull(array);
208222
assertArrayEquals(new int[]{3, 3}, array.getShape());

0 commit comments

Comments
 (0)