Skip to content

Commit 5738d6c

Browse files
Merge pull request #722 from planetlabs/downloading_asset_example-719
Downloading multiple assets in parallel example
2 parents 8cca559 + 522c17c commit 5738d6c

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

examples/download_multiple_assets.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright 2022 Planet Labs PBC.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4+
# use this file except in compliance with the License. You may obtain a copy of
5+
# the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations under
13+
# the License.
14+
"""Example of downloading multiple assets in parallel
15+
16+
This is an example of getting two assets, activating them, waiting for them to
17+
become active, downloading them, then validating the checksums of downloaded
18+
files.
19+
20+
[Planet Explorer](https://www.planet.com/explorer/) was used to define
21+
the AOIs and get the image ids.
22+
"""
23+
import asyncio
24+
25+
from planet import Session, DataClient
26+
27+
river_item_id = '20221003_002705_38_2461'
28+
river_item_type = 'PSScene'
29+
river_asset_type = 'ortho_analytic_4b'
30+
31+
wildfire_item_id = '20221019_183717_11_2475'
32+
wildfire_item_type = 'PSScene'
33+
wildfire_asset_type = 'basic_analytic_4b'
34+
35+
36+
async def download_and_validate(item_id, item_type_id, asset_type_id):
37+
async with Session() as sess:
38+
# Data client object
39+
cl = DataClient(sess)
40+
41+
# Get asset description
42+
asset = await cl.get_asset(item_type_id, item_id, asset_type_id)
43+
44+
# Activate asset
45+
await cl.activate_asset(asset)
46+
47+
# Wait for asset to become active
48+
asset = await cl.wait_asset(asset, callback=print)
49+
50+
# Download asset
51+
path = await cl.download_asset(asset)
52+
53+
# Validate download file
54+
cl.validate_checksum(asset, path)
55+
56+
57+
async def main():
58+
await asyncio.gather(
59+
download_and_validate(river_item_id, river_item_type,
60+
river_asset_type),
61+
download_and_validate(wildfire_item_id,
62+
wildfire_item_type,
63+
wildfire_asset_type))
64+
65+
66+
if __name__ == '__main__':
67+
asyncio.run(main())

0 commit comments

Comments
 (0)