calc_nd: Count days meeting set criteria

View source: R/calc_nd.r

calc_ndR Documentation

Count days meeting set criteria

Description

Function to count the number of days in a given time period that meet a given set of criteria. This can be used to extract indices such as Growing Degree Days (tmin > 0), or days with precipitation (prcp != 0).

Usage

calc_nd(
  file,
  start_doy = 1,
  end_doy = 365,
  criteria,
  value,
  internal = FALSE,
  path = tempdir()
)

Arguments

file

path of a file containing the daily gridded Daymet data

start_doy

numeric day-of-year at which counting should begin. (default = 1)

end_doy

numeric day of year at which counting should end. (default = 365)

criteria

logical expression (">=",">","<=","<","==", "!=") to evaluate

value

the value that the criteria is evaluated against

internal

return to workspace (TRUE) or write to disk (FALSE) (default = FALSE)

path

path to which to write data to disk (default = tempdir())

Value

A raster object in the R workspace or a file on disk with summary statistics for every pixel which meet the predefined criteria. Output files if written to file will be named nd_YYYY.tif (with YYYY the year of the processed tile or ncss netCDF file).

Examples


## Not run: 
# download daily gridded data
# using default settings (data written to tempdir())
download_daymet_ncss()

# read in the Daymet file and report back the number
# of days in a year with a minimum temperature lower
# than 15 degrees C
r <- calc_nd(file.path(tempdir(),"tmin_daily_1980_ncss.nc"),
            criteria = "<",
            value = 15,
            internal = TRUE)
            
# plot the output
terra::plot(r)

## End(Not run)

daymetr documentation built on Sept. 15, 2023, 5:07 p.m.