示例#1
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)
示例#2
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)
示例#3
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)))
示例#4
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)
 def download(self,
              from_bucket: bool = False,
              file_obj: IO[Union[Union[str, bytes], Any]] = None,
              save_filename: str = '',
              save_directory: str = '',
              requester_pays: bool = False,
              nsl_id: str = None) -> str:
     return utils.download_asset(asset=self._asset,
                                 from_bucket=from_bucket,
                                 file_obj=file_obj,
                                 save_filename=save_filename,
                                 save_directory=save_directory,
                                 requester_pays=requester_pays,
                                 nsl_id=nsl_id)