Skip to content

XArray IO can only select time at daily intervals #1099

Closed
@ghidalgo3

Description

@ghidalgo3

Problem description

In xarray.io.get_variable, if the datetime argument is an ISO8601 datetime like 2025-02-25T15:33:38Z with a date and a time, the time part of the datetime is dropped. This causes a problem for assets whose temporal dimension is more frequent than daily, because get_variable will always snap to the nearest day.

I think the fix is to simply remove the split by T and keep datetime intact.

# TODO: Technically we don't have to select the first time, rio-tiler should handle 3D dataset
if "time" in da.dims:
if datetime:
# TODO: handle time interval
time_as_str = datetime.split("T")[0]
if da["time"].dtype == "O":
da["time"] = da["time"].astype("datetime64[ns]")
da = da.sel(
time=numpy.array(time_as_str, dtype=numpy.datetime64), method="nearest"
)
else:
da = da.isel(time=0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions