private static String formatTimeString(Product product) { final SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH); final ProductData.UTC startTime = product.getStartTime(); return dateFormat.format(startTime.getAsDate()); }
private static long getCenterDateAsModifiedJulianDay(Product product) { final ProductData.UTC startTime = product.getStartTime(); final ProductData.UTC endTime = product.getEndTime(); final long endMillies = endTime.getAsDate().getTime(); final long startMillies = startTime.getAsDate().getTime(); final long centerMillies = (endMillies - startMillies) / 2 + startMillies; final Date centerUTCDate = new Date(centerMillies); return utcToModifiedJulianDay(centerUTCDate); }
private Product createProjectedProduct(Product toReproject, Product crsReference) { final Map<String, Product> productMap = getProductMap(toReproject, crsReference); final Map<String, Object> parameterMap = new HashMap<String, Object>(); parameterMap.put("resamplingName", "Nearest"); parameterMap.put("includeTiePointGrids", false); parameterMap.put("addDeltaBands", false); // @todo - generalise final Product reprojectedProduct = GPF.createProduct("Reproject", parameterMap, productMap); reprojectedProduct.setStartTime(toReproject.getStartTime()); reprojectedProduct.setEndTime(toReproject.getEndTime()); return reprojectedProduct; }
private boolean containsStartAndEndDate(Product product) { boolean valid = product.getStartTime() != null && product.getEndTime() != null; if (!valid) { logSkipped("The product '" + product.getName() + "' must contain start and end time."); } return valid; }
private void addSolarAzimuthAngleIfPossible(final Product product, final MetadataElement element) { try { final Calendar calendar = product.getStartTime().getAsCalendar(); final double lat = Double.parseDouble(chrisFile.getGlobalAttribute(ChrisConstants.ATTR_NAME_TARGET_LAT)); final double lon = Double.parseDouble(chrisFile.getGlobalAttribute(ChrisConstants.ATTR_NAME_TARGET_LON)); final double saa = SunPositionCalculator.calculate(calendar, lat, lon).getAzimuthAngle(); final ProductData data = ProductData.createInstance(String.format("%05.2f", saa)); element.addAttribute(new MetadataAttribute(ChrisConstants.ATTR_NAME_SOLAR_AZIMUTH_ANGLE, data, true)); } catch (Exception e) { // ignore } }
private void autoAdjustTimeInformation(ProductData.UTC rasterStartTime, ProductData.UTC rasterEndTime) { ProductData.UTC tsStartTime = tsProduct.getStartTime(); if (tsStartTime == null || rasterStartTime.getAsDate().before(tsStartTime.getAsDate())) { tsProduct.setStartTime(rasterStartTime); } ProductData.UTC tsEndTime = tsProduct.getEndTime(); if (tsEndTime == null || rasterEndTime.getAsDate().after(tsEndTime.getAsDate())) { tsProduct.setEndTime(rasterEndTime); } }
private boolean startTimeMustBeBeforeEnd(Product product) { final double startMJD = product.getStartTime().getMJD(); final double stopMJD = product.getEndTime().getMJD(); final boolean valid = startMJD < stopMJD; if (!valid) { logSkipped("The product '" + product.getName() + "' has an end time which is before start time."); } return valid; }
private boolean timeRangeIsLessThan367Days(Product product) { final double startMJD = product.getStartTime().getMJD(); final double stopMJD = product.getEndTime().getMJD(); final boolean valid = stopMJD - startMJD < 367; if (!valid) { logSkipped("The product '" + product.getName() + "' covers more than one year."); } return valid; }
@Test public void testRejectProduct_ProductsStartTimeEqualsRangeStartTime() throws Exception { when(product.getStartTime()).thenReturn(ProductData.UTC.parse("02-MAY-2013 00:00:00")); when(product.getEndTime()).thenReturn(ProductData.UTC.parse("02-MAY-2013 01:00:00")); assertThat(timeRangeProductFilter.accept(product), is(true)); assertThat(timeRangeProductFilter.getReason(), is(nullValue())); }
@Test public void testRejectProduct_ProductsEndTimeEqualsRangeEndTime() throws Exception { when(product.getStartTime()).thenReturn(ProductData.UTC.parse("02-MAY-2013 23:00:00")); when(product.getEndTime()).thenReturn(ProductData.UTC.parse("02-MAY-2013 23:59:59")); assertThat(timeRangeProductFilter.accept(product), is(true)); assertThat(timeRangeProductFilter.getReason(), is(nullValue())); } }
@Test public void testRejectProduct_ProductsStartTimeIsInsideRange() throws Exception { when(product.getStartTime()).thenReturn(ProductData.UTC.parse("02-MAY-2013 23:30:00")); when(product.getEndTime()).thenReturn(ProductData.UTC.parse("03-MAY-2013 00:30:00")); assertThat(timeRangeProductFilter.accept(product), is(true)); assertThat(timeRangeProductFilter.getReason(), is(nullValue())); }
@Test public void testRejectProduct_ProductsEndTimeIsInsideRange() throws Exception { when(product.getStartTime()).thenReturn(ProductData.UTC.parse("01-MAY-2013 23:30:00")); when(product.getEndTime()).thenReturn(ProductData.UTC.parse("02-MAY-2013 00:30:00")); assertThat(timeRangeProductFilter.accept(product), is(true)); assertThat(timeRangeProductFilter.getReason(), is(nullValue())); }
@Test public void testRejectProduct_ProductsStartAndEndTimesAreBothBeforeRange() throws Exception { when(product.getStartTime()).thenReturn(ProductData.UTC.parse("01-MAY-2013 15:10:00")); when(product.getEndTime()).thenReturn(ProductData.UTC.parse("01-MAY-2013 15:40:00")); assertThat(timeRangeProductFilter.accept(product), is(false)); assertThat(timeRangeProductFilter.getReason(), is("Does not match the time range.")); }
@Test public void testRejectProduct_ProductsStartAndEndTimesAreBothAfterRange() throws Exception { when(product.getStartTime()).thenReturn(ProductData.UTC.parse("03-MAY-2013 15:10:00")); when(product.getEndTime()).thenReturn(ProductData.UTC.parse("03-MAY-2013 15:40:00")); assertThat(timeRangeProductFilter.accept(product), is(false)); assertThat(timeRangeProductFilter.getReason(), is("Does not match the time range.")); }
private void testStartTime(final Product product) { final ProductData.UTC utc = product.getStartTime(); assertNotNull(utc); final Calendar startTime = utc.getAsCalendar(); assertEquals(2002, startTime.get(Calendar.YEAR)); assertEquals(11, startTime.get(Calendar.MONTH)); assertEquals(24, startTime.get(Calendar.DATE)); assertEquals(11, startTime.get(Calendar.HOUR_OF_DAY)); assertEquals(12, startTime.get(Calendar.MINUTE)); assertEquals(13, startTime.get(Calendar.SECOND)); }
private void initProductStartStopParams() { final ParamProperties startProperties = createStartStopProperty("Start time", "Product start time (UTC)"); final ProductData.UTC startTime = product.getStartTime(); Date startDate = startTime != null ? startTime.getAsDate() : null; paramStartTime = new Parameter("startTime", startDate, startProperties); final ParamProperties endProperties = createStartStopProperty("End time", "Product end time (UTC)"); final ProductData.UTC endTime = product.getEndTime(); Date endDate = endTime != null ? endTime.getAsDate() : null; paramEndTime = new Parameter("endTime", endDate, endProperties); }
@Override public void copyTimeCoding() { getTargetProduct().setStartTime(getSourceProduct().getStartTime()); getTargetProduct().setEndTime(getSourceProduct().getEndTime()); }
@Test public void testStartAndEndTime() throws Exception { parameterMap.put("crs", UTM33N_CODE); final Product targetPoduct = createReprojectedProduct(); assertNotNull(targetPoduct.getStartTime()); assertNotNull(targetPoduct.getEndTime()); String meanTime = "02-JAN-2008 10:30:30.000000"; assertEquals(meanTime, targetPoduct.getStartTime().format()); assertEquals(meanTime, targetPoduct.getEndTime().format()); }
@Test public void testDecode_testfile_1() throws Exception { ctx = new TestProfileReadContext("../../../test.nc"); assertNull(product.getStartTime()); assertNull(product.getEndTime()); cfTimePart.decode(ctx, product); long expectedStartTime = ProductData.UTC.parse("2002-12-24 11:12:13", "yyyy-MM-dd HH:mm:ss").getAsDate().getTime(); long expectedEndTime = ProductData.UTC.parse("2002-12-24 11:12:14", "yyyy-MM-dd HH:mm:ss").getAsDate().getTime(); assertEquals(expectedStartTime, product.getStartTime().getAsDate().getTime()); assertEquals(expectedEndTime, product.getEndTime().getAsDate().getTime()); }
@Test public void testDecode_testfile_2() throws Exception { ctx = new TestProfileReadContext("../../../test_2.nc"); assertNull(product.getStartTime()); assertNull(product.getEndTime()); cfTimePart.decode(ctx, product); long expectedStartTime = ProductData.UTC.parse("2002-12-31 11:12:13", "yyyy-MM-dd HH:mm:ss").getAsDate().getTime(); long expectedEndTime = ProductData.UTC.parse("2002-12-31 22:12:14", "yyyy-MM-dd HH:mm:ss").getAsDate().getTime(); assertEquals(expectedStartTime, product.getStartTime().getAsDate().getTime()); assertEquals(expectedEndTime, product.getEndTime().getAsDate().getTime()); }