Skip to content
Closed

pr #2

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 20 additions & 36 deletions pyphare/pyphare/pharesee/hierarchy/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,6 @@ def box_to_Rectangle(self, box):
return Rectangle(box.lower, *box.shape)

def plot_2d_patches(self, ilvl, collections, **kwargs):
from matplotlib.patches import Rectangle

if isinstance(collections, list) and all(
[isinstance(el, Box) for el in collections]
):
Expand All @@ -370,47 +368,35 @@ def plot_2d_patches(self, ilvl, collections, **kwargs):
level_domain_box = self.level_domain_box(ilvl)
mi, ma = level_domain_box.lower.min(), level_domain_box.upper.max()

fig, ax = kwargs.get("subplot", plt.subplots(figsize=(16, 16)))

i0, j0 = level_domain_box.lower
i1, j1 = level_domain_box.upper
ij = np.zeros((i1 - i0 + 1, j1 - j0 + 1)) + np.nan
ix = np.arange(i0, i1 + 1)
iy = np.arange(j0, j1 + 1)
fig, ax = kwargs.get("subplot", plt.subplots(figsize=(6, 6)))

for collection in collections:
value = collection.get("value", np.nan)
for box in collection["boxes"]:
i0, j0 = box.lower
i1, j1 = box.upper
ij[i0 : i1 + 1, j0 : j1 + 1] = value
if "coords" in collection:
for coords in collection["coords"]:
ij[coords] = collection["value"]

ax.pcolormesh(ix, iy, ij.T, edgecolors="k", cmap="jet")
ax.set_xticks(ix)
ax.set_yticks(iy)

for patch in self.level(ilvl).patches:
box = patch.box
r = Rectangle(box.lower - 0.5, *(box.upper + 0.5))

r.set_edgecolor("r")
r.set_facecolor("none")
r.set_linewidth(2)
ax.add_patch(r)
facecolor = collection.get("facecolor", "none")
edgecolor = collection.get("edgecolor", "purple")
alpha = collection.get("alpha", 1)
rects = [self.box_to_Rectangle(box) for box in collection["boxes"]]

ax.add_collection(
PatchCollection(
rects, facecolor=facecolor, alpha=alpha, edgecolor=edgecolor
)
)

if "title" in kwargs:
from textwrap import wrap

xfigsize = int(fig.get_size_inches()[0] * 10) # 10 characters per inch
ax.set_title("\n".join(wrap(kwargs["title"], xfigsize)))

if "xlim" in kwargs:
ax.set_xlim(kwargs["xlim"])
if "ylim" in kwargs:
ax.set_ylim(kwargs["ylim"])
major_ticks = np.arange(mi - 5, ma + 5 + 5, 5)
ax.set_xticks(major_ticks)
ax.set_yticks(major_ticks)

minor_ticks = np.arange(mi - 5, ma + 5 + 5, 1)
ax.set_xticks(minor_ticks, minor=True)
ax.set_yticks(minor_ticks, minor=True)

ax.grid(which="both")

return fig

Expand Down Expand Up @@ -444,8 +430,6 @@ def plot1d(self, **kwargs):
if qty is None:
qty = pdata_names[0]

layout = patch.patch_datas[qty].layout
# nbrGhosts = layout.nbrGhostFor(qty) # bad !!!
nbrGhosts = patch.patch_datas[qty].ghosts_nbr
val = patch.patch_datas[qty][patch.box]
x = patch.patch_datas[qty].x[nbrGhosts[0] : -nbrGhosts[0]]
Expand Down
10 changes: 5 additions & 5 deletions pyphare/pyphare_tests/test_pharesee/test_geometry_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ def test_large_patchoverlaps(self, expected):
collections=[
{
"boxes": overlap_boxes,
"value": 1,
"facecolor": "grey",
},
{
"boxes": [p.box for p in hierarchy.level(ilvl).patches],
"value": 2,
"facecolor": "yellow",
},
],
)
Expand Down Expand Up @@ -390,11 +390,11 @@ def test_level_ghost_boxes(self, refinement_boxes, expected):
collections=[
{
"boxes": ghost_area_box_list,
"value": 1,
"facecolor": "yellow",
},
{
"boxes": [p.box for p in hierarchy.level(ilvl).patches],
"value": 2,
"facecolor": "grey",
},
],
title="".join(
Expand Down Expand Up @@ -502,7 +502,7 @@ def test_patch_periodicity_copy(self, refinement_boxes, expected):
collections=[
{
"boxes": [p.box for p in periodic_list],
"value": 2,
"facecolor": "grey",
},
],
)
Expand Down
Loading