From dfdfff76070877dd7801f4462d50ddcedd0cc1ee Mon Sep 17 00:00:00 2001
From: Martin Reinecke <martin@mpa-garching.mpg.de>
Date: Mon, 2 Oct 2017 10:25:32 +0200
Subject: [PATCH] weight() -> dvol() for domain objects

---
 nifty/domain_object.py                               |  8 +++-----
 nifty/field.py                                       |  6 +++---
 nifty/field_types/field_type.py                      |  5 +----
 nifty/operators/fft_operator/fft_operator_support.py |  4 ++--
 nifty/spaces/gl_space/gl_space.py                    | 12 ++++++------
 nifty/spaces/hp_space/hp_space.py                    |  5 +----
 nifty/spaces/lm_space/lm_space.py                    |  5 +----
 nifty/spaces/power_space/power_space.py              |  4 ++--
 nifty/spaces/rg_space/rg_space.py                    | 11 ++++-------
 test/test_spaces/test_gl_space.py                    | 12 ++++++------
 test/test_spaces/test_hp_space.py                    |  4 ++--
 test/test_spaces/test_lm_space.py                    |  4 ++--
 test/test_spaces/test_power_space.py                 |  4 ++--
 test/test_spaces/test_rg_space.py                    |  8 ++++----
 14 files changed, 39 insertions(+), 53 deletions(-)

diff --git a/nifty/domain_object.py b/nifty/domain_object.py
index 030e4d17f..c6e32270f 100644
--- a/nifty/domain_object.py
+++ b/nifty/domain_object.py
@@ -120,7 +120,7 @@ class DomainObject(with_metaclass(
             "There is no generic dim for DomainObject.")
 
     @abc.abstractmethod
-    def scalar_weight(self):
+    def scalar_dvol(self):
         """ Returns the volume factors of this domain as a floating
         point scalar, if the volume factors are all identical, otherwise
         returns None.
@@ -139,8 +139,7 @@ class DomainObject(with_metaclass(
         raise NotImplementedError(
             "There is no generic scalar_weight method for DomainObject.")
 
-    @abc.abstractmethod
-    def weight(self):
+    def dvol(self):
         """ Returns the volume factors of this domain, either as a floating
         point scalar (if the volume factors are all identical) or as a
         floating point array with a shape of `self.shape`.
@@ -157,5 +156,4 @@ class DomainObject(with_metaclass(
             If called for this abstract class.
 
         """
-        raise NotImplementedError(
-            "There is no generic weight method for DomainObject.")
+        return self.scalar_dvol()
diff --git a/nifty/field.py b/nifty/field.py
index 60c79f408..f7022ceb4 100644
--- a/nifty/field.py
+++ b/nifty/field.py
@@ -416,13 +416,13 @@ class Field(object):
 
     def scalar_weight(self, spaces=None):
         if np.isscalar(spaces):
-            return self.domain[spaces].scalar_weight()
+            return self.domain[spaces].scalar_dvol()
 
         if spaces is None:
             spaces = range(len(self.domain))
         res = 1.
         for i in spaces:
-            tmp = self.domain[i].scalar_weight()
+            tmp = self.domain[i].scalar_dvol()
             if tmp is None:
                 return None
             res *= tmp
@@ -458,7 +458,7 @@ class Field(object):
 
         fct = 1.
         for ind in spaces:
-            wgt = self.domain[ind].weight()
+            wgt = self.domain[ind].dvol()
             if np.isscalar(wgt):
                 fct *= wgt
             else:
diff --git a/nifty/field_types/field_type.py b/nifty/field_types/field_type.py
index 768ba1570..f07ae99a7 100644
--- a/nifty/field_types/field_type.py
+++ b/nifty/field_types/field_type.py
@@ -20,8 +20,5 @@ from ..domain_object import DomainObject
 
 
 class FieldType(DomainObject):
-    def scalar_weight(self):
-        return 1.
-
-    def weight(self):
+    def scalar_dvol(self):
         return 1.
diff --git a/nifty/operators/fft_operator/fft_operator_support.py b/nifty/operators/fft_operator/fft_operator_support.py
index 53ead46fa..bb14e993c 100644
--- a/nifty/operators/fft_operator/fft_operator_support.py
+++ b/nifty/operators/fft_operator/fft_operator_support.py
@@ -62,9 +62,9 @@ class RGRGTransformation(Transformation):
         # BUT: the pixel volumes of the domain and codomain are different.
         # Hence, in order to produce the same scalar product, power==1.
         if self.codomain.harmonic:
-            fct = self.domain.weight()
+            fct = self.domain.scalar_dvol()
         else:
-            fct = 1./(self.codomain.weight()*self.domain.dim)
+            fct = 1./(self.codomain.scalar_dvol()*self.domain.dim)
 
         # Perform the transformation
         if issubclass(val.dtype.type, np.complexfloating):
diff --git a/nifty/spaces/gl_space/gl_space.py b/nifty/spaces/gl_space/gl_space.py
index 148b947d7..86b94685c 100644
--- a/nifty/spaces/gl_space/gl_space.py
+++ b/nifty/spaces/gl_space/gl_space.py
@@ -86,7 +86,7 @@ class GLSpace(Space):
 
         self._nlat = self._parse_nlat(nlat)
         self._nlon = self._parse_nlon(nlon)
-        self._wgt = None
+        self._dvol = None
 
     # ---Mandatory properties and methods---
 
@@ -109,16 +109,16 @@ class GLSpace(Space):
     def total_volume(self):
         return 4 * np.pi
 
-    def scalar_weight(self):
+    def scalar_dvol(self):
         return None
 
     # MR FIXME: this is potentially wasteful, since the return array is
     #           blown up by a factor of self.nlon
-    def weight(self):
+    def dvol(self):
         from pyHealpix import GL_weights
-        if self._wgt is None:
-            self._wgt = GL_weights(self.nlat, self.nlon)
-        return np.repeat(self._wgt, self.nlon)
+        if self._dvol is None:
+            self._dvol = GL_weights(self.nlat, self.nlon)
+        return np.repeat(self._dvol, self.nlon)
 
     # ---Added properties and methods---
 
diff --git a/nifty/spaces/hp_space/hp_space.py b/nifty/spaces/hp_space/hp_space.py
index 7fe9f1f6a..e2f5b792c 100644
--- a/nifty/spaces/hp_space/hp_space.py
+++ b/nifty/spaces/hp_space/hp_space.py
@@ -104,10 +104,7 @@ class HPSpace(Space):
     def total_volume(self):
         return 4 * np.pi
 
-    def scalar_weight(self):
-        return np.pi / (3*self._nside*self._nside)
-
-    def weight(self):
+    def scalar_dvol(self):
         return np.pi / (3*self._nside*self._nside)
 
     # ---Added properties and methods---
diff --git a/nifty/spaces/lm_space/lm_space.py b/nifty/spaces/lm_space/lm_space.py
index 73e1224de..da7248561 100644
--- a/nifty/spaces/lm_space/lm_space.py
+++ b/nifty/spaces/lm_space/lm_space.py
@@ -114,10 +114,7 @@ class LMSpace(Space):
         # the individual pixels have a fixed volume of 1.
         return np.float64(self.dim)
 
-    def scalar_weight(self):
-        return 1.
-
-    def weight(self):
+    def scalar_dvol(self):
         return 1.
 
     def get_k_length_array(self):
diff --git a/nifty/spaces/power_space/power_space.py b/nifty/spaces/power_space/power_space.py
index 93a9f05fa..ca858e298 100644
--- a/nifty/spaces/power_space/power_space.py
+++ b/nifty/spaces/power_space/power_space.py
@@ -204,10 +204,10 @@ class PowerSpace(Space):
         # every power-pixel has a volume of 1
         return float(reduce(lambda x, y: x*y, self.pindex.shape))
 
-    def scalar_weight(self):
+    def scalar_dvol(self):
         return None
 
-    def weight(self):
+    def dvol(self):
         # MR FIXME: this will probably change to 1 soon
         return np.asarray(self.rho, dtype=np.float64)
 
diff --git a/nifty/spaces/rg_space/rg_space.py b/nifty/spaces/rg_space/rg_space.py
index d8921aac6..4823bd05c 100644
--- a/nifty/spaces/rg_space/rg_space.py
+++ b/nifty/spaces/rg_space/rg_space.py
@@ -87,7 +87,7 @@ class RGSpace(Space):
         self._harmonic = bool(harmonic)
         self._shape = self._parse_shape(shape)
         self._distances = self._parse_distances(distances)
-        self._wgt = float(reduce(lambda x, y: x*y, self._distances))
+        self._dvol = float(reduce(lambda x, y: x*y, self._distances))
         self._dim = int(reduce(lambda x, y: x*y, self._shape))
 
     def __repr__(self):
@@ -108,13 +108,10 @@ class RGSpace(Space):
 
     @property
     def total_volume(self):
-        return self.dim * self._wgt
+        return self.dim * self._dvol
 
-    def scalar_weight(self):
-        return self._wgt
-
-    def weight(self):
-        return self._wgt
+    def scalar_dvol(self):
+        return self._dvol
 
     def get_k_length_array(self):
         if (not self.harmonic):
diff --git a/test/test_spaces/test_gl_space.py b/test/test_spaces/test_gl_space.py
index 6ca94eeab..6b4f67cf6 100644
--- a/test/test_spaces/test_gl_space.py
+++ b/test/test_spaces/test_gl_space.py
@@ -41,14 +41,14 @@ CONSTRUCTOR_CONFIGS = [
     ]
 
 
-def get_weight_configs():
+def get_dvol_configs():
     np.random.seed(42)
     wgt = [2.0943951,  2.0943951]
     # for GLSpace(nlat=2, nlon=3)
-    weight_0 = np.array(list(itertools.chain.from_iterable(
+    dvol_0 = np.array(list(itertools.chain.from_iterable(
         itertools.repeat(x, 3) for x in wgt)))
     return [
-        [1, weight_0],
+        [1, dvol_0],
         ]
 
 
@@ -73,6 +73,6 @@ class GLSpaceFunctionalityTests(unittest.TestCase):
             for key, value in expected.items():
                 assert_equal(getattr(g, key), value)
 
-    @expand(get_weight_configs())
-    def test_weight(self, power, expected):
-        assert_almost_equal(GLSpace(2).weight(), expected)
+    @expand(get_dvol_configs())
+    def test_dvol(self, power, expected):
+        assert_almost_equal(GLSpace(2).dvol(), expected)
diff --git a/test/test_spaces/test_hp_space.py b/test/test_spaces/test_hp_space.py
index ad665f446..c32fe339d 100644
--- a/test/test_spaces/test_hp_space.py
+++ b/test/test_spaces/test_hp_space.py
@@ -72,5 +72,5 @@ class HPSpaceFunctionalityTests(unittest.TestCase):
             for key, value in expected.items():
                 assert_equal(getattr(h, key), value)
 
-    def test_weight(self):
-        assert_almost_equal(HPSpace(2).weight(), np.pi/12)
+    def test_dvol(self):
+        assert_almost_equal(HPSpace(2).dvol(), np.pi/12)
diff --git a/test/test_spaces/test_lm_space.py b/test/test_spaces/test_lm_space.py
index 34a11c039..a92684399 100644
--- a/test/test_spaces/test_lm_space.py
+++ b/test/test_spaces/test_lm_space.py
@@ -89,8 +89,8 @@ class LMSpaceFunctionalityTests(unittest.TestCase):
             for key, value in expected.items():
                 assert_equal(getattr(l, key), value)
 
-    def test_weight(self):
-        assert_almost_equal(LMSpace(5).weight(), 1.)
+    def test_dvol(self):
+        assert_almost_equal(LMSpace(5).dvol(), 1.)
 
     @expand(get_k_length_array_configs())
     def test_k_length_array(self, lmax, expected):
diff --git a/test/test_spaces/test_power_space.py b/test/test_spaces/test_power_space.py
index 35fe3e709..a9c8042d6 100644
--- a/test/test_spaces/test_power_space.py
+++ b/test/test_spaces/test_power_space.py
@@ -129,6 +129,6 @@ class PowerSpaceFunctionalityTest(unittest.TestCase):
         p = PowerSpace(harmonic_partner=harmonic_partner)
         assert_almost_equal(p.get_k_length_array(), expected)
 
-    def test_weight(self):
+    def test_dvol(self):
         p = PowerSpace(harmonic_partner=RGSpace(10,harmonic=True))
-        assert_almost_equal(p.weight(),p.rho)
+        assert_almost_equal(p.dvol(),p.rho)
diff --git a/test/test_spaces/test_rg_space.py b/test/test_spaces/test_rg_space.py
index 297922a56..02ea682d4 100644
--- a/test/test_spaces/test_rg_space.py
+++ b/test/test_spaces/test_rg_space.py
@@ -88,7 +88,7 @@ def get_k_length_array_configs():
         ]
 
 
-def get_weight_configs():
+def get_dvol_configs():
     np.random.seed(42)
     return [
         [(11, 11), None, False, 1],
@@ -122,7 +122,7 @@ class RGSpaceFunctionalityTests(unittest.TestCase):
         r = RGSpace(shape=shape, distances=distances, harmonic=True)
         assert_almost_equal(r.get_k_length_array(), expected)
 
-    @expand(get_weight_configs())
-    def test_weight(self, shape, distances, harmonic, power):
+    @expand(get_dvol_configs())
+    def test_dvol(self, shape, distances, harmonic, power):
         r = RGSpace(shape=shape, distances=distances, harmonic=harmonic)
-        assert_almost_equal(r.weight(), np.prod(r.distances)**power)
+        assert_almost_equal(r.dvol(), np.prod(r.distances)**power)
-- 
GitLab