Skip to content

xr$interp problem with translation from posXct to np.datetime64 #2

Open
@jmarkloew

Description

@jmarkloew

I tried to interpolate a xr.dataarray in R with this code:

polRatio <- ds$VV/ds$VH
polRatio$attrs$units= "VV/VH"

load_sq= seq.Date(from = as.Date("01/10/2019", format= "%m/%d/%Y"), to= as.Date("12/31/2019", format= "%m/%d/%Y"), by= "6 day")
intp_sq= seq.POSIXt(from = as.POSIXct("01/10/2019", format= "%m/%d/%Y"), to= as.POSIXct("12/31/2019", format= "%m/%d/%Y"), by= "day")

intp_sq= intp_sq[-which(intp_sq %in% load_sq)]

CR_intp= polRatio$interp(time= intp_sq[1:length(intp_sq)])

But it gave me the following error:

Error in py_call_impl(callable, dots$args, dots$keywords): KeyError: numpy.datetime64('NaT')

Detailed traceback:
  File "/home/datacube/anaconda3/envs/jupyterhub/lib/python3.9/site-packages/xarray/core/dataarray.py", line 1725, in interp
    ds = self._to_temp_dataset().interp(
  File "/home/datacube/anaconda3/envs/jupyterhub/lib/python3.9/site-packages/xarray/core/dataset.py", line 3131, in interp
    obj, newidx = missing._localize(obj, {k: v})
  File "/home/datacube/anaconda3/envs/jupyterhub/lib/python3.9/site-packages/xarray/core/missing.py", line 559, in _localize
    imin = index.get_loc(minval, method="nearest")
  File "/home/datacube/anaconda3/envs/jupyterhub/lib/python3.9/site-packages/pandas/core/indexes/datetimes.py", line 705, in get_loc
    raise KeyError(orig_key) from err

Traceback:

1. polRatio$interp(time = intp_sq[1:length(intp_sq)])
2. py_call_impl(callable, dots$args, dots$keywords)

I also checked the type of the timestamp object of the xr.dataarray I was trying to interpolate and it is posxct
I am definitely no expert but could it point to a problem with the translation from posixct to np.datetime64?

Thanks and best regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions