Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
9580b98a
Commit
9580b98a
authored
May 09, 2017
by
Pumpe, Daniel (dpumpe)
Browse files
merged latest unit branch
parent
b2c23a9f
Changes
33
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
9580b98a
...
...
@@ -101,7 +101,7 @@ Starting with a fresh Ubuntu installation move to a folder like
git clone https://gitlab.mpcdf.mpg.de/ift/pyHealpix.git
cd pyHealpix
autoreconf -i && ./configure && sudo make install
autoreconf -i && ./configure &&
make -j4 &&
sudo make install
cd ..
-
Finally, NIFTy:
...
...
@@ -135,7 +135,7 @@ For pyHealpix, use:
git clone https://gitlab.mpcdf.mpg.de/ift/pyHealpix.git
cd pyHealpix
autoreconf -i && ./configure --prefix=$HOME/.local && make install
autoreconf -i && ./configure --prefix=$HOME/.local && make
-j4 && make
install
cd ..
### Installation on OS X 10.11
...
...
@@ -156,7 +156,7 @@ may cause trouble.
git clone https://gitlab.mpcdf.mpg.de/ift/pyHealpix.git
cd pyHealpix
autoreconf -i && ./configure && sudo make install
autoreconf -i && ./configure
--prefix=`python-config --prefix` && make -j4
&& sudo make install
cd ..
-
Install NIFTy:
...
...
nifty/domain_object.py
View file @
9580b98a
...
...
@@ -17,13 +17,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
abc
from
nifty.nifty_meta
import
NiftyMeta
from
keepers
import
Loggable
,
\
Versionable
class
DomainObject
(
Versionable
,
Loggable
,
object
):
__metaclass__
=
abc
.
ABC
Meta
__metaclass__
=
Nifty
Meta
def
__init__
(
self
):
# _global_id is used in the Versioning module from keepers
...
...
nifty/energies/energy.py
View file @
9580b98a
...
...
@@ -16,10 +16,14 @@
# 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
nifty.nifty_meta
import
NiftyMeta
from
keepers
import
Loggable
class
Energy
(
Loggable
,
object
):
__metaclass__
=
NiftyMeta
def
__init__
(
self
,
position
):
self
.
_cache
=
{}
try
:
...
...
nifty/minimization/quasi_newton_minimizer.py
View file @
9580b98a
...
...
@@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
abc
from
nifty.nifty_meta
import
NiftyMeta
import
numpy
as
np
...
...
@@ -26,7 +27,7 @@ from .line_searching import LineSearchStrongWolfe
class
QuasiNewtonMinimizer
(
Loggable
,
object
):
__metaclass__
=
abc
.
ABC
Meta
__metaclass__
=
Nifty
Meta
def
__init__
(
self
,
line_searcher
=
LineSearchStrongWolfe
(),
callback
=
None
,
convergence_tolerance
=
1E-4
,
convergence_level
=
3
,
...
...
nifty/nifty_meta.py
0 → 100644
View file @
9580b98a
# -*- coding: utf-8 -*-
import
abc
class
DocStringInheritor
(
type
):
"""
A variation on
http://groups.google.com/group/comp.lang.python/msg/26f7b4fcb4d66c95
by Paul McGuire
"""
def
__new__
(
meta
,
name
,
bases
,
clsdict
):
if
not
(
'__doc__'
in
clsdict
and
clsdict
[
'__doc__'
]):
for
mro_cls
in
(
mro_cls
for
base
in
bases
for
mro_cls
in
base
.
mro
()):
doc
=
mro_cls
.
__doc__
if
doc
:
clsdict
[
'__doc__'
]
=
doc
break
for
attr
,
attribute
in
clsdict
.
items
():
if
not
attribute
.
__doc__
:
for
mro_cls
in
(
mro_cls
for
base
in
bases
for
mro_cls
in
base
.
mro
()
if
hasattr
(
mro_cls
,
attr
)):
doc
=
getattr
(
getattr
(
mro_cls
,
attr
),
'__doc__'
)
if
doc
:
if
isinstance
(
attribute
,
property
):
clsdict
[
attr
]
=
property
(
attribute
.
fget
,
attribute
.
fset
,
attribute
.
fdel
,
doc
)
else
:
attribute
.
__doc__
=
doc
break
return
super
(
DocStringInheritor
,
meta
).
__new__
(
meta
,
name
,
bases
,
clsdict
)
class
NiftyMeta
(
DocStringInheritor
,
abc
.
ABCMeta
):
pass
nifty/operators/composed_operator/composed_operator.py
View file @
9580b98a
...
...
@@ -54,10 +54,6 @@ class ComposedOperator(LinearOperator):
self
.
_target
+=
op
.
target
return
self
.
_target
@
property
def
implemented
(
self
):
return
True
@
property
def
unitary
(
self
):
return
False
...
...
nifty/operators/diagonal_operator/diagonal_operator.py
View file @
9580b98a
...
...
@@ -85,13 +85,11 @@ class DiagonalOperator(EndomorphicOperator):
# ---Overwritten properties and methods---
def
__init__
(
self
,
domain
=
(),
implemented
=
True
,
def
__init__
(
self
,
domain
=
(),
diagonal
=
None
,
bare
=
False
,
copy
=
True
,
distribution_strategy
=
None
):
self
.
_domain
=
self
.
_parse_domain
(
domain
)
self
.
_implemented
=
bool
(
implemented
)
if
distribution_strategy
is
None
:
if
isinstance
(
diagonal
,
distributed_data_object
):
distribution_strategy
=
diagonal
.
distribution_strategy
...
...
@@ -265,10 +263,6 @@ class DiagonalOperator(EndomorphicOperator):
def
domain
(
self
):
return
self
.
_domain
@
property
def
implemented
(
self
):
return
self
.
_implemented
@
property
def
self_adjoint
(
self
):
if
self
.
_self_adjoint
is
None
:
...
...
@@ -329,16 +323,12 @@ class DiagonalOperator(EndomorphicOperator):
distribution_strategy
=
self
.
distribution_strategy
,
copy
=
copy
)
# weight if the given values were `bare`
and `implemented`
is True
# weight if the given values were `bare` is True
# do inverse weightening if the other way around
if
bare
and
self
.
implemented
:
if
bare
:
# If `copy` is True, we won't change external data by weightening
# Otherwise, inplace weightening would change the external field
f
.
weight
(
inplace
=
copy
)
elif
not
bare
and
not
self
.
implemented
:
# If `copy` is True, we won't change external data by weightening
# Otherwise, inplace weightening would change the external field
f
.
weight
(
inplace
=
copy
,
power
=-
1
)
# Reset the self_adjoint property:
self
.
_self_adjoint
=
None
...
...
nifty/operators/fft_operator/fft_operator.py
View file @
9580b98a
...
...
@@ -152,10 +152,6 @@ class FFTOperator(LinearOperator):
def
target
(
self
):
return
self
.
_target
@
property
def
implemented
(
self
):
return
True
@
property
def
unitary
(
self
):
return
True
...
...
nifty/operators/linear_operator/linear_operator.py
View file @
9580b98a
...
...
@@ -82,9 +82,6 @@ class LinearOperator(Loggable, object):
@
abc
.
abstractproperty
def
domain
(
self
):
"""
asdff
"""
raise
NotImplementedError
@
abc
.
abstractproperty
...
...
nifty/operators/projection_operator/projection_operator.py
View file @
9580b98a
...
...
@@ -140,10 +140,6 @@ class ProjectionOperator(EndomorphicOperator):
def
domain
(
self
):
return
self
.
_projection_field
.
domain
@
property
def
implemented
(
self
):
return
True
@
property
def
unitary
(
self
):
if
self
.
_unitary
is
None
:
...
...
nifty/operators/propagator_operator/propagator_operator.py
View file @
9580b98a
...
...
@@ -123,10 +123,6 @@ class PropagatorOperator(InvertibleOperatorMixin, EndomorphicOperator):
def
domain
(
self
):
return
self
.
_domain
@
property
def
implemented
(
self
):
return
True
@
property
def
self_adjoint
(
self
):
return
True
...
...
nifty/operators/smoothing_operator/smoothing_operator.py
View file @
9580b98a
...
...
@@ -53,10 +53,6 @@ class SmoothingOperator(EndomorphicOperator):
def
domain
(
self
):
return
self
.
_domain
@
property
def
implemented
(
self
):
return
True
@
property
def
self_adjoint
(
self
):
return
True
...
...
nifty/plotting/__init__.py
View file @
9580b98a
from
descriptors
import
*
from
plots
import
*
from
figures
import
*
from
colormap
import
*
\ No newline at end of file
nifty/plotting/colormap/__init__.py
0 → 100644
View file @
9580b98a
from
colormap
import
Colormap
import
colormaps
\ No newline at end of file
nifty/plotting/colormap/colormaps.py
0 → 100644
View file @
9580b98a
from
nifty.plotting.colormap.colormap
import
Colormap
def
HighEnergyCmap
():
"""
Returns a color map often used in High Energy Astronomy.
"""
red
=
[(
0.0
,
0.0
),
(
0.167
,
0.0
),
(
0.333
,
0.5
),
(
0.5
,
1.0
),
(
0.667
,
1.0
),
(
0.833
,
1.0
),
(
1.0
,
1.0
)]
green
=
[(
0.0
,
0.0
),
(
0.167
,
0.0
),
(
0.333
,
0.0
),
(
0.5
,
0.0
),
(
0.667
,
0.5
),
(
0.833
,
1.0
),
(
1.0
,
1.0
)]
blue
=
[(
0.0
,
0.0
),
(
0.167
,
1.0
),
(
0.333
,
0.5
),
(
0.5
,
0.0
),
(
0.667
,
0.0
),
(
0.833
,
0.0
),
(
1.0
,
1.0
)]
return
Colormap
(
"High Energy"
,
red
,
green
,
blue
)
def
FaradayMapCmap
():
"""
Returns a color map used in reconstruction of the "Faraday Map".
References
----------
.. [#] N. Opermann et. al.,
"An improved map of the Galactic Faraday sky",
Astronomy & Astrophysics, Volume 542, id.A93, 06/2012;
`arXiv:1111.6186 <http://www.arxiv.org/abs/1111.6186>`_
"""
red
=
[(
0.0
,
0.35
),
(
0.1
,
0.4
),
(
0.2
,
0.25
),
(
0.41
,
0.47
),
(
0.5
,
0.8
),
(
0.56
,
0.96
),
(
0.59
,
1.0
),
(
0.74
,
0.8
),
(
0.8
,
0.8
),
(
0.9
,
0.5
),
(
1.0
,
0.4
)]
green
=
[(
0.0
,
0.0
),
(
0.2
,
0.0
),
(
0.362
,
0.88
),
(
0.5
,
1.0
),
(
0.638
,
0.88
),
(
0.8
,
0.25
),
(
0.9
,
0.3
),
(
1.0
,
0.2
)]
blue
=
[(
0.0
,
0.35
),
(
0.1
,
0.4
),
(
0.2
,
0.8
),
(
0.26
,
0.8
),
(
0.41
,
1.0
),
(
0.44
,
0.96
),
(
0.5
,
0.8
),
(
0.59
,
0.47
),
(
0.8
,
0.0
),
(
1.0
,
0.0
)]
return
Colormap
(
"Faraday Map"
,
red
,
green
,
blue
)
def
FaradayUncertaintyCmap
():
"""
Returns a color map used for the "Faraday Map Uncertainty".
References
----------
.. [#] N. Opermann et. al.,
"An improved map of the Galactic Faraday sky",
Astronomy & Astrophysics, Volume 542, id.A93, 06/2012;
`arXiv:1111.6186 <http://www.arxiv.org/abs/1111.6186>`_
"""
red
=
[(
0.0
,
1.0
),
(
0.1
,
0.8
),
(
0.2
,
0.65
),
(
0.41
,
0.6
),
(
0.5
,
0.7
),
(
0.56
,
0.96
),
(
0.59
,
1.0
),
(
0.74
,
0.8
),
(
0.8
,
0.8
),
(
0.9
,
0.5
),
(
1.0
,
0.4
)]
green
=
[(
0.0
,
0.9
),
(
0.2
,
0.65
),
(
0.362
,
0.95
),
(
0.5
,
1.0
),
(
0.638
,
0.88
),
(
0.8
,
0.25
),
(
0.9
,
0.3
),
(
1.0
,
0.2
)]
blue
=
[(
0.0
,
1.0
),
(
0.1
,
0.8
),
(
0.2
,
1.0
),
(
0.41
,
1.0
),
(
0.44
,
0.96
),
(
0.5
,
0.7
),
(
0.59
,
0.42
),
(
0.8
,
0.0
),
(
1.0
,
0.0
)]
return
Colormap
(
"Faraday Uncertainty"
,
red
,
green
,
blue
)
def
PlusMinusCmap
():
"""
Returns a color map useful for a zero-centerd range of values.
"""
red
=
[(
0.0
,
1.0
),
(
0.1
,
0.96
),
(
0.2
,
0.84
),
(
0.3
,
0.64
),
(
0.4
,
0.36
),
(
0.5
,
0.0
),
(
0.6
,
0.0
),
(
0.7
,
0.0
),
(
0.8
,
0.0
),
(
0.9
,
0.0
),
(
1.0
,
0.0
)]
green
=
[(
0.0
,
0.5
),
(
0.1
,
0.32
),
(
0.2
,
0.18
),
(
0.3
,
0.08
),
(
0.4
,
0.02
),
(
0.5
,
0.0
),
(
0.6
,
0.02
),
(
0.7
,
0.08
),
(
0.8
,
0.18
),
(
0.9
,
0.32
),
(
1.0
,
0.5
)]
blue
=
[(
0.0
,
0.0
),
(
0.1
,
0.0
),
(
0.2
,
0.0
),
(
0.3
,
0.0
),
(
0.4
,
0.0
),
(
0.5
,
0.0
),
(
0.6
,
0.36
),
(
0.7
,
0.64
),
(
0.8
,
0.84
),
(
0.9
,
0.96
),
(
1.0
,
1.0
)]
return
Colormap
(
"Plus Minus"
,
red
,
green
,
blue
)
def
PlankCmap
():
"""
Returns a color map similar to the one used for the "Planck CMB Map".
"""
red
=
[(
0.0
,
0.0
),
(
0.1
,
0.0
),
(
0.2
,
0.0
),
(
0.3
,
0.0
),
(
0.4
,
0.0
),
(
0.5
,
1.0
),
(
0.6
,
1.0
),
(
0.7
,
1.0
),
(
0.8
,
0.83
),
(
0.9
,
0.67
),
(
1.0
,
0.5
)]
green
=
[(
0.0
,
0.0
),
(
0.1
,
0.0
),
(
0.2
,
0.0
),
(
0.3
,
0.3
),
(
0.4
,
0.7
),
(
0.5
,
1.0
),
(
0.6
,
0.7
),
(
0.7
,
0.3
),
(
0.8
,
0.0
),
(
0.9
,
0.0
),
(
1.0
,
0.0
)]
blue
=
[(
0.0
,
0.5
),
(
0.1
,
0.67
),
(
0.2
,
0.83
),
(
0.3
,
1.0
),
(
0.4
,
1.0
),
(
0.5
,
1.0
),
(
0.6
,
0.0
),
(
0.7
,
0.0
),
(
0.8
,
0.0
),
(
0.9
,
0.0
),
(
1.0
,
0.0
)]
return
Colormap
(
"Planck-like"
,
red
,
green
,
blue
)
nifty/plotting/figures/figure_2D.py
View file @
9580b98a
...
...
@@ -7,6 +7,7 @@ from nifty.plotting.plots import Heatmap, Mollweide
class
Figure2D
(
FigureFromPlot
):
def
__init__
(
self
,
plots
,
title
=
None
,
width
=
None
,
height
=
None
,
xaxis
=
None
,
yaxis
=
None
):
super
(
Figure2D
,
self
).
__init__
(
plots
,
title
,
width
,
height
)
# TODO: add sanitization of plots input
if
isinstance
(
plots
[
0
],
Heatmap
)
and
not
width
and
not
height
:
...
...
@@ -45,7 +46,7 @@ class Figure2D(FigureFromPlot):
showticklabels
=
False
)
if
self
.
yaxis
:
plotly_object
[
'layout'
][
'yaxis'
]
=
self
.
yaxis
.
_
to_plotly
()
plotly_object
[
'layout'
][
'yaxis'
]
=
self
.
yaxis
.
to_plotly
()
elif
not
self
.
yaxis
:
plotly_object
[
'layout'
][
'yaxis'
]
=
dict
(
showline
=
False
)
...
...
nifty/plotting/figures/figure_base.py
View file @
9580b98a
# -*- coding: utf-8 -*-
from
abc
import
abstractmethod
from
nifty.plotting.plotly_wrapper
import
PlotlyWrapper
...
...
@@ -8,3 +10,7 @@ class FigureBase(PlotlyWrapper):
self
.
title
=
title
self
.
width
=
width
self
.
height
=
height
@
abstractmethod
def
to_plotly
(
self
):
raise
NotImplementedError
nifty/plotting/figures/figure_from_plot.py
View file @
9580b98a
...
...
@@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
from
abc
import
abstractmethod
from
figure_base
import
FigureBase
...
...
@@ -11,7 +10,6 @@ class FigureFromPlot(FigureBase):
super
(
FigureFromPlot
,
self
).
__init__
(
title
,
width
,
height
)
self
.
plots
=
plots
@
abstractmethod
def
to_plotly
(
self
):
data
=
[
plt
.
to_plotly
()
for
plt
in
self
.
plots
]
layout
=
{
'title'
:
self
.
title
,
...
...
nifty/plotting/figures/multi_figure.py
View file @
9580b98a
# -*- coding: utf-8 -*-
import
numpy
as
np
from
nifty
import
dependency_injector
as
gdi
from
figure_base
import
FigureBase
from
figure_3D
import
Figure3D
plotly
=
gdi
.
get
(
'plotly'
)
# TODO: add nice height and width defaults for multifigure
class
MultiFigure
(
FigureBase
):
def
__init__
(
self
,
rows
,
columns
,
subfigures
=
None
,
title
=
None
,
width
=
None
,
height
=
None
):
def
__init__
(
self
,
rows
,
columns
,
title
=
None
,
width
=
None
,
height
=
None
,
subfigures
=
None
):
if
'plotly'
not
in
gdi
:
raise
ImportError
(
"The module plotly is needed but not available."
)
super
(
MultiFigure
,
self
).
__init__
(
title
,
width
,
height
)
...
...
@@ -31,43 +30,30 @@ class MultiFigure(FigureBase):
self
.
subfigures
[
row
,
column
]
=
figure
def
to_plotly
(
self
):
sub_titles
=
self
.
subfigures
.
copy
()
sub_titles
=
sub_titles
.
flatten
title_extractor
=
lambda
z
:
z
.
title
sub_titles
=
np
.
vectorize
(
title_extractor
)(
sub_titles
)
title_extractor
=
lambda
z
:
z
.
title
if
z
else
""
sub_titles
=
\
tuple
(
np
.
vectorize
(
title_extractor
)(
self
.
subfigures
.
flatten
()))
sub_specs
=
self
.
subfigures
.
copy_empty
()
specs_setter
=
\
lambda
z
:
{
'is_3d'
:
True
}
if
isinstance
(
z
,
Figure3D
)
else
{}
sub_specs
=
np
.
vectorize
(
specs_setter
)(
sub_specs
)
sub_specs
=
\
list
(
map
(
list
,
np
.
vectorize
(
specs_setter
)(
self
.
subfigures
)))
multi_figure_plotly_object
=
plotly
.
tools
.
make_subplots
(
self
.
rows
,
self
.
columns
,
subplot_titles
=
sub_titles
,
specs
=
sub_specs
)
# TODO resolve bug with titles and 3D subplots
for
index
,
fig
in
np
.
ndenumerate
(
self
.
subfigures
):
for
plot
in
fig
.
plots
:
multi_figure_plotly_object
.
append_trace
(
plot
.
to_plotly
(),
index
[
0
]
+
1
,
index
[
1
]
+
1
)
if
fig
:
for
plot
in
fig
.
plots
:
multi_figure_plotly_object
.
append_trace
(
plot
.
to_plotly
(),
index
[
0
]
+
1
,
index
[
1
]
+
1
)
multi_figure_plotly_object
[
'layout'
].
update
(
height
=
self
.
height
,
width
=
self
.
width
,
title
=
self
.
title
)
return
multi_figure_plotly_object
@
staticmethod
def
from_figures_2cols
(
figures
,
title
=
None
,
width
=
None
,
height
=
None
):
multi_figure
=
MultiFigure
((
len
(
figures
)
+
1
)
/
2
,
2
,
title
,
width
,
height
)
for
i
in
range
(
0
,
len
(
figures
),
2
):
multi_figure
.
add_subfigure
(
figures
[
i
],
i
/
2
,
0
)
for
i
in
range
(
1
,
len
(
figures
),
2
):
multi_figure
.
add_subfigure
(
figures
[
i
],
i
/
2
,
1
)
return
multi_figure
return
multi_figure_plotly_object
nifty/plotting/plotly_wrapper.py
View file @
9580b98a
from
abc
import
ABCMeta
,
abstractmethod
from
nifty.nifty_meta
import
NiftyMeta
class
PlotlyWrapper
(
object
):
__metaclass__
=
ABC
Meta
__metaclass__
=
Nifty
Meta
@
abstractmethod
def
to_plotly
(
self
):
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment