pipe.add_transform(r)
# Our real solution should also be changed, so we need to use same trick again.
mod.solution = real_solution
pipe.forward()
real_solution = mod.solution
mod.plot2d()
mod.solution = None
# The rescaling is successful.
# If you want to switch to previous 20x30 cells case just use pipe.backward(). Note that you will lost

# Now let's find the solution. In order to do so we need to create solver.
solver = Solver()
# We can easily track different statistics. Let's track residual norm and Chi^2 statistics.
# When the calculations are over you can plot the results or find statistical value at each step
# in "data" attribute of each object, e.g. in solver.statistics[0].data
solver.statistics = [statistics.RN(), statistics.RMS()]
# RMS need to know real solution in order to perform calculations.
solver.real_solution = real_solution

# Finally, let's choose method, we would like to use in order to find the solution.
# We start with  maximum likelihood method.
solver.iterator = ml.ML()
# Let's do 50 steps and see resulted image and statistics.
steps = 50
solver.solve(mod, steps=steps)
mod.plot2d()
solver.plot_statistics()

# Now let's change to  algebraic reconstruction technique.
solver.iterator = algebraic.ART()
# We can also add some constraints. This is important in the case of limited date reconstruction.
# Next step is to simulate each detector signal.
det_signal = signal.get_signal(real_solution, det)
mod.detector_signal = det_signal

# Now let's create solver which will use ART with step = 0.1 in order to find the solution.
solver = solver.Solver()
solver.iterator = algebraic.ART()
solver.iterator.alpha = 0.1
# When you are using ART, often a good idea is to suggest that all values are positive.
c1 = tomomak.constraints.basic.Positive()
solver.constraints = [c1]

# Finally we want some quantitative parameters in order to evaluate reconstruction results.
# Let's count residual mean square and residual norm.
solver.statistics = [statistics.RMS(), statistics.RN()]
# In order to get RMS real solution should be defined.
solver.real_solution = real_solution

# Ok, it's time to solve. Let's do 1000 iterations and see the results.
steps = 1000
solver.solve(mod, steps)
mod.plot2d()
# There are some artifacts but generally picture looks pretty good.
# Now let's plot the statistics.
solver.plot_statistics()
# You can see that both RMS and RN quickly fall during several first steps
# and than begin to slowly reach zero. !!!reach
# You can check yourself that after more iterations
# for the naked eye calculated solution will look exactly like the real one. Just uncomment two following lines.
# solver.solve(mod, 30000)