Skip to content

Commit 033c739

Browse files
committed
contd sic insitu
1 parent 7927b6b commit 033c739

File tree

4 files changed

+99
-1
lines changed

4 files changed

+99
-1
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.bc.fiduceo.reader.insitu.sic_cci;
2+
3+
import org.esa.snap.core.datamodel.ProductData;
4+
5+
import java.text.ParseException;
6+
import java.util.Date;
7+
8+
class ReferenceDataSection {
9+
10+
private static final String DATE_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'";
11+
12+
private Date time;
13+
14+
void parseTime(String line) throws ParseException {
15+
// todo 2 add some tests for negative indices tb 2022-11-03
16+
int first = line.indexOf(",");
17+
int startIndex = line.indexOf(",", first + 1) + 1;
18+
int stopIndex = line.indexOf(",", startIndex);
19+
20+
final String timeString = line.substring(startIndex, stopIndex);
21+
ProductData.UTC utcTime = ProductData.UTC.parse(timeString, DATE_PATTERN);
22+
time = utcTime.getAsDate();
23+
}
24+
25+
public Date getTime() {
26+
return time;
27+
}
28+
}

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.bc.fiduceo.core.Dimension;
44
import com.bc.fiduceo.core.Interval;
5+
import com.bc.fiduceo.core.NodeType;
56
import com.bc.fiduceo.geometry.Polygon;
67
import com.bc.fiduceo.location.PixelLocator;
78
import com.bc.fiduceo.reader.AcquisitionInfo;
@@ -16,7 +17,9 @@
1617
import java.io.File;
1718
import java.io.FileReader;
1819
import java.io.IOException;
20+
import java.text.ParseException;
1921
import java.util.ArrayList;
22+
import java.util.Date;
2023
import java.util.List;
2124

2225
public class SicCciInsituReader implements Reader {
@@ -30,10 +33,18 @@ public class SicCciInsituReader implements Reader {
3033
public void open(File file) throws IOException {
3134
fileReader = new FileReader(file);
3235

36+
readLines();
37+
}
38+
39+
private void readLines() throws IOException {
3340
linelist = new ArrayList<>();
3441
final BufferedReader bufferedReader = new BufferedReader(fileReader);
3542
String line;
3643
while ((line = bufferedReader.readLine()) != null) {
44+
if (line.startsWith("#")) {
45+
// skip comment lines tb 2022-11-03
46+
continue;
47+
}
3748
linelist.add(line);
3849
}
3950
}
@@ -52,7 +63,12 @@ public void close() throws IOException {
5263

5364
@Override
5465
public AcquisitionInfo read() throws IOException {
55-
throw new RuntimeException("not implemented");
66+
final AcquisitionInfo acquisitionInfo = new AcquisitionInfo();
67+
acquisitionInfo.setNodeType(NodeType.UNDEFINED);
68+
69+
parseSensingTimes(acquisitionInfo);
70+
71+
return acquisitionInfo;
5672
}
5773

5874
@Override
@@ -114,4 +130,27 @@ public String getLongitudeVariableName() {
114130
public String getLatitudeVariableName() {
115131
return "latitude";
116132
}
133+
134+
private void parseSensingTimes(AcquisitionInfo acquisitionInfo) throws IOException {
135+
Date minDate = new Date(Long.MAX_VALUE);
136+
Date maxDate = new Date(0);
137+
final ReferenceDataSection referenceDataSection = new ReferenceDataSection();
138+
try {
139+
for (String line :linelist) {
140+
referenceDataSection.parseTime(line);
141+
final Date refTime = referenceDataSection.getTime();
142+
if (minDate.after(refTime)) {
143+
minDate = refTime;
144+
}
145+
if (maxDate.before(refTime)){
146+
maxDate = refTime;
147+
}
148+
149+
acquisitionInfo.setSensingStart(minDate);
150+
acquisitionInfo.setSensingStop(maxDate);
151+
}
152+
} catch (ParseException e) {
153+
throw new IOException(e.getMessage());
154+
}
155+
}
117156
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.bc.fiduceo.reader.insitu.sic_cci;
2+
3+
import com.bc.fiduceo.TestUtil;
4+
import org.junit.Test;
5+
6+
import java.text.ParseException;
7+
8+
public class ReferenceDataSectionTest {
9+
10+
@Test
11+
public void testParse() throws ParseException {
12+
final String lineStart = "-59.000,+090.000,2016-01-01T08:00:00Z,ICECHART_DMI,0.0,-59.000,+090.000, ...";
13+
14+
final ReferenceDataSection section = new ReferenceDataSection();
15+
section.parseTime(lineStart);
16+
17+
TestUtil.assertCorrectUTCDate(2016, 1, 1, 8, 0, 0, section.getTime());
18+
}
19+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
import com.bc.fiduceo.IOTestRunner;
44
import com.bc.fiduceo.TestUtil;
5+
import com.bc.fiduceo.core.NodeType;
6+
import com.bc.fiduceo.reader.AcquisitionInfo;
57
import org.junit.Before;
68
import org.junit.Test;
79
import org.junit.runner.RunWith;
810

911
import java.io.File;
1012
import java.io.IOException;
1113

14+
import static org.junit.Assert.assertEquals;
15+
import static org.junit.Assert.assertNull;
16+
1217
@RunWith(IOTestRunner.class)
1318
public class SciCciInsituReader_IO_Test {
1419

@@ -26,6 +31,13 @@ public void testReadAcquisitionInfo() throws IOException {
2631

2732
try {
2833
reader.open(testFile);
34+
35+
final AcquisitionInfo acquisitionInfo = reader.read();
36+
TestUtil.assertCorrectUTCDate(2016, 1, 1, 1, 0, 0, acquisitionInfo.getSensingStart());
37+
TestUtil.assertCorrectUTCDate(2016, 12, 31, 16, 0, 0, acquisitionInfo.getSensingStop());
38+
39+
assertEquals(NodeType.UNDEFINED, acquisitionInfo.getNodeType());
40+
assertNull(acquisitionInfo.getBoundingGeometry());
2941
} finally {
3042
reader.close();
3143
}

0 commit comments

Comments
 (0)