Commit b81eb80e authored by Theo Steininger's avatar Theo Steininger
Browse files

Merge branch 'field_docu' into docstring_operators

parents 8bb5b571 223f71e3
Pipeline #12476 passed with stage
in 9 minutes and 4 seconds
...@@ -13,7 +13,7 @@ before_script: ...@@ -13,7 +13,7 @@ before_script:
- apt-get update - apt-get update
- > - >
apt-get install -y build-essential python python-pip python-dev git apt-get install -y build-essential python python-pip python-dev git
autoconf gsl-bin libgsl-dev wget python-numpy cython autoconf gsl-bin libgsl-dev wget python-numpy
- pip install --upgrade -r ci/requirements_base.txt - pip install --upgrade -r ci/requirements_base.txt
- chmod +x ci/*.sh - chmod +x ci/*.sh
......
# This Makefile implements common tasks needed by developers
# A list of implemented rules can be obtained by the command "make help"
.DEFAULT_GOAL=build
.PHONY .SILENT : help
help :
echo
echo " Implemented targets:"
echo
echo " build build pypmc for python2 and python3"
echo " buildX build pypmc for pythonX only where X is one of {2,3}"
echo " build-sdist build pypmc from the dist directory (python 2 and 3)"
echo " build-sdistX build pypmc from the dist directory (pythonX, X in {2,3})"
echo " check use nosetests to test pypmc with python 2.7 and 3"
echo " checkX use nosetests to test pypmc with python 2.7 or 3,"
echo " where X is one of {2,3}"
echo " check-fast use nosetests to run only quick tests of pypmc"
echo " using nosetests-2.7 and nosetests3"
echo " check-sdist use nosetests-2.7 and nosetests3 to test the distribution"
echo " generated by 'make sdist'"
echo " check-sdistX use nosetests-2.7 or nosetests3 to test the distribution"
echo " generated by 'make sdist', where X is one of {2,3}"
echo " clean delete compiled and temporary files"
echo " coverage produce and show a code coverage report"
echo " Note: Cython modules cannot be analyzed"
echo " distcheck runs 'check', check-sdist', 'run-examples' and"
echo " opens a browser with the built documentation"
echo " doc build the html documentation using sphinx"
echo " doc-pdf build the pdf documentation using sphinx"
echo " help show this message"
echo " run-examples run all examples using python 2 and 3"
echo " sdist make a source distribution"
echo " show-todos show todo marks in the source code"
echo
.PHONY : clean
clean:
#remove build doc
rm -rf ./doc/_build
#remove .pyc files created by python 2.7
rm -f ./*.pyc
find -P . -name '*.pyc' -delete
#remove .pyc files crated by python 3
rm -rf ./__pycache__
find -P . -name __pycache__ -delete
#remove build folder in root directory
rm -rf ./build
#remove cythonized C source and object files
find -P . -name '*.c' -delete
#remove variational binaries only if command line argument specified
find -P . -name '*.so' -delete
#remove backup files
find -P . -name '*~' -delete
#remove files created by coverage
rm -f .coverage
rm -rf coverage
# remove egg info
rm -rf pypmc.egg-info
# remove downloaded seutptools
rm -f setuptools-3.3.zip
# remove dist/
rm -rf dist
.PHONY : build
build : build2
.PHONY : build2
build2 :
python2 setup.py build_ext --inplace
.PHONY :
check : check2
.PHONY : check2
check2 : build2
@ # run tests
nosetests-2.7 --processes=-1 --process-timeout=60
# run tests in parallel
mpirun -n 2 nosetests-2.7
.PHONY : check-fast
check-fast : build
nosetests-2.7 -a '!slow' --processes=-1 --process-timeout=60
nosetests3 -a '!slow' --processes=-1 --process-timeout=60
.PHONY : .build-system-default
.build-system-default :
python setup.py build_ext --inplace
.PHONY : doc
doc : .build-system-default
cd doc && make html
.PHONY : doc-pdf
doc-pdf : .build-system-default
cd doc; make latexpdf
.PHONY : run-examples
run-examples : build
cd examples ; \
for file in $$(ls) ; do \
echo running $${file} with python2 && \
python2 $${file} && \
echo running $${file} with python3 && \
python3 $${file} && \
\
# execute with mpirun if mpi4py appears in the file \
if grep -Fq 'mpi4py' $${file} ; then \
echo "$${file}" is mpi parallelized && \
echo running $${file} in parallel with python2 && \
mpirun -n 2 python2 $${file} && \
echo running $${file} in parallel with python3 && \
mpirun -n 2 python3 $${file} ; \
fi \
; \
done
.PHONY : sdist
sdist :
python setup.py sdist
.PHONY : build-sdist
build-sdist : build-sdist2 build-sdist3
./dist/pypmc*/NUL : sdist
cd dist && tar xaf *.tar.gz && cd *
.PHONY : build-sdist2
build-sdist2 : ./dist/pypmc*/NUL
cd dist/pypmc* && python2 setup.py build
.PHONY : build-sdist3
build-sdist3 : ./dist/pypmc*/NUL
cd dist/pypmc* && python3 setup.py build
.PHONY : check-sdist
check-sdist : check-sdist2 check-sdist3
.PHONY : check-sdist2
check-sdist2 : build-sdist2
cd dist/*/build/lib*2.7 && \
nosetests-2.7 --processes=-1 --process-timeout=60 && \
mpirun -n 2 nosetests-2.7
.PHONY : check-sdist3
check-sdist3 : build-sdist3
cd dist/*/build/lib*3.* && \
nosetests3 --processes=-1 --process-timeout=60 && \
mpirun -n 2 nosetests3
.PHONY : distcheck
distcheck : check check-sdist doc
@ # execute "run-examples" after all other recipes makes are done
make run-examples
xdg-open link_to_documentation
.PHONY : show-todos
grep_cmd = ack-grep -i --no-html --no-cc [^"au""sphinx.ext."]todo
show-todos :
@ # suppress errors here
@ # note that no todo found is considered as error
$(grep_cmd) doc ; \
$(grep_cmd) pypmc ; \
$(grep_cmd) examples ; echo \
.PHONY : coverage
coverage : .build-system-default
rm -rf coverage
nosetests --with-coverage --cover-package=nifty --cover-html --cover-html-dir=coverage
xdg-open coverage/index.html
Metadata-Version: 1.0
Name: ift_nifty
Version: 1.0.6
Summary: Numerical Information Field Theory
Home-page: http://www.mpa-garching.mpg.de/ift/nifty/
Author: Theo Steininger
Author-email: theos@mpa-garching.mpg.de
License: GPLv3
Description: UNKNOWN
Platform: UNKNOWN
...@@ -15,7 +15,7 @@ Summary ...@@ -15,7 +15,7 @@ Summary
a versatile library designed to enable the development of signal a versatile library designed to enable the development of signal
inference algorithms that operate regardless of the underlying spatial inference algorithms that operate regardless of the underlying spatial
grid and its resolution. Its object-oriented framework is written in grid and its resolution. Its object-oriented framework is written in
Python, although it accesses libraries written in Cython, C++, and C for Python, although it accesses libraries written in C++ and C for
efficiency. efficiency.
NIFTY offers a toolkit that abstracts discretized representations of NIFTY offers a toolkit that abstracts discretized representations of
...@@ -71,7 +71,6 @@ Installation ...@@ -71,7 +71,6 @@ Installation
- [Python](http://www.python.org/) (v2.7.x) - [Python](http://www.python.org/) (v2.7.x)
- [NumPy](http://www.numpy.org/) - [NumPy](http://www.numpy.org/)
- [Cython](http://cython.org/)
### Download ### Download
...@@ -95,7 +94,7 @@ Starting with a fresh Ubuntu installation move to a folder like ...@@ -95,7 +94,7 @@ Starting with a fresh Ubuntu installation move to a folder like
- Using pip install numpy etc...: - Using pip install numpy etc...:
sudo pip install numpy cython sudo pip install numpy
- Install pyHealpix: - Install pyHealpix:
...@@ -147,10 +146,9 @@ MacPorts, missing ones need to be installed manually. It may also be ...@@ -147,10 +146,9 @@ MacPorts, missing ones need to be installed manually. It may also be
mentioned that one should only use one package manager, as multiple ones mentioned that one should only use one package manager, as multiple ones
may cause trouble. may cause trouble.
- Install basic packages numpy and cython: - Install numpy:
sudo port install py27-numpy sudo port install py27-numpy
sudo port install py27-cython
- Install pyHealpix: - Install pyHealpix:
......
numpy numpy
cython
mpi4py mpi4py
matplotlib matplotlib
plotly plotly
......
...@@ -11,16 +11,36 @@ rank = comm.rank ...@@ -11,16 +11,36 @@ rank = comm.rank
if __name__ == "__main__": if __name__ == "__main__":
distribution_strategy = 'not' distribution_strategy = 'not'
#Setting up physical constants
#total length of Interval or Volume the field lives on, e.g. in meters
L = 2.
#typical distance over which the field is correlated (in same unit as L)
correlation_length = 0.1
#variance of field in position space sqrt(<|s_x|^2>) (in unit of s)
field_variance = 2.
#smoothing length that response (in same unit as L)
response_sigma = 0.1
#defining resolution (pixels per dimension)
N_pixels = 512
#Setting up derived constants
k_0 = 1./correlation_length
#note that field_variance**2 = a*k_0/4. for this analytic form of power
#spectrum
a = field_variance**2/k_0*4.
pow_spec = (lambda k: a / (1 + k/k_0) ** 4)
pixel_width = L/N_pixels
# Setting up the geometry # Setting up the geometry
s_space = RGSpace([512, 512]) s_space = RGSpace([N_pixels, N_pixels], distances = pixel_width)
fft = FFTOperator(s_space) fft = FFTOperator(s_space)
h_space = fft.target[0] h_space = fft.target[0]
p_space = PowerSpace(h_space, distribution_strategy=distribution_strategy) p_space = PowerSpace(h_space, distribution_strategy=distribution_strategy)
# Creating the mock data # Creating the mock data
pow_spec = (lambda k: 42 / (k + 1) ** 3)
S = create_power_operator(h_space, power_spectrum=pow_spec, S = create_power_operator(h_space, power_spectrum=pow_spec,
distribution_strategy=distribution_strategy) distribution_strategy=distribution_strategy)
...@@ -30,7 +50,7 @@ if __name__ == "__main__": ...@@ -30,7 +50,7 @@ if __name__ == "__main__":
sh = sp.power_synthesize(real_signal=True) sh = sp.power_synthesize(real_signal=True)
ss = fft.inverse_times(sh) ss = fft.inverse_times(sh)
R = SmoothingOperator(s_space, sigma=0.1) R = SmoothingOperator(s_space, sigma=response_sigma)
signal_to_noise = 1 signal_to_noise = 1
N = DiagonalOperator(s_space, diagonal=ss.var()/signal_to_noise, bare=True) N = DiagonalOperator(s_space, diagonal=ss.var()/signal_to_noise, bare=True)
......
...@@ -91,7 +91,7 @@ if __name__ == "__main__": ...@@ -91,7 +91,7 @@ if __name__ == "__main__":
x1 = HPSpace(64) x1 = HPSpace(64)
k1 = HPLMTransformation.get_codomain(x1) k1 = HPLMTransformation.get_codomain(x1)
p1 = PowerSpace(harmonic_domain=k1, log=False) p1 = PowerSpace(harmonic_partner=k1, logarithmic=False)
# creating Power Operator with given spectrum # creating Power Operator with given spectrum
spec = (lambda k: a_s / (1 + (k / k_0) ** 2) ** 2) spec = (lambda k: a_s / (1 + (k / k_0) ** 2) ** 2)
...@@ -107,7 +107,7 @@ if __name__ == "__main__": ...@@ -107,7 +107,7 @@ if __name__ == "__main__":
exposure=[exposure]) exposure=[exposure])
# drawing a random field # drawing a random field
sk = p_field.power_synthesize(decompose_power=True, mean=0.) sk = p_field.power_synthesize(real_power=True, mean=0.)
s = Fft_op.adjoint_times(sk) s = Fft_op.adjoint_times(sk)
signal_to_noise = 1 signal_to_noise = 1
......
This diff is collapsed.
...@@ -24,7 +24,7 @@ from diagonal_operator import DiagonalOperator ...@@ -24,7 +24,7 @@ from diagonal_operator import DiagonalOperator
from endomorphic_operator import EndomorphicOperator from endomorphic_operator import EndomorphicOperator
from smoothing_operator import SmoothingOperator from smoothing_operator import *
from fft_operator import * from fft_operator import *
......
...@@ -20,45 +20,53 @@ from nifty.operators.linear_operator import LinearOperator ...@@ -20,45 +20,53 @@ from nifty.operators.linear_operator import LinearOperator
class ComposedOperator(LinearOperator): class ComposedOperator(LinearOperator):
""" NIFTY class for composed operators.
"""NIFTY class for composed operators. The NIFTY composed operator class combines multiple linear operators.
The NIFTY composed operator class inherits multiple Operators of various kinds acting on
a Field living over a product space.
Parameters Parameters
---------- ----------
Operators : tuple(NIFTy.LinearOperators) operators : tuple of NIFTy Operators
Contains the list of LinearOperators. The tuple of LinearOperators.
default_spaces : tuple of ints *optional*
Defines on which space(s) of a given field the Operator acts by
default (default: None)
Attributes Attributes
---------- ----------
domain : NIFTy.space domain : tuple of DomainObjects, i.e. Spaces and FieldTypes
The NIFTy.space in which the operator is defined. The NIFTy.space in which the operator is defined.
target : NIFTy.space target : tuple of DomainObjects, i.e. Spaces and FieldTypes
The NIFTy.space in which the outcome of the operator lives The NIFTy.space in which the outcome of the operator lives
unitary : boolean
Indicates whether the Operator is unitary or not.
Raises Raises
------ ------
TypeError TypeError
Raised if Raised if
* the elements of the operator list is not an instance of the * an element of the operator list is not an instance of the
LinearOperator-baseclass LinearOperator-baseclass.
Notes Notes
----- -----
Very usefull in case one has to transform a NIFTy.Field living over the product space. (see example below) Very usefull in case one has to transform a Field living over a product
space (see example below).
Examples Examples
-------- --------
Minimal example of transforming a Field living on two domains into its harmonic space. Minimal example of transforming a Field living on two domains into its
harmonic space.
>>> x1 = RGSpace(5) >>> x1 = RGSpace(5)
>>> x2 = RGSpace(10) >>> x2 = RGSpace(10)
>>> k1 = RGRGTransformation.get_codomain(x1) >>> k1 = RGRGTransformation.get_codomain(x1)
>>> k2 = RGRGTransformation.get_codomain(x2) >>> k2 = RGRGTransformation.get_codomain(x2)
>>> FFT1 = FFTOperator(domain=x1, target=k1, domain_dtype=np.float64, target_dtype=np.complex128) >>> FFT1 = FFTOperator(domain=x1, target=k1,
>>> FFT2 = FFTOperator(domain=x2, target=k2, domain_dtype=np.float64, target_dtype=np.complex128) domain_dtype=np.float64, target_dtype=np.complex128)
>>> FFT2 = FFTOperator(domain=x2, target=k2,
domain_dtype=np.float64, target_dtype=np.complex128)
>>> FFT = ComposedOperator((FFT1, FFT2) >>> FFT = ComposedOperator((FFT1, FFT2)
>>> f = Field.from_random('normal', domain=(x1,x2)) >>> f = Field.from_random('normal', domain=(x1,x2))
>>> FFT.times(f) >>> FFT.times(f)
......
...@@ -28,32 +28,46 @@ from nifty.operators.endomorphic_operator import EndomorphicOperator ...@@ -28,32 +28,46 @@ from nifty.operators.endomorphic_operator import EndomorphicOperator
class DiagonalOperator(EndomorphicOperator): class DiagonalOperator(EndomorphicOperator):
""" NIFTY class for diagonal operators.
The NIFTY DiagonalOperator class is a subclass derived from the
EndomorphicOperator. It multiplies an input field pixel-wise with its
diagonal.
"""NIFTY class for diagonal operators.
The NIFTY DiagonalOperator class is a subclass derived from the
EndomorphicOperator.
Parameters Parameters
---------- ----------
domain : tuple of DomainObjects, i.e. Spaces and FieldTypes
domain : NIFTy.Space The domain on which the Operator's input Field lives.
The Space on which the operator acts diagonal : {scalar, list, array, Field, d2o-object}
diagonal : {scalar, list, array, NIFTy.Field, d2o-object}
The diagonal entries of the operator. The diagonal entries of the operator.
bare : boolean bare : boolean
Indicates whether the diagonal entries are bare or not Indicates whether the input for the diagonal is bare or not
(default: False) (default: False).
copy : boolean copy : boolean
Internal copy of the diagonal (default: True) Internal copy of the diagonal (default: True)
distribution_strategy : string distribution_strategy : string
setting the prober distribution_strategy of the setting the prober distribution_strategy of the
diagonal (default : None). In case diagonal is d2o-object or Field, diagonal (default : None). In case diagonal is d2o-object or Field,
their distribution_strategy is reused. their distribution_strategy is used as a fallback.
default_spaces : tuple of ints *optional*
Defines on which space(s) of a given field the Operator acts by
default (default: None)
Attributes Attributes
---------- ----------
domain : tuple of DomainObjects, i.e. Spaces and FieldTypes
The domain on which the Operator's input Field lives.
target : tuple of DomainObjects, i.e. Spaces and FieldTypes
The domain in which the outcome of the operator lives. As the Operator
is endomorphic this is the same as its domain.
unitary : boolean
Indicates whether the Operator is unitary or not.
self_adjoint : boolean
Indicates whether the operator is self_adjoint or not.
distribution_strategy : string distribution_strategy : string
Defines the diagonal is distributed among the nodes. Defines the distribution_strategy of the distributed_data_object
in which the diagonal entries are stored in.
Raises Raises
------ ------
...@@ -71,12 +85,12 @@ class DiagonalOperator(EndomorphicOperator): ...@@ -71,12 +85,12 @@ class DiagonalOperator(EndomorphicOperator):
Examples Examples
-------- --------
>>> x_space = RGSpace(5) >>> x_space = RGSpace(5)
>>> D = DiagonalOperator(x_space, diagonal=2.) >>> D = DiagonalOperator(x_space, diagonal=[1., 3., 2., 4., 6.])
>>> f = Field(x_space, val=1.) >>> f = Field(x_space, val=2.)
>>> res = D.times(f) >>> res = D.times(f)
>>> res.val >>> res.val
<distributed_data_object> <distributed_data_object>
array([ 2., 2., 2., 2., 2.]) array([ 2., 6., 4., 8., 12.])
See Also See Also
-------- --------
...@@ -119,7 +133,7 @@ class DiagonalOperator(EndomorphicOperator): ...@@ -119,7 +133,7 @@ class DiagonalOperator(EndomorphicOperator):
operation=lambda z: z.adjoint().__rdiv__) operation=lambda z: z.adjoint().__rdiv__)
def diagonal(self, bare=False, copy=True): def diagonal(self, bare=False, copy=True):
""" Returns the diagonal of the operator. """ Returns the diagonal of the Operator.
Parameters Parameters
---------- ----------
...@@ -130,11 +144,9 @@ class DiagonalOperator(EndomorphicOperator): ...@@ -130,11 +144,9 @@ class DiagonalOperator(EndomorphicOperator):
Returns Returns
------- -------
out : NIFTy.Field out : Field
the diagonal of the Operator The diagonal of the Operator.
See Also
--------
""" """
if bare: if bare:
diagonal = self._diagonal.weight(power=-1) diagonal = self._diagonal.weight(power=-1)
...@@ -154,12 +166,10 @@ class DiagonalOperator(EndomorphicOperator): ...@@ -154,12 +166,10 @@ class DiagonalOperator(EndomorphicOperator):
Returns Returns
------- -------
out : NIFTy.Field out : Field
the inverse-diagonal of the Operator The inverse of the diagonal of the Operator.
See Also """
--------
"""
return 1./self.diagonal(bare=bare, copy=False) return 1./self.diagonal(bare=bare, copy=False)
def trace(self, bare=False): def trace(self, bare=False):
...@@ -173,10 +183,8 @@ class DiagonalOperator(EndomorphicOperator): ...@@ -173,10 +183,8 @@ class DiagonalOperator(EndomorphicOperator):
Returns Returns
------- -------
out : scalar out : scalar
the trace of the Operator