def copy_points_to_inputs(proj_path, conflict_points, in_network): """ If the given points are not in the inputs, :param proj_path: The path to the project root :param conflict_points: The path to known points of beaver dam-human conflict :param in_network: the input Conservation Restoration Network :return: Filepath to points in inputs folder """ if proj_path in conflict_points: # The points input is already in our project folder, so we don't need to copy it over return inputs_folder = find_folder(proj_path, "Inputs") conflict_pts_folder = find_folder(inputs_folder, "*[0-9]*_ConflictPoints") if conflict_pts_folder is None: conflict_pts_folder = make_folder( inputs_folder, find_available_num_prefix(inputs_folder) + "_ConflictPoints") new_pts_folder = make_folder( conflict_pts_folder, "Conflict_Points_" + find_available_num_suffix(conflict_pts_folder)) new_conflict_path = os.path.join(new_pts_folder, os.path.basename(conflict_points)) coord_sys = arcpy.Describe(in_network).spatialReference arcpy.Project_management(conflict_points, new_conflict_path, coord_sys) return new_conflict_path
def copy_dams_to_inputs(proj_path, dams, in_network): """ If the given dams are not in the inputs, :param proj_path: The path to the project root :param dams: The path to the given dams :param in_network: the input Conservation Restoration Network :return: Filepath to dams in inputs folder """ if proj_path in dams: # The dams input is already in our project folder, so we don't need to copy it over return inputs_folder = find_folder(proj_path, "Inputs") beaver_dams_folder = find_folder(inputs_folder, "*[0-9]*_BeaverDams") if beaver_dams_folder is None: beaver_dams_folder = make_folder( inputs_folder, find_available_num_prefix(inputs_folder) + "_BeaverDams") new_dam_folder = make_folder( beaver_dams_folder, "Beaver_Dam_" + find_available_num_suffix(beaver_dams_folder)) new_dam_path = os.path.join(new_dam_folder, os.path.basename(dams)) coord_sys = arcpy.Describe(in_network).spatialReference arcpy.Project_management(dams, new_dam_path, coord_sys) return new_dam_path
def make_topo_layers(topo_folder): """ Writes the layers :param topo_folder: We want to make layers for the stuff in this folder :return: """ source_code_folder = os.path.dirname(os.path.abspath(__file__)) symbology_folder = os.path.join(source_code_folder, 'BRATSymbology') dem_symbology = os.path.join(symbology_folder, "DEM.lyr") slope_symbology = os.path.join(symbology_folder, "Slope.lyr") hillshade_symbology = os.path.join(symbology_folder, "Hillshade.lyr") for folder in os.listdir(topo_folder): dem_folder_path = os.path.join(topo_folder, folder) dem_file = None for file_name in os.listdir(dem_folder_path): if file_name.endswith(".tif"): dem_file = os.path.join(dem_folder_path, file_name) make_layer(dem_folder_path, dem_file, "DEM", dem_symbology, is_raster=True) hillshade_folder = make_folder(dem_folder_path, "Hillshade") hillshade_file = os.path.join(hillshade_folder, "Hillshade.tif") try: arcpy.HillShade_3d(dem_file, hillshade_file) make_layer(hillshade_folder, hillshade_file, "Hillshade", hillshade_symbology, is_raster=True) except arcpy.ExecuteError as err: if get_execute_error_code(err) == "000859": arcpy.AddWarning( "Warning: Unable to create hillshade layer. Consider modifying your DEM input if you need a hillshade." ) else: raise arcpy.ExecuteError(err) slope_folder = make_folder(dem_folder_path, "Slope") slope_file = os.path.join(slope_folder, "Slope.tif") try: out_slope = arcpy.sa.Slope(dem_file) out_slope.save(slope_file) make_layer(slope_folder, slope_file, "Slope", slope_symbology, is_raster=True) except arcpy.ExecuteError as err: if get_execute_error_code(err) == "000859": arcpy.AddWarning( "Warning: Unable to create hillshade layer. Consider modifying your DEM input if you need a hillshade." ) else: raise arcpy.ExecuteError(err)
def main(projectRoot, bratPath, demPath, flowAcc, flowDir, horizontalKFN, verticalKFN, fieldCapacity, modflowexe): arcpy.AddMessage("Running BDLoG...") projectFolder = make_folder(projectRoot, "BDWS_Project") inputsFolder = make_folder(projectFolder, "Inputs") outDir = make_folder(projectFolder, "Output") bratCap = 1.0 #proportion (0-1) of maximum estimted dam capacity (from BRAT) for scenario bratPath = copyIntoFolder(bratPath, inputsFolder, "BRAT") demPath = copyIntoFolder(demPath, inputsFolder, "DEM") flowAcc = copyIntoFolder(flowAcc, inputsFolder, "FlowAccumulation") flowDir = copyIntoFolder(flowDir, inputsFolder, "FlowDir") if horizontalKFN: horizontalKFN = copyIntoFolder(horizontalKFN, inputsFolder, "HorizontalKSAT") if verticalKFN: verticalKFN = copyIntoFolder(verticalKFN, inputsFolder, "VerticalKSAT") if fieldCapacity: fieldCapacity = copyIntoFolder(fieldCapacity, inputsFolder, "FieldCapacity") model = BDLoG(bratPath, demPath, flowAcc, outDir, bratCap) #initialize BDLoG, sets varibles and loads inputs model.run() #run BDLoG algorithms model.close() #close any files left open by BDLoG arcpy.AddMessage("bdlog done") #run surface water storage estimation (BDSWEA) idPath = os.path.join(outDir, "damID.tif") #ouput from BDLoG modPoints = os.path.join(outDir, "ModeledDamPoints.shp") #output from BDLoG model = BDSWEA( demPath, flowDir, flowAcc, idPath, outDir, modPoints) #initialize BDSWEA object, sets variables and loads inputs model.run() #run BDSWEA algorithm model.writeModflowFiles() #generate files needed to parameterize MODFLOW model.close() #close any files left open by BDLoG arcpy.AddMessage("bdswea done") if horizontalKFN and verticalKFN and fieldCapacity and modflowexe: #run groundwater storage estimation (MODFLOW) arcpy.AddMessage("Running BDflopy") indir = projectFolder + "/inputs" #location of input raste files modflowOutput = os.path.join( projectFolder, "modflow") #directory to output MODFLOW results kconv = 0.000001 #conversion of hkfn and vkfn to meters per second fconv = 0.01 #conversion of fracfn to a proportion gwmodel = BDflopy( modflowexe, indir, outDir, modflowOutput, demPath) #initialize BDflopy, sets variables and loads inputs gwmodel.run( horizontalKFN, verticalKFN, kconv, fieldCapacity, fconv ) #run BDflopy, this will write inputs for MODFLOW and then run MODFLOW gwmodel.close() #close any open files arcpy.AddMessage("done")
def make_electivity_table(output_network): """ Makes table with totals and electivity indices for modeled capacity categories (i.e., none, rare, occasional, frequent, pervasive) :param output_network: The stream network output by the BRAT model with fields added from capacity tools :return: """ # convert network data to numpy table brat_table = arcpy.da.TableToNumPyArray(output_network, [ 'iGeo_Len', 'e_DamCt', 'mCC_EX_CT', 'e_DamDens', 'oCC_EX', 'ExCategor' ], skip_nulls=True) tot_length = brat_table['iGeo_Len'].sum() tot_surv_dams = brat_table['e_DamCt'].sum() tot_brat_cc = brat_table['mCC_EX_CT'].sum() avg_surv_dens = tot_surv_dams / (tot_length / 1000) avg_brat_dens = tot_brat_cc / (tot_length / 1000) electivity_table = [ '', 'm', 'km', '%', '# of dams', '# of dams', 'dams/km', 'dams/km', '%', '' ] add_electivity_category(brat_table, 'None', electivity_table, tot_length, tot_surv_dams) add_electivity_category(brat_table, 'Rare', electivity_table, tot_length, tot_surv_dams) add_electivity_category(brat_table, 'Occasional', electivity_table, tot_length, tot_surv_dams) add_electivity_category(brat_table, 'Frequent', electivity_table, tot_length, tot_surv_dams) add_electivity_category(brat_table, 'Pervasive', electivity_table, tot_length, tot_surv_dams) electivity_table.append([ 'Total', tot_length, tot_length / 1000, 'NA', tot_surv_dams, tot_brat_cc, avg_surv_dens, avg_brat_dens, tot_surv_dams / tot_brat_cc, 'NA' ]) # set up proper folder structure and save CSV there project_folder = os.path.dirname( os.path.dirname(os.path.dirname(os.path.dirname(output_network)))) summary_folder = make_folder(project_folder, "Summary_Products") tables_folder = make_folder(summary_folder, "SummaryTables") out_csv = os.path.join(tables_folder, 'Electivity_Index.csv') np.savetxt( out_csv, electivity_table, fmt='%s', delimiter=',', header="Segment Type, Stream Length, Stream Length," " % of Drainage Network, Surveyed Dams, BRAT Estimated Capacity," " Average Surveyed Dam Density, Average BRAT Predicted Density," " % of Modeled Capacity, Electivity Index")
def makeLayers(out_network, out_name): """ Writes the layers :param out_network: The output network, which we want to make into a layer :param out_name: The name of the layers :return: """ arcpy.AddMessage("Making layers...") analyses_folder = os.path.dirname(out_network) output_folder = make_folder( analyses_folder, find_available_num(analyses_folder) + "_Capacity") historic_folder = make_folder( output_folder, find_available_num(output_folder) + "_HistoricCapacity") existing_folder = make_folder( output_folder, find_available_num(output_folder) + "_ExistingCapacity") tribCodeFolder = os.path.dirname(os.path.abspath(__file__)) symbologyFolder = os.path.join(tribCodeFolder, 'BRATSymbology') existingCapacityLayer = os.path.join(symbologyFolder, "Existing_Capacity.lyr") historicCapacityLayer = os.path.join(symbologyFolder, "Historic_Capacity.lyr") existingCapacityCountLayer = os.path.join(symbologyFolder, "Existing_Capacity_Count.lyr") historicCapacityCountLayer = os.path.join(symbologyFolder, "Historic_Capacity_Count.lyr") make_layer(existing_folder, out_network, "Existing Dam Building Capacity", existingCapacityLayer, is_raster=False) make_layer(historic_folder, out_network, "Historic Dam Building Capacity", historicCapacityLayer, is_raster=False) make_layer(existing_folder, out_network, "Existing Dam Complex Size", existingCapacityCountLayer, is_raster=False) make_layer(historic_folder, out_network, "Historic Dam Complex Size", historicCapacityCountLayer, is_raster=False)
def copy_multi_input_to_folder(folder_path, multi_input, sub_folder_name, is_raster): """ Copies multi input ArcGIS inputs into the folder that we want them in :param folder_path: The root folder, where we'll put a bunch of sub folders :param multi_input: A string, with paths to the inputs seperated by semicolons :param sub_folder_name: The name for each subfolder (will have a number after it) :param is_raster: Tells us if the thing is a raster or not :return: A list of destinations to every input """ split_input = multi_input.split(";") i = 1 destinations = [] for input_path in split_input: str_i = str(i) if i < 10: str_i = '0' + str_i new_sub_folder = make_folder(folder_path, sub_folder_name + "_" + str_i) destination_path = os.path.join(new_sub_folder, os.path.basename(input_path)) if is_raster: arcpy.CopyRaster_management(input_path, destination_path) else: arcpy.Copy_management(input_path, destination_path) destinations.append(destination_path) i += 1 return destinations
def check_intermediate_layer(intermediates_folder, symbology_folder, symbology_layer_name, brat_table_file, folder_name, layer_name, field_for_layer, layer_file_name=None): """ :param intermediates_folder: The :param symbology_folder: :param symbology_layer_name: :param brat_table_file: :param folder_name: :param layer_name: :param field_for_layer: :param layer_file_name: :return: """ fields = [f.name for f in arcpy.ListFields(brat_table_file)] if field_for_layer not in fields: # we don't want to create the layer if the field isn't in the BRAT table file return if layer_file_name == None: layer_file_name = layer_name.replace(" ", "") layer_symbology = os.path.join(symbology_folder, symbology_layer_name) layer_folder = find_folder(intermediates_folder, folder_name) if layer_folder == None: layer_folder = make_folder(intermediates_folder, find_available_num(intermediates_folder) + "_" + folder_name) layer_path = os.path.join(layer_folder, layer_file_name) if not layer_path.endswith(".lyr"): layer_path += '.lyr' if not os.path.exists(layer_path): make_layer(layer_folder, brat_table_file, layer_name, layer_symbology, file_name=layer_file_name)
def makeLayers(inputNetwork): """ Makes the layers for the modified output :param inputNetwork: The path to the network that we'll make a layer from :return: """ arcpy.AddMessage("Making layers...") intermediates_folder = os.path.dirname(inputNetwork) hydrology_folder_name = find_available_num_prefix( intermediates_folder) + "_Hydrology" hydrology_folder = make_folder(intermediates_folder, hydrology_folder_name) tribCodeFolder = os.path.dirname(os.path.abspath(__file__)) #symbologyFolder = os.path.join(tribCodeFolder, 'BRATSymbology') highflowSymbology = os.path.join(symbologyFolder, "Highflow_StreamPower.lyr") baseflowSymbology = os.path.join(symbologyFolder, "Baseflow_StreamPower.lyr") make_layer(hydrology_folder, inputNetwork, "Highflow Stream Power", highflowSymbology, is_raster=False) make_layer(hydrology_folder, inputNetwork, "Baseflow Stream Power", baseflowSymbology, is_raster=False)
def make_layers(output_network, dams): """ Makes the layers for the modified output :param output_network: The path to the network that we'll make a layer from :param dams: Filepath to dams in the project folder :return: """ arcpy.AddMessage("Making layers...") analysis_folder = os.path.dirname(output_network) validation_folder_name = find_available_num_prefix( analysis_folder) + "_Validation" validation_folder = make_folder(analysis_folder, validation_folder_name) trib_code_folder = os.path.dirname(os.path.abspath(__file__)) symbology_folder = os.path.join(trib_code_folder, 'BRATSymbology') dam_symbology = os.path.join(symbology_folder, "SurveyedBeaverDamLocations.lyr") historic_remaining_symbology = os.path.join( symbology_folder, "PercentofHistoricDamCapacityRemaining.lyr") pred_v_surv_symbology = os.path.join( symbology_folder, "PredictedDamCountvs.SurveyedDamCount.lyr") management_strategies_symbology = os.path.join( symbology_folder, "CurrentBeaverDamManagementStrategies.lyr") occupancy_symbology = os.path.join( symbology_folder, "PercentofExistingCapacityOccupiedbySurveyedDams.lyr") make_layer(validation_folder, output_network, "Percent of Historic Dam Capacity Remaining", historic_remaining_symbology, is_raster=False, symbology_field="mCC_EXvHPE") if dams is not None: make_layer(os.path.dirname(dams), dams, "Surveyed Beaver Dam Locations", dam_symbology, is_raster=False, symbology_field="Snapped") make_layer(validation_folder, output_network, "Predicted Dam Count vs. Surveyed Dam Count", pred_v_surv_symbology, is_raster=False, symbology_field="BRATvSurv") make_layer(validation_folder, output_network, "Current Beaver Dam Management Strategies", management_strategies_symbology, is_raster=False, symbology_field="ConsVRest") make_layer(validation_folder, output_network, "Occupancy Rate of Surveyed Beaver Dams", occupancy_symbology, is_raster=False, symbology_field="e_DamPcC")
def make_layers(input_network): """ Makes the layers for the modified output :param input_network: The path to the network that we'll make a layer from :return: """ arcpy.AddMessage("Making layers...") intermediates_folder = os.path.dirname(input_network) veg_folder_name = find_available_num_prefix( intermediates_folder) + "_VegDamCapacity" veg_folder = make_folder(intermediates_folder, veg_folder_name) trib_code_folder = os.path.dirname(os.path.abspath(__file__)) symbology_folder = os.path.join(trib_code_folder, 'BRATSymbology') existing_veg_symbology = os.path.join( symbology_folder, "ExistingVegDamBuildingCapacity.lyr") historic_veg_symbology = os.path.join( symbology_folder, "HistoricVegDamBuildingCapacity.lyr") make_layer(veg_folder, input_network, "Existing Veg Dam Building Capacity", existing_veg_symbology, is_raster=False) make_layer(veg_folder, input_network, "Historic Veg Dam Building Capacity", historic_veg_symbology, is_raster=False)
def main(proj_path, in_network, max_da_thresh, out_name): """ The main function, runs the combined FIS for the BRAT input table :param proj_path: The path to the project folder for this BRAT run :param in_network: The input BRAT network :param max_da_thresh: The drainage area value above which the stream is assumed to not support dam building :param out_name: The output name for the Combined Capacity Network :return: """ scratch = 'in_memory' output_folder = os.path.dirname(os.path.dirname(in_network)) analyses_folder = make_folder(output_folder, "02_Analyses") if out_name.endswith('.shp'): out_network = os.path.join(analyses_folder, out_name) else: out_network = os.path.join(analyses_folder, out_name + ".shp") if os.path.exists(out_network): arcpy.Delete_management(out_network) arcpy.CopyFeatures_management(in_network, out_network) # run the combined fis function for both potential and existing comb_cap_fis(out_network, 'hpe', scratch, max_da_thresh) comb_cap_fis(out_network, 'ex', scratch, max_da_thresh) make_layers(out_network) add_xml_output(in_network, out_network)
def copyIntoFolder(thingToCopy, copyFolderRoot, copyFolderName): copyFolder = make_folder( copyFolderRoot, find_available_num_prefix(copyFolderRoot) + '_' + copyFolderName) copyPath = os.path.join(copyFolder, os.path.basename(thingToCopy)) arcpy.Copy_management(thingToCopy, copyPath) return copyPath
def make_electivity_table(output_network, out_csv_path): """ Makes table with totals and electivity indices for modeled undesirable dams categories (i.e., negligible, minor, some, considerable) :param output_network: The stream network output by the BRAT model with fields added from capacity tools :return: """ # convert network data to numpy table brat_table = arcpy.da.TableToNumPyArray( output_network, ['iGeo_Len', 'Conf_Ct', 'Conf_Dens', 'oPBRC_UI'], skip_nulls=True) tot_length = brat_table['iGeo_Len'].sum() tot_known_conflict = brat_table['Conf_Ct'].sum() avg_conf_dens = tot_known_conflict / (tot_length / 1000) electivity_table = [[ '', 'm', 'km', '%', '# of incidents', 'incidents/km', '%' ]] add_electivity_category(brat_table, 'Negligible Risk', electivity_table, tot_length, tot_known_conflict) add_electivity_category(brat_table, 'Minor Risk', electivity_table, tot_length, tot_known_conflict) add_electivity_category(brat_table, 'Some Risk', electivity_table, tot_length, tot_known_conflict) add_electivity_category(brat_table, 'Considerable Risk', electivity_table, tot_length, tot_known_conflict) electivity_table.append([ 'Total', tot_length, tot_length / 1000, 'NA', tot_known_conflict, avg_conf_dens, 'NA' ]) # set up proper folder structure and save CSV there project_folder = os.path.dirname( os.path.dirname(os.path.dirname(os.path.dirname(output_network)))) summary_folder = make_folder(project_folder, "Summary_Products") tables_folder = make_folder(summary_folder, "SummaryTables") if out_csv_path is None: out_csv = os.path.join(tables_folder, 'Risk_Table.csv') else: out_csv = out_csv_path np.savetxt(out_csv, electivity_table, fmt='%s', delimiter=',', header="Segment Type, Stream Length, Stream Length," " % of Drainage Network, Known Conflict," " Average Incident Density, % of Incidents")
def observed_v_predicted_plot(output_network): """ Creates plot comparing observed vs predicted. [This is currently unused] :param output_network: The Data Validation Network that was created :return: The filepath to the plot """ x, y = clean_values(output_network) # set up plot fig = plt.figure() fig.add_axes() ax = fig.add_subplot(111) ax.set(title='Predicted vs. Observed Dam Counts (per reach)', xlabel='Predicted Number of Dams', ylabel='Observed Number of Dams') # set axis range if max(x) > max(y): ax.set_xlim(0, round(max(x) + 2), 1) ax.set_ylim(0, round(max(x) + 2), 1) else: ax.set_xlim(0, round(max(y) + 2), 1) ax.set_ylim(0, round(max(y) + 2), 1) # plot data points, regression line, 1:1 reference plot_points(x, y, ax) if len(x) > 1: plot_regression(x, y, ax) else: print "No regression line plotted - only one reach with dams observed" ax.plot([0, 10], [0, 10], color='blue', linewidth=1.5, linestyle=":", label='Line of Perfect Agreement') # add legend legend = plt.legend(loc="upper left", bbox_to_anchor=(1, 1)) # save plot project_folder = os.path.dirname( os.path.dirname(os.path.dirname(os.path.dirname(output_network)))) summary_folder = make_folder(project_folder, "Summary_Products") tables_folder = make_folder(summary_folder, "SummaryTables") plot_name = os.path.join(tables_folder, "Predicted_vs_Expected_Plot.png") plt.savefig(plot_name, bbox_extra_artists=(legend, ), bbox_inches='tight') return plot_name
def make_layers(out_network): """ Writes the layers :param out_network: The output network, which we want to make into a layer :return: """ arcpy.AddMessage("Making layers...") analyses_folder = os.path.dirname(out_network) output_folder = make_folder( analyses_folder, find_available_num_prefix(analyses_folder) + "_Management") trib_code_folder = os.path.dirname(os.path.abspath(__file__)) symbology_folder = os.path.join(trib_code_folder, 'BRATSymbology') strategy_map_symbology = os.path.join( symbology_folder, "StrategiestoPromoteDamBuilding.lyr") limitations_dams_symbology = os.path.join( symbology_folder, "UnsuitableorLimitedDamBuildingOpportunities.lyr") undesirable_dams_symbology = os.path.join(symbology_folder, "RiskofUndesirableDams.lyr") conservation_restoration_symbology = os.path.join( symbology_folder, "BeaverDamConstraintsandOpportunities.lyr") make_layer(output_folder, out_network, "Unsuitable or Limited Dam Building Opportunities", limitations_dams_symbology, is_raster=False, symbology_field='oPBRC_UD') make_layer(output_folder, out_network, "Risk of Undesirable Dams", undesirable_dams_symbology, is_raster=False, symbology_field='oPBRC_UI') make_layer(output_folder, out_network, "Beaver Dam Constraints and Opportunities", conservation_restoration_symbology, is_raster=False, symbology_field='oPBRC_CR') # only try making strategies map layer if 'DamStrat' in fields fields = [f.name for f in arcpy.ListFields(out_network)] if 'DamStrat' in fields: make_layer(output_folder, out_network, "Strategies to Promote Dam Building", strategy_map_symbology, is_raster=False, symbology_field='DamStrat')
def make_optional_input_folder(input, file_path, folder_base_name): """ Creates a folder with correct numbering for optional inputs :param input: The shapefile to go into the folder. If this doesn't exist, then this function will return None. :param file_path: The filepath for the inputs folder where this folder will be created :param folder_base_name: The name of the folder to be created :return: A string that holds the complete file path for the created folder """ if input: new_folder = make_folder( file_path, find_available_num_prefix(file_path) + folder_base_name) return new_folder else: return None
def main(projPath, in_network, max_DA_thresh, out_name): scratch = 'in_memory' output_folder = os.path.dirname(os.path.dirname(in_network)) analyses_folder = make_folder(output_folder, "02_Analyses") if out_name.endswith('.shp'): out_network = os.path.join(analyses_folder, out_name) else: out_network = os.path.join(analyses_folder, out_name + ".shp") if os.path.exists(out_network): arcpy.Delete_management(out_network) arcpy.CopyFeatures_management(in_network, out_network) # run the combined fis function for both potential and existing combFIS(out_network, 'pt', scratch, max_DA_thresh) combFIS(out_network, 'ex', scratch, max_DA_thresh) makeLayers(out_network, out_name) addxmloutput(projPath, in_network, out_network)
def make_layers(input_network): """ Makes the layers for the modified output :param input_network: The path to the network that we'll make a layer from :return: """ arcpy.AddMessage("Making layers...") intermediates_folder = os.path.dirname(input_network) braid_folder_name = find_available_num( intermediates_folder) + "_AnabranchHandler" braid_folder = make_folder(intermediates_folder, braid_folder_name) trib_code_folder = os.path.dirname(os.path.abspath(__file__)) symbology_folder = os.path.join(trib_code_folder, 'BRATSymbology') mainstem_symbology = os.path.join(symbology_folder, "Mainstems.lyr") make_layer(braid_folder, input_network, "Anabranch Types", mainstem_symbology, is_raster=False)
def makeLayers(out_network): """ Writes the layers :param out_network: The output network, which we want to make into a layer :return: """ arcpy.AddMessage("Making layers...") analyses_folder = os.path.dirname(out_network) output_folder = make_folder( analyses_folder, find_available_num(analyses_folder) + "_Management") tribCodeFolder = os.path.dirname(os.path.abspath(__file__)) symbologyFolder = os.path.join(tribCodeFolder, 'BRATSymbology') managementLayer = os.path.join(symbologyFolder, "Beaver_Management_Zones_v2.lyr") managementLayer2 = os.path.join(symbologyFolder, "Dam_Building_Not_Likely.lyr") managementLayer3 = os.path.join( symbologyFolder, "Restoration_Conservation_Opportunities.lyr") make_layer(output_folder, out_network, "Beaver Management Zones", managementLayer, is_raster=False) make_layer(output_folder, out_network, "Unsuitable or Limited Opportunities", managementLayer2, is_raster=False) make_layer(output_folder, out_network, "Restoration or Conservation Opportunities", managementLayer3, is_raster=False)
def main(proj_path, ex_veg, hist_veg, network, DEM, landuse, valley, road, rr, canal, ownership): """Create a BRAT project and populate the inputs""" arcpy.env.overwriteOutput = True arcpy.env.workspace = proj_path if not os.path.exists(proj_path): os.mkdir(proj_path) inputs_folder = make_folder(proj_path, "Inputs") vegetation_folder = make_folder(inputs_folder, "01_Vegetation") network_folder = make_folder(inputs_folder, "02_Network") topo_folder = make_folder(inputs_folder, "03_Topography") anthropogenic_folder = make_folder(inputs_folder, "04_Anthropogenic") ex_veg_folder = make_folder(vegetation_folder, "01_ExistingVegetation") hist_veg_folder = make_folder(vegetation_folder, "02_HistoricVegetation") valley_bottom_folder = make_folder(anthropogenic_folder, "01_ValleyBottom") road_folder = make_folder(anthropogenic_folder, "02_Roads") railroad_folder = make_folder(anthropogenic_folder, "03_Railroads") canals_folder = make_folder(anthropogenic_folder, "04_Canals") land_use_folder = make_folder(anthropogenic_folder, "05_LandUse") land_ownership_folder = make_folder(anthropogenic_folder, "06_LandOwnership") source_code_folder = os.path.dirname(os.path.abspath(__file__)) symbology_folder = os.path.join(source_code_folder, 'BRATSymbology') # Gets all of our symbology variables set up ex_veg_suitability_symbology = os.path.join(symbology_folder, "Existing_Veg_Suitability.lyr") ex_veg_riparian_symbology = os.path.join(symbology_folder, "Existing_Veg_Riparian.lyr") ex_veg_evt_type_symbology = os.path.join(symbology_folder, "Existing_Veg_EVT_Type.lyr") ex_veg_evt_class_symbology = os.path.join(symbology_folder, "Existing_Veg_EVT_Class.lyr") ex_veg_class_name_symbology = os.path.join(symbology_folder, "Existing_Veg_ClassName.lyr") hist_veg_group_symbology = os.path.join(symbology_folder, "Historic_Veg_BPS_Type.lyr") hist_veg_bps_name_symbology = os.path.join(symbology_folder, "Historic_Veg_BPS_Name.lyr") hist_veg_suitability_symbology = os.path.join(symbology_folder, "Historic_Veg_Suitability.lyr") hist_veg_riparian_symbology = os.path.join(symbology_folder, "Historic_Veg_Riparian.lyr") network_symbology = os.path.join(symbology_folder, "Network.lyr") landuse_symbology = os.path.join(symbology_folder, "Land_Use_Raster.lyr") land_ownership_symbology = os.path.join(symbology_folder, "SurfaceManagementAgency.lyr") canals_symbology = os.path.join(symbology_folder, "Canals.lyr") roads_symbology = os.path.join(symbology_folder, "Roads.lyr") railroads_symbology = os.path.join(symbology_folder, "Railroads.lyr") valley_bottom_symbology = os.path.join(symbology_folder, "ValleyBottom.lyr") valley_bottom_outline_symbology = os.path.join(symbology_folder, "ValleyBottom_Outline.lyr") flow_direction_symbology = os.path.join(symbology_folder, "Network_FlowDirection.lyr") # add the existing veg inputs to project ex_veg_destinations = copy_multi_input_to_folder(ex_veg_folder, ex_veg, "Ex_Veg", is_raster=True) make_input_layers(ex_veg_destinations, "Existing Vegetation Suitability for Beaver Dam Building", symbology_layer=ex_veg_suitability_symbology, is_raster=True, file_name="ExVegSuitability") make_input_layers(ex_veg_destinations, "Existing Riparian", symbology_layer=ex_veg_riparian_symbology, is_raster=True, check_field="EVT_PHYS") make_input_layers(ex_veg_destinations, "Veg Type - EVT Type", symbology_layer=ex_veg_evt_type_symbology, is_raster=True, check_field="EVT_PHYS") make_input_layers(ex_veg_destinations, "Veg Type - EVT Class", symbology_layer=ex_veg_evt_class_symbology, is_raster=True) # make_input_layers(ex_veg_destinations, "Veg Type - EVT Class Name", symbology_layer=ex_veg_class_name_symbology, is_raster=True) # add the historic veg inputs to project hist_veg_destinations = copy_multi_input_to_folder(hist_veg_folder, hist_veg, "Hist_Veg", is_raster=True) make_input_layers(hist_veg_destinations, "Historic Vegetation Suitability for Beaver Dam Building", symbology_layer=hist_veg_suitability_symbology, is_raster=True, file_name="HistVegSuitability") make_input_layers(hist_veg_destinations, "Veg Type - BPS Type", symbology_layer=hist_veg_group_symbology, is_raster=True, check_field="GROUPVEG") make_input_layers(hist_veg_destinations, "Veg Type - BPS Name", symbology_layer=hist_veg_bps_name_symbology, is_raster=True) make_input_layers(hist_veg_destinations, "Historic Riparian", symbology_layer=hist_veg_riparian_symbology, is_raster=True, check_field="GROUPVEG") # add the network inputs to project network_destinations = copy_multi_input_to_folder(network_folder, network, "Network", is_raster=False) make_input_layers(network_destinations, "Network", symbology_layer=network_symbology, is_raster=False) make_input_layers(network_destinations, "Flow Direction", symbology_layer=flow_direction_symbology, is_raster=False) # add the DEM inputs to the project copy_multi_input_to_folder(topo_folder, DEM, "DEM", is_raster=True) make_topo_layers(topo_folder) # add landuse raster to the project if landuse is not None: landuse_destinations = copy_multi_input_to_folder(land_use_folder, landuse, "Land_Use", is_raster=True) make_input_layers(landuse_destinations, "Land Use Raster", symbology_layer=landuse_symbology, is_raster=True) # add the conflict inputs to the project if valley is not None: vally_bottom_destinations = copy_multi_input_to_folder(valley_bottom_folder, valley, "Valley", is_raster=False) make_input_layers(vally_bottom_destinations, "Valley Bottom Fill", symbology_layer=valley_bottom_symbology, is_raster=False) make_input_layers(vally_bottom_destinations, "Valley Bottom Outline", symbology_layer=valley_bottom_outline_symbology, is_raster=False) # add road layers to the project if road is not None: road_destinations = copy_multi_input_to_folder(road_folder, road, "Roads", is_raster=False) make_input_layers(road_destinations, "Roads", symbology_layer=roads_symbology, is_raster=False) # add railroad layers to the project if rr is not None: rr_destinations = copy_multi_input_to_folder(railroad_folder, rr, "Railroads", is_raster=False) make_input_layers(rr_destinations, "Railroads", symbology_layer=railroads_symbology, is_raster=False) # add canal layers to the project if canal is not None: canal_destinations = copy_multi_input_to_folder(canals_folder, canal, "Canals", is_raster=False) make_input_layers(canal_destinations, "Canals", symbology_layer=canals_symbology, is_raster=False) # add land ownership layers to the project if ownership is not None: ownership_destinations = copy_multi_input_to_folder(land_ownership_folder, ownership, "Land Ownership", is_raster=False) make_input_layers(ownership_destinations, "Land Ownership", symbology_layer=land_ownership_symbology, is_raster=False)
def main(proj_path, proj_name, huc_ID, watershed_name, ex_veg, hist_veg, network, DEM, landuse, valley, road, rr, canal, ownership, beaver_dams, perennial_stream): """ Gathers inputs and creates folder structure for a BRAT project. :param proj_path: The path to a specific folder. This will be where the folder structure will be created. :param proj_name: If you want the XML to have a project name, enter it here. :param huc_ID: If you want your XML to include information on what HUC you're running BRAT on, enter it here. :param watershed_name: If you want the name of your watershed to be recorded in the XML, enter it here. :param ex_veg: Add all landfire EVT layers that you want to use. :param hist_veg: Add all landfire BPS layers that you want to use. :param network: Add all stream networks that you want to use in BRAT. :param DEM: Add all DEMs that you want to use in BRAT. :param landuse: Add all land use rasters that you want to use in your BRAT runs. :param valley: Add all valley bottom polygons that you want to use in your BRAT runs. :param road: Add all road shapefiles that you want to use in your BRAT runs. :param rr: Add all railroad shapefiles that you want to use in your BRAT runs. :param canal: Add all canal shapefiles that you want to use in your BRAT runs. :param ownership: If you have land ownership shapefiles, add them here. :param beaver_dams: If you want to compare BRAT results to beaver dam survey data, add those files here. :param perennial_stream: If you want to use perennial streams for future tools, add them here. :return: """ arcpy.env.overwriteOutput = True arcpy.env.workspace = proj_path if ownership == "None": ownership = None if beaver_dams == "None": beaver_dams = None if perennial_stream == "None": perennial_stream = None if not os.path.exists(proj_path): os.mkdir(proj_path) # build folder structure in project path inputs_folder = make_folder(proj_path, "Inputs") vegetation_folder = make_folder(inputs_folder, "01_Vegetation") network_folder = make_folder(inputs_folder, "02_Network") topo_folder = make_folder(inputs_folder, "03_Topography") anthropogenic_folder = make_folder(inputs_folder, "04_Anthropogenic") perennial_stream_folder = make_optional_input_folder( perennial_stream, inputs_folder, "_PerennialStream") beaver_dam_folder = make_optional_input_folder(beaver_dams, inputs_folder, "_BeaverDams") ex_veg_folder = make_folder(vegetation_folder, "01_ExistingVegetation") hist_veg_folder = make_folder(vegetation_folder, "02_HistoricVegetation") valley_bottom_folder = make_optional_input_folder(valley, anthropogenic_folder, "_ValleyBottom") road_folder = make_optional_input_folder(road, anthropogenic_folder, "_Roads") railroad_folder = make_optional_input_folder(rr, anthropogenic_folder, "_Railroads") canals_folder = make_optional_input_folder(canal, anthropogenic_folder, "_Canals") land_use_folder = make_optional_input_folder(landuse, anthropogenic_folder, "_LandUse") land_ownership_folder = make_optional_input_folder(ownership, anthropogenic_folder, "_LandOwnership") # add the existing veg inputs to project ex_veg_destinations = copy_multi_input_to_folder(ex_veg_folder, ex_veg, "Ex_Veg", is_raster=True) # add the historic veg inputs to project hist_veg_destinations = copy_multi_input_to_folder(hist_veg_folder, hist_veg, "Hist_Veg", is_raster=True) # add the network inputs to project network_destinations = copy_multi_input_to_folder(network_folder, network, "Network", is_raster=False) # add the DEM inputs to the project dem_destinations = copy_multi_input_to_folder(topo_folder, DEM, "DEM", is_raster=True) # add landuse raster to the project landuse_destinations = [] if landuse is not None: landuse_destinations = copy_multi_input_to_folder(land_use_folder, landuse, "Land_Use", is_raster=True) # add the conflict inputs to the project valley_bottom_destinations = [] if valley is not None: valley_bottom_destinations = copy_multi_input_to_folder( valley_bottom_folder, valley, "Valley", is_raster=False) # add road layers to the project road_destinations = [] if road is not None: road_destinations = copy_multi_input_to_folder(road_folder, road, "Roads", is_raster=False) # add railroad layers to the project rr_destinations = [] if rr is not None: rr_destinations = copy_multi_input_to_folder(railroad_folder, rr, "Railroads", is_raster=False) # add canal layers to the project canal_destinations = [] if canal is not None: canal_destinations = copy_multi_input_to_folder(canals_folder, canal, "Canals", is_raster=False) # add land ownership layers to the project ownership_destinations = [] if ownership is not None: ownership_destinations = copy_multi_input_to_folder( land_ownership_folder, ownership, "Land_Ownership", is_raster=False) # add perennial stream layers to the project perennial_stream_destinations = [] if perennial_stream is not None: perennial_stream_destinations = copy_multi_input_to_folder( perennial_stream_folder, perennial_stream, "PerennialStream", is_raster=False) # add beaver dam layers to the project beaver_dams_destinations = [] if beaver_dams is not None: beaver_dams_destinations = copy_multi_input_to_folder( beaver_dam_folder, beaver_dams, "Beaver_Dam", is_raster=False) # write XML with project metadata write_xml(proj_path, proj_name, huc_ID, watershed_name, ex_veg_destinations, hist_veg_destinations, network_destinations, dem_destinations, landuse_destinations, valley_bottom_destinations, road_destinations, rr_destinations, canal_destinations, ownership_destinations, beaver_dams_destinations, perennial_stream_destinations) # make layers for all input data try: make_layers(ex_veg_destinations, hist_veg_destinations, network_destinations, topo_folder, landuse_destinations, valley_bottom_destinations, road_destinations, rr_destinations, canal_destinations, ownership_destinations, perennial_stream_destinations) except arcpy.ExecuteError as err: if err[0][6:12] == "000873": arcpy.AddError(err) arcpy.AddMessage( "The error above prevented us from creating layers") else: raise arcpy.ExecuteError(err)