예제 #1
0
def test_raster_model_grid(tmpdir, format):
    grid = RasterModelGrid((4, 3), xy_spacing=(2, 5), xy_of_lower_left=(-2.0, 10.0))
    with tmpdir.as_cwd():
        to_netcdf(grid, "test.nc", format=format)
        actual = from_netcdf("test.nc")
        assert (actual.dx, actual.dy) == (grid.dx, grid.dy)
        assert actual.xy_of_lower_left == grid.xy_of_lower_left
예제 #2
0
def test_stream_power_save_output(tmpdir):

    mg = RasterModelGrid((3, 3), xy_spacing=10.0)
    mg.set_status_at_node_on_edges(
        right=mg.BC_NODE_IS_CLOSED,
        top=mg.BC_NODE_IS_CLOSED,
        left=mg.BC_NODE_IS_CLOSED,
        bottom=mg.BC_NODE_IS_FIXED_VALUE,
    )
    mg.add_ones("node", "topographic__elevation")
    mg.add_zeros("node", "aquifer_base__elevation")
    mg.add_ones("node", "water_table__elevation")

    gdp = GroundwaterDupuitPercolator(mg, recharge_rate=1e-4)
    hm = HydrologySteadyStreamPower(mg, groundwater_model=gdp)
    sp = FastscapeEroder(
        mg,
        K_sp=1e-10,
        m_sp=1,
        n_sp=1,
        discharge_field="surface_water_area_norm__discharge",
    )
    ld = LinearDiffuser(mg, linear_diffusivity=1e-10)
    rm = RegolithConstantThickness(mg, uplift_rate=0.0)

    output = {}
    output["output_interval"] = 1000
    output["output_fields"] = [
        "at_node:topographic__elevation",
        "at_node:aquifer_base__elevation",
        "at_node:water_table__elevation",
    ]
    output["base_output_path"] = tmpdir.strpath + "/"
    output["run_id"] = 0  # make this task_id if multiple runs

    mdl = StreamPowerModel(
        mg,
        hydrology_model=hm,
        diffusion_model=ld,
        erosion_model=sp,
        regolith_model=rm,
        total_morphological_time=1e8,
        output_dict=output,
    )

    mdl.run_model()

    file = tmpdir.join("0_grid_0.nc")
    mg1 = from_netcdf(file.strpath)
    keys = [
        "topographic__elevation",
        "aquifer_base__elevation",
        "water_table__elevation",
    ]
    assert isinstance(mg1, RasterModelGrid)
    assert set(mg1.at_node.keys()) == set(keys)
    assert_equal(mg1.status_at_node, mg.status_at_node)
예제 #3
0
def test_include_keyword_is_empty(tmpdir, format, include):
    grid = RasterModelGrid((4, 3),
                           xy_spacing=(2, 5),
                           xy_of_lower_left=(-2.0, 10.0))
    grid.add_ones("elev", at="node")
    grid.add_zeros("elev", at="link")
    grid.add_empty("temp", at="node")

    with tmpdir.as_cwd():
        to_netcdf(grid, "test.nc", format=format)
        actual = from_netcdf("test.nc", include=include)
        assert len(actual.at_node) == 0
        assert len(actual.at_link) == 0
예제 #4
0
def plot_elev(file, index):
    grid = from_netcdf(file)

    fig = plt.figure(figsize=(8,6))
    imshow_grid(grid,'topographic__elevation', cmap='gist_earth', limits=(0,max(elev)), colorbar_label = 'Elevation [m]', grid_units=('m','m'))
    plt.tight_layout()

    fig.canvas.draw()       # draw the canvas, cache the renderer
    image = np.frombuffer(fig.canvas.tostring_rgb(), dtype='uint8')
    image  = image.reshape(fig.canvas.get_width_height()[::-1] + (3,))

    plt.close()
    return image
예제 #5
0
def test_hex_model_grid(tmpdir, format, orientation, node_layout):
    grid = HexModelGrid(
        shape=(4, 5),
        spacing=2.0,
        xy_of_lower_left=(-3, -5),
        orientation=orientation,
        node_layout=node_layout,
    )
    with tmpdir.as_cwd():
        to_netcdf(grid, "test.nc", format=format)
        actual = from_netcdf("test.nc")

        assert actual.spacing == grid.spacing
        assert actual.xy_of_lower_left == grid.xy_of_lower_left
        assert actual.orientation == grid.orientation
        assert actual.node_layout == grid.node_layout
예제 #6
0
def plot_hillshade(file, index):
    grid = from_netcdf(file)
    elev_plt = grid.at_node['topographic__elevation']
    y = np.arange(grid.shape[0] + 1) * grid.dy - grid.dy * 0.5
    x = np.arange(grid.shape[1] + 1) * grid.dx - grid.dx * 0.5

    ls = LightSource(azdeg=135, altdeg=45)
    fig = plt.figure(figsize=(8,6))
    plt.imshow(ls.hillshade(elev_plt.reshape(grid.shape).T, vert_exag=2, dx=grid.dx, dy=grid.dy), origin="lower", extent=(x[0], x[-1], y[0], y[-1]), cmap='gray')
    plt.tight_layout()

    fig.canvas.draw()       # draw the canvas, cache the renderer
    image = np.frombuffer(fig.canvas.tostring_rgb(), dtype='uint8')
    image  = image.reshape(fig.canvas.get_width_height()[::-1] + (3,))

    plt.close()
    return image
예제 #7
0
    def run_model(self):
        """
        Run StreamPowerModel for full duration specified by total_morphological_time.
        Record elevation change quantiles [0, 10, 50, 90, 100] and mean.
        If output dictionary was provided, record output.
        If output dictionary and steady state condition were provided, record output and stop when steady state condition is met.
        """

        # Run model forward
        for i in tqdm(range(self.N), desc="Completion"):

            self.run_step(self.dt_m, dt_m_max=self.dt_m_max)

            if self.save_output:

                if i % self.output_interval == 0 or i == max(range(self.N)):

                    # save the specified grid fields
                    filename = self.base_path + "%d_grid_%d.nc" % (self.id, i)
                    to_netcdf(
                        self._grid,
                        filename,
                        include=self.output_fields,
                        format="NETCDF4",
                    )

                if self.stop_cond and i % self.output_interval == 0 and i > 0:

                    # check stopping condition
                    filename0 = self.base_path + "%d_grid_%d.nc" % (
                        self.id,
                        i - self.output_interval,
                    )
                    grid0 = from_netcdf(filename0)
                    elev0 = grid0.at_node["topographic__elevation"]
                    dzdt = self.calc_rate_of_change(
                        self._elev, elev0, self.dt_m, self.output_interval
                    )

                    if dzdt < self.stop_rate:
                        self.verboseprint(
                            "Stopping rate condition met, dzdt = %.4e" % dzdt
                        )
                        break
예제 #8
0
    DrainageDensity,
)
from landlab.grid.mappers import map_downwind_node_link_max_to_node
from DupuitLEM.auxiliary_models import HydrologyEventStreamPower

task_id = os.environ['SLURM_ARRAY_TASK_ID']
ID = int(task_id)
base_output_path = os.environ['BASE_OUTPUT_FOLDER']

########## Load and basic plot
grid_files = glob.glob('./data/*.nc')
files = sorted(grid_files, key=lambda x: int(x.split('_')[-1][:-3]))
iteration = int(files[-1].split('_')[-1][:-3])

try:
    grid = from_netcdf(files[-1])
except KeyError:
    grid = read_netcdf(files[-1])
elev = grid.at_node['topographic__elevation']
base = grid.at_node['aquifer_base__elevation']
wt = grid.at_node['water_table__elevation']

# elevation
plt.figure(figsize=(8, 6))
imshow_grid(grid,
            elev,
            cmap='gist_earth',
            colorbar_label='Elevation [m]',
            grid_units=('m', 'm'))
plt.title('ID %d, Iteration %d' % (ID, iteration))
plt.savefig('../post_proc/%s/elev_ID_%d.png' % (base_output_path, ID))
예제 #9
0
ksf = df_params['ksf']
dtg_max = df_params['dtg_max']

output = {}
output["output_interval"] = df_params['output_interval']
output["output_fields"] = [
    "at_node:topographic__elevation",
    "at_node:aquifer_base__elevation",
    "at_node:water_table__elevation",
]
output["base_output_path"] = './data/stoch_sp_nld_svm_'
output["run_id"] = ID  #make this task_id if multiple runs

#initialize grid
try:
    mg = from_netcdf('grid.nc')
    z = mg.at_node['topographic__elevation']
    zb = mg.at_node['aquifer_base__elevation']
    zwt = mg.at_node['water_table__elevation']
    print("Using supplied initial grid")

    grid = RasterModelGrid(mg.shape, xy_spacing=mg.dx)
    grid.set_status_at_node_on_edges(
        right=grid.BC_NODE_IS_CLOSED,
        top=grid.BC_NODE_IS_CLOSED,
        left=grid.BC_NODE_IS_FIXED_VALUE,
        bottom=grid.BC_NODE_IS_CLOSED,
    )
    elev = grid.add_zeros('node', 'topographic__elevation')
    elev[:] = z.copy()
    base = grid.add_zeros('node', 'aquifer_base__elevation')
예제 #10
0
def test_from_grid(datadir, grid_type):
    grid = from_netcdf(datadir / "test-{0}.nc".format(grid_type))
    assert grid.__class__.__name__ == grid_type
    assert_array_equal(grid.at_node["elev"], 1.0)
    assert_array_equal(grid.at_node["temp"], 1.0)
    assert_array_equal(grid.at_link["elev"], 0.0)
예제 #11
0

task_id = os.environ['SLURM_ARRAY_TASK_ID']
ID = int(task_id)
base_output_path = os.environ['BASE_OUTPUT_FOLDER']


grid_files = glob.glob('./data/*.nc')
files = sorted(grid_files, key=lambda x:int(x.split('_')[-1][:-3]))

indices = []
for i in range(len(files)):
    indices.append(int(files[i].split('_')[-1][:-3]))

path = files[-1]
grid = from_netcdf(path)
elev = grid.at_node['topographic__elevation']


def plot_elev(file, index):
    grid = from_netcdf(file)

    fig = plt.figure(figsize=(8,6))
    imshow_grid(grid,'topographic__elevation', cmap='gist_earth', limits=(0,max(elev)), colorbar_label = 'Elevation [m]', grid_units=('m','m'))
    plt.tight_layout()

    fig.canvas.draw()       # draw the canvas, cache the renderer
    image = np.frombuffer(fig.canvas.tostring_rgb(), dtype='uint8')
    image  = image.reshape(fig.canvas.get_width_height()[::-1] + (3,))

    plt.close()