Difference between revisions of "Utilities"

From Rhessys
Jump to navigationJump to search
(Created page with ' == BASIN DAILY WATER BALANCE FUNCTION == COPY AND PASTE INTO R THE TEXT BELOW #####PASTE BELOW##### To create this function in an R data set: If your '''b'''asin '''d'''aily ou…')
 
Line 3: Line 3:
  
 
COPY AND PASTE INTO R THE TEXT BELOW #####PASTE BELOW#####
 
COPY AND PASTE INTO R THE TEXT BELOW #####PASTE BELOW#####
 +
 
To create this function in an R data set:
 
To create this function in an R data set:
 +
 
If your '''b'''asin '''d'''aily output is called (for example) "bd" type "bd=watbal(bd)".
 
If your '''b'''asin '''d'''aily output is called (for example) "bd" type "bd=watbal(bd)".
 +
 
This will add a number of fields to your basin daily output file, the last
 
This will add a number of fields to your basin daily output file, the last
 
of which will be called "watbal".  This is your water balance error.
 
of which will be called "watbal".  This is your water balance error.
Line 10: Line 13:
 
(on the order of 10^-6).  If your watbal values are negative then
 
(on the order of 10^-6).  If your watbal values are negative then
 
water inputs are less than water outputs, and vice versa.
 
water inputs are less than water outputs, and vice versa.
 +
  
 
#####PASTE THE TEXT BELOW IN R TO CREATE THE WATER BALANCE FUNCTION#####
 
#####PASTE THE TEXT BELOW IN R TO CREATE THE WATER BALANCE FUNCTION#####
 +
  
 
watbal = function(rb) {
 
watbal = function(rb) {

Revision as of 09:25, 19 January 2011

BASIN DAILY WATER BALANCE FUNCTION

COPY AND PASTE INTO R THE TEXT BELOW #####PASTE BELOW#####

To create this function in an R data set:

If your basin daily output is called (for example) "bd" type "bd=watbal(bd)".

This will add a number of fields to your basin daily output file, the last of which will be called "watbal". This is your water balance error. You should see a minor numerical error here even if your water balances (on the order of 10^-6). If your watbal values are negative then water inputs are less than water outputs, and vice versa.


          1. PASTE THE TEXT BELOW IN R TO CREATE THE WATER BALANCE FUNCTION#####


watbal = function(rb) { rb$watbal.tmp=with(rb,precip-streamflow-trans-evap) rb$sd=with(rb,sat_def-rz_storage-unsat_stor) tmp=diff(rb$sd) tmp=c(0,tmp) rb$sddiff=tmp tmp=diff(rb$snow) tmp=c(0,tmp) rb$snodiff=tmp tmp=diff(rb$detention_store) tmp=c(0,tmp) rb$detdiff=tmp tmp=diff(rb$litter_store) tmp=c(0,tmp) rb$litdiff=tmp tmp=diff(rb$canopy_store) tmp=c(0,tmp) rb$candiff=tmp tmp=diff(rb$gw.storage) tmp=c(0,tmp) rb$gwdiff=tmp rb$watbal=with(rb,watbal.tmp+sddiff-snodiff-detdiff-litdiff-candiff-gwdiff) rb }