Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
9c0dde2d
Commit
9c0dde2d
authored
May 16, 2017
by
Pumpe, Daniel (dpumpe)
Browse files
Merge branch 'master' of gitlab.mpcdf.mpg.de:ift/NIFTy
parents
6e2802da
76133243
Changes
21
Expand all
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
9c0dde2d
...
...
@@ -13,7 +13,7 @@ before_script:
-
apt-get update
-
>
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
-
chmod +x ci/*.sh
...
...
Makefile
deleted
100644 → 0
View file @
6e2802da
# 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
PKG-INFO
deleted
100644 → 0
View file @
6e2802da
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
README.md
View file @
9c0dde2d
...
...
@@ -15,7 +15,7 @@ Summary
a versatile library designed to enable the development of signal
inference algorithms that operate regardless of the underlying spatial
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.
NIFTY offers a toolkit that abstracts discretized representations of
...
...
@@ -38,25 +38,25 @@ certain grids, **fields** that are defined on spaces, and **operators**
that apply to fields.
-
[
Spaces
](
http://www.mpa-garching.mpg.de/ift/nifty/space.html
)
-
`
rg_s
pace`
-
*n*
-dimensional regular Euclidean grid
-
`
lm_s
pace`
- spherical harmonics
-
`
gl_s
pace`
- Gauss-Legendre grid on the 2-sphere
-
`
hp_s
pace`
-
[
HEALPix
](
http://sourceforge.net/projects/healpix/
)
-
`
RGS
pace`
-
*n*
-dimensional regular Euclidean grid
-
`
LMS
pace`
- spherical harmonics
-
`
GLS
pace`
- Gauss-Legendre grid on the 2-sphere
-
`
HPS
pace`
-
[
HEALPix
](
http://sourceforge.net/projects/healpix/
)
grid on the 2-sphere
-
[
Fields
](
http://www.mpa-garching.mpg.de/ift/nifty/field.html
)
-
`
f
ield`
- generic class for (discretized) fields
-
`
F
ield`
- generic class for (discretized) fields
<!-- -->
f
ield.conjugate
f
ield.dim
f
ield.norm
f
ield.dot
f
ield.set_val
f
ield.weight
F
ield.conjugate
F
ield.dim
F
ield.norm
F
ield.dot
F
ield.set_val
F
ield.weight
-
[
Operators
](
http://www.mpa-garching.mpg.de/ift/nifty/operator.html
)
-
`
d
iagonal
_o
perator`
- purely diagonal matrices in a specified
-
`
D
iagonal
O
perator`
- purely diagonal matrices in a specified
basis
-
`
p
rojection
_o
perator`
- projections onto subsets of a specified
-
`
P
rojection
O
perator`
- projections onto subsets of a specified
basis
-
`
p
ropagator
_o
perator`
- information propagator in Wiener filter
-
`
P
ropagator
O
perator`
- information propagator in Wiener filter
theory
-
(and more)
-
(and more)
...
...
@@ -71,16 +71,18 @@ Installation
-
[
Python
](
http://www.python.org/
)
(
v2.7.x
)
-
[
NumPy
](
http://www.numpy.org/
)
-
[
Cython
](
http://cython.org/
)
### Download
The latest release is tagged
**v1.0.7**
and is available as a source
package at
[](
https://gitlab.mpcdf.mpg.de/ift/NIFTy/tags
)
. The current
version can be obtained by cloning the repository:
The current version of Nifty3 can be obtained by cloning the repository:
git clone https://gitlab.mpcdf.mpg.de/ift/NIFTy.git
and switching to the "master" branch:
cd NIFTy
git checkout master
### Installation on Ubuntu
This is for you if you want to install NIFTy on your personal computer
...
...
@@ -90,53 +92,31 @@ Starting with a fresh Ubuntu installation move to a folder like
-
Install basic packages like python, python-dev, gsl and others:
sudo apt-get install curl git autoconf
sudo apt-get install python-dev python-pip gsl-bin libgsl0-dev libfreetype6-dev libpng-dev libatlas-base-dev
-
Using pip install numpy etc...:
sudo pip install numpy cython
sudo apt-get install curl git autoconf python-dev python-pip python-numpy
-
Install pyHealpix:
git clone https://gitlab.mpcdf.mpg.de/ift/pyHealpix.git
cd pyHealpix
autoreconf -i && ./configure && make -j4 &&
sudo
make install
autoreconf -i && ./configure
--prefix=$HOME/.local
&& make -j4 && make install
cd ..
-
Finally, NIFTy:
git clone https://gitlab.mpcdf.mpg.de/ift/NIFTy.git
cd nifty
sudo python setup.py install
cd NIFTy
git checkout master
python setup.py install --user
cd ..
### Installation on a Linux cluster
This is for you if you want to install NIFTy on a HPC machine or cluster
that is hosted by your university or institute. Most of the dependencies
will most likely already be there, but you won't have superuser
privileges. In this case, instead of:
sudo python setup.py install
use:
python setup.py install --user
or:
### Installation on Linux systems in general
python setup.py install --install-lib=/SOMEWHERE
in the instruction above. This will install the python packages into
your local user directory.
For pyHealpix, use:
git clone https://gitlab.mpcdf.mpg.de/ift/pyHealpix.git
cd pyHealpix
autoreconf -i && ./configure --prefix=$HOME/.local && make -j4 && make install
cd ..
Since all the "unconventional" packages (i.e. pyHealpix and NIFTy) listed in the
section above are installed
within the home directory of the user, the installation instructions for these
should also work on any Linux machine where you do not have root access.
In this case you have to ensure with your system administrators that the
"standard" dependencies (python, numpy, etc.) are installed system-wide.
### Installation on OS X 10.11
...
...
@@ -147,10 +127,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
may cause trouble.
-
Install
basic packages numpy and cython
:
-
Install
numpy
:
sudo port install py27-numpy
sudo port install py27-cython
-
Install pyHealpix:
...
...
@@ -159,24 +138,18 @@ may cause trouble.
autoreconf -i && ./configure --prefix=`python-config --prefix` && make -j4 && sudo make install
cd ..
(The third command installs the package system-wide. User-specific
installation would be preferrable, but we haven't found a simple recipe yet
how to determine the installation prefix ...)
-
Install NIFTy:
git clone https://gitlab.mpcdf.mpg.de/ift/NIFTy.git
cd nifty
sudo python setup.py install
cd NIFTy
git checkout master
python setup.py install --user
cd ..
### Installation using pypi
NIFTY can be installed using
[
PyPI
](
https://pypi.python.org/pypi
)
and
**pip**
by running the following command:
pip install ift_nifty
Alternatively, a private or user specific installation can be done by:
pip install --user ift_nifty
### Running the tests
In oder to run the tests one needs two additional packages:
...
...
@@ -224,4 +197,4 @@ The NIFTY package is licensed under the
[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
)
[
arXiv:1301.4499
](
http://www.arxiv.org/abs/1301.4499
)
\ No newline at end of file
ci/install_pyfftw.sh
View file @
9c0dde2d
#!/bin/bash
git clone
-b
mpi https://github.com/
ultimanet
/pyFFTW.git
git clone
-b
mpi https://github.com/
fredros
/pyFFTW.git
cd
pyFFTW/
CC
=
mpicc python setup.py build_ext
install
cd
..
...
...
ci/requirements.txt
View file @
9c0dde2d
numpy
cython
mpi4py
matplotlib
plotly
...
...
nifty/domain_object.py
View file @
9c0dde2d
...
...
@@ -87,7 +87,7 @@ class DomainObject(Versionable, Loggable, object):
@
abc
.
abstractproperty
def
shape
(
self
):
"""
Returns the shape of
the underlying array
-like object
.
"""
The domain-object's shape contribution to
the underlying array.
Returns
-------
...
...
nifty/field.py
View file @
9c0dde2d
This diff is collapsed.
Click to expand it.
nifty/operators/__init__.py
View file @
9c0dde2d
...
...
@@ -24,7 +24,7 @@ from diagonal_operator import DiagonalOperator
from
endomorphic_operator
import
EndomorphicOperator
from
smoothing_operator
import
SmoothingOperator
from
smoothing_operator
import
*
from
fft_operator
import
*
...
...
nifty/operators/linear_operator/linear_operator.py
View file @
9c0dde2d
...
...
@@ -75,7 +75,8 @@ class LinearOperator(Loggable, object):
def
__init__
(
self
,
default_spaces
=
None
):
self
.
default_spaces
=
default_spaces
def
_parse_domain
(
self
,
domain
):
@
staticmethod
def
_parse_domain
(
domain
):
return
utilities
.
parse_domain
(
domain
)
@
abc
.
abstractproperty
...
...
nifty/operators/response_operator/response_operator.py
View file @
9c0dde2d
...
...
@@ -6,6 +6,7 @@ from nifty.operators.smoothing_operator import SmoothingOperator
from
nifty.operators.composed_operator
import
ComposedOperator
from
nifty.operators.diagonal_operator
import
DiagonalOperator
class
ResponseOperator
(
LinearOperator
):
""" NIFTy ResponseOperator (example)
...
...
nifty/operators/smoothing_operator/__init__.py
View file @
9c0dde2d
...
...
@@ -16,4 +16,4 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
smoothing_operator
import
SmoothingOperator
from
.
smoothing_operator
import
SmoothingOperator
nifty/operators/smoothing_operator/direct_smoothing_operator.py
0 → 100644
View file @
9c0dde2d
# -*- coding: utf8 -*-
import
numpy
as
np
from
d2o
import
STRATEGIES
from
.smoothing_operator
import
SmoothingOperator
class
DirectSmoothingOperator
(
SmoothingOperator
):
def
__init__
(
self
,
domain
,
sigma
,
log_distances
=
False
,
default_spaces
=
None
):
super
(
DirectSmoothingOperator
,
self
).
__init__
(
domain
,
sigma
,
log_distances
,
default_spaces
)
self
.
effective_smoothing_width
=
3.01
def
_precompute
(
self
,
x
,
sigma
,
dxmax
=
None
):
""" Does precomputations for Gaussian smoothing on a 1D irregular grid.
Parameters
----------
x: 1D floating point array or list containing the individual grid
positions. Points must be given in ascending order.
sigma: The sigma of the Gaussian with which the function living on x
should be smoothed, in the same units as x.
dxmax: (optional) The maximum distance up to which smoothing is
performed, in the same units as x. Default is 3.01*sigma.
Returns
-------
ibegin: integer array of the same size as x
ibegin[i] is the minimum grid index to consider when computing the
smoothed value at grid index i
nval: integer array of the same size as x
nval[i] is the number of indices to consider when computing the
smoothed value at grid index i.
wgt: list with the same number of entries as x
wgt[i] is an array with nval[i] entries containing the
normalized smoothing weights.
"""
if
dxmax
is
None
:
dxmax
=
self
.
effective_smoothing_width
*
sigma
x
=
np
.
asarray
(
x
)
ibegin
=
np
.
searchsorted
(
x
,
x
-
dxmax
)
nval
=
np
.
searchsorted
(
x
,
x
+
dxmax
)
-
ibegin
wgt
=
[]
expfac
=
1.
/
(
2.
*
sigma
*
sigma
)
for
i
in
range
(
x
.
size
):
t
=
x
[
ibegin
[
i
]:
ibegin
[
i
]
+
nval
[
i
]]
-
x
[
i
]
t
=
np
.
exp
(
-
t
*
t
*
expfac
)
t
*=
1.
/
np
.
sum
(
t
)
wgt
.
append
(
t
)
return
ibegin
,
nval
,
wgt
def
_apply_kernel_along_array
(
self
,
power
,
startindex
,
endindex
,
distances
,
smooth_length
,
smoothing_width
,
ibegin
,
nval
,
wgt
):
if
smooth_length
==
0.0
:
return
power
[
startindex
:
endindex
]
p_smooth
=
np
.
zeros
(
endindex
-
startindex
,
dtype
=
power
.
dtype
)
for
i
in
xrange
(
startindex
,
endindex
):
imin
=
max
(
startindex
,
ibegin
[
i
])
imax
=
min
(
endindex
,
ibegin
[
i
]
+
nval
[
i
])
p_smooth
[
imin
:
imax
]
+=
(
power
[
i
]
*
wgt
[
i
][
imin
-
ibegin
[
i
]:
imax
-
imin
+
ibegin
[
i
]])
return
p_smooth
def
_apply_along_axis
(
self
,
axis
,
arr
,
startindex
,
endindex
,
distances
,
smooth_length
,
smoothing_width
):
nd
=
arr
.
ndim
if
axis
<
0
:
axis
+=
nd
if
(
axis
>=
nd
):
raise
ValueError
(
"axis must be less than arr.ndim; axis=%d, rank=%d."
%
(
axis
,
nd
))
ibegin
,
nval
,
wgt
=
self
.
_precompute
(
distances
,
smooth_length
,
smooth_length
*
smoothing_width
)
ind
=
np
.
zeros
(
nd
-
1
,
dtype
=
np
.
int
)
i
=
np
.
zeros
(
nd
,
dtype
=
object
)
shape
=
arr
.
shape
indlist
=
np
.
asarray
(
range
(
nd
))
indlist
=
np
.
delete
(
indlist
,
axis
)
i
[
axis
]
=
slice
(
None
,
None
)
outshape
=
np
.
asarray
(
shape
).
take
(
indlist
)
i
.
put
(
indlist
,
ind
)
Ntot
=
np
.
product
(
outshape
)
holdshape
=
outshape
slicedArr
=
arr
[
tuple
(
i
.
tolist
())]
res
=
self
.
_apply_kernel_along_array
(
slicedArr
,
startindex
,
endindex
,
distances
,
smooth_length
,
smoothing_width
,
ibegin
,
nval
,
wgt
)
outshape
=
np
.
asarray
(
arr
.
shape
)
outshape
[
axis
]
=
endindex
-
startindex
outarr
=
np
.
zeros
(
outshape
,
dtype
=
arr
.
dtype
)
outarr
[
tuple
(
i
.
tolist
())]
=
res
k
=
1
while
k
<
Ntot
:
# increment the index
ind
[
nd
-
1
]
+=
1
n
=
-
1
while
(
ind
[
n
]
>=
holdshape
[
n
])
and
(
n
>
(
1
-
nd
)):
ind
[
n
-
1
]
+=
1
ind
[
n
]
=
0
n
-=
1
i
.
put
(
indlist
,
ind
)
slicedArr
=
arr
[
tuple
(
i
.
tolist
())]
res
=
self
.
_apply_kernel_along_array
(
slicedArr
,
startindex
,
endindex
,
distances
,
smooth_length
,
smoothing_width
,
ibegin
,
nval
,
wgt
)
outarr
[
tuple
(
i
.
tolist
())]
=
res
k
+=
1
return
outarr
def
_smooth
(
self
,
x
,
spaces
,
inverse
):
# infer affected axes
# we rely on the knowledge, that `spaces` is a tuple with length 1.
affected_axes
=
x
.
domain_axes
[
spaces
[
0
]]
if
len
(
affected_axes
)
>
1
:
raise
ValueError
(
"By this implementation only one-dimensional "
"spaces can be smoothed directly."
)
affected_axis
=
affected_axes
[
0
]
distance_array
=
x
.
domain
[
spaces
[
0
]].
get_distance_array
(
distribution_strategy
=
'not'
)
distance_array
=
distance_array
.
get_local_data
(
copy
=
False
)
if
self
.
log_distances
:
np
.
log
(
distance_array
,
out
=
distance_array
)
# collect the local data + ghost cells
local_data_Q
=
False
if
x
.
distribution_strategy
==
'not'
:
local_data_Q
=
True
elif
x
.
distribution_strategy
in
STRATEGIES
[
'slicing'
]:
# infer the local start/end based on the slicing information of
# x's d2o. Only gets non-trivial for axis==0.
if
0
!=
affected_axis
:
local_data_Q
=
True
else
:
start_index
=
x
.
val
.
distributor
.
local_start
start_distance
=
distance_array
[
start_index
]
augmented_start_distance
=
\
(
start_distance
-
self
.
effective_smoothing_width
*
self
.
sigma
)
augmented_start_index
=
\
np
.
searchsorted
(
distance_array
,
augmented_start_distance
)
true_start
=
start_index
-
augmented_start_index
end_index
=
x
.
val
.
distributor
.
local_end
end_distance
=
distance_array
[
end_index
-
1
]
augmented_end_distance
=
\
(
end_distance
+
self
.
effective_smoothing_width
*
self
.
sigma
)
augmented_end_index
=
\
np
.
searchsorted
(
distance_array
,
augmented_end_distance
)
true_end
=
true_start
+
x
.
val
.
distributor
.
local_length
augmented_slice
=
slice
(
augmented_start_index
,
augmented_end_index
)