Title: | Meteorological Data Manipulation |
---|---|
Description: | A set of functions for weather and climate data manipulation, and other helper functions, to support dynamic ecological modeling, particularly crop and crop disease modeling. |
Authors: | Robert J. Hijmans [cre, aut], Gerald Nelson [ctb], Maarten Waterloo [ctb] |
Maintainer: | Robert J. Hijmans <[email protected]> |
License: | GPL-3 |
Version: | 0.4-6 |
Built: | 2024-11-07 03:25:40 UTC |
Source: | https://github.com/cropmodels/meteor |
This pacakges contains of a number of meteorological data manipulation functions. Some of these are also available in other R packages. The context of this package is to make the functions available from dynamic simulation models of crops and crop diseases.
Estimate hourly temperature from daily minimum and maximum temperature, or hourly relative humidity from average relative humidity and minimum and maximum temperature.
The functions require the day of the year and latitude to compute the photoperiod.
hourlyFromDailyTemp(tmin, tmax, doy, latitude) hourlyFromDailyRelh(relh, tmin, tmax, doy, latitude)
hourlyFromDailyTemp(tmin, tmax, doy, latitude) hourlyFromDailyRelh(relh, tmin, tmax, doy, latitude)
tmin |
numeric. minimum temperature (must be in C for hourlyFromDailyRelh) |
tmax |
numeric. maximum temperature (must be in C for hourlyFromDailyRelh) |
relh |
relative humidity (percent) |
doy |
integer. Day of the year (between 1 and 365) |
latitude |
numeric. Latitude |
matrix
hourlyFromDailyTemp(c(20,22), c(28,34), c(150,151), 52) hourlyFromDailyRelh(80, c(20,22), c(28,34), c(150,151), 52)
hourlyFromDailyTemp(c(20,22), c(28,34), c(150,151), 52) hourlyFromDailyRelh(80, c(20,22), c(28,34), c(150,151), 52)
Helper functions for manipulation of dates, includding conversion between (day of year) (DOY) to date and back, and extraction of parts of a date.
dateFromDoy(doy, year) doyFromDate(date) dayFromDate(date) monthFromDate(date) yearFromDate(date) isLeapYear(year) daysInYear(year)
dateFromDoy(doy, year) doyFromDate(date) dayFromDate(date) monthFromDate(date) yearFromDate(date) isLeapYear(year) daysInYear(year)
doy |
integer. Day of the year (1..365) or (1..366) for leap years |
year |
integer. Year, e.g. 1982 |
date |
Date object or character formatted 'yyyy-mm-dd', e.g. '1982-11-23' |
integer or Date
doy <- 88 year <- 1970 date <- dateFromDoy(doy, year) date dateFromDoy(-15, 2000) doyFromDate(date) isLeapYear(2000) daysInYear(2000) daysInYear(1999)
doy <- 88 year <- 1970 date <- dateFromDoy(doy, year) date dateFromDoy(-15, 2000) doyFromDate(date) isLeapYear(2000) daysInYear(2000) daysInYear(1999)
Estimate the mean temperature during the day (between sunrise and sunset) from daily minimum and maximum temperature.
The function requires the day of the year and latitude to compute the photoperiod.
dayTemp(tmin, tmax, doy, latitude)
dayTemp(tmin, tmax, doy, latitude)
tmin |
numeric. minimum temperature (any unit) |
tmax |
numeric. maximum temperature (any unit) |
doy |
integer. Day of the year (between 1 and 365) |
latitude |
numeric. Latitude |
numeric
dayTemp(c(20,22), c(28,34), c(150,151), 52)
dayTemp(c(20,22), c(28,34), c(150,151), 52)
Functions to compute the reference evapotranspiration (ET0) from meteorological data. ET0 is a representation of the atmospheric water demand. The equations estimate the evapotranspiration rate of a short green crop (grass), completely shading the ground, of uniform height and with adequate water status in the soil profile. Actual evapotranspiration is equal reference evapotranspiration when there is ample water, but taller crops could have an evapotranspiration rate that is higher than ET0.
ET0_PenmanMonteith(temp, relh, atmp, Rn, G, ra, rs) ET0_PriestleyTaylor(temp, relh, atmp, Rn, G) ET0_Makkink(temp, relh, atmp, Rs) ET0_ThornthwaiteWilmott(temp, doy, latitude) ET0_ThornthwaiteWilmottCamargo(tmin, tmax, doy, latitude, Pereira=FALSE)
ET0_PenmanMonteith(temp, relh, atmp, Rn, G, ra, rs) ET0_PriestleyTaylor(temp, relh, atmp, Rn, G) ET0_Makkink(temp, relh, atmp, Rs) ET0_ThornthwaiteWilmott(temp, doy, latitude) ET0_ThornthwaiteWilmottCamargo(tmin, tmax, doy, latitude, Pereira=FALSE)
temp |
temperature (degrees C) |
relh |
relative humidity (percent) |
atmp |
air pressure (hPa |
Rn |
net radiation (J m-2 day-1) |
Rs |
incoming solar radiation (J m-2 day-1) |
G |
soil heat flux (J m-2 day-1) |
ra |
aerodynamic resistance (s m-1) |
rs |
surface resistance (s m-1) |
doy |
integer. Day of the year (between 1–365) |
latitude |
numeric. Latitude |
tmin |
numeric. minimum temperature (C) |
tmax |
numeric. maximum temperature (C) |
Pereira |
logical. If |
vector with evaporation values (mm)
Robert Hijmans, partly based on Python evapolib by Maarten J. Waterloo http://python.hydrology-amsterdam.nl/
Allen, R.G., L.S. Pereira, D. Raes and M. Smith, 1998. Crop evapotranspiration. Guidelines for computing crop water requirements. FAO Irrigation and drainage paper 56. FAO - Food and Agriculture Organization of the United Nations, Rome, 1998. (http://www.fao.org/docrep/x0490e/x0490e07.htm)
Thornthwaite, C.W., 1948. An approach toward a rational classification of climate. Geogr. Rev. 38:55-94.
Willmott, C.J., Rowe, C.M. and Mintz, Y., 1985. Climatology of the terrestrial seasonal water cycle. J. Climatol. 5:589-606.
Camargo, A.P., Marin, F.R., Sentelhas, P.C. and Picini, A.G., 1999. Adjust of the Thornthwaite's method to estimate the potential evapotranspiration for arid and superhumid climates, based on daily temperature amplitude. Rev. Bras. Agrometeorol. 7(2):251-257
Pereira, A.R. and W.O. Pruitt, 2004. Adaptation of the Thornthwaite scheme for estimating daily reference evapotranspiration. Agricultural Water Management 66: 251-257
ET0_PenmanMonteith(21.67, 67, 1013, 14100000, 500000, 104, 70) ET0_PriestleyTaylor(21.65, 67, 1013, 18200000, 600000) ET0_Makkink(21.65, 67, 1013, 24200000)
ET0_PenmanMonteith(21.67, 67, 1013, 14100000, 500000, 104, 70) ET0_PriestleyTaylor(21.65, 67, 1013, 18200000, 600000) ET0_Makkink(21.65, 67, 1013, 24200000)
Compute incoming radiation (J day-1 m-2 ) at the top of the atmosphere and photoperiod (daylength, sunshine duration).
ExtraTerrestrialRadiation(doy, latitude, sc=1367.7, FAO=FALSE)
ExtraTerrestrialRadiation(doy, latitude, sc=1367.7, FAO=FALSE)
doy |
integer. Day of the year |
latitude |
numeric. Latitude |
sc |
numeric. The solar constant |
FAO |
logical. If |
matrix with incoming radiation (J/day) and
Robert Hijmans, based on Python meteolib by Maarten J. Waterloo and J. Delsman http://python.hydrology-amsterdam.nl/
Goudriaan and Van Laar, 1995.
R.G. Allen, L.S. Pereira, D. Raes and M. Smith (1998). Crop Evaporation - Guidelines for computing crop water requirements. Irrigation and drainage paper 56. FAO, Rome, Italy. https://www.fao.org/3/x0490e/x0490e07.htm
ExtraTerrestrialRadiation(50, 60) ExtraTerrestrialRadiation(50, 60, FAO=TRUE)
ExtraTerrestrialRadiation(50, 60) ExtraTerrestrialRadiation(50, 60, FAO=TRUE)
Helper functions for extracting information from dates. Or to create a Date from a day number.
fromDate(x, v) fromYear(y, v) fromDoy(doy, y)
fromDate(x, v) fromYear(y, v) fromDoy(doy, y)
x |
Date or POSIX |
y |
integer (year) |
v |
character. Output variable. With |
doy |
integer (day of the year) |
integer or Date
d <- as.Date("1999-12-30") + 1:2 d fromDate(d, "month") fromDate(d, "doy") fromDoy(10, 2000)
d <- as.Date("1999-12-30") + 1:2 d fromDate(d, "month") fromDate(d, "doy") fromDoy(10, 2000)
Read or write FSE formatted weather data
readFSEwth(f) writeFSEwth(w, country='AAA', station=1, lon=0, lat=0, elev=0, path=".") example_weather()
readFSEwth(f) writeFSEwth(w, country='AAA', station=1, lon=0, lat=0, elev=0, path=".") example_weather()
f |
character. filename |
w |
data.frame with daily weather data. Must include the following variables: "date", "srad", "tmin", "tmax", "wind", "prec", "vapr". The data must be sorted by date in ascending order. "date" must be a |
country |
character code for a country (up to three letters) |
station |
positive integer. Station number for the country |
lon |
numeric. Longitude of the weather station (not used by the models) |
lat |
numeric. Latitude of the weather station |
elev |
numeric. Elevation of the weather station |
path |
character. Folder where you want to write the files. It must exist |
readFSEwth
: data.frame
writeFSEwth
: character (invisibly) with the filenames
These are generic functions that are declared in this package but have no implementation here.
Globe temperatures (Tg, Tnwb, WBGT).
The can be computed for either a data.frame
or a SpatRasterDataset
. These must have variables "temp" (C), "rhum" (%), "wind" (m s-1), and "srad" (J s-1 m-2). The data.frame
must also have a variable "date".
## S4 method for signature 'data.frame' Tg(x, latitude) ## S4 method for signature 'SpatRasterDataset' Tg(x, filename="", overwrite=FALSE, ...) ## S4 method for signature 'data.frame' Tnwb(x, latitude, kelvin=FALSE) ## S4 method for signature 'SpatRasterDataset' Tnwb(x, kelvin=FALSE, filename="", overwrite=FALSE, ...) ## S4 method for signature 'data.frame' WBGT(x, latitude, kelvin=FALSE) ## S4 method for signature 'SpatRasterDataset' WBGT(x, kelvin=FALSE, mask=NULL, filename="", overwrite=FALSE, ...)
## S4 method for signature 'data.frame' Tg(x, latitude) ## S4 method for signature 'SpatRasterDataset' Tg(x, filename="", overwrite=FALSE, ...) ## S4 method for signature 'data.frame' Tnwb(x, latitude, kelvin=FALSE) ## S4 method for signature 'SpatRasterDataset' Tnwb(x, kelvin=FALSE, filename="", overwrite=FALSE, ...) ## S4 method for signature 'data.frame' WBGT(x, latitude, kelvin=FALSE) ## S4 method for signature 'SpatRasterDataset' WBGT(x, kelvin=FALSE, mask=NULL, filename="", overwrite=FALSE, ...)
x |
data.frame or SpatRasterDataset |
latitude |
numeric |
filename |
character. Output filename |
overwrite |
logical. If |
... |
additional arguments for writing files as in |
kelvin |
logical. Set to |
mask |
NULL of SpatRaster. if a SpatRaster is used, it should have one layer. No computations are done for cells that are NA, and these are set to NA in the output |
numeric or SpatRaster
wd <- data.frame(date=as.Date("2003-08-28") + 1:3, temp=c(19.1, 20.6, 19.4), rhum=c(66,71,73), wind=c(3.3, 1.9, 1.1), srad=c(168, 178, 125)) Tg(wd, 40.96) Tnwb(wd, 40.96) WBGT(wd, 40.96) library(terra) r <- rast(ncol=2, nrow=2, nlyr=1) temp <- setValues(r, 21:24) time(temp) <- as.Date("2000-01-01") rhum <- setValues(r, 81:84) wind <- setValues(r, 9:12) srad <- setValues(r, 100:103) s <- sds(list(temp=temp, rhum=rhum, wind=wind, srad=srad)) x <- Tg(s) y <- WBGT(s)
wd <- data.frame(date=as.Date("2003-08-28") + 1:3, temp=c(19.1, 20.6, 19.4), rhum=c(66,71,73), wind=c(3.3, 1.9, 1.1), srad=c(168, 178, 125)) Tg(wd, 40.96) Tnwb(wd, 40.96) WBGT(wd, 40.96) library(terra) r <- rast(ncol=2, nrow=2, nlyr=1) temp <- setValues(r, 21:24) time(temp) <- as.Date("2000-01-01") rhum <- setValues(r, 81:84) wind <- setValues(r, 9:12) srad <- setValues(r, 100:103) s <- sds(list(temp=temp, rhum=rhum, wind=wind, srad=srad)) x <- Tg(s) y <- WBGT(s)
Compute photoperiod (daylength, sunshine duration) at a given latitude and day of the year.
## S4 method for signature 'Date' photoperiod(x, latitude) ## S4 method for signature 'data.frame' photoperiod(x) ## S4 method for signature 'SpatRaster' photoperiod(x, filename="", overwrite=FALSE, ...)
## S4 method for signature 'Date' photoperiod(x, latitude) ## S4 method for signature 'data.frame' photoperiod(x) ## S4 method for signature 'SpatRaster' photoperiod(x, filename="", overwrite=FALSE, ...)
x |
Date, integer (day of the year), or data.frame (with variables "date" and "latitude", or SpatRaster |
latitude |
numeric. Latitude |
filename |
character. Output filename |
overwrite |
logical. If |
... |
additional arguments for writing files as in |
double. Photoperiod in hours
Forsythe, W.C., E.J. Rykiel Jr., R.S. Stahl, H. Wu, R.M. Schoolfield, 1995. A model comparison for photoperiod as a function of latitude and day of the year. Ecological Modeling 80: 87-95.
photoperiod(50, 52) photoperiod(50, 5) photoperiod(180, 55) p <- photoperiod(1:365, 52) d <- dateFromDoy(1:365, 2001) plot(d, p)
photoperiod(50, 52) photoperiod(50, 5) photoperiod(180, 55) p <- photoperiod(1:365, 52) d <- dateFromDoy(1:365, 2001) plot(d, p)
This functions returns a data.frame with weather data from the NASA POWER database. It has the date, incoming solar radiation (srad, kJ m-2 day-1), minimum temperature (tmin, degrees C) and maximum temperature (tmax, degrees C), vapor pressure (vapr, Pa), precipitation (prec, mm), and windspeed (wind, m/s)
The data are from 1983-01-01 to 2016-12-31
Missing values for radiation (Jan to June 1983 and ...) and a few inbetween were replaced by the long term averages.
There are no precipitation values before 1997-01-01. Missing values for precipitaion after that date were estimated as the long term average (i.e., not a particularly good method).
The data are at 1 degree spatial resolution. That is, they are the average for a large grid cell.
These are estimates. They can give a good general impression, but they are not ground observations.
Data are downloaded as-needed by tile. By default to folder called "power" in your working directory.
power_weather(lon, lat, folder=file.path(getwd(), 'power'), tiles=FALSE, ...)
power_weather(lon, lat, folder=file.path(getwd(), 'power'), tiles=FALSE, ...)
lon |
numeric |
lat |
numeric |
folder |
character |
tiles |
logical. Download by tile? |
... |
additional arguments |
data.frame
## Not run: w <- power_weather(5, 50) w$srad <- w$srad * 1000 wth <- subset(w, date > as.Date('2012-01-01')) head(wth) ## End(Not run)
## Not run: w <- power_weather(5, 50) w$srad <- w$srad * 1000 wth <- subset(w, date > as.Date('2012-01-01')) head(wth) ## End(Not run)
pwc
## S4 method for signature 'numeric' pwc(x, input="wbgt", adjust=TRUE) ## S4 method for signature 'SpatRaster' pwc(x, input="wbgt", adjust=TRUE, filename="", overwrite=FALSE, ...)
## S4 method for signature 'numeric' pwc(x, input="wbgt", adjust=TRUE) ## S4 method for signature 'SpatRaster' pwc(x, input="wbgt", adjust=TRUE, filename="", overwrite=FALSE, ...)
x |
numeric or SpatRaster |
input |
character. One of "wbgt" or "utci" |
adjust |
logical. If |
filename |
character. Output filename |
overwrite |
logical. If |
... |
additional arguments for writing files as in |
numeric or SpatRaster
Smallcombe et al.. 2022
Foster et al., 2022
pwc(25)
pwc(25)
utci
## S4 method for signature 'data.frame' utci(x)
## S4 method for signature 'data.frame' utci(x)
x |
data.frame |
numeric or SpatRaster
d <- data.frame(temp=20, rhum=80, tglb=22, wind=10) utci(d)
d <- data.frame(temp=20, rhum=80, tglb=22, wind=10) utci(d)
Functions to compute the saturated vapor pressure (SVP), actual vapor pressure (VP), and vapor pressure deficit (VPD) in Pascal or the dew-point temperature in C.
For temperature < 0C the saturation vapour pressure equation for ice is used according to Goff and Gratch (1946), whereas for temperature >=0C that of Goff (1957) is used.
SVP(temp) VP(temp, relh) VPD(temp, relh) tDew(temp, relh)
SVP(temp) VP(temp, relh) VPD(temp, relh) tDew(temp, relh)
temp |
numeric. Temperature in degrees C |
relh |
relative humidity (percent) |
numeric vector (Pascal).
Robert Hijmans, partly based on Python meteolib by Maarten J. Waterloo and J. Delsman http://python.hydrology-amsterdam.nl/
Goff, J.A.,and S. Gratch, 1946. Low-pressure properties of water from -160 to 212 F. Transactions of the American society of heating and ventilating engineers, p. 95-122, presented at the 52nd annual meeting of the American society of heating and ventilating engineers, New York, USA.
Goff, J. A. 1957. Saturation pressure of water on the new Kelvin temperature scale, Transactions of the American society of heating and ventilating engineers, pp 347-354, presented at the semi-annual meeting of the American society of heating and ventilating engineers, Murray Bay, Quebec, Canada.
temperature <- seq(-10,30,10) SVP(temperature) VP(temperature, 60) VPD(temperature, 60) tDew(temperature, 60)
temperature <- seq(-10,30,10) SVP(temperature) VP(temperature, 60) VPD(temperature, 60) tDew(temperature, 60)
Weather data
Objects can be created by calls of the form new("Weather", ...)
, or with the helper functions such as weather
.
Slots of Weather objects
data
:data.frame with the weather data
ID
:character
name
:character
country
:character
longitude
:numeric
latitude
:numeric
elevation
:numeric
showClass("Weather")
showClass("Weather")