Ejemplo n.º 1
0
    def test_bands(self) -> None:
        item = pystac.Item.from_file(self.BANDS_IN_ITEM_URI)

        # Get
        self.assertIn("eo:bands", item.properties)
        bands = EOExtension.ext(item).bands
        assert bands is not None
        self.assertEqual(
            list(map(lambda x: x.name, bands)), ["band1", "band2", "band3", "band4"]
        )

        # Set
        new_bands = [
            Band.create(name="red", description=Band.band_description("red")),
            Band.create(name="green", description=Band.band_description("green")),
            Band.create(name="blue", description=Band.band_description("blue")),
        ]

        EOExtension.ext(item).bands = new_bands
        self.assertEqual(
            "Common name: red, Range: 0.6 to 0.7",
            item.properties["eo:bands"][0]["description"],
        )
        self.assertEqual(len(EOExtension.ext(item).bands or []), 3)
        item.validate()
Ejemplo n.º 2
0
    def test_asset_bands(self) -> None:
        item = pystac.Item.from_file(self.LANDSAT_EXAMPLE_URI)

        # Get

        b1_asset = item.assets["B1"]
        asset_bands = EOExtension.ext(b1_asset).bands
        assert asset_bands is not None
        self.assertEqual(len(asset_bands), 1)
        self.assertEqual(asset_bands[0].name, "B1")
        self.assertEqual(asset_bands[0].solar_illumination, 2000)

        index_asset = item.assets["index"]
        asset_bands = EOExtension.ext(index_asset).bands
        self.assertIs(None, asset_bands)

        # No asset specified
        item_bands = EOExtension.ext(item).bands
        self.assertIsNot(None, item_bands)

        # Set
        b2_asset = item.assets["B2"]
        self.assertEqual(get_opt(EOExtension.ext(b2_asset).bands)[0].name, "B2")
        EOExtension.ext(b2_asset).bands = EOExtension.ext(b1_asset).bands

        new_b2_asset_bands = EOExtension.ext(item.assets["B2"]).bands

        self.assertEqual(get_opt(new_b2_asset_bands)[0].name, "B1")

        item.validate()

        # Check adding a new asset
        new_bands = [
            Band.create(
                name="red",
                description=Band.band_description("red"),
                solar_illumination=1900,
            ),
            Band.create(
                name="green",
                description=Band.band_description("green"),
                solar_illumination=1950,
            ),
            Band.create(
                name="blue",
                description=Band.band_description("blue"),
                solar_illumination=2000,
            ),
        ]
        asset = pystac.Asset(href="some/path.tif", media_type=pystac.MediaType.GEOTIFF)
        EOExtension.ext(asset).bands = new_bands
        item.add_asset("test", asset)

        self.assertEqual(len(item.assets["test"].extra_fields["eo:bands"]), 3)
Ejemplo n.º 3
0
    def test_asset_bands(self):
        eo_item = pystac.read_file(self.LANDSAT_EXAMPLE_URI)

        # Get

        b1_asset = eo_item.assets['B1']
        asset_bands = eo_item.ext.eo.get_bands(b1_asset)
        self.assertIsNot(None, asset_bands)
        self.assertEqual(len(asset_bands), 1)
        self.assertEqual(asset_bands[0].name, 'B1')

        index_asset = eo_item.assets['index']
        asset_bands = eo_item.ext.eo.get_bands(index_asset)
        self.assertIs(None, asset_bands)

        # Set
        b2_asset = eo_item.assets['B2']
        self.assertEqual(eo_item.ext.eo.get_bands(b2_asset)[0].name, "B2")
        eo_item.ext.eo.set_bands(eo_item.ext.eo.get_bands(b1_asset), b2_asset)

        new_b2_asset_bands = eo_item.ext.eo.get_bands(eo_item.assets['B2'])

        self.assertEqual(new_b2_asset_bands[0].name, 'B1')

        eo_item.validate()

        # Check adding a new asset
        new_bands = [
            Band.create(name="red", description=Band.band_description("red")),
            Band.create(name="green",
                        description=Band.band_description("green")),
            Band.create(name="blue",
                        description=Band.band_description("blue")),
        ]
        asset = pystac.Asset(href="some/path.tif",
                             media_type=pystac.MediaType.GEOTIFF)
        eo_item.ext.eo.set_bands(new_bands, asset)
        eo_item.add_asset("test", asset)

        self.assertEqual(len(eo_item.assets["test"].properties["eo:bands"]), 3)
Ejemplo n.º 4
0
    def test_bands(self):
        eo_item = pystac.read_file(self.BANDS_IN_ITEM_URI)

        # Get
        self.assertIn("eo:bands", eo_item.properties)
        bands = eo_item.ext.eo.bands
        self.assertEqual(list(map(lambda x: x.name, bands)),
                         ['band1', 'band2', 'band3', 'band4'])

        # Set
        new_bands = [
            Band.create(name="red", description=Band.band_description("red")),
            Band.create(name="green",
                        description=Band.band_description("green")),
            Band.create(name="blue",
                        description=Band.band_description("blue")),
        ]

        eo_item.ext.eo.bands = new_bands
        self.assertEqual('Common name: red, Range: 0.6 to 0.7',
                         eo_item.properties['eo:bands'][0]['description'])
        self.assertEqual(len(eo_item.ext.eo.bands), 3)
        eo_item.validate()
Ejemplo n.º 5
0
    def test_bands(self):
        eo_item = pystac.read_file(
            TestCases.get_path('data-files/eo/eo-landsat-example.json'))

        # Get
        self.assertIn("eo:bands", eo_item.properties)
        bands = eo_item.ext.eo.bands
        self.assertEqual(list(map(lambda x: x.name, bands)), [
            'B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9', 'B10', 'B11'
        ])
        for band in bands:
            self.assertIsInstance(band.common_name, str)
            self.assertIn(type(band.center_wavelength), [float, int])
            self.assertIn(type(band.full_width_half_max), [float, int])
            self.assertIs(None, band.description)

        # Ensure modifying the bands make changes on the item.
        bands_dict = {band.name: band for band in bands}
        bands_dict['B1'].description = "Band 1"

        self.assertTrue(
            [x for x in eo_item.properties['eo:bands']
             if x['name'] == 'B1'][0]['description'] == "Band 1")

        # Set
        new_bands = [
            Band.create(name="red", description=Band.band_description("red")),
            Band.create(name="green",
                        description=Band.band_description("green")),
            Band.create(name="blue",
                        description=Band.band_description("blue")),
        ]

        eo_item.ext.eo.bands = new_bands
        self.assertEqual('Common name: red, Range: 0.6 to 0.7',
                         eo_item.properties['eo:bands'][0]['description'])
        self.validator.validate_object(eo_item)
Ejemplo n.º 6
0
    def test_create(self) -> None:
        band = Band.create(
            name="B01",
            common_name="red",
            description=Band.band_description("red"),
            center_wavelength=0.65,
            full_width_half_max=0.1,
            solar_illumination=42.0,
        )

        self.assertEqual(band.name, "B01")
        self.assertEqual(band.common_name, "red")
        self.assertEqual(band.description, "Common name: red, Range: 0.6 to 0.7")
        self.assertEqual(band.center_wavelength, 0.65)
        self.assertEqual(band.full_width_half_max, 0.1)
        self.assertEqual(band.solar_illumination, 42.0)
        self.assertEqual(band.__repr__(), "<Band name=B01>")
Ejemplo n.º 7
0
    def test_band_description_unknown_band(self) -> None:
        desc = Band.band_description("rainbow")

        self.assertIsNone(desc)