Skip to content

Commit

Permalink
data_name -> data
Browse files Browse the repository at this point in the history
  • Loading branch information
j042 committed Feb 5, 2024
1 parent 0d198d4 commit 3d5fb94
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 34 deletions.
2 changes: 1 addition & 1 deletion examples/iga/collocation_laplace_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def source_function(x):

# Plot geometry and field
geometry.spline_data["field"] = solution_field
geometry.show_options["data_name"] = "field"
geometry.show_options["data"] = "field"
geometry.show_options["cmap"] = "jet"
geometry.show_options["lighting"] = "off"
geometry.show_options["scalarbar"] = True
Expand Down
2 changes: 1 addition & 1 deletion examples/iga/collocation_laplace_problem_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def source_function(x):

# Plot geometry and field
geometry.spline_data["field"] = solution_field
geometry.show_options["data_name"] = "field"
geometry.show_options["data"] = "field"
geometry.show_options["cmap"] = "jet"
geometry.show_options["lighting"] = "off"
geometry.show_options["scalarbar"] = True
Expand Down
2 changes: 1 addition & 1 deletion examples/iga/galerkin_laplace_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def map_positions(positions, x_min, x_max, y_min, y_max):

# Plot geometry and field
geometry.spline_data["field"] = solution_field
geometry.show_options["data_name"] = "field"
geometry.show_options["data"] = "field"
geometry.show_options["cmap"] = "jet"
geometry.show_options["lighting"] = "off"
geometry.show_options["scalarbar"] = True
Expand Down
6 changes: 3 additions & 3 deletions examples/show_isophotes_and_curvature.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ def mean_curvature(data, on=None):
a.show_options["knots"] = False

# Show Isophotes
a.show_options["data_name"] = "isophotes"
a.show_options["data"] = "isophotes"
a.show(resolutions=1000, title="Isophotes")

# Show Gaussian Curvature
a.show_options["data_name"] = "gaussian_curvature"
a.show_options["data"] = "gaussian_curvature"
a.show_options["scalarbar"] = True
a.show(resolutions=100, title="Gaussian Curvature")

# Show Curvature
a.show_options["data_name"] = "mean_curvature"
a.show_options["data"] = "mean_curvature"
a.show_options["scalarbar"] = True
a.show(resolutions=100, title="Mean Curvature")
4 changes: 2 additions & 2 deletions examples/show_multipatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# plot scalar data
m = splinepy.Multipatch([box0, box1, box2, box3])
m.spline_data["t"] = m
m.show_options["data_name"] = "t"
m.show_options["data"] = "t"
m.show_options["lighting"] = "off"
m.show()

Expand Down Expand Up @@ -72,6 +72,6 @@ def plot_jacs(data, on):

m = generator.create(center_expansion=1.2)
m.spline_data["detJ"] = splinepy.SplineDataAdaptor(m, function=plot_jacs)
m.show_options["data_name"] = "detJ"
m.show_options["data"] = "detJ"
m.show_options["lighting"] = "off"
m.show()
12 changes: 6 additions & 6 deletions examples/show_spline_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ def bspline2p3d():
# 1. see coordinates's norm
b = bspline2p3d()
b.spline_data["me"] = b
b.show_options["data_name"] = "me"
b.show_options["data"] = "me"
gus.show(["1. Show norm of coordinates.", b])

# 1.1 default scalarbar
b = bspline2p3d()
b.spline_data["me"] = b
b.show_options["data_name"] = "me"
b.show_options["data"] = "me"
b.show_options["scalarbar"] = True
gus.show(["1.1. Show 1. plus scalarbar", b])

# 2. see coordinate's norm and as arrow
b = bspline2p3d()
b.spline_data["me"] = b
b.show_options["data_name"] = "me"
b.show_options["data"] = "me"
b.show_options["arrow_data"] = "me"
gus.show(
["2. Show coordinate norm as scalar field and coordinate as arrows", b]
Expand All @@ -72,7 +72,7 @@ def bspline2p3d():
# 3. see coordinates norm and as arrows only on specified places
b = bspline2p3d()
b.spline_data["me"] = b
b.show_options["data_name"] = "me"
b.show_options["data"] = "me"
b.show_options["arrow_data"] = "me"
b.show_options["arrow_data_on"] = np.random.random((100, 2)) # para_coords
gus.show(
Expand All @@ -82,7 +82,7 @@ def bspline2p3d():
# 4. see 3. with parametric_view
b = bspline2p3d()
b.spline_data["me"] = b
b.show_options["data_name"] = "me"
b.show_options["data"] = "me"
b.show_options["arrow_data"] = "me"
b.show_options["arrow_data_on"] = np.random.random((100, 2)) # para_coords
b.show_options["scalarbar"] = True
Expand Down Expand Up @@ -181,7 +181,7 @@ def func(self_and_deformed, on):
p_view = b.create.parametric_view() # shallow copies data and options
p_view.show_options.pop("arrow_data_scale") # we want automatic scaling
p_view.show_options["arrow_data_color"] = "gold"
p_view.show_options["data_name"] = "deformed"
p_view.show_options["data"] = "deformed"
# plot side by side
gus.show(
[
Expand Down
38 changes: 18 additions & 20 deletions splinepy/helpme/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,20 +247,18 @@ def _sample_spline(spline, res):
return sp


def _process_scalar_field(spline, data_name, sampled_spline, res):
def _process_scalar_field(spline, data, sampled_spline, res):
"""
Assuming field data is defined, extracts field value and applies
to sampled spline.
"""
# get data name and try to sample scalar field
sampled_spline_data = spline.spline_data.as_scalar(
data_name, res, default=None
)
sampled_spline_data = spline.spline_data.as_scalar(data, res, default=None)

# apply sampled data as vertex data to sampled_spline
if sampled_spline_data is not None:
# transfer data
sampled_spline.vertex_data[data_name] = sampled_spline_data
sampled_spline.vertex_data[data] = sampled_spline_data

# transfer options - maybe vectorized query?
keys = (
Expand All @@ -276,10 +274,10 @@ def _process_scalar_field(spline, data_name, sampled_spline, res):
)

# mark that we want to see this data
sampled_spline.show_options["data_name"] = data_name
sampled_spline.show_options["data"] = data

else:
raise ValueError(f"No spline_data named ({data_name}) for {spline}.")
raise ValueError(f"No spline_data named ({data}) for {spline}.")


def _process_spline_color(spline, sampled_spline, res):
Expand All @@ -302,23 +300,23 @@ def _process_spline_color(spline, sampled_spline, res):
"lighting", default_lighting
)

# process scalar field if data_name is defined
data_name = spline.show_options.get("data_name", None)
if data_name is not None:
_process_scalar_field(spline, data_name, sampled_spline, res)
# process scalar field if data is defined
data = spline.show_options.get("data", None)
if data is not None:
_process_scalar_field(spline, data, sampled_spline, res)


def _sample_arrow_data(spline, adata_name, sampled_spline, res):
def _sample_arrow_data(spline, adata, sampled_spline, res):
"""
Process arrow_data. Also known as vector_data.
"""
# early exit?
if adata_name is None:
if adata is None:
return None

# use getitem to retrieve adapted_adata. this will raise key error if
# it doesn't exist
adapted_adata = spline.spline_data[adata_name]
adapted_adata = spline.spline_data[adata]

# if location is specified, this will be a separate Vertices obj with
# configured arrow_data. Multipatch might just return a multipatch,
Expand All @@ -330,7 +328,7 @@ def _sample_arrow_data(spline, adata_name, sampled_spline, res):
# this case causes conflict of interest. raise
if has_locations and adata_on:
raise ValueError(
f"arrow_data-({adata_name}) has fixed location, "
f"arrow_data-({adata}) has fixed location, "
"but and `arrow_data_on` is set.",
)

Expand All @@ -342,8 +340,8 @@ def _sample_arrow_data(spline, adata_name, sampled_spline, res):
# then, add arrow as vertex_data to them
if not create_vertices:
# sample arrows and append to sampled spline.
sampled_spline.vertex_data[adata_name] = spline.spline_data.as_arrow(
adata_name, resolutions=res
sampled_spline.vertex_data[adata] = spline.spline_data.as_arrow(
adata, resolutions=res
)

# transfer options to sampled_spline
Expand Down Expand Up @@ -375,16 +373,16 @@ def _sample_arrow_data(spline, adata_name, sampled_spline, res):
ub_diff = queries.max(axis=0) - bounds[1] - _settings.TOLERANCE
if any(lb_diff < 0) or any(ub_diff > 0):
raise ValueError(
f"Given locations for ({adata_name}) are outside the "
f"Given locations for ({adata}) are outside the "
f"parametric bounds ({bounds})."
)

# get arrow
adata = spline.spline_data.as_arrow(adata_name, on=on)
adata_values = spline.spline_data.as_arrow(adata, on=on)

# create vertices that can be shown as arrows
loc_vertices = _Vertices(spline.evaluate(queries))
loc_vertices.vertex_data[adata_name] = adata
loc_vertices.vertex_data[adata] = adata_values

# transfer options
keys = ("arrow_data_scale", "arrow_data_color", "arrow_data")
Expand Down

0 comments on commit 3d5fb94

Please sign in to comment.