Skip to content

Commit 699f15b

Browse files
authored
Merge pull request #977 from planetlabs/issue968bis
Add support for catalog source publishing stages
2 parents 30cb1c0 + 612d11b commit 699f15b

File tree

4 files changed

+68
-3
lines changed

4 files changed

+68
-3
lines changed

CHANGES.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
2.1.0 (TBD)
22

33
Added:
4-
- Add the option to get Planetary Variable subscription results as a CSV file ().
4+
- Support for catalog source publishing stages has been added to
5+
subscription_request.catalog_source (#977).
6+
- Add the option to get Planetary Variable subscription results as a CSV file
7+
(#981).
58
- A subscription_request.planetary_variable_source function has been added
69
(#976).
710
- The subscription_request.build_request function has a new option to clip to

docs/stylesheets/extra.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,6 @@ section.mdx-container::before{
8585
}
8686
}
8787

88+
.highlight .gp, .highlight .go { /* Generic.Prompt, Generic.Output */
89+
user-select: none;
90+
}

planet/subscription_request.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# the License.
1414
"""Functionality for preparing subscription requests."""
1515
from datetime import datetime
16-
from typing import Any, Dict, Optional, List, Literal, Mapping
16+
from typing import Any, Dict, Optional, List, Literal, Mapping, Sequence
1717

1818
from . import geojson, specs
1919
from .exceptions import ClientError
@@ -151,6 +151,9 @@ def catalog_source(
151151
filter: Optional[Mapping] = None,
152152
end_time: Optional[datetime] = None,
153153
rrule: Optional[str] = None,
154+
publishing_stages: Optional[Sequence[Literal["preview",
155+
"standard",
156+
"finalized"]]] = None,
154157
) -> dict:
155158
"""Construct a Catalog subscription source.
156159
@@ -173,13 +176,38 @@ def catalog_source(
173176
the past or future, and must be after the start_time.
174177
rrule: The recurrence rule, given in iCalendar RFC 5545 format.
175178
Only monthly recurrences are supported at this time.
179+
publishing_stages: A sequence of one or more of the values
180+
"preview", "standard", or "finalized".
176181
177182
Returns:
178183
dict: a representation of a subscription source.
179184
180185
Raises:
181186
ClientError: if a source can not be
182187
configured.
188+
189+
Examples:
190+
```pycon
191+
>>> source = catalog_source(
192+
... ["PSScene"],
193+
... ["ortho_analytic_4b"],
194+
... geometry={
195+
... "type": "Polygon",
196+
... "coordinates": [[[37.791595458984375, 14.84923123791421],
197+
... [37.90214538574219, 14.84923123791421],
198+
... [37.90214538574219, 14.945448293647944],
199+
... [37.791595458984375, 14.945448293647944],
200+
... [37.791595458984375, 14.84923123791421]]]
201+
... },
202+
... start_time=datetime(2021, 3, 1),
203+
... publishing_stages=["standard"],
204+
... )
205+
>>> request = build_request(
206+
... "Standard PSScene Ortho Analytic",
207+
... source=source,
208+
... delivery={})
209+
```
210+
183211
"""
184212
if len(item_types) > 1:
185213
raise ClientError(
@@ -216,6 +244,9 @@ def catalog_source(
216244
if rrule:
217245
parameters['rrule'] = rrule
218246

247+
if publishing_stages:
248+
parameters['publishing_stages'] = list(set(publishing_stages))
249+
219250
return {"type": "catalog", "parameters": parameters}
220251

221252

@@ -275,7 +306,10 @@ def planetary_variable_source(
275306
... },
276307
... start_time=datetime(2021, 3, 1)
277308
... )
278-
>>> request = build_request(source=source, ...)
309+
>>> request = build_request(
310+
... "Soil Water Content",
311+
... source=source,
312+
... delivery={})
279313
```
280314
"""
281315
# TODO: validation of variable types and ids.

tests/unit/test_subscription_request.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
from datetime import datetime
15+
import itertools
1516
import logging
1617

1718
import pytest
@@ -369,3 +370,27 @@ def test_pv_source_success(geom_geojson, var_type, var_id):
369370
assert params["id"] == var_id
370371
assert params["geometry"] == geom_geojson
371372
assert params["start_time"].startswith("2021-03-01")
373+
374+
375+
@pytest.mark.parametrize(
376+
# Test all the combinations of the three options plus some with dupes.
377+
"publishing_stages",
378+
list(
379+
itertools.chain.from_iterable(
380+
itertools.combinations(["preview", "standard", "finalized"], i)
381+
for i in range(1, 4))) + [("preview", "preview"),
382+
("preview", "finalized", "preview")])
383+
def test_catalog_source_publishing_stages(publishing_stages, geom_geojson):
384+
"""Configure publishing stages for a catalog source."""
385+
source = subscription_request.catalog_source(
386+
item_types=["PSScene"],
387+
asset_types=["ortho_analytic_4b"],
388+
geometry=geom_geojson,
389+
start_time=datetime(2021, 3, 1),
390+
end_time=datetime(2023, 11, 1),
391+
rrule="FREQ=MONTHLY;BYMONTH=3,4,5,6,7,8,9,10",
392+
publishing_stages=publishing_stages,
393+
)
394+
395+
assert source["parameters"]["publishing_stages"] == list(
396+
set(publishing_stages))

0 commit comments

Comments
 (0)