Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
af87b1f
rm psorthotile in ex resolves 874
JuLeeAtPlanet Mar 15, 2023
60a2956
Merge pull request #875 from planetlabs/DOCS_rm_psortho_eg_issue_874
kevinlacaille Mar 16, 2023
deecf20
Added bandmath tool from subscription_request.py
kevinlacaille Mar 16, 2023
6cf566c
Added bandmath tool test.
kevinlacaille Mar 16, 2023
0eb3311
simplify geojson specified as geometry in catalog_source
jreiberkyle Mar 21, 2023
ff3dc1c
Run Session class tests in an event loop
sgillies Mar 21, 2023
59682df
Update PR reference in change log
sgillies Mar 21, 2023
0692d17
move name and filter to required options in create_search
jreiberkyle Mar 21, 2023
07610b8
rearrange dataclient.search_create parameter order
jreiberkyle Mar 21, 2023
48d48e6
revert accidental changes to CHANGES.txt
jreiberkyle Mar 21, 2023
a55e851
Merge pull request #880 from planetlabs/geom-871
jreiberkyle Mar 21, 2023
0d5e420
Merge pull request #881 from planetlabs/issue879
jreiberkyle Mar 22, 2023
da532ff
raise pytest warnings to errors so they are caught by CI
jreiberkyle Mar 22, 2023
808e0eb
Revert "raise pytest warnings to errors so they are caught by CI"
jreiberkyle Mar 22, 2023
8535d4b
map pytest warnings to errors so they will be caught by CI
jreiberkyle Mar 22, 2023
3f75feb
Fixed broken test: incorrect expected format.
kevinlacaille Mar 22, 2023
c618717
Fixed format for band math tool input for _tool()
kevinlacaille Mar 22, 2023
80abd21
Fixed small bug: input to Orders API band_math -> bandmath
kevinlacaille Mar 22, 2023
2bf4cf5
relax pin on httpx and respx, switch to anyio from pytest-asyncio, fi…
jreiberkyle Mar 22, 2023
2009923
Removed $ prefixes for code example to make them more copy and pasteable
kevinlacaille Mar 22, 2023
d4318b5
fix and re-enable planet orders download checksum test
jreiberkyle Mar 22, 2023
f60f0da
Fixed all filter examples.
kevinlacaille Mar 22, 2023
7840832
Fixed STAC output with the composite tool.
kevinlacaille Mar 22, 2023
96c7914
Added options flags and removed unneeded ID flag.
kevinlacaille Mar 22, 2023
672aaae
swap order of named arguments in invocation within test
jreiberkyle Mar 22, 2023
b679d70
Added syntax highlighting for jq example.
kevinlacaille Mar 22, 2023
b483ea1
fixes for readability
jreiberkyle Mar 22, 2023
5a3dbb9
Merge branch 'saved-search-filter' of github.com:planetlabs/planet-cl…
jreiberkyle Mar 22, 2023
c70ea07
Merge pull request #883 from planetlabs/saved-search-filter
jreiberkyle Mar 22, 2023
e89550c
Moved band math globals to specs.
kevinlacaille Mar 22, 2023
0864125
Updated tests to pull band math globals from specs.
kevinlacaille Mar 22, 2023
b93f4f1
Merge pull request #876 from planetlabs/add_bandmath_tool_orders_requ…
kevinlacaille Mar 22, 2023
745884f
add instructions for how to suppress warnings
jreiberkyle Mar 22, 2023
8308fbd
Merge pull request #888 from planetlabs/py3.10-warnings-882
jreiberkyle Mar 22, 2023
6a520aa
Merge pull request #892 from planetlabs/fix-cli-examples-869
kevinlacaille Mar 23, 2023
878a1a5
Merge branch 'main' into rc3dev-fixes
jreiberkyle Mar 24, 2023
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
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2.0.0-rc.3 (TBD)

Changed:
- Session class unit tests are marked to be run within an event loop and are
no longer skipped (#881).

2.0.0-rc.2 (2023-03-15)

Added:
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/cli-intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ represent GeoJSON features, the JSON blob is a GeoJSON FeatureCollection.
Otherwise, the JSON blob is a list of the individual results.

```console
$ planet data search PSScene | planet collect -
planet data search PSScene | planet collect -
```

This gives you a fully compliant GeoJSON FeatureCollection, which is
Expand Down
12 changes: 6 additions & 6 deletions docs/cli/cli-orders.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ You can also filter orders by their `state`, which can be useful to just see ord
progress:

```console
planet orders --state running
planet orders list --state running
```

The other options are queued, failed, success, partial and cancelled.
Expand Down Expand Up @@ -100,7 +100,7 @@ To create an order you need a name, a [bundle](https://developers.planet.com/api
First lets get the ID of an item you have download access to, using the Data API:

```
planet data filter | planet data search PSScene --limit 1 - | jq -r .id
planet data filter | planet data search PSScene --limit 1 --filter - | jq -r .id
```

If you don't have access to PlanetScope data then replace PSScene with SkySatCollect.
Expand Down Expand Up @@ -515,7 +515,7 @@ One cool little trick is that you can even stream in the JSON directly with `cur

```console
curl -s https://raw.githubusercontent.com/planetlabs/planet-client-python/main/docs/cli/request-json/tools-clip-composite.json \
| planet orders request --item-type PSScene --bundle analytic_sr_udm2 --name 'Streaming Clip & Composite' \
| planet orders request --item-type PSScene --bundle analytic_sr_udm2 --name 'Streaming Clip & Composite' --no-stac \
20220605_124027_64_242b,20220605_124025_34_242b --tools - | planet orders create -
```

Expand Down Expand Up @@ -550,7 +550,7 @@ STAC metadata by default, as the STAC files are small and often more useful than
You can easily turn off STAC output request with the `--no-stac` command:

```
planet orders request PSScene visual --name 'No STAC' --no-stac --id 20220605_124027_64_242b
planet orders request --item-type PSScene --bundle visual --name 'No STAC' --no-stac 20220605_124027_64_242b
```

Currently this needs to be done for any 'composite' operation, as STAC output from composites is not yet
Expand Down Expand Up @@ -672,7 +672,7 @@ image that was published:

```console
planet orders request --item-type SkySatCollect --bundle analytic --name 'SkySat Latest' \
`planet data filter | planet data search SkySatCollect --sort 'acquired desc' --limit 1 - | jq -r .id` \
`planet data filter | planet data search SkySatCollect --sort 'acquired desc' --limit 1 --filter - | jq -r .id` \
| planet orders create -
```

Expand All @@ -681,7 +681,7 @@ Or get the 5 latest cloud free images in an area and create an order that clips

```console
ids=`planet data filter --geom geometry.geojson --range clear_percent gt 90 | planet data \
search PSScene --limit 5 - | jq -r .id | tr '\n' , | sed 's/.$//'`
search PSScene --limit 5 --filter - | jq -r .id | tr '\n' , | sed 's/.$//'`
planet orders request --item-type PSScene --bundle analytic_sr_udm2 --name 'Clipped Scenes' \
$ids --clip geometry.geojson | planet orders create -
```
Expand Down
6 changes: 4 additions & 2 deletions docs/cli/cli-tips-tricks.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,11 @@ planet orders list | jq -rs '.[3] | "\(.id) \(.created_on) \(.name) \(.state)"'

* Use jq to show just orders that have a given item type, like just skysat.

planet orders list | jq -rs '.[] | "\(.id) \(.created_on) \(.state) \(.products[0].item_type)"' will show the item type
```console
planet orders list | jq -rs '.[] | "\(.id) \(.created_on) \(.state) \(.products[0].item_type)"'
```

https://gist.github.com/ipbastola/2c955d8bf2e96f9b1077b15f995bdae3 has ideas for contains, but haven't got it right yet
will show the item type https://gist.github.com/ipbastola/2c955d8bf2e96f9b1077b15f995bdae3 has ideas for contains, but haven't got it right yet

* use jq to get the id of the an order by it's name

Expand Down
5 changes: 4 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ def test(session):
session.install(".[test]")

options = session.posargs
session.run('pytest', '--ignore', 'examples/', '-v', *options)
# -W=error raises pytest warnings to errors so they are caught by CI
# to exclude some warnings, see
# https://docs.python.org/3/library/warnings.html#temporarily-suppressing-warnings
session.run('pytest', '--ignore', 'examples/', '-v', '-W=error', *options)


@nox.session
Expand Down
26 changes: 15 additions & 11 deletions planet/cli/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ def filter(ctx,
callback=check_item_types)
@click.option('--filter',
type=types.JSON(),
help='Apply specified filter to search.')
help="""Apply specified filter to search. Can be a json string,
filename, or '-' for stdin.""")
@limit
@click.option('--name', type=str, help='Name of the saved search.')
@click.option('--sort',
Expand Down Expand Up @@ -321,32 +322,35 @@ async def search(ctx, item_types, filter, limit, name, sort, pretty):
@click.pass_context
@translate_exceptions
@coro
@click.argument('name')
@click.argument("item_types",
type=types.CommaSeparatedString(),
callback=check_item_types)
@click.argument("filter", type=types.JSON())
@click.option(
'--filter',
type=types.JSON(),
required=True,
help="""Filter to apply to search. Can be a json string, filename,
or '-' for stdin.""")
@click.option('--name',
type=str,
required=True,
help='Name of the saved search.')
@click.option('--daily-email',
is_flag=True,
help='Send a daily email when new results are added.')
@pretty
async def search_create(ctx, name, item_types, filter, daily_email, pretty):
async def search_create(ctx, item_types, filter, name, daily_email, pretty):
"""Create a new saved structured item search.

This function outputs a full JSON description of the created search,
optionally pretty-printed.

NAME is the name to give the search.

ITEM_TYPES is a comma-separated list of item-types to search.

FILTER must be JSON and can be specified a json string, filename, or '-'
for stdin.
"""
async with data_client(ctx) as cl:
items = await cl.create_search(name=name,
item_types=item_types,
items = await cl.create_search(item_types=item_types,
search_filter=filter,
name=name,
enable_email=daily_email)
echo_json(items, pretty)

Expand Down
4 changes: 2 additions & 2 deletions planet/clients/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ async def search(self,
yield i

async def create_search(self,
name: str,
item_types: List[str],
search_filter: dict,
name: str,
enable_email: bool = False) -> dict:
"""Create a new saved structured item search.
Expand All @@ -190,9 +190,9 @@ async def create_search(self,
Parameters:
name: The name of the saved search.
item_types: The item types to include in the search.
search_filter: Structured search criteria.
name: The name of the saved search.
enable_email: Send a daily email when new results are added.
Returns:
Expand Down
4 changes: 2 additions & 2 deletions planet/clients/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ async def create_order(self, request: dict) -> dict:
>>> from planet.order_request import build_request, product
>>>
>>> async def main():
... image_ids = ['3949357_1454705_2020-12-01_241c']
... image_ids = ["20200925_161029_69_2223"]
... request = build_request(
... 'test_order',
... [product(image_ids, 'analytic', 'psorthotile')]
... [product(image_ids, 'analytic_udm2', 'psscene')]
... )
... async with Session() as sess:
... cl = OrdersClient(sess)
Expand Down
58 changes: 58 additions & 0 deletions planet/order_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,61 @@ def harmonize_tool(target_sensor: str) -> dict:
raise ClientError(e)

return _tool('harmonize', {'target_sensor': target_sensor})


def band_math_tool(b1: str,
b2: Optional[str] = None,
b3: Optional[str] = None,
b4: Optional[str] = None,
b5: Optional[str] = None,
b6: Optional[str] = None,
b7: Optional[str] = None,
b8: Optional[str] = None,
b9: Optional[str] = None,
b10: Optional[str] = None,
b11: Optional[str] = None,
b12: Optional[str] = None,
b13: Optional[str] = None,
b14: Optional[str] = None,
b15: Optional[str] = None,
pixel_type: str = specs.BAND_MATH_PIXEL_TYPE_DEFAULT):
'''Specify an Orders API band math tool.

The parameters of the bandmath tool define how each output band in the
derivative product should be produced, referencing the product inputs’
original bands. Band math expressions may not reference neighboring pixels,
as non-local operations are not supported. The tool can calculate up to 15
bands for an item. Input band parameters may not be skipped. For example,
if the b4 parameter is provided, then b1, b2, and b3 parameters are also
required.

For each band expression, the bandmath tool supports normal arithmetic
operations and simple math operators offered in the Python numpy package.
(For a list of supported mathematical functions, see
[Bandmath supported numpy math routines](https://developers.planet.com/apis/orders/bandmath-numpy-routines/)).

One bandmath imagery output file is produced for each product bundle, with
output bands derived from the band math expressions. nodata pixels are
processed with the band math equation. These files have “_bandmath”
appended to their file names.

The tool passes through UDM, RPC, and XML files, and does not update values
in these files.

Parameters:
b1-b15: An expression defining how the output band should be computed.
pixel_type: A value indicating what the output pixel type should be.

Raises:
planet.exceptions.ClientError: If pixel_type is not valid.
''' # noqa
try:
pixel_type = specs.get_match(pixel_type,
specs.BAND_MATH_PIXEL_TYPE,
'pixel_type')
except specs.SpecificationException as e:
raise ClientError(e)

# e.g. {"b1": "b1", "b2":"arctan(b1)"} if b1 and b2 are specified
parameters = dict((k, v) for k, v in locals().items() if v)
return _tool('bandmath', parameters)
4 changes: 3 additions & 1 deletion planet/specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

PRODUCT_BUNDLE_SPEC_NAME = 'orders_product_bundle_2023-02-24.json'
SUPPORTED_TOOLS = [
'band_math',
'bandmath',
'clip',
'composite',
'coregister',
Expand All @@ -34,6 +34,8 @@
SUPPORTED_ARCHIVE_TYPES = ['zip']
SUPPORTED_FILE_FORMATS = ['COG', 'PL_NITF']
HARMONIZE_TOOL_TARGET_SENSORS = ('Sentinel-2', 'PS2')
BAND_MATH_PIXEL_TYPE = ('Auto', '8U', '16U', '16S', '32R')
BAND_MATH_PIXEL_TYPE_DEFAULT = 'Auto'

LOGGER = logging.getLogger(__name__)

Expand Down
9 changes: 3 additions & 6 deletions planet/subscription_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
from . import geojson, specs
from .exceptions import ClientError

BAND_MATH_PIXEL_TYPE = ('Auto', '8U', '16U', '16S', '32R')
BAND_MATH_PIXEL_TYPE_DEFAULT = 'Auto'

NOTIFICATIONS_TOPICS = ('delivery.success',
'delivery.match',
'delivery.failed',
Expand Down Expand Up @@ -133,7 +130,7 @@ def catalog_source(
parameters = {
"item_types": item_types,
"asset_types": asset_types,
"geometry": geometry,
"geometry": geojson.as_geom(geometry),
}

try:
Expand Down Expand Up @@ -296,7 +293,7 @@ def band_math_tool(b1: str,
b13: Optional[str] = None,
b14: Optional[str] = None,
b15: Optional[str] = None,
pixel_type: str = BAND_MATH_PIXEL_TYPE_DEFAULT):
pixel_type: str = specs.BAND_MATH_PIXEL_TYPE_DEFAULT):
'''Specify a subscriptions API band math tool.

The parameters of the bandmath tool define how each output band in the
Expand Down Expand Up @@ -329,7 +326,7 @@ def band_math_tool(b1: str,
''' # noqa
try:
pixel_type = specs.get_match(pixel_type,
BAND_MATH_PIXEL_TYPE,
specs.BAND_MATH_PIXEL_TYPE,
'pixel_type')
except specs.SpecificationException as e:
raise ClientError(e)
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
install_requires = [
'click>=8.0.0',
'geojson',
'httpx==0.23.0',
'httpx>=0.23.0',
'jsonschema',
'pyjwt>=2.1',
'tqdm>=4.56',
'typing-extensions',
]

test_requires = ['pytest', 'pytest-asyncio==0.16', 'pytest-cov', 'respx==0.19']
test_requires = ['pytest', 'anyio', 'pytest-cov', 'respx>=0.20']

lint_requires = ['flake8', 'mypy', 'yapf']

Expand Down
9 changes: 8 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ def get_test_file_json():

def func(filename):
file_path = _test_data_path / filename
return json.load(open(file_path, 'r'))
with open(file_path, 'r') as f:
res = json.load(f)
return res

return func

Expand Down Expand Up @@ -147,3 +149,8 @@ def multipolygon_geom_geojson():
[37.791595458984375, 14.945448293647944],
[37.791595458984375, 14.84923123791421]]]]
} # yapf: disable


@pytest.fixture
def anyio_backend():
return 'asyncio'
2 changes: 1 addition & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_disable_limiter(monkeypatch):


@pytest.fixture
@pytest.mark.asyncio
@pytest.mark.anyio
async def session():
async with planet.Session() as ps:
yield ps
Expand Down
Loading