Skip to content

Commit 287509c

Browse files
committed
remove collection path parameter and use concept_id query-parameter
1 parent 21af226 commit 287509c

File tree

4 files changed

+25
-28
lines changed

4 files changed

+25
-28
lines changed

docs/src/API.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@
44

55
## Endpoint Description
66

7-
`GET /collections/{collectionId}/tiles/{tileMatrixSetId}/{z}/{x}/{y}@{scale}x`
7+
`GET /tiles/{tileMatrixSetId}/{z}/{x}/{y}@{scale}x`
88

9-
`GET /collections/{collectionId}/tiles/{tileMatrixSetId}/{z}/{x}/{y}@{scale}x.{format}`
9+
`GET /tiles/{tileMatrixSetId}/{z}/{x}/{y}@{scale}x.{format}`
1010

11-
`GET /collections/{collectionId}/tiles/{tileMatrixSetId}/{z}/{x}/{y}.{format}`
11+
`GET /tiles/{tileMatrixSetId}/{z}/{x}/{y}.{format}`
1212

13-
`GET /collections/{collectionId}/tiles/{tileMatrixSetId}/{z}/{x}/{y}`
13+
`GET /tiles/{tileMatrixSetId}/{z}/{x}/{y}`
1414

1515
This endpoint provides tiled data for specific geographical locations and times. Tiles are defined by their x, y, and z coordinates.
1616

1717
## Parameters
1818

1919
- **Path Parameters:**
20-
- `collectionId` (string): The [concept ID](https://cmr.earthdata.nasa.gov/search/site/docs/search/api.html#c-concept-id) of the collection.
2120
- `tileMatrixSetId` (string): TileMatrixSet name (e.g **WebMercatorQuad**)
2221
- `x` (integer): The x coordinate of the tile
2322
- `y` (integer): The y coordinate of the tile
@@ -26,8 +25,9 @@ This endpoint provides tiled data for specific geographical locations and times.
2625
- `format` (string, optional): Output image format, default is set to None and will be either JPEG or PNG depending on the presence of masked value.
2726

2827
- **Query Parameters:**
28+
- `concept_id` (string): The [concept ID](https://cmr.earthdata.nasa.gov/search/site/docs/search/api.html#c-concept-id) of the collection. **REQUIRED**
2929
- `temporal` (string, optional): Either a date-time or an interval. Date and time expressions adhere to 'YYYY-MM-DD' format. Intervals may be bounded or half-bounded (double-dots at start or end) **RECOMMENDED**
30-
- `backend` (*cog* or *xarray*, optional): Backend to use in order to read the CMR dataset. Defaults to `cog`
30+
- `backend` (*rasterio* or *xarray*, optional): Backend to use in order to read the CMR dataset. Defaults to `rasterio`
3131
- `variable`* (string, optional): The variable of interest. `required` when using `xarray` backend
3232
- `time_slice`* (string, optional): The time for which data is requested, in ISO 8601 format
3333
- `decode_times`* (bool, optional): Whether to decode times
@@ -51,7 +51,7 @@ This endpoint provides tiled data for specific geographical locations and times.
5151

5252
## Request Example
5353

54-
GET /collections/C0000000000-YOCLOUD/tiles/WebMercatorQuad/1/2/3?backend=xarray&variable=temperature&timestamp=2024-01-16T00:00:00Z&colormap=viridis&rescale=0,100&temporal=2024-01-16/2024-01-16
54+
GET /tiles/WebMercatorQuad/1/2/3?backend=xarray&variable=temperature&timestamp=2024-01-16T00:00:00Z&colormap=viridis&rescale=0,100&temporal=2024-01-16/2024-01-16&concept_id=C0000000000-YOCLOUD
5555

5656

5757
## Responses

titiler/cmr/backend.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ class Asset(TypedDict, total=False):
4949
class CMRBackend(BaseBackend):
5050
"""CMR Mosaic Backend."""
5151

52-
# ConceptID
53-
input: str = attr.ib()
54-
5552
tms: TileMatrixSet = attr.ib(default=WEB_MERCATOR_TMS)
5653
minzoom: int = attr.ib()
5754
maxzoom: int = attr.ib()
@@ -70,6 +67,8 @@ class CMRBackend(BaseBackend):
7067

7168
auth: Optional[Auth] = attr.ib(default=None)
7269

70+
input: str = attr.ib("CMR", init=False)
71+
7372
_backend_name = "CMR"
7473

7574
def __attrs_post_init__(self) -> None:
@@ -146,7 +145,7 @@ def assets_for_bbox(
146145
@cached( # type: ignore
147146
TTLCache(maxsize=cache_config.maxsize, ttl=cache_config.ttl),
148147
key=lambda self, xmin, ymin, xmax, ymax, **kwargs: hashkey(
149-
self.input, xmin, ymin, xmax, ymax, **kwargs
148+
xmin, ymin, xmax, ymax, **kwargs
150149
),
151150
)
152151
@retry(
@@ -165,7 +164,6 @@ def get_assets(
165164
) -> List[Asset]:
166165
"""Find assets."""
167166
results = earthaccess.search_data(
168-
concept_id=self.input,
169167
bounding_box=(xmin, ymin, xmax, ymax),
170168
count=limit,
171169
**kwargs,

titiler/cmr/dependencies.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""titiler-cmr dependencies."""
22

33
from datetime import datetime
4-
from typing import Dict, List, Literal, Optional, get_args
4+
from typing import Any, Dict, List, Literal, Optional, get_args
55

66
from fastapi import HTTPException, Query
77
from starlette.requests import Request
@@ -78,6 +78,12 @@ def OutputType(
7878

7979

8080
def cmr_query(
81+
concept_id: Annotated[
82+
str,
83+
Query(
84+
description="A CMR concept id, in the format <concept-type-prefix> <unique-number> '-' <provider-id>"
85+
),
86+
],
8187
temporal: Annotated[
8288
Optional[str],
8389
Query(
@@ -92,7 +98,8 @@ def cmr_query(
9298
] = None,
9399
) -> Dict:
94100
"""CMR Query options."""
95-
query = {}
101+
query: Dict[str, Any] = {"concept_id": concept_id}
102+
96103
if temporal:
97104
dt = temporal.split("/")
98105
if len(dt) > 2:

titiler/cmr/factory.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -370,33 +370,27 @@ def register_tiles(self): # noqa: C901
370370
"""Register tileset endpoints."""
371371

372372
@self.router.get(
373-
"/collections/{collectionId}/tiles/{tileMatrixSetId}/{z}/{x}/{y}",
373+
"/tiles/{tileMatrixSetId}/{z}/{x}/{y}",
374374
**img_endpoint_params,
375375
tags=["Raster Tiles"],
376376
)
377377
@self.router.get(
378-
"/collections/{collectionId}/tiles/{tileMatrixSetId}/{z}/{x}/{y}.{format}",
378+
"/tiles/{tileMatrixSetId}/{z}/{x}/{y}.{format}",
379379
**img_endpoint_params,
380380
tags=["Raster Tiles"],
381381
)
382382
@self.router.get(
383-
"/collections/{collectionId}/tiles/{tileMatrixSetId}/{z}/{x}/{y}@{scale}x",
383+
"/tiles/{tileMatrixSetId}/{z}/{x}/{y}@{scale}x",
384384
**img_endpoint_params,
385385
tags=["Raster Tiles"],
386386
)
387387
@self.router.get(
388-
"/collections/{collectionId}/tiles/{tileMatrixSetId}/{z}/{x}/{y}@{scale}x.{format}",
388+
"/tiles/{tileMatrixSetId}/{z}/{x}/{y}@{scale}x.{format}",
389389
**img_endpoint_params,
390390
tags=["Raster Tiles"],
391391
)
392392
def tiles_endpoint(
393393
request: Request,
394-
collectionId: Annotated[
395-
str,
396-
Path(
397-
description="A CMR concept id, in the format <concept-type-prefix> <unique-number> '-' <provider-id>"
398-
),
399-
],
400394
tileMatrixSetId: Annotated[
401395
Literal[tuple(self.supported_tms.list())],
402396
Path(description="Identifier for a supported TileMatrixSet"),
@@ -431,9 +425,9 @@ def tiles_endpoint(
431425
query=Depends(cmr_query),
432426
###################################################################
433427
backend: Annotated[
434-
Literal["cog", "xarray"],
428+
Literal["rasterio", "xarray"],
435429
Query(description="Backend to read the CMR dataset"),
436-
] = "cog",
430+
] = "rasterio",
437431
###################################################################
438432
# ZarrReader Options
439433
###################################################################
@@ -548,7 +542,6 @@ def tiles_endpoint(
548542
reader_options = {}
549543

550544
with CMRBackend(
551-
collectionId,
552545
tms=tms,
553546
reader=reader,
554547
reader_options=reader_options,
@@ -741,7 +734,6 @@ def tilejson_endpoint( # type: ignore
741734

742735
# TODO: can we get metadata from the collection?
743736
with CMRBackend(
744-
collectionId,
745737
auth=request.app.state.cmr_auth,
746738
tms=tms,
747739
) as src_dst:

0 commit comments

Comments
 (0)