def PrintBasins_Complex(DataDirectory,fname_prefix, use_keys_not_junctions = True, show_colourbar = False, Remove_Basins = [], Rename_Basins = {}, Value_dict= {}, cmap = "jet", colorbarlabel = "colourbar", size_format = "ESURF", fig_format = "png", dpi = 250, out_fname_prefix = "", include_channels = False, label_basins = True): """ This function makes a shaded relief plot of the DEM with the basins coloured by the basin ID. Args: DataDirectory (str): the data directory with the m/n csv files fname_prefix (str): The prefix for the m/n csv files use_keys_not_junctions (bool): If true use basin keys to locate basins, otherwise use junction indices show_colourbar (bool): if true show the colourbar Remove_Basins (list): A lists containing either key or junction indices of basins you want to remove from plotting Rename_Basins (dict): A dict where the key is either basin key or junction index, and the value is a new name for the basin denoted by the key Value_dict (dict): A dict where the key is either basin key or junction index, and the value is a value of the basin that is used to colour the basins add_basin_labels (bool): If true, label the basins with text. Otherwise use a colourbar. cmap (str or colourmap): The colourmap to use for the plot cbar_loc (str): where you want the colourbar. Options are none, left, right, top and botton. The colourbar will be of the elevation. If you want only a hillshade set to none and the cmap to "gray" size_format (str): Either geomorphology or big. Anything else gets you a 4.9 inch wide figure (standard ESURF size) fig_format (str): An image format. png, pdf, eps, svg all valid dpi (int): The dots per inch of the figure out_fname_prefix (str): The prefix of the image file. If blank uses the fname_prefix include_channels (bool): If true, adds a channel plot. It uses the chi_data_maps file label_basins (bool): If true, the basins get labels Returns: Shaded relief plot with the basins coloured by basin ID. Uses a colourbar to show each basin. This allows more complex plotting with renamed and excluded basins. Author: FJC, SMM """ #import modules from LSDMapFigure.PlottingRaster import MapFigure # set figure sizes based on format if size_format == "geomorphology": fig_width_inches = 6.25 elif size_format == "big": fig_width_inches = 16 else: fig_width_inches = 4.92126 # get the basin IDs to make a discrete colourmap for each ID BasinInfoDF = PlotHelp.ReadBasinInfoCSV(DataDirectory, fname_prefix) basin_keys = list(BasinInfoDF['basin_key']) basin_keys = [int(x) for x in basin_keys] basin_junctions = list(BasinInfoDF['outlet_junction']) basin_junctions = [float(x) for x in basin_junctions] print ('Basin keys are: ') print (basin_keys) # going to make the basin plots - need to have bil extensions. print("I'm going to make the basin plots. Your topographic data must be in ENVI bil format or I'll break!!") # get the rasters raster_ext = '.bil' #BackgroundRasterName = fname_prefix+raster_ext HillshadeName = fname_prefix+'_hs'+raster_ext BasinsName = fname_prefix+'_AllBasins'+raster_ext # This initiates the figure MF = MapFigure(HillshadeName, DataDirectory,coord_type="UTM_km", colourbar_location="None") # This adds the basins MF.add_basin_plot(BasinsName,fname_prefix,DataDirectory, mask_list = Remove_Basins, rename_dict = Rename_Basins, value_dict = Value_dict, use_keys_not_junctions = use_keys_not_junctions, show_colourbar = show_colourbar, discrete_cmap=True, n_colours=15, colorbarlabel = colorbarlabel, colourmap = cmap, adjust_text = False, label_basins = label_basins) # See if you need the channels if include_channels: print("I am going to add some channels for you") ChannelFileName = fname_prefix+"_chi_data_map.csv" chi_csv_fname = DataDirectory+ChannelFileName thisPointData = LSDMap_PD.LSDMap_PointData(chi_csv_fname) MF.add_point_data(thisPointData,column_for_plotting = "basin_key", scale_points = True,column_for_scaling = "drainage_area", this_colourmap = "Blues_r", scaled_data_in_log = True, max_point_size = 3, min_point_size = 1, discrete_colours = True, NColours = 1, zorder = 5) # Save the image if len(out_fname_prefix) == 0: ImageName = DataDirectory+fname_prefix+"_selected_basins."+fig_format else: ImageName = DataDirectory+out_fname_prefix+"_selected_basins."+fig_format MF.save_fig(fig_width_inches = fig_width_inches, FigFileName = ImageName, FigFormat=fig_format, Fig_dpi = dpi, transparent=True) # Save the figure
basemap_colourmap="gray", plot_title='None', NFF_opti=False, alpha=1) # load and display the background hillslope raster MF.add_basin_plot(RasterName=RasterNameCatch, BasinInfoPrefix=BasinInfoPrefix, Directory=Import_Directory, colourmap="gray", alpha=1, show_colourbar="False", colorbarlabel="Colourbar", discrete_cmap=False, n_colours=10, cbar_type=float, use_keys_not_junctions=True, label_basins=False, adjust_text=False, rename_dict={0: '13'}, value_dict={}, mask_list=[], edgecolour='black', linewidth=2, cbar_dict={}, parallel=False, outlines_only=True, zorder=3) MF.add_point_data( thisPointData=thisPointData, column_for_plotting='m_chi', this_colourmap="rainbow",
def PrintBasins_Complex(DataDirectory, fname_prefix, use_keys_not_junctions=True, show_colourbar=False, Remove_Basins=[], Rename_Basins={}, Value_dict={}, cmap="jet", colorbarlabel="colourbar", size_format="ESURF", fig_format="png", dpi=250, out_fname_prefix="", include_channels=False, label_basins=True): """ This function makes a shaded relief plot of the DEM with the basins coloured by the basin ID. Args: DataDirectory (str): the data directory with the m/n csv files fname_prefix (str): The prefix for the m/n csv files use_keys_not_junctions (bool): If true use basin keys to locate basins, otherwise use junction indices show_colourbar (bool): if true show the colourbar Remove_Basins (list): A lists containing either key or junction indices of basins you want to remove from plotting Rename_Basins (dict): A dict where the key is either basin key or junction index, and the value is a new name for the basin denoted by the key Value_dict (dict): A dict where the key is either basin key or junction index, and the value is a value of the basin that is used to colour the basins add_basin_labels (bool): If true, label the basins with text. Otherwise use a colourbar. cmap (str or colourmap): The colourmap to use for the plot cbar_loc (str): where you want the colourbar. Options are none, left, right, top and botton. The colourbar will be of the elevation. If you want only a hillshade set to none and the cmap to "gray" size_format (str): Either geomorphology or big. Anything else gets you a 4.9 inch wide figure (standard ESURF size) fig_format (str): An image format. png, pdf, eps, svg all valid dpi (int): The dots per inch of the figure out_fname_prefix (str): The prefix of the image file. If blank uses the fname_prefix include_channels (bool): If true, adds a channel plot. It uses the chi_data_maps file label_basins (bool): If true, the basins get labels Returns: Shaded relief plot with the basins coloured by basin ID. Uses a colourbar to show each basin. This allows more complex plotting with renamed and excluded basins. Author: FJC, SMM """ #import modules from LSDMapFigure.PlottingRaster import MapFigure # set figure sizes based on format if size_format == "geomorphology": fig_width_inches = 6.25 elif size_format == "big": fig_width_inches = 16 else: fig_width_inches = 4.92126 # get the basin IDs to make a discrete colourmap for each ID BasinInfoDF = PlotHelp.ReadBasinInfoCSV(DataDirectory, fname_prefix) basin_keys = list(BasinInfoDF['basin_key']) basin_keys = [int(x) for x in basin_keys] basin_junctions = list(BasinInfoDF['outlet_junction']) basin_junctions = [float(x) for x in basin_junctions] print('Basin keys are: ') print(basin_keys) # going to make the basin plots - need to have bil extensions. print( "I'm going to make the basin plots. Your topographic data must be in ENVI bil format or I'll break!!" ) # get the rasters raster_ext = '.bil' #BackgroundRasterName = fname_prefix+raster_ext HillshadeName = fname_prefix + '_hs' + raster_ext BasinsName = fname_prefix + '_AllBasins' + raster_ext # This initiates the figure MF = MapFigure(HillshadeName, DataDirectory, coord_type="UTM_km", colourbar_location="None") # This adds the basins MF.add_basin_plot(BasinsName, fname_prefix, DataDirectory, mask_list=Remove_Basins, rename_dict=Rename_Basins, value_dict=Value_dict, use_keys_not_junctions=use_keys_not_junctions, show_colourbar=show_colourbar, discrete_cmap=True, n_colours=15, colorbarlabel=colorbarlabel, colourmap=cmap, adjust_text=False, label_basins=label_basins) # See if you need the channels if include_channels: print("I am going to add some channels for you") ChannelFileName = fname_prefix + "_chi_data_map.csv" chi_csv_fname = DataDirectory + ChannelFileName thisPointData = LSDMap_PD.LSDMap_PointData(chi_csv_fname) MF.add_point_data(thisPointData, column_for_plotting="basin_key", scale_points=True, column_for_scaling="drainage_area", this_colourmap="Blues_r", scaled_data_in_log=True, max_point_size=3, min_point_size=1, discrete_colours=True, NColours=1, zorder=5) # Save the image if len(out_fname_prefix) == 0: ImageName = DataDirectory + fname_prefix + "_selected_basins." + fig_format else: ImageName = DataDirectory + out_fname_prefix + "_selected_basins." + fig_format MF.save_fig(fig_width_inches=fig_width_inches, FigFileName=ImageName, FigFormat=fig_format, Fig_dpi=dpi, transparent=True) # Save the figure
def ExampleOne_PartFive_MaskBasinsMF(DataDirectory, fname_prefix): """ This function makes a shaded relief plot of the DEM with the basins coloured by the basin ID. Args: DataDirectory (str): the data directory with the m/n csv files fname_prefix (str): The prefix for the m/n csv files Returns: Shaded relief plot with the basins coloured by basin ID Author: SMM """ FigFormat = "png" size_format = "geomorphology" # Set up fonts for plots label_size = 10 rcParams['font.family'] = 'sans-serif' rcParams['font.sans-serif'] = ['arial'] rcParams['font.size'] = label_size # set figure sizes based on format if size_format == "geomorphology": fig_width_inches = 6.25 elif size_format == "big": fig_width_inches = 16 else: fig_width_inches = 4.92126 # going to make the basin plots - need to have bil extensions. print("I'm going to make the basin plots. Your topographic data must be in ENVI bil format or I'll break!!") # get the rasters raster_ext = '.bil' #BackgroundRasterName = fname_prefix+raster_ext HillshadeName = fname_prefix+'_hs'+raster_ext BasinsName = fname_prefix+'_AllBasins'+raster_ext print (BasinsName) # create the map figure # We set colourbar location to none since we are labelling the figures MF = MapFigure(HillshadeName, DataDirectory,coord_type="UTM_km", colourbar_location='bottom',basemap_colourmap = "gray") # add the basins drape #MF.add_drape_image(HillshadeName, DataDirectory, colourmap = cmap, alpha = 0.8, colorbarlabel='Basin ID', discrete_cmap=True, n_colours=len(basin_keys), show_colourbar = False) Remove_Basins = [4,8] Rename_Basins = { 12: 'chumbox', 14: 'zeppo'} Value_dict= { 1: 0.2, 2:0.3, 3:0.4, 5:0.9,6:0.7, 7:0.3, 9:0.5, 10:0.5} MF.add_basin_plot(BasinsName,fname_prefix,DataDirectory, mask_list = Remove_Basins, rename_dict = Rename_Basins, value_dict = Value_dict, use_keys_not_junctions = True, show_colourbar = True, discrete_cmap=True, n_colours=8, colorbarlabel = "$m/n$", colourmap = plt.cm.jet, adjust_text = False) # Save the figure ImageName = DataDirectory+fname_prefix+'_test_Coloured_basins.'+FigFormat MF.save_fig(fig_width_inches = fig_width_inches, FigFileName = ImageName, FigFormat=FigFormat, Fig_dpi = 250)
def ExampleOne_PartFive_MaskBasinsMF(DataDirectory, fname_prefix): """ This function makes a shaded relief plot of the DEM with the basins coloured by the basin ID. Args: DataDirectory (str): the data directory with the m/n csv files fname_prefix (str): The prefix for the m/n csv files Returns: Shaded relief plot with the basins coloured by basin ID Author: SMM """ FigFormat = "png" size_format = "geomorphology" # Set up fonts for plots label_size = 10 rcParams['font.family'] = 'sans-serif' rcParams['font.sans-serif'] = ['Liberation Sans'] rcParams['font.size'] = label_size # set figure sizes based on format if size_format == "geomorphology": fig_width_inches = 6.25 elif size_format == "big": fig_width_inches = 16 else: fig_width_inches = 4.92126 # going to make the basin plots - need to have bil extensions. print("I'm going to make the basin plots. Your topographic data must be in ENVI bil format or I'll break!!") # get the rasters raster_ext = '.bil' #BackgroundRasterName = fname_prefix+raster_ext HillshadeName = fname_prefix+'_hs'+raster_ext BasinsName = fname_prefix+'_AllBasins'+raster_ext print (BasinsName) # create the map figure # We set colourbar location to none since we are labelling the figures MF = MapFigure(HillshadeName, DataDirectory,coord_type="UTM_km", colourbar_location='bottom',basemap_colourmap = "gray") # add the basins drape #MF.add_drape_image(HillshadeName, DataDirectory, colourmap = cmap, alpha = 0.8, colorbarlabel='Basin ID', discrete_cmap=True, n_colours=len(basin_keys), show_colourbar = False) Remove_Basins = [4,8] Rename_Basins = { 12: 'chumbox', 14: 'zeppo'} Value_dict= { 1: 0.2, 2:0.3, 3:0.4, 5:0.9,6:0.7, 7:0.3, 9:0.5, 10:0.5} MF.add_basin_plot(BasinsName,fname_prefix,DataDirectory, mask_list = Remove_Basins, rename_dict = Rename_Basins, value_dict = Value_dict, use_keys_not_junctions = True, show_colourbar = True, discrete_cmap=True, n_colours=8, colorbarlabel = "$m/n$", colourmap = plt.cm.jet, adjust_text = False) # Save the figure ImageName = DataDirectory+fname_prefix+'_test_Coloured_basins.'+FigFormat MF.save_fig(fig_width_inches = fig_width_inches, FigFileName = ImageName, FigFormat=FigFormat, Fig_dpi = 250)
cbar_type=float, NFF_opti=False, custom_min_max=[], zorder=2) MF.add_basin_plot(RasterName=RasterName_NogPal, BasinInfoPrefix=BasinInfoPrefix_NogPal, Directory=Import_Directory, colourmap="gray", alpha=0.2, show_colourbar="False", colorbarlabel="Colourbar", discrete_cmap=False, n_colours=10, cbar_type=float, use_keys_not_junctions=True, label_basins=False, adjust_text=False, rename_dict={0: '13'}, value_dict={}, mask_list=[], edgecolour='black', linewidth=1, cbar_dict={}, parallel=False, outlines_only=True, zorder=3) MF.add_basin_plot(RasterName=RasterName_NogRib, BasinInfoPrefix=BasinInfoPrefix_NogRib, Directory=Import_Directory, colourmap="gray", alpha=0.2,
def main(argv): # If there are no arguments, send to the welcome screen if not len(sys.argv) > 1: full_paramfile = print_welcome() sys.exit() # Get the arguments import argparse parser = argparse.ArgumentParser() # The location of the data files parser.add_argument("-dir", "--base_directory", type=str, help="The base directory. If not defined, current directory.") parser.add_argument("-fname", "--fname_prefix", type=str, help="The prefix of your DEM WITHOUT EXTENSION!") parser.add_argument("-fmt", "--FigFormat", type=str, default='png', help="Set the figure format for the plots. Default is png") args = parser.parse_args() # get the base directory if args.base_directory: DataDirectory = args.base_directory # check if you remembered a / at the end of your path_name if not DataDirectory.endswith("/"): print("You forgot the '/' at the end of the directory, appending...") DataDirectory = this_dir+"/" else: this_dir = os.getcwd() if not args.fname_prefix: print("WARNING! You haven't supplied your DEM name. Please specify this with the flag '-fname'") sys.exit() else: fname_prefix = args.fname_prefix # set to not parallel parallel = False faults = True FigFormat = args.FigFormat # check if a directory exists for the chi plots. If not then make it. raster_directory = DataDirectory+'raster_plots/' if not os.path.isdir(raster_directory): os.makedirs(raster_directory) # Set up fonts for plots label_size = 8 rcParams['font.family'] = 'sans-serif' rcParams['font.sans-serif'] = ['Liberation Sans'] rcParams['font.size'] = label_size # set figure sizes based on format size_format = "" if size_format == "geomorphology": fig_width_inches = 6.25 elif size_format == "big": fig_width_inches = 16 else: fig_width_inches = 4.92126 # get the basin IDs to make a discrete colourmap for each ID BasinInfoDF = Helper.ReadBasinInfoCSV(DataDirectory, fname_prefix) basin_keys = list(BasinInfoDF['basin_key']) basin_keys = [int(x) for x in basin_keys] basin_junctions = list(BasinInfoDF['outlet_junction']) basin_junctions = [int(x) for x in basin_junctions] print("\n\n") print(basin_keys) print(basin_junctions) print("\n\n") # get a discrete colormap cmap = plt.cm.Blues # going to make the basin plots - need to have bil extensions. print("I'm going to make the basin plots. Your topographic data must be in ENVI bil format or I'll break!!") # get the rasters raster_ext = '.bil' BackgroundRasterName = fname_prefix+raster_ext HillshadeName = fname_prefix+'_hs'+raster_ext BasinsName = fname_prefix+'_AllBasins'+raster_ext # create the map figure MF = MapFigure(HillshadeName, DataDirectory,coord_type="UTM_km", colourbar_location='top') # add the basins drape BasinsDict = dict(zip(basin_keys,basin_keys)) MF.add_basin_plot(BasinsName,fname_prefix,DataDirectory, label_basins=False, use_keys_not_junctions = True, show_colourbar = True, value_dict = BasinsDict, discrete_cmap=True, n_colours=len(basin_keys), colorbarlabel = "Basin ID", cbar_type=int, colourmap = cmap, colorbartickthinfactor=2, edgecolour='none', adjust_text = True, parallel=parallel) # add the faults if faults: LineFileName = DataDirectory + fname_prefix + "_faults.shp" MF.add_line_data(LineFileName, linestyle="-", linewidth=1.5, zorder=99, legend=True, label="Fault Segments") # add the basin outlines ### need to parallelise if not parallel: Basins = LSDP.GetBasinOutlines(DataDirectory, BasinsName) else: Basins = LSDP.GetMultipleBasinOutlines(DataDirectory) # Find the relay basins and plot separately RelayBasinIDs = [1248, 4788, 4995, 5185, 6187, 6758, 6805] RelayBasins = {key:value for key, value in Basins.items() if key in RelayBasinIDs} # Plot all basins MF.plot_polygon_outlines(Basins, colour='k', linewidth=0.5, alpha = 1, legend=True, label="Catchments") # Plot relay basins MF.plot_polygon_outlines(RelayBasins, colour='r', linewidth=0.5, alpha = 1, legend=True, label="Relay Catchments") # add the channel network if not parallel: ChannelDF = Helper.ReadChiDataMapCSV(DataDirectory,fname_prefix) else: ChannelDF = Helper.AppendChiDataMapCSVs(DataDirectory) ChannelPoints = LSDP.LSDMap_PointData(ChannelDF, data_type = "pandas", PANDEX = True) MF.add_point_data(ChannelPoints,show_colourbar="False", manual_size=0.5, alpha=0.1,zorder=90, legend=True, label="Stream Network") # Add the legend MF.add_legend() # Save the figure ImageName = raster_directory+fname_prefix+'_basin_keys.'+FigFormat MF.save_fig(fig_width_inches = fig_width_inches, FigFileName = ImageName, FigFormat=FigFormat, Fig_dpi = 300)
def main(argv): # If there are no arguments, send to the welcome screen if not len(sys.argv) > 1: full_paramfile = print_welcome() sys.exit() # Get the arguments import argparse parser = argparse.ArgumentParser() # The location of the data files parser.add_argument("-dir", "--base_directory", type=str, help="The base directory. If not defined, current directory.") parser.add_argument("-fname", "--fname_prefix", type=str, help="The prefix of your DEM WITHOUT EXTENSION!") parser.add_argument("-fmt", "--FigFormat", type=str, default='png', help="Set the figure format for the plots. Default is png") args = parser.parse_args() # get the base directory if args.base_directory: DataDirectory = args.base_directory # check if you remembered a / at the end of your path_name if not DataDirectory.endswith("/"): print("You forgot the '/' at the end of the directory, appending...") DataDirectory = this_dir+"/" else: this_dir = os.getcwd() if not args.fname_prefix: print("WARNING! You haven't supplied your DEM name. Please specify this with the flag '-fname'") sys.exit() else: fname_prefix = args.fname_prefix # set to not parallel parallel = False faults = True FigFormat = args.FigFormat # check if a directory exists for the chi plots. If not then make it. raster_directory = DataDirectory+'raster_plots/' if not os.path.isdir(raster_directory): os.makedirs(raster_directory) # Set up fonts for plots label_size = 8 rcParams['font.family'] = 'sans-serif' rcParams['font.sans-serif'] = ['arial'] rcParams['font.size'] = label_size # set figure sizes based on format size_format = "" if size_format == "geomorphology": fig_width_inches = 6.25 elif size_format == "big": fig_width_inches = 16 else: fig_width_inches = 4.92126 # get the basin IDs to make a discrete colourmap for each ID BasinInfoDF = Helper.ReadBasinInfoCSV(DataDirectory, fname_prefix) basin_keys = list(BasinInfoDF['basin_key']) basin_keys = [int(x) for x in basin_keys] basin_junctions = list(BasinInfoDF['outlet_junction']) basin_junctions = [int(x) for x in basin_junctions] print("\n\n") print(basin_keys) print(basin_junctions) print("\n\n") # get a discrete colormap cmap = plt.cm.Blues # going to make the basin plots - need to have bil extensions. print("I'm going to make the basin plots. Your topographic data must be in ENVI bil format or I'll break!!") # get the rasters raster_ext = '.bil' BackgroundRasterName = fname_prefix+raster_ext HillshadeName = fname_prefix+'_hs'+raster_ext BasinsName = fname_prefix+'_AllBasins'+raster_ext # create the map figure MF = MapFigure(HillshadeName, DataDirectory,coord_type="UTM_km", colourbar_location='top') # add the basins drape BasinsDict = dict(zip(basin_keys,basin_keys)) MF.add_basin_plot(BasinsName,fname_prefix,DataDirectory, label_basins=False, use_keys_not_junctions = True, show_colourbar = True, value_dict = BasinsDict, discrete_cmap=True, n_colours=len(basin_keys), colorbarlabel = "Basin ID", cbar_type=int, colourmap = cmap, colorbartickthinfactor=2, edgecolour='none', adjust_text = True, parallel=parallel) # add the faults if faults: LineFileName = DataDirectory + fname_prefix + "_faults.shp" MF.add_line_data(LineFileName, linestyle="-", linewidth=1.5, zorder=99, legend=True, label="Fault Segments") # add the basin outlines ### need to parallelise if not parallel: Basins = LSDP.GetBasinOutlines(DataDirectory, BasinsName) else: Basins = LSDP.GetMultipleBasinOutlines(DataDirectory) # Find the relay basins and plot separately RelayBasinIDs = [1248, 4788, 4995, 5185, 6187, 6758, 6805] RelayBasins = {key:value for key, value in Basins.items() if key in RelayBasinIDs} # Plot all basins MF.plot_polygon_outlines(Basins, colour='k', linewidth=0.5, alpha = 1, legend=True, label="Catchments") # Plot relay basins MF.plot_polygon_outlines(RelayBasins, colour='r', linewidth=0.5, alpha = 1, legend=True, label="Relay Catchments") # add the channel network if not parallel: ChannelDF = Helper.ReadChiDataMapCSV(DataDirectory,fname_prefix) else: ChannelDF = Helper.AppendChiDataMapCSVs(DataDirectory) ChannelPoints = LSDP.LSDMap_PointData(ChannelDF, data_type = "pandas", PANDEX = True) MF.add_point_data(ChannelPoints,show_colourbar="False", manual_size=0.5, alpha=0.1,zorder=90, legend=True, label="Stream Network") # Add the legend MF.add_legend() # Save the figure ImageName = raster_directory+fname_prefix+'_basin_keys.'+FigFormat MF.save_fig(fig_width_inches = fig_width_inches, FigFileName = ImageName, FigFormat=FigFormat, Fig_dpi = 300)
def PrintChiCoordChannelsAndBasins(DataDirectory, fname_prefix, ChannelFileName, add_basin_labels=True, cmap="cubehelix", cbar_loc="right", size_format="ESURF", fig_format="png", dpi=250, plotting_column="source_key", discrete_colours=False, NColours=10, colour_log=True, colorbarlabel="Colourbar", Basin_remove_list=[], Basin_rename_dict={}, value_dict={}, plot_chi_raster=False, out_fname_prefix="", show_basins=True, min_channel_point_size=0.5, max_channel_point_size=2): """ This function prints a channel map over a hillshade. Args: DataDirectory (str): the data directory with the m/n csv files fname_prefix (str): The prefix for the m/n csv files add_basin_labels (bool): If true, label the basins with text. Otherwise use a colourbar. cmap (str or colourmap): The colourmap to use for the plot cbar_loc (str): where you want the colourbar. Options are none, left, right, top and botton. The colourbar will be of the elevation. If you want only a hillshade set to none and the cmap to "gray" size_format (str): Either geomorphology or big. Anything else gets you a 4.9 inch wide figure (standard ESURF size) fig_format (str): An image format. png, pdf, eps, svg all valid dpi (int): The dots per inch of the figure plotting_column (str): the name of the column to plot discrete_colours (bool): if true use a discrete colourmap NColours (int): the number of colours to cycle through when making the colourmap colour_log (bool): If true the colours are in log scale Basin_remove_list (list): A lists containing either key or junction indices of basins you want to remove from plotting Basin_rename_dict (dict): A dict where the key is either basin key or junction index, and the value is a new name for the basin denoted by the key out_fname_prefix (str): The prefix of the image file. If blank uses the fname_prefix show_basins (bool): If true, plot the basins min_channel_point_size (float): The minimum size of a channel point in points max_channel_point_size (float): The maximum size of a channel point in points Returns: Shaded relief plot with the basins coloured by basin ID. Includes channels. These can be plotted by various metrics denoted but the plotting_column parameter. Author: SMM """ # specify the figure size and format # set figure sizes based on format if size_format == "geomorphology": fig_size_inches = 6.25 elif size_format == "big": fig_size_inches = 16 else: fig_size_inches = 4.92126 ax_style = "Normal" # get the basin IDs to make a discrete colourmap for each ID BasinInfoDF = PlotHelp.ReadBasinInfoCSV(DataDirectory, fname_prefix) basin_keys = list(BasinInfoDF['basin_key']) basin_keys = [int(x) for x in basin_keys] basin_junctions = list(BasinInfoDF['outlet_junction']) basin_junctions = [float(x) for x in basin_junctions] print('Basin keys are: ') print basin_keys # going to make the basin plots - need to have bil extensions. print( "I'm going to make the basin plots. Your topographic data must be in ENVI bil format or I'll break!!" ) # get the rasters raster_ext = '.bil' #BackgroundRasterName = fname_prefix+raster_ext HillshadeName = fname_prefix + '_hs' + raster_ext BasinsName = fname_prefix + '_AllBasins' + raster_ext ChiCoordName = fname_prefix + '_Maskedchi' + raster_ext print(BasinsName) Basins = LSDP.GetBasinOutlines(DataDirectory, BasinsName) chi_csv_fname = DataDirectory + ChannelFileName chi_csv_fname = DataDirectory + ChannelFileName thisPointData = LSDMap_PD.LSDMap_PointData(chi_csv_fname) #thisPointData.ThinDataSelection("basin_key",[10]) thisPointData.selectValue("basin_key", value=Basin_remove_list, operator="!=") #print("The new point data is:") #print(thisPointData.GetLongitude()) # clear the plot plt.clf() # set up the base image and the map print("I am showing the basins without text labels.") MF = MapFigure(HillshadeName, DataDirectory, coord_type="UTM_km", colourbar_location="None") # This adds the basins if plot_chi_raster: if show_basins: MF.add_basin_plot(BasinsName, fname_prefix, DataDirectory, mask_list=Basin_remove_list, rename_dict=Basin_rename_dict, value_dict=value_dict, label_basins=add_basin_labels, show_colourbar=False, colourmap="gray", alpha=1, outlines_only=True) MF.add_drape_image(ChiCoordName, DataDirectory, colourmap="cubehelix", alpha=0.6, zorder=0.5) MF.add_point_data(thisPointData, column_for_plotting=plotting_column, scale_points=True, column_for_scaling="drainage_area", show_colourbar=True, colourbar_location=cbar_loc, colorbarlabel=colorbarlabel, this_colourmap=cmap, scaled_data_in_log=True, max_point_size=max_channel_point_size, min_point_size=min_channel_point_size, zorder=0.4, colour_log=colour_log, discrete_colours=discrete_colours, NColours=NColours) else: if show_basins: MF.add_basin_plot(BasinsName, fname_prefix, DataDirectory, mask_list=Basin_remove_list, rename_dict=Basin_rename_dict, value_dict=value_dict, label_basins=add_basin_labels, show_colourbar=False, colourmap="gray", alpha=0.7, outlines_only=False) MF.add_point_data(thisPointData, column_for_plotting=plotting_column, scale_points=True, column_for_scaling="drainage_area", show_colourbar=True, colourbar_location=cbar_loc, colorbarlabel=colorbarlabel, this_colourmap=cmap, scaled_data_in_log=True, max_point_size=2, min_point_size=0.5, zorder=10, colour_log=colour_log, discrete_colours=discrete_colours, NColours=NColours) # Save the image if len(out_fname_prefix) == 0: ImageName = DataDirectory + fname_prefix + "_chicoord_and_basins." + fig_format else: ImageName = DataDirectory + out_fname_prefix + "_chicoord_and_basins." + fig_format MF.save_fig(fig_width_inches=fig_size_inches, FigFileName=ImageName, axis_style=ax_style, FigFormat=fig_format, Fig_dpi=dpi)
def PrintChiCoordChannelsAndBasins(DataDirectory,fname_prefix, ChannelFileName, add_basin_labels = True, cmap = "cubehelix", cbar_loc = "right", size_format = "ESURF", fig_format = "png", dpi = 250,plotting_column = "source_key",discrete_colours = False, NColours = 10, colour_log = True, colorbarlabel = "Colourbar", Basin_remove_list = [], Basin_rename_dict = {} , value_dict = {}, plot_chi_raster = False, out_fname_prefix = "", show_basins = True, min_channel_point_size = 0.5, max_channel_point_size = 2): """ This function prints a channel map over a hillshade. Args: DataDirectory (str): the data directory with the m/n csv files fname_prefix (str): The prefix for the m/n csv files add_basin_labels (bool): If true, label the basins with text. Otherwise use a colourbar. cmap (str or colourmap): The colourmap to use for the plot cbar_loc (str): where you want the colourbar. Options are none, left, right, top and botton. The colourbar will be of the elevation. If you want only a hillshade set to none and the cmap to "gray" size_format (str): Either geomorphology or big. Anything else gets you a 4.9 inch wide figure (standard ESURF size) fig_format (str): An image format. png, pdf, eps, svg all valid dpi (int): The dots per inch of the figure plotting_column (str): the name of the column to plot discrete_colours (bool): if true use a discrete colourmap NColours (int): the number of colours to cycle through when making the colourmap colour_log (bool): If true the colours are in log scale Basin_remove_list (list): A lists containing either key or junction indices of basins you want to remove from plotting Basin_rename_dict (dict): A dict where the key is either basin key or junction index, and the value is a new name for the basin denoted by the key out_fname_prefix (str): The prefix of the image file. If blank uses the fname_prefix show_basins (bool): If true, plot the basins min_channel_point_size (float): The minimum size of a channel point in points max_channel_point_size (float): The maximum size of a channel point in points Returns: Shaded relief plot with the basins coloured by basin ID. Includes channels. These can be plotted by various metrics denoted but the plotting_column parameter. Author: SMM """ # specify the figure size and format # set figure sizes based on format if size_format == "geomorphology": fig_size_inches = 6.25 elif size_format == "big": fig_size_inches = 16 else: fig_size_inches = 4.92126 ax_style = "Normal" # get the basin IDs to make a discrete colourmap for each ID BasinInfoDF = PlotHelp.ReadBasinInfoCSV(DataDirectory, fname_prefix) basin_keys = list(BasinInfoDF['basin_key']) basin_keys = [int(x) for x in basin_keys] basin_junctions = list(BasinInfoDF['outlet_junction']) basin_junctions = [float(x) for x in basin_junctions] print ('Basin keys are: ') print (basin_keys) # going to make the basin plots - need to have bil extensions. print("I'm going to make the basin plots. Your topographic data must be in ENVI bil format or I'll break!!") # get the rasters raster_ext = '.bil' #BackgroundRasterName = fname_prefix+raster_ext HillshadeName = fname_prefix+'_hs'+raster_ext BasinsName = fname_prefix+'_AllBasins'+raster_ext ChiCoordName = fname_prefix+'_Maskedchi'+raster_ext print (BasinsName) Basins = LSDP.GetBasinOutlines(DataDirectory, BasinsName) chi_csv_fname = DataDirectory+ChannelFileName chi_csv_fname = DataDirectory+ChannelFileName thisPointData = LSDMap_PD.LSDMap_PointData(chi_csv_fname) # Remove data that has nodata values thisPointData.selectValue(plotting_column,value = -9999, operator = "!=") thisPointData.selectValue("basin_key",value = Basin_remove_list, operator = "!=") #print("The new point data is:") #print(thisPointData.GetLongitude()) # clear the plot plt.clf() # set up the base image and the map print("I am showing the basins without text labels.") MF = MapFigure(HillshadeName, DataDirectory,coord_type="UTM_km", colourbar_location="None") # This adds the basins if plot_chi_raster: if show_basins: MF.add_basin_plot(BasinsName,fname_prefix,DataDirectory, mask_list = Basin_remove_list, rename_dict = Basin_rename_dict, value_dict = value_dict, label_basins = add_basin_labels, show_colourbar = False, colourmap = "gray", alpha = 1, outlines_only = True) MF.add_drape_image(ChiCoordName,DataDirectory,colourmap = "cubehelix",alpha=0.6,zorder = 0.5) MF.add_point_data(thisPointData,column_for_plotting = plotting_column,scale_points = True,column_for_scaling = "drainage_area", show_colourbar = True, colourbar_location = cbar_loc,colorbarlabel = colorbarlabel, this_colourmap = cmap,scaled_data_in_log = True,max_point_size = max_channel_point_size, min_point_size = min_channel_point_size,zorder=0.4, colour_log = colour_log, discrete_colours = discrete_colours, NColours = NColours) else: if show_basins: MF.add_basin_plot(BasinsName,fname_prefix,DataDirectory, mask_list = Basin_remove_list, rename_dict = Basin_rename_dict, value_dict = value_dict, label_basins = add_basin_labels, show_colourbar = False, colourmap = "gray", alpha = 0.7, outlines_only = False) MF.add_point_data(thisPointData,column_for_plotting = plotting_column,scale_points = True,column_for_scaling = "drainage_area", show_colourbar = True, colourbar_location = cbar_loc,colorbarlabel = colorbarlabel, this_colourmap = cmap,scaled_data_in_log = True,max_point_size = 2, min_point_size = 0.5,zorder=10, colour_log = colour_log, discrete_colours = discrete_colours, NColours = NColours) # Save the image if len(out_fname_prefix) == 0: ImageName = DataDirectory+fname_prefix+"_chicoord_and_basins."+fig_format else: ImageName = DataDirectory+out_fname_prefix+"_chicoord_and_basins."+fig_format MF.save_fig(fig_width_inches = fig_size_inches, FigFileName = ImageName, axis_style = ax_style, FigFormat=fig_format, Fig_dpi = dpi)