format_weather {ascotraceR}R Documentation

Format weather data into an an object suitable for use in ascotraceR spore dispersal models

Description

Formats raw weather data into an object suitable for use in the trace_asco() function ensuring that the supplied weather data meet the requirements of the model to run.

Usage

format_weather(
  x,
  YYYY = NULL,
  MM = NULL,
  DD = NULL,
  hh = NULL,
  mm = NULL,
  POSIXct_time = NULL,
  time_zone = NULL,
  temp,
  rain,
  ws,
  wd,
  wd_sd,
  station,
  lon = NULL,
  lat = NULL,
  r = NULL,
  lonlat_file = NULL
)

Arguments

x

A data.frame object of weather station data for formatting. character.

YYYY

Column name or index in x that refers to the year when the weather was logged. character.

MM

Column name or index in x that refers to the month (numerical) when the weather was logged. character.

DD

Column name or index in x that refers to the day of month when the weather was logged. character.

hh

Column name or index in x that refers to the hour (24 hour) when the weather was logged. character.

mm

Column name or index in x that refers to the minute when the weather was logged. character.

POSIXct_time

Column name or index in x which contains a POSIXct formatted time. This can be used instead of arguments YYYY, MM, DD, hh, mm. character.

time_zone

Time zone (Olsen time zone format) where the weather station is located. May be in a column or supplied as a character string. Optional, see also r. character. See details.

temp

Column name or index in x that refers to temperature in degrees Celsius. character.

rain

Column name or index in x that refers to rainfall in mm. character.

ws

Column name or index in x that refers to wind speed in km / h. character.

wd

Column name or index in x that refers to wind direction in degrees. character.

wd_sd

Column name or index in x that refers to wind speed columns standard deviation .character. This is only applicable if weather data is already summarised to hourly increments. See details.

station

Column name or index in x that refers to the weather station name or identifier. character. See details.

lon

Column name or index in x that refers to weather station's longitude. character. See details.

lat

Column name or index in x that refers to weather station's latitude. character. See details.

r

Spatial raster which is intended to be used with this weather data for use in the blackspot model. Used to set time_zone if it is not supplied in data. character. Optional, see also time_zone.

lonlat_file

A file path to a CSV which included station name/id and longitude and latitude coordinates if they are not supplied in the data. character. Optional, see also lon and lat.

Details

time_zone All weather stations must fall within the same time zone. If the required stations are located in differing time zones, separate ascotraceR.weather objects must be created for each time zone. If a raster object, r, of previous crops is provided that spans time zones, an error will be emitted.

wd_sd If weather data is provided in hourly increments, a column with the standard deviation of the wind direction over the hour is required to be provided. If the weather data are sub-hourly, the standard deviation will be calculated and returned automatically.

lon, lat and lonlat_file If x provides longitude and latitude values for station locations, these may be specified in the lon and lat columns. If the coordinates are not relevant to the study location NA can be specified and the function will drop these column variables. If these data are not included, (NULL) a separate file may be provided that contains the longitude, latitude and matching station name to provide station locations in the final ascotraceR.weather object that is created by specifying the file path to a CSV file using lonlat_file.

Value

A ascotraceR.weather object (an extension of data.table) containing the supplied weather aggregated to each hour in a suitable format for use with trace_asco() containing the following columns:

times: Time in POSIXct format
rain: Rainfall in mm
ws: Wind speed in km / h
wd: Wind direction in compass degrees
wd_sd: Wind direction standard deviation in compass degrees
lon: Station longitude in decimal degrees
lat: Station latitude in decimal degrees
station: Unique station identifying name
YYYY: Year
MM: Month
DD: Day
hh: Hour
mm: Minute

Examples

# Weather data files for Newmarracara for testing and examples have been
# included in ascotraceR. The weather data files both are of the same format,
# so they will be combined for formatting here.

Newmarracarra <- read.csv(
 system.file("extdata",
             "1998_Newmarracarra_weather_table.csv",
             package = "ascotraceR")
)

station_data <- system.file("extdata",
                            "stat_dat.csv",
                            package = "ascotraceR")

weather <- format_weather(
  x = Newmarracarra,
  POSIXct_time = "Local.Time",
  temp = "mean_daily_temp",
  rain = "rain_mm",
  ws = "ws",
  wd = "wd",
  wd_sd = "wd_sd",
  station = "Location",
  time_zone = "Australia/Perth",
  lonlat_file = station_data
)

# Saving weather data and reimporting can lose the object class
# Reimported data can be quickly reformatted, adding the 'asco.weather' class
#  with this same function
temp_file_path <- paste0(tempdir(),"weather_file.csv")
write.csv(weather, file = temp_file_path, row.names = FALSE)
weather_imported <- read.csv(temp_file_path)
weather <- format_weather(weather_imported,
                          time_zone = "Australia/Perth")
unlink(temp_file_path) # remove temporary weather file

[Package ascotraceR version 0.0.1 Index]