From 70b5b7cd77b6028de008e40fe58cf99d2033679c Mon Sep 17 00:00:00 2001
From: Martin Reinecke <martin@mpa-garching.mpg.de>
Date: Thu, 22 Feb 2018 11:48:44 +0100
Subject: [PATCH] first iteration

---
 1d_separation.py     | 32 ++++++++++++++++----------------
 hubble_separation.py |  2 +-
 point_separation.py  | 39 +++++++++++++++++++--------------------
 separation_energy.py |  4 ++--
 4 files changed, 38 insertions(+), 39 deletions(-)

diff --git a/1d_separation.py b/1d_separation.py
index bc73eed..012b542 100644
--- a/1d_separation.py
+++ b/1d_separation.py
@@ -1,5 +1,5 @@
 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_space = PowerSpace(h_space)
-    sp = Field(p_space, val=1./(1+p_space.k_lengths)**2.5 )
-    sh = power_synthesize(sp)
+    p_spec = 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)
 
diff --git a/hubble_separation.py b/hubble_separation.py
index 23eddf9..f4e3272 100644
--- a/hubble_separation.py
+++ b/hubble_separation.py
@@ -1,5 +1,5 @@
 from point_separation import build_problem, problem_iteration, load_data
-from nifty2go import *
+from nifty4 import *
 import numpy as np
 from matplotlib import rc
 rc('font',**{'family':'serif','serif':['Palatino']})
diff --git a/point_separation.py b/point_separation.py
index d68ac84..3b68e99 100644
--- a/point_separation.py
+++ b/point_separation.py
@@ -1,9 +1,9 @@
-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 nifty2go.library.nonlinearities import PositiveTanh
+from nifty4.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)
diff --git a/separation_energy.py b/separation_energy.py
index b280e8c..ca44a76 100644
--- a/separation_energy.py
+++ b/separation_energy.py
@@ -1,5 +1,5 @@
-from nifty2go import Energy, Field, log, exp, DiagonalOperator
-from nifty2go.library import WienerFilterCurvature
+from nifty4 import Energy, Field, log, exp, DiagonalOperator
+from nifty4.library import WienerFilterCurvature
 
 
 class SeparationEnergy(Energy):
-- 
GitLab