Skip to content

Commit

Permalink
Update to v1.5.8
Browse files Browse the repository at this point in the history
  • Loading branch information
celray committed Oct 9, 2019
1 parent 72dda5b commit 607934e
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 133 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Celray James CHAWANDA
Copyright (c) 2019 Celray James CHAWANDA

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# QSWAT_Automated_Workflow v1.5.2
# QSWAT_Automated_Workflow v1.5.8

Automated workflow for setting up the SWAT Model presented in Chawanda et al., 2018 EMS.

## What is new in v1.5.2?
## What is new in v1.5.8?
Included mechanism to go back from model to input data and namelist.
New setting in the namelist include:
* Model_2_namelist
Expand All @@ -15,10 +15,7 @@ Descriptions are included in the namelist.

## To Install
[Qgis 2.6.1 (32bit)](http://qgis.org/downloads/QGIS-OSGeo4W-2.6.1-1-Setup-x86.exe)
[QSWAT 1.5](https://swat.tamu.edu/media/115805/qswatinstall15.zip)
[gdal](https://sandbox.idre.ucla.edu/sandbox/tutorials/installing-gdal-for-windows)
install pyodbc via `pip install pyodbc`

[QSWAT Workflow v1.5.8](https://swat.tamu.edu/media/115805/qswatinstall15.zip)

## For users
This repository includes the code for the wrapper presented in this paper. The wrapper runs in 32 bit version of python 2.7.
Expand All @@ -36,7 +33,7 @@ This directory contains all the modules for the workflow
This directory has an example dataset for testing

## Versions
Version 1.5.2 - December 2018
Version 1.5.8 - September 2019

## Authors
Celray James CHAWANDA
Expand Down
Binary file removed __pycache__/namelist.cpython-37.pyc
Binary file not shown.
Binary file removed __pycache__/settings.cpython-37.pyc
Binary file not shown.
79 changes: 0 additions & 79 deletions namelist.py

This file was deleted.

4 changes: 4 additions & 0 deletions runQSWAT.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo off
set mycd=%cd:\=\\%
@echo on
"C:\Python27\python.exe" "C:\SWAT\QSWAT Workflow\run_QSWAT.py" %mycd%
46 changes: 0 additions & 46 deletions runQSWAT.py

This file was deleted.

57 changes: 57 additions & 0 deletions run_QSWAT.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""
Author : Celray James CHAWANDA ([email protected])
Institution : Vrije Universiteit Brussel (VUB)
This is the main script for launching the SWAT model setup process
"""
import sys, os, shutil, shlex

home_dir = os.path.dirname(os.path.realpath(__file__))
python = "C:\\Python27\\python.exe"
current_dir = os.getcwd()
sys.path.append(current_dir)
from namelist import *
from datetime import datetime
import subprocess

def run_and_log(command, log_, save_dir, mode, args_):
if log_:
print("\t> logging is set to 'True' in namelist; output is being saved to " + save_dir)
if mode == "w":
os.system(command + " " +args_ + ">" + save_dir + '2>&1')
elif mode == "a":
os.system(command + " " +args_ + ">>" + save_dir + '2>&1')
else:
os.system(command + " " +args_)

def copy_file(original_file_path, destination):
if os.path.isfile(destination):
os.remove(destination)
shutil.copy(original_file_path, destination)

time_begin = datetime.now().strftime('%Y-%m-%d %H:%M:%S')

copy_file("namelist.py", home_dir + "/workflow_lib/namelist.py")
os.chdir(home_dir + "/workflow_lib/")

if not Model_2_namelist:
run_and_log(python + ' "' + os.path.join(home_dir, 'workflow_lib', 'prepare_project.py') + '"', log, '"' + os.path.join(home_dir, 'log.txt') + '"', "w", current_dir)
run_and_log(python + ' "' + os.path.join(home_dir, 'workflow_lib', 'main.py') + '"', log, '"' + os.path.join(home_dir, 'log.txt') + '"', "a", current_dir)
else:
run_and_log(python + ' "' + os.path.join(home_dir, 'workflow_lib', 'model_2_namelist.py') + '"', log, '"' + os.path.join(home_dir, 'log.txt') + '"', "a", current_dir)

if not Model_2_namelist:
if calibrate:
run_and_log(python + ' "' + os.path.join(home_dir, 'workflow_lib', 'calibrate_model.py') + '"', False, '"' + os.path.join(home_dir, 'log.txt') + '"', "a", current_dir + " " + Project_Name)

if make_figures:
run_and_log(python + ' "' + os.path.join(home_dir, 'workflow_lib', 'figures.py') + '"', False, '"' + os.path.join(home_dir, 'log.txt') + '"', "a", os.path.join(current_dir, "model", Project_Name) + " sub null " + " ".join([str(i) for i in range(int(Model_Run_period.split(" ")[0].split("-")[0]), int(Model_Run_period.split(" ")[-1].split("-")[-1]) + 1 )]))

time_end = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print("Run Time:\n From : " + time_begin)
print(" To : " + time_end)

with open(current_dir + "/run_time.txt", "w") as f:
f.write("Begin: " + time_begin + "\nEnd : " + time_end)

raw_input("\n\npress ENTER to exit...")

0 comments on commit 607934e

Please sign in to comment.