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
On Thursday, 7th July from 1 to 3 pm there will be a maintenance with a short downtime of GitLab.
Open sidebar
ift
NIFTy
Commits
dd7d3e4b
Commit
dd7d3e4b
authored
Feb 06, 2018
by
Martin Reinecke
Browse files
tweak demos; simplify Field printing
parent
378af2c5
Pipeline
#24433
passed with stage
in 6 minutes and 35 seconds
Changes
9
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
demos/critical_filtering.py
View file @
dd7d3e4b
...
...
@@ -7,12 +7,12 @@ np.random.seed(42)
if
__name__
==
"__main__"
:
# Set up position space
s_space
=
ift
.
RGSpace
([
128
,
128
])
#
s_space = ift.HPSpace(32)
#
s_space = ift.RGSpace([128, 128])
s_space
=
ift
.
HPSpace
(
32
)
# Define harmonic transformation and associated harmonic space
h_space
=
s_space
.
get_default_codomain
()
fft
=
ift
.
HarmonicTransformOperator
(
h_space
,
s_space
)
HT
=
ift
.
HarmonicTransformOperator
(
h_space
,
s_space
)
# Set up power space
p_space
=
ift
.
PowerSpace
(
h_space
,
...
...
@@ -34,10 +34,10 @@ if __name__ == "__main__":
# Instrument._diagonal.val[64:512-64, 64:512-64] = 0
# Add a harmonic transformation to the instrument
R
=
Instrument
*
fft
R
=
Instrument
*
HT
noise
=
1.
N
=
ift
.
Diagonal
Operator
(
ift
.
Field
.
full
(
s_space
,
noise
).
weight
(
1
)
)
N
=
ift
.
Scaling
Operator
(
noise
,
s_space
)
n
=
ift
.
Field
.
from_random
(
domain
=
s_space
,
random_type
=
'normal'
,
std
=
np
.
sqrt
(
noise
),
mean
=
0
)
...
...
@@ -48,7 +48,7 @@ if __name__ == "__main__":
j
=
R
.
adjoint_times
(
N
.
inverse_times
(
d
))
realized_power
=
ift
.
log
(
ift
.
power_analyze
(
sh
,
binbounds
=
p_space
.
binbounds
))
data_power
=
ift
.
log
(
ift
.
power_analyze
(
fft
.
adjoint_times
(
d
),
data_power
=
ift
.
log
(
ift
.
power_analyze
(
HT
.
adjoint_times
(
d
),
binbounds
=
p_space
.
binbounds
))
d_data
=
d
.
val
ift
.
plot
(
d
,
name
=
"data.png"
)
...
...
@@ -91,4 +91,4 @@ if __name__ == "__main__":
# Plot current estimate
ift
.
dobj
.
mprint
(
i
)
if
i
%
50
==
0
:
ift
.
plot
(
fft
(
m0
),
name
=
'map.png'
)
ift
.
plot
(
HT
(
m0
),
name
=
'map.png'
)
demos/log_normal_wiener_filter.py
View file @
dd7d3e4b
...
...
@@ -20,7 +20,7 @@ if __name__ == "__main__":
# signal_space = ift.RGSpace([N_pixels, N_pixels], distances=L/N_pixels)
signal_space
=
ift
.
HPSpace
(
16
)
harmonic_space
=
signal_space
.
get_default_codomain
()
ht
=
ift
.
HarmonicTransformOperator
(
harmonic_space
,
target
=
signal_space
)
HT
=
ift
.
HarmonicTransformOperator
(
harmonic_space
,
target
=
signal_space
)
power_space
=
ift
.
PowerSpace
(
harmonic_space
)
# Creating the mock signal
...
...
@@ -35,15 +35,14 @@ if __name__ == "__main__":
# mask.val[N10*5:N10*9, N10*5:N10*9] = 0.
R
=
ift
.
GeometryRemover
(
signal_space
)
R
=
R
*
ift
.
DiagonalOperator
(
mask
)
R
=
R
*
ht
R
=
R
*
HT
R
=
R
*
ift
.
create_harmonic_smoothing_operator
((
harmonic_space
,),
0
,
response_sigma
)
data_domain
=
R
.
target
[
0
]
# Setting up the noise covariance and drawing a random noise realization
noiseless_data
=
R
(
mock_signal
)
noise_amplitude
=
noiseless_data
.
val
.
std
()
/
signal_to_noise
N
=
ift
.
DiagonalOperator
(
ift
.
Field
.
full
(
data_domain
,
noise_amplitude
**
2
))
N
=
ift
.
ScalingOperator
(
noise_amplitude
**
2
,
data_domain
)
noise
=
ift
.
Field
.
from_random
(
domain
=
data_domain
,
random_type
=
'normal'
,
std
=
noise_amplitude
,
mean
=
0
)
...
...
@@ -61,11 +60,11 @@ if __name__ == "__main__":
#minimizer = ift.SteepestDescent(controller=ctrl2)
me
=
minimizer
(
energy
)
m
=
ht
(
me
[
0
].
position
)
m
=
HT
(
me
[
0
].
position
)
# Plotting
plotdict
=
{
"colormap"
:
"Planck-like"
}
ift
.
plot
(
ht
(
mock_signal
),
name
=
"mock_signal.png"
,
**
plotdict
)
ift
.
plot
(
HT
(
mock_signal
),
name
=
"mock_signal.png"
,
**
plotdict
)
logdata
=
np
.
log
(
ift
.
dobj
.
to_global_data
(
data
.
val
)).
reshape
(
signal_space
.
shape
)
ift
.
plot
(
ift
.
Field
(
signal_space
,
val
=
ift
.
dobj
.
from_global_data
(
logdata
)),
name
=
"log_of_data.png"
,
**
plotdict
)
...
...
@@ -75,8 +74,8 @@ if __name__ == "__main__":
class
Proby
(
ift
.
DiagonalProberMixin
,
ift
.
Prober
):
pass
proby
=
Proby
(
signal_space
,
probe_count
=
1
)
proby
(
lambda
z
:
ht
(
me2
[
0
].
curvature
.
inverse_times
(
ht
.
adjoint_times
(
z
))))
proby
(
lambda
z
:
HT
(
me2
[
0
].
curvature
.
inverse_times
(
HT
.
adjoint_times
(
z
))))
sm
=
ift
.
FFTSmoothingOperator
(
signal_space
,
sigma
=
0.02
)
variance
=
sm
(
proby
.
diagonal
.
weig
ht
(
-
1
))
variance
=
sm
(
proby
.
diagonal
.
weig
HT
(
-
1
))
ift
.
plot
(
variance
,
name
=
'variance.png'
,
**
plotdict
)
demos/nonlinear_critical_filter.py
View file @
dd7d3e4b
...
...
@@ -66,8 +66,7 @@ if __name__ == "__main__":
true_sky
=
nonlinearity
(
HT
(
power
*
sh
))
noiseless_data
=
MeasurementOperator
(
true_sky
)
noise_amplitude
=
noiseless_data
.
val
.
std
()
*
noise_level
N
=
ift
.
DiagonalOperator
(
ift
.
Field
.
full
(
d_space
,
noise_amplitude
**
2
))
N
=
ift
.
ScalingOperator
(
noise_amplitude
**
2
,
d_space
)
n
=
ift
.
Field
.
from_random
(
domain
=
d_space
,
random_type
=
'normal'
,
std
=
noise_amplitude
,
mean
=
0
)
...
...
demos/paper_demos/cartesian_wiener_filter.py
View file @
dd7d3e4b
...
...
@@ -83,7 +83,6 @@ if __name__ == "__main__":
noiseless_data
=
R
(
mock_signal
)
noise_amplitude
=
noiseless_data
.
val
.
std
()
/
signal_to_noise
# Setting up the noise covariance and drawing a random noise realization
#ndiag = ift.Field.full(data_domain, noise_amplitude**2)
N
=
ift
.
ScalingOperator
(
noise_amplitude
**
2
,
data_domain
)
noise
=
ift
.
Field
.
from_random
(
domain
=
data_domain
,
random_type
=
'normal'
,
...
...
@@ -100,8 +99,7 @@ if __name__ == "__main__":
m_k
=
wiener_curvature
.
inverse_times
(
j
)
m
=
ht
(
m_k
)
plotdict
=
{
"xlabel"
:
"Pixel index"
,
"ylabel"
:
"Pixel index"
,
"colormap"
:
"Planck-like"
}
plotdict
=
{
"colormap"
:
"Planck-like"
}
plot_space
=
ift
.
RGSpace
((
N_pixels_1
,
N_pixels_2
))
ift
.
plot
(
ift
.
Field
(
plot_space
,
val
=
ht
(
mock_signal
).
val
),
name
=
'mock_signal.png'
,
**
plotdict
)
...
...
@@ -110,3 +108,4 @@ if __name__ == "__main__":
# sampling the uncertainty map
mean
,
variance
=
ift
.
probe_with_posterior_samples
(
wiener_curvature
,
m_k
,
ht
,
10
)
ift
.
plot
(
ift
.
Field
(
plot_space
,
val
=
ift
.
sqrt
(
variance
).
val
),
name
=
"uncertainty.png"
,
**
plotdict
)
ift
.
plot
(
ift
.
Field
(
plot_space
,
val
=
mean
.
val
),
name
=
"posterior_mean.png"
,
**
plotdict
)
demos/paper_demos/wiener_filter.py
View file @
dd7d3e4b
...
...
@@ -44,8 +44,7 @@ if __name__ == "__main__":
noiseless_data
=
R
(
mock_signal
)
noise_amplitude
=
noiseless_data
.
val
.
std
()
/
signal_to_noise
# Setting up the noise covariance and drawing a random noise realization
ndiag
=
ift
.
Field
.
full
(
data_domain
,
noise_amplitude
**
2
)
N
=
ift
.
DiagonalOperator
(
ndiag
)
N
=
ift
.
ScalingOperator
(
noise_amplitude
**
2
,
data_domain
)
noise
=
ift
.
Field
.
from_random
(
domain
=
data_domain
,
random_type
=
'normal'
,
std
=
noise_amplitude
,
mean
=
0
)
...
...
@@ -60,20 +59,13 @@ if __name__ == "__main__":
m_k
=
wiener_curvature
.
inverse_times
(
j
)
m
=
ht
(
m_k
)
plotdict
=
{
"xlabel"
:
"Pixel index"
,
"ylabel"
:
"Pixel index"
,
"colormap"
:
"Planck-like"
}
plotdict
=
{
"colormap"
:
"Planck-like"
}
ift
.
plot
(
ht
(
mock_signal
),
name
=
"mock_signal.png"
,
**
plotdict
)
ift
.
plot
(
ift
.
Field
(
signal_space
,
val
=
data
.
val
),
name
=
"data.png"
,
**
plotdict
)
ift
.
plot
(
m
,
name
=
"map.png"
,
**
plotdict
)
# sampling the uncertainty map
sample_variance
=
ift
.
Field
.
zeros
(
signal_space
)
sample_mean
=
ift
.
Field
.
zeros
(
signal_space
)
n_samples
=
10
for
i
in
range
(
n_samples
):
sample
=
ht
(
wiener_curvature
.
draw_sample
())
+
m
sample_variance
+=
sample
**
2
sample_mean
+=
sample
variance
=
sample_variance
/
n_samples
-
(
sample_mean
/
n_samples
)
**
2
mean
,
variance
=
ift
.
probe_with_posterior_samples
(
wiener_curvature
,
m_k
,
ht
,
5
)
ift
.
plot
(
ift
.
sqrt
(
variance
),
name
=
"uncertainty.png"
,
**
plotdict
)
ift
.
plot
(
mean
,
name
=
"posterior_mean.png"
,
**
plotdict
)
demos/wiener_filter_easy.py
View file @
dd7d3e4b
...
...
@@ -43,7 +43,7 @@ if __name__ == "__main__":
noiseless_data
=
R
(
sh
)
signal_to_noise
=
1.
noise_amplitude
=
noiseless_data
.
val
.
std
()
/
signal_to_noise
N
=
ift
.
Diagonal
Operator
(
ift
.
Field
.
full
(
s_space
,
noise_amplitude
**
2
)
)
N
=
ift
.
Scaling
Operator
(
noise_amplitude
**
2
,
s_space
)
n
=
ift
.
Field
.
from_random
(
domain
=
s_space
,
random_type
=
'normal'
,
std
=
noise_amplitude
,
...
...
demos/wiener_filter_via_curvature.py
View file @
dd7d3e4b
...
...
@@ -59,8 +59,7 @@ if __name__ == "__main__":
noiseless_data
=
R
(
mock_signal
)
noise_amplitude
=
noiseless_data
.
val
.
std
()
/
signal_to_noise
N
=
ift
.
DiagonalOperator
(
ift
.
Field
.
full
(
data_domain
,
noise_amplitude
**
2
))
N
=
ift
.
ScalingOperator
(
noise_amplitude
**
2
,
data_domain
)
noise
=
ift
.
Field
.
from_random
(
domain
=
data_domain
,
random_type
=
'normal'
,
std
=
noise_amplitude
,
mean
=
0
)
...
...
demos/wiener_filter_via_hamiltonian.py
View file @
dd7d3e4b
...
...
@@ -42,7 +42,7 @@ if __name__ == "__main__":
noiseless_data
=
R
(
sh
)
signal_to_noise
=
1.
noise_amplitude
=
noiseless_data
.
val
.
std
()
/
signal_to_noise
N
=
ift
.
Diagonal
Operator
(
ift
.
Field
.
full
(
s_space
,
noise_amplitude
**
2
)
)
N
=
ift
.
Scaling
Operator
(
noise_amplitude
**
2
,
s_space
)
n
=
ift
.
Field
.
from_random
(
domain
=
s_space
,
random_type
=
'normal'
,
std
=
noise_amplitude
,
...
...
nifty4/field.py
View file @
dd7d3e4b
...
...
@@ -529,13 +529,9 @@ class Field(object):
return
"<nifty4.Field>"
def
__str__
(
self
):
minmax
=
[
self
.
min
(),
self
.
max
()]
mean
=
self
.
mean
()
return
"nifty4.Field instance
\n
- domain = "
+
\
self
.
_domain
.
__str__
()
+
\
"
\n
- val = "
+
repr
(
self
.
val
)
+
\
"
\n
- min.,max. = "
+
str
(
minmax
)
+
\
"
\n
- mean = "
+
str
(
mean
)
"
\n
- val = "
+
repr
(
self
.
val
)
# Arithmetic functions working on Fields
...
...
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