Slice a netCDF file and create a data.frame according to several dimensions

Hi, I am trying to slice a netCDF file according to two of its dimension (depth and time) with the final intent to create a smaller data frame.

I have tried to do it by using ncdf4

First I extracted the dimension (which was as numeric period format) and converted it into Date

mydata$dim$time$vals <- nc.get.time.series(f = mydata,
                                          time.dim.name = "time") #it works

then I tried to "slice" the nc.data following a question I found online:

Zdim <- which(mydata$dim$depth$vals  > -355 | mydata$dim$depth$vals < -10)
timedim <- which(mydata$dim$time$vals  > as.Date("2017-01-01") | mydata$dim$time$vals < as.Date("2017-04-01"))

it returns an empty vector for timedim and a warning message:

Warning messages:
1: In which(mydata$dim$time$vals > as.Date("2017-01-01") | mydata$dim$time$vals <  :
  Incompatible methods ("Ops.PCICt", ">.Date") for ">"
MyVariable <- ncvar_get( ncFile, varName)[ LonIdx, LatIdx]

the final intent is to get an array or a data.frame with the variable and all the dimensions (four in total) of mydata so I would do this:

newdata <- ncvar_get( mydata, varName)[Zdim, timedime]

Assuming that it will keep the other two dimensions (Lat and Lon).

Otherwise, I learnt that tidync works pretty well, but I do not have any basis knowledge on it.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.