WRFnearest2obs: Extracts CRHM obs variables from a WRF NetCDF closest to...

View source: R/WRFnearest2obs.R

WRFnearest2obsR Documentation

Extracts CRHM obs variables from a WRF NetCDF closest to specified point

Description

This function is intended to work with NetCDF created by the research group of Dr. Yanping Li of Global Water Futures gwf.usask.ca. This function creates a CRHMr data frame from a WRF NetCDF specified by their longitude and latitude, extracting values from the nearest location.

Usage

WRFnearest2obs(
  NetCDF = "",
  obsfile = "",
  longitude = 0,
  latitude = 0,
  airPressure = 0,
  returnRH = TRUE,
  restrictRH = TRUE,
  startDatetime = "2000-10-01 00:00",
  endDatetime = "2100-12-01 23:00",
  timezone = "",
  trim = TRUE,
  quiet = TRUE,
  logfile = ""
)

Arguments

NetCDF

Required. The name of the netCDF file containing the WRF data.

obsfile

Optional. If specified the values are written to the obs file.

longitude

Required. The longitude of the point being sought. The input value is not checked for validity, in case the model extent changes.

latitude

Required. The latitude of the point being sought. The input value is not checked for validity, in case the model extent changes.

airPressure

Optional. The mean air pressure in Pa. If set to zero (the default) then the air pressure within the NetCDf file will be used for converting the specific humidity to relative humidity. Because the air pressure may be incorrect or missing, you may wish to specify a mean air pressure to be used for the conversion. Note that if there is no air pressure within the NetCDF and you do not specify an air pressure value, this will trigger an error message, and the RH cannot be calculated.

returnRH

Optional. If TRUE, the default, RH will be returned if air temperature values are present. If FALSE, then ea values will be returned, even if air temperatures are available.

restrictRH

Optional. If TRUE, the default, RH values will be restricted to being between 0 and 100 percent. If FALSE, then impossible RH values can be returned. Note that this will have no effect if there are no air temperatures present, or if returnRH = FALSE, in which case values of ea will be returned.

startDatetime

Optional. Beginning date of data to be extracted. A string formatted as "yyyy-mm-dd hh:mm". The default value is 2000-10-01 00:00.

endDatetime

Optional. Ending date of data to be extracted. A string formatted as "yyyy-mm-dd hh:mm". The default value is 2100-12-01 23:00.

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. Under Linux, you can use CST and MST for Central Standard or Mountain Standard time, respectively. Under Windows or OSX, 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.

trim

Optional. If TRUE (the default) then the final output will be trimmed to CRHM day boundaries.

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 either TRUE (if an obs file is specified) or a CRHMr obs data frame (if no obs file is specified). The data frame will contain the standard CRHM variables: t, p, u, either rh or ea, qsi, and qli, depending on their presence in the NetCDF. Note that the precipitation is the accumulated value, because it can contain negative spikes and resets. To deaccumulate the precipitation, you will have to use the CRHMr weighing gauge functions, such as weighingGauge1, to fill gaps, weighingGauge2 or weighingGauge5 to remove resets. You can use weighingGaugeInterval to deaccumulate the values. Note that because these functions use thresholds to define missing values, spike and resets, they need to be used interatively. You can use the weighingGaugePlot to see how well the data are being processed. You may also need to remove too-large precipitation events. If unsucessful, returns FALSE.

Author(s)

Kevin Shook

See Also

WRFbyloc2obs

Examples

## Not run:  f <- "wrf2d_tquvr.nc"
r <- WRFnearest2obs(f, longitude=-115.27, 
latitude=52.03, startDatetime = "1980-01-01 00:00", endDatetime="1980-12-31 23:00")

## End(Not run)

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