Exemple #1
0
 def test_both(self) -> None:
     orbit_state = sat.OrbitState.DESCENDING
     relative_orbit = 4321
     SatExtension.ext(self.item).apply(orbit_state, relative_orbit)
     self.assertEqual(orbit_state, SatExtension.ext(self.item).orbit_state)
     self.assertEqual(relative_orbit, SatExtension.ext(self.item).relative_orbit)
     self.item.validate()
Exemple #2
0
 def test_relative_orbit(self) -> None:
     relative_orbit = 1234
     SatExtension.ext(self.item).apply(None, relative_orbit)
     self.assertEqual(relative_orbit, SatExtension.ext(self.item).relative_orbit)
     self.assertNotIn(sat.ORBIT_STATE_PROP, self.item.properties)
     self.assertIsNone(SatExtension.ext(self.item).orbit_state)
     self.item.validate()
Exemple #3
0
 def test_orbit_state(self) -> None:
     orbit_state = sat.OrbitState.ASCENDING
     SatExtension.ext(self.item).apply(orbit_state)
     self.assertEqual(orbit_state, SatExtension.ext(self.item).orbit_state)
     self.assertNotIn(sat.RELATIVE_ORBIT_PROP, self.item.properties)
     self.assertIsNone(SatExtension.ext(self.item).relative_orbit)
     self.item.validate()
Exemple #4
0
 def test_absolute_orbit(self) -> None:
     absolute_orbit = 1234
     SatExtension.ext(self.item).apply(absolute_orbit=absolute_orbit)
     self.assertEqual(absolute_orbit, SatExtension.ext(self.item).absolute_orbit)
     self.assertNotIn(sat.RELATIVE_ORBIT_PROP, self.item.properties)
     self.assertIsNone(SatExtension.ext(self.item).relative_orbit)
     self.item.validate()
Exemple #5
0
 def test_anx_datetime(self) -> None:
     anx_datetime = str_to_datetime("2020-01-01T00:00:00Z")
     SatExtension.ext(self.item).apply(anx_datetime=anx_datetime)
     self.assertEqual(anx_datetime, SatExtension.ext(self.item).anx_datetime)
     self.assertNotIn(sat.RELATIVE_ORBIT_PROP, self.item.properties)
     self.assertIsNone(SatExtension.ext(self.item).relative_orbit)
     self.item.validate()
Exemple #6
0
    def test_to_from_dict(self) -> None:
        orbit_state = sat.OrbitState.GEOSTATIONARY
        relative_orbit = 1002
        SatExtension.ext(self.item).apply(orbit_state, relative_orbit)
        d = self.item.to_dict()
        self.assertEqual(orbit_state.value, d["properties"][sat.ORBIT_STATE_PROP])
        self.assertEqual(relative_orbit, d["properties"][sat.RELATIVE_ORBIT_PROP])

        item = pystac.Item.from_dict(d)
        self.assertEqual(orbit_state, SatExtension.ext(item).orbit_state)
        self.assertEqual(relative_orbit, SatExtension.ext(item).relative_orbit)
Exemple #7
0
 def test_platform_international_designator(self) -> None:
     platform_international_designator = "2018-080A"
     SatExtension.ext(self.item).apply(
         platform_international_designator=platform_international_designator
     )
     self.assertEqual(
         platform_international_designator,
         SatExtension.ext(self.item).platform_international_designator,
     )
     self.assertNotIn(sat.ORBIT_STATE_PROP, self.item.properties)
     self.assertIsNone(SatExtension.ext(self.item).orbit_state)
     self.item.validate()
Exemple #8
0
    def test_item_ext_add_to(self) -> None:
        item = pystac.Item.from_file(self.sentinel_example_uri)
        item.stac_extensions.remove(SatExtension.get_schema_uri())
        self.assertNotIn(SatExtension.get_schema_uri(), item.stac_extensions)

        _ = SatExtension.ext(item, add_if_missing=True)

        self.assertIn(SatExtension.get_schema_uri(), item.stac_extensions)
Exemple #9
0
    def test_extension_not_implemented(self) -> None:
        # Should raise exception if Item does not include extension URI
        item = pystac.Item.from_file(self.sentinel_example_uri)
        item.stac_extensions.remove(SatExtension.get_schema_uri())

        with self.assertRaises(pystac.ExtensionNotImplemented):
            _ = SatExtension.ext(item)

        # Should raise exception if owning Item does not include extension URI
        asset = item.assets["measurement_iw1_vh"]

        with self.assertRaises(pystac.ExtensionNotImplemented):
            _ = SatExtension.ext(asset)

        # Should succeed if Asset has no owner
        ownerless_asset = pystac.Asset.from_dict(asset.to_dict())
        _ = SatExtension.ext(ownerless_asset)
Exemple #10
0
    def test_asset_repr(self) -> None:
        item = pystac.Item.from_file(self.sentinel_example_uri)
        asset = item.assets["measurement_iw1_vh"]
        sat_asset_ext = SatExtension.ext(asset)

        self.assertEqual(
            f"<AssetSatExtension Asset href={asset.href}>", sat_asset_ext.__repr__()
        )
Exemple #11
0
    def test_asset_ext_add_to(self) -> None:
        item = pystac.Item.from_file(self.sentinel_example_uri)
        item.stac_extensions.remove(SatExtension.get_schema_uri())
        self.assertNotIn(SatExtension.get_schema_uri(), item.stac_extensions)
        asset = item.assets["measurement_iw1_vh"]

        _ = SatExtension.ext(asset, add_if_missing=True)

        self.assertIn(SatExtension.get_schema_uri(), item.stac_extensions)
Exemple #12
0
 def test_from_dict(self) -> None:
     orbit_state = sat.OrbitState.GEOSTATIONARY
     relative_orbit = 1001
     d: Dict[str, Any] = {
         "type": "Feature",
         "stac_version": "1.0.0-beta.2",
         "id": "an/asset",
         "properties": {
             "sat:orbit_state": orbit_state.value,
             "sat:relative_orbit": relative_orbit,
             "datetime": "2018-01-02T00:00:00Z",
         },
         "geometry": None,
         "links": [],
         "assets": {},
         "stac_extensions": [SatExtension.get_schema_uri()],
     }
     item = pystac.Item.from_dict(d)
     self.assertEqual(orbit_state, SatExtension.ext(item).orbit_state)
     self.assertEqual(relative_orbit, SatExtension.ext(item).relative_orbit)
Exemple #13
0
    def test_modify(self) -> None:
        SatExtension.ext(self.item).apply(sat.OrbitState.DESCENDING, 999)

        orbit_state = sat.OrbitState.GEOSTATIONARY
        SatExtension.ext(self.item).orbit_state = orbit_state
        relative_orbit = 1000
        SatExtension.ext(self.item).relative_orbit = relative_orbit
        self.assertEqual(orbit_state, SatExtension.ext(self.item).orbit_state)
        self.assertEqual(relative_orbit, SatExtension.ext(self.item).relative_orbit)
        self.item.validate()
Exemple #14
0
 def test_relative_orbit_no_negative(self) -> None:
     negative_relative_orbit = -2
     SatExtension.ext(self.item).apply(None, negative_relative_orbit)
     with self.assertRaises(pystac.STACValidationError):
         self.item.validate()
Exemple #15
0
    def test_clear_orbit_state(self) -> None:
        SatExtension.ext(self.item).apply(sat.OrbitState.DESCENDING, 999)

        SatExtension.ext(self.item).orbit_state = None
        self.assertIsNone(SatExtension.ext(self.item).orbit_state)
        self.item.validate()
Exemple #16
0
    def test_clear_relative_orbit(self) -> None:
        SatExtension.ext(self.item).apply(sat.OrbitState.DESCENDING, 999)

        SatExtension.ext(self.item).relative_orbit = None
        self.assertIsNone(SatExtension.ext(self.item).relative_orbit)
        self.item.validate()
Exemple #17
0
 def test_no_args_fails(self) -> None:
     SatExtension.ext(self.item).apply()
     with self.assertRaises(pystac.STACValidationError):
         self.item.validate()
Exemple #18
0
 def test_item_repr(self) -> None:
     sat_item_ext = SatExtension.ext(self.item)
     self.assertEqual(
         f"<ItemSatExtension Item id={self.item.id}>", sat_item_ext.__repr__()
     )