How to use pystac - 10 common examples

To help you get started, we’ve selected a few pystac examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github azavea / pystac / tests / serialization / test_migrate.py View on Github external
info = identify_stac_object(d)

                migrated_d, info = migrate_to_latest(d, info)

                migrated_info = identify_stac_object(migrated_d)

                self.assertEqual(migrated_info.object_type, info.object_type)
                self.assertEqual(migrated_info.version_range.latest_valid_version(),
                                 pystac.get_stac_version())
                self.assertEqual(set(migrated_info.common_extensions), set(info.common_extensions))
                self.assertEqual(set(migrated_info.custom_extensions), set(info.custom_extensions))

                # Test that PySTAC can read it without errors.
                if info.object_type != STACObjectType.ITEMCOLLECTION:
                    self.assertIsInstance(STAC_IO.stac_object_from_dict(migrated_d, href=path),
                                          STACObject)
github azavea / pystac / tests / serialization / test_migrate.py View on Github external
def test_migrate(self):
        collection_cache = CollectionCache()
        for example in self.examples:
            with self.subTest(example['path']):
                path = example['path']

                d = STAC_IO.read_json(path)
                if identify_stac_object_type(d) == STACObjectType.ITEM:
                    merge_common_properties(d, json_href=path, collection_cache=collection_cache)

                info = identify_stac_object(d)

                migrated_d, info = migrate_to_latest(d, info)

                migrated_info = identify_stac_object(migrated_d)

                self.assertEqual(migrated_info.object_type, info.object_type)
                self.assertEqual(migrated_info.version_range.latest_valid_version(),
                                 pystac.get_stac_version())
                self.assertEqual(set(migrated_info.common_extensions), set(info.common_extensions))
                self.assertEqual(set(migrated_info.custom_extensions), set(info.custom_extensions))

                # Test that PySTAC can read it without errors.
github azavea / pystac / tests / extensions / test_label.py View on Github external
def test_label_methods(self):
        label_item = pystac.read_file(self.label_example_1_uri)

        # Get
        self.assertIn("label:methods", label_item.properties)
        label_prop = label_item.ext.label.label_methods
        self.assertEqual(label_prop, ["manual"])

        # Set
        label_item.ext.label.label_methods = ["manual", "automated"]
        self.assertEqual(["manual", "automated"], label_item.properties['label:methods'])
        self.validator.validate_object(label_item)
github azavea / pystac / tests / extensions / test_label.py View on Github external
def test_label_classes(self):
        # Get
        label_item = pystac.read_file(self.label_example_1_uri)
        label_classes = label_item.ext.label.label_classes

        self.assertEqual(len(label_classes), 2)
        self.assertEqual(label_classes[1].classes, ["three", "four"])

        # Set
        new_classes = [
            label.LabelClasses.create(name="label2", classes=["five", "six"]),
            label.LabelClasses.create(name="label", classes=["seven", "eight"])
        ]

        label_item.ext.label.label_classes = new_classes
        self.assertEqual([
            class_name for lc in label_item.properties["label:classes"]
            for class_name in lc["classes"]
        ], ["five", "six", "seven", "eight"])
github azavea / pystac / tests / serialization / test_migrate.py View on Github external
def test_migrates_added_extension(self):
        item = pystac.read_file(
            TestCases.get_path('data-files/examples/0.8.1/item-spec/'
                               'examples/planet-sample.json'))
        self.assertTrue('view' in item.stac_extensions)
        self.assertEqual(item.ext.view.sun_azimuth, 101.8)
        self.assertEqual(item.ext.view.sun_elevation, 58.8)
        self.assertEqual(item.ext.view.off_nadir, 1)
github azavea / pystac / tests / extensions / test_label.py View on Github external
def test_label_overviews(self):
        # Get
        label_item = pystac.read_file(self.label_example_1_uri)
        label_overviews = label_item.ext.label.label_overviews

        label_item2 = pystac.read_file(self.label_example_2_uri)
        label_overviews2 = label_item2.ext.label.label_overviews

        self.assertEqual(len(label_overviews), 2)
        self.assertEqual(label_overviews[1].property_key, "label-reg")
        self.assertEqual(label_overviews2[1].property_key, None)  # Raster

        label_counts = label_overviews[0].counts
        self.assertEqual(label_counts[1].count, 17)
        label_item.ext.label.label_overviews[0].counts[1].count = 18
        self.assertEqual(label_item.properties['label:overviews'][0]['counts'][1]['count'], 18)

        label_statistics = label_overviews[1].statistics
        self.assertEqual(label_statistics[0].name, "mean")
github azavea / pystac / tests / extensions / test_view.py View on Github external
def test_azimuth(self):
        view_item = pystac.read_file(self.example_uri)

        # Get
        self.assertIn("view:azimuth", view_item.properties)
        view_azimuth = view_item.ext.view.azimuth
        self.assertEqual(view_azimuth, view_item.properties['view:azimuth'])

        # Set
        view_item.ext.view.azimuth = view_azimuth + 100
        self.assertEqual(view_azimuth + 100, view_item.properties['view:azimuth'])

        # Get from Asset
        asset_no_prop = view_item.assets['blue']
        asset_prop = view_item.assets['red']
        self.assertEqual(view_item.ext.view.get_azimuth(asset_no_prop),
                         view_item.ext.view.get_azimuth())
        self.assertEqual(view_item.ext.view.get_azimuth(asset_prop), 5.0)
github azavea / pystac / tests / extensions / test_eo.py View on Github external
def test_validate_eo(self):
        item = pystac.read_file(self.LANDSAT_EXAMPLE_URI)
        item2 = pystac.read_file(self.BANDS_IN_ITEM_URI)
        self.validator.validate_object(item)
        self.validator.validate_object(item2)
github azavea / pystac / tests / extensions / test_projection.py View on Github external
def test_wkt2(self):
        proj_item = pystac.read_file(self.example_uri)

        # Get
        self.assertIn("proj:wkt2", proj_item.properties)
        proj_wkt2 = proj_item.ext.projection.wkt2
        self.assertEqual(proj_wkt2, proj_item.properties['proj:wkt2'])

        # Set
        proj_item.ext.projection.wkt2 = WKT2
        self.assertEqual(WKT2, proj_item.properties['proj:wkt2'])

        # Get from Asset
        asset_no_prop = proj_item.assets['B1']
        asset_prop = proj_item.assets['B8']
        self.assertEqual(proj_item.ext.projection.get_wkt2(asset_no_prop),
                         proj_item.ext.projection.get_wkt2())
        self.assertTrue('TEST_TEXT' in proj_item.ext.projection.get_wkt2(asset_prop))
github azavea / pystac / tests / extensions / test_view.py View on Github external
def test_incidence_angle(self):
        view_item = pystac.read_file(self.example_uri)

        # Get
        self.assertIn("view:incidence_angle", view_item.properties)
        view_incidence_angle = view_item.ext.view.incidence_angle
        self.assertEqual(view_incidence_angle, view_item.properties['view:incidence_angle'])

        # Set
        view_item.ext.view.incidence_angle = view_incidence_angle + 100
        self.assertEqual(view_incidence_angle + 100, view_item.properties['view:incidence_angle'])

        # Get from Asset
        asset_no_prop = view_item.assets['blue']
        asset_prop = view_item.assets['red']
        self.assertEqual(view_item.ext.view.get_incidence_angle(asset_no_prop),
                         view_item.ext.view.get_incidence_angle())
        self.assertEqual(view_item.ext.view.get_incidence_angle(asset_prop), 4.0)