diff --git a/nifty/domain_object.py b/nifty/domain_object.py index 7760a7f9bb3612e1f1467542fbe175a5f37f42f7..081a4877c54aefad7c04ced72473f1383eef1026 100644 --- a/nifty/domain_object.py +++ b/nifty/domain_object.py @@ -48,6 +48,11 @@ class DomainObject(Versionable, Loggable, object): raise NotImplementedError( "There is no generic dim for DomainObject.") + @abc.abstractmethod + def weight(self, x, power=1, axes=None, inplace=False): + raise NotImplementedError( + "There is no generic weight-method for DomainObject.") + def pre_cast(self, x, axes=None): return x diff --git a/nifty/field_types/field_type.py b/nifty/field_types/field_type.py index 16a9a8022c0b5f0234534309ed64a6acb2251250..5cb2436f0e1f9895ca41ec87675d09e55f0128ae 100644 --- a/nifty/field_types/field_type.py +++ b/nifty/field_types/field_type.py @@ -5,6 +5,13 @@ from nifty.domain_object import DomainObject class FieldType(DomainObject): + def weight(self, x, power=1, axes=None, inplace=False): + if inplace: + result = x + else: + result = x.copy() + return result + def process(self, method_name, array, inplace=True, **kwargs): try: result_array = self.__getattr__(method_name)(array, diff --git a/nifty/spaces/space/space.py b/nifty/spaces/space/space.py index a3e026eef821249a345f1ccc4bacda18d3bfd749..aaec0dd3b8dd89c38f77285057b4b5efe6e42a1c 100644 --- a/nifty/spaces/space/space.py +++ b/nifty/spaces/space/space.py @@ -221,26 +221,6 @@ class Space(DomainObject): def copy(self): return self.__class__(dtype=self.dtype) - @abc.abstractmethod - def weight(self, x, power=1, axes=None, inplace=False): - """ - Weights a given array of field values with the pixel volumes (not - the meta volumes) to a given power. - - Parameters - ---------- - x : numpy.ndarray - Array to be weighted. - power : float, *optional* - Power of the pixel volumes to be used (default: 1). - - Returns - ------- - y : numpy.ndarray - Weighted array. - """ - raise NotImplementedError - def get_distance_array(self, distribution_strategy): raise NotImplementedError( "There is no generic distance structure for Space base class.")