-
Notifications
You must be signed in to change notification settings - Fork 10
/
bdwsRun.py
58 lines (49 loc) · 3 KB
/
bdwsRun.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from bdws import BDLoG, BDSWEA
from bdflopy import BDflopy
import arcpy
import os
from SupportingFunctions import make_folder, find_available_num_prefix
def main(projectRoot, bratPath, demPath, flowAcc, flowDir, horizontalKFN, verticalKFN, fieldCapacity, modflowexe):
arcpy.AddMessage("Running BDLoG...")
projectFolder = make_folder(projectRoot, "BDWS_Project")
inputsFolder = make_folder(projectFolder, "Inputs")
outDir = make_folder(projectFolder, "Output")
bratCap = 1.0 #proportion (0-1) of maximum estimted dam capacity (from BRAT) for scenario
bratPath = copyIntoFolder(bratPath, inputsFolder, "BRAT")
demPath = copyIntoFolder(demPath, inputsFolder, "DEM")
flowAcc = copyIntoFolder(flowAcc, inputsFolder, "FlowAccumulation")
flowDir = copyIntoFolder(flowDir, inputsFolder, "FlowDir")
if horizontalKFN:
horizontalKFN = copyIntoFolder(horizontalKFN, inputsFolder, "HorizontalKSAT")
if verticalKFN:
verticalKFN = copyIntoFolder(verticalKFN, inputsFolder, "VerticalKSAT")
if fieldCapacity:
fieldCapacity = copyIntoFolder(fieldCapacity, inputsFolder, "FieldCapacity")
model = BDLoG(bratPath, demPath, flowAcc, outDir, bratCap) #initialize BDLoG, sets varibles and loads inputs
model.run() #run BDLoG algorithms
model.close() #close any files left open by BDLoG
arcpy.AddMessage("bdlog done")
#run surface water storage estimation (BDSWEA)
idPath = os.path.join(outDir, "damID.tif")#ouput from BDLoG
modPoints = os.path.join(outDir, "ModeledDamPoints.shp") #output from BDLoG
model = BDSWEA(demPath, flowDir, flowAcc, idPath, outDir, modPoints) #initialize BDSWEA object, sets variables and loads inputs
model.run() #run BDSWEA algorithm
model.writeModflowFiles() #generate files needed to parameterize MODFLOW
model.close() #close any files left open by BDLoG
arcpy.AddMessage("bdswea done")
if horizontalKFN and verticalKFN and fieldCapacity and modflowexe:
#run groundwater storage estimation (MODFLOW)
arcpy.AddMessage("Running BDflopy")
indir = projectFolder + "/inputs" #location of input raste files
modflowOutput = os.path.join(projectFolder, "modflow") #directory to output MODFLOW results
kconv = 0.000001 #conversion of hkfn and vkfn to meters per second
fconv = 0.01 #conversion of fracfn to a proportion
gwmodel = BDflopy(modflowexe, indir, outDir, modflowOutput, demPath) #initialize BDflopy, sets variables and loads inputs
gwmodel.run(horizontalKFN, verticalKFN, kconv, fieldCapacity, fconv) #run BDflopy, this will write inputs for MODFLOW and then run MODFLOW
gwmodel.close() #close any open files
arcpy.AddMessage("done")
def copyIntoFolder(thingToCopy, copyFolderRoot, copyFolderName):
copyFolder = make_folder(copyFolderRoot, find_available_num_prefix(copyFolderRoot) + '_' + copyFolderName)
copyPath = os.path.join(copyFolder, os.path.basename(thingToCopy))
arcpy.Copy_management(thingToCopy, copyPath)
return copyPath