-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create mesh visualization #184
base: main
Are you sure you want to change the base?
Changes from 6 commits
2ce7bef
df7611e
805c75b
393d2ea
63fb47a
979e739
950dc17
f619b6e
28c0839
e7590d9
9e3a3e6
d056bae
9f5c0de
d5834af
6efc237
d555fa0
f1b9e4d
0d6d577
c36b25f
c334c05
c27ab21
aef5a64
ffb67bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -800,3 +800,73 @@ def _get_flattened_orientation( | |
flattened_orientation[:3, :3] = _get_orientation(view_plane) | ||
|
||
return (distance_from_camera * flattened_orientation).ravel().tolist() | ||
|
||
|
||
def plot_isosurface( | ||
mesh, | ||
value, | ||
structure_plot=None, | ||
samwaseda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
isomin: Optional[float] = None, | ||
isomax: Optional[float] = None, | ||
surface_fill: Optional[float] = None, | ||
opacity: Optional[float] = None, | ||
surface_count: Optional[int] = None, | ||
colorbar_nticks: Optional[int] = None, | ||
caps: Optional[dict] = dict(x_show=False, y_show=False, z_show=False), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid mutable default arguments. Using mutable default arguments can lead to unexpected behavior. Replace with - caps: Optional[dict] = dict(x_show=False, y_show=False, z_show=False),
+ caps: Optional[dict] = None, Initialize within the function: if caps is None:
caps = dict(x_show=False, y_show=False, z_show=False) ToolsRuff
|
||
colorscale: Optional[str] = None, | ||
height: Optional[float] = 600, | ||
samwaseda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
camera: Optional[str] = "orthographic", | ||
**kwargs, | ||
): | ||
""" | ||
Make a mesh plot | ||
|
||
Args: | ||
mesh (numpy.ndarray): Mesh grid. Must have a shape of (nx, ny, nz, 3). | ||
It can be generated from structuretoolkit.create_mesh | ||
value: (numpy.ndarray): Value to plot. Must have a shape of (nx, ny, nz) | ||
structure_plot (plotly.graph_objs._figure.Figure): Plot of the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the type hint should show import directly from the public part of the API ( |
||
structure to overlay. You should basically always use | ||
structuretoolkit.plot3d(structure, mode="plotly") | ||
isomin(float): Min color value | ||
isomax(float): Max color value | ||
surface_fill(float): Polygonal filling of the surface to choose between | ||
0 and 1 | ||
opacity(float): Opacity | ||
surface_count(int): Number of isosurfaces, 2 by default, which means | ||
only min and max | ||
colorbar_nticks(int): Colorbar ticks correspond to isosurface values | ||
caps(dict): Whether to set cap on sides or not. Default is False. You | ||
can set: caps=dict(x_show=True, y_show=True, z_show=True) | ||
colorscale(str): Colorscale ("turbo", "gnbu" etc.) | ||
height(float): Height of the figure. 600px by default | ||
camera(str): Camera perspective to choose from "orthographic" and | ||
"perspective". Default is "orthographic" | ||
""" | ||
try: | ||
import plotly.graph_objects as go | ||
except ModuleNotFoundError: | ||
raise ModuleNotFoundError("plotly not installed - use plot3d instead") | ||
samwaseda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
x_mesh = np.reshape(mesh, (-1, 3)).T | ||
data = go.Isosurface( | ||
x=x_mesh[0], | ||
y=x_mesh[1], | ||
z=x_mesh[2], | ||
value=np.array(value).flatten(), | ||
isomin=isomin, | ||
isomax=isomax, | ||
surface_fill=surface_fill, | ||
opacity=opacity, | ||
surface_count=surface_count, | ||
colorbar_nticks=colorbar_nticks, | ||
caps=caps, | ||
colorscale=colorscale, | ||
**kwargs, | ||
) | ||
fig = go.Figure(data=data) | ||
if structure_plot is not None: | ||
fig = go.Figure(data=fig.data + structure_plot.data) | ||
fig.update_scenes(aspectmode="data") | ||
fig.layout.scene.camera.projection.type = camera | ||
fig.update_layout(autosize=True, height=height) | ||
return fig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add missing import for
Union
.The
Union
type hint is used but not imported. Import it from thetyping
module.+from typing import Union
Committable suggestion