Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
marscher committed Oct 28, 2024
1 parent 362b159 commit aec6530
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 173 deletions.
18 changes: 6 additions & 12 deletions weldx_widgets/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

import numpy as np
import pandas as pd
import weldx
from IPython import get_ipython
from ipyfilechooser import FileChooser
from IPython import get_ipython
from ipywidgets import HTML, Button, HBox, Label

import weldx
from weldx_widgets.widget_base import WeldxImportExport, WidgetMyHBox, WidgetMyVBox
from weldx_widgets.widget_factory import (
WidgetLabeledTextInput,
Expand Down Expand Up @@ -94,18 +94,12 @@ class WidgetTimeSeries(WidgetMyVBox, WeldxImportExport):
"""Preliminary time series editing widget."""

# TODO: handle math-expr
def __init__(
self, base_unit, time_unit="s", base_data="0", time_data="0", title=""
):
def __init__(self, base_unit, time_unit="s", base_data="0", time_data="0", title=""):
layout_prefilled_text = copy_layout(textbox_layout)
layout_prefilled_text.width = "300px"

self.base_data = WidgetLabeledTextInput(
label_text="Input dimension", prefilled_text=base_data
)
self.time_data = WidgetLabeledTextInput(
label_text="Time steps", prefilled_text=time_data
)
self.base_data = WidgetLabeledTextInput(label_text="Input dimension", prefilled_text=base_data)
self.time_data = WidgetLabeledTextInput(label_text="Time steps", prefilled_text=time_data)
self.base_data.text.layout = layout_prefilled_text
self.time_data.text.layout = layout_prefilled_text

Expand Down Expand Up @@ -148,7 +142,7 @@ def from_tree(self, tree: dict):
else:
self.time_data.text_value = ""
if np.__version__ > "2":
with np.printoptions(legacy='1.25'):
with np.printoptions(legacy="1.25"):
self.base_data.text_value = repr(list(ts.data.magnitude))
else:
self.base_data.text_value = repr(list(ts.data.magnitude))
Expand Down
8 changes: 2 additions & 6 deletions weldx_widgets/tests/test_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@ def test_plot_coordinate_system():
[[-1, 0, 0], [0, -1, 0], [0, 0, 1]],
]
coordinates_tdp = Q_([[0, 0, 1], [0, 0, 2], [0, -1, 0]], "mm")
lcs_tdp = tf.LocalCoordinateSystem(
orientation=orientation_tdp, coordinates=coordinates_tdp, time=time
)
lcs_tdp = tf.LocalCoordinateSystem(orientation=orientation_tdp, coordinates=coordinates_tdp, time=time)

_, ax = plt.subplots(subplot_kw=dict(projection="3d"))

vs.draw_coordinate_system_matplotlib(lcs_constant, ax, "g")
vs.draw_coordinate_system_matplotlib(lcs_tdp, ax, "r", "2016-01-10")
vs.draw_coordinate_system_matplotlib(lcs_tdp, ax, "b", "2016-01-11", time_idx=1)
vs.draw_coordinate_system_matplotlib(
lcs_tdp, ax, "y", "2016-01-12", pd.TimedeltaIndex([12], "s")
)
vs.draw_coordinate_system_matplotlib(lcs_tdp, ax, "y", "2016-01-12", pd.TimedeltaIndex([12], "s"))

# exceptions ------------------------------------------

Expand Down
40 changes: 10 additions & 30 deletions weldx_widgets/visualization/csm_k3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ def _get_limits_from_stack(limits):
return np.vstack([mins, maxs])


def _get_coordinates_and_orientation(
lcs: LocalCoordinateSystem, index: int = 0
) -> tuple[pint.Quantity, pint.Quantity]:
def _get_coordinates_and_orientation(lcs: LocalCoordinateSystem, index: int = 0) -> tuple[pint.Quantity, pint.Quantity]:
"""Get the coordinates and orientation of a coordinate system.
Parameters
Expand All @@ -68,20 +66,14 @@ def _get_coordinates_and_orientation(
"Interpolate values before plotting to solve this issue"
)

coordinates = lcs.coordinates.isel(time=index, missing_dims="ignore").data.astype(
"float32"
)
coordinates = lcs.coordinates.isel(time=index, missing_dims="ignore").data.astype("float32")

orientation = lcs.orientation.isel(time=index, missing_dims="ignore").data.astype(
"float32"
)
orientation = lcs.orientation.isel(time=index, missing_dims="ignore").data.astype("float32")

return coordinates, orientation


def _create_model_matrix(
coordinates: pint.Quantity, orientation: np.ndarray
) -> np.ndarray:
def _create_model_matrix(coordinates: pint.Quantity, orientation: np.ndarray) -> np.ndarray:
"""Create the model matrix from an orientation and coordinates.
Parameters
Expand Down Expand Up @@ -487,9 +479,7 @@ def update_model_matrix(self, model_mat):
if self._mesh is not None:
self._mesh.model_matrix = model_mat
if self._label is not None:
self._label.position = (
np.matmul(model_mat[0:3, 0:3], self._label_pos) + model_mat[0:3, 3]
)
self._label.position = np.matmul(model_mat[0:3, 0:3], self._label_pos) + model_mat[0:3, 3]


class CoordinateSystemManagerVisualizerK3D:
Expand Down Expand Up @@ -780,26 +770,20 @@ def _create_controls(
traces_cb = Checkbox(value=show_traces, description="show traces", layout=lo)
labels_cb = Checkbox(value=show_labels, description="show labels", layout=lo)
wf_cb = Checkbox(value=show_wireframe, description="show wireframe", layout=lo)
data_labels_cb = Checkbox(
value=show_data_labels, description="show data labels", layout=lo
)
data_labels_cb = Checkbox(value=show_data_labels, description="show data labels", layout=lo)

jslink((play, "value"), (time_slider, "value"))
play.disabled = disable_time_widgets
time_slider.disabled = disable_time_widgets

# register callbacks
time_slider.observe(lambda c: self.update_time_index(c["new"]), names="value")
reference_dropdown.observe(
lambda c: self.update_reference_system(c["new"]), names="value"
)
reference_dropdown.observe(lambda c: self.update_reference_system(c["new"]), names="value")
vectors_cb.observe(lambda c: self.show_vectors(c["new"]), names="value")
origin_cb.observe(lambda c: self.show_origins(c["new"]), names="value")
traces_cb.observe(lambda c: self.show_traces(c["new"]), names="value")
labels_cb.observe(lambda c: self.show_labels(c["new"]), names="value")
data_dropdown.observe(
lambda c: self.set_data_visualization_method(c["new"]), names="value"
)
data_dropdown.observe(lambda c: self.set_data_visualization_method(c["new"]), names="value")
data_labels_cb.observe(lambda c: self.show_data_labels(c["new"]), names="value")
wf_cb.observe(lambda c: self.show_wireframes(c["new"]), names="value")

Expand All @@ -817,9 +801,7 @@ def _get_model_matrix(self, lcs_name):
return lcs_vis.origin.model_matrix

lcs = self._csm.get_cs(lcs_name, self._current_reference_system)
coordinates, orientation = _get_coordinates_and_orientation(
lcs, self._current_time_index
)
coordinates, orientation = _get_coordinates_and_orientation(lcs, self._current_time_index)
return _create_model_matrix(coordinates, orientation)

def _update_spatial_data(self):
Expand Down Expand Up @@ -916,9 +898,7 @@ def update_reference_system(self, reference_system):
"""
self._current_reference_system = reference_system
for lcs_name, lcs_vis in self._lcs_vis.items():
lcs_vis.update_lcs(
self._csm.get_cs(lcs_name, reference_system), self._current_time_index
)
lcs_vis.update_lcs(self._csm.get_cs(lcs_name, reference_system), self._current_time_index)
self._update_spatial_data()

def update_time_index(self, index: int):
Expand Down
10 changes: 2 additions & 8 deletions weldx_widgets/visualization/csm_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def new_3d_figure_and_axes(
The matplotlib axes object
"""
fig, ax = plt.subplots(
ncols=num_subplots, subplot_kw={"projection": "3d", "proj_type": "ortho"}
)
fig, ax = plt.subplots(ncols=num_subplots, subplot_kw={"projection": "3d", "proj_type": "ortho"})
try:
fig.canvas.layout.height = f"{height}px"
fig.canvas.layout.width = f"{width}px"
Expand Down Expand Up @@ -260,11 +258,7 @@ def plot_local_coordinate_system_matplotlib(
show_vectors=show_vectors,
)

if (
show_trace
and not isinstance(lcs.coordinates, TimeSeries)
and lcs.coordinates.data.ndim > 1
):
if show_trace and not isinstance(lcs.coordinates, TimeSeries) and lcs.coordinates.data.ndim > 1:
coords = lcs.coordinates.data
if isinstance(coords, Q_):
coords = coords.to(_DEFAULT_LEN_UNIT).m
Expand Down
6 changes: 1 addition & 5 deletions weldx_widgets/widget_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ def metaclass_resolver(*classes):
def cls_name(classes):
return "_".join(mcls.__name__ for mcls in classes)

metaclass = (
metaclass[0]
if len(metaclass) == 1
else type(cls_name(metaclass), metaclass, {})
) # class M_C
metaclass = metaclass[0] if len(metaclass) == 1 else type(cls_name(metaclass), metaclass, {}) # class M_C
return metaclass(cls_name(classes), classes, {}) # class C


Expand Down
21 changes: 5 additions & 16 deletions weldx_widgets/widget_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ def make_output():
# start and end time of experiment
t = (file["TCP"].time[[0, -1]]).as_timedelta()

WidgetProcessInfo(
file["process"]["welding_process"], t, out=tabs["Process parameters"]
)
WidgetProcessInfo(file["process"]["welding_process"], t, out=tabs["Process parameters"])

groove = file["workpiece"]["geometry"]["groove_shape"]
with tabs["Specimen"]:
Expand All @@ -132,10 +130,7 @@ def make_output():
# clean up scan data (fill up NaNs)
scans_available = True
try:
foo = [
_clean_nans_from_spatial_data(csm.get_data(f"scan_{i}"))
for i in range(0, 2)
]
foo = [_clean_nans_from_spatial_data(csm.get_data(f"scan_{i}")) for i in range(0, 2)]
assert len(foo) == 2
# assert csm.get_data("scan_1").coordinates.
except KeyError:
Expand All @@ -145,18 +140,14 @@ def make_output():
spatial_data_geo_full = geometry_full_width.spatial_data(
profile_raster_width=Q_(4, "mm"), trace_raster_width=Q_(60, "mm")
)
spatial_data_geo_full.coordinates = spatial_data_geo_full.coordinates.astype(
"float32"
)
spatial_data_geo_full.coordinates = spatial_data_geo_full.coordinates.astype("float32")

spatial_data_geo_reduced = geometry.spatial_data(
profile_raster_width=Q_(4, "mm"), trace_raster_width=Q_(60, "mm")
)

csm.assign_data(spatial_data_geo_full, "workpiece geometry", "workpiece")
csm.assign_data(
spatial_data_geo_reduced, "workpiece geometry (reduced)", "workpiece"
)
csm.assign_data(spatial_data_geo_reduced, "workpiece geometry (reduced)", "workpiece")

with tabs["CSM-Subsystems"]:
csm.plot_graph()
Expand Down Expand Up @@ -284,9 +275,7 @@ def _welding_wire_geo_data(radius, length, cross_section_resolution=8):
triangles[-1][1] = 1
triangles[-1][2] = 0

return SpatialData(
Q_(points, "mm").astype("float32"), np.array(triangles, dtype="uint32")
)
return SpatialData(Q_(points, "mm").astype("float32"), np.array(triangles, dtype="uint32"))

@staticmethod
def _create_geometry(groove, seam_length, width):
Expand Down
4 changes: 1 addition & 3 deletions weldx_widgets/widget_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ class WidgetFloatWithUnit(WidgetMyHBox):

def __init__(self, text, unit, value: float = 0.0, min=0):
self._label = Label(text, layout=description_layout)
self._float = BoundedFloatText(
value=value, min=min, max=2**32, layout=textbox_layout
)
self._float = BoundedFloatText(value=value, min=min, max=2**32, layout=textbox_layout)
self._unit = Text(value=unit, placeholder="unit", layout=textbox_layout)

super().__init__(
Expand Down
22 changes: 5 additions & 17 deletions weldx_widgets/widget_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ def __init__(self, index=0, percentage=100):
self.initial_percentage = percentage
self.components = {self.gas_list[index]: gas}

self.out = Output(
layout=Layout(
width="auto", height="80px", display="none", border="2px solid"
)
)
self.out = Output(layout=Layout(width="auto", height="80px", display="none", border="2px solid"))

button_add = Button(description="Add gas component")
button_add.on_click(self._add_gas_comp)
Expand All @@ -58,9 +54,7 @@ def _create_gas_dropdown(self, index=0, percentage=100):
style={"description_width": "initial"},
)

percentage = IntSlider(
start=0, end=100, value=percentage, description="percentage"
)
percentage = IntSlider(start=0, end=100, value=percentage, description="percentage")
percentage.observe(self._check, type="change")

self.gas_selection = gas_dropdown
Expand Down Expand Up @@ -109,9 +103,7 @@ def _check(self, value):

def to_tree(self) -> dict:
gas_components = [
GasComponent(
self._mapping[element], Q_(int(widget.children[1].value), "percent")
)
GasComponent(self._mapping[element], Q_(int(widget.children[1].value), "percent"))
for element, widget in self.components.items()
]
return dict(gas_component=gas_components)
Expand Down Expand Up @@ -149,9 +141,7 @@ def to_tree(self) -> dict:
"""Return weldx objects describing the shielding gas."""
gas_for_proc = ShieldingGasForProcedure(
use_torch_shielding_gas=True,
torch_shielding_gas=ShieldingGasType(
**self.gas_components.to_tree(), common_name="SG"
),
torch_shielding_gas=ShieldingGasType(**self.gas_components.to_tree(), common_name="SG"),
torch_shielding_gas_flowrate=self.flowrate.quantity,
)
return dict(shielding_gas=gas_for_proc)
Expand All @@ -160,7 +150,5 @@ def from_tree(self, tree):
"""Restore widget state from tree."""
gas_for_proc: ShieldingGasForProcedure = tree["shielding_gas"]
self.flowrate.quantity = gas_for_proc.torch_shielding_gas_flowrate
gas_components = dict(
gas_component=gas_for_proc.torch_shielding_gas.gas_component
)
gas_components = dict(gas_component=gas_for_proc.torch_shielding_gas.gas_component)
self.gas_components.from_tree(gas_components)
Loading

0 comments on commit aec6530

Please sign in to comment.