How to use the pystac.read_file function in pystac

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 / 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)
github azavea / pystac / tests / extensions / test_commons.py View on Github external
def test_doesnt_common_metadata_if_not_enabled(self):
        # Test reading from collection
        collection = pystac.read_file(
            TestCases.get_path('data-files/commons/example-collection-without-commons.json'))

        self.assertFalse(collection.ext.implements(pystac.Extensions.COMMONS))

        item = collection.get_item("item-without")

        self.assertFalse(item.ext.implements(pystac.Extensions.COMMONS))
        self.assertTrue(item.ext.implements(pystac.Extensions.EO))

        # Should fail since required EO properties weren't inherited.
        with self.assertRaises(STACValidationError):
            self.validator.validate_object(item)

        # Test reading item directly

        item2 = pystac.read_file(