fpm-rs Python quickstart¶
Configure a microscope, simulate NumPy data, and reconstruct it with the Rust core. Before running the code, install the released package in this notebook's environment with %pip install "fpm-rs[notebook]".
In [1]:
Copied!
import matplotlib.pyplot as plt
import numpy as np
from IPython.display import display
import fpm_rs as fpm
import matplotlib.pyplot as plt
import numpy as np
from IPython.display import display
import fpm_rs as fpm
In [2]:
Copied!
optics = fpm.Optics(532e-9, 0.10, 4.0, 6.5e-6)
leds = fpm.LEDArray((3, 3), 4e-3, 90e-3, (1.0, 1.0))
model = fpm.compile_model(optics, leds, (32, 32), (64, 64))
row, column = np.indices(model.reconstruction_shape)
true_amplitude = 0.7 + 0.3 * ((row // 8 + column // 8) % 2)
true_phase = 0.4 * np.sin(row / 7.0) * np.cos(column / 9.0)
object_field = np.asarray(true_amplitude * np.exp(1j * true_phase), dtype=np.complex128)
optics = fpm.Optics(532e-9, 0.10, 4.0, 6.5e-6)
leds = fpm.LEDArray((3, 3), 4e-3, 90e-3, (1.0, 1.0))
model = fpm.compile_model(optics, leds, (32, 32), (64, 64))
row, column = np.indices(model.reconstruction_shape)
true_amplitude = 0.7 + 0.3 * ((row // 8 + column // 8) % 2)
true_phase = 0.4 * np.sin(row / 7.0) * np.cos(column / 9.0)
object_field = np.asarray(true_amplitude * np.exp(1j * true_phase), dtype=np.complex128)
In [3]:
Copied!
simulation = fpm.simulate(model, object_field, seed=1234)
problem = fpm.ReconstructionProblem(simulation.measurements, simulation.reconstruction_model)
result = fpm.AlternatingProjection(iterations=20).run(problem)
simulation = fpm.simulate(model, object_field, seed=1234)
problem = fpm.ReconstructionProblem(simulation.measurements, simulation.reconstruction_model)
result = fpm.AlternatingProjection(iterations=20).run(problem)
In [4]:
Copied!
truth = simulation.ground_truth_object
figure, axes = fpm.plot.plot_reconstruction(truth, result)
display(figure)
# figure.savefig("quickstart_reconstruction.png", dpi=180, bbox_inches="tight")
plt.close(figure)
truth = simulation.ground_truth_object
figure, axes = fpm.plot.plot_reconstruction(truth, result)
display(figure)
# figure.savefig("quickstart_reconstruction.png", dpi=180, bbox_inches="tight")
plt.close(figure)