Skip to content

Commit

Permalink
Merge pull request #15 from developmentseed/vincents/remove-collection
Browse files Browse the repository at this point in the history
remove collection path parameter and use concept_id query-parameter
  • Loading branch information
vincentsarago authored Feb 8, 2024
2 parents 21af226 + 287509c commit f58a960
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
14 changes: 7 additions & 7 deletions docs/src/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@

## Endpoint Description

`GET /collections/{collectionId}/tiles/{tileMatrixSetId}/{z}/{x}/{y}@{scale}x`
`GET /tiles/{tileMatrixSetId}/{z}/{x}/{y}@{scale}x`

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

`GET /collections/{collectionId}/tiles/{tileMatrixSetId}/{z}/{x}/{y}.{format}`
`GET /tiles/{tileMatrixSetId}/{z}/{x}/{y}.{format}`

`GET /collections/{collectionId}/tiles/{tileMatrixSetId}/{z}/{x}/{y}`
`GET /tiles/{tileMatrixSetId}/{z}/{x}/{y}`

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

## Parameters

- **Path Parameters:**
- `collectionId` (string): The [concept ID](https://cmr.earthdata.nasa.gov/search/site/docs/search/api.html#c-concept-id) of the collection.
- `tileMatrixSetId` (string): TileMatrixSet name (e.g **WebMercatorQuad**)
- `x` (integer): The x coordinate of the tile
- `y` (integer): The y coordinate of the tile
Expand All @@ -26,8 +25,9 @@ This endpoint provides tiled data for specific geographical locations and times.
- `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.

- **Query Parameters:**
- `concept_id` (string): The [concept ID](https://cmr.earthdata.nasa.gov/search/site/docs/search/api.html#c-concept-id) of the collection. **REQUIRED**
- `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**
- `backend` (*cog* or *xarray*, optional): Backend to use in order to read the CMR dataset. Defaults to `cog`
- `backend` (*rasterio* or *xarray*, optional): Backend to use in order to read the CMR dataset. Defaults to `rasterio`
- `variable`* (string, optional): The variable of interest. `required` when using `xarray` backend
- `time_slice`* (string, optional): The time for which data is requested, in ISO 8601 format
- `decode_times`* (bool, optional): Whether to decode times
Expand All @@ -51,7 +51,7 @@ This endpoint provides tiled data for specific geographical locations and times.

## Request Example

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
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


## Responses
Expand Down
8 changes: 3 additions & 5 deletions titiler/cmr/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ class Asset(TypedDict, total=False):
class CMRBackend(BaseBackend):
"""CMR Mosaic Backend."""

# ConceptID
input: str = attr.ib()

tms: TileMatrixSet = attr.ib(default=WEB_MERCATOR_TMS)
minzoom: int = attr.ib()
maxzoom: int = attr.ib()
Expand All @@ -70,6 +67,8 @@ class CMRBackend(BaseBackend):

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

input: str = attr.ib("CMR", init=False)

_backend_name = "CMR"

def __attrs_post_init__(self) -> None:
Expand Down Expand Up @@ -146,7 +145,7 @@ def assets_for_bbox(
@cached( # type: ignore
TTLCache(maxsize=cache_config.maxsize, ttl=cache_config.ttl),
key=lambda self, xmin, ymin, xmax, ymax, **kwargs: hashkey(
self.input, xmin, ymin, xmax, ymax, **kwargs
xmin, ymin, xmax, ymax, **kwargs
),
)
@retry(
Expand All @@ -165,7 +164,6 @@ def get_assets(
) -> List[Asset]:
"""Find assets."""
results = earthaccess.search_data(
concept_id=self.input,
bounding_box=(xmin, ymin, xmax, ymax),
count=limit,
**kwargs,
Expand Down
11 changes: 9 additions & 2 deletions titiler/cmr/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""titiler-cmr dependencies."""

from datetime import datetime
from typing import Dict, List, Literal, Optional, get_args
from typing import Any, Dict, List, Literal, Optional, get_args

from fastapi import HTTPException, Query
from starlette.requests import Request
Expand Down Expand Up @@ -78,6 +78,12 @@ def OutputType(


def cmr_query(
concept_id: Annotated[
str,
Query(
description="A CMR concept id, in the format <concept-type-prefix> <unique-number> '-' <provider-id>"
),
],
temporal: Annotated[
Optional[str],
Query(
Expand All @@ -92,7 +98,8 @@ def cmr_query(
] = None,
) -> Dict:
"""CMR Query options."""
query = {}
query: Dict[str, Any] = {"concept_id": concept_id}

if temporal:
dt = temporal.split("/")
if len(dt) > 2:
Expand Down
20 changes: 6 additions & 14 deletions titiler/cmr/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,33 +370,27 @@ def register_tiles(self): # noqa: C901
"""Register tileset endpoints."""

@self.router.get(
"/collections/{collectionId}/tiles/{tileMatrixSetId}/{z}/{x}/{y}",
"/tiles/{tileMatrixSetId}/{z}/{x}/{y}",
**img_endpoint_params,
tags=["Raster Tiles"],
)
@self.router.get(
"/collections/{collectionId}/tiles/{tileMatrixSetId}/{z}/{x}/{y}.{format}",
"/tiles/{tileMatrixSetId}/{z}/{x}/{y}.{format}",
**img_endpoint_params,
tags=["Raster Tiles"],
)
@self.router.get(
"/collections/{collectionId}/tiles/{tileMatrixSetId}/{z}/{x}/{y}@{scale}x",
"/tiles/{tileMatrixSetId}/{z}/{x}/{y}@{scale}x",
**img_endpoint_params,
tags=["Raster Tiles"],
)
@self.router.get(
"/collections/{collectionId}/tiles/{tileMatrixSetId}/{z}/{x}/{y}@{scale}x.{format}",
"/tiles/{tileMatrixSetId}/{z}/{x}/{y}@{scale}x.{format}",
**img_endpoint_params,
tags=["Raster Tiles"],
)
def tiles_endpoint(
request: Request,
collectionId: Annotated[
str,
Path(
description="A CMR concept id, in the format <concept-type-prefix> <unique-number> '-' <provider-id>"
),
],
tileMatrixSetId: Annotated[
Literal[tuple(self.supported_tms.list())],
Path(description="Identifier for a supported TileMatrixSet"),
Expand Down Expand Up @@ -431,9 +425,9 @@ def tiles_endpoint(
query=Depends(cmr_query),
###################################################################
backend: Annotated[
Literal["cog", "xarray"],
Literal["rasterio", "xarray"],
Query(description="Backend to read the CMR dataset"),
] = "cog",
] = "rasterio",
###################################################################
# ZarrReader Options
###################################################################
Expand Down Expand Up @@ -548,7 +542,6 @@ def tiles_endpoint(
reader_options = {}

with CMRBackend(
collectionId,
tms=tms,
reader=reader,
reader_options=reader_options,
Expand Down Expand Up @@ -741,7 +734,6 @@ def tilejson_endpoint( # type: ignore

# TODO: can we get metadata from the collection?
with CMRBackend(
collectionId,
auth=request.app.state.cmr_auth,
tms=tms,
) as src_dst:
Expand Down

0 comments on commit f58a960

Please sign in to comment.