Skip to content

Commit 4c0a62d

Browse files
Merge pull request #891 from planetlabs/docs-885-886
Data CLI documentation updates
2 parents 1f7abc9 + 754d00a commit 4c0a62d

File tree

1 file changed

+204
-19
lines changed

1 file changed

+204
-19
lines changed

docs/cli/cli-data.md

Lines changed: 204 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ descending order. The options are are:
146146
* 'published asc'
147147
* 'published desc'
148148

149-
The lets you do things like get the id of the most recent skysat image taken (that you have download access to):
149+
This lets you do things like get the ID of the most recent SkySat image taken (and that you have permissions to download):
150150

151151
```console
152152
planet data search SkySatCollect --sort 'acquired desc' --limit 1
@@ -158,7 +158,6 @@ And you can also just get the ID, using `jq`
158158
planet data search SkySatCollect --sort 'acquired desc' --limit 1 - | jq -r .id
159159
```
160160

161-
162161
## Filtering
163162

164163
### Run a search on a bounding box
@@ -282,7 +281,6 @@ You can specify multiple strings to match, with a comma:
282281

283282
```console
284283
planet data filter --string-in instrument PS2,PSB.SD | planet data search PSScene --filter -
285-
286284
```
287285

288286
Another example is to select all data in a single strip:
@@ -292,7 +290,7 @@ planet data filter --string-in strip_id 5743640 | planet data search PSScene --f
292290
```
293291

294292
Note that in all these commands we are piping the results into the search. If you don't include the pipe then you'll
295-
get the filter output, which can be interested to inspect to see exactly what is sent to the server.
293+
get the filter output, which can be interesting to inspect to see exactly what is sent to the server.
296294

297295
### Filter by asset
298296

@@ -326,25 +324,212 @@ that are of standard (aka not test) quality. Therefore, these filters can be eas
326324
planet data filter --permission --std-quality --asset ortho_analytic_8b_sr | planet data search PSScene --filter -
327325
```
328326

329-
## `data asset` command basics
327+
## Stats
330328

331-
To activate an asset for download three commands must be queried, in sequence:
332-
1. `asset-activate` - activate an asset
333-
2. `asset-wait` - wait for an asset to be activated
334-
3. `asset-download` - download an activated asset
329+
One command that can be quite useful for getting a sense of a search is the `stats` command. It works with the
330+
exact same filters as the main `search` command, but it just returns a count of the results, which can be
331+
binned by different time periods.
335332

336-
For example, if we want to download a `basic_udm2` asset from item ID
337-
`20221003_002705_38_2461`, a `PSScene` item type:
333+
This can be used for things like getting the number of items in a strip:
338334

339335
```
340-
planet data asset-activate PSScene 20221003_002705_38_2461 basic_udm2 && \
341-
planet data asset-wait PSScene 20221003_002705_38_2461 basic_udm2 && \
342-
planet data asset-download PSScene 20221003_002705_38_2461 basic_udm2 --directory /path/to/data/
343-
00:00 - order my asset - state: active
344-
{'_links': {'_self': 'https://api.planet.com/data/v1/assets/eyJpIjogIjIwMjIxMDAzXzAwMjcwNV8zOF8yNDYxIiwgImMiOiAiUFNTY2VuZSIsICJ0IjogImJhc2ljX3VkbTIiLCAiY3QiOiAiaXRlbS10eXBlIn0', 'activate': 'https://api.planet.com/data/v1/assets/eyJpIjogIjIwMjIxMDAzXzAwMjcwNV8zOF8yNDYxIiwgImMiOiAiUFNTY2VuZSIsICJ0IjogImJhc2ljX3VkbTIiLCAiY3QiOiAiaXRlbS10eXBlIn0/activate', 'type': 'https://api.planet.com/data/v1/asset-types/basic_udm2'}, '_permissions': ['download'], 'expires_at': '2023-03-02T19:30:48.942718', 'location': 'https://api.planet.com/data/v1/download?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJQYWtGNHZuUEs3WXRmSFNGUklHY2I3YTNXT3piaTlaam4zWUpZMmxnd0x5cVlFMVBRSHU5QXNCcjR5Q3FxSjBNbl9yN3VwVEFQYUI1ZzhYNUJmcDhmUT09IiwiZXhwIjoxNjc3Nzg1NDQ4LCJ0b2tlbl90eXBlIjoidHlwZWQtaXRlbSIsIml0ZW1fdHlwZV9pZCI6IlBTU2NlbmUiLCJpdGVtX2lkIjoiMjAyMjEwMDNfMDAyNzA1XzM4XzI0NjEiLCJhc3NldF90eXBlIjoiYmFzaWNfdWRtMiJ9.Dd0opDjW3bBS6qLLZoNiJkfBsO2n5Xz9pM5apEUz_K6viDPFexhJiy6bMbaySbby8W0YvuATdb1uYXS2FkweDg', 'md5_digest': '3a9f7dd1ce500f699d0a96afdd0e3aa2', 'status': 'active', 'type': 'basic_udm2'}
345-
/path/to/data/20221003_002705_38_2461_1A_udm2.tif: 100%|██████████████████████████████████| 3.16k/3.16k [00:00<00:00, 32.0MB/s]
336+
planet data filter --string-in strip_id 5743640 | planet data stats PSScene --interval day --filter -
346337
```
347338

348-
## Stats
339+
Or the number of PlanetScope scenes collected in California each year:
340+
341+
```
342+
curl -s https://raw.githubusercontent.com/ropensci/geojsonio/main/inst/examples/california.geojson | \
343+
planet data filter --geom - | planet data stats PSScene --interval year --filter - | jq
344+
```
345+
346+
Will result in output like:
347+
348+
```json
349+
{
350+
"buckets": [
351+
{
352+
"count": 5261,
353+
"start_time": "2014-01-01T00:00:00.000000Z"
354+
},
355+
{
356+
"count": 34377,
357+
"start_time": "2015-01-01T00:00:00.000000Z"
358+
},
359+
{
360+
"count": 112331,
361+
"start_time": "2016-01-01T00:00:00.000000Z"
362+
},
363+
{
364+
"count": 504377,
365+
"start_time": "2017-01-01T00:00:00.000000Z"
366+
},
367+
{
368+
"count": 807086,
369+
"start_time": "2018-01-01T00:00:00.000000Z"
370+
},
371+
{
372+
"count": 806945,
373+
"start_time": "2019-01-01T00:00:00.000000Z"
374+
},
375+
{
376+
"count": 776757,
377+
"start_time": "2020-01-01T00:00:00.000000Z"
378+
},
379+
{
380+
"count": 684095,
381+
"start_time": "2021-01-01T00:00:00.000000Z"
382+
},
383+
{
384+
"count": 323557,
385+
"start_time": "2022-01-01T00:00:00.000000Z"
386+
},
387+
{
388+
"count": 56733,
389+
"start_time": "2023-01-01T00:00:00.000000Z"
390+
}
391+
],
392+
"interval": "year",
393+
"utc_offset": "+0h"
394+
}
395+
```
396+
397+
You can see how the yearly output of Planet has gone up, though it actually went down in 2022 as the upgrade to
398+
SuperDove meant much larger swaths, so the number of individual items went down even as we captured the whole
399+
earth.
400+
401+
The API does not support an 'all time' interval to get the total of all collections for an area, but
402+
you can easily use [jq]((cli-intro.md#jq) to total up the results of an interval count:
403+
404+
```
405+
curl -s https://raw.githubusercontent.com/ropensci/geojsonio/main/inst/examples/california.geojson | \
406+
planet data filter --geom - | planet data stats PSScene --interval year --filter - | jq '.buckets | map(.count) | add'
407+
```
408+
409+
Just pipe the results to `jq '.buckets | map(.count) | add'` and it'll give you the total of all the values.
410+
411+
## Asset Activation and Download
412+
413+
While we recommend using the Orders or Subscriptions API's to deliver Planet data, the Data API has the capability
414+
to activate and download data. Only one asset can be activated at once, and there is no clipping or additional
415+
processing of the data like the great 'tools' of Subscriptions & Orders. But the advantage is that it can often
416+
be faster for working with a small number of items & assets.
417+
418+
### Activate an Asset
419+
420+
All items in the Data API have a list of assets. This includes the main imagery geotiff files, usually in a few
421+
different formats, and also accompanying files like the [Usable Data Mask](https://developers.planet.com/docs/data/udm-2/)
422+
(UDM) and JSON metadata. You can't immediately download them, as they must first be created in the cloud, known as
423+
'activated'. To activate data you need to get its item id, plus the name of the asset - the available ones
424+
can be seen by looking at the Item's JSON. Once you have the item id and asset type you can run the CLI
425+
426+
```
427+
planet data asset-activate PSScene 20230310_083933_71_2431 ortho_udm2
428+
```
429+
430+
This will kick off the activation process, and the command should return immediately. In this example
431+
we're activating the UDM, which is one of the most common things to do through the Data API, to
432+
first get a sense of where there are clouds before placing a proper clipping order.
433+
434+
### Download an Asset
435+
436+
Once an asset is ready you can use `asset-download` with a similar command:
437+
438+
```
439+
planet data asset-download PSScene 20230310_083933_71_2431 ortho_udm2
440+
```
441+
442+
While some assets activate almost immediately (if another user has requested
443+
it recently), some can take a few minutes. If you try to download it before it's active
444+
you'll get a message like: `Error: asset missing ["location"] entry. Is asset active?`
445+
446+
Thankfully the CLI has the great `asset-wait` command will complete when the asset is activated:
447+
448+
```
449+
planet data asset-wait PSScene 20230310_083933_71_2431 ortho_udm2
450+
```
451+
452+
And you can pair with download so that as soon as the asset is active it'll be downloaded:
453+
454+
```
455+
planet data asset-wait PSScene 20230310_083933_71_2431 ortho_udm2 && \
456+
planet data asset-download PSScene 20230310_083933_71_2431 ortho_udm2
457+
```
458+
459+
Download has a few different options:
460+
461+
* `--directory` lets you specify a base directory to put the asset in.
462+
* `--filename` assigns a custom name to the downloaded file.
463+
* `--overwrite` will overwrite files if they already exist.
464+
* `--checksum` checks to make sure the file you downloaded is the exact same as the one on the server. This can be useful if you script thousands of files to download to detect any corruptions in that process.
465+
466+
## Saved Searches
467+
468+
The core `planet data search` command uses what is called a 'quick search' in the API. The API
469+
also supports what we call a '[saved searches](https://developers.planet.com/docs/apis/data/quick-saved-search/#saved-search)',
470+
and the CLI supports this as well.
471+
472+
### List Searches
473+
474+
You can easily get a list of all the searches you've made:
475+
476+
```
477+
planet data search-list
478+
```
479+
480+
This defaults to returning 100 results, but you can use `--limit` to return the number you
481+
specify, and set it to 0 to return all your searches. By default this returns both
482+
your quick searches and saved searches, but you can also limit to to only return
483+
your saved searches:
484+
485+
```
486+
planet data search-list --search-type saved
487+
```
488+
489+
If you've not created any saved searches it may be an empty list. You can create
490+
saved searches with Planet Explorer, or it's also easy with the command-line.
491+
492+
### Create Search
493+
494+
To make a new saved search you can use the exact same filter syntax as the regular `search` command,
495+
but you must also add a 'name' to refer to the search by:
496+
497+
```
498+
planet data filter --geom geometry.geojson | planet data search-create PSScene --name 'my saved search' --filter -
499+
```
500+
501+
### Run Search
502+
503+
When you save a new search you'll get back the JSON describing the search. If you grab the 'id' field from it then
504+
you can get the current results for that search:
505+
506+
```
507+
planet data search-run da963039dbe94573a3ac9e4629d065b6
508+
```
509+
510+
This is just like running a normal (quick) search, and takes similar arguments: `--limit` and `--pretty`,
511+
and also the same [sort](#sort) parameter (`--sort`). You can also run any previous `quick` search.
512+
They don't have names (the ID is just used as the name), but they are saved in the system and can be
513+
executed again. Searches (except those with an end date that has passed) show new results
514+
if run later and match newly acquired imagery.
515+
516+
### Update Search
517+
518+
You can also update an existing search to have a different set of values. This takes similar arguments, and
519+
will overwrite the previous values.
520+
521+
```
522+
planet data filter --string-in instrument PS2,PSB.SD | planet data search-update da963039dbe94573a3ac9e4629d065b6 --name 'my updated search' --filter - SkySatCollect
523+
```
524+
525+
### Delete Search
526+
527+
If you're no longer using a search you can delete it:
528+
529+
```
530+
planet data search-delete da963039dbe94573a3ac9e4629d065b6
531+
```
349532

350-
TODO
533+
If the deletion was successful the command-line won't print out anything except a new line. If the
534+
search didn't exist it will say `Error: {"general": [{"message": "The requested search id does not exist"}], "field": {}}`.
535+
You can also delete `quick` searches, which would remove them from your history.

0 commit comments

Comments
 (0)