-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into mcflugen/at-keyword-for-imshow
- Loading branch information
Showing
8 changed files
with
172 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
from .imshow import imshow_grid, imshow_grid_at_node | ||
from .imshowhs import imshowhs_grid, imshowhs_grid_at_node | ||
from .network_sediment_transporter import plot_network_and_parcels | ||
from .graph import plot_graph | ||
from .layers import plot_layers | ||
|
||
|
||
__all__ = [ | ||
"imshow_grid", | ||
"imshowhs_grid", | ||
"imshow_grid_at_node", | ||
"imshowhs_grid_at_node", | ||
"plot_network_and_parcels", | ||
"plot_layers", | ||
"plot_graph", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Enhanced the ``plot_graph`` function: allow the ``with_id`` keyword to | ||
accept a list of elements that should have included IDs, fill in patches and | ||
cells. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
The ``plot_graph`` function now can take lists of graph elements rather than only comma-separated strings. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Added a new keyword, ``axes`` to ``plot_graph`` to allow plotting within an | ||
existing axes. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Fixed a bug where ``plot_graph`` would incorrectly include the last | ||
node/corner with patches/cells that had fewer links/faces than the maximum of | ||
the graph. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Fixed a bug in ``plot_graph`` where patch and cell polygons were not drawn. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import pytest | ||
|
||
from landlab import RasterModelGrid | ||
from landlab.plot.graph import _parse_locations_as_set, plot_graph | ||
|
||
|
||
def _axes_arrows(ax): | ||
from matplotlib.patches import FancyArrow | ||
|
||
return [child for child in ax.get_children() if isinstance(child, FancyArrow)] | ||
|
||
|
||
def test_parse_locations_from_str(): | ||
assert _parse_locations_as_set("node") == {"node"} | ||
assert _parse_locations_as_set("node,link") == {"node", "link"} | ||
assert _parse_locations_as_set("node,link,cell,link") == {"node", "link", "cell"} | ||
assert _parse_locations_as_set("node , link, patch ") == {"node", "link", "patch"} | ||
|
||
|
||
def test_parse_locations_from_iterable(): | ||
assert _parse_locations_as_set(["cell"]) == {"cell"} | ||
assert _parse_locations_as_set(("patch", "corner")) == {"patch", "corner"} | ||
assert _parse_locations_as_set(("patch", "corner", "patch")) == {"patch", "corner"} | ||
assert _parse_locations_as_set((" patch ", "corner ")) == {"patch", "corner"} | ||
|
||
|
||
def test_parse_locations_bad_value(): | ||
with pytest.raises(ValueError, match=r"^unknown location "): | ||
_parse_locations_as_set("foo") | ||
with pytest.raises(ValueError, match=r"^unknown locations "): | ||
_parse_locations_as_set("cells,nodes") | ||
|
||
|
||
@pytest.mark.parametrize("at", ["node", "link", "patch", "corner", "face", "cell"]) | ||
def test_plot_graph(at): | ||
grid = RasterModelGrid((3, 4)) | ||
ax = plot_graph(grid, at=at) | ||
|
||
assert ax.get_ylim() == (-0.5, 2.5) | ||
assert ax.get_xlim() == (-0.5, 3.5) | ||
|
||
if at in ("patch", "cell"): | ||
assert len(ax.patches) == grid.number_of_elements(at) | ||
elif at in ("link", "face"): | ||
assert len(_axes_arrows(ax)) == grid.number_of_elements(at) | ||
else: | ||
assert len(ax.lines) == grid.number_of_elements(at) | ||
|
||
|
||
def test_plot_graph_onto_existing(): | ||
grid = RasterModelGrid((3, 4)) | ||
ax = plot_graph(grid, at="node") | ||
plot_graph(grid, at="cell", axes=ax) | ||
|
||
assert ( | ||
len(ax.patches) + len(ax.lines) == grid.number_of_nodes + grid.number_of_cells | ||
) |