Commit 4fb590bb authored by Martin Reinecke's avatar Martin Reinecke

Merge branch 'NIFTy_4' into 'proj_to_dist'

# Conflicts:
#   demos/wiener_filter_via_hamiltonian.py
parents 0193c903 e8fbf7e7
Pipeline #24972 passed with stage
in 9 minutes and 53 seconds
#FROM ubuntu:artful
FROM debian:testing-slim
# dependencies via apt
RUN apt-get update
ADD ci/install_basics.sh /tmp/install_basics.sh
RUN sh /tmp/install_basics.sh
# python dependencies
ADD ci/requirements.txt /tmp/requirements.txt
RUN pip install --process-dependency-links -r /tmp/requirements.txt
# copy sources and install nifty
COPY . /tmp/NIFTy
RUN pip install /tmp/NIFTy
# Cleanup
RUN rm -r /tmp/*
parameterized
coverage
git+https://gitlab.mpcdf.mpg.de/ift/pyHealpix.git
sphinx
sphinx==1.6.7
sphinx_rtd_theme
numpydoc
......@@ -8,7 +8,7 @@ np.random.seed(42)
if __name__ == "__main__":
# Set up position space
s_space = ift.RGSpace([128, 128])
#s_space = ift.HPSpace(32)
# s_space = ift.HPSpace(32)
# Define harmonic transformation and associated harmonic space
h_space = s_space.get_default_codomain()
......@@ -63,7 +63,8 @@ if __name__ == "__main__":
tol_abs_gradnorm=1e-15)
minimizer = ift.RelaxedNewton(IC1)
ICI = ift.GradientNormController(iteration_limit=500, tol_abs_gradnorm=1e-10)
ICI = ift.GradientNormController(iteration_limit=500,
tol_abs_gradnorm=1e-10)
map_inverter = ift.ConjugateGradient(controller=ICI)
ICI2 = ift.GradientNormController(iteration_limit=200,
......
......@@ -53,8 +53,9 @@ if __name__ == "__main__":
MaskOperator = ift.DiagonalOperator(mask)
R = ift.GeometryRemover(s_space)
R = R*MaskOperator
#R = R*HT
#R = R * ift.create_harmonic_smoothing_operator((harmonic_space,),0,response_sigma)
# R = R*HT
# R = R * ift.create_harmonic_smoothing_operator((harmonic_space,), 0,
# response_sigma)
MeasurementOperator = R
d_space = MeasurementOperator.target
......
......@@ -71,8 +71,8 @@ if __name__ == "__main__":
mask_2 = ift.Field(signal_space_2, ift.dobj.from_global_data(mask_2))
R = ift.GeometryRemover(signal_domain)
R = R*ift.DiagonalOperator(mask_1, signal_domain,spaces=0)
R = R*ift.DiagonalOperator(mask_2, signal_domain,spaces=1)
R = R*ift.DiagonalOperator(mask_1, signal_domain, spaces=0)
R = R*ift.DiagonalOperator(mask_2, signal_domain, spaces=1)
R = R*ht
R = R * ift.create_harmonic_smoothing_operator(harmonic_domain, 0,
response_sigma_1)
......@@ -101,11 +101,13 @@ if __name__ == "__main__":
plotdict = {"colormap": "Planck-like"}
plot_space = ift.RGSpace((N_pixels_1, N_pixels_2))
ift.plot(ift.Field(plot_space,val=ht(mock_signal).val), name='mock_signal.png',
**plotdict)
ift.plot(ift.Field(plot_space,val=data.val), name='data.png', **plotdict)
ift.plot(ift.Field(plot_space,val=m.val), name='map.png', **plotdict)
ift.plot(ift.Field(plot_space, val=ht(mock_signal).val),
name='mock_signal.png', **plotdict)
ift.plot(ift.Field(plot_space, val=data.val), name='data.png', **plotdict)
ift.plot(ift.Field(plot_space, val=m.val), name='map.png', **plotdict)
# sampling the uncertainty map
mean, variance = ift.probe_with_posterior_samples(wiener_curvature, ht, 10)
ift.plot(ift.Field(plot_space, val=ift.sqrt(variance).val), name="uncertainty.png", **plotdict)
ift.plot(ift.Field(plot_space, val=(mean+m).val), name="posterior_mean.png", **plotdict)
ift.plot(ift.Field(plot_space, val=ift.sqrt(variance).val),
name="uncertainty.png", **plotdict)
ift.plot(ift.Field(plot_space, val=(mean+m).val),
name="posterior_mean.png", **plotdict)
......@@ -38,7 +38,8 @@ if __name__ == "__main__":
R = ift.GeometryRemover(signal_space)
R = R*ift.DiagonalOperator(mask)
R = R*ht
R = R * ift.create_harmonic_smoothing_operator((harmonic_space,),0,response_sigma)
R = R * ift.create_harmonic_smoothing_operator((harmonic_space,), 0,
response_sigma)
data_domain = R.target[0]
noiseless_data = R(mock_signal)
......
......@@ -85,5 +85,5 @@ if __name__ == "__main__":
# try to do the same with diagonal probing
variance = ift.probe_diagonal(ht*curv.inverse*ht.adjoint, 100)
#sm = ift.FFTSmoothingOperator(s_space, sigma=0.005)
ift.plot(variance, name="posterior_variance2.png", **plotdict2)
# sm = ift.FFTSmoothingOperator(s_space, sigma=0.015)
ift.plot(variance, name="posterior_variance2.png", **plotdict)
This diff is collapsed.
rm -rf docs/build docs/source/mod
sphinx-apidoc -l -e -d 2 -o docs/source/mod nifty4
#sphinx-apidoc -l -e -d 2 -o docs/source/mod nifty4
python docs/better_apidoc.py -l -e -d 3 -t docs/generation-templates -o docs/source/mod nifty4
sphinx-build -b html docs/source/ docs/build/
{% if name %}
{{ name }}
{% for item in range(8 + name|length) -%}={%- endfor %}
{% else %}
{{ fullname }}
{% for item in range(8 + fullname|length) -%}={%- endfor %}
{% endif %}
({{ fullname }} module)
.. currentmodule:: {{ fullname }}
.. automodule:: {{ fullname }}
{% if members -%}
:members: {{ members|join(", ") }}
:undoc-members:
:show-inheritance:
:member-order: bysource
Summary
-------
{%- if exceptions %}
Exceptions:
.. autosummary::
:nosignatures:
{% for item in exceptions %}
{{ item }}
{%- endfor %}
{%- endif %}
{%- if classes %}
Classes:
.. autosummary::
:nosignatures:
{% for item in classes %}
{{ item }}
{%- endfor %}
{%- endif %}
{%- if functions %}
Functions:
.. autosummary::
:nosignatures:
{% for item in functions %}
{{ item }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- if data %}
Data:
.. autosummary::
:nosignatures:
{% for item in data %}
{{ item }}
{%- endfor %}
{%- endif %}
{% if all_refs %}
``__all__``: {{ all_refs|join(", ") }}
{%- endif %}
{% if members %}
Reference
---------
{%- endif %}
{% if name %}
{{ name }}
{% for item in range(8 + name|length) -%}={%- endfor %}
{% else %}
{{ fullname }}
{% for item in range(8 + fullname|length) -%}={%- endfor %}
{% endif %}
({{ fullname }} package)
.. automodule:: {{ fullname }}
{% if members -%}
:members: {{ members|join(", ") }}
:undoc-members:
:show-inheritance:
{%- endif %}
{% if submodules %}
Submodules
----------
.. toctree::
:maxdepth: 1
{% for item in submodules %}
{{ fullname }}.{{ item }}
{%- endfor %}
{%- endif -%}
{% if subpackages %}
Subpackages
-----------
.. toctree::
:maxdepth: 1
{% for item in subpackages %}
{{ fullname }}.{{ item }}
{%- endfor %}
{%- endif %}
{% if members %}
Summary
-------
{%- if exceptions %}
Exceptions:
.. autosummary::
:nosignatures:
{% for item in exceptions %}
{{ item }}
{%- endfor %}
{%- endif %}
{%- if classes %}
Classes:
.. autosummary::
:nosignatures:
{% for item in classes %}
{{ item }}
{%- endfor %}
{%- endif %}
{%- if functions %}
Functions:
.. autosummary::
:nosignatures:
{% for item in functions %}
{{ item }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- if data %}
Data:
.. autosummary::
:nosignatures:
{% for item in data %}
{{ item }}
{%- endfor %}
{%- endif %}
{% if all_refs %}
``__all__``: {{ all_refs|join(", ") }}
{%- endif %}
{% if members %}
Reference
---------
{%- endif %}
......@@ -52,16 +52,12 @@ extensions = [
'numpydoc',
'sphinx.ext.autosummary',
'sphinx.ext.napoleon',
'sphinx.ext.coverage',
'sphinx.ext.todo',
# 'sphinx.ext.coverage',
# 'sphinx.ext.todo',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode'
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
......
NIFTy -- Numerical Information Field Theory
===========================================
**NIFTy** [1]_, "\ **N**\umerical **I**\nformation **F**\ield **T**\heor\ **y**\ ", is a versatile library designed to enable the development of signal inference algorithms that operate regardless of the underlying spatial grid and its resolution.
**NIFTy** [1]_, "\ **N**\umerical **I**\nformation **F**\ield **T**\heor\ **y**\ ", is a versatile library designed to enable the development of signal inference algorithms that are independent of the underlying spatial grid and its resolution.
Its object-oriented framework is written in Python, although it accesses libraries written in C++ and C for efficiency.
NIFTy offers a toolkit that abstracts discretized representations of continuous spaces, fields in these spaces, and operators acting on fields into classes.
Thereby, the correct normalization of operations on fields is taken care of automatically without concerning the user.
This allows for an abstract formulation and programming of inference algorithms, including those derived within information field theory.
Thus, NIFTy permits its user to rapidly prototype algorithms in 1D and then apply the developed code in higher-dimensional settings of real world problems.
Thus, NIFTy permits its user to rapidly prototype algorithms in 1D and then apply the developed code in higher-dimensional settings to real world problems.
The set of spaces on which NIFTy operates comprises point sets, *n*-dimensional regular grids, spherical spaces, their harmonic counterparts, and product spaces constructed as combinations of those.
References
----------
.. [1] Selig et al., "NIFTy -- Numerical Information Field Theory -- a versatile Python library for signal inference", `A&A, vol. 554, id. A26 <http://dx.doi.org/10.1051/0004-6361/201321236>`_, 2013; `arXiv:1301.4499 <http://www.arxiv.org/abs/1301.4499>`_
Documentation
-------------
Welcome to NIFTy's documentation!
.. [1] Steininger et al., "NIFTy 3 - Numerical Information Field Theory - A Python framework for multicomponent signal inference on HPC clusters", 2017, submitted to PLOS One; `[arXiv:1708.01073] <https://arxiv.org/abs/1708.01073>`_
Contents
........
......
......@@ -2,7 +2,7 @@ Installation
============
In the following, we assume a Debian-based distribution. For other
In the following, we assume a Debian-based Linux distribution. For other
distributions, the "apt" lines will need slight changes.
NIFTy4 and its mandatory dependencies can be installed via::
......@@ -19,7 +19,7 @@ Plotting support is added via::
pip install --user matplotlib
Support for spherical harmonic transforms is added via:
Support for spherical harmonic transforms is added via::
pip install --user git+https://gitlab.mpcdf.mpg.de/ift/pyHealpix.git
......
......@@ -22,14 +22,16 @@ from .structured_domain import StructuredDomain
class GLSpace(StructuredDomain):
"""NIFTy subclass for Gauss-Legendre pixelizations [#]_ of the two-sphere.
"""NIFTy subclass for Gauss-Legendre pixelizations of the two-sphere.
Its harmonic partner is the :class:`LMSpace`
Parameters
----------
nlat : int
Number of latitudinal bins (or rings) that are used for this
pixelization.
nlon : int, *optional*
nlon : int, optional
Number of longitudinal bins that are used for this pixelization.
Default value is 2*nlat + 1.
......@@ -37,19 +39,6 @@ class GLSpace(StructuredDomain):
------
ValueError
If input `nlat` or `nlon` is invalid.
See Also
--------
HPSpace, LMSpace
References
----------
.. [#] M. Reinecke and D. Sverre Seljebotn, 2013, "Libsharp - spherical
harmonic transforms revisited";
`arXiv:1303.4945 <http://www.arxiv.org/abs/1303.4945>`_
.. [#] K.M. Gorski et al., 2005, "HEALPix: A Framework for
High-Resolution Discretization and Fast Analysis of Data
Distributed on the Sphere", *ApJ* 622..759G.
"""
def __init__(self, nlat, nlon=None):
......
......@@ -24,34 +24,22 @@ from .. import dobj
class LMSpace(StructuredDomain):
"""NIFTy subclass for spherical harmonics components, for representations
of fields on the two-sphere.
"""NIFTy subclass for sets of spherical harmonic coefficients.
Its harmonic partner spaces are :class:`HPSpace` and :class:`GLSpace`.
Parameters
----------
lmax : int
The maximum :math:`l` value of any spherical harmonics
:math:`Y_{lm}` that is represented in this Space.
Must be >=0.
mmax : int *optional*
The maximum :math:`m` value of any spherical harmonics
:math:`Y_{lm}` that is represented in this Space.
If not supplied, it is set to lmax.
Must be >=0 and <=lmax.
See Also
--------
HPSpace, GLSpace
References
----------
.. [#] K.M. Gorski et al., 2005, "HEALPix: A Framework for
High-Resolution Discretization and Fast Analysis of Data
Distributed on the Sphere", *ApJ* 622..759G.
.. [#] M. Reinecke and D. Sverre Seljebotn, 2013, "Libsharp - spherical
harmonic transforms revisited";
`arXiv:1303.4945 <http://www.arxiv.org/abs/1303.4945>`_
The maximum :math:`l` value of any spherical harmonic coefficient
:math:`a_{lm}` that is represented by this object.
Must be :math:`\ge 0`.
mmax : int, optional
The maximum :math:`m` value of any spherical harmonic coefficient
:math:`a_{lm}` that is represented by this object.
If not supplied, it is set to `lmax`.
Must be :math:`\ge 0` and :math:`\le` `lmax`.
"""
def __init__(self, lmax, mmax=None):
......@@ -122,14 +110,14 @@ class LMSpace(StructuredDomain):
@property
def lmax(self):
""" Returns the maximum :math:`l` value of any spherical harmonic
:math:`Y_{lm}` that is represented in this Space.
coefficient :math:`a_{lm}` that is represented in this Space.
"""
return self._lmax
@property
def mmax(self):
""" Returns the maximum :math:`m` value of any spherical harmonic
:math:`Y_{lm}` that is represented in this Space.
coefficient :math:`a_{lm}` that is represented in this Space.
"""
return self._mmax
......
......@@ -24,14 +24,14 @@ from .. import dobj
class PowerSpace(StructuredDomain):
"""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 domain where
k-modes of equal length get mapped to one power index.
Parameters
----------
harmonic_partner : Space
The harmonic Space of which this is the power space.
binbounds: None, or tuple/array/list of float
harmonic_partner : StructuredDomain
The harmonic dmain of which this is the power space.
binbounds : None, or tuple of float
if None:
There will be as many bins as there are distinct k-vector lengths
in the harmonic partner space.
......@@ -54,9 +54,9 @@ class PowerSpace(StructuredDomain):
binbounds[0]=first_bound and binbounds[-1]=last_bound and the remaining
values equidistantly spaced (in linear scale) between these two.
nbin: integer
nbin : int
the number of bins
first_bound, last_bound: float
first_bound, last_bound : float
the k values for the right boundary of the first bin and the left
boundary of the last bin, respectively. They are given in length
units of the harmonic partner space.
......@@ -74,9 +74,9 @@ class PowerSpace(StructuredDomain):
values equidistantly spaced (in natural logarithmic scale)
between these two.
nbin: integer
nbin : int
the number of bins
first_bound, last_bound: float
first_bound, last_bound : float
the k values for the right boundary of the first bin and the left
boundary of the last bin, respectively. They are given in length
units of the harmonic partner space.
......
......@@ -30,16 +30,16 @@ class RGSpace(StructuredDomain):
Parameters
----------
shape : {int, numpy.ndarray}
shape : int or tuple of int
Number of grid points or numbers of gridpoints along each axis.
distances : {float, numpy.ndarray}, *optional*
distances : None or float or tuple of float, optional
Distance between two grid points along each axis
(default: None).
If distances==None:
if harmonic==True, all distances will be set to 1
if harmonic==False, the distance along each axis will be
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.
(default: False).
"""
......
......@@ -35,7 +35,7 @@ class Field(object):
Parameters
----------
domain : None, DomainTuple, tuple(Domain), or Domain
domain : None, DomainTuple, tuple of Domain, or Domain
val : None, Field, data_object, or scalar
The values the array should contain after init. A scalar input will
......@@ -45,7 +45,7 @@ class Field(object):
dtype : type
A numpy.type. Most common are float and complex.
copy: boolean
copy: bool
"""
def __init__(self, domain=None, val=None, dtype=None, copy=False):
......@@ -143,7 +143,7 @@ class Field(object):
Parameters
----------
random_type : String
random_type : str
'pm1', 'normal', 'uniform' are the supported arguments for this
method.
......@@ -155,7 +155,7 @@ class Field(object):
Returns
-------
out : Field
Field
The output object.
"""
domain = DomainTuple.make(domain)
......@@ -187,7 +187,8 @@ class Field(object):
Returns
-------
Integer tuple containing the dimensions of the spaces in domain.
tuple of int
the dimensions of the spaces in domain.
"""
return self._domain.shape
......@@ -199,8 +200,8 @@ class Field(object):
Returns
-------
out : int
The dimension of the Field.
int
the dimension of the Field.
"""
return self._domain.size
......@@ -225,7 +226,7 @@ class Field(object):
Returns
-------
out : Field
Field
The output object. An identical copy of 'self'.
"""
return Field(val=self, copy=True)
......@@ -263,7 +264,7 @@ class Field(object):
power : number
The pixels get weighted with the volume-factor**power.
spaces : tuple of ints
spaces : int or tuple of int
Determines on which subspace the operation takes place.
out : Field or None
......@@ -273,7 +274,7 @@ class Field(object):
Returns
-------
out : Field
Field
The weighted field.
"""
if out is None:
......@@ -313,13 +314,13 @@ class Field(object):
x : Field
x must live on the same domain as `self`.
spaces : None, int or tuple of ints (default: None)
spaces : None, int or tuple of int (default: None)
The dot product is only carried out over the sub-domains in this
tuple. If None, it is carried out over all sub-domains.
Returns
-------
out : float, complex, either scalar (for full dot products)
float, complex, either scalar (for full dot products)
or Field (for partial dot products)
"""
if not isinstance(x, Field):
......@@ -343,7 +344,7 @@ class Field(object):
Returns
-------
norm : float
float
The L2-norm of the field values.
"""
return np.sqrt(np.abs(self.vdot(x=self)))
......@@ -353,7 +354,8 @@ class Field(object):
Returns
-------
The complex conjugated field.
Field
The complex conjugated field.
"""
return Field(self._domain, self.val.conjugate())
......
......@@ -34,33 +34,34 @@ class CriticalPowerEnergy(Energy):
Parameters
----------
position : Field,
position : Field
The current position of this energy. (Logarithm of power spectrum)
m : Field,
m : Field
The map whose power spectrum is inferred. Needs to live in harmonic
signal space.
D : EndomorphicOperator,
D : EndomorphicOperator, optional