diff --git a/nifty/domain_object.py b/nifty/domain_object.py index 030e4d17feae4a1f0c7b386bc1c89768778c2492..c6e32270fb7869f968bd8f025a435d67287f6077 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 60c79f4089bf32df68918277aad9b13f67797c9f..f7022ceb4596b365cd1e708c80ab47ce5fd1c33f 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 768ba157059a813c2cb03ee7629e936bb815ff07..f07ae99a72e18ca7d6354a9a04b6005f43ed13c7 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 53ead46fa432c460d8abad2807705fbe213c85a0..bb14e993cddc3b01bb50044c06592bb03eb1ed93 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 148b947d76038a084958ac21242dbc5b1cb8c1c5..86b94685cce485803919911fea713eb3fccfd33d 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 7fe9f1f6a18894faaa4f449acf5f1a06372b9526..e2f5b792cd1837fab499e87260bd0091cb135d20 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 73e1224decba9b3754f6fd0e498d1fdcf36f5a40..da7248561e5ed949aee232a181f18ca1e26994ae 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 93a9f05fae8babb77326dcc55fb31ccabc4f0c94..ca858e2980a47a954f568e1cc87e9b77fd2ad97b 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 d8921aac696bf95c84fb769b2c02cbbf9eaa04ca..4823bd05ce0a871d26e30d33b86c5604b19b69b0 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 6ca94eeab1c396227617e30be1226540db426783..6b4f67cf6075e8f94a276cc587147dcaa69e4e06 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 ad665f44687231d1f8fb35a469dfd498dbd14f93..c32fe339d8f913c0c9d91dfffcb5a65d0fd537a0 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 34a11c039a11d3bb15906509d361bff548c1fd0a..a926843999fcfbdbdb2a400fb17ad42ef61d910c 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 35fe3e709bfe1fe1a6ebc8f43ad6cbd85cc50917..a9c8042d6d8a4abdc1772f51c75efffe22aefea8 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 297922a56b2a6ca7e136bd3e1ad05c5a81480f47..02ea682d41ddc53c886a0d8ff13a40c477e6cb0a 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)