def run_raster_calc(self):
        msg0 = "Analysis takes a while. \nPython windows seem unresponsive in the meanwhile. \nCheck console messages."
        msg1 = "\n\nClick OK to start DHSI and VHSI calculation."
        showinfo("INFORMATION ", msg0 + msg1)
        hhsi = chsi.HHSI(self.dir_input_ras, self.condition, self.unit)

        hhsi.make_hhsi(self.fish_applied, self.boundary_shp)
        self.top.bell()

        try:
            if not hhsi.error:
                fGl.open_folder(hhsi.path_hsi)
                self.l_run_info.config(fg="forest green", text="RUN SUCCESSFULLY COMPLETED (close window)")
                self.b_run.config(width=30, fg="dark green", bg="PaleGreen1", text="Re-run (generate habitat condition)")
            else:
                self.l_run_info.config(fg="red", text="RUN COMPLETED WITH ERRORS")
                self.b_run.config(bg="salmon", text="Re-run (generate habitat condition)")
        except:
            pass
        msg = "COMPUTATION FINISHED - Check logfile (logfile.log)."
        try:
            hhsi.clear_cache()
            try:
                fGl.rm_dir(hhsi.cache)
            except:
                pass
            msg = str("WARNING: Remove .cache (%s) folder manually \n\n" % str(hhsi.cache)) + msg
        except:
            pass
        showinfo("INFO", msg)
 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 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 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 map_maker(condition, feature_groups, *args):
    # condition = STR for identifying feature input dir
    # feature_group = LIST of feature groups
    # args[0] = alternative input dir
    try:
        mapper = cMp.Mapper(condition, "mlf", args[0])
    except:
        mapper = cMp.Mapper(condition, "mlf")
    mapper.prepare_layout(True, map_items=feature_groups)

    if not mapper.error:
        fGl.open_folder(mapper.output_dir)
 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
예제 #8
0
    def run_raster_calc(self):
        relevant_types = []
        for rt in self.hsi_types.keys():
            if self.hsi_types[rt].get():
                relevant_types.append(rt)

        msg0 = "Analysis takes a while. \nPython windows seem unresponsive in the meanwhile. \nCheck console messages."
        msg1 = "\n\nThe following HSI types will be created:\n - "
        showinfo("INFORMATION ", msg0 + msg1 + "\n - ".join(relevant_types))
        error_occurred = False
        dir_out = ""
        for cov in relevant_types:
            cov_hsi = chsi.CovHSI(self.dir_input_ras, self.condition, cov,
                                  self.unit)
            cov_hsi.make_covhsi(self.fish_applied, self.h_ras_path)
            if cov_hsi.error:
                error_occurred = True
            else:
                dir_out = cov_hsi.path_hsi
            del cov_hsi
            try:
                fGl.clean_dir(
                    os.path.dirname(os.path.realpath(__file__)) + "\\.cache\\")
                try:
                    fGl.rm_dir(cov_hsi.cache)
                except:
                    pass
            except:
                print("WARNING: Could not clean up cache.")
        self.top.bell()
        try:
            if not error_occurred:
                fGl.open_folder(dir_out)
                self.l_run_info.config(fg="forest green",
                                       text="HSI RASTERS SUCCESSFULLY CREATED")
                self.b_run.config(width=30,
                                  bg="pale green",
                                  text="RE-run (generate habitat condition)",
                                  command=lambda: self.run_raster_calc())
            else:
                self.l_run_info.config(fg="red",
                                       text="HSI RASTERS COMPILED WITH ERRORS")
                self.b_run.config(bg="salmon",
                                  text="RE-run (generate habitat condition)",
                                  command=lambda: self.run_raster_calc())
        except:
            pass

        showinfo("COMPUTATION FINISHED", "Check logfile (logfile.log).")
예제 #9
0
    def run_map_maker(self):
        mapper = cMp.Mapper(self.vol_name, "mt", self.dir_ras_vol)
        for ras in self.raster4mapping:
            mapper.prepare_layout(True, map_items=[ras])

        self.master.bell()
        tk.Button(self,
                  width=25,
                  bg="pale green",
                  text="Mapping finished. Click to quit.",
                  command=lambda: self.quit_tab()).grid(sticky=tk.EW,
                                                        row=12,
                                                        column=0,
                                                        columnspan=5,
                                                        padx=self.xd,
                                                        pady=self.yd)
        try:
            if not mapper.error:
                fGl.open_folder(mapper.output_dir)
        except:
            pass
def map_maker(*args, **kwargs):
    # prepares layout of all available rasters in Output folder
    # *args[0] = LIST with (optional) directory for input rasters
    #  args[1] = LIST of reach_IDs
    logger = logging.getLogger("logfile")
    try:
        raster_dirs = args[0]
        logger.info("Raster input directories provided:")
        logger.info("\n ".join(raster_dirs))
    except:
        raster_dirs = [config.dir2map_templates + "rasters\\"]
    reaches = None
    try:
        for k in kwargs.items():
            if "reach_ids" in k[0].lower():
                reach_IDs = k[1]
                reaches = cDef.ReachDefinitions()
                reach_names = []
                [
                    reach_names.append(reaches.dict_id_names[rid])
                    for rid in reach_IDs
                ]
                logger.info("Mapping reach(es):")
                logger.info("\n ".join(reach_names))
    except:
        pass

    for rd in raster_dirs:
        try:
            if "\\" in str(rd):
                condition_new = rd.split("\\")[-2]
            else:
                condition_new = rd.split("/")[-2]
            logger.info("* identified condition = " + str(condition_new))
        except:
            logger.info("WARNING: Invalid raster directory: " + str(rd))
        mapper = cMp.Mapper(condition_new, "lf")
        mapper.prepare_layout(False)

        if reaches:
            reach_reader = cRM.Read(
            )  # define xy map center point s in feet according to mapping_details.xlsx
            for rid in reach_IDs:
                try:
                    reach_extents = reach_reader.get_reach_coordinates(
                        reaches.dict_id_int_id[rid])
                except:
                    reach_extents = "MAXOF"
                for ras in mapper.map_list:
                    mapper.make_pdf_maps(str(ras).split(".tif")[0],
                                         extent=reach_extents)
        else:
            for ras in mapper.map_list:
                mapper.make_pdf_maps(str(ras).split(".tif")[0],
                                     extent='raster')

    try:
        if not mapper.error:
            fGl.open_folder(mapper.output_dir)
    except:
        pass

    return config.dir2map + condition_new + "\\"