Commit 24147f38 authored by Torsten Ensslin's avatar Torsten Ensslin
Browse files

Merge branch 'NIFTy_5' into 'docstrings_torsten'

# Conflicts:
#   nifty5/operators/energy_operators.py
parents 9a8c07ff 9c813309
...@@ -11,6 +11,7 @@ setup.cfg ...@@ -11,6 +11,7 @@ setup.cfg
.svn/ .svn/
*.csv *.csv
.pytest_cache/ .pytest_cache/
*.png
# from https://github.com/github/gitignore/blob/master/Python.gitignore # from https://github.com/github/gitignore/blob/master/Python.gitignore
......
...@@ -46,32 +46,32 @@ if __name__ == '__main__': ...@@ -46,32 +46,32 @@ if __name__ == '__main__':
mode = 1 mode = 1
position_space = ift.RGSpace([128, 128]) position_space = ift.RGSpace([128, 128])
harmonic_space = position_space.get_default_codomain()
ht = ift.HarmonicTransformOperator(harmonic_space, position_space)
power_space = ift.PowerSpace(harmonic_space)
# Set up an amplitude operator for the field # Set up an amplitude operator for the field
# The parameters mean: dct = {
# 64 spectral bins 'target': power_space,
# 'n_pix': 64, # 64 spectral bins
# Spectral smoothness (affects Gaussian process part)
# 3 = relatively high variance of spectral curbvature # Spectral smoothness (affects Gaussian process part)
# 0.4 = quefrency mode below which cepstrum flattens 'a': 3, # relatively high variance of spectral curbvature
# 'k0': .4, # quefrency mode below which cepstrum flattens
# Power-law part of spectrum:
# -5 = preferred power-law slope # Power-law part of spectrum:
# 0.5 = low variance of power-law slope 'sm': -5, # preferred power-law slope
# 0.4 = y-intercept mean 'sv': .5, # low variance of power-law slope
# 0.3 = relatively high y-intercept variance 'im': .4, # y-intercept mean
A = ift.AmplitudeOperator(position_space, 64, 3, 0.4, -5., 0.5, 0.4, 0.3) 'iv': .3 # relatively high y-intercept variance
}
A = ift.AmplitudeOperator(**dct)
# Build the operator for a correlated signal # Build the operator for a correlated signal
harmonic_space = position_space.get_default_codomain()
ht = ift.HarmonicTransformOperator(harmonic_space, position_space)
power_space = A.target[0]
power_distributor = ift.PowerDistributor(harmonic_space, power_space) power_distributor = ift.PowerDistributor(harmonic_space, power_space)
vol = harmonic_space.scalar_dvol**-0.5
vol = ift.ScalingOperator(harmonic_space.scalar_dvol**(-0.5), xi = ift.ducktape(harmonic_space, None, 'xi')
harmonic_space) correlated_field = ht(vol*power_distributor(A)*xi)
correlated_field = ht(
vol(power_distributor(A))*ift.ducktape(harmonic_space, None, 'xi'))
# Alternatively, one can use: # Alternatively, one can use:
# correlated_field = ift.CorrelatedField(position_space, A) # correlated_field = ift.CorrelatedField(position_space, A)
......
sphinx-apidoc -l -e -d 2 -o docs/source/mod nifty5 sphinx-apidoc -e -o docs/source/mod nifty5
sphinx-build -b html docs/source/ docs/build/ sphinx-build -b html docs/source/ docs/build/
This diff is collapsed.
...@@ -10,6 +10,9 @@ master_doc = 'index' ...@@ -10,6 +10,9 @@ master_doc = 'index'
napoleon_google_docstring = False napoleon_google_docstring = False
napoleon_numpy_docstring = True napoleon_numpy_docstring = True
napoleon_use_ivar = True napoleon_use_ivar = True
napoleon_use_admonition_for_notes = True
napoleon_use_admonition_for_examples = True
napoleon_use_admonition_for_references = True
project = u'NIFTy5' project = u'NIFTy5'
copyright = u'2013-2019, Max-Planck-Society' copyright = u'2013-2019, Max-Planck-Society'
......
...@@ -76,7 +76,8 @@ from .plot import Plot ...@@ -76,7 +76,8 @@ from .plot import Plot
from .library.amplitude_operator import AmplitudeOperator from .library.amplitude_operator import AmplitudeOperator
from .library.inverse_gamma_operator import InverseGammaOperator from .library.inverse_gamma_operator import InverseGammaOperator
from .library.los_response import LOSResponse from .library.los_response import LOSResponse
from .library.dynamic_operator import dynamic_operator, dynamic_lightcone_operator from .library.dynamic_operator import (dynamic_operator,
dynamic_lightcone_operator)
from .library.light_cone_operator import LightConeOperator from .library.light_cone_operator import LightConeOperator
from .library.wiener_filter_curvature import WienerFilterCurvature from .library.wiener_filter_curvature import WienerFilterCurvature
......
...@@ -103,7 +103,7 @@ class DomainTuple(object): ...@@ -103,7 +103,7 @@ class DomainTuple(object):
"""tuple of int: number of pixels along each axis """tuple of int: number of pixels along each axis
The shape of the array-like object required to store information The shape of the array-like object required to store information
living on the DomainTuple. defined on the DomainTuple.
""" """
return self._shape return self._shape
...@@ -112,7 +112,7 @@ class DomainTuple(object): ...@@ -112,7 +112,7 @@ class DomainTuple(object):
"""tuple of int: number of pixels along each axis on the local task """tuple of int: number of pixels along each axis on the local task
The shape of the array-like object required to store information The shape of the array-like object required to store information
living on part of the domain which is stored on the local MPI task. defined on part of the domain which is stored on the local MPI task.
""" """
from .dobj import local_shape from .dobj import local_shape
return local_shape(self._shape) return local_shape(self._shape)
......
...@@ -80,7 +80,7 @@ class Domain(NiftyMetaBase()): ...@@ -80,7 +80,7 @@ class Domain(NiftyMetaBase()):
"""tuple of int: number of pixels along each axis """tuple of int: number of pixels along each axis
The shape of the array-like object required to store information The shape of the array-like object required to store information
living on the domain. defined on the domain.
""" """
raise NotImplementedError raise NotImplementedError
...@@ -89,7 +89,7 @@ class Domain(NiftyMetaBase()): ...@@ -89,7 +89,7 @@ class Domain(NiftyMetaBase()):
"""tuple of int: number of pixels along each axis on the local task """tuple of int: number of pixels along each axis on the local task
The shape of the array-like object required to store information The shape of the array-like object required to store information
living on part of the domain which is stored on the local MPI task. defined on part of the domain which is stored on the local MPI task.
""" """
from ..dobj import local_shape from ..dobj import local_shape
return local_shape(self.shape) return local_shape(self.shape)
......
...@@ -32,13 +32,13 @@ class LMSpace(StructuredDomain): ...@@ -32,13 +32,13 @@ class LMSpace(StructuredDomain):
lmax : int lmax : int
The maximum :math:`l` value of any spherical harmonic coefficient The maximum :math:`l` value of any spherical harmonic coefficient
:math:`a_{lm}` that is represented by this object. :math:`a_{lm}` that is represented by this object.
Must be :math:`\ge 0`. Must be :math:`\\ge 0`.
mmax : int, optional mmax : int, optional
The maximum :math:`m` value of any spherical harmonic coefficient The maximum :math:`m` value of any spherical harmonic coefficient
:math:`a_{lm}` that is represented by this object. :math:`a_{lm}` that is represented by this object.
If not supplied, it is set to `lmax`. If not supplied, it is set to `lmax`.
Must be :math:`\ge 0` and :math:`\le` `lmax`. Must be :math:`\\ge 0` and :math:`\\le` `lmax`.
""" """
_needed_for_hash = ["_lmax", "_mmax"] _needed_for_hash = ["_lmax", "_mmax"]
......
...@@ -38,7 +38,7 @@ class LogRGSpace(StructuredDomain): ...@@ -38,7 +38,7 @@ class LogRGSpace(StructuredDomain):
FIXME FIXME
harmonic : bool, optional harmonic : bool, optional
Whether the space represents a grid in position or harmonic space. Whether the space represents a grid in position or harmonic space.
(default: False). Default: False.
""" """
_needed_for_hash = ['_shape', '_bindistances', '_t_0', '_harmonic'] _needed_for_hash = ['_shape', '_bindistances', '_t_0', '_harmonic']
......
...@@ -31,13 +31,13 @@ class PowerSpace(StructuredDomain): ...@@ -31,13 +31,13 @@ class PowerSpace(StructuredDomain):
---------- ----------
harmonic_partner : StructuredDomain harmonic_partner : StructuredDomain
The harmonic domain of which this is the power space. The harmonic domain of which this is the power space.
binbounds : None, or tuple of float (default: None) binbounds : None, or tuple of float
if None: By default (binbounds=None):
There will be as many bins as there are distinct k-vector lengths There are as many bins as there are distinct k-vector lengths in
in the harmonic partner space. the harmonic partner space.
The `binbounds` property of the PowerSpace will also be None. The `binbounds` property of the PowerSpace will be None.
else: else:
the bin bounds requested for this PowerSpace. The array The bin bounds requested for this PowerSpace. The array
must be sorted and strictly ascending. The first entry is the right must be sorted and strictly ascending. The first entry is the right
boundary of the first bin, and the last entry is the left boundary boundary of the first bin, and the last entry is the left boundary
of the last bin, i.e. thee will be `len(binbounds)+1` bins in of the last bin, i.e. thee will be `len(binbounds)+1` bins in
......
...@@ -31,19 +31,21 @@ class RGSpace(StructuredDomain): ...@@ -31,19 +31,21 @@ class RGSpace(StructuredDomain):
shape : int or tuple of int shape : int or tuple of int
Number of grid points or numbers of gridpoints along each axis. Number of grid points or numbers of gridpoints along each axis.
distances : None or float or tuple of float, optional distances : None or float or tuple of float, optional
Distance between two grid points along each axis Distance between two grid points along each axis.
(default: None).
If distances is None: By default (distances=None):
- If harmonic==True, all distances will be set to 1
- if harmonic==True, all distances will be set to 1 - If harmonic==False, the distance along each axis will be
- if harmonic==False, the distance along each axis will be
set to the inverse of the number of points along that axis. set to the inverse of the number of points along that axis.
harmonic : bool, optional harmonic : bool, optional
Whether the space represents a grid in position or harmonic space. Whether the space represents a grid in position or harmonic space.
(default: False). Default: False.
Notes
-----
Topologically, a n-dimensional RGSpace is a n-Torus, i.e. it has periodic
boundary conditions.
""" """
_needed_for_hash = ["_distances", "_shape", "_harmonic"] _needed_for_hash = ["_distances", "_shape", "_harmonic"]
......
...@@ -25,7 +25,7 @@ from .domain_tuple import DomainTuple ...@@ -25,7 +25,7 @@ from .domain_tuple import DomainTuple
class Field(object): class Field(object):
_scalar_dom = DomainTuple.scalar_domain() _scalar_dom = DomainTuple.scalar_domain()
""" The discrete representation of a continuous field over multiple spaces. """The discrete representation of a continuous field over multiple spaces.
In NIFTy, Fields are used to store data arrays and carry all the needed In NIFTy, Fields are used to store data arrays and carry all the needed
metainformation (i.e. the domain) for operators to be able to work on them. metainformation (i.e. the domain) for operators to be able to work on them.
...@@ -159,13 +159,13 @@ class Field(object): ...@@ -159,13 +159,13 @@ class Field(object):
Returns Returns
------- -------
Field Field
Field living on `new_domain`, but with the same data as `self`. Field defined on `new_domain`, but with the same data as `self`.
""" """
return Field(DomainTuple.make(new_domain), self._val) return Field(DomainTuple.make(new_domain), self._val)
@staticmethod @staticmethod
def from_random(random_type, domain, dtype=np.float64, **kwargs): def from_random(random_type, domain, dtype=np.float64, **kwargs):
""" Draws a random field with the given parameters. """Draws a random field with the given parameters.
Parameters Parameters
---------- ----------
...@@ -284,7 +284,7 @@ class Field(object): ...@@ -284,7 +284,7 @@ class Field(object):
return res return res
def weight(self, power=1, spaces=None): def weight(self, power=1, spaces=None):
""" Weights the pixels of `self` with their invidual pixel-volume. """Weights the pixels of `self` with their invidual pixel-volume.
Parameters Parameters
---------- ----------
...@@ -325,7 +325,7 @@ class Field(object): ...@@ -325,7 +325,7 @@ class Field(object):
return Field.from_local_data(self._domain, aout) return Field.from_local_data(self._domain, aout)
def outer(self, x): def outer(self, x):
""" Computes the outer product of 'self' with x. """Computes the outer product of 'self' with x.
Parameters Parameters
---------- ----------
...@@ -342,21 +342,21 @@ class Field(object): ...@@ -342,21 +342,21 @@ class Field(object):
return OuterProduct(self, x.domain)(x) return OuterProduct(self, x.domain)(x)
def vdot(self, x=None, spaces=None): def vdot(self, x=None, spaces=None):
""" Computes the dot product of 'self' with x. """Computes the dot product of 'self' with x.
Parameters Parameters
---------- ----------
x : Field x : Field
x must be defined on the same domain as `self`. x must be defined on the same domain as `self`.
spaces : None, int or tuple of int (default: None) spaces : None, int or tuple of int
The dot product is only carried out over the sub-domains in this The dot product is only carried out over the sub-domains in this
tuple. If None, it is carried out over all sub-domains. tuple. If None, it is carried out over all sub-domains.
Default: None.
Returns Returns
------- -------
float, complex, either scalar (for full dot products) float, complex, either scalar (for full dot products) or Field (for partial dot products).
or Field (for partial dot products)
""" """
if not isinstance(x, Field): if not isinstance(x, Field):
raise TypeError("The dot-partner must be an instance of " + raise TypeError("The dot-partner must be an instance of " +
...@@ -375,12 +375,12 @@ class Field(object): ...@@ -375,12 +375,12 @@ class Field(object):
return (self.conjugate()*x).sum(spaces=spaces) return (self.conjugate()*x).sum(spaces=spaces)
def norm(self, ord=2): def norm(self, ord=2):
""" Computes the L2-norm of the field values. """Computes the L2-norm of the field values.
Parameters Parameters
---------- ----------
ord : int, default=2 ord : int
accepted values: 1, 2, ..., np.inf Accepted values: 1, 2, ..., np.inf. Default: 2.
Returns Returns
------- -------
...@@ -390,7 +390,7 @@ class Field(object): ...@@ -390,7 +390,7 @@ class Field(object):
return dobj.norm(self._val, ord) return dobj.norm(self._val, ord)
def conjugate(self): def conjugate(self):
""" Returns the complex conjugate of the field. """Returns the complex conjugate of the field.
Returns Returns
------- -------
...@@ -441,9 +441,9 @@ class Field(object): ...@@ -441,9 +441,9 @@ class Field(object):
Parameters Parameters
---------- ----------
spaces : None, int or tuple of int (default: None) spaces : None, int or tuple of int
The summation is only carried out over the sub-domains in this The summation is only carried out over the sub-domains in this
tuple. If None, it is carried out over all sub-domains. tuple. If None, it is carried out over all sub-domains. Default: None.
Returns Returns
------- -------
...@@ -461,9 +461,10 @@ class Field(object): ...@@ -461,9 +461,10 @@ class Field(object):
Parameters Parameters
---------- ----------
spaces : None, int or tuple of int (default: None) spaces : None, int or tuple of int
The summation is only carried out over the sub-domains in this The summation is only carried out over the sub-domains in this
tuple. If None, it is carried out over all sub-domains. tuple. If None, it is carried out over all sub-domains.
Default: None.
Returns Returns
------- -------
...@@ -484,9 +485,10 @@ class Field(object): ...@@ -484,9 +485,10 @@ class Field(object):
Parameters Parameters
---------- ----------
spaces : None, int or tuple of int (default: None) spaces : None, int or tuple of int
The operation is only carried out over the sub-domains in this The operation is only carried out over the sub-domains in this
tuple. If None, it is carried out over all sub-domains. tuple. If None, it is carried out over all sub-domains.
Default: None.
Returns Returns
------- -------
...@@ -544,9 +546,9 @@ class Field(object): ...@@ -544,9 +546,9 @@ class Field(object):
Parameters Parameters
---------- ----------
spaces : None, int or tuple of int (default: None) spaces : None, int or tuple of int
The operation is only carried out over the sub-domains in this The operation is only carried out over the sub-domains in this
tuple. If None, it is carried out over all sub-domains. tuple. If None, it is carried out over all sub-domains. Default: None.
Returns Returns
------- -------
...@@ -566,9 +568,10 @@ class Field(object): ...@@ -566,9 +568,10 @@ class Field(object):
Parameters Parameters
---------- ----------
spaces : None, int or tuple of int (default: None) spaces : None, int or tuple of int
The operation is only carried out over the sub-domains in this The operation is only carried out over the sub-domains in this
tuple. If None, it is carried out over all sub-domains. tuple. If None, it is carried out over all sub-domains.
Default: None.
Returns Returns
------- -------
...@@ -594,9 +597,10 @@ class Field(object): ...@@ -594,9 +597,10 @@ class Field(object):
Parameters Parameters
---------- ----------
spaces : None, int or tuple of int (default: None) spaces : None, int or tuple of int
The operation is only carried out over the sub-domains in this The operation is only carried out over the sub-domains in this
tuple. If None, it is carried out over all sub-domains. tuple. If None, it is carried out over all sub-domains.
Default: None.
Returns Returns
------- -------
......
...@@ -30,7 +30,7 @@ def make_adjust_variances(a, ...@@ -30,7 +30,7 @@ def make_adjust_variances(a,
samples=[], samples=[],
scaling=None, scaling=None,
ic_samp=None): ic_samp=None):
""" Creates a Hamiltonian for constant likelihood optimizations. """Creates a Hamiltonian for constant likelihood optimizations.
Constructs a Hamiltonian to solve constant likelihood optimizations of the Constructs a Hamiltonian to solve constant likelihood optimizations of the
form phi = a * xi under the constraint that phi remains constant. form phi = a * xi under the constraint that phi remains constant.
......
...@@ -19,76 +19,51 @@ import numpy as np ...@@ -19,76 +19,51 @@ import numpy as np
from ..domains.power_space import PowerSpace from ..domains.power_space import PowerSpace
from ..field import Field from ..field import Field
from ..sugar import makeOp, sqrt from ..sugar import makeOp
def _ceps_kernel(dof_space, k, a, k0): def _ceps_kernel(dof_space, k, a, k0):
return a**2/(1 + (k/k0)**2)**2 return a**2/(1 + (k/k0)**2)**2
def create_cepstrum_amplitude_field(domain, cepstrum): def _create_cepstrum_amplitude_field(domain, cepstrum):
"""Creates a ...
Writes the sum of all modes into the zero-mode.
Parameters
----------
domain: ???
???
cepstrum: Callable
???
"""
dim = len(domain.shape) dim = len(domain.shape)
shape = domain.shape shape = domain.shape
q_array = domain.get_k_array() q_array = domain.get_k_array()
# Fill cepstrum field (all non-zero modes) # Fill all non-zero modes
no_zero_modes = (slice(1, None),)*dim no_zero_modes = (slice(1, None), )*dim
ks = q_array[(slice(None),) + no_zero_modes] ks = q_array[(slice(None), ) + no_zero_modes]
cepstrum_field = np.zeros(shape) cepstrum_field = np.zeros(shape)
cepstrum_field[no_zero_modes] = cepstrum(ks) cepstrum_field[no_zero_modes] = cepstrum(ks)
# Fill cepstrum field (zero-mode subspaces) # Fill zero-mode subspaces
for i in range(dim): for i in range(dim):
# Prepare indices fst_dims = (slice(None), )*i
fst_dims = (slice(None),)*i sl = fst_dims + (slice(1, None), )
sl = fst_dims + (slice(1, None),) sl2 = fst_dims + (0, )
sl2 = fst_dims + (0,)
# Do summation
cepstrum_field[sl2] = np.sum(cepstrum_field[sl], axis=i) cepstrum_field[sl2] = np.sum(cepstrum_field[sl], axis=i)
return Field.from_global_data(domain, cepstrum_field) return Field.from_global_data(domain, cepstrum_field)
def _CepstrumOperator(logk_space, ceps_a, ceps_k, zero_mode=True): def CepstrumOperator(domain, a, k0):
''' '''
Parameters .. math::
---------- C(k) = \\left(\\frac{a}{1+(k/k0)^2}\\right)^2
ceps_a, ceps_k0 : Smoothness parameters in ceps_kernel
eg. ceps_kernel(k) = (a/(1+(k/k0)**2))**2
a = ceps_a, k0 = ceps_k0
''' '''
from ..operators.qht_operator import QHTOperator from ..operators.qht_operator import QHTOperator
from ..operators.symmetrizing_operator import SymmetrizingOperator from ..operators.symmetrizing_operator import SymmetrizingOperator
qht = QHTOperator(target=logk_space)
# FIXME a>0 k0>0
qht = QHTOperator(target=domain)
dof_space = qht.domain[0] dof_space = qht.domain[0]
sym = SymmetrizingOperator(logk_space) sym = SymmetrizingOperator(domain)
kern = lambda k: _ceps_kernel(dof_space, k, ceps_a, ceps_k) kern = lambda k: _ceps_kernel(dof_space, k, a, k0)
cepstrum = create_cepstrum_amplitude_field(dof_space, kern) cepstrum = _create_cepstrum_amplitude_field(dof_space, kern)