Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 31 additions & 21 deletions examples/orders_create_and_download_multiple_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import planet

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we get rid of the 2020 copyright on line 1?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, according to @cholmes investigation, we just add a line above

DOWNLOAD_DIR = os.getenv('TEST_DOWNLOAD_DIR', '.')

iowa_aoi = {
"type":
"Polygon",
Expand All @@ -36,11 +36,18 @@
[-91.198465, 42.893071]]]
}

iowa_images = ['20200925_161029_69_2223', '20200925_161027_48_2223']
iowa_order = planet.order_request.build_request(
'iowa_order',
[planet.order_request.product(iowa_images, 'analytic_udm2', 'PSScene')],
tools=[planet.order_request.clip_tool(iowa_aoi)])
name='iowa_order',
products=[
planet.order_request.product(
item_ids=['20200925_161029_69_2223', '20200925_161027_48_2223'],
product_bundle='analytic_udm2',
item_type='PSScene')
],
Copy link
Contributor Author

@sgillies sgillies Mar 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using product()'s keyword arguments makes the calls more understandable and the whole example more instructive.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes it much more readable, thank you!

tools=[
planet.order_request.clip_tool(aoi=iowa_aoi)
]
)

oregon_aoi = {
"type":
Expand All @@ -50,33 +57,36 @@
[-117.558734, 45.229745]]]
}

oregon_images = ['20200909_182525_1014', '20200909_182524_1014']
oregon_order = planet.order_request.build_request(
'oregon_order',
[planet.order_request.product(oregon_images, 'analytic_udm2', 'PSScene')],
tools=[planet.order_request.clip_tool(oregon_aoi)])


async def create_and_download(order_detail, directory, client):
name='oregon_order',
products=[
planet.order_request.product(
item_ids=['20200909_182525_1014', '20200909_182524_1014'],
product_bundle='analytic_udm2',
item_type='PSScene')
],
tools=[
planet.order_request.clip_tool(aoi=oregon_aoi)
]
)


async def create_and_download(client, order_detail, directory):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the client argument to the head of the list to make the signature of this function more like that of client.download_order(), where client (aka self) is implicitly the first argument.

"""Place an order, wait for completion, and download assets as a single task."""
with planet.reporting.StateBar(state='creating') as reporter:
# create
order = await client.create_order(order_detail)
reporter.update(state='created', order_id=order['id'])

# wait for completion
await client.wait(order['id'], callback=reporter.update_state)

# download
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed obvious comments and rolled them up into a docstring.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do the same thing for the data example.

await client.download_order(order['id'], directory, progress_bar=True)


async def main():
async with planet.Session() as ps:
client = planet.OrdersClient(ps)

async with planet.Session() as sess:
client = sess.client('orders')
await asyncio.gather(
create_and_download(iowa_order, DOWNLOAD_DIR, client),
create_and_download(oregon_order, DOWNLOAD_DIR, client),
create_and_download(client, iowa_order, DOWNLOAD_DIR),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above.

create_and_download(client, oregon_order, DOWNLOAD_DIR),
)


Expand Down