Skip to content
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

Minor changes #751

Merged
merged 7 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
run: echo "nbsphinx_execute=${{ github.event.inputs.nbsphinx_execute }}" >> $GITHUB_ENV

- name: Build docs
run: sphinx-build -W -n -b html -d build/doctrees doc build/html --keep-going -j auto -D nbsphinx_execute=${{ env.nbsphinx_execute }}
run: sphinx-build -W -n -b html -d build/doctrees doc build/html --keep-going -j 2 -D nbsphinx_execute=${{ env.nbsphinx_execute }}

- uses: actions/upload-artifact@v3
if: |
Expand Down
6 changes: 3 additions & 3 deletions weldx/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
WELDX_QUANTITY = WELDX_UNIT_REGISTRY.Quantity
Q_ = WELDX_QUANTITY
Q_.__name__ = "Q_"
Q_.__module_ = "pint.quantity" # skipcq: PYL-W0212
Q_.__module__ = "pint.quantity" # skipcq: PYL-W0212
Q_.__doc__ = """Create a quantity from a scalar or array.

The quantity class supports lots of physical units and will combine them during
Expand Down Expand Up @@ -70,8 +70,8 @@
"""

# set default units
_DEFAULT_LEN_UNIT = WELDX_UNIT_REGISTRY.millimeters
_DEFAULT_ANG_UNIT = WELDX_UNIT_REGISTRY.rad
_DEFAULT_LEN_UNIT: pint.Unit = WELDX_UNIT_REGISTRY.millimeters
_DEFAULT_ANG_UNIT: pint.Unit = WELDX_UNIT_REGISTRY.rad

# set default unit registry for pint-xarray
pint.set_application_registry(WELDX_UNIT_REGISTRY)
Expand Down
3 changes: 3 additions & 0 deletions weldx/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"types_file_like",
"types_path_like",
"types_path_and_file_like",
"ArrayLike",
"QuantityLike",
"UnitLike",
]


Expand Down
109 changes: 34 additions & 75 deletions weldx/welding/groove/iso_9692_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from sympy import Point2D, Polygon

import weldx.geometry as geo
from weldx.constants import Q_, U_
from weldx.constants import _DEFAULT_LEN_UNIT, Q_
from weldx.util import inherit_docstrings, ureg_check_class

if TYPE_CHECKING: # pragma: no cover
Expand All @@ -36,9 +36,6 @@
]


_DEFAULT_LEN_UNIT = U_("mm")


def _set_default_heights(groove):
"""Calculate default h1/h2 values."""
if groove.h1 is None and groove.h2 is None:
Expand Down Expand Up @@ -79,15 +76,15 @@ def _compute_cross_sect_shape_points(

bounding_box = Polygon((x1, y1), (x2, y1), (x2, y2), (x1, y2), evaluate=False)

return Q_(float(bounding_box.area - area_workpiece), "mm²")
return Q_(float(bounding_box.area - area_workpiece), f"{_DEFAULT_LEN_UNIT}**2")


class IsoBaseGroove(metaclass=abc.ABCMeta):
"""Generic base class for all groove types."""

_mapping: dict[str, str] = None

_AREA_RASTER_WIDTH = Q_("0.1mm")
_AREA_RASTER_WIDTH: pint.Quantity = Q_(0.1, _DEFAULT_LEN_UNIT)
"""steers the area approximation of the groove in ~cross_sect_area."""

def __post_init__(self):
Expand Down Expand Up @@ -141,7 +138,7 @@ def plot(
ax :
Axis to plot to
show_area
Calculate and show the groove cross section area in the plot title.
Calculate and show the groove cross-section area in the plot title.

"""
if raster_width is None:
Expand All @@ -153,7 +150,7 @@ def plot(
if show_area:
try:
ca = self.cross_sect_area
title = title + f" ({np.around(ca,1):~.3P})"
title = title + f" ({np.around(ca, 1):~.3P})"
except NotImplementedError:
pass
except Exception as ex:
Expand Down Expand Up @@ -222,6 +219,16 @@ def _compute_cross_sect_area_interpolated(self):

return _compute_cross_sect_shape_points(points)

@staticmethod
def _translate_reflect(b, segment_list, x_value, y_value):
shape = _helperfunction(segment_list, (x_value, y_value))
shape = shape.translate(Q_(np.append(-b / 2, 0), _DEFAULT_LEN_UNIT))
# y-axis as mirror axis
shape_r = shape.reflect_across_line(
Q_([0, 0], _DEFAULT_LEN_UNIT), Q_([0, 1], _DEFAULT_LEN_UNIT)
)
return geo.Profile([shape, shape_r], units=_DEFAULT_LEN_UNIT)


@ureg_check_class("[length]", "[length]", None)
@inherit_docstrings
Expand Down Expand Up @@ -268,15 +275,7 @@ def to_profile(self, width_default: pint.Quantity = None) -> geo.Profile:
y_value = np.stack((0, 0, t, t))
segment_list = ["line", "line", "line"]

shape = _helperfunction(segment_list, [x_value, y_value])

shape = shape.translate(np.append(-b / 2, 0))
# y-axis as mirror axis
shape_r = shape.reflect_across_line(
Q_([0, 0], _DEFAULT_LEN_UNIT), Q_([0, 1], _DEFAULT_LEN_UNIT)
)

return geo.Profile([shape, shape_r], units=_DEFAULT_LEN_UNIT)
return self._translate_reflect(b, segment_list, x_value, y_value)

@property
def cross_sect_area(self): # noqa
Expand Down Expand Up @@ -363,15 +362,7 @@ def to_profile(self, width_default: pint.Quantity = None) -> geo.Profile:
y_value = np.append(y_value, t)
segment_list.append("line")

shape = _helperfunction(segment_list, [x_value, y_value])

shape = shape.translate(np.append(-b / 2, 0))
# y-axis is mirror axis
shape_r = shape.reflect_across_line(
Q_([0, 0], _DEFAULT_LEN_UNIT), Q_([0, 1], _DEFAULT_LEN_UNIT)
)

return geo.Profile([shape, shape_r], units=_DEFAULT_LEN_UNIT)
return self._translate_reflect(b, segment_list, x_value, y_value)

@property
def cross_sect_area(self): # noqa
Expand Down Expand Up @@ -463,15 +454,7 @@ def to_profile(self, width_default: pint.Quantity = None) -> geo.Profile:
y_value = np.append(y_value, (h + c, t, t))
segment_list += ["line", "line", "line"]

shape = _helperfunction(segment_list, [x_value, y_value])

shape = shape.translate(np.append(-b / 2, 0))
# y-axis as mirror axis
shape_r = shape.reflect_across_line(
Q_([0, 0], _DEFAULT_LEN_UNIT), Q_([0, 1], _DEFAULT_LEN_UNIT)
)

return geo.Profile([shape, shape_r], units=_DEFAULT_LEN_UNIT)
return self._translate_reflect(b, segment_list, x_value, y_value)

@property
def cross_sect_area(self): # noqa
Expand Down Expand Up @@ -570,15 +553,7 @@ def to_profile(self, width_default: pint.Quantity = None) -> geo.Profile:
y_value = np.stack((0, 0, h, y_m, y_arc, t, t))
segment_list = ["line", "line", "arc", "line", "line"]

shape = _helperfunction(segment_list, [x_value, y_value])

shape = shape.translate(np.append(-b / 2, 0))
# y-axis as mirror axis
shape_r = shape.reflect_across_line(
Q_([0, 0], _DEFAULT_LEN_UNIT), Q_([0, 1], _DEFAULT_LEN_UNIT)
)

return geo.Profile([shape, shape_r], units=_DEFAULT_LEN_UNIT)
return self._translate_reflect(b, segment_list, x_value, y_value)

@property
def cross_sect_area(self): # noqa
Expand Down Expand Up @@ -694,15 +669,7 @@ def to_profile(self, width_default: pint.Quantity = None) -> geo.Profile:
y_value = np.append(y_value, t)
segment_list.append("line")

shape = _helperfunction(segment_list, [x_value, y_value])

shape = shape.translate(np.append(-b / 2, 0))
# y-axis as mirror axis
shape_r = shape.reflect_across_line(
Q_([0, 0], _DEFAULT_LEN_UNIT), Q_([0, 1], _DEFAULT_LEN_UNIT)
)

return geo.Profile([shape, shape_r], units=_DEFAULT_LEN_UNIT)
return self._translate_reflect(b, segment_list, x_value, y_value)

@property
def cross_sect_area(self): # noqa
Expand Down Expand Up @@ -1017,14 +984,7 @@ def to_profile(self, width_default: pint.Quantity = None) -> geo.Profile:
y_value = np.append(y_value, (t, t))
segment_list += ["line", "line"]

shape = _helperfunction(segment_list, [x_value, y_value])
shape = shape.translate(np.append(-b / 2, 0))
# y-axis as mirror axis
shape_r = shape.reflect_across_line(
Q_([0, 0], _DEFAULT_LEN_UNIT), Q_([0, 1], _DEFAULT_LEN_UNIT)
)

return geo.Profile([shape, shape_r], units=_DEFAULT_LEN_UNIT)
return self._translate_reflect(b, segment_list, x_value, y_value)

@property
def cross_sect_area(self): # noqa
Expand Down Expand Up @@ -1159,14 +1119,7 @@ def to_profile(self, width_default: pint.Quantity = None) -> geo.Profile:
y_value = np.append(y_value, (h2 + c + R, t - (h1 - (R - y_upper)), t, t))
segment_list += ["arc", "line", "line"]

shape = _helperfunction(segment_list, [x_value, y_value])
shape = shape.translate(np.append(-b / 2, 0))
# y-axis as mirror axis
shape_r = shape.reflect_across_line(
Q_([0, 0], _DEFAULT_LEN_UNIT), Q_([0, 1], _DEFAULT_LEN_UNIT)
)

return geo.Profile([shape, shape_r], units=_DEFAULT_LEN_UNIT)
return self._translate_reflect(b, segment_list, x_value, y_value)

@property
def cross_sect_area(self): # noqa
Expand Down Expand Up @@ -1645,7 +1598,7 @@ def cross_sect_area(self): # noqa
raise NotImplementedError("Cannot determine FFGroove cross sectional area")


def _helperfunction(segment, array) -> geo.Shape:
def _helperfunction(segment: list[str], array: np.ndarray) -> geo.Shape:
"""Calculate a shape from input.

Input segment of successive segments as strings.
Expand All @@ -1667,22 +1620,28 @@ def _helperfunction(segment, array) -> geo.Shape:
geo.Shape

"""
segment_list = []
segment_list: list[Union[geo.LineSegment, geo.ArcSegment]] = []
counter = 0
for elem in segment:
if elem == "line":
seg = geo.LineSegment(
np.vstack(
[array[0][counter : counter + 2], array[1][counter : counter + 2]]
Q_(
np.vstack(
[
array[0][counter : counter + 2],
array[1][counter : counter + 2],
]
),
_DEFAULT_LEN_UNIT,
)
)
segment_list.append(seg)
counter += 1
if elem == "arc":
elif elem == "arc":
arr0 = array[0][[counter, counter + 2, counter + 1]]
arr1 = array[1][[counter, counter + 2, counter + 1]]
arr = np.vstack((arr0, arr1))
seg = geo.ArcSegment(arr, False)
seg = geo.ArcSegment(Q_(arr, _DEFAULT_LEN_UNIT), False)
segment_list.append(seg)
counter += 2

Expand Down