eo2cube / odcr Goto Github PK
View Code? Open in Web Editor NEWodcr is an R package that serves as an interface to the Open Data Cube.
Home Page: https://eo2cube.github.io/odcr/
License: GNU General Public License v3.0
odcr is an R package that serves as an interface to the Open Data Cube.
Home Page: https://eo2cube.github.io/odcr/
License: GNU General Public License v3.0
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
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.