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 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]

    # get a discrete colormap
    cmap = plt.cm.viridis

    # 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='none')

    # 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 = False,
    #                      value_dict = BasinsDict, discrete_cmap=True, n_colours=len(basin_keys),
    #                      colorbarlabel = "Basin ID", cbar_type=int, tickspacefactor=2,
    #                      colourmap = cmap, edgecolour='none', adjust_text = True, parallel=parallel)

    # add the channel network
    if not parallel:
        ChannelDF = Helper.ReadChiDataMapCSV(DataDirectory, fname_prefix)
    else:
        ChannelDF = Helper.AppendChiDataMapCSVs(DataDirectory)

    # remove chi no data values
    ChannelDF = ChannelDF[ChannelDF.chi != -9999]

    ChannelPoints = LSDP.LSDMap_PointData(ChannelDF,
                                          data_type="pandas",
                                          PANDEX=True)

    # add chi map
    MF.add_point_data(ChannelPoints,
                      column_for_plotting="chi",
                      column_for_scaling="chi",
                      colorbarlabel="$\chi$ (m)",
                      show_colourbar=True,
                      this_colourmap=cmap,
                      colourbar_location="top")

    # 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")
    MF.plot_polygon_outlines(RelayBasins,
                             colour='r',
                             linewidth=0.5,
                             alpha=1,
                             legend=True,
                             label="Relay Catchments")

    # Add the legend
    MF.add_legend()

    # Save the figure
    ImageName = raster_directory + fname_prefix + '_chi_map.' + FigFormat
    MF.save_fig(fig_width_inches=fig_width_inches,
                FigFileName=ImageName,
                FigFormat=FigFormat,
                Fig_dpi=300)
def PrintChannelsAndBasins(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 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_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: 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
    print(BasinsName)
    Basins = LSDP.GetBasinOutlines(DataDirectory, BasinsName)

    ChannelFileName = fname_prefix + "_chi_data_map.csv"
    chi_csv_fname = DataDirectory + ChannelFileName

    thisPointData = LSDMap_PD.LSDMap_PointData(chi_csv_fname)

    # 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")
    MF.plot_polygon_outlines(Basins, linewidth=0.8)
    MF.add_drape_image(BasinsName,
                       DataDirectory,
                       colourmap=cmap,
                       alpha=0.1,
                       discrete_cmap=False,
                       n_colours=len(basin_keys),
                       show_colourbar=False,
                       modify_raster_values=True,
                       old_values=basin_junctions,
                       new_values=basin_keys,
                       cbar_type=int)

    MF.add_point_data(thisPointData,
                      column_for_plotting="basin_key",
                      scale_points=True,
                      column_for_scaling="drainage_area",
                      this_colourmap=cmap,
                      scaled_data_in_log=True,
                      max_point_size=3,
                      min_point_size=1)

    # Save the image
    if len(out_fname_prefix) == 0:
        ImageName = DataDirectory + fname_prefix + "_channels_with_basins." + fig_format
    else:
        ImageName = DataDirectory + out_fname_prefix + "_channels_with_basins." + fig_format

    MF.save_fig(fig_width_inches=fig_size_inches,
                FigFileName=ImageName,
                axis_style=ax_style,
                FigFormat=fig_format,
                Fig_dpi=dpi)
Exemple #4
0
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)
Exemple #5
0
def ExampleOne_PartTwo_PrintBasins(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: FJC
    """
    #import modules
    from LSDMapFigure.PlottingRaster import MapFigure

    # Set up fonts for plots
    label_size = 10
    rcParams['font.family'] = 'sans-serif'
    rcParams['font.sans-serif'] = ['Liberation Sans']
    rcParams['font.size'] = label_size
    size_format  = "geomorphology"

    # 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

    # 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
    MF = MapFigure(HillshadeName, DataDirectory,coord_type="UTM_km", colourbar_location='bottom')
    # 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)
    MF.plot_polygon_outlines(Basins, linewidth=0.8)

    FigFormat = "png"
    ImageName = DataDirectory+fname_prefix+'_coloured_basins.'+FigFormat
    MF.save_fig(fig_width_inches = fig_width_inches, FigFileName = ImageName, FigFormat=FigFormat, Fig_dpi = 250) # Save the figure
Exemple #6
0
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)
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)