ncread_cmip: read nc file

View source: R/ncread_cmip.R

ncread_cmipR Documentation

read nc file

Description

getCMIP5date make sure that if dates geenrated according to time and dates in files consistent. If not, error will occur.

Usage

ncread_cmip(
  file,
  varnames = 1L,
  range = NULL,
  delta = 0,
  ntime = -1,
  DatePeriod,
  grid_type = NULL,
  scale = 1,
  offset = 0,
  value_range = NULL,
  adjust_lon = FALSE,
  check_date = FALSE
)

Arguments

file

Character, nc file name.

varnames

String or integer vector which specify which variable to read. if integer vector, for example: 1 means the first variable to read;

  • 0 or NULL: no data to be read, just return dimension infomation

  • -1 : read all data

range

A numeric vector, ⁠[lon_min, lon_max, lat_min, lat_max]⁠. If range is NULL, delta will be ignored, and all data will be read.

delta

suggest 3deg. Extend range into ⁠[lat_min - delta, lat_max + delta, lon_min - delta, lon_max + delta]⁠. This is to make sure no missing value in margin.

ntime

How many time to read?

DatePeriod

Date character vector, starting and ending date. DatePeriod works only in the situation when time2date is true. Note that in that situation if DatePeriod provided, ntime will be overrided.

grid_type

'vec', 'mat' or NULL. If not null, 3d array will be converted to 2d matrix, with the dimension of ⁠[nlon*nlat, ntime]⁠.

  • vec: spdata_array(vals, flip = TRUE) will be applied.

  • mat: spdata_array(vals, flip = FALSE)

scale, offset

If the variable in the netCDF file has a scale and/or offset attribute defined, the returned data are automatically and silently scaled and/or offset as requested. Then you should just leave scale = 1, and offset = 0.

value_range

If not null, values out of value_range are set to NA.

adjust_lon

If true, lon = lon + cellsize_y/2

check_date

If true, check whether date in nc file is consistent with date_begin and date_end in its filename.

Value

list(dim, date, value)

Note

In some CMIP5 file, time band is incorrect. So we decide to generate date by the date information containing in the file name.

This function is initially designed for CMIP5 nc files.

See Also

spdata_array

Examples

## Not run: 
file <- "H:/CMIP5/historical_tasmax/tasmax_day_ACCESS1-0_historical_r1i1p1_20000101-20051231.nc"

range <- c(0, 360, -90, 90)
range <- c(70,140, 15, 55)
l <- ncread_cmip(file, varnames = "tasmax", range = range, delta = 2, ntime = 1)

## End(Not run)


rpkgs/nctools documentation built on Sept. 24, 2023, 9:23 p.m.