Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
([5], Scalar([6]), 0),
pytest.param([3], 'larry', None, marks=pytest.mark.xfail),
], indirect=['scalar'])
def test_equality(scalar, other, expected):
eq = scalar == other
assert np.allclose(eq, expected)
def scalar(request):
return Scalar(request.param)
phase_id = crystal_map.get_map_data("phase_id")
phase_id = phase_id[self._data_slices]
unique_phase_ids = np.unique(phase_id[~np.isnan(phase_id)])
data = np.ones(phase_id.shape + (3,))
for i, color in zip(
unique_phase_ids, crystal_map.phases_in_data.colors_rgb
):
mask = phase_id == int(i)
data[mask] = data[mask] * color
# Add legend patches to plot
patches = []
for _, p in crystal_map.phases_in_data:
patches.append(mpatches.Patch(color=p.color_rgb, label=p.name))
else: # Create masked array of correct shape
if isinstance(value, Scalar) or isinstance(value, Vector3d):
value = value.data
data = crystal_map.get_map_data(value)
data = data[self._data_slices]
# Squeeze 1-dimensions
data = np.squeeze(data)
# Legend
if legend and isinstance(patches, list):
if legend_properties is None:
legend_properties = {}
self._add_legend(patches, **legend_properties)
# Scalebar
if scalebar:
if scalebar_properties is None:
def __add__(self, other):
if isinstance(other, Vector3d):
return self.__class__(self.data + other.data)
elif isinstance(other, Scalar):
return self.__class__(self.data + other.data[..., np.newaxis])
elif isinstance(other, (int, float)):
return self.__class__(self.data + other)
elif isinstance(other, (list, tuple)):
other = np.array(other)
if isinstance(other, np.ndarray):
return self.__class__(self.data + other[..., np.newaxis])
return NotImplemented
def angle_with(self, other):
"""The angle of rotation transforming this rotation to the other.
Returns
-------
Scalar
"""
other = Rotation(other)
angles = Scalar(
np.nan_to_num(np.arccos(2 * self.unit.dot(other.unit).data ** 2 - 1))
)
return angles
def z(self):
"""Scalar : This vector's z data."""
return Scalar(self.data[..., 2])
def dot_outer(self, other):
"""Scalar : the outer dot product of this quaternion and the other."""
dots = np.tensordot(self.data, other.data, axes=(-1, -1))
return Scalar(dots)
def y(self):
"""Scalar : This vector's y data."""
return Scalar(self.data[..., 1])
def b(self):
return Scalar(self.data[..., 1])
def angle(self):
return Scalar(np.arctan(self.norm.data) * 2)