Read and write data from the LARS-WG stochastic weather generator file formats; also convert to a format for HELP
# 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")
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 name with a *.sce
extension; this is a
‘scenario’ file with absolute and relative changes of climate
data
input file
output file
data.frame
of climate data
same as x
same as x
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’
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
scenario name
same as ‘LAT’ in st
file; if missing, this
will try to be read from attr(x$latitude)
same as ‘LON’ in st
file; if missing, this
will try to be read from attr(x$longitude)
same as ‘ALT’ in st
file; if missing, this
will try to be read from attr(x$elevation)
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).
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, 10.1023/A:1005342632279
write.help
, read.sdsm
,
summerland
example synthetic data,
conv365toGregorian
# NOT RUN {
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))
# }
Run the code above in your browser using DataLab