ProductRecordSource implements RecordSource { @Override public Iterable<Record> getRecords() throws Exception { return new Iterable<Record>() { @Override public Iterator<Record> iterator() { return new PixelPosRecordGenerator(pixelPosRecords.iterator()); } }; } ProductRecordSource(Product product,
                               Header referenceRecordHeader,
                               Iterable<PixelPosProvider.PixelPosRecord> pixelPosRecords,
                               MAConfig config,
                               AffineTransform transform); @Override Header getHeader(); @Override Iterable<Record> getRecords(); @Override String getTimeAndLocationColumnDescription(); static final String SOURCE_NAME_ATT_NAME; static final String PIXEL_X_ATT_NAME; static final String PIXEL_Y_ATT_NAME; static final String PIXEL_LAT_ATT_NAME; static final String PIXEL_LON_ATT_NAME; static final String PIXEL_TIME_ATT_NAME; static final String PIXEL_MASK_ATT_NAME; }
@Test public void testThatRecordsAreGeneratedForContainedCoordinates() throws Exception { MAConfig config = new MAConfig(); config.setMacroPixelSize(1); RecordSource input = new DefaultRecordSource(new TestHeader(true, "lat", "lon"), new TestRecord(0, new GeoPos(1, 0)), new TestRecord(1, new GeoPos(1, 1 - EPS)), new TestRecord(2, new GeoPos(0, 0)), new TestRecord(3, new GeoPos(0, 1 - EPS))); ProductRecordSource output = createProductRecordSource(2, 3, input, config); int n = 0; for (Record r : output.getRecords()) { assertSame(DefaultRecord.class, r.getClass()); assertNotNull(r); n++; } assertEquals(4, n); }
@Test public void testThatRecordsAreNotGeneratedForOutlyingCoordinates() throws Exception { DefaultRecordSource input = new DefaultRecordSource(new TestHeader(true, "lat", "lon"), new TestRecord(0, new GeoPos(-1, -1)), new TestRecord(1, new GeoPos(-1, 2)), new TestRecord(2, new GeoPos(-3, -1))); MAConfig config = new MAConfig(); config.setMacroPixelSize(1); ProductRecordSource output = createProductRecordSource(2, 3, input, config); int n = 0; for (Record r : output.getRecords()) { assertNotNull(r); n++; } assertEquals(0, n); }
@Test public void testTheIteratorForSourceRecordsThatAreInAndOutOfProductBoundaries() throws Exception { DefaultRecordSource input = new DefaultRecordSource(new TestHeader(true, "lat", "lon"), new TestRecord(0, new GeoPos(1, 0)), new TestRecord(1, new GeoPos(-1, 2)), new TestRecord(2, new GeoPos(1, 1 - EPS)), new TestRecord(3, new GeoPos(-1, -1)), new TestRecord(4, new GeoPos(0, 0)), new TestRecord(5, new GeoPos(0, 1 - EPS)), new TestRecord(6, new GeoPos(-3, -1))); MAConfig config = new MAConfig(); config.setMacroPixelSize(1); ProductRecordSource output = createProductRecordSource(2, 3, input, config); int n = 0; for (Record r : output.getRecords()) { assertNotNull(r); n++; } assertEquals(4, n); }
@Test public void testThatInputSortingWorks() throws Exception { DefaultRecordSource input = new DefaultRecordSource(new TestHeader(true, "lat", "lon"), new TestRecord(0, new GeoPos(0.0F, 0.0F)), new TestRecord(1, new GeoPos(0.0F, 1.0F - EPS)), new TestRecord(2, new GeoPos(1.0F, 0.0F)), new TestRecord(3, new GeoPos(0.5F, 0.5F)), new TestRecord(4, new GeoPos(1.0F, 1.0F - EPS))); final int PIXEL_Y = 3; MAConfig config1 = new MAConfig(); config1.setMacroPixelSize(1); config1.setCopyInput(false); ProductRecordSource sort = createProductRecordSource(2, 3, input, config1); List<Record> sorted = getRecords(sort); assertEquals(5, sorted.size()); assertEquals(0, ((int[]) sorted.get(0).getAttributeValues()[PIXEL_Y])[0]); assertEquals(0, ((int[]) sorted.get(1).getAttributeValues()[PIXEL_Y])[0]); assertEquals(1, ((int[]) sorted.get(2).getAttributeValues()[PIXEL_Y])[0]); assertEquals(2, ((int[]) sorted.get(3).getAttributeValues()[PIXEL_Y])[0]); assertEquals(2, ((int[]) sorted.get(4).getAttributeValues()[PIXEL_Y])[0]); }
@Test public void testThatGetRecordsFulfillsIterableContract() throws Exception { DefaultRecordSource input = new DefaultRecordSource(new TestHeader(true, "lat", "lon")); RecordUtils.addPointRecord(input, 1F, 0F); RecordUtils.addPointRecord(input, 1F, 1F - EPS); RecordUtils.addPointRecord(input, -2F, 1F - EPS); RecordUtils.addPointRecord(input, 0F, 0F); RecordUtils.addPointRecord(input, 0F, 1F - EPS); RecordUtils.addPointRecord(input, 0F, -1F - EPS); RecordUtils.addPointRecord(input, 5F, 0F); MAConfig config = new MAConfig(); config.setMacroPixelSize(1); ProductRecordSource output = createProductRecordSource(2, 3, input, config); Iterable<Record> records = output.getRecords(); assertNotNull(records); Iterator<Record> iterator = records.iterator(); assertTrue(iterator.hasNext()); assertNotNull(iterator.next()); assertTrue(iterator.hasNext()); assertNotNull(iterator.next()); assertTrue(iterator.hasNext()); assertNotNull(iterator.next()); assertTrue(iterator.hasNext()); assertNotNull(iterator.next()); assertFalse(iterator.hasNext()); assertFalse(iterator.hasNext()); assertFalse(iterator.hasNext()); try { iterator.next(); fail("NSEE expected"); } catch (NoSuchElementException e) { } }
@Test public void testGoodPixelExpressionCriterion() throws Exception { MAConfig config = new MAConfig(); config.setMacroPixelSize(1); config.setMaxTimeDifference(null); config.setGoodPixelExpression("feq(X, 1.5)"); RecordSource input = new DefaultRecordSource(new TestHeader(true, "latitude", "longitude"), RecordUtils.create(new GeoPos(0.0, 0.0), null), RecordUtils.create(new GeoPos(0.0, 1- EPS), null), RecordUtils.create(new GeoPos(0.5, 0.0), null), RecordUtils.create(new GeoPos(0.5, 1- EPS), null), RecordUtils.create(new GeoPos(1- EPS, 0.0), null), RecordUtils.create(new GeoPos(1- EPS, 1- EPS), null)); ProductRecordSource output = createProductRecordSource(2, 3, input, config); List<Record> records = getRecords(output); assertEquals(6, records.size()); int goodRecords = 0; int allMaskedRecords = 0; for (Record record : records) { String reason = (String) record.getAnnotationValues()[EXCLUSION_REASON_INDEX]; if (reason.isEmpty()) { goodRecords++; } else if (reason.equals(PixelExtractor.EXCLUSION_REASON_ALL_MASKED)) { allMaskedRecords++; } } assertEquals(3, goodRecords); assertEquals(3, allMaskedRecords); }
@Test public void test3x3MacroPixelGeneratesFloatArraysWith9Elements() throws Exception { MAConfig config = new MAConfig(); config.setCopyInput(false); config.setMacroPixelSize(3); int w = 2 * 3; int h = 3 * 3; float lon = 0.0F + 1.0F / (w - 1.0F); float lat = 1.0F - 1.0F / (h - 1.0F); RecordSource input = new DefaultRecordSource(new TestHeader(true, "latitude", "longitude"), RecordUtils.create(new GeoPos(lat, lon), null)); ProductRecordSource output = createProductRecordSource(w, h, input, config); List<Record> records = getRecords(output); assertEquals(1, records.size()); final int PIXEL_X = 2; final int PIXEL_Y = 3; final int B2 = 7; Object[] firstAttributeValues = records.get(0).getAttributeValues(); Object pixelXValue = firstAttributeValues[PIXEL_X]; assertEquals(int[].class, pixelXValue.getClass()); int[] actualX = (int[]) pixelXValue; assertEquals(9, actualX.length); assertArrayEquals(new int[]{0, 1, 2, 0, 1, 2, 0, 1, 2}, actualX); Object pixelYValue = firstAttributeValues[PIXEL_Y]; assertEquals(int[].class, pixelYValue.getClass()); int[] actualY = (int[]) pixelYValue; assertEquals(9, actualY.length); assertArrayEquals(new int[]{0, 0, 0, 1, 1, 1, 2, 2, 2}, actualY); Object b2Value = firstAttributeValues[B2]; assertEquals(int[].class, b2Value.getClass()); int[] actualB2 = (int[]) b2Value; assertEquals(9, actualB2.length); assertArrayEquals(new int[]{0, 0, 0, 1, 1, 1, 2, 2, 2}, actualB2); }
@Test public void testTimeCriterion() throws Exception { MAConfig config = new MAConfig(); config.setMacroPixelSize(1); config.setMaxTimeDifference(null); RecordSource input = new DefaultRecordSource(new DefaultHeader(true, true, "latitude", "longitude", "time"), RecordUtils.create(new GeoPos(0, 0), date("07-MAY-2010 11:25:00")), RecordUtils.create(new GeoPos(0, 1 - EPS), date("07-MAY-2010 10:25:00")), RecordUtils.create(new GeoPos(1, 0), date("07-MAY-2010 10:59:00")), RecordUtils.create(new GeoPos(1, 1 - EPS), date("07-MAY-2010 09:25:00"))); ProductRecordSource output = createProductRecordSource(2, 3, input, config); List<Record> records = getRecords(output); assertEquals(4, records.size()); config = new MAConfig(); config.setMacroPixelSize(1); config.setMaxTimeDifference("0.25"); input = new DefaultRecordSource(new DefaultHeader(true, true, "latitude", "longitude", "time"), RecordUtils.create(new GeoPos(0.5F, 0.5F), date("07-MAY-2010 11:26:00")), RecordUtils.create(new GeoPos(0.5F, 0.5F), date("07-JUN-2010 13:25:00")), RecordUtils.create(new GeoPos(0.5F, 0.5F), date("07-MAY-2010 10:59:00")), RecordUtils.create(new GeoPos(0.5F, 0.5F), date("07-MAY-2010 08:10:00"))); output = createProductRecordSource(2, 3, input, config); records = getRecords(output); assertEquals(1, records.size()); }