Giter Club home page Giter Club logo

odcr's Introduction

odcr

CRAN version R-CMD-check Package dependencies

odcr is an R package that serves as a simple interface to the Open Data Cube. As such, it facilitates interaction with an Open Data Cube instance to access, query, list and load data as a native xarray-equivalent class. It implements basic methods to subset/index, plot and execute basic arithmetic operations on data and convert to native spatial raster classes such as stars or raster.

Features (in development)

  • basic database connection (see ?odcr::database)
  • datacube core Datacube class methods (see ?odcr::datacube)
  • datacube core data discovery methods (see ?odcr::datacube
  • datacube core data loading methods (see ?odcr::datacube
  • datacube core grid processing methods
  • datacube core indexing methods
  • support for native proxy class for streaming values directly (such as stars_proxy)
  • xarray xarray.core.dataarray.DataArray class and formal S3 definition
  • xarray xarray.core.dataset.Dataset class and formal S3 definition
  • xarray native S3 methods for retrieving dimensions (see ?odcr::dim)
  • xarray native S3 methods for indexing by arbitrary number of dimensions (see ?odcr::Extract)
  • xarray native S3 methods for indexing by variable (see ?odcr::Extract)
  • xarray native S3 methods for indexing by time strings (see ?odcr::Extract)
  • xarray native S3 methods for assigning/replacing variables (see ?odcr::Extract)
  • xarray native S3 methods for arithmetic operators (see ?odcr::Arithmetic)
  • xarray native S3 methods for coercing to native spatial classes raster* and stars (see ?odcr::as)
  • xarray native S3 methods for plotting (see ?odcr::plot)
  • unit tests
  • configuration (see ?odcr::config)
  • ...

System requirements

odcr requires the Open Data Cube Python library datacube which needs to be installed as part of a working Open Data Cube installation. See odcbox, if you want to install and set-up an Open Data Cube container environment that meets all odcr system requirements "out-of-the-box".

In case you have multiple Python installations or (virtual) environments installed, use odcr::config to make sure that odcr is using the correct Python installation and environment so that it can load and interact with the datacube library.

Installation

odcr is in active development and thus breaking changes to its interface need to be expected. Install the latest development version of odcr from GitHub:

devtools::install_github("eo2cube/odcr")

Build instructions

In case you want to build the package manually, clone the repository and cd to its main directory. odcr uses roxygen2 for documentation. Make sure, devtools, roxygen2 and pkgdown are installed. Run:

source("build.R")

Get Started

See the vignette Using odcr for a full introduction on how to use odcr with Sentinel-2 example data. Documentation and examples are available at https://eo2cube.github.io/odcr/.

List of functions and methods

See the package index.

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.