Code Monkey home page Code Monkey logo

odcr's People

Contributors

16eagle avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

odcr's Issues

Add xr.data array to xr.dataset

Hi,
I am trying to add an index I calculated to the original xr.dataset. In python it looks like this:

band_ratio= data.VV- data.VH
data["polRatio"]= band_ratio
print(data)

<xarray.Dataset>
Dimensions:      (time: 59, y: 1538, x: 1718)
Coordinates:
  * time         (time) datetime64[ns] 2019-01-10T16:52:32 ... 2019-12-30T16:...
  * y            (y) float64 5.96e+06 5.96e+06 5.96e+06 ... 5.991e+06 5.991e+06
  * x            (x) float64 3.599e+05 3.599e+05 ... 3.942e+05 3.942e+05
    spatial_ref  int32 32633
Data variables:
    VH           (time, y, x) float32 -19.91 -18.74 -17.19 ... -19.88 -20.44
    VV           (time, y, x) float32 -12.08 -12.63 -10.78 ... -10.14 -11.54
    polRatio     (time, y, x) float32 7.832 6.111 6.404 ... 12.11 9.747 8.906
Attributes:
    crs:           EPSG:32633
    grid_mapping:  spatial_ref
    

Now I try to replicate this in R:

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

ds[["CR"]] <- polRatio

Error in py_set_attr_impl(x, name, value): AttributeError: cannot set attribute 'CR' on a 'Dataset' object. Use __setitem__ styleassignment (e.g., `ds['name'] = ...`) instead of assigning variables.

Detailed traceback:
  File "/home/datacube/anaconda3/envs/jupyterhub/lib/python3.9/site-packages/xarray/core/common.py", line 275, in __setattr__
    raise AttributeError(

Traceback:

1. `[[<-`(`*tmp*`, "CR", value = <environment>)
2. `[[<-.python.builtin.object`(`*tmp*`, "CR", value = <environment>)
3. py_set_attr(x, name, value)
4. py_set_attr_impl(x, name, value)

How can I replicate it successfully?

Thanks and best regards

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

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.