Skip to content

Commit 4dbe92b

Browse files
Refactor planetary_variable_source() signature (#1170)
* remove source type param from pv source method * docs * update method names and signatrues
1 parent 94b1fd2 commit 4dbe92b

File tree

6 files changed

+43
-75
lines changed

6 files changed

+43
-75
lines changed

docs/cli/cli-subscriptions.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -450,22 +450,21 @@ planet subscriptions request-catalog \
450450
--filter filter.json > request-catalog.json
451451
```
452452

453-
### Planetary Variable Request
454-
455-
Subscribing to Planetary Variables is much like subscribing to imagery from
456-
Planet's catalog. The `planet subscriptions request-pv` command can construct the source
457-
part of a Planetary Variable request like `request-catalog` does for cataloged
458-
imagery. Planetary Variable subscriptions come in 4 types and are further
459-
subdivided within these types by an identifier. See [Subscribing to Planetary
460-
Variables](https://docs.planet.com/develop/apis/subscriptions/sources/#planetary-variable-and-analysis-ready-source-types)
461-
for details. To constrain data delivery by space and time, you will use the
453+
### Planetary Variable and Analysis-Ready Source Requests
454+
455+
Subscribing to Planetary Variables and Analysis-Ready data is much like subscribing to imagery from
456+
Planet's catalog. The `planet subscriptions request-source` command can construct the source
457+
part of a Planetary Variable or Analysis-Ready source request like `request-catalog` does for cataloged
458+
imagery. See [Subscribing to Planetary
459+
Variables and Analysis Ready sources](https://docs.planet.com/develop/apis/subscriptions/sources/#planetary-variable-and-analysis-ready-source-types)
460+
for details about different product options. To constrain data delivery by space and time, you will use the
462461
`--geometry`, `start-time`, and `end-time` options described above.
463462

464463
```sh
465-
planet subscriptions request-pv \
466-
--var-id BIOMASS-PROXY_V3.0_10 \
464+
planet subscriptions request-source \
465+
--source-id BIOMASS-PROXY_V3.0_10 \
467466
--geometry geometry.geojson \
468-
--start-time 2022-08-24T00:00:00-07:00 > request-pv.json
467+
--start-time 2022-08-24T00:00:00-07:00 > request-source.json
469468
```
470469

471470
### Subscription Tools

docs/hooks/mkdocs_hooks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from planet import __version__ as _pl_sdk_version
22

3+
34
def on_config(config):
45
"""
56
This is for injecting the package version into mkdocs

planet/cli/subscriptions.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -535,15 +535,9 @@ def request_catalog(item_types,
535535

536536
@subscriptions.command() # type: ignore
537537
@translate_exceptions
538-
@click.option(
539-
'--var-type',
540-
required=False,
541-
help='A Planetary Variable type. See documentation for all available types.'
542-
)
543-
@click.option(
544-
'--var-id',
545-
required=True,
546-
help='A Planetary Variable ID. See documentation for all available IDs.')
538+
@click.option('--source-id',
539+
required=True,
540+
help='A source ID. See documentation for all available IDs.')
547541
@click.option(
548542
'--geometry',
549543
required=True,
@@ -559,17 +553,14 @@ def request_catalog(item_types,
559553
type=types.DateTime(),
560554
help='Date and time to end subscription.')
561555
@pretty
562-
def request_pv(var_type, var_id, geometry, start_time, end_time, pretty):
563-
"""Generate a Planetary Variable subscription source.
556+
def request_source(source_id, geometry, start_time, end_time, pretty):
557+
"""Generate a subscription source.
564558
565-
Planetary Variables come in 4 types and are further subdivided
566-
within these types. See [Subscribing to Planetary Variables](https://docs.planet.com/develop/apis/subscriptions/sources/#planetary-variable-and-analysis-ready-source-types)
567-
or the [OpenAPI spec](https://api.planet.com/subscriptions/v1/spec) for
568-
more details.
559+
See [Subscribing to Planetary Variables and Analysis Ready sources](https://docs.planet.com/develop/apis/subscriptions/sources/#planetary-variable-and-analysis-ready-source-types)
560+
or the [OpenAPI spec](https://api.planet.com/subscriptions/v1/spec) to learn more about different product options.
569561
"""
570-
res = subscription_request.planetary_variable_source(
571-
var_type,
572-
var_id,
562+
res = subscription_request.subscription_source(
563+
source_id,
573564
geometry,
574565
start_time,
575566
end_time=end_time,

planet/subscription_request.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -272,30 +272,24 @@ def catalog_source(
272272
return {"parameters": parameters}
273273

274274

275-
def planetary_variable_source(
276-
var_type: Optional[str],
277-
var_id: str,
275+
def subscription_source(
276+
source_id: str,
278277
geometry: Union[dict, str],
279278
start_time: datetime,
280279
end_time: Optional[datetime] = None,
281280
) -> dict:
282-
"""Construct a Planetary Variable subscription source.
281+
"""Construct a subscription source.
283282
284-
Planetary Variables come in 4 types and are further subdivided
285-
within these types. See [Subscribing to Planetary Variables](https://docs.planet.com/develop/apis/subscriptions/sources/#planetary-variable-and-analysis-ready-source-types)
286-
or the [OpenAPI spec](https://api.planet.com/subscriptions/v1/spec) for
287-
more details.
283+
See [Subscribing to Planetary Variables and Analysis Ready sources](https://docs.planet.com/develop/apis/subscriptions/sources/#planetary-variable-and-analysis-ready-source-types)
284+
or the [OpenAPI spec](https://api.planet.com/subscriptions/v1/spec) to learn more about different product options.
288285
289286
The return value can be passed to
290287
[planet.subscription_request.build_request][].
291288
292289
Note: this function does not validate variable types and ids.
293290
294291
Parameters:
295-
var_type: Planetary Variable type. See documentation for all
296-
available types. Used to be a required parameter but
297-
is now optional and can be 'None'.
298-
var_id: A Planetary Variable ID. See documenation for all
292+
source_id: A source ID. See documenation for all
299293
available IDs.
300294
geometry: The area of interest of the subscription that will be
301295
used to determine matches. May be a geojson-like dict or a
@@ -315,8 +309,7 @@ def planetary_variable_source(
315309
Examples:
316310
317311
```python
318-
pv_source = planetary_variables_source(
319-
"soil_water_content",
312+
pv_source = subscription_source(
320313
"SWC-AMSR2-C_V1.0_100",
321314
geometry={
322315
"type": "Polygon",
@@ -343,7 +336,7 @@ def planetary_variable_source(
343336
# TODO: validation of variable types and ids.
344337

345338
parameters = {
346-
"id": var_id,
339+
"id": source_id,
347340
"geometry": geojson.as_geom_or_ref(geometry),
348341
}
349342

@@ -359,8 +352,6 @@ def planetary_variable_source(
359352
raise ClientError('Could not convert end_time to an iso string')
360353

361354
source: dict[str, Any] = {"parameters": parameters}
362-
if var_type:
363-
source["type"] = var_type
364355
return source
365356

366357

tests/integration/test_subscriptions_cli.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -418,33 +418,25 @@ def test_subscriptions_results_csv(invoke):
418418
assert result.output.splitlines() == ["id,status", "1234-abcd,SUCCESS"]
419419

420420

421-
@pytest.mark.parametrize("geom, source_type",
422-
[("geom_geojson", "biomass_proxy"),
423-
("geom_reference", None),
424-
("str_geom_reference", None)])
425-
def test_request_pv_success(invoke, geom, source_type, request):
426-
"""Request-pv command succeeds"""
421+
@pytest.mark.parametrize("geom",
422+
[("geom_geojson"), ("geom_reference"),
423+
("str_geom_reference")])
424+
def test_request_source_success(invoke, geom, request):
425+
"""Request-source command succeeds"""
427426
geom = request.getfixturevalue(geom)
428427
if isinstance(geom, dict):
429428
geom = json.dumps(geom)
430429
cmd = [
431-
"request-pv",
432-
"--var-id=BIOMASS-PROXY_V3.0_10",
430+
"request-source",
431+
"--source-id=BIOMASS-PROXY_V3.0_10",
433432
f"--geometry={geom}",
434433
"--start-time=2021-03-01T00:00:00",
435434
]
436435

437-
if source_type:
438-
cmd.append(f"--var-type={source_type}")
439-
440436
result = invoke(cmd)
441437

442438
assert result.exit_code == 0 # success.
443439
source = json.loads(result.output)
444-
if source_type:
445-
assert source["type"] == "biomass_proxy"
446-
else:
447-
assert "type" not in source
448440
assert source["parameters"]["id"] == "BIOMASS-PROXY_V3.0_10"
449441

450442

tests/unit/test_subscription_request.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -556,28 +556,22 @@ def test_toar_tool_success():
556556

557557

558558
@pytest.mark.parametrize(
559-
"var_type, var_id",
559+
"source_id",
560560
[
561-
("biomass_proxy", "BIOMASS-PROXY_V3.0_10"), # actual real type and id.
562-
("var1", "VAR1-ABCD"), # nonsense type and id
563-
(None, "BIOMASS-PROXY_V3.0_10"), # None type with valid id
561+
("BIOMASS-PROXY_V3.0_10"), # actual valid id.
562+
("VAR1-ABCD"), # nonsense id
564563
])
565-
def test_pv_source_success(geom_geojson, var_type, var_id):
564+
def test_subscription_source_success(geom_geojson, source_id):
566565
"""Configure a planetary variable subscription source."""
567-
source = subscription_request.planetary_variable_source(
568-
var_type,
569-
var_id,
566+
source = subscription_request.subscription_source(
567+
source_id,
570568
geometry=geom_geojson,
571569
start_time=datetime(2021, 3, 1),
572570
end_time=datetime(2021, 3, 2),
573571
)
574572

575-
if var_type:
576-
assert source["type"] == var_type
577-
else:
578-
assert "type" not in source
579573
params = source["parameters"]
580-
assert params["id"] == var_id
574+
assert params["id"] == source_id
581575
assert params["geometry"] == geom_geojson
582576
assert params["start_time"].startswith("2021-03-01")
583577

0 commit comments

Comments
 (0)