Commit aa91ea8c authored by Martin Reinecke's avatar Martin Reinecke

Merge branch 'demo_fixes' into 'NIFTy_5'

Python compatibility

See merge request !286
parents c4e46aae e718532a
Pipeline #43302 passed with stages
in 18 minutes and 37 seconds
......@@ -21,6 +21,8 @@
# 1D (set mode=0), 2D (mode=1), or on the sphere (mode=2)
###############################################################################
import sys
import numpy as np
import nifty5 as ift
......@@ -51,7 +53,6 @@ def mask_to_nan(mask, field):
if __name__ == '__main__':
import sys
np.random.seed(42)
# Choose space on which the signal field is defined
......@@ -140,7 +141,7 @@ if __name__ == '__main__':
# Plotting
rg = isinstance(position_space, ift.RGSpace)
plot = ift.Plot()
filename = f"getting_started_1_mode_{mode}.png"
filename = "getting_started_1_mode_{}.png".format(mode)
if rg and len(position_space.shape) == 1:
plot.add(
[HT(MOCK_SIGNAL), GR.adjoint(data),
......@@ -155,4 +156,4 @@ if __name__ == '__main__':
plot.add(HT(m), title='Reconstruction')
plot.add(mask_to_nan(mask, HT(m - MOCK_SIGNAL)), title='Residuals')
plot.output(nx=2, ny=2, xsize=10, ysize=10, name=filename)
print(f"Saved results as '{filename}'.")
print("Saved results as '{}'.".format(filename))
......@@ -21,6 +21,8 @@
# 1D (set mode=0), 2D (mode=1), or on the sphere (mode=2)
###############################################################################
import sys
import numpy as np
import nifty5 as ift
......@@ -42,8 +44,6 @@ def exposure_2d():
if __name__ == '__main__':
import sys
# FIXME All random seeds to 42
np.random.seed(42)
# Choose space on which the signal field is defined
......@@ -112,11 +112,11 @@ if __name__ == '__main__':
# Plotting
signal = sky(mock_position)
reconst = sky(H.position)
filename = f"getting_started_2_mode_{mode}.png"
filename = "getting_started_2_mode_{}.png".format(mode)
plot = ift.Plot()
plot.add(signal, title='Signal')
plot.add(GR.adjoint(data), title='Data')
plot.add(reconst, title='Reconstruction')
plot.add(reconst - signal, title='Residuals')
plot.output(xsize=12, ysize=10, name=filename)
print(f"Saved results as '{filename}'.")
print("Saved results as '{}'.".format(filename))
......@@ -25,6 +25,8 @@
# Demo takes a while to compute
#############################################################
import sys
import numpy as np
import nifty5 as ift
......@@ -43,8 +45,7 @@ def radial_los(n_los):
if __name__ == '__main__':
import sys
np.random.seed(420) # picked for a nice field realization
np.random.seed(420)
# Choose between random line-of-sight response (mode=0) and radial lines
# of sight (mode=1)
......@@ -52,7 +53,7 @@ if __name__ == '__main__':
mode = int(sys.argv[1])
else:
mode = 0
filename = f"getting_started_3_mode_{mode}_" + "{}.png"
filename = "getting_started_3_mode_{}_".format(mode) + "{}.png"
position_space = ift.RGSpace([128, 128])
harmonic_space = position_space.get_default_codomain()
......@@ -135,7 +136,7 @@ if __name__ == '__main__':
plot.add(signal(KL.position), title="reconstruction")
plot.add([A.force(KL.position), A.force(mock_position)], title="power")
plot.output(ny=1, ysize=6, xsize=16,
name=filename.format(f"loop_{i:02}"))
name=filename.format("loop_{:02d}".format(i)))
# Draw posterior samples
KL = ift.MetricGaussianKL(mean, H, N_samples)
......@@ -156,4 +157,4 @@ if __name__ == '__main__':
title="Sampled Posterior Power Spectrum",
linewidth=[1.]*len(powers) + [3., 3.])
plot.output(ny=1, nx=3, xsize=24, ysize=6, name=filename_res)
print(f"Saved results as '{filename_res}'.")
print("Saved results as '{}'.".format(filename_res))
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