def extract_single_river_from_source(): # Here are the different parameters and their default value fr this script default_param = AGPD.get_common_default_param() default_param["already_preprocessed"] = False default_param["X"] = 0 default_param["Y"] = 0 default_param["output_name"] = "Single_River" default_param = AGPD.ingest_param(default_param, sys.argv) if (default_param["help"] or len(sys.argv) == 1): print(""" This command-line tool preprocess your raster to the right format and remove elevation below a threshold, typically the sea. Quick example: lsdtt-extract-single-river file=test_raster.tif X=592149.7 Y=4103817.2 Option available: file: name of the raster (file=name.tif) path: path to the file (default = current folder) already_preprocessed (default = False): Add the keyword if your raster is already preprocessed for flow analysis, False if it needs preprocessing. To get more control on the preprocessing you can use lsdtt-depressions command. X: Easting/X coordinate of the source Y: Easting/Y coordinate of the source output_name (default = Single_River): prefix of the ouput(s) files. Future improvements: - Automatic plotting of base statistic - Adding Chi/ksn/gradient options """) quit() print( "This command-line tool extract a single river from a DEM from the XY coordinates of the source" ) print("Loading the dem") mydem = LSDDEM(file_name=default_param["file"], path=default_param["path"], already_preprocessed=bool( default_param["already_preprocessed"]), verbose=True) if (bool(default_param["already_preprocessed"]) == False): print( "I am preprocessing your dem (carving + filling), if you have already done that, you can save time by adding the option already_preprocessed=True to the command line (it saves time)" ) mydem.PreProcessing() river = pd.DataFrame( mydem.ExtractSingleRiverFromSource(float(default_param["X"]), float(default_param["Y"]))) river.to_csv("%s.csv" % (default_param["output_name"]), index=False)
def concavity_FFS_down_to_top(): # Here are the different parameters and their default value fr this script default_param = AGPD.get_common_default_param() default_param["already_preprocessed"] = False default_param["save_XY_array"] = False default_param["X_source"] = None default_param["Y_source"] = None default_param["min_elevation"] = None default_param["area_threshold"] = None default_param["flow_distance_step"] = None default_param["min_DA"] = None default_param["prefix"] = "" default_param = AGPD.ingest_param(default_param, sys.argv) if (default_param["help"] or len(sys.argv) == 1 or "help" in sys.argv): print(""" This command-line tool run concavity analysis tools from LSDTopoTools. Description of the algorithms in Mudd et al., 2018 -> https://www.earth-surf-dynam.net/6/505/2018/ To use, run the script with relevant options, for example: lsdtt-concavity-down-to-top file=myraster.tif --- option available: file: name of the raster (file=name.tif) path: path to the file (default = current folder) todo help: if written, diplay this message. Documentation soon to be written. """) quit() try: default_param["X_source"] = float(default_param["X_source"]) default_param["Y_source"] = float(default_param["Y_source"]) default_param["min_elevation"] = float(default_param["min_elevation"]) default_param["area_threshold"] = float( default_param["area_threshold"]) default_param["flow_distance_step"] = float( default_param["flow_distance_step"]) default_param["min_DA"] = float(default_param["min_DA"]) except: print(default_param) print( "I struggle to understand your input parameters: make sure I can convert them to number" ) raise SystemExit("I need to quit now") mydem = LSDDEM(file_name=default_param["file"], path=default_param["path"], already_preprocessed=default_param["already_preprocessed"], remove_seas=True, sea_level=default_param["min_elevation"]) if (default_param["already_preprocessed"] == False): print( "I am preprocessing your raster with default options, see lsdtt-depressions for extended options." ) print( "Command line tools can load already processed rasters with the keyword already_preprocessed" ) mydem.PreProcessing() # flwo routines print("Processing flow routines with d8 algorithm") mydem.CommonFlowRoutines() print("Extracting the river") river = mydem.ExtractSingleRiverFromSource(default_param["X_source"], default_param["Y_source"]) river = pd.DataFrame(river) print("Saving teh river to csv file: river_for_concavity.csv") river.to_csv("%sriver_for_concavity.csv" % (default_param["prefix"]), index=False) print("Initialising the concavity analysis") river.sort_values("elevation", inplace=True) river.reset_index(drop=True, inplace=True) # OUtputs global_results = {} outlet_info = { "X": [], "Y": [], "elevation": [], "flow_distance": [], "drainage_area": [] } # potential saving of basins XY_basins = {} flow_distance_this = river["flow_distance"].min() index_this = river["flow_distance"].idxmin() while (flow_distance_this < river["flow_distance"].max() and river["drainage_area"][index_this] > default_param["min_DA"]): print("processing flow distance =", flow_distance_this) del mydem mydem = LSDDEM(file_name="%sdem_for_concavity.tif" % (default_param["prefix"]), already_preprocessed=True, remove_seas=True, sea_level=river["elevation"][index_this] - 5) mydem.CommonFlowRoutines() # mydem.save_array_to_raster_extent(mydem.cppdem.get_DA_raster(), name = "DA", save_directory = "./") mydem.ExtractRiverNetwork( area_threshold_min=default_param["area_threshold"]) # print(river.iloc[index_this]) mydem.DefineCatchment(method="from_XY", X_coords=[river["X"][index_this]], Y_coords=[river["Y"][index_this]], coord_search_radius_nodes=0) mydem.GenerateChi() print(mydem.df_base_river["source_key"].unique()) mydem.cppdem.calculate_movern_disorder(0.05, 0.05, 19, 1, default_param["area_threshold"]) all_disorder = mydem.cppdem.get_best_fits_movern_per_BK() global_results[str(round( river["flow_distance"][index_this], 2))] = np.array( all_disorder[0] ) # [0] means basin 0, which is normal as I only have one outlet_info["X"].append(river["X"][index_this]) outlet_info["Y"].append(river["Y"][index_this]) outlet_info["elevation"].append(river["elevation"][index_this]) outlet_info["flow_distance"].append( round(river["flow_distance"][index_this], 2)) outlet_info["drainage_area"].append(river["drainage_area"][index_this]) # New index flow_distance_this += default_param["flow_distance_step"] index_this = river.index[ river["flow_distance"] >= flow_distance_this].values[0] np.savez("%sdown_to_top_conc.npz" % (default_param["prefix"]), **global_results) pd.DataFrame(outlet_info).to_csv("%sdown_to_top_conc_basin_info.csv" % (default_param["prefix"]), index=False) if (default_param["save_XY_array"]): this_basin = mydem.cppdem.query_xy_for_each_basin()[ 0] # [0] because I want a single basin there print(this_basin) XY_basins[str(round(river["flow_distance"][index_this], 2))] = this_basin np.savez(default_param["prefix"] + "down_to_top_basins_XY.npz", **XY_basins)