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
starblade
Commits
70b5b7cd
Commit
70b5b7cd
authored
Feb 22, 2018
by
Martin Reinecke
Browse files
first iteration
parent
0c5937f2
Changes
4
Hide whitespace changes
Inline
Side-by-side
1d_separation.py
View file @
70b5b7cd
from
point_separation
import
build_problem
,
problem_iteration
from
nifty2go
import
*
import
nifty4
as
ift
import
numpy
as
np
from
matplotlib
import
rc
rc
(
'font'
,
**
{
'family'
:
'serif'
,
'serif'
:[
'Palatino'
]})
...
...
@@ -8,15 +8,15 @@ from matplotlib import pyplot as plt
np
.
random
.
seed
(
42
)
if
__name__
==
'__main__'
:
s_space
=
RGSpace
([
1024
])
FFT
=
FFTOperator
(
s_space
)
s_space
=
ift
.
RGSpace
([
1024
])
FFT
=
ift
.
FFTOperator
(
s_space
)
h_space
=
FFT
.
target
[
0
]
p_sp
ace
=
PowerSpace
(
h_space
)
sp
=
Field
(
p_space
,
val
=
1.
/
(
1
+
p_space
.
k_lengths
)
**
2.5
)
sh
=
power_synthesize
(
sp
)
p_sp
ec
=
lambda
k
:
(
1.
/
(
1
+
k
)
**
2.5
)
S
=
ift
.
create_power_operator
(
h_space
,
power_spectrum
=
p_spec
)
sh
=
S
.
draw_sample
(
)
s
=
FFT
.
adjoint_times
(
sh
)
u
=
Field
(
s_space
,
val
=
-
12
)
u
=
ift
.
Field
(
s_space
,
val
=
-
12
)
u
.
val
[
200
]
=
1
u
.
val
[
300
]
=
3
u
.
val
[
500
]
=
4
...
...
@@ -27,7 +27,7 @@ if __name__ == '__main__':
u
.
val
[
652
]
=
1
u
.
val
[
1002
]
=
2.5
d
=
exp
(
s
)
+
exp
(
u
)
d
=
ift
.
exp
(
s
)
+
ift
.
exp
(
u
)
data
=
d
.
val
energy1
=
build_problem
(
data
,
1.25
)
...
...
@@ -45,17 +45,17 @@ if __name__ == '__main__':
f
,
(
ax0
,
ax1
,
ax2
)
=
plt
.
subplots
(
3
,
sharex
=
True
,
sharey
=
True
)
plt
.
suptitle
(
'diffuse components'
,
size
=
size
)
ax0
.
plot
(
exp
(
energy1
.
s
).
val
,
'k-'
)
ax0
.
plot
(
ift
.
exp
(
energy1
.
s
).
val
,
'k-'
)
ax0
.
yaxis
.
set_label_position
(
"right"
)
ax0
.
set_ylabel
(
r
'$\alpha = 1.25$'
,
size
=
size
)
ax0
.
set_ylim
(
1e-1
,
1e3
)
ax0
.
set_yscale
(
"log"
)
ax1
.
plot
(
exp
(
energy2
.
s
).
val
,
'k-'
)
ax1
.
plot
(
ift
.
exp
(
energy2
.
s
).
val
,
'k-'
)
ax1
.
yaxis
.
set_label_position
(
"right"
)
ax1
.
set_ylabel
(
r
'$\alpha = 1.5$'
,
size
=
size
)
ax2
.
plot
(
exp
(
energy3
.
s
).
val
,
'k-'
)
ax2
.
plot
(
ift
.
exp
(
energy3
.
s
).
val
,
'k-'
)
ax2
.
yaxis
.
set_label_position
(
"right"
)
ax2
.
set_ylabel
(
r
'$\alpha = 1.75$'
,
size
=
size
)
...
...
@@ -66,17 +66,17 @@ if __name__ == '__main__':
plt
.
suptitle
(
'point-like components'
,
size
=
size
)
ax0
.
plot
(
exp
(
energy1
.
u
).
val
,
'k-'
)
ax0
.
plot
(
ift
.
exp
(
energy1
.
u
).
val
,
'k-'
)
ax0
.
yaxis
.
set_label_position
(
"right"
)
ax0
.
set_ylabel
(
r
'$\alpha = 1.25$'
,
size
=
size
)
ax0
.
set_ylim
(
1e-1
,
1e3
)
ax0
.
set_yscale
(
"log"
)
ax1
.
plot
(
exp
(
energy2
.
u
).
val
,
'k-'
)
ax1
.
plot
(
ift
.
exp
(
energy2
.
u
).
val
,
'k-'
)
ax1
.
yaxis
.
set_label_position
(
"right"
)
ax1
.
set_ylabel
(
r
'$\alpha = 1.5$'
,
size
=
size
)
ax2
.
plot
(
exp
(
energy3
.
u
).
val
,
'k-'
)
ax2
.
plot
(
ift
.
exp
(
energy3
.
u
).
val
,
'k-'
)
ax2
.
yaxis
.
set_label_position
(
"right"
)
ax2
.
set_ylabel
(
r
'$\alpha = 1.75$'
,
size
=
size
)
...
...
@@ -97,10 +97,10 @@ if __name__ == '__main__':
ax0
.
set_ylabel
(
r
'data'
,
size
=
size
)
ax1
.
plot
(
exp
(
s
).
val
,
'k-'
)
ax1
.
plot
(
ift
.
exp
(
s
).
val
,
'k-'
)
ax1
.
yaxis
.
set_label_position
(
"right"
)
ax1
.
set_ylabel
(
r
'diffuse'
,
size
=
size
)
ax2
.
plot
(
exp
(
u
).
val
,
'k-'
)
ax2
.
plot
(
ift
.
exp
(
u
).
val
,
'k-'
)
ax2
.
yaxis
.
set_label_position
(
"right"
)
ax2
.
set_ylabel
(
r
'point-like'
,
size
=
size
)
...
...
hubble_separation.py
View file @
70b5b7cd
from
point_separation
import
build_problem
,
problem_iteration
,
load_data
from
nifty
2go
import
*
from
nifty
4
import
*
import
numpy
as
np
from
matplotlib
import
rc
rc
(
'font'
,
**
{
'family'
:
'serif'
,
'serif'
:[
'Palatino'
]})
...
...
point_separation.py
View file @
70b5b7cd
from
nifty2go
import
*
import
nifty4
as
ift
import
numpy
as
np
# from matplotlib import pyplot as plt
from
astropy.io
import
fits
from
separation_energy
import
SeparationEnergy
from
nifty
2go
.library.nonlinearities
import
PositiveTanh
from
nifty
4
.library.nonlinearities
import
PositiveTanh
def
load_data
(
path
):
...
...
@@ -17,22 +17,21 @@ def load_data(path):
return
data
def
build_problem
(
data
,
alpha
):
s_space
=
RGSpace
(
data
.
shape
,
distances
=
len
(
data
.
shape
)
*
[
1
])
data
=
Field
(
s_space
,
val
=
data
)
FFT
=
FFTOperator
(
s_space
)
s_space
=
ift
.
RGSpace
(
data
.
shape
,
distances
=
len
(
data
.
shape
)
*
[
1
])
data
=
ift
.
Field
(
s_space
,
val
=
data
)
FFT
=
ift
.
FFTOperator
(
s_space
)
h_space
=
FFT
.
target
[
0
]
binbounds
=
PowerSpace
.
useful_binbounds
(
h_space
,
logarithmic
=
False
)
p_space
=
PowerSpace
(
h_space
,
binbounds
=
binbounds
)
initial_spectrum
=
power_analyze
(
FFT
(
log
(
data
)),
binbounds
=
p_space
.
binbounds
)
initial_correlation
=
create_power_operator
(
h_space
,
initial_spectrum
)
initial_x
=
Field
(
s_space
,
val
=-
1.
)
alpha
=
Field
(
s_space
,
val
=
alpha
)
q
=
Field
(
s_space
,
val
=
10e-40
)
binbounds
=
ift
.
PowerSpace
.
useful_binbounds
(
h_space
,
logarithmic
=
False
)
p_space
=
ift
.
PowerSpace
(
h_space
,
binbounds
=
binbounds
)
initial_spectrum
=
ift
.
power_analyze
(
FFT
(
ift
.
log
(
data
)),
binbounds
=
p_space
.
binbounds
)
initial_correlation
=
ift
.
create_power_operator
(
h_space
,
initial_spectrum
)
initial_x
=
ift
.
Field
(
s_space
,
val
=-
1.
)
alpha
=
ift
.
Field
(
s_space
,
val
=
alpha
)
q
=
ift
.
Field
(
s_space
,
val
=
10e-40
)
pos_tanh
=
PositiveTanh
()
ICI
=
GradientNormController
(
verbose
=
False
,
name
=
"ICI"
,
iteration_limit
=
500
,
ICI
=
ift
.
GradientNormController
(
iteration_limit
=
500
,
tol_abs_gradnorm
=
1e-5
)
inverter
=
ConjugateGradient
(
controller
=
ICI
)
inverter
=
ift
.
ConjugateGradient
(
controller
=
ICI
)
parameters
=
dict
(
data
=
data
,
correlation
=
initial_correlation
,
alpha
=
alpha
,
q
=
q
,
...
...
@@ -41,15 +40,15 @@ def build_problem(data, alpha):
return
separationEnergy
def
problem_iteration
(
energy
,
iterations
=
3
):
controller
=
GradientNormController
(
verbose
=
True
,
tol_abs_gradnorm
=
0.00000001
,
iteration_limit
=
iterations
)
minimizer
=
RelaxedNewton
(
controller
=
controller
)
controller
=
ift
.
GradientNormController
(
name
=
"test1"
,
tol_abs_gradnorm
=
0.00000001
,
iteration_limit
=
iterations
)
minimizer
=
ift
.
RelaxedNewton
(
controller
=
controller
)
energy
,
convergence
=
minimizer
(
energy
)
new_position
=
energy
.
position
h_space
=
energy
.
correlation
.
domain
[
0
]
FFT
=
energy
.
FFT
binbounds
=
PowerSpace
.
useful_binbounds
(
h_space
,
logarithmic
=
False
)
new_power
=
power_analyze
(
FFT
(
energy
.
s
),
binbounds
=
binbounds
)
new_correlation
=
create_power_operator
(
h_space
,
new_power
)
binbounds
=
ift
.
PowerSpace
.
useful_binbounds
(
h_space
,
logarithmic
=
False
)
new_power
=
ift
.
power_analyze
(
FFT
(
energy
.
s
),
binbounds
=
binbounds
)
new_correlation
=
ift
.
create_power_operator
(
h_space
,
new_power
)
new_parameters
=
energy
.
parameters
new_parameters
[
'correlation'
]
=
new_correlation
new_energy
=
SeparationEnergy
(
new_position
,
new_parameters
)
...
...
separation_energy.py
View file @
70b5b7cd
from
nifty
2go
import
Energy
,
Field
,
log
,
exp
,
DiagonalOperator
from
nifty
2go
.library
import
WienerFilterCurvature
from
nifty
4
import
Energy
,
Field
,
log
,
exp
,
DiagonalOperator
from
nifty
4
.library
import
WienerFilterCurvature
class
SeparationEnergy
(
Energy
):
...
...
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