This is an example RavenR workflow for taking a watershed exported from the Ontario Flow Assessment Tool (OFAT) and converting it to a simple Raven Model discretization (.rvh) file. The first step is to generate and download watershed information in OFAT. Using the OFAT interface, perform the following tasks:

  1. Select a watershed using the Create Watershed tool.
  2. Determine the watershed land cover distribution by clicking on Land Cover and selecting the Extract Land Cover button in the left hand menu.
  3. Choose Export from the top menu, check the “Land cover table (areas and percentages)” and click Download Package in the left hand menu.
  4. Unzip the package to a folder on your machine

This Rmd script (downloadable here) should be unzipped itself and moved to the unzipped folder next to the landcoverGRID folder. The script can be used with any watershed generated by OFAT. Simply open up in RStudio and click ‘Knit’ after changing the watershed name, latitude, and longitude, as indicated below.

For this model, we generated the watershed for Boomer Creek in the Municipality of Wellesley, ON with its outlet located at (48.03396N, 84.68364W), depicted here as it was selected in OFAT:

Boomer Creek

library(foreign)
library(knitr)
library(RavenR)

fileprefix <-"BoomerCreek"    # this needs to be modified for each new watershed
lat <-  48.03396              # this needs to be modified for each new watershed
long<- -84.68364              # this needs to be modified for each new watershed

topdir     <-paste0(getwd(),"/")

Read in the mapping file which can be used to simplify the Ontario Land Cover data to hydrologically significant categories:

map<-read.csv(url("http://raven.uwaterloo.ca/files/OntarioRavenReclass.csv"),strip.white=TRUE)
kable(map,caption="Land Cover Mapping Table")
Land Cover Mapping Table
ID Land.Cover.Type RavenLandClass RavenVegClass
0 Other NA NA
0 Cloud/Shadow NA NA
1 Clear Open Water WATER NO_VEG
2 Turbid Water WATER NO_VEG
3 Shoreline NA NA
4 Mudflats NA NA
5 Marsh WETLAND WET_VEG
6 Swamp WETLAND WET_VEG
7 Fen WETLAND WET_VEG
8 Bog WETLAND WET_VEG
9 Heath GRASSLAND GRASS
11 Sparse Treed GRASSLAND GRASS
12 Treed Upland FOREST FOREST
13 Deciduous Treed FOREST FOREST
14 Mixed Treed FOREST FOREST
15 Coniferous Treed FOREST FOREST
16 Plantations - Treed Cultivated FOREST FOREST
17 Hedge Rows GRASSLAND GRASS
18 Disturbance NA NA
19 Open Cliff and Talus OPEN NO_VEG
20 Alvar OPEN NO_VEG
21 Sand Barren and Dune OPEN NO_VEG
22 Open Tallgrass Prairie GRASSLAND GRASS
23 Tallgrass Savannah GRASSLAND GRASS
24 Tallgrass Woodland GRASSLAND GRASS
25 Sand/Gravel/Mine Tailings/Extraction NA NA
26 Bedrock OPEN NO_VEG
27 Community/Infrastructure URBAN NO_VEG
28 Agriculture and Undifferentiated Rural Land Use AGRICULTURE CROP

Open up the land cover database file, extract the areas, and re-classify the land use data based upon the mapping to simpler Raven classes. This assumes the land cover name is Watershed 1 Landcover.dbf, which is only the case if this was the first watershed delineated on OFAT.

lcfile<-paste0(topdir,"landcoverGRID/Watershed 1 Landcover.dbf")
df<-read.dbf(lcfile,as.is=TRUE)

# left join mapping file to landcover
df<-merge(df,map,by.x="VALUE",by.y="ID",all.x=TRUE) 

# remove unmappable (NA) land use classes and correct total area accordingly
sumarea<-sum(df$AREA)
NAarea <-sum(df[is.na(df$RavenLandClass),]$AREA)
df$AREA<-df$AREA * (sumarea/(sumarea-NAarea))
df<-df[!is.na(df$RavenLandClass),] #trim out NA land use cases

nHRUs<-nrow(df)           # get final number of HRUs
df$AREA=df$AREA *(10^-6)  # convert area to km2

Create a simple single subbasin data frame (i.e., table)

SBtable<-data.frame("SBID"=c(1),"Name"=c(fileprefix),"Downstream_ID"=c(-1),"Profile"=c("[NONE]"),"ReachLength"=c(0.0),"Gauged"=c(1),stringsAsFactors=FALSE)

kable(SBtable, caption="Raven SubBasin table")
Raven SubBasin table
SBID Name Downstream_ID Profile ReachLength Gauged
1 BoomerCreek -1 [NONE] 0 1

Create a data frame (i.e., table) for the model HRUs

HRUtable<-data.frame("ID"=1:nHRUs,"Area"=df$AREA,"Elevation"=rep(0.0,nHRUs), "Latitude"=rep(lat,nHRUs),"Longitude"=rep(long,nHRUs),"SBID"=rep(1,nHRUs),"LandUse"=df$RavenLandClass,"Vegetation"=df$RavenVegClass,"SoilProfile"=rep("DEFAULT_P",nHRUs),"Terrain"=rep("[NONE]",nHRUs),"Aquifer"=rep("[NONE]",nHRUs),"Slope"=rep(0,nHRUs),"Aspect"=rep(0.0,nHRUs),stringsAsFactors=FALSE)

kable(HRUtable, caption="Raven HRU table")
Raven HRU table
ID Area Elevation Latitude Longitude SBID LandUse Vegetation SoilProfile Terrain Aquifer Slope Aspect
1 0.0353504 0 48.03396 -84.68364 1 WATER NO_VEG DEFAULT_P [NONE] [NONE] 0 0
2 0.0301716 0 48.03396 -84.68364 1 WETLAND WET_VEG DEFAULT_P [NONE] [NONE] 0 0
3 3.2968149 0 48.03396 -84.68364 1 WETLAND WET_VEG DEFAULT_P [NONE] [NONE] 0 0
4 0.0090065 0 48.03396 -84.68364 1 FOREST FOREST DEFAULT_P [NONE] [NONE] 0 0
5 2.9457881 0 48.03396 -84.68364 1 FOREST FOREST DEFAULT_P [NONE] [NONE] 0 0
6 0.1143820 0 48.03396 -84.68364 1 FOREST FOREST DEFAULT_P [NONE] [NONE] 0 0
7 0.1168588 0 48.03396 -84.68364 1 FOREST FOREST DEFAULT_P [NONE] [NONE] 0 0
8 0.1585137 0 48.03396 -84.68364 1 FOREST FOREST DEFAULT_P [NONE] [NONE] 0 0
9 0.0049536 0 48.03396 -84.68364 1 GRASSLAND GRASS DEFAULT_P [NONE] [NONE] 0 0
10 2.8160951 0 48.03396 -84.68364 1 URBAN NO_VEG DEFAULT_P [NONE] [NONE] 0 0
11 60.7323653 0 48.03396 -84.68364 1 AGRICULTURE CROP DEFAULT_P [NONE] [NONE] 0 0

Use these data frames to generate the Raven input .rvh file

# create model output directory
modeldir<-paste0(topdir,"model/")
if (!dir.exists(modeldir)){
  dir.create(modeldir)
}

# generate and print .rvh file
rvhfile<-paste0(modeldir,fileprefix,".rvh")
err<-rvn_rvh_write(rvhfile,SBtable,HRUtable,description="Created by OFATConversionScript.Rmd")

cat(readLines(rvhfile),sep='\n', fill=FALSE) # print rvh file contents
##########################################################################
:FileType                           .rvh
:CreationDate                   Feb 2021
#
# Created by OFATConversionScript.Rmd
# ------------------------------------------------------------------------
#
:SubBasins 
  :Attributes,        NAME, DOWNSTREAM_ID, PROFILE, REACH_LENGTH, GAUGED
  :Units     ,        none,          none,    none,           km,   none
            1, BoomerCreek,            -1,  [NONE],            0,      1
:EndSubBasins
 
:HRUs 
  :Attributes,                AREA, ELEVATION, LATITUDE, LONGITUDE, BASIN_ID, LAND_USE_CLASS, VEG_CLASS, SOIL_PROFILE, AQUIFER_PROFILE, TERRAIN_CLASS, SLOPE, ASPECT
  :Units     ,                 km2,      masl,      deg,       deg,     none,           none,      none,         none,            none,          none,   deg,   degN
            1,  0.0353503579623386,         0, 48.03396, -84.68364,        1,          WATER,    NO_VEG,    DEFAULT_P,          [NONE],        [NONE],     0,      0
            2,  0.0301716431016139,         0, 48.03396, -84.68364,        1,        WETLAND,   WET_VEG,    DEFAULT_P,          [NONE],        [NONE],     0,      0
            3,    3.29681491264053,         0, 48.03396, -84.68364,        1,        WETLAND,   WET_VEG,    DEFAULT_P,          [NONE],        [NONE],     0,      0
            4, 0.00900646062734742,         0, 48.03396, -84.68364,        1,         FOREST,    FOREST,    DEFAULT_P,          [NONE],        [NONE],     0,      0
            5,    2.94578810968966,         0, 48.03396, -84.68364,        1,         FOREST,    FOREST,    DEFAULT_P,          [NONE],        [NONE],     0,      0
            6,   0.114382049967312,         0, 48.03396, -84.68364,        1,         FOREST,    FOREST,    DEFAULT_P,          [NONE],        [NONE],     0,      0
            7,   0.116858826639833,         0, 48.03396, -84.68364,        1,         FOREST,    FOREST,    DEFAULT_P,          [NONE],        [NONE],     0,      0
            8,   0.158513707041315,         0, 48.03396, -84.68364,        1,         FOREST,    FOREST,    DEFAULT_P,          [NONE],        [NONE],     0,      0
            9, 0.00495355334504108,         0, 48.03396, -84.68364,        1,      GRASSLAND,     GRASS,    DEFAULT_P,          [NONE],        [NONE],     0,      0
           10,    2.81609507665586,         0, 48.03396, -84.68364,        1,          URBAN,    NO_VEG,    DEFAULT_P,          [NONE],        [NONE],     0,      0
           11,    60.7323653023292,         0, 48.03396, -84.68364,        1,    AGRICULTURE,      CROP,    DEFAULT_P,          [NONE],        [NONE],     0,      0
:EndHRUs