from landlab import RasterModelGrid
import numpy as np
from landlab.plot.imshow import imshow_grid_at_node
from matplotlib.pyplot import show
%matplotlib inline

mg = RasterModelGrid((10, 10))

"""
Explanation: <a href="http://landlab.github.io"><img style="float: left" src="../../landlab_header.png"></a>
Setting Boundary Conditions: interior rectangle
<hr>
<small>For more Landlab tutorials, click here: <a href="https://landlab.readthedocs.io/en/latest/user_guide/tutorials.html">https://landlab.readthedocs.io/en/latest/user_guide/tutorials.html</a></small>
<hr>

This tutorial illustrates how to modify the boundary conditions of an interior rectangle in the grid if you know the x and y coordinates of the rectangle.
End of explanation
"""


min_x = 2.5
max_x = 5.
min_y = 3.5
max_y = 7.5

"""
Explanation: Known coordinates of rectangle:
End of explanation
"""


x_condition = np.logical_and(mg.x_of_node < max_x, mg.x_of_node > min_x)
y_condition = np.logical_and(mg.y_of_node < max_y, mg.y_of_node > min_y)
my_nodes = np.logical_and(x_condition, y_condition)

"""
Explanation: Define the area inside x and y coordinates:
End of explanation
"""


mg.status_at_node[my_nodes] = mg.BC_NODE_IS_CLOSED

"""
Explanation: Define boundaries as CLOSED:
End of explanation
"""


z = mg.add_zeros('topographic__elevation', at='node')

imshow_grid_at_node(mg, z)

"""
Explanation: Make a new elevation field for display:
End of explanation
"""


