Skip to content

Commit 6cca815

Browse files
committed
started TAO reader
1 parent 5d8d9ce commit 6cca815

File tree

4 files changed

+241
-0
lines changed

4 files changed

+241
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package com.bc.fiduceo.reader.insitu.tao;
2+
3+
import com.bc.fiduceo.core.Dimension;
4+
import com.bc.fiduceo.core.Interval;
5+
import com.bc.fiduceo.geometry.Polygon;
6+
import com.bc.fiduceo.location.PixelLocator;
7+
import com.bc.fiduceo.reader.AcquisitionInfo;
8+
import com.bc.fiduceo.reader.Reader;
9+
import com.bc.fiduceo.reader.time.TimeLocator;
10+
import com.bc.fiduceo.util.NetCDFUtils;
11+
import com.bc.fiduceo.util.VariableProxy;
12+
import ucar.ma2.Array;
13+
import ucar.ma2.ArrayInt;
14+
import ucar.ma2.DataType;
15+
import ucar.ma2.InvalidRangeException;
16+
import ucar.nc2.Attribute;
17+
import ucar.nc2.Variable;
18+
19+
import java.io.File;
20+
import java.io.IOException;
21+
import java.util.ArrayList;
22+
import java.util.List;
23+
24+
import static com.bc.fiduceo.util.NetCDFUtils.*;
25+
26+
class TaoReader implements Reader {
27+
28+
private final static String REG_EX = "(?:TAO|TRITON)_\\w+_\\w+(-\\w+)??\\d{4}-\\d{2}.txt";
29+
30+
@Override
31+
public void open(File file) throws IOException {
32+
throw new RuntimeException("not implemented");
33+
}
34+
35+
@Override
36+
public void close() throws IOException {
37+
throw new RuntimeException("not implemented");
38+
}
39+
40+
@Override
41+
public AcquisitionInfo read() throws IOException {
42+
throw new RuntimeException("not implemented");
43+
}
44+
45+
@Override
46+
public String getRegEx() {
47+
return REG_EX;
48+
}
49+
50+
@Override
51+
public PixelLocator getPixelLocator() throws IOException {
52+
throw new RuntimeException("not implemented");
53+
}
54+
55+
@Override
56+
public PixelLocator getSubScenePixelLocator(Polygon sceneGeometry) throws IOException {
57+
throw new RuntimeException("not implemented");
58+
}
59+
60+
@Override
61+
public TimeLocator getTimeLocator() throws IOException {
62+
throw new RuntimeException("not implemented");
63+
}
64+
65+
@Override
66+
public int[] extractYearMonthDayFromFilename(String fileName) {
67+
throw new RuntimeException("not implemented");
68+
}
69+
70+
@Override
71+
public Array readRaw(int centerX, int centerY, Interval interval, String variableName) throws IOException, InvalidRangeException {
72+
throw new RuntimeException("not implemented");
73+
}
74+
75+
@Override
76+
public Array readScaled(int centerX, int centerY, Interval interval, String variableName) throws IOException, InvalidRangeException {
77+
throw new RuntimeException("not implemented");
78+
}
79+
80+
@Override
81+
public ArrayInt.D2 readAcquisitionTime(int x, int y, Interval interval) throws IOException, InvalidRangeException {
82+
throw new RuntimeException("not implemented");
83+
}
84+
85+
@Override
86+
public List<Variable> getVariables() throws InvalidRangeException, IOException {
87+
final ArrayList<Variable> variables = new ArrayList<>();
88+
89+
List<Attribute> attributes = new ArrayList<>();
90+
attributes.add(new Attribute(CF_UNITS_NAME, "degree_east"));
91+
attributes.add(new Attribute(CF_STANDARD_NAME, "longitude"));
92+
variables.add(new VariableProxy("longitude", DataType.FLOAT, attributes));
93+
94+
return variables;
95+
}
96+
97+
@Override
98+
public Dimension getProductSize() throws IOException {
99+
throw new RuntimeException("not implemented");
100+
}
101+
102+
@Override
103+
public String getLongitudeVariableName() {
104+
return "longitude";
105+
}
106+
107+
@Override
108+
public String getLatitudeVariableName() {
109+
return "latitude";
110+
}
111+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.bc.fiduceo.reader.insitu.tao;
2+
3+
import com.bc.fiduceo.reader.DataType;
4+
import com.bc.fiduceo.reader.Reader;
5+
import com.bc.fiduceo.reader.ReaderContext;
6+
import com.bc.fiduceo.reader.ReaderPlugin;
7+
8+
public class TaoReaderPlugin implements ReaderPlugin {
9+
10+
private final static String[] SENSOR_KEYS = {"tao-sss"};
11+
12+
@Override
13+
public Reader createReader(ReaderContext readerContext) {
14+
return new TaoReader();
15+
}
16+
17+
@Override
18+
public String[] getSupportedSensorKeys() {
19+
return SENSOR_KEYS;
20+
}
21+
22+
@Override
23+
public DataType getDataType() {
24+
return DataType.INSITU;
25+
}
26+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.bc.fiduceo.reader.insitu.tao;
2+
3+
import com.bc.fiduceo.reader.DataType;
4+
import com.bc.fiduceo.reader.Reader;
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
8+
import static org.junit.Assert.*;
9+
10+
public class TaoReaderPluginTest {
11+
12+
private TaoReaderPlugin plugin;
13+
14+
@Before
15+
public void setUp() {
16+
plugin = new TaoReaderPlugin();
17+
}
18+
19+
@Test
20+
public void testGetSupportedKeys() {
21+
final String[] expected = {"tao-sss"};
22+
23+
assertArrayEquals(expected, plugin.getSupportedSensorKeys());
24+
}
25+
26+
@Test
27+
public void testGetDataType() {
28+
assertEquals(DataType.INSITU, plugin.getDataType());
29+
}
30+
31+
@Test
32+
public void testCreateReader(){
33+
final Reader reader = plugin.createReader(null);
34+
assertTrue(reader instanceof TaoReader);
35+
}
36+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.bc.fiduceo.reader.insitu.tao;
2+
3+
import org.junit.Before;
4+
import org.junit.Test;
5+
import ucar.ma2.DataType;
6+
import ucar.ma2.InvalidRangeException;
7+
import ucar.nc2.Attribute;
8+
import ucar.nc2.Variable;
9+
10+
import java.io.IOException;
11+
import java.util.List;
12+
import java.util.regex.Matcher;
13+
import java.util.regex.Pattern;
14+
15+
import static com.bc.fiduceo.util.NetCDFUtils.CF_STANDARD_NAME;
16+
import static org.junit.Assert.assertEquals;
17+
import static org.junit.Assert.assertTrue;
18+
19+
public class TaoReaderTest {
20+
21+
private TaoReader reader;
22+
23+
@Before
24+
public void setUp() {
25+
reader = new TaoReader();
26+
}
27+
28+
@Test
29+
public void testGetRegEx() {
30+
final String expected = "(?:TAO|TRITON)_\\w+_\\w+(-\\w+)??\\d{4}-\\d{2}.txt";
31+
32+
assertEquals(expected, reader.getRegEx());
33+
final Pattern pattern = java.util.regex.Pattern.compile(expected);
34+
35+
Matcher matcher = pattern.matcher("TRITON_TR0N156E_1998_2016-07.txt");
36+
assertTrue(matcher.matches());
37+
38+
matcher = pattern.matcher("TAO_T0N170W_DM207A-20160829_2017-04.txt");
39+
assertTrue(matcher.matches());
40+
41+
matcher = pattern.matcher("TAO_T2S110W_DM233A-20170608_2018-02.txt");
42+
assertTrue(matcher.matches());
43+
}
44+
45+
@Test
46+
public void testGetLongitudeVariableName() {
47+
assertEquals("longitude", reader.getLongitudeVariableName());
48+
}
49+
50+
@Test
51+
public void testGetLatitudeVariableName() {
52+
assertEquals("latitude", reader.getLatitudeVariableName());
53+
}
54+
55+
@Test
56+
public void testGetVariables() throws InvalidRangeException, IOException {
57+
final List<Variable> variables = reader.getVariables();
58+
59+
assertEquals(1, variables.size());
60+
61+
Variable variable = variables.get(0);
62+
assertEquals("longitude", variable.getShortName());
63+
assertEquals(DataType.FLOAT, variable.getDataType());
64+
65+
Attribute attribute = variable.findAttribute(CF_STANDARD_NAME);
66+
assertEquals("longitude", attribute.getStringValue());
67+
}
68+
}

0 commit comments

Comments
 (0)