コード例 #1
0
 def test_basename(self):
     asset_name = 'LO81120152015061LGN00_B2.TIF'
     id = "LO81120152015061LGN00"
     stac_request = StacRequest(id=id)
     stac_item = search_one(stac_request)
     asset = utils.get_asset(stac_item, asset_basename=asset_name)
     self.assertIsNotNone(asset)
コード例 #2
0
    def test_download_href(self):
        stac_id = "20190829T173549Z_1799_POM1_ST2_P"
        stac_item = client.search_one(stac_request=StacRequest(id=stac_id))
        asset = utils.get_asset(stac_item, asset_type=AssetType.THUMBNAIL)

        self.assertIsNotNone(asset)

        with tempfile.TemporaryDirectory() as d:
            file_path = utils.download_asset(asset=asset, save_directory=d)
            with open(file_path, 'rb') as f:
                data1 = f.read()

            file_path = utils.download_asset(asset=asset,
                                             save_filename=file_path)
            with open(file_path, 'rb') as f:
                data2 = f.read()

            self.assertEqual(data1, data2)

            with tempfile.NamedTemporaryFile('w+b', delete=False) as file_obj:
                utils.download_asset(asset=asset, file_obj=file_obj)
                data3 = file_obj.read()
                self.assertEqual(data1, data3)

            b = io.BytesIO()
            utils.download_asset(asset=asset, file_obj=b)
            data4 = b.read()
            self.assertEqual(data2, data4)
コード例 #3
0
    def test_download_aws(self):
        stac_id = "LC80270392015025LGN00"
        stac_item = client.search_one(stac_request=StacRequest(id=stac_id))
        asset = utils.get_asset(stac_item,
                                asset_type=AssetType.TXT,
                                cloud_platform=CloudPlatform.AWS)
        self.assertIsNotNone(asset)
        with tempfile.TemporaryDirectory() as d:
            print(d)
            file_path = utils.download_asset(asset=asset,
                                             from_bucket=True,
                                             save_directory=d)
            with open(file_path) as f:
                data1 = f.read()

            file_path = utils.download_asset(asset=asset,
                                             from_bucket=True,
                                             save_filename=file_path)
            with open(file_path) as f:
                data2 = f.read()

            self.assertMultiLineEqual(data1, data2)

            with tempfile.NamedTemporaryFile('w+b', delete=False) as f_obj:
                utils.download_asset(asset=asset,
                                     from_bucket=True,
                                     file_obj=f_obj)
                data3 = f_obj.read().decode('ascii')
                self.assertMultiLineEqual(data1, data3)
コード例 #4
0
 def test_thumbnail(self):
     stac_id = 'LO81120152015061LGN00'
     stac_request = StacRequest(id=stac_id)
     stac_item = client.search_one(stac_request)
     asset = utils.get_asset(stac_item,
                             asset_type=AssetType.THUMBNAIL,
                             cloud_platform=CloudPlatform.AWS)
     self.assertIsNotNone(asset)
コード例 #5
0
 def test_thumbnail(self):
     id = 'LO81120152015061LGN00'
     stac_request = StacRequest(id=id)
     stac_item = search_one(stac_request)
     asset_type = THUMBNAIL
     asset = utils.get_asset(stac_item,
                             asset_types=[asset_type],
                             cloud_platform=AWS)
     self.assertIsNotNone(asset)
コード例 #6
0
 def test_basename(self):
     asset_name = r'.*LO81120152015061LGN00_B2\.TIF$'
     stac_id = "LO81120152015061LGN00"
     stac_request = StacRequest(id=stac_id)
     stac_item = client.search_one(stac_request)
     asset = utils.get_asset(stac_item,
                             asset_regex={'object_path': asset_name},
                             cloud_platform=CloudPlatform.AWS)
     self.assertIsNotNone(asset)
コード例 #7
0
    def test_download_geotiff(self):
        stac_request = StacRequest(id='20190822T183518Z_746_POM1_ST2_P')

        stac_item = client.search_one(stac_request)

        # get the Geotiff asset from the assets map
        asset = utils.get_asset(stac_item, asset_type=enum.AssetType.GEOTIFF)

        with tempfile.TemporaryDirectory() as d:
            file_path = utils.download_asset(asset=asset, save_directory=d)
            print("{0} has {1} bytes".format(os.path.basename(file_path),
                                             os.path.getsize(file_path)))
コード例 #8
0
    def test_OLI(self):
        id = "LO81120152015061LGN00"
        stac_request = StacRequest(id=id)
        stac_item = search_one(stac_request)
        asset = utils.get_asset(stac_item, band=Eo.BLUE, cloud_platform=GCP)
        self.assertIsNotNone(asset)
        asset = utils.get_asset(stac_item, band=Eo.BLUE, cloud_platform=AWS)
        self.assertIsNotNone(asset)

        asset = utils.get_asset(stac_item, band=Eo.LWIR_1, cloud_platform=GCP)
        self.assertIsNone(asset)
        asset = utils.get_asset(stac_item, band=Eo.LWIR_1, cloud_platform=AWS)
        self.assertIsNone(asset)

        asset = utils.get_asset(stac_item, band=Eo.CIRRUS, cloud_platform=GCP)
        self.assertIsNotNone(asset)
        asset = utils.get_asset(stac_item, band=Eo.CIRRUS, cloud_platform=AWS)
        self.assertIsNotNone(asset)

        aws_count, gcp_count = 0, 0
        for key, asset in stac_item.assets.items():
            if asset.cloud_platform == AWS:
                print(asset.object_path)
                aws_count += 1
            else:
                # print(asset.object_path)
                gcp_count += 1
        self.assertEquals(25, aws_count)
        self.assertEquals(12, gcp_count)
コード例 #9
0
    def test_download_aws_href(self):
        stac_id = 'LC80270392015025LGN00'
        stac_item = client.search_one(stac_request=StacRequest(id=stac_id))
        asset = utils.get_asset(stac_item,
                                asset_type=AssetType.THUMBNAIL,
                                asset_regex={"asset_key": ".*_2$"},
                                cloud_platform=enum.CloudPlatform.AWS)
        self.assertIsNotNone(asset)

        with tempfile.TemporaryDirectory() as d:
            file_path = utils.download_asset(asset=asset, save_directory=d)
            with open(file_path, 'rb') as f:
                data1 = f.read()

            file_path = utils.download_asset(asset=asset,
                                             save_filename=file_path)
            with open(file_path, 'rb') as f:
                data2 = f.read()

            self.assertEqual(data1, data2)
コード例 #10
0
    def test_OLI(self):
        stac_id = "LO81120152015061LGN00"
        stac_request = StacRequest(id=stac_id)
        stac_item = client.search_one(stac_request)
        asset = utils.get_asset(stac_item,
                                eo_bands=Band.BLUE,
                                cloud_platform=CloudPlatform.GCP)
        self.assertIsNotNone(asset)
        asset = utils.get_asset(stac_item,
                                eo_bands=Band.BLUE,
                                asset_type=enum.AssetType.GEOTIFF,
                                cloud_platform=CloudPlatform.AWS)
        self.assertIsNotNone(asset)

        asset = utils.get_asset(stac_item,
                                eo_bands=Band.LWIR_1,
                                cloud_platform=CloudPlatform.GCP)
        self.assertIsNone(asset)
        asset = utils.get_asset(stac_item,
                                eo_bands=Band.LWIR_1,
                                cloud_platform=CloudPlatform.AWS)
        self.assertIsNone(asset)

        asset = utils.get_asset(stac_item,
                                eo_bands=Band.CIRRUS,
                                cloud_platform=CloudPlatform.GCP)
        self.assertIsNotNone(asset)
        asset = utils.get_asset(stac_item,
                                eo_bands=Band.CIRRUS,
                                cloud_platform=CloudPlatform.AWS,
                                asset_type=enum.AssetType.GEOTIFF)
        self.assertIsNotNone(asset)

        aws_count, gcp_count = 0, 0
        for key, asset in stac_item.assets.items():
            if asset.cloud_platform == CloudPlatform.AWS:
                print(asset.object_path)
                aws_count += 1
            else:
                # print(asset.object_path)
                gcp_count += 1
        self.assertEquals(25, aws_count)
        self.assertEquals(12, gcp_count)