Commit 6ad2e1ec authored by Martin Reinecke's avatar Martin Reinecke
Browse files

renamings

parent 63eb16f4
Pipeline #24332 passed with stage
in 5 minutes and 53 seconds
...@@ -58,7 +58,7 @@ if __name__ == "__main__": ...@@ -58,7 +58,7 @@ if __name__ == "__main__":
data_domain = R.target[0] data_domain = R.target[0]
noiseless_data = R(mock_signal) noiseless_data = R(mock_signal)
noise_amplitude = noiseless_data.std()/signal_to_noise noise_amplitude = noiseless_data.val.std()/signal_to_noise
N = ift.DiagonalOperator( N = ift.DiagonalOperator(
ift.Field.full(data_domain, noise_amplitude**2)) ift.Field.full(data_domain, noise_amplitude**2))
noise = ift.Field.from_random( noise = ift.Field.from_random(
......
...@@ -2,10 +2,9 @@ from .version import __version__ ...@@ -2,10 +2,9 @@ from .version import __version__
from . import dobj from . import dobj
from .domain_object import DomainObject from .spaces.domain import Domain
from .spaces.unstructured_domain import UnstructuredDomain
from .spaces.field_array import FieldArray from .spaces.structured_domain import StructuredDomain
from .spaces.space import Space
from .spaces.rg_space import RGSpace from .spaces.rg_space import RGSpace
from .spaces.lm_space import LMSpace from .spaces.lm_space import LMSpace
from .spaces.hp_space import HPSpace from .spaces.hp_space import HPSpace
...@@ -55,7 +54,7 @@ from .sugar import * ...@@ -55,7 +54,7 @@ from .sugar import *
from .plotting.plot import plot from .plotting.plot import plot
from . import library from . import library
__all__ = ["DomainObject", "FieldArray", "Space", "RGSpace", "LMSpace", __all__ = ["Domain", "UnstructuredDomain", "StructuredDomain", "RGSpace", "LMSpace",
"HPSpace", "GLSpace", "DOFSpace", "PowerSpace", "DomainTuple", "HPSpace", "GLSpace", "DOFSpace", "PowerSpace", "DomainTuple",
"LinearOperator", "EndomorphicOperator", "ScalingOperator", "LinearOperator", "EndomorphicOperator", "ScalingOperator",
"DiagonalOperator", "FFTOperator", "FFTSmoothingOperator", "DiagonalOperator", "FFTOperator", "FFTSmoothingOperator",
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
# and financially supported by the Studienstiftung des deutschen Volkes. # and financially supported by the Studienstiftung des deutschen Volkes.
from functools import reduce from functools import reduce
from .domain_object import DomainObject from .spaces.domain import Domain
class DomainTuple(object): class DomainTuple(object):
...@@ -28,12 +28,10 @@ class DomainTuple(object): ...@@ -28,12 +28,10 @@ class DomainTuple(object):
self._axtuple = self._get_axes_tuple() self._axtuple = self._get_axes_tuple()
shape_tuple = tuple(sp.shape for sp in self._dom) shape_tuple = tuple(sp.shape for sp in self._dom)
self._shape = reduce(lambda x, y: x + y, shape_tuple, ()) self._shape = reduce(lambda x, y: x + y, shape_tuple, ())
self._dim = reduce(lambda x, y: x * y, self._shape, 1) self._size = reduce(lambda x, y: x * y, self._shape, 1)
self._accdims = (1,)
prod = 1 prod = 1
for dom in self._dom: for dom in self._dom:
prod *= dom.dim prod *= dom.size
self._accdims += (prod,)
def _get_axes_tuple(self): def _get_axes_tuple(self):
i = 0 i = 0
...@@ -60,16 +58,16 @@ class DomainTuple(object): ...@@ -60,16 +58,16 @@ class DomainTuple(object):
def _parse_domain(domain): def _parse_domain(domain):
if domain is None: if domain is None:
return () return ()
if isinstance(domain, DomainObject): if isinstance(domain, Domain):
return (domain,) return (domain,)
if not isinstance(domain, tuple): if not isinstance(domain, tuple):
domain = tuple(domain) domain = tuple(domain)
for d in domain: for d in domain:
if not isinstance(d, DomainObject): if not isinstance(d, Domain):
raise TypeError( raise TypeError(
"Given object contains something that is not an " "Given object contains something that is not an "
"instance of DomainObject class.") "instance of Domain class.")
return domain return domain
def __getitem__(self, i): def __getitem__(self, i):
...@@ -80,8 +78,8 @@ class DomainTuple(object): ...@@ -80,8 +78,8 @@ class DomainTuple(object):
return self._shape return self._shape
@property @property
def dim(self): def size(self):
return self._dim return self._size
@property @property
def axes(self): def axes(self):
......
...@@ -35,7 +35,7 @@ class Field(object): ...@@ -35,7 +35,7 @@ class Field(object):
Parameters Parameters
---------- ----------
domain : None, DomainTuple, tuple of DomainObjects, or single DomainObject domain : None, DomainTuple, tuple(Domain), or Domain
val : None, Field, data_object, or scalar val : None, Field, data_object, or scalar
The values the array should contain after init. A scalar input will The values the array should contain after init. A scalar input will
...@@ -156,7 +156,7 @@ class Field(object): ...@@ -156,7 +156,7 @@ class Field(object):
'pm1', 'normal', 'uniform' are the supported arguments for this 'pm1', 'normal', 'uniform' are the supported arguments for this
method. method.
domain : DomainObject domain : DomainTuple
The domain of the output random field The domain of the output random field
dtype : type dtype : type
...@@ -201,7 +201,7 @@ class Field(object): ...@@ -201,7 +201,7 @@ class Field(object):
return self._domain.shape return self._domain.shape
@property @property
def dim(self): def size(self):
""" Returns the total number of pixel-dimensions the field has. """ Returns the total number of pixel-dimensions the field has.
Effectively, all values from shape are multiplied. Effectively, all values from shape are multiplied.
...@@ -211,7 +211,7 @@ class Field(object): ...@@ -211,7 +211,7 @@ class Field(object):
out : int out : int
The dimension of the Field. The dimension of the Field.
""" """
return self._domain.dim return self._domain.size
@property @property
def real(self): def real(self):
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
# and financially supported by the Studienstiftung des deutschen Volkes. # and financially supported by the Studienstiftung des deutschen Volkes.
from ..field import Field from ..field import Field
from ..spaces.field_array import FieldArray from ..spaces.unstructured_domain import UnstructuredDomain
from ..domain_tuple import DomainTuple from ..domain_tuple import DomainTuple
from .linear_operator import LinearOperator from .linear_operator import LinearOperator
from .fft_smoothing_operator import FFTSmoothingOperator from .fft_smoothing_operator import FFTSmoothingOperator
...@@ -30,7 +30,7 @@ class GeometryRemover(LinearOperator): ...@@ -30,7 +30,7 @@ class GeometryRemover(LinearOperator):
def __init__(self, domain): def __init__(self, domain):
super(GeometryRemover, self).__init__() super(GeometryRemover, self).__init__()
self._domain = DomainTuple.make(domain) self._domain = DomainTuple.make(domain)
target_list = [FieldArray(dom.shape) for dom in self._domain] target_list = [UnstructuredDomain(dom.shape) for dom in self._domain]
self._target = DomainTuple.make(target_list) self._target = DomainTuple.make(target_list)
@property @property
......
...@@ -17,10 +17,10 @@ ...@@ -17,10 +17,10 @@
# and financially supported by the Studienstiftung des deutschen Volkes. # and financially supported by the Studienstiftung des deutschen Volkes.
import numpy as np import numpy as np
from .space import Space from .structured_domain import StructuredDomain
class DOFSpace(Space): class DOFSpace(StructuredDomain):
def __init__(self, dof_weights): def __init__(self, dof_weights):
super(DOFSpace, self).__init__() super(DOFSpace, self).__init__()
self._dvol = tuple(dof_weights) self._dvol = tuple(dof_weights)
...@@ -35,7 +35,7 @@ class DOFSpace(Space): ...@@ -35,7 +35,7 @@ class DOFSpace(Space):
return (len(self._dvol),) return (len(self._dvol),)
@property @property
def dim(self): def size(self):
return len(self._dvol) return len(self._dvol)
def scalar_dvol(self): def scalar_dvol(self):
......
...@@ -16,19 +16,15 @@ ...@@ -16,19 +16,15 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik # NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes. # and financially supported by the Studienstiftung des deutschen Volkes.
from __future__ import division
import abc import abc
from .utilities import NiftyMeta from ..utilities import NiftyMeta
from future.utils import with_metaclass from future.utils import with_metaclass
import numpy as np import numpy as np
class DomainObject(with_metaclass( class Domain(with_metaclass(
NiftyMeta, type('NewBase', (object,), {}))): NiftyMeta, type('NewBase', (object,), {}))):
"""The abstract class that can be used as a domain for a field. """The abstract class repesenting a (structured or unstructured) domain.
This holds all the information and functionality a field needs to know
about its domain and how the data of the field are stored.
""" """
def __init__(self): def __init__(self):
...@@ -45,16 +41,16 @@ class DomainObject(with_metaclass( ...@@ -45,16 +41,16 @@ class DomainObject(with_metaclass(
return result_hash return result_hash
def __eq__(self, x): def __eq__(self, x):
"""Checks if two domain_objects are equal. """Checks if two domains are equal.
Parameters Parameters
---------- ----------
x: domain_object x: Domain
The domain_object `self` is compared to. The domain `self` is compared to.
Returns Returns
------- -------
bool: True iff `self` and x describe the same manifold. bool: True iff `self` and x describe the same domain.
""" """
if self is x: # shortcut for simple case if self is x: # shortcut for simple case
return True return True
...@@ -70,47 +66,22 @@ class DomainObject(with_metaclass( ...@@ -70,47 +66,22 @@ class DomainObject(with_metaclass(
@abc.abstractproperty @abc.abstractproperty
def shape(self): def shape(self):
"""The domain-object's shape contribution to the underlying array. """The shape of the array-like object required to store information
living on the domain.
Returns Returns
------- -------
tuple of ints: shape of the underlying array-like object tuple of ints: shape of the required array-like object
""" """
raise NotImplementedError raise NotImplementedError
@abc.abstractproperty @abc.abstractproperty
def dim(self): def size(self):
""" Returns the number of pixel-dimensions the object has. """Number of data elements associated with this domain.
Equivalent to the products over all entries in the domain's shape.
Returns
-------
int: number of pixels
"""
raise NotImplementedError
@abc.abstractmethod
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.
Returns Returns
------- -------
float or None: Volume factor int: number of data elements
""" """
raise NotImplementedError raise NotImplementedError
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`.
Returns
-------
float or numpy.ndarray(dtype=float): Volume factors
"""
return self.scalar_dvol()
def total_volume(self):
tmp = self.dvol()
return self.dim * tmp if np.isscalar(tmp) else np.sum(tmp)
...@@ -18,10 +18,10 @@ ...@@ -18,10 +18,10 @@
from __future__ import division from __future__ import division
import numpy as np import numpy as np
from .space import Space from .structured_domain import StructuredDomain
class GLSpace(Space): class GLSpace(StructuredDomain):
"""NIFTy subclass for Gauss-Legendre pixelizations [#]_ of the two-sphere. """NIFTy subclass for Gauss-Legendre pixelizations [#]_ of the two-sphere.
Parameters Parameters
...@@ -79,7 +79,7 @@ class GLSpace(Space): ...@@ -79,7 +79,7 @@ class GLSpace(Space):
return (np.int((self.nlat * self.nlon)),) return (np.int((self.nlat * self.nlon)),)
@property @property
def dim(self): def size(self):
return np.int((self.nlat * self.nlon)) return np.int((self.nlat * self.nlon))
def scalar_dvol(self): def scalar_dvol(self):
......
...@@ -18,10 +18,10 @@ ...@@ -18,10 +18,10 @@
from __future__ import division from __future__ import division
import numpy as np import numpy as np
from .space import Space from .structured_domain import StructuredDomain
class HPSpace(Space): class HPSpace(StructuredDomain):
"""NIFTy subclass for HEALPix discretizations of the two-sphere [#]_. """NIFTy subclass for HEALPix discretizations of the two-sphere [#]_.
Parameters Parameters
...@@ -65,10 +65,10 @@ class HPSpace(Space): ...@@ -65,10 +65,10 @@ class HPSpace(Space):
@property @property
def shape(self): def shape(self):
return (self.dim,) return (self.size,)
@property @property
def dim(self): def size(self):
return np.int(12 * self.nside * self.nside) return np.int(12 * self.nside * self.nside)
def scalar_dvol(self): def scalar_dvol(self):
......
...@@ -18,12 +18,12 @@ ...@@ -18,12 +18,12 @@
from __future__ import division from __future__ import division
import numpy as np import numpy as np
from .space import Space from .structured_domain import StructuredDomain
from ..field import Field, exp from ..field import Field, exp
from .. import dobj from .. import dobj
class LMSpace(Space): class LMSpace(StructuredDomain):
"""NIFTy subclass for spherical harmonics components, for representations """NIFTy subclass for spherical harmonics components, for representations
of fields on the two-sphere. of fields on the two-sphere.
...@@ -75,10 +75,10 @@ class LMSpace(Space): ...@@ -75,10 +75,10 @@ class LMSpace(Space):
@property @property
def shape(self): def shape(self):
return (self.dim, ) return (self.size, )
@property @property
def dim(self): def size(self):
l = self._lmax l = self._lmax
m = self._mmax m = self._mmax
# the LMSpace consists of the full triangle (including -m's!), # the LMSpace consists of the full triangle (including -m's!),
...@@ -91,7 +91,7 @@ class LMSpace(Space): ...@@ -91,7 +91,7 @@ class LMSpace(Space):
def get_k_length_array(self): def get_k_length_array(self):
lmax = self._lmax lmax = self._lmax
mmax = self._mmax mmax = self._mmax
ldist = np.empty((self.dim,), dtype=np.float64) ldist = np.empty((self.size,), dtype=np.float64)
ldist[0:lmax+1] = np.arange(lmax+1, dtype=np.float64) ldist[0:lmax+1] = np.arange(lmax+1, dtype=np.float64)
tmp = np.empty((2*lmax+2), dtype=np.float64) tmp = np.empty((2*lmax+2), dtype=np.float64)
tmp[0::2] = np.arange(lmax+1) tmp[0::2] = np.arange(lmax+1)
......
...@@ -17,11 +17,11 @@ ...@@ -17,11 +17,11 @@
# and financially supported by the Studienstiftung des deutschen Volkes. # and financially supported by the Studienstiftung des deutschen Volkes.
import numpy as np import numpy as np
from .space import Space from .structured_domain import StructuredDomain
from .. import dobj from .. import dobj
class PowerSpace(Space): class PowerSpace(StructuredDomain):
"""NIFTy class for spaces of power spectra. """NIFTy class for spaces of power spectra.
A power space is the result of a projection of a harmonic space where A power space is the result of a projection of a harmonic space where
...@@ -90,7 +90,7 @@ class PowerSpace(Space): ...@@ -90,7 +90,7 @@ class PowerSpace(Space):
@staticmethod @staticmethod
def useful_binbounds(space, logarithmic, nbin=None): def useful_binbounds(space, logarithmic, nbin=None):
if not (isinstance(space, Space) and space.harmonic): if not (isinstance(space, StructuredDomain) and space.harmonic):
raise ValueError("first argument must be a harmonic space.") raise ValueError("first argument must be a harmonic space.")
if logarithmic is None and nbin is None: if logarithmic is None and nbin is None:
return None return None
...@@ -122,7 +122,7 @@ class PowerSpace(Space): ...@@ -122,7 +122,7 @@ class PowerSpace(Space):
super(PowerSpace, self).__init__() super(PowerSpace, self).__init__()
self._needed_for_hash += ['_harmonic_partner', '_binbounds'] self._needed_for_hash += ['_harmonic_partner', '_binbounds']
if not (isinstance(harmonic_partner, Space) and if not (isinstance(harmonic_partner, StructuredDomain) and
harmonic_partner.harmonic): harmonic_partner.harmonic):
raise ValueError("harmonic_partner must be a harmonic space.") raise ValueError("harmonic_partner must be a harmonic space.")
if harmonic_partner.scalar_dvol() is None: if harmonic_partner.scalar_dvol() is None:
...@@ -180,7 +180,7 @@ class PowerSpace(Space): ...@@ -180,7 +180,7 @@ class PowerSpace(Space):
return self.k_lengths.shape return self.k_lengths.shape
@property @property
def dim(self): def size(self):
return self.shape[0] return self.shape[0]
def scalar_dvol(self): def scalar_dvol(self):
......
...@@ -20,13 +20,13 @@ from __future__ import division ...@@ -20,13 +20,13 @@ from __future__ import division
from builtins import range from builtins import range
from functools import reduce from functools import reduce
import numpy as np import numpy as np
from .space import Space from .structured_domain import StructuredDomain
from ..field import Field, exp from ..field import Field, exp
from .. import dobj from .. import dobj
class RGSpace(Space): class RGSpace(StructuredDomain):
"""NIFTy subclass for spaces of regular Cartesian grids. """NIFTy subclass for regular Cartesian grids.
Parameters Parameters
---------- ----------
...@@ -66,7 +66,7 @@ class RGSpace(Space): ...@@ -66,7 +66,7 @@ class RGSpace(Space):
self._distances = tuple(temp) self._distances = tuple(temp)
self._dvol = 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._size = int(reduce(lambda x, y: x*y, self._shape))
def __repr__(self): def __repr__(self):
return ("RGSpace(shape=%r, distances=%r, harmonic=%r)" return ("RGSpace(shape=%r, distances=%r, harmonic=%r)"
...@@ -81,8 +81,8 @@ class RGSpace(Space): ...@@ -81,8 +81,8 @@ class RGSpace(Space):
return self._shape return self._shape
@property @property
def dim(self): def size(self):
return self._dim return self._size
def scalar_dvol(self): def scalar_dvol(self):
return self._dvol return self._dvol
......
...@@ -17,28 +17,56 @@ ...@@ -17,28 +17,56 @@
# and financially supported by the Studienstiftung des deutschen Volkes. # and financially supported by the Studienstiftung des deutschen Volkes.
import abc import abc
from ..domain_object import DomainObject from .domain import Domain
import numpy as np