def run_sub_c(self): self.dir2sub_condition = config.dir2conditions + str( self.sub_condition_name.get()) + "\\" if not os.path.exists(self.dir2sub_condition): os.makedirs(self.dir2sub_condition) os.makedirs(config.dir2flows + str(self.sub_condition_name.get())) else: showinfo( "WARNING", "The defined condition already exists and files may be overwritten. Make sure to SAVE IMPORTANT FILE from the existing condition BEFORE CLICKING OK." ) condition = cCC.ConditionCreator(self.dir2sub_condition) condition.create_sub_condition(self.dir2src_condition, self.dir2bound) self.top.bell() try: if not condition.error: fGl.open_folder(self.dir2sub_condition) self.b_create_c.config(fg="forest green", text="Sub-Condition created.") self.l_run_info.config(text="New condition: %s" % self.dir2sub_condition) if str(self.dir2bound).endswith("shp"): msg = "Restart River Architect to create ANOTHER SUBSET (arcpy issue)" self.b_create_c.config(text=msg, fg="MediumOrchid4") else: self.b_create_c.config( fg="red", text="Sub-Condition creation failed (click to re-run).") except: pass
def scan_condition(self): items = self.lb_condition.curselection() self.condition = str( [self.condition_list[int(item)] for item in items][0]) self.dir2condition_act = config.dir2conditions + self.condition # INFO: dir2new_condition may not end with "\\"! if os.path.isfile(self.dir2condition_act + "\\flow_definitions.xlsx"): run = tk.messagebox.askyesno( "Create new?", "%s already exists.\nDo you want to create another flow_definitions.xlsx?" % self.dir2condition_act, parent=self.top) else: run = True if run: condition4flows = cCC.ConditionCreator(self.dir2condition_act) self.flows_xlsx = condition4flows.create_discharge_table() self.l_c_dir.config(fg="forest green", text="Selected: " + self.dir2condition_act) self.b_sc.config(fg="forest green", text="Analyzed") self.b_sct["state"] = "normal" try: if run and not condition4flows.error: msg0 = "Analysis complete.\n" msg1 = "Complete discharge (flood) return periods in the discharges workbook." showinfo("INFO", msg0 + msg1, parent=self.top) fGl.open_file(self.flows_xlsx) if run and condition4flows.error: self.b_sc.config(fg="firebrick3", text="Analysis failed") except: pass
def run_creation(self): self.dir2new_condition = config.dir2conditions + str( self.new_condition_name.get()) + "\\" if not os.path.exists(self.dir2new_condition): os.makedirs(self.dir2new_condition) else: showinfo( "WARNING", "The defined condition already exists and files may be overwritten. Make sure to SAVE IMPORTANT FILES from the existing condition BEFORE CLICKING OK." ) new_condition = cCC.ConditionCreator(self.dir2new_condition) new_condition.transfer_rasters_from_folder(self.dir2h, "h", str(self.str_h.get())) new_condition.transfer_rasters_from_folder(self.dir2u, "u", str(self.str_u.get())) new_condition.save_tif(self.dir2dem, "dem") new_condition.save_tif(self.dir2grains, "dmean") if str(self.dir2va).__len__() > 2: new_condition.transfer_rasters_from_folder(self.dir2va, "va", str(self.str_va.get())) if self.dir2scour.__len__() > 2: new_condition.save_tif(self.dir2scour, "scour") if self.dir2fill.__len__() > 2: new_condition.save_tif(self.dir2fill, "fill") if self.dir2back.__len__() > 2: new_condition.save_tif(self.dir2back, "back") if self.align_rasters.get(): snap_ras = os.path.join(self.dir2new_condition, "back.tif") new_condition.fix_alignment(snap_ras) new_condition.check_alignment(self.dir2new_condition) self.top.bell() try: if new_condition.error: self.l_run_info.config(fg="red", text="Condition creation failed.") elif new_condition.warning: self.l_run_info.config( fg="gold4", text="Condition created with warnings (see logfile).") showwarning( "WARNING", "Input rasters are not properly aligned (see logfile). Rasters can be aligned by inputting a background raster and selecting the checkbox \"Use to align input rasters\", or by using the \"Align Input Rasters\" tool from the GetStarted menu." ) else: fGl.open_folder(self.dir2new_condition) self.l_run_info.config(fg="forest green", text="Condition successfully created.") except: pass msg0 = "Condition created. Next:\n (1) Return to the Main Window and\n (2) Use \'Populate Condition\' to create geomorphic unit, depth to groundwater and detrended DEM rasters." msg1 = "\n\nEnsure that the Rasters are correctly defined in LifespanDesign/.templates/input_definitions.inp." showinfo("INFO", msg0 + msg1, parent=self.top)
def align_rasters(self): ccc = cCC.ConditionCreator( os.path.join(config.dir2conditions, self.condition)) code = ccc.fix_alignment(self.dir2snap) if code == 0: showinfo("INFO", "Rasters aligned successfully.", parent=self.top) else: showinfo( "ERROR", "Errors occurred during raster alignment. See logfile for details.", parent=self.top)
def run_mu(self): condition = cCC.ConditionCreator(self.dir2condition_act) condition.make_mu(self.unit, self.dir2h, self.dir2u) self.top.bell() try: if not condition.error: fGl.open_folder(self.dir2condition_act) self.b_mu.config(fg="forest green", text="mu.tif created.") else: self.b_mu.config(fg="red", text="mu.tif creation failed.") except: pass
def run_det(self): condition = cCC.ConditionCreator(self.dir2condition_act) condition.make_det(self.dir2h, self.dir2dem) self.top.bell() try: if not condition.error: fGl.open_folder(self.dir2condition_act) self.b_det.config(fg="forest green", text="dem_detrend.tif created.") else: self.b_det.config(fg="red", text="dem_detrend.tif creation failed.") except: pass
def run_d2w(self): condition = cCC.ConditionCreator(self.dir2condition_act) condition.make_d2w(self.dir2h, self.dir2dem, method=self.c_interp.get()) self.top.bell() try: if not condition.error: fGl.open_folder(self.dir2condition_act) self.b_d2w.config(fg="forest green", text="d2w.tif created.") else: self.b_d2w.config(fg="red", text="d2w.tif creation failed.") except: pass
def make_flow_duration(self): condition4input = cCC.ConditionCreator(self.dir2condition_act) if not self.flow_series_xlsx: self.select_flow_series_xlsx() flow_duration_xlsx = condition4input.create_flow_duration_table( self.flow_series_xlsx, self.eco_flow_type_applied) try: if not condition4input.error: fGl.open_file(flow_duration_xlsx) self.b_q_dur.config(fg="forest green") else: showinfo("ERROR", "Review error messages (console / logfile.log).", parent=self.top) self.b_q_dur.config(fg="firebrick3", text="Re-try flow duration creation") except: pass
def make_input_file(self): items = self.lb_condition.curselection() # INFO: dir2new_condition may not end with "\\"! condition = str([self.condition_list[int(item)] for item in items][0]) condition4input = cCC.ConditionCreator(config.dir2conditions + condition) condition4input.generate_input_file(config.dir2conditions + condition + "\\flow_definitions.xlsx") try: if not condition4input.error: fGl.open_file(config.dir2conditions + condition + "\\input_definition.inp") self.b_sc.config(fg="forest green") self.l_c_dir.config(fg="forest green", text=config.dir2conditions + condition + "\\input_definition.inp") else: showinfo( "INFO", "Make sure that the flow return periods are defined.") self.b_sc.config(fg="red", text="failed - try again") except: pass