Commit 3f210e87 authored by Martin Reinecke's avatar Martin Reinecke

Merge branch 'proj_to_dist' into 'NIFTy_4'

Rename projection operators to distributors

See merge request ift/NIFTy!224
parents e8fbf7e7 75d8fd5b
Pipeline #24975 passed with stages
in 6 minutes and 39 seconds
......@@ -60,9 +60,8 @@ if __name__ == "__main__":
d_space = MeasurementOperator.target
Projection = ift.PowerProjectionOperator(domain=h_space,
power_space=p_space)
power = Projection.adjoint_times(ift.exp(0.5*log_p))
Distributor = ift.PowerDistributor(target=h_space, power_space=p_space)
power = Distributor(ift.exp(0.5*log_p))
# Creating the mock data
true_sky = nonlinearity(HT(power*sh))
noiseless_data = MeasurementOperator(true_sky)
......@@ -76,7 +75,7 @@ if __name__ == "__main__":
m0 = ift.power_synthesize(ift.Field(p_space, val=1e-7))
t0 = ift.Field(p_space, val=-4.)
power0 = Projection.adjoint_times(ift.exp(0.5 * t0))
power0 = Distributor.times(ift.exp(0.5 * t0))
IC1 = ift.GradientNormController(name="IC1", iteration_limit=100,
tol_abs_gradnorm=1e-3)
......@@ -88,7 +87,7 @@ if __name__ == "__main__":
inverter = ift.ConjugateGradient(controller=ICI)
for i in range(20):
power0 = Projection.adjoint_times(ift.exp(0.5*t0))
power0 = Distributor(ift.exp(0.5*t0))
map0_energy = ift.library.NonlinearWienerFilterEnergy(
m0, d, MeasurementOperator, nonlinearity, HT, power0, N, S,
inverter=inverter)
......@@ -104,7 +103,7 @@ if __name__ == "__main__":
power0_energy = ift.library.NonlinearPowerEnergy(
position=t0, d=d, N=N, xi=m0, D=D0, ht=HT,
Instrument=MeasurementOperator, nonlinearity=nonlinearity,
Projection=Projection, sigma=1., samples=2, inverter=inverter)
Distribution=Distributor, sigma=1., samples=2, inverter=inverter)
power0_energy = minimizer(power0_energy)[0]
......
......@@ -71,6 +71,7 @@ if __name__ == "__main__":
zmax = max(ht(sh).max(), ht(m).max())
zmin = min(ht(sh).min(), ht(m).min())
plotdict = {"zmax": zmax, "zmin": zmin, "colormap": "Planck-like"}
plotdict2 = {"colormap": "Planck-like"}
ift.plot(ht(sh), name="mock_signal.png", **plotdict)
ift.plot(ht(m), name="reconstruction.png", **plotdict)
......@@ -79,7 +80,7 @@ if __name__ == "__main__":
sample_mean = ift.Field.zeros(s_space)
mean, variance = ift.probe_with_posterior_samples(curv, ht, 50)
ift.plot(variance, name="posterior_variance.png", **plotdict)
ift.plot(variance, name="posterior_variance.png", **plotdict2)
ift.plot(mean+ht(m), name="posterior_mean.png", **plotdict)
# try to do the same with diagonal probing
......
......@@ -6,7 +6,7 @@ NIFTy's domain classes
**Abstract base class**
:py:class:`Domain` is the abstract ancestor for all of NIFTy's domains.
:class:`Domain` is the abstract ancestor for all of NIFTy's domains.
.. toctree::
:maxdepth: 1
......@@ -21,7 +21,7 @@ associated with them, like position in space and volume factors),
or *unstructured* (meaning that the data points have no associated manifold).
Unstructured domains can be described by instances of NIFTy's
:py:class:`UnstructuredDomain` class.
:class:`UnstructuredDomain` class.
.. toctree::
:maxdepth: 1
......@@ -34,24 +34,24 @@ Unstructured domains can be described by instances of NIFTy's
In contrast to unstructured domains, these domains have an assigned geometry.
NIFTy requires these domains to provide the volume elements of their grid cells.
The additional methods are described in the abstract class
:py:class:`StructuredDomain`.
:class:`StructuredDomain`.
.. toctree::
:maxdepth: 1
StructuredDomain <../mod/nifty4.domains.structured_domain>
NIFTy comes with several concrete subclasses of :py:class:`StructuredDomain`.
NIFTy comes with several concrete subclasses of :class:`StructuredDomain`.
:py:class:`RGSpace` represents a regular Cartesian grid with an arbitrary
:class:`RGSpace` represents a regular Cartesian grid with an arbitrary
number of dimensions, which is supposed to be periodic in each dimension.
This domain can be constructed to represent either position or harmonic space.
:py:class:`HPSpace` and :py:class:`GLSpace` describe pixelisations of the
2-sphere; their counterpart in harmonic space is :py:class:`LMSpace`, which
:class:`HPSpace` and :class:`GLSpace` describe pixelisations of the
2-sphere; their counterpart in harmonic space is :class:`LMSpace`, which
contains spherical harmonic coefficients.
:py:class:`PowerSpace` is used to describe one-dimensional power spectra.
:class:`PowerSpace` is used to describe one-dimensional power spectra.
.. toctree::
:maxdepth: 1
......
......@@ -12,7 +12,7 @@ Description of Operators
ScalingOperator <../mod/nifty4.operators.scaling_operator>
DiagonalOperator <../mod/nifty4.operators.diagonal_operator>
HarmonicTransformOperator <../mod/nifty4.operators.harmonic_transform_operator>
PowerProjectionOperator <../mod/nifty4.operators.power_projection_operator>
PowerDistributor <../mod/nifty4.operators.power_distributor>
.. toctree::
:maxdepth: 1
......@@ -26,7 +26,7 @@ Description of Operators
.. Adjoint <../mod/nifty4.operators.adjoint_operator>
.. Chain <../mod/nifty4.operators.chain_operator>
.. DOF Projection <../mod/nifty4.operators.dof_projection_operator>
.. DOF Distributor <../mod/nifty4.operators.dof_distributor>
.. Inverse <../mod/nifty4.operators.inverse_operator>
.. Laplace <../mod/nifty4.operators.linear_operator>
.. Sum <../mod/nifty4.operators.sum_operator>
......@@ -3,9 +3,6 @@
First steps -- An informal introduction
=======================================
NIFTy4 Tutorial
---------------
.. currentmodule:: nifty4
.. automodule:: nifty4
......@@ -42,61 +39,61 @@ Domains
.......
One of the fundamental building blocks of the NIFTy4 framework is the *domain*.
Its required capabilities are expressed by the abstract :py:class:`Domain` class.
Its required capabilities are expressed by the abstract :class:`Domain` class.
A domain must be able to answer the following queries:
- its total number of data entries (pixels)
- the shape of the array that is supposed to hold them
- equality/inequality to another :py:class:`Domain` instance
- equality/inequality to another :class:`Domain` instance
Unstructured domains
....................
There are domains (e.g. the data domain) which have no geometry associated to the individual data values.
In NIFTy4 they are represented by the :py:class:`UnstructuredDomain` class, which is derived from
:py:class:`Domain`.
In NIFTy4 they are represented by the :class:`UnstructuredDomain` class, which is derived from
:class:`Domain`.
Structured domains
..................
All domains defined on a geometrical manifold are derived from :py:class:`StructuredDomain` (which is in turn derived from :py:class:`Domain`).
All domains defined on a geometrical manifold are derived from :class:`StructuredDomain` (which is in turn derived from :class:`Domain`).
In addition to the capabilities of :py:class:`Domain`, :py:class:`StructuredDomain` offers the following functionality:
In addition to the capabilities of :class:`Domain`, :class:`StructuredDomain` offers the following functionality:
- methods returing the pixel volume(s) and the total volume
- a :py:attr:`harmonic` property
- methods :meth:`~StructuredDomain.scalar_dvol`, :meth:`~StructuredDomain.dvol`, and :meth:`~StructuredDomain.total_volume` returning the pixel volume(s) and the total volume
- a :attr:`~StructuredDomain.harmonic` property
- (iff the domain is harmonic) some methods concerned with Gaussian convolution and the absolute distances of the individual grid cells from the origin
Examples for structured domains are
- :py:class:`RGSpace` (an equidistant Cartesian grid with a user-definable number of dimensions),
- :py:class:`GLSpace` (a Gauss-Legendre grid on the sphere), and
- :py:class:`LMSpace` (a grid storing spherical harmonic coefficients).
- :class:`RGSpace` (an equidistant Cartesian grid with a user-definable number of dimensions),
- :class:`GLSpace` (a Gauss-Legendre grid on the sphere), and
- :class:`LMSpace` (a grid storing spherical harmonic coefficients).
Among these, :py:class:`RGSpace` can be harmonic or not (depending on constructor arguments), :py:class:`GLSpace` is a pure position domain (i.e. nonharmonic), and :py:class:`LMSpace` is always harmonic.
Among these, :class:`RGSpace` can be harmonic or not (depending on constructor arguments), :class:`GLSpace` is a pure position domain (i.e. nonharmonic), and :class:`LMSpace` is always harmonic.
Combinations of domains
.......................
A field can live on a single domain, but it can also live on a product of domains (or no domain at all, in which case it is a scalar).
The tuple of domain on which a field lives is described by the :py:class:`DomainTuple` class.
A :py:class:`DomainTuple` object can be constructed from
The tuple of domain on which a field lives is described by the :class:`DomainTuple` class.
A :class:`DomainTuple` object can be constructed from
- a single instance of anything derived from :py:class:`Domain`
- a single instance of anything derived from :class:`Domain`
- a tuple of such instances (possibly empty)
- another :py:class:`DomainTuple` object
- another :class:`DomainTuple` object
.. _fields:
Fields
......
A :py:class:`Field` object consists of the following components:
A :class:`Field` object consists of the following components:
- a domain in form of a :py:class:`DomainTuple` object
- a domain in form of a :class:`DomainTuple` object
- a data type (e.g. numpy.float64)
- an array containing the actual values
......@@ -107,8 +104,8 @@ Fields support arithmetic operations, contractions, etc.
Linear Operators
................
A linear operator (represented by NIFTy4's abstract :py:class:`LinearOperator` class) can be interpreted as an (implicitly defined) matrix.
It can be applied to :py:class:`Field` instances, resulting in other :py:class:`Field` instances that potentially live on other domains.
A linear operator (represented by NIFTy4's abstract :class:`LinearOperator` class) can be interpreted as an (implicitly defined) matrix.
It can be applied to :class:`Field` instances, resulting in other :class:`Field` instances that potentially live on other domains.
There are four basic ways of applying an operator :math:`A` to a field :math:`f`:
......@@ -123,14 +120,14 @@ Operator classes defined in NIFTy may implement an arbitrary subset of these fou
If needed, the set of supported operations can be enhanced by iterative inversion methods;
for example, an operator defining direct and adjoint multiplication, could be enhanced to support the complete set by this method.
There are two domains associated with a :py:class:`LinearOperator`: a *domain* and a *target*.
There are two domains associated with a :class:`LinearOperator`: a *domain* and a *target*.
Direct multiplication and adjoint inverse multiplication transform a field living on the operator's *domain* to one living on the operator's *target*, whereas adjoint multiplication and inverse multiplication transform from *target* to *domain*.
Operators with identical domain and target can be derived from :py:class:`EndomorphicOperator`;
typical examples for this category are the :py:class:`ScalingOperator`, which simply multiplies its input by a scalar value, and :py:class:`DiagonalOperator`, which multiplies every value of its input field with potentially different values.
Operators with identical domain and target can be derived from :class:`EndomorphicOperator`;
typical examples for this category are the :class:`ScalingOperator`, which simply multiplies its input by a scalar value, and :class:`DiagonalOperator`, which multiplies every value of its input field with potentially different values.
Nifty4 allows simple and intuitive construction of combined operators.
As an example, if ``A``, ``B`` and ``C`` are of type :py:class:`LinearOperator` and ``f1`` and ``f2`` are :py:class:`Field` s, writing::
As an example, if ``A``, ``B`` and ``C`` are of type :class:`LinearOperator` and ``f1`` and ``f2`` are :class:`Field` s, writing::
X = A*B.inverse*A.adjoint + C
f2 = X(f1)
......@@ -146,11 +143,11 @@ Minimization
Most problems in IFT are solved by (possibly nested) minimizations of high-dimensional functions, which are often nonlinear.
In NIFTy4 such functions are represented by objects of type :py:class:`Energy`.
In NIFTy4 such functions are represented by objects of type :class:`Energy`.
These hold the prescription how to calculate the function's value, gradient and (optionally) curvature at any given position.
Function values are floating-point scalars, gradients have the form of fields living on the energy's position domain, and curvatures are represented by linear operator objects.
Some examples of concrete energy classes delivered with NIFTy4 are :py:class:`QuadraticEnergy` (with position-independent curvature, mainly used with conjugate gradient minimization) and :py:class:`WienerFilterEnergy`.
Some examples of concrete energy classes delivered with NIFTy4 are :class:`QuadraticEnergy` (with position-independent curvature, mainly used with conjugate gradient minimization) and :class:`WienerFilterEnergy`.
Energies are classes that typically have to be provided by the user when tackling new IFT problems.
The minimization procedure can be carried out by one of several algorithms; NIFTy4 currently ships solvers based on
......
......@@ -18,7 +18,7 @@
from ..minimization.energy import Energy
from ..operators.smoothness_operator import SmoothnessOperator
from ..operators.power_projection_operator import PowerProjectionOperator
from ..operators.power_distributor import PowerDistributor
from .critical_power_curvature import CriticalPowerCurvature
from ..utilities import memo
from .. import Field, exp
......@@ -87,17 +87,17 @@ class CriticalPowerEnergy(Energy):
self._inverter = inverter
if w is None:
P = PowerProjectionOperator(domain=self.m.domain,
power_space=self.position.domain[0])
Dist = PowerDistributor(target=self.m.domain,
power_space=self.position.domain[0])
if self.D is not None:
w = Field.zeros(self.position.domain, dtype=self.m.dtype)
for i in range(self.samples):
sample = self.D.draw_sample() + self.m
w += P(abs(sample)**2)
w += Dist.adjoint_times(abs(sample)**2)
w *= 1./self.samples
else:
w = P(abs(self.m)**2)
w = Dist.adjoint_times(abs(self.m)**2)
self._w = w
self._theta = exp(-self.position) * (self.q + self._w*0.5)
......
......@@ -25,7 +25,7 @@ from ..minimization.energy import Energy
class NoiseEnergy(Energy):
def __init__(self, position, d, xi, D, t, ht, Instrument,
nonlinearity, alpha, q, Projection, samples=3,
nonlinearity, alpha, q, Distribution, samples=3,
xi_sample_list=None, inverter=None):
super(NoiseEnergy, self).__init__(position=position)
self.xi = xi
......@@ -40,8 +40,8 @@ class NoiseEnergy(Energy):
self.alpha = alpha
self.q = q
self.Projection = Projection
self.power = self.Projection.adjoint_times(exp(0.5 * self.t))
self.Distribution = Distribution
self.power = self.Distribution(exp(0.5 * self.t))
if xi_sample_list is None:
if samples is None or samples == 0:
xi_sample_list = [xi]
......@@ -51,7 +51,7 @@ class NoiseEnergy(Energy):
self.xi_sample_list = xi_sample_list
self.inverter = inverter
A = Projection.adjoint_times(exp(.5*self.t))
A = Distribution(exp(.5*self.t))
self._gradient = None
for sample in self.xi_sample_list:
......@@ -81,7 +81,7 @@ class NoiseEnergy(Energy):
return self.__class__(
position, self.d, self.xi, self.D, self.t, self.ht,
self.Instrument, self.nonlinearity, self.alpha, self.q,
self.Projection, xi_sample_list=self.xi_sample_list,
self.Distribution, xi_sample_list=self.xi_sample_list,
samples=self.samples, inverter=self.inverter)
@property
......
......@@ -20,12 +20,12 @@ from ..operators.inversion_enabler import InversionEnabler
from .response_operators import LinearizedPowerResponse
def NonlinearPowerCurvature(tau, ht, Instrument, nonlinearity, Projection, N,
def NonlinearPowerCurvature(tau, ht, Instrument, nonlinearity, Distribution, N,
T, xi_sample_list, inverter):
result = None
for xi_sample in xi_sample_list:
LinearizedResponse = LinearizedPowerResponse(
Instrument, nonlinearity, ht, Projection, tau, xi_sample)
Instrument, nonlinearity, ht, Distribution, tau, xi_sample)
op = LinearizedResponse.adjoint*N.inverse*LinearizedResponse
result = op if result is None else result + op
result = result*(1./len(xi_sample_list)) + T
......
......@@ -52,7 +52,7 @@ class NonlinearPowerEnergy(Energy):
"""
def __init__(self, position, d, N, xi, D, ht, Instrument, nonlinearity,
Projection, sigma=0., samples=3, xi_sample_list=None,
Distribution, sigma=0., samples=3, xi_sample_list=None,
inverter=None):
super(NonlinearPowerEnergy, self).__init__(position)
self.xi = xi
......@@ -64,7 +64,7 @@ class NonlinearPowerEnergy(Energy):
self.ht = ht
self.Instrument = Instrument
self.nonlinearity = nonlinearity
self.Projection = Projection
self.Distribution = Distribution
self.sigma = sigma
if xi_sample_list is None:
if samples is None or samples == 0:
......@@ -75,7 +75,7 @@ class NonlinearPowerEnergy(Energy):
self.xi_sample_list = xi_sample_list
self.inverter = inverter
A = Projection.adjoint_times(exp(.5 * position))
A = Distribution(exp(.5 * position))
map_s = self.ht(A * xi)
Tpos = self.T(position)
......@@ -83,7 +83,7 @@ class NonlinearPowerEnergy(Energy):
for xi_sample in self.xi_sample_list:
map_s = self.ht(A * xi_sample)
LinR = LinearizedPowerResponse(
self.Instrument, self.nonlinearity, self.ht, self.Projection,
self.Instrument, self.nonlinearity, self.ht, self.Distribution,
self.position, xi_sample)
residual = self.d - \
......@@ -106,7 +106,7 @@ class NonlinearPowerEnergy(Energy):
def at(self, position):
return self.__class__(position, self.d, self.N, self.xi, self.D,
self.ht, self.Instrument, self.nonlinearity,
self.Projection, sigma=self.sigma,
self.Distribution, sigma=self.sigma,
samples=len(self.xi_sample_list),
xi_sample_list=self.xi_sample_list,
inverter=self.inverter)
......@@ -124,5 +124,5 @@ class NonlinearPowerEnergy(Energy):
def curvature(self):
return NonlinearPowerCurvature(
self.position, self.ht, self.Instrument, self.nonlinearity,
self.Projection, self.N, self.T, self.xi_sample_list,
self.Distribution, self.N, self.T, self.xi_sample_list,
self.inverter)
......@@ -23,8 +23,9 @@ def LinearizedSignalResponse(Instrument, nonlinearity, ht, power, m):
return Instrument * nonlinearity.derivative(m) * ht * power
def LinearizedPowerResponse(Instrument, nonlinearity, ht, Projection, tau, xi):
def LinearizedPowerResponse(Instrument, nonlinearity, ht, Distribution, tau,
xi):
power = exp(0.5*tau)
position = ht(Projection.adjoint_times(power)*xi)
position = ht(Distribution(power)*xi)
linearization = nonlinearity.derivative(position)
return 0.5*Instrument*linearization*ht*xi*Projection.adjoint*power
return 0.5*Instrument*linearization*ht*xi*Distribution*power
......@@ -7,10 +7,10 @@ from .fft_operator import FFTOperator
from .fft_smoothing_operator import FFTSmoothingOperator
from .geometry_remover import GeometryRemover
from .laplace_operator import LaplaceOperator
from .power_projection_operator import PowerProjectionOperator
from .power_distributor import PowerDistributor
from .inversion_enabler import InversionEnabler
__all__ = ["LinearOperator", "EndomorphicOperator", "ScalingOperator",
"DiagonalOperator", "HarmonicTransformOperator", "FFTOperator",
"FFTSmoothingOperator", "GeometryRemover",
"LaplaceOperator", "PowerProjectionOperator", "InversionEnabler"]
"LaplaceOperator", "PowerDistributor", "InversionEnabler"]
......@@ -25,15 +25,15 @@ from .. import dobj
from ..domains.dof_space import DOFSpace
class DOFProjectionOperator(LinearOperator):
def __init__(self, dofdex, domain=None, space=None):
super(DOFProjectionOperator, self).__init__()
class DOFDistributor(LinearOperator):
def __init__(self, dofdex, target=None, space=None):
super(DOFDistributor, self).__init__()
if domain is None:
domain = dofdex.domain
self._domain = DomainTuple.make(domain)
space = infer_space(self._domain, space)
partner = self._domain[space]
if target is None:
target = dofdex.domain
self._target = DomainTuple.make(target)
space = infer_space(self._target, space)
partner = self._target[space]
if not isinstance(dofdex, Field):
raise TypeError("dofdex must be a Field")
if not len(dofdex.domain) == 1:
......@@ -64,41 +64,41 @@ class DOFProjectionOperator(LinearOperator):
def _init2(self, dofdex, space, other_space):
self._space = space
tgt = list(self._domain)
tgt[self._space] = other_space
self._target = DomainTuple.make(tgt)
dom = list(self._target)
dom[self._space] = other_space
self._domain = DomainTuple.make(dom)
if dobj.default_distaxis() in self._domain.axes[self._space]:
dofdex = dobj.local_data(dofdex)
else: # dofdex must be available fully on every task
dofdex = dobj.to_global_data(dofdex)
self._dofdex = dofdex.ravel()
firstaxis = self._domain.axes[self._space][0]
lastaxis = self._domain.axes[self._space][-1]
arrshape = dobj.local_shape(self._domain.shape, 0)
firstaxis = self._target.axes[self._space][0]
lastaxis = self._target.axes[self._space][-1]
arrshape = dobj.local_shape(self._target.shape, 0)
presize = np.prod(arrshape[0:firstaxis], dtype=np.int)
postsize = np.prod(arrshape[lastaxis+1:], dtype=np.int)
self._hshape = (presize, self._target[self._space].shape[0], postsize)
self._hshape = (presize, self._domain[self._space].shape[0], postsize)
self._pshape = (presize, self._dofdex.size, postsize)
def _times(self, x):
def _adjoint_times(self, x):
arr = dobj.local_data(x.val)
arr = arr.reshape(self._pshape)
oarr = np.zeros(self._hshape, dtype=x.dtype)
np.add.at(oarr, (slice(None), self._dofdex, slice(None)), arr)
if dobj.distaxis(x.val) in x.domain.axes[self._space]:
oarr = dobj.np_allreduce_sum(oarr).reshape(self._target.shape)
res = Field(self._target, dobj.from_global_data(oarr))
oarr = dobj.np_allreduce_sum(oarr).reshape(self._domain.shape)
res = Field(self._domain, dobj.from_global_data(oarr))
else:
oarr = oarr.reshape(dobj.local_shape(self._target.shape,
oarr = oarr.reshape(dobj.local_shape(self._domain.shape,
dobj.distaxis(x.val)))
res = Field(self._target,
dobj.from_local_data(self._target.shape, oarr,
res = Field(self._domain,
dobj.from_local_data(self._domain.shape, oarr,
dobj.default_distaxis()))
return res
def _adjoint_times(self, x):
res = Field.empty(self._domain, dtype=x.dtype)
def _times(self, x):
res = Field.empty(self._target, dtype=x.dtype)
if dobj.distaxis(x.val) in x.domain.axes[self._space]:
arr = dobj.to_global_data(x.val)
else:
......
......@@ -16,20 +16,20 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from .dof_projection_operator import DOFProjectionOperator
from .dof_distributor import DOFDistributor
from ..domain_tuple import DomainTuple
from ..utilities import infer_space
from ..domains.power_space import PowerSpace
class PowerProjectionOperator(DOFProjectionOperator):
def __init__(self, domain, power_space=None, space=None):
class PowerDistributor(DOFDistributor):
def __init__(self, target, power_space=None, space=None):
# Initialize domain and target
self._domain = DomainTuple.make(domain)
self._space = infer_space(self._domain, space)
hspace = self._domain[self._space]
self._target = DomainTuple.make(target)
self._space = infer_space(self._target, space)
hspace = self._target[self._space]
if not hspace.harmonic:
raise ValueError("Operator acts on harmonic spaces only")
raise ValueError("Operator requires harmonic target space")
if power_space is None:
power_space = PowerSpace(hspace)
else:
......
......@@ -21,7 +21,7 @@ from .domains.structured_domain import StructuredDomain
from .domains.power_space import PowerSpace
from .field import Field, sqrt
from .operators.diagonal_operator import DiagonalOperator
from .operators.power_projection_operator import PowerProjectionOperator
from .operators.power_distributor import PowerDistributor
from .operators.harmonic_transform_operator import HarmonicTransformOperator
from .domain_tuple import DomainTuple
from . import dobj, utilities
......@@ -45,8 +45,8 @@ def PS_field(pspace, func, dtype=None):
def _single_power_analyze(field, idx, binbounds):
power_domain = PowerSpace(field.domain[idx], binbounds)
ppo = PowerProjectionOperator(field.domain, power_domain, idx)
return ppo(field.weight(1)).weight(-1) # divides by bin size
pd = PowerDistributor(field.domain, power_domain, idx)
return pd.adjoint_times(field.weight(1)).weight(-1) # divides by bin size
def power_analyze(field, spaces=None, binbounds=None,
......@@ -126,8 +126,8 @@ def power_synthesize_nonrandom(field, spaces=None):
spec = sqrt(field)
for i in spaces:
result_domain[i] = field.domain[i].harmonic_partner
ppo = PowerProjectionOperator(result_domain, field.domain[i], i)
spec = ppo.adjoint_times(spec)
pd = PowerDistributor(result_domain, field.domain[i], i)
spec = pd(spec)
return spec
......@@ -204,7 +204,7 @@ def create_power_field(domain, power_spectrum, dtype=None):
power_domain = PowerSpace(domain)
fp = PS_field(power_domain, power_spectrum, dtype)
return PowerProjectionOperator(domain, power_domain).adjoint_times(fp)
return PowerDistributor(domain, power_domain)(fp)
def create_power_operator(domain, power_spectrum, space=None, dtype=None):
......
......@@ -34,8 +34,8 @@ def get_slice_list(shape, axes):
axes: tuple
Axes which should not be iterated over.
Returns
-------
Yields
------
list
The next list of indices and/or slice objects for each dimension.
......
......@@ -11,7 +11,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright(C) 2013-2017 Max-Planck-Society
# Copyright(C) 2013-2018 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
......@@ -39,12 +39,12 @@ class Energy_Tests(unittest.TestCase):
ht = ift.HarmonicTransformOperator(hspace, target=space)
binbounds = ift.PowerSpace.useful_binbounds(hspace, logarithmic=False)
pspace = ift.PowerSpace(hspace, binbounds=binbounds)
P = ift.PowerProjectionOperator(domain=hspace, power_space=pspace)
Dist = ift.PowerDistributor(target=hspace, power_space=pspace)
xi0 = ift.Field.from_random(domain=hspace, random_type='normal')
def pspec(k): return 1 / (1 + k**2)**dim
pspec = ift.PS_field(pspace, pspec)
A = P.adjoint_times(ift.sqrt(pspec))
A = Dist(ift.sqrt(pspec))
n = ift.Field.from_random(domain=space, random_type='normal')
s0 = xi0 * A
Instrument = ift.ScalingOperator(10., space)
......@@ -85,12 +85,12 @@ class Energy_Tests(unittest.TestCase):
ht = ift.HarmonicTransformOperator(hspace, target=space)
binbounds = ift.PowerSpace.useful_binbounds(hspace, logarithmic=False)
pspace = ift.PowerSpace(hspace, binbounds=binbounds)
P = ift.PowerProjectionOperator(domain=hspace, power_space=pspace)
Dist = ift.PowerDistributor(target=hspace, power_space=pspace)
xi0 = ift.Field.from_random(domain=hspace, random_type='normal')
def pspec(k): return 1 / (1 + k**2)**dim
pspec = ift.PS_field(pspace, pspec)
A = P.adjoint_times(ift.sqrt(pspec))
A = Dist(ift.sqrt(pspec))
n = ift.Field.from_random(domain=space, random_type='normal')
s = ht(xi0 * A)
R = ift.ScalingOperator(10., space)
......@@ -129,12 +129,12 @@ class Curvature_Tests(unittest.TestCase):
ht = ift.HarmonicTransformOperator(hspace, target=space)
binbounds = ift.PowerSpace.useful_binbounds(hspace, logarithmic=False)
pspace = ift.PowerSpace(hspace, binbounds=binbounds)
P = ift.PowerProjectionOperator(domain=hspace, power_space=pspace)
Dist = ift.PowerDistributor(target=hspace, power_space=pspace)
xi0 = ift.Field.from_random(domain=hspace, random_type='normal')