Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

XArray IO can only select time at daily intervals #1099

Open
ghidalgo3 opened this issue Feb 25, 2025 · 0 comments
Open

XArray IO can only select time at daily intervals #1099

ghidalgo3 opened this issue Feb 25, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@ghidalgo3
Copy link

ghidalgo3 commented Feb 25, 2025

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)

@ghidalgo3 ghidalgo3 added the bug Something isn't working label Feb 25, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant