nc <- nc_open("xxxxx")
print(nc)
*Time variable info printed....*
time Size:22281`
axis: T`
bounds: time_bounds
units: hours since 1800-01-01 00:00:00
standard_name:time
calendar: gregorian
region <- ncvar_get(nc, "geo_region")
temp <- ncvar_get(nc, "tasmin")
time <- nc.get.time.series(f = nc,
correct.for.gregorian.julian = TRUE,
time.dim.name = "time")
使该文件进入可用的每日区域温度 DF 的最佳方法是什么?我不确定我是否已将时间变量转换为 2021 年 11 月结束,但应该是 12 月。
我下载了该文件,得到了 22,646 个观察值的时间维度。
CFtime
包,您可以轻松处理气候观测文件中的时间维度,如下所示:
library(CFtime)
nc <- nc_open("./tasmin_hadukgrid_uk_region_day_19600101-20211231.nc")
# Use CFtime to read in the time dimension from the file.
cf <- CFtime(nc$dim$time$units, nc$dim$time$calendar, nc$dim$time$vals)
# Get the dates as a character vector
dates <- CFtimestamp(cf)
# The "geo_region" variable has the names of the administrative units
region <- ncvar_get(nc, "geo_region")
# Read the data, transpose to get regions in columns and dates in rows
tasmin <- t(ncvar_get(nc, "tasmin"))
nc_close(nc)
# Set the dimnames on the array
dimnames(tasmin) <- list(dates, region)
# Convert the array to a data.frame
tasmin <- as.data.frame(tasmin)