Title: | Analysis the Weather Data |
---|---|
Description: | Functions are collected to analyse weather data for agriculture purposes including to read weather records in multiple formats, calculate extreme climate index. |
Authors: | Bangyou Zheng [aut, cre] |
Maintainer: | Bangyou Zheng <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.0 |
Built: | 2025-02-12 04:30:39 UTC |
Source: | https://github.com/byzheng/weaana |
Getter to access the weather data at a specific position.
## S4 method for signature 'WeaAna' x[i, j, drop]
## S4 method for signature 'WeaAna' x[i, j, drop]
x |
A WeaAna object. |
i |
the specific position which will access. |
j |
None use parameter. |
drop |
None use parameter. |
A WeaAnaSite object at the position i.
library(weaana) data( "WeatherRecordsDemo" ) records[1] records[1:2] records[2:2]
library(weaana) data( "WeatherRecordsDemo" ) records[1] records[1:2] records[2:2]
Change weather records
Change weather records
changeWeatherRecords(object, ...) ## S4 method for signature 'WeaAna' changeWeatherRecords(object, ...)
changeWeatherRecords(object, ...) ## S4 method for signature 'WeaAna' changeWeatherRecords(object, ...)
object |
A WeaAna object. |
... |
New weather records |
A new WeaAna object with updated records
Summarise the climate variable by growth stages
climate_by_stages( climates, sowing, emergence, heading = NULL, flowering = NULL, maturity, latitude )
climate_by_stages( climates, sowing, emergence, heading = NULL, flowering = NULL, maturity, latitude )
climates |
a data.frame for climate records |
sowing |
date. an vector of sowing date |
emergence |
numeric (days after sowing). an vector of emergence date |
heading |
numeric (days after sowing). an vector of heading date (optional. see details) |
flowering |
numeric (days after sowing). an vector of flowering time (optional. see details) |
maturity |
numeric (days after sowing). an vector of maturity time |
latitude |
latitude |
Define of growth stages
S0: From start of year to emergence
S1: From emergence to flowering time - 300Cd
S2: From flowering time - 300Cd to flowering time + 100Cd
S3: From flowering time + 100 Cd to flowering time + 600Cd
S4: From flowering + 600Cd to maturity
Climate variables
stage: defination of stages
n: Number of days in each stage
avgt: average temperature (C)
sum.tt: total thermal time (Cd) with base temperature 0C
avg.mint: average minimum temperature
avg.maxt: average maximum temperature
sum.rain: total rainfall
avg.evap: average evapration
avg.radn average radiation
hot.days: number of hot days (daily maximum temperature is more than 30C)
very.hot.days: number of very hot days (daily maximum temperature is more than 35C)
frost.days: number of frost days (daily minimum temperature is less than 0C)
hot.sum: total thermal time above 30C of hot days (daily maximum temperature is more than 30C)
very.hot.sum: total thermal time above 35C of very hot days (daily maximum temperature is more than 35C)
frost.sum: total thermal time below 0C of frost days (daily minimum temperature is less than 0C)
vpd: vapour-pressure deficit
te: transpiration efficiency
bio.radn: bio.radn
bio.water: bio.water
bio.tt: bio.tt
ptq: photothermal quotient
avt.diffuse.radn: average diffuse radiation
a data.frame for summarised climate variable by stages. See details for more information.
if (FALSE) { sowing <- rep(as.Date("1981-05-01"), 10) emergence <- rep(10, 10) heading <- NULL flowering <- runif(10) * 20 + 50 maturity <- runif(10) * 20 + 100 latitude <- -27 res <- climate_by_stages(climates = climates, sowing = sowing, emergence = emergence, heading = heading, flowering = flowering, maturity = maturity, latitude = latitude) }
if (FALSE) { sowing <- rep(as.Date("1981-05-01"), 10) emergence <- rep(10, 10) heading <- NULL flowering <- runif(10) * 20 + 50 maturity <- runif(10) * 20 + 100 latitude <- -27 res <- climate_by_stages(climates = climates, sowing = sowing, emergence = emergence, heading = heading, flowering = flowering, maturity = maturity, latitude = latitude) }
Convert a data frame to weaana class
convert2Records(infor, records)
convert2Records(infor, records)
infor |
A list or data frame of site information |
records |
A data frame will convert to records |
A new WeaAna object
create WeaAna class
createWeaAna(mets)
createWeaAna(mets)
mets |
A list contained information of weather records. |
A new WeaAna class
The time elapsed in hours between the specified sun angle from 90 degree in am and pm. +ve above the horizon, -ve below the horizon.
dayLength(doy, lat, angle = -6)
dayLength(doy, lat, angle = -6)
doy |
day of year number |
lat |
latitude of site (deg) |
angle |
angle to measure time between, such as twilight (deg). angular distance between 90 deg and end of twilight - altitude of sun. +ve up, -ve down. |
day length in hours
Calculate the diurnal variation in air temperature. Parton WJ, Logan JA (1981) A model for diurnal variation in soil and air temperature. Agricultural Meteorology, 23, 205?216. Codes copied from APSIM Utilities.cpp
diurnalT(maxt, mint, doy, hour, latitude, A = 1.5, B = 4, C = 1)
diurnalT(maxt, mint, doy, hour, latitude, A = 1.5, B = 4, C = 1)
maxt |
maximum daily temperature |
mint |
minimum daily temperature |
doy |
day of year |
hour |
hour from 1 to 24 |
latitude |
latitude in radials |
A |
is the time lag in temperature after noon |
B |
is coef that controls temperature decrease at night |
C |
is the time lag for min temperature after sunrise |
A vector with diurnal air temperature
diurnalT(maxt = 20, mint = 10, doy = 1, hour = seq(from = 1, to = 23.99, by = 0.1), latitude = -10, A = 1.5, B = 4, C = 1)
diurnalT(maxt = 20, mint = 10, doy = 1, hour = seq(from = 1, to = 23.99, by = 0.1), latitude = -10, A = 1.5, B = 4, C = 1)
Get all weather records by year range
Get all weather records by year range
getWeatherRecords(object, ...) ## S4 method for signature 'WeaAna' getWeatherRecords(object, yrange = NULL, vars = "all", ...)
getWeatherRecords(object, ...) ## S4 method for signature 'WeaAna' getWeatherRecords(object, yrange = NULL, vars = "all", ...)
object |
A WeaAna object. |
... |
Other arguments |
yrange |
Year range. |
vars |
Variable |
A data frame with all weather records
library(weaana) data( "WeatherRecordsDemo" ) getWeatherRecords( records, yrange = c( 2008, 2009 ) ) getWeatherRecords( records, yrange = c( 2008, 2009 ), length = 10 )
library(weaana) data( "WeatherRecordsDemo" ) getWeatherRecords( records, yrange = c( 2008, 2009 ) ) getWeatherRecords( records, yrange = c( 2008, 2009 ), length = 10 )
Return a y value from a linear interpolation function
interpolationFunction(x, y, values, split = "\\s+")
interpolationFunction(x, y, values, split = "\\s+")
x |
x |
y |
y |
values |
values |
split |
split |
The interpolated values
Calculate the moving values
mov(x, k = 10, shift = "centre", fun = "mean")
mov(x, k = 10, shift = "centre", fun = "mean")
x |
A vector to calculate moving values |
k |
The moving windows |
shift |
if shift = "centre", then values are shifted to centre. if shift = "begin", then values are at begin of period. if shift = "end", then values are at end of period. The default value (centre) will be used if shift is other value. |
fun |
The method to calculate moving values. Curruntly, only "mean", "max", "min", and "sum" are supported. A NULL will be returned for any other values |
The moving value of vector x at moving windows k. A NULL will be returned for any unsupported fun
Note that for n = odd, can average at central period. If n = even, must average at end of period and then shift values
mov.avg(x, k = 10, shift = "centre")
mov.avg(x, k = 10, shift = "centre")
x |
A vector to calculate moving average |
k |
The moving windows |
shift |
if shift = "centre", then values are shifted to centre. if shift = "begin", then values are at begin of period. if shift = "end", then values are at end of period. The default value (centre) will be used if shift is other value. |
The moving average of vector x at moving windows n
Calculate the moving maximum. For compatibility only.
mov.max(x, k, shift = "centre")
mov.max(x, k, shift = "centre")
x |
A vector to calculate moving maximum |
k |
The moving windows |
shift |
if shift = "centre", then values are shifted to centre. if shift = "begin", then values are at begin of period. if shift = "end", then values are at end of period. The default value (centre) will be used if shift is other value. |
The moving maximum of vector x at moving windows k
Calculate the moving minimum. For compatibility only.
mov.min(x, k, shift = "centre")
mov.min(x, k, shift = "centre")
x |
A vector to calculate moving minimum |
k |
The moving windows |
shift |
if shift = "centre", then values are shifted to centre. if shift = "begin", then values are at begin of period. if shift = "end", then values are at end of period. The default value (centre) will be used if shift is other value. |
The moving minimum of vector x at moving windows k
Calculate the moving sum. For compatibility only.
mov.sum(x, k, shift = "centre")
mov.sum(x, k, shift = "centre")
x |
A vector to calculate moving sum |
k |
The moving windows |
shift |
if shift = "centre", then values are shifted to centre. if shift = "begin", then values are at begin of period. if shift = "end", then values are at end of period. The default value (centre) will be used if shift is other value. |
The moving sum of vector x at moving windows k
Read weather records from a file list and/or a folder list
readWeatherRecords( dataFiles = NULL, dataFolders = NULL, dataFormat = "APSIM", dataWeather = NULL, load.later = FALSE, ... )
readWeatherRecords( dataFiles = NULL, dataFolders = NULL, dataFormat = "APSIM", dataWeather = NULL, load.later = FALSE, ... )
dataFiles |
A character vector to specify the path of weather data files. |
dataFolders |
A character vector to specify the path of weather data folders. |
dataFormat |
The format of weather data file. |
dataWeather |
A data.frame for existing data. |
load.later |
Whether load weather records now or later. "dataFroamt" should be One of "APSIM" and "RDATA". |
... |
Other arguments |
A WeaAna class which contains all weather data.
Demo weather records
records
records
An object of class WeaAna
of length 1.
Define the class for statistics results
name
Name of result
type
Type of result
Show the name, number, latitude, longitude of all weather stations.
## S4 method for signature 'WeaAna' show(object)
## S4 method for signature 'WeaAna' show(object)
object |
WeaAna objects |
library(weaana) data( "WeatherRecordsDemo" ) show( records ) records
library(weaana) data( "WeatherRecordsDemo" ) show( records ) records
Get site information
Get site information
Get site information
siteInfor(object, ...) ## S4 method for signature 'WeaAna' siteInfor(object, load.now = FALSE) ## S4 method for signature 'WeaAnaSite' siteInfor(object, load.now = FALSE)
siteInfor(object, ...) ## S4 method for signature 'WeaAna' siteInfor(object, load.now = FALSE) ## S4 method for signature 'WeaAnaSite' siteInfor(object, load.now = FALSE)
object |
A WeaAnaSite object. |
... |
Not used |
load.now |
Whether load site information |
Site information in the WeaAna object
Site information in the WeaAnaSite object
library(weaana) data( "WeatherRecordsDemo" ) siteInfor( records ) siteInfor( records, load.now = TRUE )
library(weaana) data( "WeatherRecordsDemo" ) siteInfor( records ) siteInfor( records, load.now = TRUE )
Calculate the sphere distance
sphericalDistance(lat1, lon1, lat2, lon2)
sphericalDistance(lat1, lon1, lat2, lon2)
lat1 |
Latitude |
lon1 |
Longitude |
lat2 |
Latitude |
lon2 |
Longitude |
Distance in km
Calculate thermal time using cardinal temperatures
thermalTime(weather, x_temp, y_temp, method = NULL)
thermalTime(weather, x_temp, y_temp, method = NULL)
weather |
WeaAna object |
x_temp |
The cardinal temperatures |
y_temp |
The effective thermal time |
method |
The method to calculate thermal time. The default method is ( maxt + mint ) / 2 - base. The three hour temperature methods will be used if method = '3hr' |
A data.frame with three columns: year, day and thermalTime.
met_file <- system.file("extdata/WeatherRecordsDemo1.met", package = "weaana") records <- readWeatherRecords(met_file) x_temp <- c(0, 26, 34) y_temp <- c(0, 26, 0) res <- thermalTime(records, x_temp, y_temp) head(res) res <- thermalTime(records, x_temp, y_temp, method = "3hr") head(res)
met_file <- system.file("extdata/WeatherRecordsDemo1.met", package = "weaana") records <- readWeatherRecords(met_file) x_temp <- c(0, 26, 34) y_temp <- c(0, 26, 0) res <- thermalTime(records, x_temp, y_temp) head(res) res <- thermalTime(records, x_temp, y_temp, method = "3hr") head(res)
Calculate thermal time using cardinal temperatures
thermalTimeDaily(mint, maxt, x_temp, y_temp, method = NULL)
thermalTimeDaily(mint, maxt, x_temp, y_temp, method = NULL)
mint |
The minimum temperature |
maxt |
The maximum temperature |
x_temp |
The cardinal temperatures |
y_temp |
The effective thermal time |
method |
The method to calculate thermal time. The default method is ( maxt + mint ) / 2 - base. The three hour temperature methods will be usesd if method = '3hr' |
The thermal time.
mint <- c(0, 10) maxt <- c(30, 40) x_temp <- c(0, 20, 35) y_temp <- c(0, 20, 0) thermalTimeDaily(mint, maxt, x_temp, y_temp) thermalTimeDaily(mint, maxt, x_temp, y_temp, method = '3hr')
mint <- c(0, 10) maxt <- c(30, 40) x_temp <- c(0, 20, 35) y_temp <- c(0, 20, 0) thermalTimeDaily(mint, maxt, x_temp, y_temp) thermalTimeDaily(mint, maxt, x_temp, y_temp, method = '3hr')
Calculate thermal time using the hourly temperature (non daily temperature)
thermalTimeHourly(timestamp, temperature, x_temp, y_temp)
thermalTimeHourly(timestamp, temperature, x_temp, y_temp)
timestamp |
The timestamp of weather records |
temperature |
The temperature |
x_temp |
The cardinal temperatures |
y_temp |
The effective thermal time |
A data frame with daily thermal time
met_file <- system.file("extdata/WeatherHourly.csv", package = "weaana") hourly <- read.csv(met_file, as.is = TRUE) hourly$timestamp <- as.POSIXct(hourly$timestamp, format = "%Y-%m-%dT%H:%M:%SZ") x_temp <- c(0, 20, 35) y_temp <- c(0, 20, 0) thermalTimeHourly(hourly$timestamp, hourly$temperature, x_temp, y_temp)
met_file <- system.file("extdata/WeatherHourly.csv", package = "weaana") hourly <- read.csv(met_file, as.is = TRUE) hourly$timestamp <- as.POSIXct(hourly$timestamp, format = "%Y-%m-%dT%H:%M:%SZ") x_temp <- c(0, 20, 35) y_temp <- c(0, 20, 0) thermalTimeHourly(hourly$timestamp, hourly$temperature, x_temp, y_temp)
Method is presented by Santer et al. 2000
ttest_ts(y, slope = NULL)
ttest_ts(y, slope = NULL)
y |
A vector of time serial data |
slope |
Whether export slope |
p values of t-test
There are two modes to use wcal
, function mode if FUN
is not null,
and string formula mode if FUN
is NULL.
wcal(object, ...) ## S4 method for signature 'WeaAna' wcal(object, FUN = NULL, ..., var.args = NULL, var.name = NULL)
wcal(object, ...) ## S4 method for signature 'WeaAna' wcal(object, FUN = NULL, ..., var.args = NULL, var.name = NULL)
object |
A WeaAna objects. |
... |
Optional arguments to |
FUN |
A function to be used which results should have the same length as original records. |
var.args |
Arguments of weather variable pass to |
var.name |
Variable name is used if |
library(weaana) data( "records" ) # Daily mean temperature wcal( records, avgt2 = "( maxt + mint ) / 2" ) # Moving average temperature wcal( records, FUN = mov.avg, var.args = "avgt", k = 5, shift = "begin", var.name = "mov.avg" )
library(weaana) data( "records" ) # Daily mean temperature wcal( records, avgt2 = "( maxt + mint ) / 2" ) # Moving average temperature wcal( records, FUN = mov.avg, var.args = "avgt", k = 5, shift = "begin", var.name = "mov.avg" )
Define the class for multiple sites
num
total number of weather station
records
A pointer vector to weather records of each site
result
A pointer for all results name and type.
Define the class of WeaAna
name
Name of weather station
number
Station number of weather station
latitude
Latitude of weather station
longitude
Latitude of weather station
tav
Annual average ambient temperature
amp
Annual amplitude in mean monthly temperature
marker
The extra marker for this site
year
A vector of year of weather station
day
A vector of day of weather station
radn
A vector of radiation of weather station
maxt
A vector of maximum temperature of weather station
mint
A vector of minimum temperature of weather station
evap
A vector of evaporation of weather station
rain
A vector of rainfall of weather station
vp
A vector of pressure atmosphere of weather station
code
The 6 digit code indicates the source of the 6 data columns
extra
A list of variables need to store
res
All statistics results store in this slot
figures
A list to store all plotted figures.
file.path
The file path for this site.
data.format
The data format for this site.
load.later
Whether are records loaded laterly.
Write weather records into file
Write weather records into file
writeWeatherRecords(object, ...) ## S4 method for signature 'WeaAna' writeWeatherRecords(object, file, cols = NULL)
writeWeatherRecords(object, ...) ## S4 method for signature 'WeaAna' writeWeatherRecords(object, file, cols = NULL)
object |
A WeaAna object. |
... |
Not used |
file |
Path of output file. |
cols |
Columns to export. All columns exported if NULL |
No return values