Exemplo n.º 1
0
 def test_datetime_GT(self):
     bdt = datetime(2015, 11, 3, 1, 1, 1, tzinfo=timezone.utc)
     observed_range = TimestampFilter(value=utils.pb_timestamp(bdt),
                                      rel_type=FilterRelationship.GT)
     stac_request = StacRequest(observed=observed_range)
     stac_item = client.search_one(stac_request)
     self.assertIsNotNone(stac_item)
     self.assertLessEqual(
         utils.pb_timestamp(bdt).seconds, stac_item.datetime.seconds)
Exemplo n.º 2
0
 def test_date_GT_OR_EQ(self):
     bd = date(2015, 11, 3)
     observed_range = TimestampField(value=utils.pb_timestamp(bd),
                                     rel_type=FieldRelationship.GT_OR_EQ)
     stac_request = StacRequest(observed=observed_range)
     stac_item = client.search_one(stac_request)
     self.assertIsNotNone(stac_item)
     self.assertLessEqual(
         utils.pb_timestamp(bd).seconds, stac_item.datetime.seconds)
Exemplo n.º 3
0
 def test_datetime_not_range(self):
     start = datetime(2013, 4, 1, 12, 45, 59, tzinfo=timezone.utc)
     end = datetime(2014, 4, 1, 12, 45, 59, tzinfo=timezone.utc)
     observed_range = TimestampField(start=utils.pb_timestamp(start),
                                     stop=utils.pb_timestamp(end),
                                     rel_type=FieldRelationship.NOT_BETWEEN)
     stac_request = StacRequest(observed=observed_range, limit=5)
     for stac_item in client.search(stac_request):
         print(
             datetime.fromtimestamp(stac_item.datetime.seconds,
                                    tz=timezone.utc))
         self.assertTrue(
             utils.pb_timestamp(end).seconds < stac_item.datetime.seconds or
             utils.pb_timestamp(start).seconds > stac_item.datetime.seconds)
Exemplo n.º 4
0
 def test_datetime_range(self):
     start = datetime(2013, 4, 1, 12, 45, 59, tzinfo=timezone.utc)
     end = datetime(2014, 4, 1, 12, 45, 59, tzinfo=timezone.utc)
     observed_range = TimestampFilter(start=utils.pb_timestamp(start),
                                      end=utils.pb_timestamp(end),
                                      rel_type=FilterRelationship.BETWEEN)
     stac_request = StacRequest(observed=observed_range, limit=5)
     for stac_item in client.search(stac_request):
         print(
             datetime.fromtimestamp(stac_item.datetime.seconds,
                                    tz=timezone.utc))
         self.assertGreaterEqual(
             utils.pb_timestamp(end).seconds, stac_item.datetime.seconds)
         self.assertLessEqual(
             utils.pb_timestamp(start).seconds, stac_item.datetime.seconds)
Exemplo n.º 5
0
 def test_datetime_not_range_desc(self):
     start = datetime(2013, 4, 1, 12, 45, 59, tzinfo=timezone.utc)
     end = datetime(2014, 4, 1, 12, 45, 59, tzinfo=timezone.utc)
     observed_range = TimestampField(start=utils.pb_timestamp(start),
                                     stop=utils.pb_timestamp(end),
                                     rel_type=FieldRelationship.NOT_BETWEEN,
                                     sort_direction=enum.SortDirection.DESC)
     stac_request = StacRequest(observed=observed_range, limit=5)
     count = 0
     for stac_item in client.search(stac_request):
         count += 1
         print(
             datetime.fromtimestamp(stac_item.datetime.seconds,
                                    tz=timezone.utc))
         self.assertTrue(
             utils.pb_timestamp(end).seconds < stac_item.datetime.seconds)
     self.assertEqual(count, 5)
Exemplo n.º 6
0
    def test_durations(self):
        d = utils.duration(datetime(2016, 1, 1), datetime(2017, 1, 1))
        self.assertEquals(d.seconds, 31622400)
        d = utils.duration(date(2016, 1, 1), datetime(2017, 1, 1))
        self.assertEquals(d.seconds, 31622400)
        d = utils.duration(date(2016, 1, 1), date(2017, 1, 1))
        self.assertEquals(d.seconds, 31622400)
        d = utils.duration(datetime(2016, 1, 1), date(2017, 1, 1))
        self.assertEquals(d.seconds, 31622400)

        td = timedelta(seconds=d.seconds)
        d_end = datetime(2016, 1, 1) + td
        self.assertEquals(d_end.year, 2017)
        self.assertEquals(d_end.day, 1)
        self.assertEquals(d_end.month, 1)

        # FromDatetime for protobuf 3.6.1 throws "TypeError: can't subtract offset-naive and offset-aware datetimes"
        ts = utils.pb_timestamp(datetime(2016, 1, 1, tzinfo=timezone.utc))
        self.assertIsNotNone(ts)

        d = utils.duration(datetime(2017, 1, 1),
                           datetime(2017, 1, 1, 0, 0, 59))
        self.assertEquals(d.seconds, 59)

        now_local = datetime.now().astimezone()
        now_utc = datetime.now(tz=timezone.utc)
        d = utils.duration(now_local, now_utc)
        self.assertLess(d.seconds, 1)

        ts = utils.pb_timestamp(now_local)
        ts2 = timestamp_pb2.Timestamp()
        ts2.FromDatetime(now_local)
        self.assertEquals(ts.seconds, ts2.seconds)

        d = utils.duration(datetime(2016, 1, 1, 0, 0, 59, tzinfo=timezone.utc),
                           datetime(2016, 1, 1, 0, 1, 59, tzinfo=timezone.utc))
        self.assertEquals(d.seconds, 60)

        utc_now = now_local.astimezone(tz=timezone.utc)
        later_now = utc_now + timedelta(seconds=33)

        d = utils.duration(now_local, later_now)
        self.assertEquals(d.seconds, 33)
Exemplo n.º 7
0
 def test_date_LT_OR_EQ(self):
     bd = date(2014, 11, 3)
     observed_range = utils.pb_timestampfield(
         rel_type=FilterRelationship.LTE, value=bd)
     stac_request = StacRequest(observed=observed_range,
                                mission_enum=enum.Mission.NAIP)
     stac_item = client.search_one(stac_request)
     self.assertIsNotNone(stac_item)
     self.assertLessEqual(
         utils.pb_timestamp(bd).seconds, stac_item.datetime.seconds)
Exemplo n.º 8
0
    def test_2000(self):
        start = datetime(1999, 4, 1, 12, 45, 59, tzinfo=timezone.utc)
        end = datetime(1999, 4, 6, 12, 52, 59, tzinfo=timezone.utc)
        observed_range = utils.pb_timestampfield(
            rel_type=FilterRelationship.BETWEEN, start=start, end=end)

        stac_request = StacRequest(observed=observed_range,
                                   limit=20,
                                   landsat=LandsatRequest())
        for stac_item in client.search(stac_request):
            self.assertEqual(Mission.LANDSAT, stac_item.mission_enum)
            print(
                datetime.fromtimestamp(stac_item.datetime.seconds,
                                       tz=timezone.utc))
            self.assertGreaterEqual(
                utils.pb_timestamp(end).seconds, stac_item.datetime.seconds)
            self.assertLessEqual(
                utils.pb_timestamp(start).seconds, stac_item.datetime.seconds)

        self.assertEquals(2728, client.count(stac_request))
Exemplo n.º 9
0
    def test_count_more(self):
        start = datetime(2014, 4, 1, 12, 45, 59, tzinfo=timezone.utc)
        end = datetime(2014, 4, 1, 12, 52, 59, tzinfo=timezone.utc)
        observed_range = TimestampFilter(start=utils.pb_timestamp(start),
                                         end=utils.pb_timestamp(end),
                                         rel_type=FilterRelationship.BETWEEN)

        stac_request = StacRequest(observed=observed_range,
                                   limit=40,
                                   landsat=LandsatRequest())
        for stac_item in client.search(stac_request):
            self.assertEquals(Mission.LANDSAT, stac_item.mission_enum)
            print(
                datetime.fromtimestamp(stac_item.datetime.seconds,
                                       tz=timezone.utc))
            self.assertGreaterEqual(
                utils.pb_timestamp(end).seconds, stac_item.datetime.seconds)
            self.assertLessEqual(
                utils.pb_timestamp(start).seconds, stac_item.datetime.seconds)

        self.assertEquals(12, client.count(stac_request))
 def updated(self, value: Union[datetime, date]):
     self.stac_item.updated.CopyFrom(utils.pb_timestamp(d_utc=value))
 def observed(self, value: Union[datetime, date]):
     self.stac_item.datetime.CopyFrom(utils.pb_timestamp(d_utc=value))
     self.stac_item.observed.CopyFrom(utils.pb_timestamp(d_utc=value))
 def end_observed(self, value: Union[datetime, date]):
     self.stac_item.end_observation.CopyFrom(
         utils.pb_timestamp(d_utc=value))
     self.stac_item.end_datetime.CopyFrom(utils.pb_timestamp(d_utc=value))