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
51c6d01a
Commit
51c6d01a
authored
Aug 30, 2017
by
Martin Reinecke
Browse files
PEP8
parent
8e1151de
Pipeline
#17549
passed with stage
in 17 minutes and 54 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
nifty/field.py
View file @
51c6d01a
...
...
@@ -18,7 +18,6 @@
from
__future__
import
division
from
builtins
import
zip
#from builtins import str
from
builtins
import
range
import
ast
...
...
nifty/spaces/power_space/power_space.py
View file @
51c6d01a
...
...
@@ -16,7 +16,6 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
#from builtins import str
import
ast
import
numpy
as
np
...
...
@@ -87,7 +86,7 @@ class PowerSpace(Space):
# ---Overwritten properties and methods---
@
staticmethod
def
linear_binbounds
(
nbin
,
first_bound
,
last_bound
):
def
linear_binbounds
(
nbin
,
first_bound
,
last_bound
):
"""
nbin: integer
the number of bins
...
...
@@ -100,11 +99,11 @@ class PowerSpace(Space):
values equidistantly spaced (in linear scale) between these two.
"""
nbin
=
int
(
nbin
)
assert
nbin
>=
3
,
"nbin must be at least 3"
return
np
.
linspace
(
float
(
first_bound
),
float
(
last_bound
),
nbin
-
1
)
assert
nbin
>=
3
,
"nbin must be at least 3"
return
np
.
linspace
(
float
(
first_bound
),
float
(
last_bound
),
nbin
-
1
)
@
staticmethod
def
logarithmic_binbounds
(
nbin
,
first_bound
,
last_bound
):
def
logarithmic_binbounds
(
nbin
,
first_bound
,
last_bound
):
"""
nbin: integer
the number of bins
...
...
@@ -118,7 +117,7 @@ class PowerSpace(Space):
between these two.
"""
nbin
=
int
(
nbin
)
assert
nbin
>=
3
,
"nbin must be at least 3"
assert
nbin
>=
3
,
"nbin must be at least 3"
return
np
.
logspace
(
np
.
log
(
float
(
first_bound
)),
np
.
log
(
float
(
last_bound
)),
nbin
-
1
,
base
=
np
.
e
)
...
...
@@ -153,7 +152,7 @@ class PowerSpace(Space):
binbounds
=
binbounds
,
distribution_strategy
=
distribution_strategy
)
temp_rho
=
temp_pindex
.
bincount
().
get_full_data
()
assert
not
np
.
any
(
temp_rho
==
0
),
"empty bins detected"
assert
not
np
.
any
(
temp_rho
==
0
),
"empty bins detected"
temp_kindex
=
\
(
temp_pindex
.
bincount
(
weights
=
distance_array
).
get_full_data
()
/
temp_rho
)
...
...
nifty/spaces/rg_space/rg_space.py
View file @
51c6d01a
...
...
@@ -125,6 +125,8 @@ class RGSpace(Space):
# return fixed_points
def
hermitianize_inverter
(
self
,
x
,
axes
):
if
(
not
self
.
harmonic
):
raise
NotImplementedError
if
nifty_configuration
[
'harmonic_rg_base'
]
==
'real'
:
return
x
else
:
...
...
@@ -210,7 +212,8 @@ class RGSpace(Space):
"""
if
(
not
self
.
harmonic
):
raise
NotImplementedError
if
(
not
self
.
harmonic
):
raise
NotImplementedError
shape
=
self
.
shape
# prepare the distributed_data_object
nkdict
=
distributed_data_object
(
...
...
@@ -258,7 +261,8 @@ class RGSpace(Space):
return
dists
def
get_unique_distances
(
self
):
if
(
not
self
.
harmonic
):
raise
NotImplementedError
if
(
not
self
.
harmonic
):
raise
NotImplementedError
dimensions
=
len
(
self
.
shape
)
if
dimensions
==
1
:
# extra easy
maxdist
=
self
.
shape
[
0
]
//
2
...
...
@@ -285,12 +289,14 @@ class RGSpace(Space):
return
tmp
[
np
.
diff
(
np
.
r_
[
tmp
,
2
*
tmp
[
-
1
]])
>
tol
]
def
get_natural_binbounds
(
self
):
if
(
not
self
.
harmonic
):
raise
NotImplementedError
if
(
not
self
.
harmonic
):
raise
NotImplementedError
tmp
=
self
.
get_unique_distances
()
return
0.5
*
(
tmp
[:
-
1
]
+
tmp
[
1
:])
def
get_fft_smoothing_kernel_function
(
self
,
sigma
):
if
(
not
self
.
harmonic
):
raise
NotImplementedError
if
(
not
self
.
harmonic
):
raise
NotImplementedError
return
lambda
x
:
np
.
exp
(
-
2.
*
np
.
pi
*
np
.
pi
*
x
*
x
*
sigma
*
sigma
)
# ---Added properties and methods---
...
...
nifty/spaces/space/space.py
View file @
51c6d01a
...
...
@@ -51,21 +51,18 @@ class Space(DomainObject):
Notes
-----
`Space` is an abstract base class. In order to allow for instantiation
the methods `get_distance_array`, `total_volume` and `copy` must be
implemented as well as the abstract methods inherited from
`DomainObject`.
the methods `total_volume` and `copy` must be implemented as well as the
abstract methods inherited from `DomainObject`.
"""
def
__init__
(
self
):
super
(
Space
,
self
).
__init__
()
@
abc
.
abstractproperty
def
harmonic
(
self
):
""" Returns True if this space is a harmonic space.
"""
raise
NotImplementedError
@
abc
.
abstractproperty
...
...
@@ -76,9 +73,7 @@ class Space(DomainObject):
-------
float
A real number representing the sum of all pixel volumes.
"""
raise
NotImplementedError
(
"There is no generic volume for the Space base class."
)
...
...
@@ -90,9 +85,7 @@ class Space(DomainObject):
-------
Space
A copy of this instance.
"""
return
self
.
__class__
()
def
get_distance_array
(
self
,
distribution_strategy
):
...
...
@@ -165,6 +158,7 @@ class Space(DomainObject):
def
hermitianize_inverter
(
self
,
x
,
axes
):
""" Inverts/flips x in the context of Hermitian decomposition.
This method is only implemented for harmonic spaces.
This method is mainly used for power-synthesizing and -analyzing
Fields.
...
...
test/common.py
View file @
51c6d01a
...
...
@@ -47,7 +47,8 @@ def generate_harmonic_spaces():
spaces
=
[
RGSpace
(
4
,
harmonic
=
True
),
LMSpace
(
5
)]
return
spaces
def
marco_binbounds
(
space
,
logarithmic
,
nbin
=
None
):
def
marco_binbounds
(
space
,
logarithmic
,
nbin
=
None
):
"""Only for testing purposes. DO NOT USE IN REAL LIFE!"""
if
logarithmic
is
None
and
nbin
is
None
:
return
None
...
...
@@ -55,8 +56,8 @@ def marco_binbounds (space, logarithmic, nbin=None):
raise
ValueError
(
"space must be a harmonic space."
)
logarithmic
=
bool
(
logarithmic
)
if
nbin
is
not
None
:
nbin
=
int
(
nbin
)
assert
nbin
>=
3
,
"nbin must be at least 3"
nbin
=
int
(
nbin
)
assert
nbin
>=
3
,
"nbin must be at least 3"
# equidistant binning (linear or log)
# MR FIXME: this needs to improve
kindex
=
space
.
get_unique_distances
()
...
...
test/test_operators/test_laplace_operator.py
View file @
51c6d01a
...
...
@@ -28,7 +28,7 @@ class LaplaceOperatorTests(unittest.TestCase):
@
expand
(
product
([
None
,
False
,
True
],
[
False
,
True
],
[
10
,
100
,
1000
]))
def
test_Laplace
(
self
,
log1
,
log2
,
sz
):
s
=
ift
.
RGSpace
(
sz
,
harmonic
=
True
)
p
=
ift
.
PowerSpace
(
s
,
binbounds
=
marco_binbounds
(
s
,
logarithmic
=
log1
))
p
=
ift
.
PowerSpace
(
s
,
binbounds
=
marco_binbounds
(
s
,
logarithmic
=
log1
))
L
=
ift
.
LaplaceOperator
(
p
,
logarithmic
=
log2
)
arr
=
np
.
random
.
random
(
p
.
shape
[
0
])
fp
=
ift
.
Field
(
p
,
val
=
arr
)
...
...
test/test_spaces/test_power_space.py
View file @
51c6d01a
...
...
@@ -41,8 +41,8 @@ HARMONIC_SPACES = [RGSpace((8,), harmonic=True),
LMSpace
(
9
)]
#Try all sensible kinds of combinations of spaces, distribution strategy and
#binning parameters
#
Try all sensible kinds of combinations of spaces, distribution strategy and
#
binning parameters
CONSISTENCY_CONFIGS_IMPLICIT
=
product
(
HARMONIC_SPACES
,
[
"not"
,
"equal"
,
"fftw"
],
[
None
],
[
None
,
3
,
4
],
[
True
,
False
])
...
...
@@ -123,18 +123,20 @@ class PowerSpaceInterfaceTest(unittest.TestCase):
class
PowerSpaceConsistencyCheck
(
unittest
.
TestCase
):
@
expand
(
CONSISTENCY_CONFIGS
)
def
test_rhopindexConsistency
(
self
,
harmonic_partner
,
distribution_strategy
,
def
test_rhopindexConsistency
(
self
,
harmonic_partner
,
distribution_strategy
,
binbounds
,
nbin
,
logarithmic
):
if
distribution_strategy
==
"fftw"
:
if
not
hasattr
(
gdi
.
get
(
'fftw'
),
'FFTW_MPI'
):
raise
SkipTest
p
=
PowerSpace
(
harmonic_partner
=
harmonic_partner
,
distribution_strategy
=
distribution_strategy
,
binbounds
=
marco_binbounds
(
harmonic_partner
,
logarithmic
,
nbin
))
distribution_strategy
=
distribution_strategy
,
binbounds
=
marco_binbounds
(
harmonic_partner
,
logarithmic
,
nbin
))
assert_equal
(
p
.
pindex
.
flatten
().
bincount
(),
p
.
rho
,
err_msg
=
'rho is not equal to pindex degeneracy'
)
err_msg
=
'rho is not equal to pindex degeneracy'
)
class
PowerSpaceFunctionalityTest
(
unittest
.
TestCase
):
@
expand
(
CONSTRUCTOR_CONFIGS
)
...
...
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