self.name = pcp_line.split(",")[1] self.elev = pcp_line.split(",")[4] self.lon = pcp_line.split(",")[3] self.lat = pcp_line.split(",")[2] self.data_list = self.get_data() def get_data(self): self.data = cj.read_from(variables.WeatherDIR + self.name + ".txt") return self.data stations_dict = {} stations_list = [] station_nr = [] used_stations = cj.extract_table_from_mdb(variables.ProjMDB, "SubPcp", variables.path + "\\subpcp.tmp~") all_stations = cj.extract_table_from_mdb(variables.ProjMDB, "pcp", variables.path + "\\pcp.tmp~") count = 0 for station_line in used_stations: if not station_line.split(",")[4] in stations_list: for pcp_file_line in all_stations: if station_line.split(",")[4] == pcp_file_line.split(",")[1]: count += 1 stations_list.append(station_line.split(",")[4]) station_nr.append(count) stations_dict[str(count)] = station(pcp_file_line) # making header
import init_file as variables import cj_function_lib as cj from datetime import datetime sub_table = cj.extract_table_from_mdb(variables.ProjMDB, "sub", variables.path + "\\sub.tmp~") now = datetime.now() DateAndTime = str(now.month) + "/" + str(now.day) + "/" + \ str(now.year) + " " + str(now.time()).split(".")[0] SWAT_Vers = "QSWAT Workflow v1.5.2" for sub_record in sub_table: # Parameters SUBBASIN = sub_record.split(",")[1].strip("\n") SUB_KM = sub_record.split(",")[2].strip("\n") SUB_LAT = sub_record.split(",")[3].strip("\n") SUB_ELEV = sub_record.split(",")[4].strip("\n") IRGAGE = sub_record.split(",")[5].strip("\n") ITGAGE = sub_record.split(",")[6].strip("\n") ISGAGE = sub_record.split(",")[7].strip("\n") IHGAGE = sub_record.split(",")[8].strip("\n") IWGAGE = sub_record.split(",")[9].strip("\n") ELEVB1 = sub_record.split(",")[10].strip("\n") ELEVB2 = sub_record.split(",")[11].strip("\n") ELEVB3 = sub_record.split(",")[12].strip("\n") ELEVB4 = sub_record.split(",")[13].strip("\n") ELEVB5 = sub_record.split(",")[14].strip("\n") ELEVB6 = sub_record.split(",")[15].strip("\n") ELEVB7 = sub_record.split(",")[16].strip("\n")
import init_file as variables import cj_function_lib as cj from datetime import datetime from sys import exit reach_table = cj.extract_table_from_mdb(variables.ProjMDB, "Reach", variables.path + "\\reach.tmp~") fig_string = "" class reach: def __init__(self, reach_number): self.number = reach_number self.order_number = None self.connects_to_reach = None self.receives_from = None # a list from which the reach receives reaches = [] number_of_subbasins = len(reach_table) reach_dictionary = {} sinks = [] sink_receive_info = {} # Here we create a list of all reaches in the watershed for counter in range(1, number_of_subbasins + 1): reaches.append(int(counter)) #here we obtain sinks (the reaches that take frome more than one reaches)
import init_file as variables import cj_function_lib as cj from datetime import datetime Sol_table = cj.extract_table_from_mdb(variables.ProjMDB, "Sol", variables.path + "\\Sol.tmp~") now = datetime.now() DateAndTime = str(now.month) + "/" + str(now.day) + "/" + \ str(now.year) + " " + str(now.time()).split(".")[0] SWAT_Vers = "QSWAT Workflow v1.5.2" for hru_record in Sol_table: # Hru ID WshedHRU = hru_record.split(",")[0].strip('"') SubBasin = hru_record.split(",")[1].strip('"') HRU_No = hru_record.split(",")[2].strip('"') Luse = hru_record.split(",")[3].strip('"') Soil = hru_record.split(",")[4].strip('"') Slope = hru_record.split(",")[5].strip('"') # Parameters SNAM = hru_record.split(",")[6].strip('"') NLAYERS = hru_record.split(",")[7].strip('"') HYDGRP = hru_record.split(",")[8].strip('"') SOL_ZMX = hru_record.split(",")[9].strip('"') ANION_EXCL = hru_record.split(",")[10].strip('"') SOL_CRK = hru_record.split(",")[11].strip('"') TEXTURE = hru_record.split(",")[12].strip('"')
import init_file as variables import cj_function_lib as cj from datetime import datetime pnd_table = cj.extract_table_from_mdb(variables.ProjMDB, "pnd", variables.path + "\\pnd.tmp~") now = datetime.now() DateAndTime = str(now.month) + "/" + str(now.day) + "/" + \ str(now.year) + " " + str(now.time()).split(".")[0] SWAT_Vers = "QSWAT Workflow v1.5.2" for hru_record in pnd_table: # Hru ID WshedHRU = hru_record.split(",")[0].strip('"') SubBasin = hru_record.split(",")[1].strip('"') # Parameters PND_FR = hru_record.split(",")[2].strip('"') PND_PSA = hru_record.split(",")[3].strip('"') PND_PVOL = hru_record.split(",")[4].strip('"') PND_ESA = hru_record.split(",")[5].strip('"') PND_EVOL = hru_record.split(",")[6].strip('"') PND_VOL = hru_record.split(",")[7].strip('"') PND_SED = hru_record.split(",")[8].strip('"') PND_NSED = hru_record.split(",")[9].strip('"') PND_K = hru_record.split(",")[10].strip('"') IFLOD1 = hru_record.split(",")[11].strip('"')
import init_file as variables import cj_function_lib as cj from datetime import datetime import pandas as pd mgt_table1 = cj.extract_table_from_mdb(variables.ProjMDB, "mgt1", variables.path + "\\mgt1.tmp~") mgt_table2_unsorted = cj.extract_table_from_mdb(variables.ProjMDB, "mgt2", variables.path + "\\mgt2.tmp~") now = datetime.now() mgt_table_lol = [] for u in mgt_table2_unsorted: mgt_table_lol.append(u.split(",")) df = pd.DataFrame.from_records(mgt_table_lol) df[0] = df[0].astype(int) df2 = df.sort_values([0], ascending=True) mgt_table2 = df2.values.tolist() DateAndTime = str(now.month) + "/" + str(now.day) + "/" + \ str(now.year) + " " + str(now.time()).split(".")[0] SWAT_Vers = "QSWAT Workflow v1.5.2" for hru_record in mgt_table1: # Hru ID WshedHRU = hru_record.split(",")[0].strip('"') SubBasin = hru_record.split(",")[1].strip('"')
self.lat = slr_line.split(",")[2] self.data_list = self.get_data() def get_data(self): self.data = cj.read_from(variables.WeatherDIR + self.name + ".txt") return self.data stations_dict = {} stations_list = [] station_nr = [] if not os.path.isfile(variables.slr_file_txt): pass else: used_stations = cj.extract_table_from_mdb(variables.ProjMDB, "SubSlr", variables.path + "\\subslr.tmp~") all_stations = cj.extract_table_from_mdb(variables.ProjMDB, "slr", variables.path + "\\slr.tmp~") count = 0 for station_line in used_stations: if not station_line.split(",")[4] in stations_list: for slr_file_line in all_stations: if station_line.split(",")[4] == slr_file_line.split(",")[1]: count += 1 stations_list.append(station_line.split(",")[4]) station_nr.append(count) stations_dict[str(count)] = station(slr_file_line) # Header creation now = datetime.now()
import init_file as variables import cj_function_lib as cj from datetime import datetime wwq_table = cj.extract_table_from_mdb(variables.ProjMDB, "wwq", variables.path + "\\wwq.tmp~") wwq_params = wwq_table[0].split(",") now = datetime.now() DateAndTime = str(now.month) + "/" + str(now.day) + "/" + \ str(now.year) + " " + str(now.time()).split(".")[0] SWAT_Vers = "QSWAT Workflow v1.5.2" # Parameters OID = wwq_params[0].strip('"') LAO = wwq_params[1].strip('"') IGROPT = wwq_params[2].strip('"') AI0 = wwq_params[3].strip('"') AI1 = wwq_params[4].strip('"') AI2 = wwq_params[5].strip('"') AI3 = wwq_params[6].strip('"') AI4 = wwq_params[7].strip('"') AI5 = wwq_params[8].strip('"') AI6 = wwq_params[9].strip('"') MUMAX = wwq_params[10].strip('"') RHOQ = wwq_params[11].strip('"') TFACT = wwq_params[12].strip('"') K_L = wwq_params[13].strip('"') K_N = wwq_params[14].strip('"') K_P = wwq_params[15].strip('"') LAMBDA0 = wwq_params[16].strip('"')
import init_file as variables import cj_function_lib as cj from datetime import datetime chm_table = cj.extract_table_from_mdb(variables.ProjMDB, "chm", variables.path + "\\chm.tmp~") now = datetime.now() DateAndTime = str(now.month) + "/" + str(now.day) + "/" + \ str(now.year) + " " + str(now.time()).split(".")[0] SWAT_Vers = "QSWAT Workflow v1.5.2" for chm_record in chm_table: # Hru ID WshedHRU = chm_record.split(",")[0].strip('"') SubBasin = chm_record.split(",")[1].strip('"') HRU_No = chm_record.split(",")[2].strip('"') Luse = chm_record.split(",")[3].strip('"') Soil = chm_record.split(",")[4].strip('"') Slope = chm_record.split(",")[5].strip('"') # Parameters SOL_NO31 = chm_record.split(",")[6].strip('"') SOL_NO32 = chm_record.split(",")[7].strip('"') SOL_NO33 = chm_record.split(",")[8].strip('"') SOL_NO34 = chm_record.split(",")[9].strip('"') SOL_NO35 = chm_record.split(",")[10].strip('"') SOL_NO36 = chm_record.split(",")[11].strip('"') SOL_NO37 = chm_record.split(",")[12].strip('"') SOL_NO38 = chm_record.split(",")[13].strip('"')
import sys import cj_function_lib as cj import init_file as variables import mdbtools as mdt #print variables.ProjMDB #print variables.QSWAT_MDB hrus = cj.extract_table_from_mdb(variables.ProjMDB, 'hrus', variables.path + "\\hrus.tmp~") mgt2rgn = cj.extract_table_from_mdb(variables.QSWAT_MDB, 'mgt2rng', variables.path + "\\mgt2rgn.tmp~") crop = cj.extract_table_from_mdb(variables.QSWAT_MDB, 'crop', variables.path + "\\crop.tmp~") opSchedules = cj.extract_table_from_mdb(variables.QSWAT_MDB, 'OpSchedules', variables.path + "\\opSchedules.tmp~") mgt2_defaults = {} for record in mgt2rgn: # Getting a list of parameter names for mgt2 and their defaults if record.split(",")[0].strip(" ") != "": mgt2_defaults[record.split(",")[0].strip("\[").strip( "\]")] = record.split(",")[3] #if (record.split(",")[5][0:4] == "AUTO") or (record.split(",")[5][0:4] == "INTE"): # if record.split(",")[3] == "na": # mgt2_defaults[record.split(",")[0].strip("\[").strip("\]")] = int(1) # else: # mgt2_defaults[record.split(",")[0].strip("\[").strip("\]")] = int(record.split(",")[3]) #elif (record.split(",")[5][0:4] == "FLOA"): # mgt2_defaults[record.split(",")[0].strip("\[").strip("\]")] = float(record.split(",")[3]) #elif (record.split(",")[5][0:4] == "TEXT"):
""" Author : Celray James CHAWANDA ([email protected]) Institution : Vrije Universiteit Brussel (VUB) This script writes the bsn file """ import init_file as variables import cj_function_lib as cj from datetime import datetime bsn_table = cj.extract_table_from_mdb(variables.ProjMDB, "bsn", variables.path + "\\bsn.tmp~") bsn_params = bsn_table[0].split(",") now = datetime.now() DateAndTime = str(now.month) + "/" + str(now.day) + "/" + \ str(now.year) + " " + str(now.time()).split(".")[0] SWAT_Vers = "QSWAT Workflow v1.5.2" # Parameters SFTMP = bsn_params[1].strip('"') SMTMP = bsn_params[2].strip('"') SMFMX = bsn_params[3].strip('"') SMFMN = bsn_params[4].strip('"') TIMP = bsn_params[5].strip('"') SNOCOVMX = bsn_params[6].strip('"') SNO50COV = bsn_params[7].strip('"') IPET = bsn_params[8].strip('"') ESCO = bsn_params[9].strip('"')
import sys import cj_function_lib as cj import init_file as variables import mdbtools as mdt #print variables.ProjMDB #print variables.QSWAT_MDB watersheds = cj.extract_table_from_mdb(variables.ProjMDB, 'Watershed', variables.path + "\\watershed.tmp~") swqrgn = cj.extract_table_from_mdb(variables.QSWAT_MDB, 'swqrng', variables.path + "\\swqrgn.tmp~") swq_defaults = {} for record in swqrgn: # Getting a list of parameter names for swq and their defaults if record.split(",")[0].strip(" ") != "": swq_defaults[record.split(",")[0].strip("\[").strip( "\]")] = record.split(",")[3] """ # here we commit to table the parameters for the subbasin to a row in the table swq """ swq = mdt.mdb_with_ops(variables.ProjMDB) swq.clear_table("swq") OID = 0 for watershed in watersheds: # getting field values from from watershed table OID = OID + 1 swq_defaults["OID"] = OID swq_defaults["SUBBASIN"] = int(watershed.split(",")[3])
import sys import cj_function_lib as cj import init_file as variables import mdbtools as mdt #print variables.ProjMDB #print variables.QSWAT_MDB wwqrng = cj.extract_table_from_mdb(variables.QSWAT_MDB, 'wwqrng', variables.path + "\\wwqrng.tmp~") wwq_defaults = {} for record in wwqrng: # Getting a list of parameter names for wwq and their defaults if record.split(",")[0].strip(" ") != "": wwq_defaults[record.split(",")[0].strip("\[").strip( "\]")] = record.split(",")[3] """ # here we commit to table the parameters for the wwq to the row in the table wwq """ wwq = mdt.mdb_with_ops(variables.ProjMDB) wwq.clear_table("wwq") wwq_defaults["OID"] = 1 wwq_defaults = cj.format_data_type(wwq_defaults, wwqrng) wwq.insert_row("wwq", wwq_defaults, True) wwq.disconnect()
import sys import cj_function_lib as cj import init_file as variables import mdbtools as mdt #print variables.ProjMDB #print variables.QSWAT_MDB hrus = cj.extract_table_from_mdb(variables.ProjMDB, 'hrus', variables.path + "\\hrus.tmp~") gwrgn = cj.extract_table_from_mdb(variables.QSWAT_MDB, 'gwrng', variables.path + "\\gwrgn.tmp~") gw_defaults={} for record in gwrgn: # Getting a list of parameter names for gw and their defaults if record.split(",")[0].strip(" ") != "": gw_defaults[record.split(",")[0].strip("\[").strip("\]")] = record.split(",")[3] #gw_defaults.pop("ALPHA_BF_D") """ # here we commit to table the parameters for the hru to a row in the table gw """ gw = mdt.mdb_with_ops(variables.ProjMDB) gw.connect() try: gw.add_field("gw", "ALPHA_BF_D", "FLOAT") gw.disconnect() except: pass
self.lat = hmd_line.split(",")[2] self.data_list = self.get_data() def get_data(self): self.data = cj.read_from(variables.WeatherDIR + self.name + ".txt") return self.data stations_dict = {} stations_list = [] station_nr = [] if not os.path.isfile(variables.hmd_file_txt): pass else: used_stations = cj.extract_table_from_mdb(variables.ProjMDB, "SubHmd", variables.path + "\\subhmd.tmp~") all_stations = cj.extract_table_from_mdb(variables.ProjMDB, "hmd", variables.path + "\\hmd.tmp~") count = 0 for station_line in used_stations: if not station_line.split(",")[4] in stations_list: for hmd_file_line in all_stations: if station_line.split(",")[4] == hmd_file_line.split(",")[1]: count += 1 stations_list.append(station_line.split(",")[4]) station_nr.append(count) stations_dict[str(count)] = station(hmd_file_line) # Header creation now = datetime.now()
import sys import os.path import cj_function_lib as cj import init_file as variables import namelist import mdbtools as mdt #print variables.ProjMDB #print variables.QSWAT_MDB ciorgn = cj.extract_table_from_mdb(variables.QSWAT_MDB, 'ciorng', variables.path + "\\ciorgn.tmp~") cio_configuration = cj.read_from(variables.path + "\\cio_config.tmp~") cio_defaults = {} defaults_list = [] for record in ciorgn: # Getting a list of parameter names for cio and their defaults if record.split(",")[0].strip(" ") != "": cio_defaults[record.split(",")[0].strip("\[").strip( "\]")] = record.split(",")[3] defaults_list.append(record.split(",")[0].strip("\[").strip("\]")) """ # here we commit to table the parameters for the hru to a row in the table cio """ cio = mdt.mdb_with_ops(variables.ProjMDB) cio.connect() cio.create_table("cio", "OID", "INTEGER") for field in defaults_list:
self.lat = wnd_line.split(",")[2] self.data_list = self.get_data() def get_data(self): self.data = cj.read_from(variables.WeatherDIR + self.name + ".txt") return self.data stations_dict = {} stations_list = [] station_nr = [] if not os.path.isfile(variables.wnd_file_txt): pass else: used_stations = cj.extract_table_from_mdb(variables.ProjMDB, "SubWnd", variables.path + "\\subwnd.tmp~") all_stations = cj.extract_table_from_mdb(variables.ProjMDB, "wnd", variables.path + "\\wnd.tmp~") count = 0 for station_line in used_stations: if not station_line.split(",")[4] in stations_list: for wnd_file_line in all_stations: if station_line.split(",")[4] == wnd_file_line.split(",")[1]: count += 1 stations_list.append(station_line.split(",")[4]) station_nr.append(count) stations_dict[str(count)] = station(wnd_file_line) # Header creation now = datetime.now()
import init_file as variables import cj_function_lib as cj from datetime import datetime sep_table = cj.extract_table_from_mdb(variables.ProjMDB, "sep", variables.path + "\\sep.tmp~") now = datetime.now() DateAndTime = str(now.month) + "/" + str(now.day) + "/" + \ str(now.year) + " " + str(now.time()).split(".")[0] SWAT_Vers = "QSWAT Workflow v1.5.2" for hru_record in sep_table: # Hru ID WshedHRU = hru_record.split(",")[0].strip('"') SubBasin = hru_record.split(",")[1].strip('"') HRU_No = hru_record.split(",")[2].strip('"') Luse = hru_record.split(",")[3].strip('"') Soil = hru_record.split(",")[4].strip('"') Slope = hru_record.split(",")[5].strip('"') # Parameters ISEP_TYP = hru_record.split(",")[6].strip('"') ISEP_IYR = hru_record.split(",")[7].strip('"') ISEP_OPT = hru_record.split(",")[8].strip('"') SEP_CAP = hru_record.split(",")[9].strip('"') BZ_AREA = hru_record.split(",")[10].strip('"') ISEP_TFAIL = hru_record.split(",")[11].strip('"') BZ_Z = hru_record.split(",")[12].strip('"')
import init_file as variables import cj_function_lib as cj from datetime import datetime wus_table = cj.extract_table_from_mdb( variables.ProjMDB, "wus", variables.path + "\\wus.tmp~") now = datetime.now() DateAndTime = str(now.month) + "/" + str(now.day) + "/" + str(now.year) + " " + str(now.time()).split(".")[0] SWAT_Vers = "QSWAT Workflow v1.5.2" for sub_record in wus_table: # Hru ID SubBasin = sub_record.split(",")[1].strip('"') # Parameters WUPND1 = cj.trailing_spaces(10, sub_record.split(",")[2].strip('"'), 1) WUPND2 = cj.trailing_spaces(10, sub_record.split(",")[3].strip('"'), 1) WUPND3 = cj.trailing_spaces(10, sub_record.split(",")[4].strip('"'), 1) WUPND4 = cj.trailing_spaces(10, sub_record.split(",")[5].strip('"'), 1) WUPND5 = cj.trailing_spaces(10, sub_record.split(",")[6].strip('"'), 1) WUPND6 = cj.trailing_spaces(10, sub_record.split(",")[7].strip('"'), 1) WUPND7 = cj.trailing_spaces(10, sub_record.split(",")[8].strip('"'), 1) WUPND8 = cj.trailing_spaces(10, sub_record.split(",")[9].strip('"'), 1) WUPND9 = cj.trailing_spaces(10, sub_record.split(",")[10].strip('"'), 1) WUPND10 = cj.trailing_spaces(10, sub_record.split(",")[11].strip('"'), 1) WUPND11 = cj.trailing_spaces(10, sub_record.split(",")[12].strip('"'), 1) WUPND12 = cj.trailing_spaces(10, sub_record.split(",")[13].strip('"'), 1) WURCH1 = cj.trailing_spaces(10, sub_record.split(",")[14].strip('"'), 1) WURCH2 = cj.trailing_spaces(10, sub_record.split(",")[15].strip('"'), 1)
import sys import cj_function_lib as cj import init_file as variables import mdbtools as mdt #print variables.ProjMDB #print variables.QSWAT_MDB hrus = cj.extract_table_from_mdb(variables.ProjMDB, 'hrus', variables.path + "\\hrus.tmp~") hrurgn = cj.extract_table_from_mdb(variables.QSWAT_MDB, 'hrurng', variables.path + "\\hrurgn.tmp~") crop = cj.extract_table_from_mdb(variables.QSWAT_MDB, 'crop', variables.path + "\\crop.tmp~") hru_defaults={} for record in hrurgn: # Getting a list of parameter names for hru and their defaults if record.split(",")[0].strip(" ") != "": hru_defaults[record.split(",")[0].strip("\[").strip("\]")] = record.split(",")[3] fields_to_add = ["POT_SOLP", "POT_K", "N_REDUC", "N_LAG", "N_LN", "N_LNCO", "SURLAG", "R2ADJ"] #Adding fields, that are missing from the table in this order """ # here we commit to table the parameters for the hru to a row in the table hru """ hru = mdt.mdb_with_ops(variables.ProjMDB) hru.connect() for field in fields_to_add: try: hru.add_field("hru", field, "FLOAT") hru.disconnect()
import init_file as variables import cj_function_lib as cj from datetime import datetime fert_table = cj.extract_table_from_mdb(variables.QSWAT_MDB, "fert", variables.path + "\\fert.tmp~") fert = "" for fert_line in fert_table: fert += cj.trailing_spaces( 4, fert_line.split(",")[1], 0) + cj.string_trailing_spaces( 9, fert_line.split(",")[2]) + cj.trailing_spaces( 8, fert_line.split(",")[3], 3) + cj.trailing_spaces( 8, fert_line.split(",")[4], 3) + cj.trailing_spaces( 8, fert_line.split(",")[5], 3) + cj.trailing_spaces( 8, fert_line.split(",")[6], 3) + cj.trailing_spaces( 8, fert_line.split(",")[7], 3) + cj.trailing_spaces( 4, fert_line.split(",")[8], 2) + "E+00" + cj.trailing_spaces( 4, fert_line.split(",")[9],
import sys import cj_function_lib as cj import init_file as variables import mdbtools as mdt #print variables.ProjMDB #print variables.QSWAT_MDB rtergn = cj.extract_table_from_mdb(variables.QSWAT_MDB, 'rterng', variables.path + "\\rtergn.tmp~") reach_data = cj.extract_table_from_mdb(variables.ProjMDB, 'Reach', variables.path + "\\reach_data.tmp~") rte_defaults = {} for record in rtergn: # Getting a list of parameter names for rte and their defaults if record.split(",")[0].strip(" ") != "": rte_defaults[record.split(",")[0].strip("\[").strip( "\]")] = record.split(",")[3] """ # here we commit to table the parameters for the rte to a row in the table rte """ rte = mdt.mdb_with_ops(variables.ProjMDB) rte.clear_table("rte") for reach in reach_data: # getting field values from from Reach table rte_defaults["SUBBASIN"] = reach.split(",")[6] #.split(".")[0] rte_defaults["OID"] = reach.split(",")[0] rte_defaults["CH_W2"] = reach.split(",")[11] rte_defaults["CH_D"] = reach.split(",")[12]
self.name = tmp_line.split(",")[1] self.elev = tmp_line.split(",")[4] self.lon = tmp_line.split(",")[3] self.lat = tmp_line.split(",")[2] self.data_list = self.get_data() def get_data(self): self.data = cj.read_from(variables.WeatherDIR + self.name + ".txt") return self.data stations_dict = {} stations_list = [] station_nr = [] used_stations = cj.extract_table_from_mdb(variables.ProjMDB, "SubTmp", variables.path + "\\subtmp.tmp~") all_stations = cj.extract_table_from_mdb(variables.ProjMDB, "tmp", variables.path + "\\tmp.tmp~") count = 0 for station_line in used_stations: if not station_line.split(",")[4] in stations_list: for tmp_file_line in all_stations: if station_line.split(",")[4] == tmp_file_line.split(",")[1]: count += 1 stations_list.append(station_line.split(",")[4]) station_nr.append(count) stations_dict[str(count)] = station(tmp_file_line) # making header
import init_file as variables import mdbtools as mdt def get_distance(x1, y1, x2, y2): distance = ((x2 - x1)**2 + (y2 - y1)**2)**0.5 return distance #print variables.ProjMDB #print variables.QSWAT_MDB if not os.path.isfile(variables.pcp_file_txt): pass else: subbasins = cj.extract_table_from_mdb(variables.ProjMDB, 'Watershed', variables.path + "\\watershed.tmp~") pcp_stations = cj.read_from(variables.pcp_file_txt) #pcp_fields = ["ID", "NAME", "LAT", "LONG", "ELEVATION"] pcp_values = {} # initialising the dictionary #for field in pcp_fields: # pcp_values[field] = 0 pcp = mdt.mdb_with_ops(variables.ProjMDB) pcp.connect() pcp.clear_table("pcp") for i in range( 1, len(pcp_stations)
import sys, os import cj_function_lib as cj import init_file as variables import mdbtools as mdt #print variables.ProjMDB #print variables.QSWAT_MDB hrus = cj.extract_table_from_mdb(variables.ProjMDB, 'hrus', variables.path + "\\hrus.tmp~") subrgn = cj.extract_table_from_mdb(variables.QSWAT_MDB, 'subrng', variables.path + "\\subrgn.tmp~") basindata1 = cj.extract_table_from_mdb(variables.ProjMDB, 'BASINSDATA1', variables.path + "\\basindata1.tmp~") try: subpcp = cj.extract_table_from_mdb(variables.ProjMDB, 'SubPcp', variables.path + "\\subpcp.tmp~") except: pass try: subslr = cj.extract_table_from_mdb(variables.ProjMDB, 'SubSlr', variables.path + "\\subslr.tmp~") except: pass try: subtmp = cj.extract_table_from_mdb(variables.ProjMDB, 'SubTmp', variables.path + "\\subtmp.tmp~") except: pass
import sys import cj_function_lib as cj import init_file as variables import mdbtools as mdt #print variables.ProjMDB #print variables.QSWAT_MDB hrus = cj.extract_table_from_mdb(variables.ProjMDB, 'hrus', variables.path + "\\hrus.tmp~") mgt1rgn = cj.extract_table_from_mdb(variables.QSWAT_MDB, 'mgt1rng', variables.path + "\\mgt1rgn.tmp~") crop = cj.extract_table_from_mdb(variables.QSWAT_MDB, 'crop', variables.path + "\\crop.tmp~") usersoil = cj.extract_table_from_mdb(variables.QSWAT_MDB, 'usersoil', variables.path + "\\usersoil.tmp~") mgt1_defaults = {} for record in mgt1rgn: # Getting a list of parameter names for mgt1 and their defaults if record.split(",")[0].strip(" ") != "": if (record.split(",")[5][0:4] == "AUTO") or (record.split(",")[5][0:4] == "INTE"): if record.split(",")[3] == "na": mgt1_defaults[record.split(",")[0]] = int(1) else: mgt1_defaults[record.split(",")[0]] = int(record.split(",")[3]) elif (record.split(",")[5][0:4] == "FLOA"): mgt1_defaults[record.split(",")[0]] = float(record.split(",")[3]) elif (record.split(",")[5][0:4] == "TEXT"): mgt1_defaults[record.split(",")[0]] = record.split(",")[3]
import init_file as variables import cj_function_lib as cj from datetime import datetime wgn_table = cj.extract_table_from_mdb(variables.ProjMDB, "wgn", variables.path + "\\wgn.tmp~") now = datetime.now() DateAndTime = str(now.month) + "/" + str(now.day) + "/" + \ str(now.year) + " " + str(now.time()).split(".")[0] SWAT_Vers = "QSWAT Workflow v1.5.2" for hru_record in wgn_table: # Hru ID WshedHRU = hru_record.split(",")[0].strip('"') SubBasin = hru_record.split(",")[1].strip('"') # Parameters STATION = hru_record.split(",")[2].strip('"') WLATITUDE = hru_record.split(",")[3].strip('"') WLONGITUDE = hru_record.split(",")[4].strip('"') WELEV = hru_record.split(",")[5].strip('"') RAIN_YRS = hru_record.split(",")[6].strip('"') TMPMX1 = hru_record.split(",")[7].strip('"') TMPMX2 = hru_record.split(",")[8].strip('"') TMPMX3 = hru_record.split(",")[9].strip('"') TMPMX4 = hru_record.split(",")[10].strip('"') TMPMX5 = hru_record.split(",")[11].strip('"') TMPMX6 = hru_record.split(",")[12].strip('"') TMPMX7 = hru_record.split(",")[13].strip('"')
import init_file as variables import cj_function_lib as cj from datetime import datetime rte_table = cj.extract_table_from_mdb(variables.ProjMDB, "rte", variables.path + "\\rte.tmp~") now = datetime.now() DateAndTime = str(now.month) + "/" + str(now.day) + "/" + \ str(now.year) + " " + str(now.time()).split(".")[0] SWAT_Vers = "QSWAT Workflow v1.5.2" for sub_record in rte_table: # Hru ID WshedHRU = sub_record.split(",")[0].strip('"') SubBasin = sub_record.split(",")[1].strip('"') # Parameters CHW2 = sub_record.split(",")[2].strip('"') CHD = sub_record.split(",")[3].strip('"') CH_S2 = sub_record.split(",")[4].strip('"') CH_L2 = sub_record.split(",")[5].strip('"') CH_N2 = sub_record.split(",")[6].strip('"') CH_K2 = sub_record.split(",")[7].strip('"') CH_COV1 = sub_record.split(",")[8].strip('"') CH_COV2 = sub_record.split(",")[9].strip('"') CH_WDR = sub_record.split(",")[10].strip('"') ALPHA_BNK = sub_record.split(",")[11].strip('"') ICANAL = sub_record.split(",")[12].strip('"')
""" The distance units must be the same, elevation is not used and can be removed from arguments """ x2_, y2_ = transform_point_coordinates(x2, y2, epsg_) x1_, y1_ = transform_point_coordinates(x1, y1, epsg_) #distance = ((x2_ - x1_)**2 + (y2_ - y1_)**2)**0.5 distance = ((x2 - x1)**2 + (y2 - y1)**2)**0.5 return distance #print variables.ProjMDB #print variables.QSWAT_MDB transform_epsg = int(cj.read_from(variables.path + "/epsg_code.tmp~")[0]) subbasins = cj.extract_table_from_mdb(variables.ProjMDB, 'Watershed', variables.path + "\\watershed.tmp~") wgnrgn = cj.extract_table_from_mdb(variables.QSWAT_MDB, 'wgnrng', variables.path + "\\wgnrgn.tmp~") WGEN_user = cj.extract_table_from_mdb(variables.QSWAT_MDB, 'WGEN_user', variables.path + "\\WGEN_user.tmp~") wgn_defaults = {} SubWgn_defaults = {} for record in wgnrgn: # Getting a list of parameter names for wgn and their defaults if record.split(",")[0].strip(" ") != "": wgn_defaults[record.split(",")[0].strip("\[").strip( "\]")] = record.split(",")[3] #wgn_defaults.pop("ALPHA_BF_D")