|
3 | 3 | import com.bc.fiduceo.IOTestRunner; |
4 | 4 | import com.bc.fiduceo.NCTestUtils; |
5 | 5 | import com.bc.fiduceo.TestUtil; |
| 6 | +import com.bc.fiduceo.core.Dimension; |
6 | 7 | import com.bc.fiduceo.core.Interval; |
7 | 8 | import com.bc.fiduceo.core.NodeType; |
| 9 | +import com.bc.fiduceo.geometry.GeometryFactory; |
| 10 | +import com.bc.fiduceo.geometry.Polygon; |
8 | 11 | import com.bc.fiduceo.reader.AcquisitionInfo; |
| 12 | +import com.bc.fiduceo.reader.time.TimeLocator; |
9 | 13 | import org.junit.After; |
10 | 14 | import org.junit.Before; |
11 | 15 | import org.junit.Test; |
12 | 16 | import org.junit.runner.RunWith; |
13 | 17 | import ucar.ma2.Array; |
| 18 | +import ucar.ma2.ArrayInt; |
14 | 19 | import ucar.ma2.DataType; |
15 | 20 | import ucar.nc2.Variable; |
16 | 21 |
|
17 | 22 | import java.io.File; |
18 | 23 | import java.io.IOException; |
| 24 | +import java.util.Arrays; |
19 | 25 | import java.util.List; |
20 | 26 |
|
21 | 27 | import static org.junit.Assert.*; |
@@ -221,6 +227,110 @@ public void testReadRaw_xbt_uniqueId() throws Exception { |
221 | 227 | NCTestUtils.assertValueAt(2002040001657855L, 0, 0, idArray); |
222 | 228 | } |
223 | 229 |
|
| 230 | + @Test |
| 231 | + public void testReadAcquisitionTime_drifter() throws Exception { |
| 232 | + openFile("SSTCCI2_refdata_drifter_201304.nc"); |
| 233 | + final ArrayInt.D2 array = insituReader.readAcquisitionTime(0, 9, new Interval(3, 3)); |
| 234 | + |
| 235 | + assertNotNull(array); |
| 236 | + assertArrayEquals(new int[]{3, 3}, array.getShape()); |
| 237 | + assertEquals(DataType.INT, array.getDataType()); |
| 238 | + |
| 239 | + NCTestUtils.assertValueAt(-2147483647, 0, 0, array); |
| 240 | + NCTestUtils.assertValueAt(-2147483647, 1, 0, array); |
| 241 | + NCTestUtils.assertValueAt(-2147483647, 2, 0, array); |
| 242 | + NCTestUtils.assertValueAt(-2147483647, 0, 1, array); |
| 243 | + NCTestUtils.assertValueAt(1364774400, 1, 1, array); |
| 244 | + NCTestUtils.assertValueAt(-2147483647, 2, 1, array); |
| 245 | + NCTestUtils.assertValueAt(-2147483647, 0, 2, array); |
| 246 | + NCTestUtils.assertValueAt(-2147483647, 1, 2, array); |
| 247 | + NCTestUtils.assertValueAt(-2147483647, 2, 2, array); |
| 248 | + } |
| 249 | + |
| 250 | + @Test |
| 251 | + public void testReadAcquisitionTime_mooring() throws Exception { |
| 252 | + openFile("SSTCCI2_refdata_mooring_201602.nc"); |
| 253 | + final ArrayInt.D2 array = insituReader.readAcquisitionTime(0, 10, new Interval(1, 1)); |
| 254 | + |
| 255 | + assertNotNull(array); |
| 256 | + assertArrayEquals(new int[]{1, 1}, array.getShape()); |
| 257 | + assertEquals(DataType.INT, array.getDataType()); |
| 258 | + |
| 259 | + NCTestUtils.assertValueAt(1454284800, 0, 0, array); |
| 260 | + } |
| 261 | + |
| 262 | + @Test |
| 263 | + public void testGetProductSize_xbt() throws Exception { |
| 264 | + openFile("SSTCCI2_refdata_xbt_200204.nc"); |
| 265 | + final Dimension productSize = insituReader.getProductSize(); |
| 266 | + |
| 267 | + assertNotNull(productSize); |
| 268 | + assertEquals("product_size", productSize.getName()); |
| 269 | + assertEquals(1, productSize.getNx()); |
| 270 | + assertEquals(1339, productSize.getNy()); |
| 271 | + } |
| 272 | + |
| 273 | + @Test |
| 274 | + public void testGetProductSize_drifter() throws Exception { |
| 275 | + openFile("SSTCCI2_refdata_drifter_201304.nc"); |
| 276 | + final Dimension productSize = insituReader.getProductSize(); |
| 277 | + |
| 278 | + assertNotNull(productSize); |
| 279 | + assertEquals("product_size", productSize.getName()); |
| 280 | + assertEquals(1, productSize.getNx()); |
| 281 | + assertEquals(671404, productSize.getNy()); |
| 282 | + } |
| 283 | + |
| 284 | + @Test |
| 285 | + public void testGetTimeLocator_mooring() throws Exception { |
| 286 | + openFile("SSTCCI2_refdata_mooring_201602.nc"); |
| 287 | + final TimeLocator timeLocator = insituReader.getTimeLocator(); |
| 288 | + |
| 289 | + assertNotNull(timeLocator); |
| 290 | + assertEquals(1454284800000L, timeLocator.getTimeFor(0, 11)); |
| 291 | + assertEquals(1454284800000L, timeLocator.getTimeFor(1, 12)); |
| 292 | + assertEquals(1454284800000L, timeLocator.getTimeFor(2, 13)); |
| 293 | + } |
| 294 | + |
| 295 | + @Test |
| 296 | + public void testGetTimeLocator_xbt() throws Exception { |
| 297 | + openFile("SSTCCI2_refdata_xbt_200204.nc"); |
| 298 | + final TimeLocator timeLocator = insituReader.getTimeLocator(); |
| 299 | + |
| 300 | + assertNotNull(timeLocator); |
| 301 | + assertEquals(1017639360000L, timeLocator.getTimeFor(3, 14)); |
| 302 | + assertEquals(1017641772000L, timeLocator.getTimeFor(4, 15)); |
| 303 | + assertEquals(1017644292000L, timeLocator.getTimeFor(5, 16)); |
| 304 | + } |
| 305 | + |
| 306 | + @Test |
| 307 | + public void testGetPixelLocator() throws Exception { |
| 308 | + openFile("SSTCCI2_refdata_drifter_201304.nc"); |
| 309 | + |
| 310 | + try { |
| 311 | + insituReader.getPixelLocator(); |
| 312 | + fail("RuntimeException expected"); |
| 313 | + } catch (RuntimeException expected) { |
| 314 | + } |
| 315 | + } |
| 316 | + |
| 317 | + @Test |
| 318 | + public void testGetSubScenePixelLocator() throws Exception { |
| 319 | + openFile("SSTCCI2_refdata_mooring_201602.nc"); |
| 320 | + final GeometryFactory geometryFactory = new GeometryFactory(GeometryFactory.Type.S2); |
| 321 | + final Polygon polygon = geometryFactory.createPolygon(Arrays.asList( |
| 322 | + geometryFactory.createPoint(4, 5), |
| 323 | + geometryFactory.createPoint(5, 6), |
| 324 | + geometryFactory.createPoint(6, 5) |
| 325 | + )); |
| 326 | + |
| 327 | + try { |
| 328 | + insituReader.getSubScenePixelLocator(polygon); |
| 329 | + fail("RuntimeException expected"); |
| 330 | + } catch (RuntimeException expected) { |
| 331 | + } |
| 332 | + } |
| 333 | + |
224 | 334 | private void openFile(String fileName) throws IOException { |
225 | 335 | final String testFilePath = TestUtil.assembleFileSystemPath(new String[]{"insitu", "sirds", "v1.0", fileName}, false); |
226 | 336 | final File insituDataFile = TestUtil.getTestDataFileAsserted(testFilePath); |
|
0 commit comments