Skip to content

Commit 402db25

Browse files
committed
contd sic insitu
1 parent 033c739 commit 402db25

File tree

11 files changed

+309
-37
lines changed

11 files changed

+309
-37
lines changed

core/src/main/java/com/bc/fiduceo/reader/insitu/gruan_uleic/GruanUleicInsituReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import com.bc.fiduceo.reader.AcquisitionInfo;
99
import com.bc.fiduceo.reader.Reader;
1010
import com.bc.fiduceo.reader.time.TimeLocator;
11-
import com.bc.fiduceo.reader.time.SecsSince1970TimeLocator;
11+
import com.bc.fiduceo.reader.time.TimeLocator_SecsSince1970;
1212
import com.bc.fiduceo.util.NetCDFUtils;
1313
import com.bc.fiduceo.util.TimeUtils;
1414
import com.bc.fiduceo.util.VariableProxy;
@@ -121,7 +121,7 @@ public PixelLocator getSubScenePixelLocator(Polygon sceneGeometry) {
121121

122122
@Override
123123
public TimeLocator getTimeLocator() {
124-
return new SecsSince1970TimeLocator(this);
124+
return new TimeLocator_SecsSince1970(this);
125125
}
126126

127127
@Override

core/src/main/java/com/bc/fiduceo/reader/insitu/ocean_rain/OceanRainInsituReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import com.bc.fiduceo.reader.AcquisitionInfo;
2929
import com.bc.fiduceo.reader.Reader;
3030
import com.bc.fiduceo.reader.time.TimeLocator;
31-
import com.bc.fiduceo.reader.time.SecsSince1970TimeLocator;
31+
import com.bc.fiduceo.reader.time.TimeLocator_SecsSince1970;
3232
import com.bc.fiduceo.util.NetCDFUtils;
3333
import com.bc.fiduceo.util.TimeUtils;
3434
import com.bc.fiduceo.util.VariableProxy;
@@ -129,7 +129,7 @@ public PixelLocator getSubScenePixelLocator(Polygon sceneGeometry) {
129129

130130
@Override
131131
public TimeLocator getTimeLocator() {
132-
return new SecsSince1970TimeLocator(this);
132+
return new TimeLocator_SecsSince1970(this);
133133
}
134134

135135
@Override
Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,63 @@
11
package com.bc.fiduceo.reader.insitu.sic_cci;
22

3+
import com.bc.fiduceo.util.NetCDFUtils;
4+
import com.bc.fiduceo.util.VariableProxy;
35
import org.esa.snap.core.datamodel.ProductData;
6+
import ucar.ma2.DataType;
7+
import ucar.nc2.Attribute;
8+
import ucar.nc2.Variable;
49

510
import java.text.ParseException;
11+
import java.util.ArrayList;
612
import java.util.Date;
13+
import java.util.List;
14+
15+
import static com.bc.fiduceo.util.NetCDFUtils.*;
716

817
class ReferenceDataSection {
918

1019
private static final String DATE_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'";
1120

12-
private Date time;
13-
14-
void parseTime(String line) throws ParseException {
21+
static Date parseTime(String line) throws ParseException {
1522
// todo 2 add some tests for negative indices tb 2022-11-03
1623
int first = line.indexOf(",");
1724
int startIndex = line.indexOf(",", first + 1) + 1;
1825
int stopIndex = line.indexOf(",", startIndex);
1926

2027
final String timeString = line.substring(startIndex, stopIndex);
2128
ProductData.UTC utcTime = ProductData.UTC.parse(timeString, DATE_PATTERN);
22-
time = utcTime.getAsDate();
29+
return utcTime.getAsDate();
2330
}
2431

25-
public Date getTime() {
26-
return time;
32+
static List<Variable> getVariables() {
33+
final List<Variable> variables = new ArrayList<>();
34+
35+
List<Attribute> attributes = new ArrayList<>();
36+
attributes.add(new Attribute(CF_UNITS_NAME, "degree_east"));
37+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
38+
attributes.add(new Attribute(CF_STANDARD_NAME, "longitude"));
39+
variables.add(new VariableProxy("longitude", DataType.FLOAT, attributes));
40+
41+
attributes = new ArrayList<>();
42+
attributes.add(new Attribute(CF_UNITS_NAME, "degree_north"));
43+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
44+
attributes.add(new Attribute(CF_STANDARD_NAME, "latitude"));
45+
variables.add(new VariableProxy("latitude", DataType.FLOAT, attributes));
46+
47+
attributes = new ArrayList<>();
48+
attributes.add(new Attribute(CF_UNITS_NAME, "seconds since 1970-01-01"));
49+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(int.class)));
50+
attributes.add(new Attribute(CF_STANDARD_NAME, "time"));
51+
variables.add(new VariableProxy("time", DataType.INT, attributes));
52+
53+
attributes = new ArrayList<>();
54+
variables.add(new VariableProxy("reference-id", DataType.CHAR, attributes));
55+
56+
attributes = new ArrayList<>();
57+
attributes.add(new Attribute(CF_FILL_VALUE_NAME, NetCDFUtils.getDefaultFillValue(float.class)));
58+
attributes.add(new Attribute(CF_STANDARD_NAME, "sea_ice_area_fraction"));
59+
variables.add(new VariableProxy("SIC", DataType.FLOAT, attributes));
60+
61+
return variables;
2762
}
2863
}

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

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.bc.fiduceo.reader.AcquisitionInfo;
99
import com.bc.fiduceo.reader.Reader;
1010
import com.bc.fiduceo.reader.time.TimeLocator;
11+
import com.bc.fiduceo.reader.time.TimeLocator_MillisSince1970;
1112
import ucar.ma2.Array;
1213
import ucar.ma2.ArrayInt;
1314
import ucar.ma2.InvalidRangeException;
@@ -24,9 +25,10 @@
2425

2526
public class SicCciInsituReader implements Reader {
2627

27-
private static final String REG_EX = "ASCAT-vs-AMSR2-vs-ERA5-vs-DMISIC0-\\d{4}-[N|S].text";
28+
private static final String REG_EX = "ASCAT-vs-AMSR2-vs-ERA5-vs-\\p{Upper}{6}\\d{1}-\\d{4}-[N|S].text";
2829

2930
private FileReader fileReader;
31+
private TimeLocator timeLocator;
3032
private ArrayList<String> linelist;
3133

3234
@Override
@@ -59,6 +61,7 @@ public void close() throws IOException {
5961
fileReader.close();
6062
fileReader = null;
6163
}
64+
timeLocator = null;
6265
}
6366

6467
@Override
@@ -88,16 +91,33 @@ public PixelLocator getSubScenePixelLocator(Polygon sceneGeometry) throws IOExce
8891

8992
@Override
9093
public TimeLocator getTimeLocator() throws IOException {
91-
throw new RuntimeException("not implemented");
94+
if (timeLocator == null) {
95+
long[] timeArray = new long[linelist.size()];
96+
try {
97+
int i = 0;
98+
for (String line : linelist) {
99+
final Date refTime = ReferenceDataSection.parseTime(line);
100+
timeArray[i] = refTime.getTime();
101+
++i;
102+
}
103+
104+
timeLocator = new TimeLocator_MillisSince1970(timeArray);
105+
} catch (ParseException e) {
106+
throw new IOException(e.getMessage());
107+
}
108+
}
109+
return timeLocator;
92110
}
93111

94112
@Override
95113
public int[] extractYearMonthDayFromFilename(String fileName) {
96-
throw new RuntimeException("not implemented");
114+
return new int[3];
97115
}
98116

99117
@Override
100118
public Array readRaw(int centerX, int centerY, Interval interval, String variableName) throws IOException, InvalidRangeException {
119+
// detect from variable name which section
120+
// - all sections have prefix, except for reference data section
101121
throw new RuntimeException("not implemented");
102122
}
103123

@@ -113,12 +133,18 @@ public ArrayInt.D2 readAcquisitionTime(int x, int y, Interval interval) throws I
113133

114134
@Override
115135
public List<Variable> getVariables() throws InvalidRangeException, IOException {
116-
throw new RuntimeException("not implemented");
136+
return ReferenceDataSection.getVariables();
117137
}
118138

119139
@Override
120140
public Dimension getProductSize() throws IOException {
121-
throw new RuntimeException("not implemented");
141+
final Dimension productSize = new Dimension();
142+
143+
productSize.setName("product_size");
144+
productSize.setNx(1);
145+
productSize.setNy(linelist.size());
146+
147+
return productSize;
122148
}
123149

124150
@Override
@@ -134,21 +160,20 @@ public String getLatitudeVariableName() {
134160
private void parseSensingTimes(AcquisitionInfo acquisitionInfo) throws IOException {
135161
Date minDate = new Date(Long.MAX_VALUE);
136162
Date maxDate = new Date(0);
137-
final ReferenceDataSection referenceDataSection = new ReferenceDataSection();
138163
try {
139-
for (String line :linelist) {
140-
referenceDataSection.parseTime(line);
141-
final Date refTime = referenceDataSection.getTime();
164+
for (String line : linelist) {
165+
final Date refTime = ReferenceDataSection.parseTime(line);
142166
if (minDate.after(refTime)) {
143167
minDate = refTime;
144168
}
145-
if (maxDate.before(refTime)){
169+
if (maxDate.before(refTime)) {
146170
maxDate = refTime;
147171
}
148-
149-
acquisitionInfo.setSensingStart(minDate);
150-
acquisitionInfo.setSensingStop(maxDate);
151172
}
173+
174+
acquisitionInfo.setSensingStart(minDate);
175+
acquisitionInfo.setSensingStop(maxDate);
176+
152177
} catch (ParseException e) {
153178
throw new IOException(e.getMessage());
154179
}

core/src/main/java/com/bc/fiduceo/reader/time/TimeLocator_MicrosSince2000.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ public class TimeLocator_MicrosSince2000 implements TimeLocator {
66

77
private final long[] timeStamps;
88

9-
109
public TimeLocator_MicrosSince2000(long[] timeStamps) {
1110
this.timeStamps = timeStamps;
1211
}
1312

14-
1513
@Override
1614
public long getTimeFor(int x, int y) {
1715
if (y < 0 || y >= timeStamps.length) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.bc.fiduceo.reader.time;
2+
3+
public class TimeLocator_MillisSince1970 implements TimeLocator{
4+
5+
private final long[] times;
6+
7+
public TimeLocator_MillisSince1970(long[] times) {
8+
this.times = times;
9+
}
10+
11+
@Override
12+
public long getTimeFor(int x, int y) {
13+
if (y < 0 || y >= times.length) {
14+
return -1;
15+
}
16+
17+
return times[y];
18+
}
19+
}

core/src/main/java/com/bc/fiduceo/reader/time/SecsSince1970TimeLocator.java renamed to core/src/main/java/com/bc/fiduceo/reader/time/TimeLocator_SecsSince1970.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
import java.io.IOException;
99

10-
public class SecsSince1970TimeLocator implements TimeLocator {
10+
public class TimeLocator_SecsSince1970 implements TimeLocator {
1111

1212
private final Reader reader;
1313
private final Interval interval;
1414

15-
public SecsSince1970TimeLocator(Reader reader) {
15+
public TimeLocator_SecsSince1970(Reader reader) {
1616
this.reader = reader;
1717
interval = new Interval(1, 1);
1818
}

core/src/test/java/com/bc/fiduceo/reader/insitu/sic_cci/ReferenceDataSectionTest.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,50 @@
22

33
import com.bc.fiduceo.TestUtil;
44
import org.junit.Test;
5+
import ucar.ma2.DataType;
6+
import ucar.nc2.Variable;
57

68
import java.text.ParseException;
9+
import java.util.Date;
10+
import java.util.List;
11+
12+
import static org.junit.Assert.assertEquals;
713

814
public class ReferenceDataSectionTest {
915

1016
@Test
1117
public void testParse() throws ParseException {
1218
final String lineStart = "-59.000,+090.000,2016-01-01T08:00:00Z,ICECHART_DMI,0.0,-59.000,+090.000, ...";
1319

14-
final ReferenceDataSection section = new ReferenceDataSection();
15-
section.parseTime(lineStart);
20+
final Date date = ReferenceDataSection.parseTime(lineStart);
21+
22+
TestUtil.assertCorrectUTCDate(2016, 1, 1, 8, 0, 0, date);
23+
}
24+
25+
@Test
26+
public void testGetVariables() {
27+
final List<Variable> variables = ReferenceDataSection.getVariables();
28+
29+
assertEquals(5, variables.size());
30+
31+
Variable variable = variables.get(0);
32+
assertEquals("longitude", variable.getShortName());
33+
assertEquals(DataType.FLOAT, variable.getDataType());
34+
35+
variable = variables.get(1);
36+
assertEquals("latitude", variable.getShortName());
37+
assertEquals(DataType.FLOAT, variable.getDataType());
38+
39+
variable = variables.get(2);
40+
assertEquals("time", variable.getShortName());
41+
assertEquals(DataType.INT, variable.getDataType());
42+
43+
variable = variables.get(3);
44+
assertEquals("reference-id", variable.getShortName());
45+
assertEquals(DataType.CHAR, variable.getDataType());
1646

17-
TestUtil.assertCorrectUTCDate(2016, 1, 1, 8, 0, 0, section.getTime());
47+
variable = variables.get(4);
48+
assertEquals("SIC", variable.getShortName());
49+
assertEquals(DataType.FLOAT, variable.getDataType());
1850
}
1951
}

0 commit comments

Comments
 (0)