Commit 2511a1d0 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

adjust demos

parent 316da9a2
# -*- coding: utf-8 -*-
import numpy as np
import nifty as ift
from nifty import plotting
import nifty2go as ift
from nifty2go import plotting
if __name__ == "__main__":
signal_to_noise = 1.5 # The signal to noise ratio
......@@ -22,7 +22,7 @@ if __name__ == "__main__":
N_pixels_1 = 512 # Grid resolution (pixels per axis)
signal_space_1 = ift.RGSpace([N_pixels_1], distances=L_1/N_pixels_1)
harmonic_space_1 = ift.FFTOperator.get_default_codomain(signal_space_1)
harmonic_space_1 = signal_space_1.get_default_codomain()
fft_1 = ift.FFTOperator(harmonic_space_1, target=signal_space_1)
power_space_1 = ift.PowerSpace(harmonic_space_1)
......@@ -45,7 +45,7 @@ if __name__ == "__main__":
N_pixels_2 = 512 # Grid resolution (pixels per axis)
signal_space_2 = ift.RGSpace([N_pixels_2], distances=L_2/N_pixels_2)
harmonic_space_2 = ift.FFTOperator.get_default_codomain(signal_space_2)
harmonic_space_2 = signal_space_2.get_default_codomain()
fft_2 = ift.FFTOperator(harmonic_space_2, target=signal_space_2)
power_space_2 = ift.PowerSpace(harmonic_space_2)
......
# -*- coding: utf-8 -*-
import nifty as ift
from nifty import plotting
import nifty2go as ift
from nifty2go import plotting
import numpy as np
......@@ -20,7 +20,7 @@ if __name__ == "__main__":
L = 2. # Total side-length of the domain
N_pixels = 512 # Grid resolution (pixels per axis)
signal_space = ift.RGSpace([N_pixels, N_pixels], distances=L/N_pixels)
harmonic_space = ift.FFTOperator.get_default_codomain(signal_space)
harmonic_space = signal_space.get_default_codomain()
fft = ift.FFTOperator(harmonic_space, target=signal_space)
power_space = ift.PowerSpace(harmonic_space)
......
# -*- coding: utf-8 -*-
from __future__ import print_function
from nifty import Field, RGSpace, DiagonalProberMixin, TraceProberMixin,\
Prober, DiagonalOperator
import nifty2go as ift
import numpy as np
np.random.seed(42)
class DiagonalProber(DiagonalProberMixin, Prober):
class DiagonalProber(ift.DiagonalProberMixin, ift.Prober):
pass
class MultiProber(DiagonalProberMixin, TraceProberMixin, Prober):
class MultiProber(ift.DiagonalProberMixin, ift.TraceProberMixin, ift.Prober):
pass
x = RGSpace((8, 8))
x = ift.RGSpace((8, 8))
f = Field.from_random(domain=x, random_type='normal')
diagOp = DiagonalOperator(domain=x, diagonal=f)
f = ift.Field.from_random(domain=x, random_type='normal')
diagOp = ift.DiagonalOperator(domain=x, diagonal=f)
diagProber = DiagonalProber(domain=x)
diagProber(diagOp)
......
import numpy as np
from nifty import RGSpace, PowerSpace, Field, FFTOperator, ComposedOperator,\
DiagonalOperator, ResponseOperator, plotting,\
create_power_operator
from nifty.library import WienerFilterCurvature
import nifty as ift
import nifty2go as ift
if __name__ == "__main__":
np.random.seed(43)
# Setting up variable parameters
......@@ -33,28 +29,27 @@ if __name__ == "__main__":
# Grid resolution (pixels per axis)
N_pixels = 512
signal_space = RGSpace([N_pixels, N_pixels], distances=L/N_pixels)
harmonic_space = FFTOperator.get_default_codomain(signal_space)
fft = FFTOperator(harmonic_space, target=signal_space)
power_space = PowerSpace(harmonic_space)
signal_space = ift.RGSpace([N_pixels, N_pixels], distances=L/N_pixels)
harmonic_space = signal_space.get_default_codomain()
fft = ift.FFTOperator(harmonic_space, target=signal_space)
power_space = ift.PowerSpace(harmonic_space)
# Creating the mock data
S = create_power_operator(harmonic_space, power_spectrum=power_spectrum)
S = ift.create_power_operator(harmonic_space, power_spectrum=power_spectrum)
mock_power = Field(power_space, val=power_spectrum(power_space.kindex))
np.random.seed(43)
mock_power = ift.Field(power_space, val=power_spectrum(power_space.kindex))
mock_harmonic = mock_power.power_synthesize(real_signal=True)
mock_harmonic = mock_harmonic.real
mock_signal = fft(mock_harmonic)
R = ResponseOperator(signal_space, sigma=(response_sigma,))
R = ift.ResponseOperator(signal_space, sigma=(response_sigma,))
data_domain = R.target[0]
R_harmonic = ComposedOperator([fft, R], default_spaces=[0, 0])
R_harmonic = ift.ComposedOperator([fft, R], default_spaces=[0, 0])
N = DiagonalOperator(data_domain,
N = ift.DiagonalOperator(data_domain,
diagonal=mock_signal.var()/signal_to_noise,
bare=True)
noise = Field.from_random(domain=data_domain,
noise = ift.Field.from_random(domain=data_domain,
random_type='normal',
std=mock_signal.std()/np.sqrt(signal_to_noise),
mean=0)
......@@ -65,16 +60,16 @@ if __name__ == "__main__":
j = R_harmonic.adjoint_times(N.inverse_times(data))
ctrl = ift.DefaultIterationController(verbose=True,tol_abs_gradnorm=1e-2)
inverter = ift.ConjugateGradient(controller=ctrl)
wiener_curvature = WienerFilterCurvature(S=S, N=N, R=R_harmonic, inverter=inverter)
wiener_curvature = ift.library.WienerFilterCurvature(S=S, N=N, R=R_harmonic, inverter=inverter)
m = wiener_curvature.inverse_times(j)
m_s = fft(m)
plotter = plotting.RG2DPlotter()
plotter = ift.plotting.RG2DPlotter()
plotter.path = 'mock_signal.html'
plotter(mock_signal.real)
plotter.path = 'data.html'
plotter(Field(
plotter(ift.Field(
signal_space,
val=data.val.real.reshape(signal_space.shape)))
plotter.path = 'map.html'
......
import nifty as ift
import nifty2go as ift
import numpy as np
np.random.seed(42)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment