Skip to content
GitLab
Menu
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
281f5127
Commit
281f5127
authored
Sep 16, 2017
by
Martin Reinecke
Browse files
get_distance_array() -> get_k_length_array(); get_unique_distances() -> get_unique_k_lengths()
parent
f1a42ebc
Pipeline
#18301
passed with stage
in 6 minutes and 4 seconds
Changes
10
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
nifty2go/operators/smoothing_operator/direct_smoothing_operator.py
View file @
281f5127
...
...
@@ -99,7 +99,7 @@ class DirectSmoothingOperator(EndomorphicOperator):
"spaces can be smoothed directly."
)
axis
=
affected_axes
[
0
]
distances
=
x
.
domain
[
spaces
[
0
]].
get_
distance
_array
()
distances
=
x
.
domain
[
spaces
[
0
]].
get_
k_length
_array
()
if
self
.
_log_distances
:
distances
=
np
.
log
(
np
.
maximum
(
distances
,
1e-15
))
...
...
nifty2go/operators/smoothing_operator/fft_smoothing_operator.py
View file @
281f5127
...
...
@@ -24,7 +24,7 @@ class FFTSmoothingOperator(EndomorphicOperator):
self
.
_transformator
=
FFTOperator
(
self
.
_domain
)
codomain
=
self
.
_domain
[
0
].
get_default_codomain
()
self
.
_kernel
=
codomain
.
get_
distance
_array
()
self
.
_kernel
=
codomain
.
get_
k_length
_array
()
smoother
=
codomain
.
get_fft_smoothing_kernel_function
(
self
.
_sigma
)
self
.
_kernel
=
smoother
(
self
.
_kernel
)
...
...
nifty2go/spaces/lm_space/lm_space.py
View file @
281f5127
...
...
@@ -122,7 +122,7 @@ class LMSpace(Space):
def
weight
(
self
):
return
1.
def
get_
distance
_array
(
self
):
def
get_
k_length
_array
(
self
):
lmax
=
self
.
lmax
ldist
=
np
.
empty
((
self
.
dim
,),
dtype
=
np
.
float64
)
ldist
[
0
:
lmax
+
1
]
=
np
.
arange
(
lmax
+
1
,
dtype
=
np
.
float64
)
...
...
@@ -135,7 +135,7 @@ class LMSpace(Space):
idx
+=
2
*
(
lmax
+
1
-
l
)
return
ldist
def
get_unique_
distance
s
(
self
):
def
get_unique_
k_length
s
(
self
):
return
np
.
arange
(
self
.
lmax
+
1
,
dtype
=
np
.
float64
)
def
get_fft_smoothing_kernel_function
(
self
,
sigma
):
...
...
nifty2go/spaces/power_space/power_space.py
View file @
281f5127
...
...
@@ -121,7 +121,7 @@ class PowerSpace(Space):
return
None
nbin
=
None
if
nbin
is
None
else
int
(
nbin
)
logarithmic
=
bool
(
logarithmic
)
dists
=
space
.
get_unique_
distance
s
()
dists
=
space
.
get_unique_
k_length
s
()
if
len
(
dists
)
<
3
:
raise
ValueError
(
"Space does not have enough unique k lengths"
)
lbound
=
0.5
*
(
dists
[
0
]
+
dists
[
1
])
...
...
@@ -156,15 +156,15 @@ class PowerSpace(Space):
key
=
(
harmonic_partner
,
binbounds
)
if
self
.
_powerIndexCache
.
get
(
key
)
is
None
:
distance
_array
=
self
.
harmonic_partner
.
get_
distance
_array
()
k_length
_array
=
self
.
harmonic_partner
.
get_
k_length
_array
()
temp_pindex
=
self
.
_compute_pindex
(
harmonic_partner
=
self
.
harmonic_partner
,
distance_array
=
distance
_array
,
k_length_array
=
k_length
_array
,
binbounds
=
binbounds
)
temp_rho
=
np
.
bincount
(
temp_pindex
.
ravel
())
assert
not
np
.
any
(
temp_rho
==
0
),
"empty bins detected"
temp_kindex
=
np
.
bincount
(
temp_pindex
.
ravel
(),
weights
=
distance
_array
.
ravel
())
\
weights
=
k_length
_array
.
ravel
())
\
/
temp_rho
self
.
_powerIndexCache
[
key
]
=
(
binbounds
,
temp_pindex
,
...
...
@@ -175,11 +175,11 @@ class PowerSpace(Space):
self
.
_powerIndexCache
[
key
]
@
staticmethod
def
_compute_pindex
(
harmonic_partner
,
distance
_array
,
binbounds
):
def
_compute_pindex
(
harmonic_partner
,
k_length
_array
,
binbounds
):
if
binbounds
is
None
:
tmp
=
harmonic_partner
.
get_unique_
distance
s
()
tmp
=
harmonic_partner
.
get_unique_
k_length
s
()
binbounds
=
0.5
*
(
tmp
[:
-
1
]
+
tmp
[
1
:])
return
np
.
searchsorted
(
binbounds
,
distance
_array
)
return
np
.
searchsorted
(
binbounds
,
k_length
_array
)
# ---Mandatory properties and methods---
...
...
@@ -215,7 +215,7 @@ class PowerSpace(Space):
# MR FIXME: this will probably change to 1 soon
return
np
.
asarray
(
self
.
rho
,
dtype
=
np
.
float64
)
def
get_
distance
_array
(
self
):
def
get_
k_length
_array
(
self
):
return
self
.
kindex
.
copy
()
def
get_fft_smoothing_kernel_function
(
self
,
sigma
):
...
...
nifty2go/spaces/rg_space/rg_space.py
View file @
281f5127
...
...
@@ -120,17 +120,7 @@ class RGSpace(Space):
def
weight
(
self
):
return
self
.
_wgt
def
get_distance_array
(
self
):
""" Calculates an n-dimensional array with its entries being the
lengths of the vectors from the zero point of the grid.
Returns
-------
numpy.ndarray
An array containing the distances.
"""
def
get_k_length_array
(
self
):
if
(
not
self
.
harmonic
):
raise
NotImplementedError
res
=
np
.
arange
(
self
.
shape
[
0
],
dtype
=
np
.
float64
)
...
...
@@ -145,7 +135,7 @@ class RGSpace(Space):
res
=
np
.
add
.
outer
(
res
,
tmp
)
return
np
.
sqrt
(
res
)
def
get_unique_
distance
s
(
self
):
def
get_unique_
k_length
s
(
self
):
if
(
not
self
.
harmonic
):
raise
NotImplementedError
dimensions
=
len
(
self
.
shape
)
...
...
@@ -165,7 +155,7 @@ class RGSpace(Space):
tmp
[
t2
]
=
True
return
np
.
sqrt
(
np
.
nonzero
(
tmp
)[
0
])
*
self
.
distances
[
0
]
else
:
# do it the hard way
tmp
=
self
.
get_
distance
_array
().
unique
()
# expensive!
tmp
=
self
.
get_
k_length
_array
().
unique
()
# expensive!
tol
=
1e-12
*
tmp
[
-
1
]
# remove all points that are closer than tol to their right
# neighbors.
...
...
nifty2go/spaces/space/space.py
View file @
281f5127
...
...
@@ -88,7 +88,7 @@ class Space(DomainObject):
"""
return
self
.
__class__
()
def
get_
distance
_array
(
self
):
def
get_
k_length
_array
(
self
):
""" The length of the k vector for every pixel.
This method is only implemented for harmonic spaces.
...
...
@@ -100,7 +100,7 @@ class Space(DomainObject):
"""
raise
NotImplementedError
def
get_unique_
distance
s
(
self
):
def
get_unique_
k_length
s
(
self
):
""" Returns an array of floats containing the unique k vector lengths
for this space.
This method is only implemented for harmonic spaces.
...
...
test/test_spaces/test_interface.py
View file @
281f5127
...
...
@@ -38,7 +38,7 @@ class SpaceInterfaceTests(unittest.TestCase):
attr_expected_type
[
1
]))
@
expand
(
product
(
generate_harmonic_spaces
(),
[
[
'get_
distance
_array'
,
np
.
ndarray
],
[
'get_
k_length
_array'
,
np
.
ndarray
],
[
'get_fft_smoothing_kernel_function'
,
2.0
,
LambdaType
],
]))
def
test_method_ret_type
(
self
,
space
,
method_expected_type
):
...
...
test/test_spaces/test_lm_space.py
View file @
281f5127
...
...
@@ -49,7 +49,7 @@ CONSTRUCTOR_CONFIGS = [
]
def
_
distance
_array_helper
(
index_arr
,
lmax
):
def
_
k_length
_array_helper
(
index_arr
,
lmax
):
if
index_arr
<=
lmax
:
index_half
=
index_arr
else
:
...
...
@@ -64,8 +64,8 @@ def _distance_array_helper(index_arr, lmax):
return
index_half
-
m
*
(
2
*
lmax
+
1
-
m
)
//
2
def
get_
distance
_array_configs
():
da_0
=
[
_
distance
_array_helper
(
idx
,
5
)
for
idx
in
np
.
arange
(
36
)]
def
get_
k_length
_array_configs
():
da_0
=
[
_
k_length
_array_helper
(
idx
,
5
)
for
idx
in
np
.
arange
(
36
)]
return
[[
5
,
da_0
]]
...
...
@@ -92,7 +92,7 @@ class LMSpaceFunctionalityTests(unittest.TestCase):
def
test_weight
(
self
):
assert_almost_equal
(
LMSpace
(
5
).
weight
(),
1.
)
@
expand
(
get_
distance
_array_configs
())
def
test_
distance
_array
(
self
,
lmax
,
expected
):
@
expand
(
get_
k_length
_array_configs
())
def
test_
k_length
_array
(
self
,
lmax
,
expected
):
l
=
LMSpace
(
lmax
)
assert_almost_equal
(
l
.
get_
distance
_array
(),
expected
)
assert_almost_equal
(
l
.
get_
k_length
_array
(),
expected
)
test/test_spaces/test_power_space.py
View file @
281f5127
...
...
@@ -73,7 +73,7 @@ CONSTRUCTOR_CONFIGS = [
]
def
get_
distance
_array_configs
():
def
get_
k_length
_array_configs
():
da_0
=
np
.
array
([
0
,
1.0
,
1.41421356
,
2.
,
2.23606798
,
2.82842712
])
return
[
[
RGSpace
((
4
,
4
),
harmonic
=
True
),
da_0
],
...
...
@@ -124,10 +124,10 @@ class PowerSpaceFunctionalityTest(unittest.TestCase):
else
:
assert_equal
(
getattr
(
p
,
key
),
value
)
@
expand
(
get_
distance
_array_configs
())
def
test_
distance
_array
(
self
,
harmonic_partner
,
expected
):
@
expand
(
get_
k_length
_array_configs
())
def
test_
k_length
_array
(
self
,
harmonic_partner
,
expected
):
p
=
PowerSpace
(
harmonic_partner
=
harmonic_partner
)
assert_almost_equal
(
p
.
get_
distance
_array
(),
expected
)
assert_almost_equal
(
p
.
get_
k_length
_array
(),
expected
)
def
test_weight
(
self
):
p
=
PowerSpace
(
harmonic_partner
=
RGSpace
(
10
,
harmonic
=
True
))
...
...
test/test_spaces/test_rg_space.py
View file @
281f5127
...
...
@@ -74,7 +74,7 @@ CONSTRUCTOR_CONFIGS = [
]
def
get_
distance
_array_configs
():
def
get_
k_length
_array_configs
():
# for RGSpace(shape=(4, 4), distances=(0.25,0.25))
cords_0
=
np
.
ogrid
[
0
:
4
,
0
:
4
]
da_0
=
((
cords_0
[
0
]
-
4
//
2
)
*
0.25
)
**
2
...
...
@@ -117,10 +117,10 @@ class RGSpaceFunctionalityTests(unittest.TestCase):
for
key
,
value
in
expected
.
items
():
assert_equal
(
getattr
(
x
,
key
),
value
)
@
expand
(
get_
distance
_array_configs
())
def
test_
distance
_array
(
self
,
shape
,
distances
,
expected
):
@
expand
(
get_
k_length
_array_configs
())
def
test_
k_length
_array
(
self
,
shape
,
distances
,
expected
):
r
=
RGSpace
(
shape
=
shape
,
distances
=
distances
,
harmonic
=
True
)
assert_almost_equal
(
r
.
get_
distance
_array
(),
expected
)
assert_almost_equal
(
r
.
get_
k_length
_array
(),
expected
)
@
expand
(
get_weight_configs
())
def
test_weight
(
self
,
shape
,
distances
,
harmonic
,
power
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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