From 7b883b97c68588249c20da3d72165a36da059013 Mon Sep 17 00:00:00 2001 From: Luke Winslow Date: Tue, 23 Feb 2016 09:04:57 -0600 Subject: [PATCH 1/2] fixing hostetler driver issues --- R/get_driver_nhd.R | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/R/get_driver_nhd.R b/R/get_driver_nhd.R index 1b61f75..93d4cb5 100644 --- a/R/get_driver_nhd.R +++ b/R/get_driver_nhd.R @@ -97,8 +97,8 @@ drivers_to_glm = function(driver_df){ driver_df$WindSpeed = sqrt(driver_df$ugrd10m^2 + driver_df$vgrd10m^2) driver_df$ShortWave = driver_df$dswrfsfc driver_df$LongWave = driver_df$dlwrfsfc - driver_df$Rain = driver_df$apcpsfc*24/1000 #convert to m/day rate + ##TODO Maybe: Generalize these conversions so they aren't if/else statements if('tmp2m' %in% names(driver_df)){ driver_df$AirTemp = driver_df$tmp2m - 273.15 #convert K to deg C }else if('airtemp' %in% names(driver_df)){ @@ -115,6 +115,17 @@ drivers_to_glm = function(driver_df){ stop('Unable to find humidity data.\nDriver service must have humidity data (named relhum or spfh2m). ') } + if('apcpsfc' %in% names(driver_df)){ + #convert from mm/hour to m/day + driver_df$Rain = driver_df$apcpsfc*24/1000 #convert to m/day rate + }else if('precip' %in% names(driver_df)){ + #convert from mm/day to m/day + driver_df$Rain = driver_df$precip/1000 + }else{ + stop('Unable to find precipitation data. \nMust be either apcpsfc or precip') + } + + #now deal with snow driver_df$Snow = 0 From 23956ae098cdb6f1800e81dc94a6afe6a7eabb65 Mon Sep 17 00:00:00 2001 From: Luke Winslow Date: Fri, 18 Mar 2016 15:25:28 -0500 Subject: [PATCH 2/2] updating to handle new downscaled drivers --- DESCRIPTION | 2 +- R/get_driver_nhd.R | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index e342a86..8ca7788 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: mda.lakes Type: Package Title: Tools for combining models, data, and processing for lakes -Version: 3.0.0 +Version: 3.0.1 Date: 2015-12-03 Author: Luke Winslow, Jordan Read Maintainer: Luke Winslow diff --git a/R/get_driver_nhd.R b/R/get_driver_nhd.R index 93d4cb5..a426535 100644 --- a/R/get_driver_nhd.R +++ b/R/get_driver_nhd.R @@ -12,7 +12,7 @@ get_driver_nhd = function(id, driver_name, loc_cache, timestep){ #match id to index match_i = which(indx$id == id) - if(length(match_i) < 8){ + if(length(match_i) < 6){ stop('flawed or missing driver set for ', id) } @@ -93,11 +93,19 @@ get_driver_index = function(driver_name, loc_cache=TRUE){ drivers_to_glm = function(driver_df){ ## convert and downsample wind - - driver_df$WindSpeed = sqrt(driver_df$ugrd10m^2 + driver_df$vgrd10m^2) driver_df$ShortWave = driver_df$dswrfsfc driver_df$LongWave = driver_df$dlwrfsfc + if('windspeed' %in% names(driver_df)){ + driver_df$WindSpeed = driver_df$windspeed + }else if('ugrd10m' %in% names(driver_df)){ + driver_df$WindSpeed = sqrt(driver_df$ugrd10m^2 + driver_df$vgrd10m^2) + }else{ + stop('Unable to find wind data.\nDriver service must have temp data (named windspeed or ugrd10m). ') + } + + + ##TODO Maybe: Generalize these conversions so they aren't if/else statements if('tmp2m' %in% names(driver_df)){ driver_df$AirTemp = driver_df$tmp2m - 273.15 #convert K to deg C @@ -111,6 +119,8 @@ drivers_to_glm = function(driver_df){ driver_df$RelHum = 100*driver_df$relhum }else if('spfh2m' %in% names(driver_df)){ driver_df$RelHum = 100*driver_df$spfh2m/qsat(driver_df$tmp2m-273.15, driver_df$pressfc*0.01) + }else if('relhumperc' %in% names(driver_df)){ + driver_df$RelHum = driver_df$relhumperc }else{ stop('Unable to find humidity data.\nDriver service must have humidity data (named relhum or spfh2m). ') } @@ -126,14 +136,14 @@ drivers_to_glm = function(driver_df){ } - - #now deal with snow + #now deal with snow base case driver_df$Snow = 0 # 10:1 ratio assuming 1:10 density ratio water weight driver_df$Snow[driver_df$AirTemp < 0] = driver_df$Rain[driver_df$AirTemp < 0]*10 driver_df$Rain[driver_df$AirTemp < 0] = 0 + #convert DateTime to properly formatted string driver_df$time = driver_df$DateTime driver_df$time = format(driver_df$time,'%Y-%m-%d %H:%M:%S')