Example #1
0
def test_imshowhs_grid_8():
    """
    Show Layer 1 and Layer 2 over the shaded topographic relief, vmax >10<100
    """
    # %%
    mg = landlab.RasterModelGrid((4, 5))
    _ = mg.add_zeros("topographic__elevation", at="node")
    _ = mg.add_zeros("soil__depth", at="node")
    L1 = mg.add_zeros("Layer_1", at="node")
    L2 = mg.add_zeros("Layer_2", at="node")
    L1[:] += 10
    L2[:] += 100
    _ = landlab.plot.imshowhs_grid(
        mg,
        "topographic__elevation",
        drape1="topographic__elevation",
        drape2="soil__depth",
        plot_type="Drape2",
        var_name="Layer 1",
        var_units=r"m",
        grid_units=("m", "m"),
        cmap="terrain",
        ticks_km=False,
        limits=(0, 2),
        colorbar_label_y=-55,
        add_label_bbox=True,
        thres_drape1=0.001,
        color_for_closed="red",
        thres_drape2=1,
        cmap2=None,
        add_double_colorbar=True,
        vmin=0,
        vmax=99,
    )
Example #2
0
def test_imshowhs_grid_11():
    """
    Show Layer 1 and Layer 2 over the shaded topographic relief
    """
    # %%
    mg = landlab.RasterModelGrid((4, 5))
    _ = mg.add_zeros("topographic__elevation", at="node")
    _ = mg.add_zeros("soil__depth", at="node")
    _ = mg.add_zeros("Layer_1", at="node")
    _ = mg.add_zeros("Layer_2", at="node")
    with pytest.raises(ValueError):
        _ = landlab.plot.imshowhs_grid(
            mg,
            "topographic__elevation",
            plot_type="Drape1",
            var_name="Layer 1",
            var_units=r"m",
            grid_units=("m", "m"),
            cmap="terrain",
            ticks_km=False,
            limits=(0, 2),
            colorbar_label_y=-55,
            add_label_bbox=True,
            thres_drape1=0.001,
        )
Example #3
0
def test_imshowhs_grid_12():
    """
    Test imshowhs without units
    """
    # %%
    mg = landlab.RasterModelGrid((4, 5))
    _ = mg.add_zeros("topographic__elevation", at="node")
    _ = landlab.plot.imshowhs_grid(mg, "topographic__elevation")
Example #4
0
def test_imshowhs_grid_input():
    rmg = landlab.RasterModelGrid((4, 5))
    values = np.arange(rmg.number_of_nodes - 1)
    with pytest.raises(ValueError):
        _ = landlab.plot.imshowhs_grid(rmg,
                                       values,
                                       values_at="node",
                                       limits=(0, 20))
def main():
    mg = ll.RasterModelGrid(20, 30, 1.0)

    nt = 1000

    s = mg.zeros(centering='node')
    g = mg.zeros(centering='active_link')
    divg = mg.zeros(centering='node')

    start_time = time.time()

    for i in range(nt):

        g = mg.calculate_gradients_at_active_links(s, g)

    time1 = time.time()

    for i in range(nt):

        g = mg._calculate_gradients_at_active_links_slow(s, g)

    time2 = time.time()

    for i in range(nt):

        divg = mg.calculate_flux_divergence_at_nodes(g, divg)

    time3 = time.time()

    for i in range(nt):

        divg = mg.calculate_flux_divergence_at_nodes_slow(g, divg)

    time4 = time.time()

    for i in range(nt):

        divg = mg.calculate_flux_divergence_at_active_cells(g)

    time5 = time.time()

    for i in range(nt):

        divg = mg.calculate_flux_divergence_at_active_cells_slow(g)

    time6 = time.time()

    print('Elapsed time with fast gradient algo: ' + str(time1 - start_time))
    print('Elapsed time with slow gradient algo: ' + str(time2 - time1))
    print('Elapsed time with fast node-divergence algo: ' + str(time3 - time2))
    print('Elapsed time with slow node-divergence algo: ' + str(time4 - time3))
    print('Elapsed time with fast activecell-divergence algo: ' +
          str(time5 - time4))
    print('Elapsed time with slow activecell-divergence algo: ' +
          str(time6 - time5))
Example #6
0
def main():
    """
    do some stuff
    """

    # User-defined parameter values
    nr = 5
    nc = 6
    nnodes = nr * nc
    dx = 1
    #instantiate grid
    rg = landlab.RasterModelGrid(nr, nc, dx)
    #rg.set_inactive_boundaries(False, False, True, True)

    nodata_val = 0
    elevations = nodata_val * np.ones(nnodes)
    #set-up interior elevations with random numbers
    #for i in range(0, nnodes):
    #    if rg.is_interior(i):
    #        elevations[i]=random.random_sample()

    #set-up with prescribed elevations to test drainage area calcualtion
    helper = [7, 8, 9, 10, 13, 14, 15, 16]
    elevations[helper] = 2
    helper = [19, 20, 21, 22]
    elevations[helper] = 3
    elevations[7] = 1

    # Get a 2D array version of the elevations
    elev_raster = rg.node_vector_to_raster(elevations, True)

    of = OverlandFlow('input_data.txt', rg, 0)
    rainfall = PrecipitationDistribution()
    rainfall.initialize('input_data.txt')
    rainfall.update

    #for now this is in hours, so put into seconds
    storm_duration = rainfall.storm_duration * 3600
    #in mm/hour, so convert to m/second
    storm_intensity = rainfall.intensity / 1000 / 3600
    print "storm duration, seconds ", storm_duration
    print "storm duration, hours ", rainfall.storm_duration
    print "storm intensity ", storm_intensity

    tau = of.run_one_step(rg, elevations, storm_duration, storm_intensity)
Example #7
0
def test_imshow_grid():
    rmg = landlab.RasterModelGrid(4, 5)

    pp = PdfPages('test.pdf')

    values = np.arange(rmg.number_of_nodes)
    landlab.plot.imshow_grid(rmg, values, values_at='node', limits=(0, 20))
    pp.savefig()

    plt.clf()
    rmg.status_at_node[7] = landlab.CLOSED_BOUNDARY
    values = np.arange(rmg.number_of_cells)
    landlab.plot.imshow_grid(rmg,
                             values,
                             values_at='cell',
                             symmetric_cbar=True)
    pp.savefig()
    pp.close()
Example #8
0
def test_imshow_grid():
    rmg = landlab.RasterModelGrid((4, 5))

    pp = PdfPages("test.pdf")

    values = np.arange(rmg.number_of_nodes)
    landlab.plot.imshow_grid(rmg, values, values_at="node", limits=(0, 20))
    pp.savefig()

    plt.clf()
    rmg.status_at_node[7] = rmg.BC_NODE_IS_CLOSED
    values = np.arange(rmg.number_of_cells)
    landlab.plot.imshow_grid(rmg,
                             values,
                             values_at="cell",
                             symmetric_cbar=True)
    pp.savefig()
    pp.close()
Example #9
0
def test_imshowhs_grid_input_Layer1():
    mg = landlab.RasterModelGrid((4, 5))
    _ = mg.add_zeros("topographic__elevation", at="node")
    values1 = np.arange(mg.number_of_nodes - 1)

    with pytest.raises(ValueError):
        _ = landlab.plot.imshowhs_grid(
            mg,
            "topographic__elevation",
            drape1=values1,
            plot_type="Drape1",
            var_name="Soil",
            var_units=r"m",
            grid_units=("m", "m"),
            cmap="terrain",
            ticks_km=False,
            limits=(0, 2),
        )
Example #10
0
def test_imshowhs_grid_1():
    """
    Show DEM draped over the shaded topographic relief
    """
    # %%
    mg = landlab.RasterModelGrid((4, 5))
    _ = mg.add_zeros("topographic__elevation", at="node")
    _ = landlab.plot.imshowhs_grid(
        mg,
        "topographic__elevation",
        var_name="Topo",
        var_units=r"m",
        grid_units=("m", "m"),
        cmap="terrain",
        ticks_km=False,
        symmetric_cbar=True,
        limits=(0, 10),
    )
Example #11
0
def test_imshowhs_grid_2():
    """
    Show DEM draped over the shaded topographic relief with exaggeration
    """
    # %%
    mg = landlab.RasterModelGrid((4, 5))
    _ = mg.add_zeros("topographic__elevation", at="node")
    _ = landlab.plot.imshowhs_grid(
        mg,
        "topographic__elevation",
        var_name="Topo",
        var_units=r"m",
        grid_units=("m", "m"),
        vertical_exa=2,
        ticks_km=True,
        symmetric_cbar=True,
        vmin=0,
        vmax=10,
    )
Example #12
0
def test_imshowhs_grid_3():
    """
    Show Hillshade
    """
    # %%
    mg = landlab.RasterModelGrid((4, 5))
    _ = mg.add_zeros("topographic__elevation", at="node")
    _ = landlab.plot.imshowhs_grid(
        mg,
        "topographic__elevation",
        plot_type="Hillshade",
        var_name="Topo",
        var_units=r"m",
        grid_units=("m", "m"),
        cmap="terrain",
        ticks_km=False,
        plt_contour=True,
        vmax=10,
        vmin=0,
    )
Example #13
0
def test_imshowhs_grid_4c():
    """
    Show Drape1 draped over the shaded topographic relief with exaggeration
    """
    # %%
    mg = landlab.RasterModelGrid((4, 5))
    _ = mg.add_zeros("topographic__elevation", at="node")
    _ = mg.add_zeros("soil__depth", at="node")
    # Show Soil thickness draped over the shaded topographic relief
    _ = landlab.plot.imshowhs_grid(
        mg,
        "topographic__elevation",
        drape1=mg.at_node["soil__depth"],
        plot_type="Drape1",
        var_name="Soil",
        var_units=r"m",
        grid_units=("m", "m"),
        cmap="terrain",
        ticks_km=False,
        symmetric_cbar=True,
    )
Example #14
0
    def test_imshow_grid(self):
        rmg = landlab.RasterModelGrid(4, 5)

        pp = PdfPages('test.pdf')

        values = np.arange(rmg.number_of_nodes)
        landlab.plot.imshow_grid(rmg, values, values_at='node', limits=(0, 20))
        pp.savefig()

        plt.clf()
        values = np.arange(rmg.number_of_cells)
        landlab.plot.imshow_grid(rmg,
                                 values,
                                 values_at='cell',
                                 symmetric_cbar=True)
        pp.savefig()

        plt.clf()
        values = np.arange(rmg.number_of_cells)
        landlab.plot.imshow_grid(rmg, values, values_at='active_cell')
        pp.savefig()

        pp.close()
Example #15
0
                  help='Run doctests in module [%default]')
parser.add_option('--coverage',
                  action='store_true',
                  dest='coverage',
                  default=False,
                  help='report coverage of landlab [%default]')
parser.add_option('-m',
                  '--mode',
                  action='store',
                  dest='mode',
                  default='fast',
                  help='"fast", "full", or something that can be passed to '
                  'nosetests -A [%default]')

(options, args) = parser.parse_args()

import landlab

landlab.RasterModelGrid(4, 5)

result = landlab.test(label=options.mode,
                      verbose=options.verbose,
                      doctests=options.doctests,
                      coverage=options.coverage,
                      extra_argv=args)

if result.wasSuccessful():
    sys.exit(0)
else:
    sys.exit(1)
Example #16
0
def main():
    mg = ll.RasterModelGrid()
    mg._unit_test()
Example #17
0
        Parameters
        ----------
        (none)
        
        Returns
        -------
        (none)
        
        Creates
        -------
        self.active_link_orientation : 1D numpy array
        
        Notes
        -----
        This overrides the method of the same name in landlab_ca.py.
        """
        self.active_link_orientation = zeros(self.grid.number_of_active_links, dtype=int)
        number_of_vertical_links = self.grid.number_of_node_columns * \
                                        (self.grid.number_of_node_rows-1)
        self.active_link_orientation[:number_of_vertical_links] = 1
    
    
if __name__=='__main__':
    mg = landlab.RasterModelGrid(3, 4, 1.0)
    nsd = {0 : 'yes', 1 : 'no'}
    xnlist = []
    xnlist.append( Transition( (0,1,0), (1,1,0), 1.0, 'frogging' ) )
    nsg = mg.add_zeros('node', 'node_state_grid')
    orlca = OrientedRasterLCA(mg, nsd, xnlist, nsg)
    print orlca.__dict__
Example #18
0
def setup_landlab():

    np_topo_map, np_uplift_map, map_shape = load_np_maps()
    map_width, map_height = map_shape

    # Set up landlab grid
    # For now using a raster grid
    print(f"Setting up Landlab grid")
    mg = lab.RasterModelGrid((map_width, map_height), node_spacing)
    mg.add_field('node', 'topographic__elevation', np_topo_map, units='m')
    mg.add_field('node',
                 'topographic__init_elevation',
                 np_topo_map.copy(),
                 units='m')

    g = mg.calc_grad_at_link('topographic__elevation')
    mg.add_field('link', 'topographic__slope', g)

    # Setup boundaries
    print(f"Setting up boundaries")
    mg.set_closed_boundaries_at_grid_edges(False, False, False, False)
    #mg.set_closed_boundaries_at_grid_edges(True, True, True, True)
    #mg.status_at_node[outlet_node] = mg.BC_NODE_IS_FIXED_VALUE

    # Setup uplift
    print(f"Setting up uplift component")
    mg.add_field('node', 'uplift_map', np_uplift_map, units='m/a')
    uplifter = StaticUplifter(mg)

    # Setup flow router and run it once
    print(f"Setting up flow router component")
    flow_router = lab_components.FlowAccumulator(
        mg,
        flow_director='FlowDirectorD8',
        depression_finder=lab_components.DepressionFinderAndRouter)
    flow_router.run_one_step()
    mg['node']['init_drainage_area'] = mg['node']['drainage_area'].copy()

    # Setup fluvial erosion
    print(f"Setting up fluvial erosion component")
    fluvial = lab_components.FastscapeEroder(mg)
    #fluvial = lab_components.ErosionDeposition(mg)

    # Setup diffusion
    print(f"Setting up diffusion component")
    diffusion = lab_components.LinearDiffuser(mg)

    components = {
        "uplift": uplifter,
        "flow_router": flow_router,
        "fluvial": fluvial,
        "diffusion": diffusion,
    }

    component_order = [
        "uplift",
        "flow_router",
        "fluvial",
        "diffusion",
    ]

    print(f"Finished setting up")
    print()
    return mg, components, component_order