Skip to content

Commit cde1713

Browse files
authored
Merge pull request #988 from planetlabs/issue987
request-pv and request --clip-to-source
2 parents 33f6903 + 6ca6f03 commit cde1713

File tree

4 files changed

+115
-6
lines changed

4 files changed

+115
-6
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
2.1b1 (2023-07-11)
44

55
Added:
6+
- The request command of the subscriptions CLI has a new --clip-to-source
7+
option (#988).
8+
- A new request-pv command has been added to the subscriptions CLi (#988).
69
- Support for catalog source publishing stages (#977) and time range types
710
(#978) have been added to subscription_request.catalog_source.
811
- Add the option to get Planetary Variable subscription results as a CSV file

planet/cli/subscriptions.py

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,32 @@ async def list_subscription_results_cmd(ctx,
238238
'--tools',
239239
type=types.JSON(),
240240
help='Toolchain JSON. Can be a string, filename, or - for stdin.')
241+
@click.option(
242+
'--clip-to-source',
243+
is_flag=True,
244+
default=False,
245+
help="Clip to the source geometry without specifying a clip tool.")
241246
@pretty
242-
def request(name, source, delivery, notifications, tools, pretty):
243-
"""Generate a subscriptions request."""
247+
def request(name,
248+
source,
249+
delivery,
250+
notifications,
251+
tools,
252+
clip_to_source,
253+
pretty):
254+
"""Generate a subscriptions request.
255+
256+
Note: the next version of the Subscription API will remove the clip
257+
tool option and always clip to the source geometry. Thus the
258+
--clip-to-source option is a preview of the next API version's
259+
default behavior.
260+
"""
244261
res = subscription_request.build_request(name,
245262
source,
246263
delivery,
247264
notifications=notifications,
248-
tools=tools)
265+
tools=tools,
266+
clip_to_source=clip_to_source)
249267
echo_json(res, pretty)
250268

251269

@@ -298,3 +316,49 @@ def request_catalog(item_types,
298316
rrule=rrule,
299317
filter=filter)
300318
echo_json(res, pretty)
319+
320+
321+
@subscriptions.command() # type: ignore
322+
@translate_exceptions
323+
@click.option(
324+
'--var-type',
325+
required=True,
326+
help='Planetary variable type.',
327+
type=click.Choice([
328+
"biomass_proxy",
329+
"land_surface_temperature",
330+
"soil_water_content",
331+
"vegetation_optical_depth"
332+
]),
333+
)
334+
@click.option('--var-id', required=True, help='Planetary variable id.')
335+
@click.option(
336+
'--geometry',
337+
required=True,
338+
type=types.JSON(),
339+
help="""Geometry of the area of interest of the subscription that will be
340+
used to determine matches. Can be a string, filename, or - for stdin.""")
341+
@click.option('--start-time',
342+
required=True,
343+
type=types.DateTime(),
344+
help='Date and time to begin subscription.')
345+
@click.option('--end-time',
346+
type=types.DateTime(),
347+
help='Date and time to end subscription.')
348+
@pretty
349+
def request_pv(var_type, var_id, geometry, start_time, end_time, pretty):
350+
"""Generate a Planetary Variable subscription source.
351+
352+
Planetary Variables come in 4 types and are further subdivided
353+
within these types. See [Subscribing to Planetary
354+
Variables](https://developers.planet.com/docs/subscriptions/pvs-subs/#planetary-variables-types-and-ids)
355+
for details.
356+
"""
357+
res = subscription_request.planetary_variable_source(
358+
var_type,
359+
var_id,
360+
geometry,
361+
start_time,
362+
end_time=end_time,
363+
)
364+
echo_json(res, pretty)

planet/subscription_request.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ def build_request(name: str,
118118
if notifications:
119119
details['notifications'] = dict(notifications)
120120

121-
if tools:
122-
tool_list = [dict(tool) for tool in tools]
121+
if tools or clip_to_source:
122+
tool_list = [dict(tool) for tool in (tools or [])]
123123

124124
# If clip_to_source is True a clip configuration will be added
125125
# to the list of requested tools unless an existing clip tool

tests/integration/test_subscriptions_cli.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def test_subscriptions_results_success(invoke, options, expected_count):
252252

253253

254254
def test_request_base_success(invoke, geom_geojson):
255-
"""Request command succeeds"""
255+
"""Request command succeeds."""
256256
source = json.dumps({
257257
"type": "catalog",
258258
"parameters": {
@@ -285,6 +285,32 @@ def test_request_base_success(invoke, geom_geojson):
285285
assert result.exit_code == 0 # success.
286286

287287

288+
def test_request_base_clip_to_source(invoke, geom_geojson):
289+
"""Clip to source using command line option."""
290+
source = json.dumps({
291+
"type": "catalog",
292+
"parameters": {
293+
"geometry": geom_geojson,
294+
"start_time": "2021-03-01T00:00:00Z",
295+
"item_types": ["PSScene"],
296+
"asset_types": ["ortho_analytic_4b"]
297+
}
298+
})
299+
result = invoke([
300+
'request',
301+
'--name=test',
302+
f'--source={source}',
303+
'--delivery={"type": "fake"}',
304+
'--clip-to-source'
305+
])
306+
307+
assert result.exit_code == 0 # success.
308+
req = json.loads(result.output)
309+
tool = req["tools"][0]
310+
assert tool["type"] == "clip"
311+
assert tool["parameters"]["aoi"] == geom_geojson
312+
313+
288314
def test_request_catalog_success(invoke, geom_geojson):
289315
"""Request-catalog command succeeds"""
290316
source = {
@@ -314,3 +340,19 @@ def test_subscriptions_results_csv(invoke):
314340
result = invoke(['results', 'test', '--csv'])
315341
assert result.exit_code == 0 # success.
316342
assert result.output.splitlines() == ['id,status', '1234-abcd,SUCCESS']
343+
344+
345+
def test_request_pv_success(invoke, geom_geojson):
346+
"""Request-pv command succeeds"""
347+
result = invoke([
348+
'request-pv',
349+
'--var-type=biomass_proxy',
350+
'--var-id=BIOMASS-PROXY_V3.0_10',
351+
f"--geometry={json.dumps(geom_geojson)}",
352+
'--start-time=2021-03-01T00:00:00'
353+
])
354+
355+
assert result.exit_code == 0 # success.
356+
source = json.loads(result.output)
357+
assert source["type"] == "biomass_proxy"
358+
assert source["parameters"]["id"] == "BIOMASS-PROXY_V3.0_10"

0 commit comments

Comments
 (0)