While it is not consistent with the Unidata conventions and recommendations, some netcdf files have a time variable with units of the form "years since {some_date}". An
Example file was obtained from the KNMI Climate Explorer. With the R
package metR
version 0.11.0
reading in such a file using ReadNetCDF()
yields a reasonable output (as in, a date/time unambiguously in the correct year), at least for multi-decadal length data with reference date near the middle of the year. With metR 0.14.0
, nc_ts = ReadNetCDF("sample_yrtime.nc")
yields the warning:
In .parse_time(ncfile$dim[[dims[i]]]$vals, ncfile$dim[[dims[i]]]$units,:
time unit has unrecognised units: years. Not parsing.
The time
column in the output data.table
is essentially an integer index. Is there a way to extract the reference date ({some_date}) or to recover the correct year for each data point using metR >= 0.14
? At the moment I'm manually reading the reference date with other software and then doing something like:
library(data.table)
yr0 = 1960
nc_ts[, yr := time + yr0]