Skip to content

Commit 72477fb

Browse files
committed
polarstern insitu section
1 parent b6767be commit 72477fb

File tree

4 files changed

+495
-31
lines changed

4 files changed

+495
-31
lines changed

core/src/main/java/com/bc/fiduceo/reader/insitu/sic_cci/ANTXXXISectionParser.java

Lines changed: 241 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.bc.fiduceo.util.NetCDFUtils;
44
import com.bc.fiduceo.util.VariableProxy;
5+
import org.esa.snap.core.datamodel.ProductData;
6+
import ucar.ma2.Array;
57
import ucar.ma2.DataType;
68
import ucar.nc2.Attribute;
79
import ucar.nc2.Variable;
@@ -24,6 +26,12 @@ List<Variable> getVariables() {
2426
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(byte.class)));
2527
attributes.add(new Attribute(CF_STANDARD_NAME, "sea_ice_area_fraction"));
2628
attributes.add(new Attribute(CF_UNITS_NAME, "percent"));
29+
variables.add(new VariableProxy("SIC-total", DataType.BYTE, attributes));
30+
31+
attributes = new ArrayList<>();
32+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(byte.class)));
33+
attributes.add(new Attribute(CF_STANDARD_NAME, "sea_ice_area_fraction"));
34+
attributes.add(new Attribute(CF_UNITS_NAME, "percent"));
2735
variables.add(new VariableProxy("SIC-primary", DataType.BYTE, attributes));
2836

2937
attributes = new ArrayList<>();
@@ -32,16 +40,246 @@ List<Variable> getVariables() {
3240
variables.add(new VariableProxy("Ice-type-primary", DataType.BYTE, attributes));
3341

3442
attributes = new ArrayList<>();
35-
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(short.class)));
43+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
44+
attributes.add(new Attribute(CF_STANDARD_NAME, "sea_ice_thickness"));
45+
attributes.add(new Attribute(CF_UNITS_NAME, "m"));
46+
variables.add(new VariableProxy("SIT-primary", DataType.FLOAT, attributes));
47+
48+
attributes = new ArrayList<>();
49+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
50+
variables.add(new VariableProxy("Ridged-ice-fraction-primary", DataType.FLOAT, attributes));
51+
52+
attributes = new ArrayList<>();
53+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
54+
attributes.add(new Attribute(CF_UNITS_NAME, "m"));
55+
variables.add(new VariableProxy("Ridge-height-primary", DataType.FLOAT, attributes));
56+
57+
attributes = new ArrayList<>();
58+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(byte.class)));
59+
attributes.add(new Attribute(CF_LONG_NAME, "Snow-cover-type-primary ASPeCt code"));
60+
variables.add(new VariableProxy("Snow-cover-type-primary", DataType.BYTE, attributes));
61+
62+
attributes = new ArrayList<>();
63+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
64+
attributes.add(new Attribute(CF_STANDARD_NAME, "thickness_of_snowfall_amount"));
65+
attributes.add(new Attribute(CF_UNITS_NAME, "m"));
66+
variables.add(new VariableProxy("Snow-depth-primary", DataType.FLOAT, attributes));
67+
68+
attributes = new ArrayList<>();
69+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(byte.class)));
70+
attributes.add(new Attribute(CF_STANDARD_NAME, "sea_ice_area_fraction"));
71+
attributes.add(new Attribute(CF_UNITS_NAME, "percent"));
72+
variables.add(new VariableProxy("SIC-secondary", DataType.BYTE, attributes));
73+
74+
attributes = new ArrayList<>();
75+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(byte.class)));
76+
attributes.add(new Attribute(CF_LONG_NAME, "Ice-type-secondary ASPeCt code"));
77+
variables.add(new VariableProxy("Ice-type-secondary", DataType.BYTE, attributes));
78+
79+
attributes = new ArrayList<>();
80+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
3681
attributes.add(new Attribute(CF_STANDARD_NAME, "sea_ice_thickness"));
3782
attributes.add(new Attribute(CF_UNITS_NAME, "m"));
38-
variables.add(new VariableProxy("SIT-primary", DataType.SHORT, attributes));
83+
variables.add(new VariableProxy("SIT-secondary", DataType.FLOAT, attributes));
84+
85+
attributes = new ArrayList<>();
86+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
87+
variables.add(new VariableProxy("Ridged-ice-fraction-secondary", DataType.FLOAT, attributes));
88+
89+
attributes = new ArrayList<>();
90+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
91+
attributes.add(new Attribute(CF_UNITS_NAME, "m"));
92+
variables.add(new VariableProxy("Ridge-height-secondary", DataType.FLOAT, attributes));
93+
94+
attributes = new ArrayList<>();
95+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(byte.class)));
96+
attributes.add(new Attribute(CF_LONG_NAME, "Snow-cover-type-secondary ASPeCt code"));
97+
variables.add(new VariableProxy("Snow-cover-type-secondary", DataType.BYTE, attributes));
98+
99+
attributes = new ArrayList<>();
100+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
101+
attributes.add(new Attribute(CF_STANDARD_NAME, "thickness_of_snowfall_amount"));
102+
attributes.add(new Attribute(CF_UNITS_NAME, "m"));
103+
variables.add(new VariableProxy("Snow-depth-secondary", DataType.FLOAT, attributes));
104+
105+
attributes = new ArrayList<>();
106+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(byte.class)));
107+
attributes.add(new Attribute(CF_STANDARD_NAME, "sea_ice_area_fraction"));
108+
attributes.add(new Attribute(CF_UNITS_NAME, "percent"));
109+
variables.add(new VariableProxy("SIC-tertiary", DataType.BYTE, attributes));
110+
111+
attributes = new ArrayList<>();
112+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(byte.class)));
113+
attributes.add(new Attribute(CF_LONG_NAME, "Ice-type-tertiary ASPeCt code"));
114+
variables.add(new VariableProxy("Ice-type-tertiary", DataType.BYTE, attributes));
115+
116+
attributes = new ArrayList<>();
117+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
118+
attributes.add(new Attribute(CF_STANDARD_NAME, "sea_ice_thickness"));
119+
attributes.add(new Attribute(CF_UNITS_NAME, "m"));
120+
variables.add(new VariableProxy("SIT-tertiary", DataType.FLOAT, attributes));
121+
122+
attributes = new ArrayList<>();
123+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
124+
variables.add(new VariableProxy("Ridged-ice-fraction-tertiary", DataType.FLOAT, attributes));
125+
126+
attributes = new ArrayList<>();
127+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
128+
attributes.add(new Attribute(CF_UNITS_NAME, "m"));
129+
variables.add(new VariableProxy("Ridge-height-tertiary", DataType.FLOAT, attributes));
130+
131+
attributes = new ArrayList<>();
132+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(byte.class)));
133+
attributes.add(new Attribute(CF_LONG_NAME, "Snow-cover-type-tertiary ASPeCt code"));
134+
variables.add(new VariableProxy("Snow-cover-type-tertiary", DataType.BYTE, attributes));
135+
136+
attributes = new ArrayList<>();
137+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
138+
attributes.add(new Attribute(CF_STANDARD_NAME, "thickness_of_snowfall_amount"));
139+
attributes.add(new Attribute(CF_UNITS_NAME, "m"));
140+
variables.add(new VariableProxy("Snow-depth-tertiary", DataType.FLOAT, attributes));
141+
142+
attributes = new ArrayList<>();
143+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
144+
attributes.add(new Attribute(CF_STANDARD_NAME, "sea_water_temperature"));
145+
attributes.add(new Attribute(CF_UNITS_NAME, "degree_C"));
146+
variables.add(new VariableProxy("Sea-water-temperature", DataType.FLOAT, attributes));
147+
148+
attributes = new ArrayList<>();
149+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
150+
attributes.add(new Attribute(CF_STANDARD_NAME, "air_temperature"));
151+
attributes.add(new Attribute(CF_UNITS_NAME, "degree_C"));
152+
variables.add(new VariableProxy("Air-temperature", DataType.FLOAT, attributes));
153+
154+
attributes = new ArrayList<>();
155+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
156+
attributes.add(new Attribute(CF_STANDARD_NAME, "wind_speed"));
157+
attributes.add(new Attribute(CF_UNITS_NAME, "m s-1"));
158+
variables.add(new VariableProxy("Wind-speed", DataType.FLOAT, attributes));
159+
160+
attributes = new ArrayList<>();
161+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(short.class)));
162+
attributes.add(new Attribute(CF_UNITS_NAME, "degree"));
163+
variables.add(new VariableProxy("Wind-direction", DataType.SHORT, attributes));
164+
165+
attributes = new ArrayList<>();
166+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(byte.class)));
167+
variables.add(new VariableProxy("Visibility", DataType.BYTE, attributes));
168+
169+
attributes = new ArrayList<>();
170+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(byte.class)));
171+
variables.add(new VariableProxy("Cloud-cover", DataType.BYTE, attributes));
172+
173+
attributes = new ArrayList<>();
174+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(byte.class)));
175+
variables.add(new VariableProxy("Weather", DataType.BYTE, attributes));
39176

40177
return variables;
41178
}
42179

43180
@Override
44181
Section parse(String[] tokens) throws ParseException {
45-
throw new RuntimeException("not implemented");
182+
final Section section = new Section();
183+
184+
final float lat = Float.parseFloat(tokens[0]);
185+
section.add("latitude", Array.factory(DataType.FLOAT, SCALAR, new float[]{lat}));
186+
187+
final float lon = Float.parseFloat(tokens[1]);
188+
section.add("longitude", Array.factory(DataType.FLOAT, SCALAR, new float[]{lon}));
189+
190+
final ProductData.UTC utcTime = ProductData.UTC.parse(tokens[2], DATE_PATTERN);
191+
final int utcSeconds = (int) (utcTime.getAsDate().getTime() / 1000);
192+
section.add("time", Array.factory(DataType.INT, SCALAR, new int[]{utcSeconds}));
193+
194+
section.add("reference-id", Array.factory(DataType.CHAR, new int[]{tokens[3].length()}, tokens[3].toCharArray()));
195+
196+
final byte sic_total = Byte.parseByte(tokens[4]);
197+
section.add("SIC-total", Array.factory(DataType.BYTE, SCALAR, new byte[]{sic_total}));
198+
199+
final byte sic_prim = Byte.parseByte(tokens[5]);
200+
section.add("SIC-primary", Array.factory(DataType.BYTE, SCALAR, new byte[]{sic_prim}));
201+
202+
final byte ice_type_prim = Byte.parseByte(tokens[6]);
203+
section.add("Ice-type-primary", Array.factory(DataType.BYTE, SCALAR, new byte[]{ice_type_prim}));
204+
205+
final float sit_prim = Float.parseFloat(tokens[7]);
206+
section.add("SIT-primary", Array.factory(DataType.FLOAT, SCALAR, new float[]{sit_prim}));
207+
208+
final float rif_prim = Float.parseFloat(tokens[8]);
209+
section.add("Ridged-ice-fraction-primary", Array.factory(DataType.FLOAT, SCALAR, new float[]{rif_prim}));
210+
211+
final float rih_prim = Float.parseFloat(tokens[9]);
212+
section.add("Ridged-height-primary", Array.factory(DataType.FLOAT, SCALAR, new float[]{rih_prim}));
213+
214+
final byte sct_prim = Byte.parseByte(tokens[10]);
215+
section.add("Snow-cover-type-primary", Array.factory(DataType.BYTE, SCALAR, new byte[]{sct_prim}));
216+
217+
final float sd_prim = Float.parseFloat(tokens[11]);
218+
section.add("Snow-depth-primary", Array.factory(DataType.FLOAT, SCALAR, new float[]{sd_prim}));
219+
220+
final byte sic_sec = Byte.parseByte(tokens[12]);
221+
section.add("SIC-secondary", Array.factory(DataType.BYTE, SCALAR, new byte[]{sic_sec}));
222+
223+
final byte ice_type_sec = Byte.parseByte(tokens[13]);
224+
section.add("Ice-type-secondary", Array.factory(DataType.BYTE, SCALAR, new byte[]{ice_type_sec}));
225+
226+
final float sit_sec = Float.parseFloat(tokens[14]);
227+
section.add("SIT-secondary", Array.factory(DataType.FLOAT, SCALAR, new float[]{sit_sec}));
228+
229+
final float rif_sec = Float.parseFloat(tokens[15]);
230+
section.add("Ridged-ice-fraction-secondary", Array.factory(DataType.FLOAT, SCALAR, new float[]{rif_sec}));
231+
232+
final float rih_sec = Float.parseFloat(tokens[16]);
233+
section.add("Ridged-height-secondary", Array.factory(DataType.FLOAT, SCALAR, new float[]{rih_sec}));
234+
235+
final byte sct_sec = Byte.parseByte(tokens[17]);
236+
section.add("Snow-cover-type-secondary", Array.factory(DataType.BYTE, SCALAR, new byte[]{sct_sec}));
237+
238+
final float sd_sec = Float.parseFloat(tokens[18]);
239+
section.add("Snow-depth-secondary", Array.factory(DataType.FLOAT, SCALAR, new float[]{sd_sec}));
240+
241+
final byte sic_ter = Byte.parseByte(tokens[19]);
242+
section.add("SIC-tertiary", Array.factory(DataType.BYTE, SCALAR, new byte[]{sic_ter}));
243+
244+
final byte ice_type_ter = Byte.parseByte(tokens[20]);
245+
section.add("Ice-type-tertiary", Array.factory(DataType.BYTE, SCALAR, new byte[]{ice_type_ter}));
246+
247+
final float sit_ter = Float.parseFloat(tokens[21]);
248+
section.add("SIT-tertiary", Array.factory(DataType.FLOAT, SCALAR, new float[]{sit_ter}));
249+
250+
final float rif_ter = Float.parseFloat(tokens[22]);
251+
section.add("Ridged-ice-fraction-tertiary", Array.factory(DataType.FLOAT, SCALAR, new float[]{rif_ter}));
252+
253+
final float rih_ter = Float.parseFloat(tokens[23]);
254+
section.add("Ridged-height-tertiary", Array.factory(DataType.FLOAT, SCALAR, new float[]{rih_ter}));
255+
256+
final byte sct_ter = Byte.parseByte(tokens[24]);
257+
section.add("Snow-cover-type-tertiary", Array.factory(DataType.BYTE, SCALAR, new byte[]{sct_ter}));
258+
259+
final float sd_ter = Float.parseFloat(tokens[25]);
260+
section.add("Snow-depth-tertiary", Array.factory(DataType.FLOAT, SCALAR, new float[]{sd_ter}));
261+
262+
final float swt = Float.parseFloat(tokens[26]);
263+
section.add("Sea-water-temperature", Array.factory(DataType.FLOAT, SCALAR, new float[]{swt}));
264+
265+
final float at = Float.parseFloat(tokens[27]);
266+
section.add("Air-temperature", Array.factory(DataType.FLOAT, SCALAR, new float[]{at}));
267+
268+
final float ws = Float.parseFloat(tokens[28]);
269+
section.add("Wind-speed", Array.factory(DataType.FLOAT, SCALAR, new float[]{ws}));
270+
271+
final short wd = Short.parseShort(tokens[29]);
272+
section.add("Wind-direction", Array.factory(DataType.SHORT, SCALAR, new short[]{wd}));
273+
274+
final byte vis = Byte.parseByte(tokens[30]);
275+
section.add("Visibility", Array.factory(DataType.BYTE, SCALAR, new byte[]{vis}));
276+
277+
final byte cc = Byte.parseByte(tokens[31]);
278+
section.add("Cloud-cover", Array.factory(DataType.BYTE, SCALAR, new byte[]{cc}));
279+
280+
final byte weather = Byte.parseByte(tokens[32]);
281+
section.add("Weather", Array.factory(DataType.BYTE, SCALAR, new byte[]{weather}));
282+
283+
return section;
46284
}
47285
}

core/src/main/java/com/bc/fiduceo/reader/insitu/sic_cci/SicCciInsituReader.java

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ public void open(File file) throws IOException {
4646
referenceSectionParser = new DMISIC0SectionParser();
4747
} else if (fileName.contains("DTUSIC1")) {
4848
referenceSectionParser = new DTUSIC1SectionParser();
49+
} else if (fileName.contains("ANTXXXI")) {
50+
referenceSectionParser = new ANTXXXISectionParser();
4951
}
5052

51-
sectionCache = new SectionCache(linelist, new AbstractSectionParser[] {referenceSectionParser});
53+
sectionCache = new SectionCache(linelist, new AbstractSectionParser[]{referenceSectionParser});
5254
}
5355

5456
private void readLines() throws IOException {
@@ -121,9 +123,28 @@ public int[] extractYearMonthDayFromFilename(String fileName) {
121123

122124
@Override
123125
public Array readRaw(int centerX, int centerY, Interval interval, String variableName) throws IOException, InvalidRangeException {
124-
// detect from variable name which section
125-
// - all sections have prefix, except for reference data section
126-
throw new RuntimeException("not implemented");
126+
try {
127+
final Array insituArray = sectionCache.get(variableName, centerY);
128+
final DataType dataType = insituArray.getDataType();
129+
if (dataType == DataType.CHAR) {
130+
// string data is not patched or padded, just returned tb 2022-11-09
131+
return insituArray;
132+
}
133+
134+
final int windowHeight = interval.getY();
135+
final int windowWidth = interval.getX();
136+
final Array windowArray = NetCDFUtils.create(dataType,
137+
new int[]{windowHeight, windowWidth},
138+
NetCDFUtils.getDefaultFillValue(dataType, false));
139+
140+
final int windowCenterX = windowWidth / 2;
141+
final int windowCenterY = windowHeight / 2;
142+
windowArray.setObject(windowWidth * windowCenterY + windowCenterX, insituArray.getObject(0));
143+
144+
return windowArray;
145+
} catch (ParseException e) {
146+
throw new IOException(e);
147+
}
127148
}
128149

129150
@Override
@@ -133,23 +154,9 @@ public Array readScaled(int centerX, int centerY, Interval interval, String vari
133154

134155
@Override
135156
public ArrayInt.D2 readAcquisitionTime(int x, int y, Interval interval) throws IOException, InvalidRangeException {
136-
final int windowHeight = interval.getY();
137-
final int windowWidth = interval.getX();
138-
final Array windowArray = NetCDFUtils.create(DataType.INT,
139-
new int[]{windowHeight, windowWidth},
140-
NetCDFUtils.getDefaultFillValue(DataType.INT, false));
141-
142-
try {
143-
final int windowCenterX = windowWidth / 2;
144-
final int windowCenterY = windowHeight / 2;
145-
146-
final Array timeArray = sectionCache.get("time", y);
147-
windowArray.setObject(windowWidth * windowCenterY + windowCenterX, timeArray.getInt(0));
148-
} catch (ParseException e) {
149-
throw new IOException(e);
150-
}
157+
final Array timeArray = readRaw(x, y, interval, "time");
151158

152-
return (ArrayInt.D2) windowArray;
159+
return (ArrayInt.D2) timeArray;
153160
}
154161

155162
@Override

0 commit comments

Comments
 (0)