lars: Read and write data from LARS-WG file formats

Description Usage Arguments Details Author(s) References See Also Examples

Description

Read and write data from the LARS-WG stochastic weather generator file formats; also convert to a format for HELP

Usage

1
2
3
4
5
6
7
8
9
# read synthetic or observed *.st file
read.lars(stfile, year.offset = 0)

# write observed climate data (*.st and/or *.sr)
write.lars(x, stfile, datfile, site, lat, lon, alt)

# experimental functions (may not work great; or at all!)
lars2help(infile, outfile, year.offset, site)
write.lars.scenario(file, x1, x2, name = "anomaly")

Arguments

stfile

file name with ‘*.st’ extension; this is a ‘site file’ for LARS-WG which contains meta-data for the climate data, and has the location of the the climate data file; for write.lars, if this variable is NA or FALSE, this file will not be written (however, datfile must be defined)

datfile

file name with either ‘*.sr’ or ‘*.dat’ extension; contains climate data, as described by stfile; this does not need to be set if stfile is defined, as this datum is found in the ‘st’ file

file

file name with a ‘*.sce’ extension; this is a ‘scenario’ file with absolute and relative changes of climate data

infile

input file

outfile

output file

x

data.frame of climate data

x1

same as x

x2

same as x

year.offset

offset of years between what is contained in the data files and what is needed in R to produce a reasonable ‘Date’; this is required, for example, if synthetic data are produced that start from an arbitrary year ‘1’ but represent climate from the year ‘2000’

site

same as ‘[SITE]’ in ‘st’ file; if missing, this will try to read from attr(x$name); this is the same as a ‘region’ for HELP

name

scenario name

lat

same as ‘LAT’ in ‘st’ file; if missing, this will try to be read from attr(x$latitude)

lon

same as ‘LON’ in ‘st’ file; if missing, this will try to be read from attr(x$longitude)

alt

same as ‘ALT’ in ‘st’ file; if missing, this will try to be read from attr(x$elevation)

Details

These functions interface with the LARS-WG files (Version 4.0), which is a stochastic weather generator by Mikhail Semenov.

The climate data files used with LARS-WG have two parts: (1)~a ‘site file’ with a ‘st’ extension, containing the meta-data; and (2)~a data file with a ‘*.sr’ or ‘*.dat’ extension, containing all the data. The variable names are translated according to the following table:

seas LARS-WG
year ‘YEAR’
yday ‘JDAY’
t_min ‘MIN’
t_max ‘MAX’
preicp ‘RAIN’
solar ‘RAD’
sun ‘SUN’
pet ‘PET’

To write climate data from R to a LARS-WG file, the data.frame names need to match those in the seas-side of the table.

Data exported from write.lars always has legal (according to the Gregorian calendar) and increasing sequence of days (even if there are gaps in x$date). Missing data values are written as -99.

Synthetically generated data from LARS-WG use a 365-day calendar, and may need to be converted to a Gregorian calendar, which can be done using conv365toGregorian.

lars2help and write.lars.scenario are experimental functions to translate data between LARS and HELP (see write.help for more info).

Author(s)

Mike Toews

References

LARS-WG was can be downloaded for academic and research uses from
http://www.rothamsted.bbsrc.ac.uk/mas-models/larswg.php

Semenov, M.A. and Barrow, E.M. 1997. Use of a stochastic weather generator in the development of climate change scenarios. Climate Change, 35 (4), 397–414, doi: 10.1023/A:1005342632279

See Also

write.help, read.sdsm, summerland example synthetic data, conv365toGregorian

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
stfile <- system.file("extdata", "summerland.st", package="seas")
print(stfile)
summ <- read.lars(stfile, year.offset=1960)
head(summ)
str(summ)

# plot temperature
summ$t_mean <- rowMeans(summ[, c("t_min", "t_max")])
seas.temp.plot(summ)

# plot solar radiation
seas.var.plot(summ, "solar")

# plot precipitation
summ.ss <- seas.sum(summ)
image(summ.ss)
plot(seas.norm(summ.ss))

Example output

[1] "/usr/lib/R/site-library/seas/extdata/summerland.st"
  year yday t_min t_max precip solar pet       date
1 1961    1  -1.8   3.2    0.0   2.6 0.3 1961-01-01
2 1961    2  -5.0   1.8    0.0   2.9 0.3 1961-01-02
3 1961    3  -4.3  -2.2    0.2   2.6 0.3 1961-01-03
4 1961    4  -2.7  -2.6    1.9   1.9 0.2 1961-01-04
5 1961    5  -5.3  -1.2    0.0   1.4 0.1 1961-01-05
6 1961    6  -0.2   3.4    0.1   4.0 0.6 1961-01-06
'data.frame':	10950 obs. of  8 variables:
 $ year  : int  1961 1961 1961 1961 1961 1961 1961 1961 1961 1961 ...
 $ yday  : int  1 2 3 4 5 6 7 8 9 10 ...
 $ t_min : atomic  -1.8 -5 -4.3 -2.7 -5.3 -0.2 6.4 0.1 -1.4 4.4 ...
  ..- attr(*, "units")= chr "degC"
  ..- attr(*, "long.name")= chr "daily minimum temperature"
 $ t_max : atomic  3.2 1.8 -2.2 -2.6 -1.2 3.4 6.9 1.7 -0.7 4.5 ...
  ..- attr(*, "units")= chr "degC"
  ..- attr(*, "long.name")= chr "daily maximum temperature"
 $ precip: atomic  0 0 0.2 1.9 0 0.1 1 1.1 0 0 ...
  ..- attr(*, "units")= chr "mm"
  ..- attr(*, "long.name")= chr "total daily precipitation"
 $ solar : atomic  2.6 2.9 2.6 1.9 1.4 4 5.2 3.9 5.6 0.9 ...
  ..- attr(*, "units")= chr "MJ/(m^2day)"
  ..- attr(*, "long.name")= chr "total daily global solar radiation"
 $ pet   : atomic  0.3 0.3 0.3 0.2 0.1 0.6 0.9 0.5 0.7 0.1 ...
  ..- attr(*, "units")= chr "mm"
  ..- attr(*, "long.name")= chr "potential evapotranspiration"
 $ date  : Date, format: "1961-01-01" "1961-01-02" ...
 - attr(*, "name")= chr "Summerland"

seas documentation built on May 2, 2019, 4:16 a.m.