Skip to content

Commit

Permalink
Merge pull request #53 from developmentseed/ab/change-timeslice-to-da…
Browse files Browse the repository at this point in the history
…tetime

Change time_slice to datetime
  • Loading branch information
abarciauskas-bgse authored Mar 21, 2024
2 parents 52fd61a + 9ca652a commit c0893d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions titiler/xarray/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def tiles_endpoint( # type: ignore
Optional[str],
Query(description="Dimension to drop"),
] = None,
time_slice: Annotated[
datetime: Annotated[
Optional[str], Query(description="Slice of time to read (if available)")
] = None,
post_process=Depends(self.process_dependency),
Expand All @@ -239,7 +239,7 @@ def tiles_endpoint( # type: ignore
reference=reference,
decode_times=decode_times,
drop_dim=drop_dim,
time_slice=time_slice,
datetime=datetime,
tms=tms,
consolidated=consolidated,
) as src_dst:
Expand Down Expand Up @@ -313,7 +313,7 @@ def tilejson_endpoint( # type: ignore
Optional[str],
Query(description="Dimension to drop"),
] = None,
time_slice: Annotated[
datetime: Annotated[
Optional[str], Query(description="Slice of time to read (if available)")
] = None,
tile_format: Annotated[
Expand Down Expand Up @@ -490,7 +490,7 @@ def map_viewer(
Optional[str],
Query(description="Dimension to drop"),
] = None,
time_slice: Annotated[
datetime: Annotated[
Optional[str], Query(description="Slice of time to read (if available)")
] = None,
tile_format: Annotated[
Expand Down
10 changes: 5 additions & 5 deletions titiler/xarray/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def arrange_coordinates(da: xarray.DataArray) -> xarray.DataArray:
def get_variable(
ds: xarray.Dataset,
variable: str,
time_slice: Optional[str] = None,
datetime: Optional[str] = None,
drop_dim: Optional[str] = None,
) -> xarray.DataArray:
"""Get Xarray variable as DataArray."""
Expand All @@ -179,8 +179,8 @@ def get_variable(
da = da.sortby(da.x)

if "time" in da.dims:
if time_slice:
time_as_str = time_slice.split("T")[0]
if datetime:
time_as_str = datetime.split("T")[0]
if da["time"].dtype == "O":
da["time"] = da["time"].astype("datetime64[ns]")
da = da.sel(
Expand All @@ -206,7 +206,7 @@ class ZarrReader(XarrayReader):
consolidated: Optional[bool] = attr.ib(default=True)

# xarray.DataArray options
time_slice: Optional[str] = attr.ib(default=None)
datetime: Optional[str] = attr.ib(default=None)
drop_dim: Optional[str] = attr.ib(default=None)

tms: TileMatrixSet = attr.ib(default=WEB_MERCATOR_TMS)
Expand Down Expand Up @@ -237,7 +237,7 @@ def __attrs_post_init__(self):
self.input = get_variable(
self.ds,
self.variable,
time_slice=self.time_slice,
datetime=self.datetime,
drop_dim=self.drop_dim,
)

Expand Down

0 comments on commit c0893d1

Please sign in to comment.