Skip to content
Snippets Groups Projects
Commit 8ea719a5 authored by Jan Caron's avatar Jan Caron
Browse files

Implemented division (truediv and floordiv) for fielddata and phasemap.

parent 2fa049b7
No related branches found
No related tags found
No related merge requests found
......@@ -144,7 +144,17 @@ class FieldData(object, metaclass=abc.ABCMeta):
def __mul__(self, other): # self * other
self._log.debug('Calling __mul__')
assert isinstance(other, Number), 'FieldData objects can only be multiplied by numbers!'
return self.__class__(self.a, other * self.field)
return self.__class__(self.a, self.field * other)
def __truediv__(self, other): # self / other
self._log.debug('Calling __truediv__')
assert isinstance(other, Number), 'FieldData objects can only be divided by numbers!'
return self.__class__(self.a, self.field / other)
def __floordiv__(self, other): # self // other
self._log.debug('Calling __floordiv__')
assert isinstance(other, Number), 'FieldData objects can only be divided by numbers!'
return self.__class__(self.a, self.field // other)
def __radd__(self, other): # other + self
self._log.debug('Calling __radd__')
......@@ -170,6 +180,14 @@ class FieldData(object, metaclass=abc.ABCMeta):
self._log.debug('Calling __imul__')
return self.__mul__(other)
def __itruediv__(self, other): # self /= other
self._log.debug('Calling __itruediv__')
return self.__truediv__(other)
def __ifloordiv__(self, other): # self //= other
self._log.debug('Calling __ifloordiv__')
return self.__floordiv__(other)
def __array__(self, dtype=None):
if dtype:
return self.field.astype(dtype)
......
......@@ -233,13 +233,20 @@ class PhaseMap(object):
'PhaseMap objects can only be multiplied by scalar numbers or fitting arrays!'
return PhaseMap(self.a, self.phase * other, self.mask, self.confidence, self.unit)
def __div__(self, other): # self / other
self._log.debug('Calling __div__')
def __truediv__(self, other): # self / other
self._log.debug('Calling __truediv__')
assert (isinstance(other, Number) or
(isinstance(other, np.ndarray) and other.shape == self.dim_uv)), \
'PhaseMap objects can only be multiplied by scalar numbers or fitting arrays!'
'PhaseMap objects can only be divided by scalar numbers or fitting arrays!'
return PhaseMap(self.a, self.phase / other, self.mask, self.confidence, self.unit)
def __floordiv__(self, other): # self // other
self._log.debug('Calling __floordiv__')
assert (isinstance(other, Number) or
(isinstance(other, np.ndarray) and other.shape == self.dim_uv)), \
'PhaseMap objects can only be divided by scalar numbers or fitting arrays!'
return PhaseMap(self.a, self.phase // other, self.mask, self.confidence, self.unit)
def __radd__(self, other): # other + self
self._log.debug('Calling __radd__')
return self.__add__(other)
......@@ -264,9 +271,13 @@ class PhaseMap(object):
self._log.debug('Calling __imul__')
return self.__mul__(other)
def __idiv__(self, other): # self /= other
self._log.debug('Calling __idiv__')
return self.__div__(other)
def __itruediv__(self, other): # self /= other
self._log.debug('Calling __itruediv__')
return self.__truediv__(other)
def __ifloordiv__(self, other): # self //= other
self._log.debug('Calling __ifloordiv__')
return self.__floordiv__(other)
def __array__(self, dtype=None):
if dtype:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment