SpatialDataPeriod implements DataPeriod { @Override public Membership getObservationMembership(double lon, double time) { final double h = 24.0 * (time - startTime); final double h0 = minDataHour + (lon + 180.0) * SLOPE; if (h - EPS < h0) { return Membership.PREVIOUS_PERIODS; } else if (h + EPS > h0 + 24.0 * duration) { return Membership.SUBSEQUENT_PERIODS; } else { return Membership.CURRENT_PERIOD; } } SpatialDataPeriod(double startTime, double duration, double minDataHour); @Override Membership getObservationMembership(double lon, double time);  }
@Test public void testIt() throws Exception { final double T0 = 53637.21235; final double H = 1 / 24.; final SpatialDataPeriod p = new SpatialDataPeriod(T0, 1, 10.0); assertEquals(DataPeriod.Membership.PREVIOUS_PERIODS, p.getObservationMembership(-180, T0 - 12 * H)); assertEquals(DataPeriod.Membership.PREVIOUS_PERIODS, p.getObservationMembership(-180, T0 - 6 * H)); assertEquals(DataPeriod.Membership.PREVIOUS_PERIODS, p.getObservationMembership(-180, T0 + 0 * H)); assertEquals(DataPeriod.Membership.PREVIOUS_PERIODS, p.getObservationMembership(-180, T0 + 6 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(-180, T0 + 12 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(-180, T0 + 18 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(-180, T0 + 24 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(-180, T0 + (24 + 6) * H)); assertEquals(DataPeriod.Membership.SUBSEQUENT_PERIODS, p.getObservationMembership(-180, T0 + (24 + 12) * H)); assertEquals(DataPeriod.Membership.PREVIOUS_PERIODS, p.getObservationMembership(-135, T0 - 12 * H)); assertEquals(DataPeriod.Membership.PREVIOUS_PERIODS, p.getObservationMembership(-135, T0 - 6 * H)); assertEquals(DataPeriod.Membership.PREVIOUS_PERIODS, p.getObservationMembership(-135, T0 + 0 * H)); assertEquals(DataPeriod.Membership.PREVIOUS_PERIODS, p.getObservationMembership(-135, T0 + 6 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(-135, T0 + 12 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(-135, T0 + 18 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(-135, T0 + 24 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(-135, T0 + (24 + 6) * H)); assertEquals(DataPeriod.Membership.SUBSEQUENT_PERIODS, p.getObservationMembership(-135, T0 + (24 + 12) * H)); assertEquals(DataPeriod.Membership.PREVIOUS_PERIODS, p.getObservationMembership(-90, T0 - 12 * H)); assertEquals(DataPeriod.Membership.PREVIOUS_PERIODS, p.getObservationMembership(-90, T0 - 6 * H)); assertEquals(DataPeriod.Membership.PREVIOUS_PERIODS, p.getObservationMembership(-90, T0 + 0 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(-90, T0 + 6 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(-90, T0 + 12 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(-90, T0 + 18 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(-90, T0 + 24 * H)); assertEquals(DataPeriod.Membership.SUBSEQUENT_PERIODS, p.getObservationMembership(-90, T0 + (24 + 6) * H)); assertEquals(DataPeriod.Membership.SUBSEQUENT_PERIODS, p.getObservationMembership(-90, T0 + (24 + 12) * H)); assertEquals(DataPeriod.Membership.PREVIOUS_PERIODS, p.getObservationMembership(0, T0 - 12 * H)); assertEquals(DataPeriod.Membership.PREVIOUS_PERIODS, p.getObservationMembership(0, T0 - 6 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(0, T0 + 0 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(0, T0 + 6 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(0, T0 + 12 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(0, T0 + 18 * H)); assertEquals(DataPeriod.Membership.SUBSEQUENT_PERIODS, p.getObservationMembership(0, T0 + 24 * H)); assertEquals(DataPeriod.Membership.SUBSEQUENT_PERIODS, p.getObservationMembership(0, T0 + (24 + 6) * H)); assertEquals(DataPeriod.Membership.SUBSEQUENT_PERIODS, p.getObservationMembership(0, T0 + (24 + 12) * H)); assertEquals(DataPeriod.Membership.PREVIOUS_PERIODS, p.getObservationMembership(90, T0 - 12 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(90, T0 - 6 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(90, T0 + 0 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(90, T0 + 6 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(90, T0 + 12 * H)); assertEquals(DataPeriod.Membership.SUBSEQUENT_PERIODS, p.getObservationMembership(90, T0 + 18 * H)); assertEquals(DataPeriod.Membership.SUBSEQUENT_PERIODS, p.getObservationMembership(90, T0 + 24 * H)); assertEquals(DataPeriod.Membership.SUBSEQUENT_PERIODS, p.getObservationMembership(90, T0 + (24 + 6) * H)); assertEquals(DataPeriod.Membership.SUBSEQUENT_PERIODS, p.getObservationMembership(90, T0 + (24 + 12) * H)); assertEquals(DataPeriod.Membership.PREVIOUS_PERIODS, p.getObservationMembership(135, T0 - 12 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(135, T0 - 6 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(135, T0 + 0 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(135, T0 + 6 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(135, T0 + 12 * H)); assertEquals(DataPeriod.Membership.SUBSEQUENT_PERIODS, p.getObservationMembership(135, T0 + 18 * H)); assertEquals(DataPeriod.Membership.SUBSEQUENT_PERIODS, p.getObservationMembership(135, T0 + 24 * H)); assertEquals(DataPeriod.Membership.SUBSEQUENT_PERIODS, p.getObservationMembership(135, T0 + (24 + 6) * H)); assertEquals(DataPeriod.Membership.SUBSEQUENT_PERIODS, p.getObservationMembership(135, T0 + (24 + 12) * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(179, T0 - 12 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(179, T0 - 6 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(179, T0 + 0 * H)); assertEquals(DataPeriod.Membership.CURRENT_PERIOD, p.getObservationMembership(179, T0 + 6 * H)); assertEquals(DataPeriod.Membership.SUBSEQUENT_PERIODS, p.getObservationMembership(179, T0 + 12 * H)); assertEquals(DataPeriod.Membership.SUBSEQUENT_PERIODS, p.getObservationMembership(179, T0 + 18 * H)); assertEquals(DataPeriod.Membership.SUBSEQUENT_PERIODS, p.getObservationMembership(179, T0 + 24 * H)); assertEquals(DataPeriod.Membership.SUBSEQUENT_PERIODS, p.getObservationMembership(179, T0 + (24 + 6) * H)); assertEquals(DataPeriod.Membership.SUBSEQUENT_PERIODS, p.getObservationMembership(179, T0 + (24 + 12) * H)); }