예제 #1
0
def plot_recursive_upstream_profiles(elevation, flow_direction, area, outlet, plot_code, downstream = False, start_at = 0.0, figure = None, minimum_area = 1.0E6):
    
    def plot_ld_link(current_length, ld_list, plot_code, downstream_sign, minimum_area):
        (current_row, current_column) = ld_list['index']
        
        if ld_list.get('next') is None:
            return
        for next_list in ld_list['next']:
            
            if next_list['area'] >= minimum_area:
                
                (next_row, next_column) = next_list['index']
                if (current_row != next_row) & (current_column != next_column):
                    next_length = current_length + (ld_list['de'] * 1.414 * downstream_sign)
                else:
                    next_length = current_length + (ld_list['de'] * downstream_sign)
                plt.plot([current_length, next_length], [ld_list['elevation'], next_list['elevation']], plot_code)
                plot_ld_link(next_length, next_list, plot_code, downstream_sign, minimum_area)
                
    mean_pixel_dimension = d.BaseSpatialGrid()
    mean_pixel_dimension._copy_info_from_grid(area, True)
    mean_pixel_dimension._griddata = area._mean_pixel_dimension()
                
    ld_list = flow_direction.map_values_to_recursive_list(outlet, elevation = elevation, area = area, de = mean_pixel_dimension)
    current_length = start_at
    if downstream:
        downstream_sign = 1.0
    else:
        downstream_sign = -1.0
        
    if figure is None:
        figure = plt.figure()
    
    plt.figure(figure.number)
    plot_ld_link(current_length, ld_list, plot_code, downstream_sign, minimum_area)
예제 #2
0
def calculate_ks(prefix, outlet_distance, suffix):
    chi = d.Chi.load(prefix + '_chi_' + outlet_distance + suffix)
    relief = d.ScaledRelief.load(prefix + '_relief_' + outlet_distance +
                                 suffix)
    ks = d.BaseSpatialGrid()
    ks._copy_info_from_grid(relief)
    ks._griddata = np.divide(ks._griddata, chi._griddata)
    ks.save(prefix + '_ks_' + outlet_distance + suffix)
예제 #3
0
def map_chi_profiles(elevation,
                     flow_direction,
                     area,
                     outlet,
                     minimum_area=1.0E6,
                     theta=0.5,
                     start_at=0.0,
                     downstream=True,
                     Ao=1.0E6):

    ((row, col), ) = elevation._xy_to_rowscols((outlet, ))
    base_elevation = elevation[row, col]

    return_map = {}

    def map_ld_link(current_chi, ld_list, downstream_sign, minimum_area):
        (current_row, current_column) = ld_list['index']

        if ld_list.get('next') is None:
            return
        for next_list in ld_list['next']:

            if next_list['area'] >= minimum_area:

                index = next_list['index']
                (next_row, next_column) = index
                if (current_row != next_row) & (current_column != next_column):
                    next_chi = current_chi + (
                        1 / np.array(next_list['area']))**theta * np.array(
                            ld_list['de'] * 1.414 * downstream_sign)
                else:
                    next_chi = current_chi + (
                        1 / np.array(next_list['area']))**theta * np.array(
                            ld_list['de'] * downstream_sign)
                next_elevation = next_list['elevation'] - base_elevation
                return_map[index] = (next_chi, next_elevation)
                map_ld_link(next_chi, next_list, downstream_sign, minimum_area)

    import dem as d
    mean_pixel_dimension = d.BaseSpatialGrid()
    mean_pixel_dimension._copy_info_from_grid(area, True)
    mean_pixel_dimension._griddata = area._mean_pixel_dimension()

    ld_list = flow_direction.map_values_to_recursive_list(
        outlet, elevation=elevation, area=area, de=mean_pixel_dimension)
    current_chi = start_at
    if downstream:
        downstream_sign = 1.0
    else:
        downstream_sign = -1.0

    map_ld_link(current_chi, ld_list, downstream_sign, minimum_area)

    return return_map
예제 #4
0
def plot_chi_profiles(elevation, flow_direction, area, outlet, plot_code, minimum_area = 1.0E6, figure = None, theta = 0.5, start_at = 0.0, downstream = True, Ao = 1.0E6):
    
    ((row, col),) = elevation._xy_to_rowscols((outlet,))
    base_elevation = elevation[row,col]
    
    def plot_ld_link(current_chi, ld_list, plot_code, downstream_sign, minimum_area):
        (current_row, current_column) = ld_list['index']
        
        if ld_list.get('next') is None:
            return
        for next_list in ld_list['next']:
            
            if next_list['area'] >= minimum_area:
                
                (next_row, next_column) = next_list['index']
                if (current_row != next_row) & (current_column != next_column):
                    next_chi = current_chi + (1 / np.array(next_list['area']))**theta * np.array(ld_list['de']*1.414*downstream_sign)
                                        
                else:
                    next_chi = current_chi + (1 / np.array(next_list['area']))**theta * np.array(ld_list['de']*downstream_sign)
                plt.plot([current_chi, next_chi], [(ld_list['elevation'] - base_elevation) * np.power(Ao,theta), (next_list['elevation'] - base_elevation)*np.power(Ao,theta)], plot_code)
                plot_ld_link(next_chi, next_list, plot_code, downstream_sign, minimum_area)
                
    mean_pixel_dimension = d.BaseSpatialGrid()
    mean_pixel_dimension._copy_info_from_grid(area, True)
    mean_pixel_dimension._griddata = area._mean_pixel_dimension()
                
    ld_list = flow_direction.map_values_to_recursive_list(outlet, elevation = elevation, area = area, de = mean_pixel_dimension)
    current_chi = start_at
    if downstream:
        downstream_sign = 1.0
    else:
        downstream_sign = -1.0
        
    if figure is None:
        figure = plt.figure()
    
    plt.figure(figure.number)
    plot_ld_link(current_chi, ld_list, plot_code, downstream_sign, minimum_area)  
예제 #5
0
grid_name = 'gebco_bath_near'
slope_threshold_degrees = 1.0
base_elevation = -300.0

dem = d.Elevation.load(grid_name)

mask1 = d.Mask()
s = d.GeographicMaxSlope(elevation=dem)
threshold_slope = np.tan(slope_threshold_degrees * np.pi / 180.0)
mask1._copy_info_from_grid(dem, True)
mask1.dtype = np.uint8
mask1._griddata = mask1._griddata.astype(np.uint8)
mask1._griddata[np.isnan(dem._griddata)] = 1
mask1._griddata = mask1._griddata + morph.binary_dilation(mask1._griddata)
coast_mask = d.BaseSpatialGrid()
coast_mask._copy_info_from_grid(dem, True)
coast_mask.dtype = np.uint8
coast_mask._griddata = coast_mask._griddata.astype(np.uint8)
coast_mask._griddata[(mask1._griddata == 1)
                     & (dem._griddata >= base_elevation)] = 1
i = np.where(coast_mask._griddata == 1)
rc = zip(i[0].tolist(), i[1].tolist())
outlets = coast_mask._rowscols_to_xy(rc)
mask = d.Mask()
mask._copy_info_from_grid(dem, True)
i = np.where(s._griddata <= threshold_slope)
mask._griddata[i] = 1
shelf = d.PriorityFillGrid(mask=mask, outlets=outlets)
shelf._griddata = morph.binary_fill_holes(shelf._griddata)
예제 #6
0
# Need to implement tiling scheme:

x_beg = range(-180, 160, 20)
y_beg = range(-90, 70, 20)

#x_beg = [-180]
#y_beg = [-90]

for x_s in x_beg:
    for y_s in y_beg:
        extent = [x_s, x_s + 20, y_s, y_s + 20]
        coords = ((x_s, y_s), (x_s + 20, y_s + 20))
        rc_bounds = dem._xy_to_rowscols(coords)
        this_dem = dem.clip_to_extent(extent)
        mask1 = d.BaseSpatialGrid()
        mask2 = d.BaseSpatialGrid()
        s = d.GeographicMaxSlope(elevation=this_dem)
        s.dtype = np.float32
        s._griddata = s._griddata.astype(np.float32)
        threshold_slope = np.tan(slope_threshold_degrees * np.pi / 180.0)
        mask1._copy_info_from_grid(this_dem, True)
        mask1.dtype = np.uint8
        mask1._griddata = mask1._griddata.astype(np.uint8)
        mask1._griddata[np.isnan(this_dem._griddata)] = 1
        mask2._copy_info_from_grid(mask1, False)
        mask2._griddata = morph.binary_dilation(mask2._griddata)
        mask2._griddata = mask1._griddata + mask2._griddata
        coast_mask = d.BaseSpatialGrid()
        coast_mask._copy_info_from_grid(this_dem, True)
        coast_mask.dtype = np.uint8
예제 #7
0
def area_elevation_for_mainstem_and_tributaries(outlet,
                                                flow_direction,
                                                elevation,
                                                area,
                                                theta=0.5,
                                                minimum_area=1.0E7):

    import dem as d
    mean_pixel_dimension = d.BaseSpatialGrid()
    mean_pixel_dimension._copy_info_from_grid(area, True)
    mean_pixel_dimension._griddata = area._mean_pixel_dimension()

    ld_list = flow_direction.map_values_to_recursive_list(
        outlet, elevation=elevation, area=area, de=mean_pixel_dimension)

    area = [ld_list['area']]
    elevation = [ld_list['elevation']]
    de = [ld_list['de'] * ld_list['distance_scale']]
    tributary_ld = []

    def get_elevations_and_areas(ld_list, area, elevation, de, tributary_ld,
                                 minimum_area_to_consider):
        maximum_area = 0.0
        for next in ld_list['next']:
            if (next['area'] > minimum_area_to_consider) and (next['area'] >
                                                              maximum_area):
                maximum_area = next['area']

        for next in ld_list['next']:
            if next['area'] == maximum_area:
                area += [next['area']]
                elevation += [next['elevation']]
                de += [next['de'] * next['distance_scale']]
                (area, elevation, de, tributary_ld) = get_elevations_and_areas(
                    next, area, elevation, de, tributary_ld,
                    minimum_area_to_consider)
            elif next['area'] > minimum_area_to_consider:
                tributary_ld.append(next)
        return (area, elevation, de, tributary_ld)

    (area, elevation, de,
     tributary_ld) = get_elevations_and_areas(ld_list, area, elevation, de,
                                              tributary_ld, minimum_area)

    area = [area]
    elevation = [elevation]
    de = [de]

    while len(tributary_ld) > 0:
        next_tributary_ld = []
        for trb_ld in tributary_ld:
            this_area = [trb_ld['area']]
            this_elevation = [trb_ld['elevation']]
            this_de = [trb_ld['de'] + trb_ld['distance_scale']]
            (this_area, this_elevation, this_de,
             next_tributary_ld) = get_elevations_and_areas(
                 trb_ld, this_area, this_elevation, this_de, next_tributary_ld,
                 minimum_area)
            area.append(this_area)
            elevation.append(this_elevation)
            de.append(this_de)
        tributary_ld = next_tributary_ld

    return_area = []
    return_elevation = []
    return_de = []

    for (this_area, this_elevation, this_de) in zip(area, elevation, de):
        this_return_elevation = []
        this_return_de = []
        this_return_area = []
        for (elevation_value, de_value,
             area_value) in zip(this_elevation, this_de, this_area):
            if elevation_value is not None and de_value is not None and area_value is not None:
                this_return_elevation += [elevation_value - this_elevation[0]]
                this_return_de += [de_value]
                this_return_area += [area_value]

        if len(this_return_elevation) > 4:
            return_elevation.append(this_return_elevation)
            return_de.append(this_return_de)
            return_area.append(this_return_area)

    return (return_area, return_elevation, return_de)
예제 #8
0
slope_mask = d.Mask()
slope_mask._copy_info_from_grid(dem, True)

# Need to implement tiling scheme:

x_beg = range(-180, 160, 20)
y_beg = range(-90, 70, 20)

for x_s in x_beg:
    for y_s in y_beg:
        extent = [x_s, x_s + 20, y_s, y_s + 20]
        coords = ((x_s, y_s), (x_s + 20, y_s + 20))
        rc_bounds = dem._xy_to_rowscols(coords)
        this_dem = dem.clip_to_extent(extent)
        this_shelf = shelf_mask.clip_to_extent(extent)
        shelf_edge = d.BaseSpatialGrid()
        shelf_edge._copy_info_from_grid(this_shelf, True)
        i = np.where(this_shelf._griddata == 1)
        shelf_edge._griddata[i] = 1
        shelf_edge._griddata = shelf_edge._griddata + morph.binary_dilation(
            this_shelf._griddata).astype(np.float64)
        shelf_edge._griddata = shelf_edge._griddata + morph.binary_erosion(
            this_shelf._griddata).astype(np.float64)
        i = np.where((shelf_edge._griddata == 2) & (this_dem._griddata <= -50))
        rc = zip(i[0].tolist(), i[1].tolist())
        outlets = shelf_edge._rowscols_to_xy(rc)

        s = d.GeographicMaxSlope(elevation=this_dem)
        s.dtype = np.float32
        s._griddata = s._griddata.astype(np.float32)
        threshold_slope = np.tan(slope_threshold_degrees * np.pi / 180.0)