Commit dfdfff76 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

weight() -> dvol() for domain objects

parent 537a2d3d
Pipeline #19131 canceled with stage
...@@ -120,7 +120,7 @@ class DomainObject(with_metaclass( ...@@ -120,7 +120,7 @@ class DomainObject(with_metaclass(
"There is no generic dim for DomainObject.") "There is no generic dim for DomainObject.")
@abc.abstractmethod @abc.abstractmethod
def scalar_weight(self): def scalar_dvol(self):
""" Returns the volume factors of this domain as a floating """ Returns the volume factors of this domain as a floating
point scalar, if the volume factors are all identical, otherwise point scalar, if the volume factors are all identical, otherwise
returns None. returns None.
...@@ -139,8 +139,7 @@ class DomainObject(with_metaclass( ...@@ -139,8 +139,7 @@ class DomainObject(with_metaclass(
raise NotImplementedError( raise NotImplementedError(
"There is no generic scalar_weight method for DomainObject.") "There is no generic scalar_weight method for DomainObject.")
@abc.abstractmethod def dvol(self):
def weight(self):
""" Returns the volume factors of this domain, either as a floating """ Returns the volume factors of this domain, either as a floating
point scalar (if the volume factors are all identical) or as a point scalar (if the volume factors are all identical) or as a
floating point array with a shape of `self.shape`. floating point array with a shape of `self.shape`.
...@@ -157,5 +156,4 @@ class DomainObject(with_metaclass( ...@@ -157,5 +156,4 @@ class DomainObject(with_metaclass(
If called for this abstract class. If called for this abstract class.
""" """
raise NotImplementedError( return self.scalar_dvol()
"There is no generic weight method for DomainObject.")
...@@ -416,13 +416,13 @@ class Field(object): ...@@ -416,13 +416,13 @@ class Field(object):
def scalar_weight(self, spaces=None): def scalar_weight(self, spaces=None):
if np.isscalar(spaces): if np.isscalar(spaces):
return self.domain[spaces].scalar_weight() return self.domain[spaces].scalar_dvol()
if spaces is None: if spaces is None:
spaces = range(len(self.domain)) spaces = range(len(self.domain))
res = 1. res = 1.
for i in spaces: for i in spaces:
tmp = self.domain[i].scalar_weight() tmp = self.domain[i].scalar_dvol()
if tmp is None: if tmp is None:
return None return None
res *= tmp res *= tmp
...@@ -458,7 +458,7 @@ class Field(object): ...@@ -458,7 +458,7 @@ class Field(object):
fct = 1. fct = 1.
for ind in spaces: for ind in spaces:
wgt = self.domain[ind].weight() wgt = self.domain[ind].dvol()
if np.isscalar(wgt): if np.isscalar(wgt):
fct *= wgt fct *= wgt
else: else:
......
...@@ -20,8 +20,5 @@ from ..domain_object import DomainObject ...@@ -20,8 +20,5 @@ from ..domain_object import DomainObject
class FieldType(DomainObject): class FieldType(DomainObject):
def scalar_weight(self): def scalar_dvol(self):
return 1.
def weight(self):
return 1. return 1.
...@@ -62,9 +62,9 @@ class RGRGTransformation(Transformation): ...@@ -62,9 +62,9 @@ class RGRGTransformation(Transformation):
# BUT: the pixel volumes of the domain and codomain are different. # BUT: the pixel volumes of the domain and codomain are different.
# Hence, in order to produce the same scalar product, power==1. # Hence, in order to produce the same scalar product, power==1.
if self.codomain.harmonic: if self.codomain.harmonic:
fct = self.domain.weight() fct = self.domain.scalar_dvol()
else: else:
fct = 1./(self.codomain.weight()*self.domain.dim) fct = 1./(self.codomain.scalar_dvol()*self.domain.dim)
# Perform the transformation # Perform the transformation
if issubclass(val.dtype.type, np.complexfloating): if issubclass(val.dtype.type, np.complexfloating):
......
...@@ -86,7 +86,7 @@ class GLSpace(Space): ...@@ -86,7 +86,7 @@ class GLSpace(Space):
self._nlat = self._parse_nlat(nlat) self._nlat = self._parse_nlat(nlat)
self._nlon = self._parse_nlon(nlon) self._nlon = self._parse_nlon(nlon)
self._wgt = None self._dvol = None
# ---Mandatory properties and methods--- # ---Mandatory properties and methods---
...@@ -109,16 +109,16 @@ class GLSpace(Space): ...@@ -109,16 +109,16 @@ class GLSpace(Space):
def total_volume(self): def total_volume(self):
return 4 * np.pi return 4 * np.pi
def scalar_weight(self): def scalar_dvol(self):
return None return None
# MR FIXME: this is potentially wasteful, since the return array is # MR FIXME: this is potentially wasteful, since the return array is
# blown up by a factor of self.nlon # blown up by a factor of self.nlon
def weight(self): def dvol(self):
from pyHealpix import GL_weights from pyHealpix import GL_weights
if self._wgt is None: if self._dvol is None:
self._wgt = GL_weights(self.nlat, self.nlon) self._dvol = GL_weights(self.nlat, self.nlon)
return np.repeat(self._wgt, self.nlon) return np.repeat(self._dvol, self.nlon)
# ---Added properties and methods--- # ---Added properties and methods---
......
...@@ -104,10 +104,7 @@ class HPSpace(Space): ...@@ -104,10 +104,7 @@ class HPSpace(Space):
def total_volume(self): def total_volume(self):
return 4 * np.pi return 4 * np.pi
def scalar_weight(self): def scalar_dvol(self):
return np.pi / (3*self._nside*self._nside)
def weight(self):
return np.pi / (3*self._nside*self._nside) return np.pi / (3*self._nside*self._nside)
# ---Added properties and methods--- # ---Added properties and methods---
......
...@@ -114,10 +114,7 @@ class LMSpace(Space): ...@@ -114,10 +114,7 @@ class LMSpace(Space):
# the individual pixels have a fixed volume of 1. # the individual pixels have a fixed volume of 1.
return np.float64(self.dim) return np.float64(self.dim)
def scalar_weight(self): def scalar_dvol(self):
return 1.
def weight(self):
return 1. return 1.
def get_k_length_array(self): def get_k_length_array(self):
......
...@@ -204,10 +204,10 @@ class PowerSpace(Space): ...@@ -204,10 +204,10 @@ class PowerSpace(Space):
# every power-pixel has a volume of 1 # every power-pixel has a volume of 1
return float(reduce(lambda x, y: x*y, self.pindex.shape)) return float(reduce(lambda x, y: x*y, self.pindex.shape))
def scalar_weight(self): def scalar_dvol(self):
return None return None
def weight(self): def dvol(self):
# MR FIXME: this will probably change to 1 soon # MR FIXME: this will probably change to 1 soon
return np.asarray(self.rho, dtype=np.float64) return np.asarray(self.rho, dtype=np.float64)
......
...@@ -87,7 +87,7 @@ class RGSpace(Space): ...@@ -87,7 +87,7 @@ class RGSpace(Space):
self._harmonic = bool(harmonic) self._harmonic = bool(harmonic)
self._shape = self._parse_shape(shape) self._shape = self._parse_shape(shape)
self._distances = self._parse_distances(distances) 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)) self._dim = int(reduce(lambda x, y: x*y, self._shape))
def __repr__(self): def __repr__(self):
...@@ -108,13 +108,10 @@ class RGSpace(Space): ...@@ -108,13 +108,10 @@ class RGSpace(Space):
@property @property
def total_volume(self): def total_volume(self):
return self.dim * self._wgt return self.dim * self._dvol
def scalar_weight(self): def scalar_dvol(self):
return self._wgt return self._dvol
def weight(self):
return self._wgt
def get_k_length_array(self): def get_k_length_array(self):
if (not self.harmonic): if (not self.harmonic):
......
...@@ -41,14 +41,14 @@ CONSTRUCTOR_CONFIGS = [ ...@@ -41,14 +41,14 @@ CONSTRUCTOR_CONFIGS = [
] ]
def get_weight_configs(): def get_dvol_configs():
np.random.seed(42) np.random.seed(42)
wgt = [2.0943951, 2.0943951] wgt = [2.0943951, 2.0943951]
# for GLSpace(nlat=2, nlon=3) # 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))) itertools.repeat(x, 3) for x in wgt)))
return [ return [
[1, weight_0], [1, dvol_0],
] ]
...@@ -73,6 +73,6 @@ class GLSpaceFunctionalityTests(unittest.TestCase): ...@@ -73,6 +73,6 @@ class GLSpaceFunctionalityTests(unittest.TestCase):
for key, value in expected.items(): for key, value in expected.items():
assert_equal(getattr(g, key), value) assert_equal(getattr(g, key), value)
@expand(get_weight_configs()) @expand(get_dvol_configs())
def test_weight(self, power, expected): def test_dvol(self, power, expected):
assert_almost_equal(GLSpace(2).weight(), expected) assert_almost_equal(GLSpace(2).dvol(), expected)
...@@ -72,5 +72,5 @@ class HPSpaceFunctionalityTests(unittest.TestCase): ...@@ -72,5 +72,5 @@ class HPSpaceFunctionalityTests(unittest.TestCase):
for key, value in expected.items(): for key, value in expected.items():
assert_equal(getattr(h, key), value) assert_equal(getattr(h, key), value)
def test_weight(self): def test_dvol(self):
assert_almost_equal(HPSpace(2).weight(), np.pi/12) assert_almost_equal(HPSpace(2).dvol(), np.pi/12)
...@@ -89,8 +89,8 @@ class LMSpaceFunctionalityTests(unittest.TestCase): ...@@ -89,8 +89,8 @@ class LMSpaceFunctionalityTests(unittest.TestCase):
for key, value in expected.items(): for key, value in expected.items():
assert_equal(getattr(l, key), value) assert_equal(getattr(l, key), value)
def test_weight(self): def test_dvol(self):
assert_almost_equal(LMSpace(5).weight(), 1.) assert_almost_equal(LMSpace(5).dvol(), 1.)
@expand(get_k_length_array_configs()) @expand(get_k_length_array_configs())
def test_k_length_array(self, lmax, expected): def test_k_length_array(self, lmax, expected):
......
...@@ -129,6 +129,6 @@ class PowerSpaceFunctionalityTest(unittest.TestCase): ...@@ -129,6 +129,6 @@ class PowerSpaceFunctionalityTest(unittest.TestCase):
p = PowerSpace(harmonic_partner=harmonic_partner) p = PowerSpace(harmonic_partner=harmonic_partner)
assert_almost_equal(p.get_k_length_array(), expected) 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)) p = PowerSpace(harmonic_partner=RGSpace(10,harmonic=True))
assert_almost_equal(p.weight(),p.rho) assert_almost_equal(p.dvol(),p.rho)
...@@ -88,7 +88,7 @@ def get_k_length_array_configs(): ...@@ -88,7 +88,7 @@ def get_k_length_array_configs():
] ]
def get_weight_configs(): def get_dvol_configs():
np.random.seed(42) np.random.seed(42)
return [ return [
[(11, 11), None, False, 1], [(11, 11), None, False, 1],
...@@ -122,7 +122,7 @@ class RGSpaceFunctionalityTests(unittest.TestCase): ...@@ -122,7 +122,7 @@ class RGSpaceFunctionalityTests(unittest.TestCase):
r = RGSpace(shape=shape, distances=distances, harmonic=True) r = RGSpace(shape=shape, distances=distances, harmonic=True)
assert_almost_equal(r.get_k_length_array(), expected) assert_almost_equal(r.get_k_length_array(), expected)
@expand(get_weight_configs()) @expand(get_dvol_configs())
def test_weight(self, shape, distances, harmonic, power): def test_dvol(self, shape, distances, harmonic, power):
r = RGSpace(shape=shape, distances=distances, harmonic=harmonic) 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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment