Skip to content

Commit

Permalink
delaunay plotter unitt est
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy2211 committed Nov 14, 2024
1 parent 852e093 commit 7dd9b07
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 30 deletions.
4 changes: 2 additions & 2 deletions autoarray/config/visualize/mat_wrap_2d.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ VectorYXQuiver: # wrapper for `plt.quiver()`: customize (y,x) vectors appea
linewidth: 5
pivot: middle
units: xy
DelaunayDrawer: # wrapper for `plt.fill()`: customize the appearance of Voronoi mesh's.
DelaunayDrawer: # wrapper for `plt.fill()`: customize the appearance of Delaunay mesh's.
figure:
alpha: 0.7
edgecolor: k
linewidth: 0.0
subplot:
alpha: 0.7
edgecolor: k
linewidth: 0.0
linewidth: 0.0
VoronoiDrawer: # wrapper for `plt.fill()`: customize the appearance of Voronoi mesh's.
figure:
alpha: 0.7
Expand Down
26 changes: 13 additions & 13 deletions autoarray/plot/mat_plot/two_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(
vector_yx_quiver: Optional[w2d.VectorYXQuiver] = None,
patch_overlay: Optional[w2d.PatchOverlay] = None,
interpolated_reconstruction: Optional[w2d.InterpolatedReconstruction] = None,
delaunay_drawer : Optional[w2d.DelaunayDrawer] = None,
delaunay_drawer: Optional[w2d.DelaunayDrawer] = None,
voronoi_drawer: Optional[w2d.VoronoiDrawer] = None,
origin_scatter: Optional[w2d.OriginScatter] = None,
mask_scatter: Optional[w2d.MaskScatter] = None,
Expand Down Expand Up @@ -662,21 +662,21 @@ def _plot_delaunay_mapper(
interpolation_array = None

if interpolate_to_uniform:

interpolation_array = self.interpolated_reconstruction.imshow_reconstruction(
mapper=mapper,
pixel_values=pixel_values,
units=self.units,
cmap=self.cmap,
colorbar=self.colorbar,
colorbar_tickparams=self.colorbar_tickparams,
aspect=aspect_inv,
ax=ax,
use_log10=self.use_log10,
interpolation_array = (
self.interpolated_reconstruction.imshow_reconstruction(
mapper=mapper,
pixel_values=pixel_values,
units=self.units,
cmap=self.cmap,
colorbar=self.colorbar,
colorbar_tickparams=self.colorbar_tickparams,
aspect=aspect_inv,
ax=ax,
use_log10=self.use_log10,
)
)

else:

self.delaunay_drawer.draw_delaunay_pixels(
mapper=mapper,
pixel_values=pixel_values,
Expand Down
23 changes: 8 additions & 15 deletions autoarray/plot/wrap/two_d/delaunay_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
from autoarray.plot.wrap import base as wb


def facecolors_from(
values,
simplices
):
def facecolors_from(values, simplices):
facecolors = np.zeros(shape=simplices.shape[0])
for i in range(simplices.shape[0]):
facecolors[i] = np.sum(1.0 / 3.0 * values[simplices[i, :]])
Expand Down Expand Up @@ -65,17 +62,19 @@ def draw_delaunay_pixels(
If `True`, the colorbar is plotted using a log10 scale.
"""

if pixel_values is None:
raise ValueError(
"pixel_values input to DelaunayPlotter are None and thus cannot be plotted."
)

if ax is None:
ax = plt.gca()

source_pixelization_grid = mapper.mapper_grids.source_plane_mesh_grid

simplices = mapper.delaunay.simplices

facecolors = facecolors_from(
values=pixel_values,
simplices=simplices
)
facecolors = facecolors_from(values=pixel_values, simplices=simplices)

norm = cmap.norm_from(array=pixel_values, use_log10=use_log10)

Expand All @@ -89,15 +88,9 @@ def draw_delaunay_pixels(
color_values = np.where(pixel_values > vmax, vmax, pixel_values)
color_values = np.where(pixel_values < vmin, vmin, color_values)

if vmax != vmin:
color_array = (color_values - vmin) / (vmax - vmin)
else:
color_array = np.ones(color_values.shape[0])

cmap = plt.get_cmap(cmap.cmap)

if colorbar is not None:

cb = colorbar.set_with_color_values(
units=units,
norm=norm,
Expand All @@ -120,4 +113,4 @@ def draw_delaunay_pixels(
vmin=vmin,
vmax=vmax,
**self.config_dict
)
)
26 changes: 26 additions & 0 deletions test_autoarray/plot/wrap/two_d/test_delaunay_drawer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import autoarray.plot as aplt

import numpy as np


def test__draws_delaunay_pixels_for_sensible_input(delaunay_mapper_9_3x3):
delaunay_drawer = aplt.DelaunayDrawer(linewidth=0.5, edgecolor="r", alpha=1.0)

delaunay_drawer.draw_delaunay_pixels(
mapper=delaunay_mapper_9_3x3,
pixel_values=np.ones(9),
units=aplt.Units(),
cmap=aplt.Cmap(),
colorbar=None,
)

values = np.ones(9)
values[0] = 0.0

delaunay_drawer.draw_delaunay_pixels(
mapper=delaunay_mapper_9_3x3,
pixel_values=values,
units=aplt.Units(),
cmap=aplt.Cmap(),
colorbar=aplt.Colorbar(fraction=0.1, pad=0.05),
)

0 comments on commit 7dd9b07

Please sign in to comment.