Commit 51f49206 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

adjustments for new plotter

parent d89a5670
Pipeline #18002 passed with stage
in 4 minutes and 47 seconds
import numpy as np import numpy as np
import nifty2go as ift import nifty2go as ift
import plotly.graph_objs as go
import plotly.offline as pl
np.random.seed(42) np.random.seed(42)
#np.seterr(all="raise",under="ignore") #np.seterr(all="raise",under="ignore")
def plot_parameters(m, t, p, p_d): def plot_parameters(m, t, p, p_d):
x = ift.log(t.domain[0].kindex) x = ift.log(t.domain[0].kindex)
m = fft.adjoint_times(m) m = fft.adjoint_times(m)
m = m.val.real
t = t.val.real t = t.val.real
p = p.val.real p = p.val.real
p_d = p_d.val.real p_d = p_d.val.real
pl.plot([go.Heatmap(z=m)], filename='map.html', auto_open=False) ift.plotting.plot(m.real, name='map.pdf')
pl.plot([go.Scatter(x=x, y=t), go.Scatter(x=x, y=p), #pl.plot([go.Scatter(x=x, y=t), go.Scatter(x=x, y=p),
go.Scatter(x=x, y=p_d)], filename="t.html", auto_open=False) # go.Scatter(x=x, y=p_d)], filename="t.html", auto_open=False)
class AdjointFFTResponse(ift.LinearOperator): class AdjointFFTResponse(ift.LinearOperator):
...@@ -90,7 +86,7 @@ if __name__ == "__main__": ...@@ -90,7 +86,7 @@ if __name__ == "__main__":
realized_power = ift.log(sh.power_analyze(binbounds=p_space.binbounds)) realized_power = ift.log(sh.power_analyze(binbounds=p_space.binbounds))
data_power = ift.log(fft(d).power_analyze(binbounds=p_space.binbounds)) data_power = ift.log(fft(d).power_analyze(binbounds=p_space.binbounds))
d_data = d.val.real d_data = d.val.real
pl.plot([go.Heatmap(z=d_data)], filename='data.html', auto_open=False) ift.plotting.plot(d.real, name="data.pdf")
IC1 = ift.DefaultIterationController(verbose=True,iteration_limit=100) IC1 = ift.DefaultIterationController(verbose=True,iteration_limit=100)
minimizer1 = ift.RelaxedNewton(IC1) minimizer1 = ift.RelaxedNewton(IC1)
......
...@@ -18,7 +18,7 @@ if __name__ == "__main__": ...@@ -18,7 +18,7 @@ if __name__ == "__main__":
# Setting up the geometry |\label{code:wf_geometry}| # Setting up the geometry |\label{code:wf_geometry}|
L = 2. # Total side-length of the domain L = 2. # Total side-length of the domain
N_pixels = 128 # Grid resolution (pixels per axis) N_pixels = 128 # Grid resolution (pixels per axis)
#signal_space = RGSpace([N_pixels, N_pixels], distances=L/N_pixels) #signal_space = ift.RGSpace([N_pixels, N_pixels], distances=L/N_pixels)
signal_space = ift.HPSpace(16) signal_space = ift.HPSpace(16)
harmonic_space = signal_space.get_default_codomain() harmonic_space = signal_space.get_default_codomain()
fft = ift.FFTOperator(harmonic_space, target=signal_space) fft = ift.FFTOperator(harmonic_space, target=signal_space)
...@@ -53,39 +53,27 @@ if __name__ == "__main__": ...@@ -53,39 +53,27 @@ if __name__ == "__main__":
minimizer2 = ift.RelaxedNewton(controller=ctrl2) minimizer2 = ift.RelaxedNewton(controller=ctrl2)
minimizer3 = ift.SteepestDescent(controller=ctrl2) minimizer3 = ift.SteepestDescent(controller=ctrl2)
print type(energy.value) #me1 = minimizer1(energy)
me1 = minimizer1(energy)
me2 = minimizer2(energy) me2 = minimizer2(energy)
me3 = minimizer3(energy) #me3 = minimizer3(energy)
m1 = fft(me1[0].position) #m1 = fft(me1[0].position)
m2 = fft(me2[0].position) m2 = fft(me2[0].position)
m3 = fft(me3[0].position) #m3 = fft(me3[0].position)
# Probing the variance
#class Proby(ift.DiagonalProberMixin, ift.Prober): pass
#proby = Proby(signal_space, probe_count=100)
#proby(lambda z: fft(wiener_curvature.inverse_times(fft.inverse_times(z))))
#sm = SmoothingOperator(signal_space, sigma=0.02)
#variance = sm(proby.diagonal.weight(-1))
#Plotting #|\label{code:wf_plotting}| #Plotting #|\label{code:wf_plotting}|
#plotter = plotting.RG2DPlotter(color_map=plotting.colormaps.PlankCmap()) ift.plotting.plot(mock_signal.real,name='mock_signal.pdf', colormap="plasma",xlabel="Pixel Index",ylabel="Pixel Index")
plotter = ift.plotting.HealpixPlotter(color_map=ift.plotting.colormaps.PlankCmap()) ift.plotting.plot(ift.Field(signal_space, val=np.log(data.val.real).reshape(signal_space.shape)),name="log_of_data.pdf", colormap="plasma",xlabel="Pixel Index",ylabel="Pixel Index")
#ift.plotting.plot(m1.real,name='m_LBFGS.pdf', colormap="plasma",xlabel="Pixel Index",ylabel="Pixel Index")
ift.plotting.plot(m2.real,name='m_Newton.pdf', colormap="plasma",xlabel="Pixel Index",ylabel="Pixel Index")
#ift.plotting.plot(m3.real,name='m_SteepestDescent.pdf', colormap="plasma",xlabel="Pixel Index",ylabel="Pixel Index")
plotter.figure.xaxis = ift.plotting.Axis(label='Pixel Index') # Probing the variance
plotter.figure.yaxis = ift.plotting.Axis(label='Pixel Index') class Proby(ift.DiagonalProberMixin, ift.Prober): pass
proby = Proby(signal_space, probe_count=1)
proby(lambda z: fft(me2[0].curvature.inverse_times(fft.adjoint_times(z))))
plotter.plot.zmax = 5; plotter.plot.zmin = -5 sm = ift.FFTSmoothingOperator(signal_space, sigma=0.02)
#plotter(variance, path = 'variance.html') variance = sm(proby.diagonal.weight(-1))
# #plotter.plot.zmin = exp(mock_signal.min()); ift.plotting.plot(variance, name = 'variance.pdf')
# plotter(mock_signal.real, path='mock_signal.html')
# plotter(Field(signal_space, val=np.log(data.val.get_full_data().real).reshape(signal_space.shape)),
# path = 'log_of_data.html')
#
plotter(m1.real, path='m_LBFGS.html')
plotter(m2.real, path='m_Newton.html')
plotter(m3.real, path='m_SteepestDescent.html')
#
...@@ -58,7 +58,7 @@ if __name__ == "__main__": ...@@ -58,7 +58,7 @@ if __name__ == "__main__":
diagonal = mock_power.power_synthesize(spaces=(0, 1), mean=1, std=0, diagonal = mock_power.power_synthesize(spaces=(0, 1), mean=1, std=0,
real_signal=False)**2 real_signal=False)**2
#diagonal = diagonal.real diagonal = diagonal.real
S = ift.DiagonalOperator(domain=(harmonic_space_1, harmonic_space_2), S = ift.DiagonalOperator(domain=(harmonic_space_1, harmonic_space_2),
diagonal=diagonal) diagonal=diagonal)
...@@ -101,20 +101,19 @@ if __name__ == "__main__": ...@@ -101,20 +101,19 @@ if __name__ == "__main__":
# Probing the variance # Probing the variance
class Proby(ift.DiagonalProberMixin, ift.Prober): pass class Proby(ift.DiagonalProberMixin, ift.Prober): pass
proby = Proby((signal_space_1, signal_space_2), probe_count=100) proby = Proby((signal_space_1, signal_space_2), probe_count=2,ncpu=2)
proby(lambda z: fft(wiener_curvature.inverse_times(fft.inverse_times(z)))) proby(lambda z: fft(wiener_curvature.inverse_times(fft.inverse_times(z))))
# sm = SmoothingOperator(signal_space, sigma=0.02) # sm = SmoothingOperator(signal_space, sigma=0.02)
# variance = sm(proby.diagonal.weight(-1)) # variance = sm(proby.diagonal.weight(-1))
variance = proby.diagonal.weight(-1) variance = proby.diagonal.weight(-1)
plot_space = ift.RGSpace((N_pixels_1, N_pixels_2)) plot_space = ift.RGSpace((N_pixels_1, N_pixels_2))
plotter = plotting.RG2DPlotter(color_map=plotting.colormaps.PlankCmap())
plotter.figure.xaxis = ift.plotting.Axis(label='Pixel Index')
plotter.figure.yaxis = ift.plotting.Axis(label='Pixel Index')
plotter.plot.zmin = 0.
plotter.plot.zmax = 3.
sm = ift.FFTSmoothingOperator(plot_space, sigma=0.03) sm = ift.FFTSmoothingOperator(plot_space, sigma=0.03)
ift.plotting.plot(ift.log(ift.sqrt(sm(ift.Field(plot_space, val=variance.val.real)))), name='uncertainty.pdf',zmin=0.,zmax=3.,title="Uncertainty map",xlabel="x")
ift.plotting.plot(ift.Field(plot_space, val=mock_signal.val.real), name='mock_signal.pdf')
ift.plotting.plot(ift.Field(plot_space, val=data.val.real), name='data.pdf')
ift.plotting.plot(ift.Field(plot_space, val=m.val.real), name='map.pdf')
exit()
plotter(ift.log(ift.sqrt(sm(ift.Field(plot_space, val=variance.val.real)))), path='uncertainty.html') plotter(ift.log(ift.sqrt(sm(ift.Field(plot_space, val=variance.val.real)))), path='uncertainty.html')
plotter.plot.zmin = np.real(mock_signal.min()); plotter.plot.zmin = np.real(mock_signal.min());
......
...@@ -66,8 +66,7 @@ if __name__ == "__main__": ...@@ -66,8 +66,7 @@ if __name__ == "__main__":
m = wiener_curvature.inverse_times(j) m = wiener_curvature.inverse_times(j)
m_s = fft(m) m_s = fft(m)
ift.plotting.plot(mock_signal.real,"mock_signal.pdf") ift.plotting.plot(mock_signal.real,name="mock_signal.pdf")
ift.plotting.plot(mock_power.real,"power.pdf")
ift.plotting.plot(ift.Field(signal_space, ift.plotting.plot(ift.Field(signal_space,
val=data.val.real.reshape(signal_space.shape)), "data.pdf") val=data.val.real.reshape(signal_space.shape)), name="data.pdf")
ift.plotting.plot(m_s.real, "map.pdf") ift.plotting.plot(m_s.real, name="map.pdf")
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