Skip to content

Commit

Permalink
split clamping of the variable and the colorbar limits
Browse files Browse the repository at this point in the history
  • Loading branch information
otvam committed Nov 10, 2023
1 parent 04dc456 commit a9e7916
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
18 changes: 16 additions & 2 deletions examples/config/plotter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
# - var: name of the scalar variable to be plotted (color scale)
# - scale: scaling of the variable (scaling done just before plotting)
# - log: use (or not) a log scale for the color axis
# - color_lim: clamping range for the color axis (null for complete range)
# - color_lim: limit range for the color axis (null for complete range)
# - clamp_lim: clamping range for the color axis (null for complete range)
# - filter_lim: hide voxels/points with values outside this range (null for complete range)
# - point_size: size of the marker used for plotting on the point cloud
#
Expand All @@ -36,7 +37,8 @@
# - var_vector: name of the vector variable to be plotted (arrow direction)
# - scale: scaling of the scalar variable (scaling done just before plotting)
# - log: use (or not) a log scale for the color axis
# - color_lim: clamping range for the color axis (null for complete range)
# - color_lim: limit range for the color axis (null for complete range)
# - clamp_lim: clamping range for the color axis (null for complete range)
# - filter_lim: hide arrows with scalar values outside this range (null for complete range)
# - arrow_threshold: relative threshold for hiding arrows with small scalar values
# - arrow_scale: relative arrow length (with respect to the voxel size)
Expand Down Expand Up @@ -80,6 +82,7 @@
"scale": 1.0
"log": false
"color_lim": null
"clamp_lim": null
"filter_lim": null
"point_size": 10.0
"V_m_abs":
Expand All @@ -95,6 +98,7 @@
"scale": 1.0
"log": false
"color_lim": null
"clamp_lim": null
"filter_lim": null
"point_size": 10.0
"S_c_abs":
Expand All @@ -110,6 +114,7 @@
"scale": 1.0e-9
"log": false
"color_lim": null
"clamp_lim": null
"filter_lim": null
"point_size": 10.0
"Q_m_abs":
Expand All @@ -125,6 +130,7 @@
"scale": 1.0
"log": false
"color_lim": null
"clamp_lim": null
"filter_lim": null
"point_size": 10.0
"P_c_abs":
Expand All @@ -140,6 +146,7 @@
"scale": 1.0e-6
"log": false
"color_lim": null
"clamp_lim": null
"filter_lim": null
"point_size": 10.0
"P_m_abs":
Expand All @@ -155,6 +162,7 @@
"scale": 1.0e-6
"log": false
"color_lim": null
"clamp_lim": null
"filter_lim": null
"point_size": 10.0
"J_c_norm":
Expand All @@ -170,6 +178,7 @@
"scale": 1.0e-6
"log": false
"color_lim": null
"clamp_lim": null
"filter_lim": null
"point_size": 10.0
"J_c_vec":
Expand All @@ -186,6 +195,7 @@
"scale": 1.0e-6
"log": false
"color_lim": null
"clamp_lim": null
"filter_lim": null
"arrow_threshold": 1.0e-3
"arrow_scale": 0.75
Expand All @@ -202,6 +212,7 @@
"scale": 1.0e+3
"log": false
"color_lim": null
"clamp_lim": null
"filter_lim": null
"point_size": 10.0
"B_m_vec":
Expand All @@ -218,6 +229,7 @@
"scale": 1.0e+3
"log": false
"color_lim": null
"clamp_lim": null
"filter_lim": null
"arrow_threshold": 1.0e-3
"arrow_scale": 0.75
Expand All @@ -234,6 +246,7 @@
"scale": 1.0
"log": false
"color_lim": null
"clamp_lim": null
"filter_lim": null
"point_size": 10.0
"H_vec":
Expand All @@ -250,6 +263,7 @@
"scale": 1.0
"log": false
"color_lim": null
"clamp_lim": null
"filter_lim": null
"arrow_threshold": 1.0e-3
"arrow_scale": 0.75
Expand Down
3 changes: 2 additions & 1 deletion pypeec/lib_check/check_data_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _check_data_plot_plotter(layout, data_plot):
# check the options for scalar and arrow plots
if layout in ["scalar_voxel", "scalar_point", "arrow_voxel", "arrow_point"]:
# check type
key_list = ["title", "scale", "log", "legend", "color_lim", "filter_lim"]
key_list = ["title", "scale", "log", "legend", "color_lim", "clamp_lim", "filter_lim"]
datachecker.check_dict("data_plot", data_plot, key_list=key_list)

# check data
Expand All @@ -231,6 +231,7 @@ def _check_data_plot_plotter(layout, data_plot):
datachecker.check_string("legend", data_plot["legend"], can_be_empty=True)
datachecker.check_float("scale", data_plot["scale"], is_positive=True, can_be_zero=True)
datachecker.check_float_array("color_lim", data_plot["color_lim"], size=2, can_be_none=True)
datachecker.check_float_array("clamp_lim", data_plot["clamp_lim"], size=2, can_be_none=True)
datachecker.check_float_array("filter_lim", data_plot["filter_lim"], size=2, can_be_none=True)

# check the scalar options
Expand Down
20 changes: 14 additions & 6 deletions pypeec/lib_visualization/manage_pyvista.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def _get_filter_scalar(obj, var, filter_lim):
return obj


def _get_clamp_scalar(obj, var, color_lim):
def _get_clamp_scalar(obj, var, clamp_lim):
"""
Clamp a scalar variable between a lower and upper bound.
"""
Expand All @@ -245,11 +245,11 @@ def _get_clamp_scalar(obj, var, color_lim):
return obj

# handle None
if color_lim is None:
if clamp_lim is None:
c_min = -float("inf")
c_max = +float("inf")
else:
(c_min, c_max) = color_lim
(c_min, c_max) = clamp_lim

# get var
data = obj[var]
Expand Down Expand Up @@ -277,6 +277,7 @@ def _plot_scalar(pl, obj, data_plot, plot_clip, plot_theme):
scale = data_plot["scale"]
log = data_plot["log"]
filter_lim = data_plot["filter_lim"]
clamp_lim = data_plot["clamp_lim"]
color_lim = data_plot["color_lim"]
point_size = data_plot["point_size"]
legend = data_plot["legend"]
Expand All @@ -298,12 +299,13 @@ def _plot_scalar(pl, obj, data_plot, plot_clip, plot_theme):
obj_tmp = obj.copy(deep=True)
obj_tmp = _get_scale_scalar(obj_tmp, var, scale)
obj_tmp = _get_filter_scalar(obj_tmp, var, filter_lim)
obj_tmp = _get_clamp_scalar(obj_tmp, var, color_lim)
obj_tmp = _get_clamp_scalar(obj_tmp, var, clamp_lim)

# add the resulting plot to the plotter
arg = dict(
scalars=var,
log_scale=log,
clim=color_lim,
point_size=point_size,
scalar_bar_args=scalar_bar_args,
render_points_as_spheres=True,
Expand All @@ -329,6 +331,7 @@ def _plot_arrow(pl, grid, obj, data_plot, plot_clip, plot_theme):
scale = data_plot["scale"]
log = data_plot["log"]
filter_lim = data_plot["filter_lim"]
clamp_lim = data_plot["clamp_lim"]
color_lim = data_plot["color_lim"]
arrow_scale = data_plot["arrow_scale"]
arrow_threshold = data_plot["arrow_threshold"]
Expand Down Expand Up @@ -357,14 +360,19 @@ def _plot_arrow(pl, grid, obj, data_plot, plot_clip, plot_theme):
obj_tmp = _get_filter_vector(obj_tmp, var_norm, arrow_threshold)
obj_tmp = _get_scale_scalar(obj_tmp, var_norm, scale)
obj_tmp = _get_filter_scalar(obj_tmp, var_norm, filter_lim)
obj_tmp = _get_clamp_scalar(obj_tmp, var_norm, color_lim)
obj_tmp = _get_clamp_scalar(obj_tmp, var_norm, clamp_lim)

# get arrow size
d_char = min(grid.spacing)
factor = d_char*arrow_scale

# add the resulting plot to the plotter
arg = dict(scalars=var_norm, log_scale=log, scalar_bar_args=scalar_bar_args)
arg = dict(
scalars=var_norm,
log_scale=log,
clim=color_lim,
scalar_bar_args=scalar_bar_args,
)
if obj_tmp.n_cells > 0:
glyph_tmp = obj_tmp.glyph(orient=var_time, scale=False, factor=factor)
_get_clip_mesh(pl, glyph_tmp, arg, plot_clip)
Expand Down

0 comments on commit a9e7916

Please sign in to comment.