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
643d308b
Commit
643d308b
authored
Sep 24, 2017
by
Martin Reinecke
Browse files
more dobj; kindex->k_lengths
parent
0674df96
Changes
14
Show whitespace changes
Inline
Side-by-side
demos/critical_filtering.py
View file @
643d308b
...
...
@@ -5,7 +5,7 @@ np.random.seed(42)
#np.seterr(all="raise",under="ignore")
def
plot_parameters
(
m
,
t
,
p
,
p_d
):
x
=
np
.
log
(
t
.
domain
[
0
].
k
index
)
x
=
np
.
log
(
t
.
domain
[
0
].
k
_lengths
)
m
=
fft
.
adjoint_times
(
m
)
t
=
t
.
val
.
real
p
=
p
.
val
.
real
...
...
@@ -59,7 +59,7 @@ if __name__ == "__main__":
S
=
ift
.
create_power_operator
(
h_space
,
power_spectrum
=
p_spec
)
# Draw a sample sh from the prior distribution in harmonic space
sp
=
ift
.
Field
(
p_space
,
val
=
p_spec
(
p_space
.
k
index
))
sp
=
ift
.
Field
(
p_space
,
val
=
p_spec
(
p_space
.
k
_lengths
))
sh
=
sp
.
power_synthesize
(
real_signal
=
True
)
# Choose the measurement instrument
...
...
@@ -101,7 +101,7 @@ if __name__ == "__main__":
def
ps0
(
k
):
return
(
1.
/
(
1.
+
k
)
**
2
)
t0
=
ift
.
Field
(
p_space
,
val
=
np
.
log
(
1.
/
(
1
+
p_space
.
k
index
)
**
2
))
t0
=
ift
.
Field
(
p_space
,
val
=
np
.
log
(
1.
/
(
1
+
p_space
.
k
)
_lengths
)
**
2
))
for
i
in
range
(
500
):
S0
=
ift
.
create_power_operator
(
h_space
,
power_spectrum
=
ps0
)
...
...
demos/log_normal_wiener_filter.py
View file @
643d308b
...
...
@@ -26,7 +26,7 @@ if __name__ == "__main__":
# Creating the mock signal |\label{code:wf_mock_signal}|
S
=
ift
.
create_power_operator
(
harmonic_space
,
power_spectrum
=
power_spectrum
)
mock_power
=
ift
.
Field
(
power_space
,
val
=
power_spectrum
(
power_space
.
k
index
))
mock_power
=
ift
.
Field
(
power_space
,
val
=
power_spectrum
(
power_space
.
k
_lengths
))
mock_signal
=
fft
(
mock_power
.
power_synthesize
(
real_signal
=
True
))
# Setting up an exemplary response
...
...
demos/paper_demos/cartesian_wiener_filter.py
View file @
643d308b
...
...
@@ -25,7 +25,7 @@ if __name__ == "__main__":
fft_1
=
ift
.
FFTOperator
(
harmonic_space_1
,
target
=
signal_space_1
)
power_space_1
=
ift
.
PowerSpace
(
harmonic_space_1
)
mock_power_1
=
ift
.
Field
(
power_space_1
,
val
=
power_spectrum_1
(
power_space_1
.
k
index
))
mock_power_1
=
ift
.
Field
(
power_space_1
,
val
=
power_spectrum_1
(
power_space_1
.
k
_lengths
))
...
...
@@ -48,7 +48,7 @@ if __name__ == "__main__":
fft_2
=
ift
.
FFTOperator
(
harmonic_space_2
,
target
=
signal_space_2
)
power_space_2
=
ift
.
PowerSpace
(
harmonic_space_2
)
mock_power_2
=
ift
.
Field
(
power_space_2
,
val
=
power_spectrum_2
(
power_space_2
.
k
index
))
mock_power_2
=
ift
.
Field
(
power_space_2
,
val
=
power_spectrum_2
(
power_space_2
.
k
_lengths
))
fft
=
ift
.
ComposedOperator
((
fft_1
,
fft_2
))
...
...
demos/paper_demos/wiener_filter.py
View file @
643d308b
...
...
@@ -25,7 +25,7 @@ if __name__ == "__main__":
# Creating the mock signal |\label{code:wf_mock_signal}|
S
=
ift
.
create_power_operator
(
harmonic_space
,
power_spectrum
=
power_spectrum
)
mock_power
=
ift
.
Field
(
power_space
,
val
=
power_spectrum
(
power_space
.
k
index
))
mock_power
=
ift
.
Field
(
power_space
,
val
=
power_spectrum
(
power_space
.
k
_lengths
))
mock_signal
=
fft
(
mock_power
.
power_synthesize
(
real_signal
=
True
))
# Setting up an exemplary response
...
...
demos/wiener_filter_via_curvature.py
View file @
643d308b
...
...
@@ -38,7 +38,7 @@ if __name__ == "__main__":
S
=
ift
.
create_power_operator
(
harmonic_space
,
power_spectrum
=
power_spectrum
)
np
.
random
.
seed
(
43
)
mock_power
=
ift
.
Field
(
power_space
,
val
=
power_spectrum
(
power_space
.
k
index
))
mock_power
=
ift
.
Field
(
power_space
,
val
=
power_spectrum
(
power_space
.
k
_lengths
))
mock_harmonic
=
mock_power
.
power_synthesize
(
real_signal
=
True
)
mock_harmonic
=
mock_harmonic
.
real
mock_signal
=
fft
(
mock_harmonic
)
...
...
demos/wiener_filter_via_hamiltonian.py
View file @
643d308b
...
...
@@ -50,7 +50,7 @@ if __name__ == "__main__":
S
=
ift
.
create_power_operator
(
h_space
,
power_spectrum
=
p_spec
)
# Drawing a sample sh from the prior distribution in harmonic space
sp
=
ift
.
Field
(
p_space
,
val
=
p_spec
(
p_space
.
k
index
))
sp
=
ift
.
Field
(
p_space
,
val
=
p_spec
(
p_space
.
k
_lengths
))
sh
=
sp
.
power_synthesize
(
real_signal
=
True
)
ss
=
fft
.
adjoint_times
(
sh
)
...
...
nifty/basic_arithmetics.py
View file @
643d308b
...
...
@@ -19,6 +19,7 @@
from
__future__
import
division
import
numpy
as
np
from
.field
import
Field
from
.
import
dobj
__all__
=
[
'cos'
,
'sin'
,
'cosh'
,
'sinh'
,
'tan'
,
'tanh'
,
'arccos'
,
'arcsin'
,
...
...
@@ -39,68 +40,68 @@ def _math_helper(x, function, out):
def
cos
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
cos
,
out
)
return
_math_helper
(
x
,
dobj
.
cos
,
out
)
def
sin
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
sin
,
out
)
return
_math_helper
(
x
,
dobj
.
sin
,
out
)
def
cosh
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
cosh
,
out
)
return
_math_helper
(
x
,
dobj
.
cosh
,
out
)
def
sinh
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
sinh
,
out
)
return
_math_helper
(
x
,
dobj
.
sinh
,
out
)
def
tan
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
tan
,
out
)
return
_math_helper
(
x
,
dobj
.
tan
,
out
)
def
tanh
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
tanh
,
out
)
return
_math_helper
(
x
,
dobj
.
tanh
,
out
)
def
arccos
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
arccos
,
out
)
return
_math_helper
(
x
,
dobj
.
arccos
,
out
)
def
arcsin
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
arcsin
,
out
)
return
_math_helper
(
x
,
dobj
.
arcsin
,
out
)
def
arccosh
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
arccosh
,
out
)
return
_math_helper
(
x
,
dobj
.
arccosh
,
out
)
def
arcsinh
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
arcsinh
,
out
)
return
_math_helper
(
x
,
dobj
.
arcsinh
,
out
)
def
arctan
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
arctan
,
out
)
return
_math_helper
(
x
,
dobj
.
arctan
,
out
)
def
arctanh
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
arctanh
,
out
)
return
_math_helper
(
x
,
dobj
.
arctanh
,
out
)
def
sqrt
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
sqrt
,
out
)
return
_math_helper
(
x
,
dobj
.
sqrt
,
out
)
def
exp
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
exp
,
out
)
return
_math_helper
(
x
,
dobj
.
exp
,
out
)
def
log
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
log
,
out
)
return
_math_helper
(
x
,
dobj
.
log
,
out
)
def
conjugate
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
conjugate
,
out
)
return
_math_helper
(
x
,
dobj
.
conjugate
,
out
)
def
conj
(
x
,
out
=
None
):
return
_math_helper
(
x
,
np
.
conj
,
out
)
return
_math_helper
(
x
,
dobj
.
conj
,
out
)
nifty/data_objects/numpy_do.py
View file @
643d308b
...
...
@@ -2,7 +2,7 @@
import
numpy
as
np
from
numpy
import
ndarray
as
data_object
from
numpy
import
full
,
empty
,
sqrt
,
ones
,
zeros
,
vdot
,
abs
from
numpy
import
full
,
empty
,
sqrt
,
ones
,
zeros
,
vdot
,
abs
,
bincount
def
from_object
(
object
,
dtype
=
None
,
copy
=
True
):
return
np
.
array
(
object
,
dtype
=
dtype
,
copy
=
copy
)
nifty/operators/laplace_operator/laplace_operator.py
View file @
643d308b
...
...
@@ -50,7 +50,7 @@ class LaplaceOperator(EndomorphicOperator):
self
.
_logarithmic
=
bool
(
logarithmic
)
pos
=
self
.
domain
[
0
].
k
index
.
copy
()
pos
=
self
.
domain
[
0
].
k
_lengths
.
copy
()
if
self
.
logarithmic
:
pos
[
1
:]
=
np
.
log
(
pos
[
1
:])
pos
[
0
]
=
pos
[
1
]
-
1.
...
...
nifty/plotting/plot.py
View file @
643d308b
...
...
@@ -197,7 +197,7 @@ def plot(f, **kwargs):
_makeplot
(
kwargs
.
get
(
"name"
))
return
elif
isinstance
(
dom
,
PowerSpace
):
xcoord
=
dom
.
k
index
xcoord
=
dom
.
k
_lengths
ycoord
=
f
.
val
plt
.
xscale
(
'log'
)
plt
.
yscale
(
'log'
)
...
...
nifty/spaces/power_space/power_space.py
View file @
643d308b
...
...
@@ -20,6 +20,7 @@ import numpy as np
from
...spaces.space
import
Space
from
functools
import
reduce
from
...
import
dobj
class
PowerSpace
(
Space
):
...
...
@@ -45,10 +46,10 @@ class PowerSpace(Space):
Attributes
----------
pindex :
numpy.ndarray
pindex :
data object
This holds the information which pixel of the harmonic partner gets
mapped to which power bin
k
index
: numpy.ndarray
k
_lengths
: numpy.ndarray
Sorted array of all k-modes.
rho : numpy.ndarray
The amount of k-modes that get mapped to one power bin is given by
...
...
@@ -161,17 +162,17 @@ class PowerSpace(Space):
harmonic_partner
=
self
.
harmonic_partner
,
k_length_array
=
k_length_array
,
binbounds
=
binbounds
)
temp_rho
=
np
.
bincount
(
temp_pindex
.
ravel
())
temp_rho
=
dobj
.
bincount
(
temp_pindex
.
ravel
())
assert
not
np
.
any
(
temp_rho
==
0
),
"empty bins detected"
temp_k
index
=
np
.
bincount
(
temp_pindex
.
ravel
(),
temp_k
_lengths
=
np
.
bincount
(
temp_pindex
.
ravel
(),
weights
=
k_length_array
.
ravel
())
\
/
temp_rho
self
.
_powerIndexCache
[
key
]
=
(
binbounds
,
temp_pindex
,
temp_k
index
,
temp_k
_lengths
,
temp_rho
)
(
self
.
_binbounds
,
self
.
_pindex
,
self
.
_k
index
,
self
.
_rho
)
=
\
(
self
.
_binbounds
,
self
.
_pindex
,
self
.
_k
_lengths
,
self
.
_rho
)
=
\
self
.
_powerIndexCache
[
key
]
@
staticmethod
...
...
@@ -193,7 +194,7 @@ class PowerSpace(Space):
@
property
def
shape
(
self
):
return
self
.
k
index
.
shape
return
self
.
k
_lengths
.
shape
@
property
def
dim
(
self
):
...
...
@@ -216,7 +217,7 @@ class PowerSpace(Space):
return
np
.
asarray
(
self
.
rho
,
dtype
=
np
.
float64
)
def
get_k_length_array
(
self
):
return
self
.
k
index
.
copy
()
return
self
.
k
_lengths
.
copy
()
def
get_fft_smoothing_kernel_function
(
self
,
sigma
):
raise
NotImplementedError
(
...
...
@@ -236,16 +237,16 @@ class PowerSpace(Space):
@
property
def
pindex
(
self
):
""" A
numpy.ndarray
having the shape of the harmonic partner
""" A
data object
having the shape of the harmonic partner
space containing the indices of the power bin a pixel belongs to.
"""
return
self
.
_pindex
@
property
def
k
index
(
self
):
def
k
_lengths
(
self
):
""" Sorted array of all k-modes.
"""
return
self
.
_k
index
return
self
.
_k
_lengths
@
property
def
rho
(
self
):
...
...
nifty/sugar.py
View file @
643d308b
...
...
@@ -58,7 +58,7 @@ def create_power_operator(domain, power_spectrum, dtype=None):
raise
TypeError
(
"power_spectrum must be callable"
)
power_domain
=
PowerSpace
(
domain
)
fp
=
Field
(
power_domain
,
val
=
power_spectrum
(
power_domain
.
k
index
),
fp
=
Field
(
power_domain
,
val
=
power_spectrum
(
power_domain
.
k
_lengths
),
dtype
=
dtype
)
f
=
fp
.
power_synthesize_special
()
...
...
test/test_field.py
View file @
643d308b
...
...
@@ -63,11 +63,11 @@ class Test_Functionality(unittest.TestCase):
p1
=
PowerSpace
(
space1
)
spec1
=
lambda
k
:
42
/
(
1
+
k
)
**
2
fp1
=
Field
(
p1
,
val
=
spec1
(
p1
.
k
index
))
fp1
=
Field
(
p1
,
val
=
spec1
(
p1
.
k
_lengths
))
p2
=
PowerSpace
(
space2
)
spec2
=
lambda
k
:
42
/
(
1
+
k
)
**
3
fp2
=
Field
(
p2
,
val
=
spec2
(
p2
.
k
index
))
fp2
=
Field
(
p2
,
val
=
spec2
(
p2
.
k
_lengths
))
outer
=
np
.
outer
(
fp1
.
val
,
fp2
.
val
)
fp
=
Field
((
p1
,
p2
),
val
=
outer
)
...
...
test/test_spaces/test_power_space.py
View file @
643d308b
...
...
@@ -56,7 +56,7 @@ CONSTRUCTOR_CONFIGS = [
'harmonic_partner'
:
RGSpace
((
8
,),
harmonic
=
True
),
'binbounds'
:
None
,
'pindex'
:
np
.
array
([
0
,
1
,
2
,
3
,
4
,
3
,
2
,
1
]),
'k
index
'
:
np
.
array
([
0.
,
1.
,
2.
,
3.
,
4.
]),
'k
_lengths
'
:
np
.
array
([
0.
,
1.
,
2.
,
3.
,
4.
]),
'rho'
:
np
.
array
([
1
,
2
,
2
,
2
,
1
]),
}],
[
RGSpace
((
8
,),
harmonic
=
True
),
True
,
None
,
None
,
{
...
...
@@ -67,7 +67,7 @@ CONSTRUCTOR_CONFIGS = [
'harmonic_partner'
:
RGSpace
((
8
,),
harmonic
=
True
),
'binbounds'
:
(
0.5
,
1.3228756555322954
,
3.5
),
'pindex'
:
np
.
array
([
0
,
1
,
2
,
2
,
3
,
2
,
2
,
1
]),
'k
index
'
:
np
.
array
([
0.
,
1.
,
2.5
,
4.
]),
'k
_lengths
'
:
np
.
array
([
0.
,
1.
,
2.5
,
4.
]),
'rho'
:
np
.
array
([
1
,
2
,
4
,
1
]),
}],
]
...
...
@@ -85,7 +85,7 @@ class PowerSpaceInterfaceTest(unittest.TestCase):
[
'harmonic_partner'
,
Space
],
[
'binbounds'
,
type
(
None
)],
[
'pindex'
,
np
.
ndarray
],
[
'k
index
'
,
np
.
ndarray
],
[
'k
_lengths
'
,
np
.
ndarray
],
[
'rho'
,
np
.
ndarray
],
])
def
test_property_ret_type
(
self
,
attribute
,
expected_type
):
...
...
Write
Preview
Markdown
is supported
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