def get_data(self): self.data = cj.read_from(variables.WeatherDIR + self.name + ".txt") return self.data
crop_dir=landuse_raster_name, rt=root)): os.makedirs("{rt}Data/rasters/{crop_dir}".format( crop_dir=landuse_raster_name, rt=root)) l_copy_list = cj_function_lib.list_files_from( "{pjd}Source/crop/{lu}".format(lu=landuse_raster_name, pjd=ProjDir), "*") for l_c_item in l_copy_list: cj_function_lib.copy_file( l_c_item, "{rt}Data/rasters/{crop_dir}".format(crop_dir=landuse_raster_name, rt=root)) # # get thresholds and options report("retrieving thresholds and model options") project_string_list = cj_function_lib.read_from("{dir}model/{fn}.qgs".format( dir=root, fn=ProjName)) project_string = "" for pj_line in project_string_list: project_string += pj_line slope_classes = project_string.split('<slopeBands type="QString">[')[-1].split( "]</slopeBands")[0] ws_threshold = project_string.split('<threshold type="int">')[-1].split( "</threshold>")[0] snap_threshold = project_string.split('<snapThreshold type="int">')[-1].split( "</snapThreshold>")[0] is_multiple = project_string.split('<isMultiple type="int">')[-1].split( "</isMultiple>")[0] is_dominant_hru = project_string.split('<isDominantHRU type="int">')[-1].split( "</isDominantHRU>")[0]
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) ): # the square brackets are used to escape reserved column names
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:
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.wnd_file_txt): pass else: subbasins = cj.extract_table_from_mdb(variables.ProjMDB, 'Watershed', variables.path + "\\watershed.tmp~") wnd_stations = cj.read_from(variables.wnd_file_txt) #wnd_fields = ["ID", "NAME", "LAT", "LONG", "ELEVATION"] wnd_values = {} # initialising the dictionary #for field in wnd_fields: # wnd_values[field] = 0 wnd = mdt.mdb_with_ops(variables.ProjMDB) wnd.connect() wnd.create_table("wnd", "[ID]", "INTEGER") wnd.add_field("wnd", "[NAME]", "TEXT") wnd.add_field("wnd", "[LAT]", "FLOAT") wnd.add_field("wnd", "[LONG]", "FLOAT") wnd.add_field("wnd", "[ELEVATION]", "FLOAT")
copyshape(outletshapefile, "outlet", current_root + "/" + project_name + "/Watershed/Shapes/") copyshape(outletshapefile, "outlet_sel", current_root + "/" + project_name + "/Watershed/Shapes/") copyshape(outletshapefile, "outlet_sel_snap", current_root + "/" + project_name + "/Watershed/Shapes/") else: print( "\t! Error: either No outletshape file was specified, or it does not exist." ) print("\t> Getting database tables \t\t: {0}".format( os.path.join(sys.argv[1], "Data", "tables"))) # Here we set lookup tables, usersoil and WGEN_user in the Ref and Project Databases soil_lu = cj.read_from( os.path.join(sys.argv[1], "Data", "tables", namelist.soil_lookup)) landuse_lu = cj.read_from( os.path.join(sys.argv[1], "Data", "tables", namelist.landuse_lookup)) WGEN_data = cj.read_from( os.path.join(sys.argv[1], "Data", "tables", namelist.WGEN_user)) usersoil_data = cj.read_from( os.path.join(sys.argv[1], "Data", "tables", namelist.Usersoil)) print("\t> Configuring databasses \t\t: {0}.mdb & QSWATRef2012.mdb".format( project_name)) prj_dbase = mdt.mdb_with_ops( os.path.join(current_root, project_name, project_name + ".mdb")) ref_dbase = mdt.mdb_with_ops( os.path.join(current_root, project_name, "QSWATRef2012.mdb")) # how to remove existing table if any?
#import sys, os, zipfile #import cj_function_lib as cj #import mdbtools as mdt #path = os.path.dirname(__file__) #root = path.replace("mdbtoascii", "") #sys.path.append(root) # #import settings # #print "____________________________________________________________________________\nPreparing Project...\n" # #project_name = settings.Project_Name # #proj4, is_proj = cj.get_proj4_from(root + "/" + project_name + "/Source/crop/" + settings.Land_Use) # #print proj4 #print is_proj import cj_function_lib as cj number = cj.trailing_zeros(5, "0.000001", 2) print number filec = cj.read_from("WGEN_user.csv") for line in filec: for part in line.split(","): text = cj._removeNonAscii(part) #for i in range (10000): #cj.update_status(str(i)) print text
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.slr_file_txt): pass else: subbasins = cj.extract_table_from_mdb(variables.ProjMDB, 'Watershed', variables.path + "\\watershed.tmp~") slr_stations = cj.read_from(variables.slr_file_txt) #slr_fields = ["ID", "NAME", "LAT", "LONG", "ELEVATION"] slr_values = {} # initialising the dictionary #for field in slr_fields: # slr_values[field] = 0 slr = mdt.mdb_with_ops(variables.ProjMDB) slr.connect() try: slr.create_table("SubSlr", "ObjectID", "INTEGER") except: pass try:
pcp_file_txt = WeatherDIR + namelist.Precipitation tmp_file_txt = WeatherDIR + namelist.Temperature hmd_file_txt = WeatherDIR + namelist.Rel_Humidity wnd_file_txt = WeatherDIR + namelist.Wind slr_file_txt = WeatherDIR + namelist.Solar_Radiation # for logging logging = namelist.log os.chdir(cwd) copyfile(root + "workflow_lib/runQSWATBatch.bat", cwd + "\\runQSWATBatch.bat") os.system("runQSWATBatch.bat " + ProjName + ".qgs") # set projections for shape files in "...\Project Name\Watershed\Shapes\" prj_ = osr.SpatialReference() prj_.ImportFromEPSG(int(cj.read_from(root + "workflow_lib/epsg_code.tmp~")[0])) prj_wkt = prj_.ExportToWkt() cj.write_to(cwd + "{0}/Watershed/Shapes/subs1.prj".format(namelist.Project_Name), prj_wkt) cj.write_to(cwd + "{0}/Watershed/Shapes/riv1.prj".format(namelist.Project_Name), prj_wkt) # work on the databases os.chdir(cwd) print '' cj.update_status("Working on the Project Database : chm", logging = logging) execfile(root + "workflow_lib/chm_dbase.py") cj.update_status("Working on the Project Database : gw", logging = logging) execfile(root + "workflow_lib/gw_dbase.py") cj.update_status("Working on the Project Database : bsn", logging = logging) execfile(root + "workflow_lib/bsn_dbase.py") cj.update_status("Working on the Project Database : hru", logging = logging)
def get_distance(x1, y1, z1, x2, y2, z2, epsg_): """ 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]