Predict GPP sample R code


#1

Hi there,

Like a user before me, I am mostly familiar with R. To get a sense for how to access the cube data I am replicating the code available in the jupyter notebook “gpp-prediction-from-air-temp-and-surface-moisture.ipynb”. However I’ve run into an error because for a single cell the read.cube function returns a list object with different dimensions for time (length 1702) and RS variables (length 444). That means that when I try to convert this list into a dataframe I get an error.

I’m using the ESDCv1.0.2/esdc-31d-1deg-1x180x360-1.0.2 cube.

Below the warnings and error messages:

cubepath <- “/home/jovyan/work/datacube/ESDCv1.0.2/esdc-31d-1deg-1x180x360-1.0.2”
cube <- open.cube(cubepath)
Warning message in .parseConfigFile(cubepath):
“NAs introduced by coercion”

x<-read.cube(cube,variable=c(“gross_primary_productivity”,“air_temperature_2m”,“surface_moisture”),
longitude=50,latitude=50)
str(x)
Warning message in unclass(e1) + unclass(e2):
“longer object length is not a multiple of shorter object length”
List of 6
time : POSIXct[1:1702], format: "1980-01-01" "1980-01-09" ... longitude : num 50.5
latitude : num 49.5 gross_primary_productivity: num [1, 1, 1:444] NA NA NA NA NA NA NA NA NA NA …
air_temperature_2m : num [1, 1, 1:444] NA NA NA NA NA NA NA NA NA NA ... surface_moisture : num [1, 1, 1:444] NA NA NA NA NA NA NA NA NA NA …

d=data.frame(time=x$time,gpp=as.vector(x$gross_primary_productivity),tair=as.vector(x$air_temperature_2m),moist=as.vector(x$surface_moisture))

Error in data.frame(time = x$time, gpp = as.vector(x$gross_primary_productivity), : arguments imply differing number of rows: 1702, 444
Traceback:

  1. data.frame(time = x$time, gpp = as.vector(x$gross_primary_productivity),
    . tair = as.vector(x$air_temperature_2m), moist = as.vector(x$surface_moisture))
  2. stop(gettextf(“arguments imply differing number of rows: %s”,
    . paste(unique(nrows), collapse = ", ")), domain = NA)

Thank you for any help regarding this issue,

Jorge


#2

Dear Jorge,

thanks for reporting this. It looks like the reading software is not compatible with the monthly datacube. However, using the 8daily time resolution should work, at least this worked for me:

library(RCABLAB)

cubepath <- '/home/jovyan/work/datacube/ESDCv1.0.2/esdc-8d-0.25deg-46x90x90-1.0.2/'
cube <- open.cube(cubepath)

x<-read.cube(cube,variable=c("gross_primary_productivity","air_temperature_2m","surface_moisture"),
            longitude=35,latitude=55,time=c("2001-01-01","2011-12-31"))

d=data.frame(time=x$time,gpp=as.vector(x$gross_primary_productivity),tair=as.vector(x$air_temperature_2m),moist=as.vector(x$surface_moisture))

Bear also in mind that the support for R is only experimental and might drop in the future. The main reason is that we will use the zarr format as the datacube storage starting with ESDCv2.0 and there is no R package yet that lets you read these datasets.

So we can hope that someone implements this https://github.com/zarr-developers/zarr/issues/279 . Alternatively, if there is strong demand I might test if it is feasible to get basic reading capabilities by making a shallow z5 wrapper through Rcpp.