Example #1
0
def ResetErosionRaster():
    DataDirectory = "T://analysis_for_papers//Manny_Idaho//Revised//nested//"
    #DataDirectory = "C://basin_data//Manny_Idaho//nested//"
    ConstFname = "ConstEros.bil"
    NewErateName = "HarringCreek_ERKnown.bil"
    ThisFile = DataDirectory + ConstFname
    NewFilename = DataDirectory + NewErateName

    LSDP.CheckNoData(ThisFile)

    # now print the constant value file
    constant_value = 0.0092
    LSDP.SetToConstantValue(ThisFile, NewFilename, constant_value)

    LSDP.CheckNoData(NewFilename)
def coloured_chans_like_graphs(hillshade_file, tree_file):
    """
    Plots outlines of channels taken from the *.tree file over a hillshade
    giving each channel a unique colour which corresponds to the colours used
    in the Chi plotting routines in chi_visualisation.py.
    
    """
 
    label_size = 20
    #title_size = 30
    axis_size = 28

    
   
    import matplotlib.pyplot as pp
    import numpy as np
    import matplotlib.colors as colors
    import matplotlib.cm as cmx
    from matplotlib import rcParams
    import matplotlib.lines as mpllines
    
    # make sure the nodata is formatted
    LSDP.CheckNoData(hillshade_file)    
    
    #get data
    hillshade = LSDP.ReadRasterArrayBlocks(hillshade_file)
    
    #ignore nodata values    
    hillshade = np.ma.masked_where(hillshade == -9999, hillshade)    

    # now get the extent
    extent_raster = LSDP.GetRasterExtent(hillshade_file)
    
    x_min = extent_raster[0]
    x_max = extent_raster[1]
    y_min = extent_raster[2]
    y_max = extent_raster[3]

    
    #fonts
    rcParams['font.family'] = 'sans-serif'
    rcParams['font.sans-serif'] = ['arial']
    rcParams['font.size'] = label_size  

    #get coordinates of streams from tree file   
    channel_id = []
    row = []
    col = []
        
    with open(tree_file, 'r') as f:
        lines = f.readlines()
        
    for q,line in enumerate(lines):
        if q > 0: #skip first line
            channel_id.append(int(line.split()[0]))
            row.append(float(line.split()[4]))
            col.append(float(line.split()[5]))

    #get bounding box & pad to 10% of the dimension
    x_max = max(col)
    x_min = min(col)
    y_max = max(row)
    y_min = min(row) 
    
    pad_x = (x_max - x_min) * 0.1
    pad_y = (x_max - y_min) * 0.1
    
    if (pad_y > pad_x):
        pad_x = pad_y
    else:
        pad_y = pad_x
    
    x_max += pad_x
    x_min -= pad_x
    y_max += pad_y
    y_min -= pad_y 
    
    fig = pp.figure(1, facecolor='white',figsize=(10,7.5))
    ax = fig.add_subplot(1,1,1)
    ax.imshow(hillshade, vmin=0, vmax=255, cmap=cmx.gray)
    

    # now get the tick marks 
    n_target_tics = 5
    xlocs,ylocs,new_x_labels,new_y_labels = LSDP.GetTicksForUTM(hillshade_file,x_max,x_min,y_max,y_min,n_target_tics)  

    pp.xticks(xlocs, new_x_labels, rotation=60)  #[1:-1] skips ticks where we have no data
    pp.yticks(ylocs, new_y_labels) 
    


    # some formatting to make some of the ticks point outward    
    for line in ax.get_xticklines():
        line.set_marker(mpllines.TICKDOWN)
        #line.set_markeredgewidth(3)

    for line in ax.get_yticklines():
        line.set_marker(mpllines.TICKLEFT)
        #line.set_markeredgewidth(3)  
    
    pp.xlim(x_min,x_max)    
    pp.ylim(y_max,y_min)   
   
    pp.xlabel('Easting (m)',fontsize = axis_size)
    pp.ylabel('Northing (m)', fontsize = axis_size)  
                  
    # channel ID
    Channel_ID_MIN = np.min(channel_id)
    Channel_ID_MAX = np.max(channel_id)
    cNorm_channel_ID  = colors.Normalize(vmin=Channel_ID_MIN, vmax=Channel_ID_MAX)  # the max number of channel segs is the 'top' colour
    jet = pp.get_cmap('jet')
    scalarMap_channel_ID = cmx.ScalarMappable(norm=cNorm_channel_ID, cmap=jet) 
    

    #for a,i in enumerate(reversed(channel_id)):
    for a,i in enumerate(channel_id):
        if i != 0:
            # plot other stream segments
            colorVal = scalarMap_channel_ID.to_rgba(i) # this gets the distinct colour for this segment
            pp.scatter(col[a], row[a], 30,marker=".", color=colorVal,edgecolors='none') 

    for a,i in enumerate(channel_id):
        if i == 0:
            # plot trunk stream in black
            pp.scatter(col[a], row[a], 40,marker=".", color='k',edgecolors='none')
 
    ax.spines['top'].set_linewidth(2.5)
    ax.spines['left'].set_linewidth(2.5)
    ax.spines['right'].set_linewidth(2.5)
    ax.spines['bottom'].set_linewidth(2.5) 
    ax.tick_params(axis='both', width=2.5)     
 
    pp.xlim(x_min,x_max)    
    pp.ylim(y_max,y_min) 
 
    pp.title("Channels colored by channel number",fontsize=label_size)  
    pp.tight_layout()        

    
    
    pp.show()