WATCHcreateHourlyWFDEIobs: Creates a CRHM .obs file of hourly values from WATCH...

View source: R/WATCHcreateHourlyWFDEIobs.R

WATCHcreateHourlyWFDEIobsR Documentation

Creates a CRHM .obs file of hourly values from WATCH reanalysis data WFDEI files

Description

Extracts data from WATCH WDFEI netCDF files and builds a CRHM .obs file of hourly values containing t, ea, u10, p Qsi and Qli. All values are interpolated from 3 and 6 hur data. The windspeeds are at 10m, hence they are denoted as u10. Air temperatures are at 2m. The values for ea are computed from the atmospheric pressure (at 10m) and the absolute humidity (at 2m). Because the original NetCDF files are very large, this function typically runs very slowly. Also, because this function assembles and processes all of the data in memory, it can require a lot of RAM to execute.

Usage

WATCHcreateHourlyWFDEIobs(
  nc.location = "",
  startyear = 1979,
  endyear = 2012,
  lon = 0,
  lat = 0,
  precipType = "CRU",
  sunTimeOffset = 2,
  solarMethod = "simpleMaxSolar",
  interpolationMethod = "linear",
  obsFileName = "",
  timezone = "",
  quiet = TRUE,
  logfile = ""
)

Arguments

nc.location

Required. A character string of the directory holding the WATCH WFDEI netCDf files. This is a file path WITHOUT a terminal slash, e.g. z:\WATCH\WFDEI

startyear

Optional. Year to begin. Must be in the range 1979-2012. Default is 1979.

endyear

Optional. Year to end. Must be in the range 1979-2012. Default is 2012.

lon

Required. Decimal longitude to extract for.

lat

Required. Decimal latitude to extract for.

precipType

Optional. The precipitation type used; can be CRU (the default) or GPCC.

sunTimeOffset

Optional. Number of hours that local noon is offset from solar noon. The default is 2 hours. This may be incorrect. It seems that WATCH data may not incorporate the temporal offset correctly - zero may work better.

solarMethod

The method to be used for calculating the extra-terrestrial radiation. The default method is simpleMaxSolar. Note that this method is only valid for latitudes between 49 and 55 N. The other supported method is PotSolarInst, which requires the package EcoHydRology to be installed

interpolationMethod

Optional. A vector containing the methods to be used for interpolation for each of the variables. Currently supported methods are linear and spline. The default is to use linear interpolation. If fewer methods than columns are specified, the methods are recycled.

obsFileName

Required. Name of the .obs file to be created.

timezone

Required. The name of the timezone of the data as a character string. This should be the timezone of your data, but omitting daylight savings time. Note that the timezone code is specific to your OS. To avoid problems, you should use a timezone without daylight savings time. You can use Etc/GMT+6 or Etc/GMT+7 for Central Standard and Mountain Standard time. DO NOT use America/Regina as the time zone, as it includes historical changes between standard and daylight savings time.

quiet

Optional. Suppresses display of messages, except for errors. If you are calling this function in an R script, you will usually leave quiet=TRUE (i.e. the default). If you are working interactively, you will probably want to set quiet=FALSE.

logfile

Optional. Name of the file to be used for logging the action. Normally not used.

Value

If successful, returns the value TRUE and writes the specified .obs file. If unsuccessful, returns the value FALSE.

Note

Because this function can be slow, and uses a lot of memory, you may wish to run it repeatedly for short intervals. You can then use the function appendObs in CRHMr to join the files together. The time shifting results in obs files which do not begin and end on day boundaries, so you should use the function trimObs in CRHMr to trim the obs file - after the final file has been assembled.

Author(s)

Kevin Shook.

References

R code for conversion of air pressure and absolute humidity was taken from project PEcAn The Predictive Ecosystem Analyzer http://pecanproject.github.io. The source code is available at https://github.com/PecanProject/pecan/blob/master/modules/data.atmosphere/R/metutils.R.

See Also

WATCHcreateHourlyWFDobs trimObs appendObs

Examples

## Not run: 
location <- 'z:\data\WATCH\WFDEI'
obsName <- 'VermilionWATCH_WFDEI.obs'
WATCHcreateHourlyWFDEIobs(nc.location=location, 
startyear=1979, endyear=2001, lon=-111.9, lat=53.2, timezone='Etc/GMT+7', obsFileName=obsName)
# read in file and trim it
obs <- CRHMr::readObsFile(obsFile=obsName, timezone='Etc/GMT+7')
trimmedObs <- CRHMr::trimObs(obs)
CRHMr::writeObsFile(trimmedObs, obsFileName)
## End(Not run)


CentreForHydrology/Reanalysis documentation built on Nov. 23, 2022, 2:57 a.m.