def MakeRasterLithoBasinMap(DataDirectory, fname_prefix, lname_prefix, lithodict, size_format='ESURF', FigFormat='png', basins=True, m_chi=False, mancol=[], log_scale_river=False, minmax_m_chi=[]): """ This function makes a shaded relief plot of the DEM with lithologic map on the top and basin outline Args: DataDirectory (str): the data directory with the m/n csv files fname_prefix (str): The prefix for the m/n csv files size_format (str): Can be "big" (16 inches wide), "geomorphology" (6.25 inches wide), or "ESURF" (4.92 inches wide) (defualt esurf). FigFormat (str): The format of the figure. Usually 'png' or 'pdf'. If "show" then it calls the matplotlib show() command. Basins (bool): Do you want the basin on top minmax_m_chi (list): define a minimum/maximum for plotting m_chi on the top of litho (at the moment this plot is generated from knickpoint dataset) Returns: Shaded relief plot with the basins coloured by basin ID Author: BG, FJC """ # 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 = 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 raster_ext = '.bil' # get the basin IDs to make a discrete colourmap for each ID if (basins): 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 = [float(x) for x in basin_junctions] print('Basin keys are: ') print(basin_keys) BasinsName = fname_prefix + '_AllBasins.bil' # 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 LithoMap = lname_prefix + raster_ext # create the map figure MF = MapFigure(HillshadeName, DataDirectory, coord_type="UTM_km", colourbar_location='None') MF.add_drape_image(HillshadeName, DataDirectory, NFF_opti=True, custom_min_max=[90, 240], alpha=1) # add the geology drape # MF.add_basin_plot(BasinsName,fname_prefix,DataDirectory, # use_keys_not_junctions = True, show_colourbar = True, # discrete_cmap=True, n_colours=len(basin_keys), colorbarlabel = "Basin ID", # colourmap = cmap, adjust_text = False) # getting the right color now color_map_litho = getLithoColorMap(fname_prefix, DataDirectory) df_litho_size = pd.read_csv(DataDirectory + fname_prefix + "_lithokey.csv") MF.add_drape_image(LithoMap, DataDirectory, colourmap=color_map_litho, alpha=0.6, show_colourbar=False, colorbarlabel="Colourbar", discrete_cmap=False, norm="None", colour_min_max=[0, df_litho_size["rocktype"].max() - 1], modify_raster_values=False, old_values=[], new_values=[], cbar_type=int, NFF_opti=True, custom_min_max=[]) if (basins): # add the basin outlines Basins = LSDP.GetBasinOutlines(DataDirectory, BasinsName) MF.plot_polygon_outlines(Basins, linewidth=0.8) # knickpoints! if (m_chi): ChannelDF = pd.read_csv(DataDirectory + fname_prefix + "_ksnkp_mchi.csv") ChannelPoints = LSDP.LSDMap_PointData(ChannelDF, data_type="pandas", PANDEX=True) MF.add_point_data(ChannelPoints, column_for_plotting='m_chi', show_colourbar=True, scale_points=True, column_for_scaling='drainage_area', alpha=0.5, zorder=100, this_colourmap="RdBu_r", colour_manual_scale=mancol, scaled_data_in_log=log_scale_river, max_point_size=minmax_m_chi[1], min_point_size=minmax_m_chi[0]) else: # add the channel network ChannelDF = Helper.ReadChiDataMapCSV(DataDirectory, fname_prefix) ChannelPoints = LSDP.LSDMap_PointData(ChannelDF, data_type="pandas", PANDEX=True) MF.add_point_data(ChannelPoints, show_colourbar="False", scale_points=True, column_for_scaling='drainage_area', alpha=0.5, zorder=100) if (basins): # add the basin labelling label_dict = dict(zip(basin_junctions, basin_keys)) Points = LSDP.GetPointWithinBasins(DataDirectory, BasinsName) MF.add_text_annotation_from_shapely_points(Points, text_colour='k', label_dict=label_dict, zorder=200) if (basins): # Save the figure ImageName = raster_directory + fname_prefix + '_basin_keys_litho.' + FigFormat else: ImageName = raster_directory + fname_prefix + '_litho.' + FigFormat MF.save_fig(fig_width_inches=fig_width_inches, FigFileName=ImageName, FigFormat=FigFormat, Fig_dpi=500)
def PrintBasins(DataDirectory, fname_prefix, add_basin_labels=True, cmap="jet", cbar_loc="right", size_format="ESURF", fig_format="png", dpi=250, out_fname_prefix=""): """ This function makes a shaded relief plot of the DEM with the basins coloured by the basin ID. IMPORTANT: To get this to run you need to set the flags in chi mapping tool to: write_hillshade: true print_basin_raster: true print_chi_data_maps: true 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_lox (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 Returns: Shaded relief plot with the basins coloured by basin ID. Uses a colourbar to show each basin 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 print(BasinsName) Basins = LSDP.GetBasinOutlines(DataDirectory, BasinsName) # If wanted, add the labels if add_basin_labels: print("I am going to add basin labels, there will be no colourbar.") MF = MapFigure(HillshadeName, DataDirectory, coord_type="UTM_km", colourbar_location="None") MF.plot_polygon_outlines(Basins, linewidth=0.8) MF.add_drape_image(BasinsName, DataDirectory, colourmap=cmap, alpha=0.8, colorbarlabel='Basin ID', discrete_cmap=True, n_colours=len(basin_keys), show_colourbar=False, modify_raster_values=True, old_values=basin_junctions, new_values=basin_keys, cbar_type=int) # This is used to label the basins label_dict = dict(zip(basin_junctions, basin_keys)) # this dict has the basin junction as the key and the basin_key as the value Points = LSDP.GetPointWithinBasins(DataDirectory, BasinsName) MF.add_text_annotation_from_shapely_points(Points, text_colour='k', label_dict=label_dict) else: print("I am showing the basins without text labels.") MF = MapFigure(HillshadeName, DataDirectory, coord_type="UTM_km", colourbar_location=cbar_loc) MF.plot_polygon_outlines(Basins, linewidth=0.8) MF.add_drape_image(BasinsName, DataDirectory, colourmap=cmap, alpha=0.8, colorbarlabel='Basin ID', discrete_cmap=True, n_colours=len(basin_keys), show_colourbar=True, modify_raster_values=True, old_values=basin_junctions, new_values=basin_keys, cbar_type=int) # Save the image if len(out_fname_prefix) == 0: ImageName = DataDirectory + fname_prefix + "_basins." + fig_format else: ImageName = DataDirectory + out_fname_prefix + "_basins." + fig_format MF.save_fig(fig_width_inches=fig_width_inches, FigFileName=ImageName, FigFormat=fig_format, Fig_dpi=dpi) # Save the figure
def ExampleOne_PartFour_MaskBasins(DataDirectory, fname_prefix): """ This function makes a shaded relief plot of the DEM with the basins coloured by the basin ID. It shows how to mask certain basins. Search the function for "Basins_to_mask". 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 """ import numpy as np Basins_to_mask = [0,4,6] FigFormat = "png" size_format = "geomorphology" #import modules # from LSDMapFigure.PlottingRaster import MapFigure # from LSDMapFigure.PlottingRaster import BaseRaster # import LSDPlottingTools.LSDMap_VectorTools as LSDMap_VT # import LSDPlottingTools.LSDMap_PointTools as LSDMap_PT # 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 # 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] # get the junctions to mask key_to_index_dict = dict(zip(basin_keys,basin_junctions)) junctions_to_mask = [] for basin in Basins_to_mask: junctions_to_mask.append( key_to_index_dict[basin]) print("The junctions to mask are") print(junctions_to_mask) print ('Basin keys are: ') print basin_keys print("Let me mask those for you") new_keys = [] for key in basin_keys: if key in Basins_to_mask: new_keys.append(np.nan) else: new_keys.append(key) print("The new keys are: ") print(new_keys) basin_keys = new_keys # get a discrete colormap cmap = plt.cm.jet # 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='none') # add the basins drape MF.add_drape_image(BasinsName, DataDirectory, colourmap = cmap, alpha = 0.8, colorbarlabel='Basin ID', discrete_cmap=True, n_colours=len(basin_keys), show_colourbar = True, modify_raster_values=True, old_values=basin_junctions, new_values=basin_keys, cbar_type = int) # add the basin outlines Basins = LSDP.GetBasinOutlines(DataDirectory, BasinsName) # get rid of the basins that are being masked for junction in junctions_to_mask: del Basins[junction] # note that at this stage the Basins are keyed with the junction index MF.plot_polygon_outlines(Basins, linewidth=0.8) # add the basin labelling label_dict = dict(zip(basin_junctions,basin_keys)) # this dict has the basin junction as the key and the basin_key as the value Points = LSDP.GetPointWithinBasins(DataDirectory, BasinsName) # get rid of points as well for junction in junctions_to_mask: del Points[junction] del label_dict[junction] MF.add_text_annotation_from_shapely_points(Points, text_colour='k', label_dict=label_dict) # Save the figure ImageName = DataDirectory+fname_prefix+'_labelled_basins.'+FigFormat MF.save_fig(fig_width_inches = fig_width_inches, FigFileName = ImageName, FigFormat=FigFormat, Fig_dpi = 250)