Skip to main content

fpm_rs/
lib.rs

1#![deny(missing_docs)]
2//! Image-plane Fourier ptychographic microscopy (FPM) reconstruction and simulation.
3//!
4//! The crate separates experimental geometry from numerical reconstruction. A typical
5//! workflow is:
6//!
7//! 1. describe the microscope with [`experiment::Optics`] and an illumination source
8//!    such as [`experiment::PlanarLedArray`], plus calibration and acquisition;
9//! 2. compile that description into an algorithm-facing [`model::ImagePlaneModel`];
10//! 3. pair the model with resident or lazy [`measurements`] in a
11//!    [`reconstruction::ReconstructionProblem`];
12//! 4. select an [`algorithms`] implementation and run it directly or through a
13//!    [`reconstruction::Runner`];
14//! 5. inspect the complex object, amplitude, phase, pupil, trace, and [`diagnostics`]
15//!    in the resulting [`reconstruction::ReconstructionResult`]; and
16//! 6. optionally create controlled data with [`simulation`], calculate [`metrics`],
17//!    or persist result and benchmark bundles through [`reconstruction::ResultBundle`]
18//!    and [`benchmark`].
19//!
20//! Experimental coordinates and detector arrays use explicit conventions documented on
21//! their types. Two-dimensional arrays are generally indexed `(row, column)` and shaped
22//! `(height, width)`; transverse wave vectors are `(kx, ky)` in radians per metre.
23//!
24//! # Example
25//!
26//! ```
27//! use fpm_rs::{
28//!     algorithms::{AlternatingProjection, ReconstructionAlgorithm},
29//!     experiment::{ArrayPose, Illumination, Optics, PlanarLedArray},
30//!     measurements::{FrameMetadata, MeasurementStack},
31//!     model::{ImagePlaneModel, ReconstructionShape},
32//!     reconstruction::ReconstructionProblem,
33//! };
34//! use ndarray::Array3;
35//!
36//! # fn main() -> fpm_rs::Result<()> {
37//! let optics = Optics {
38//!     wavelength_vacuum_m: 532e-9,
39//!     objective_na: 0.1,
40//!     magnification: 4.0,
41//!     camera_pixel_size: 6.5e-6,
42//!     illumination_refractive_index: 1.0,
43//!     objective_medium_refractive_index: 1.0,
44//!     defocus_distance: None,
45//!     pupil_aberration: None,
46//! };
47//! let illumination = Illumination::from_geometry(PlanarLedArray::new(
48//!     (1, 1),
49//!     (4e-3, 4e-3),
50//!     (0.0, 0.0),
51//!     ArrayPose::from_translation([0.0, 0.0, -90e-3]),
52//! ))?;
53//! let model = ImagePlaneModel::from_experiment(
54//!     &optics,
55//!     &illumination,
56//!     (4, 4),
57//!     ReconstructionShape::Exact((4, 4)),
58//! )?;
59//! let measurements = MeasurementStack::new(
60//!     Array3::from_elem((1, 4, 4), 1.0),
61//!     vec![FrameMetadata::new(0)],
62//! )?;
63//! let problem = ReconstructionProblem::new(measurements, model)?;
64//! let result = AlternatingProjection::default().iterations(1).run(&problem)?;
65//! assert_eq!(result.object.dim(), (4, 4));
66//! # Ok(())
67//! # }
68//! ```
69
70/// Reconstruction algorithms and their shared execution contract.
71pub mod algorithms;
72mod array_layout;
73mod array_serde;
74/// CPU execution and the interfaces used by future resident-buffer backends.
75pub mod backend;
76pub mod benchmark;
77#[cfg(feature = "parquet")]
78pub mod benchmark_bundle;
79/// Iteration callbacks for progress, checkpoints, diagnostics, and image output.
80pub mod callbacks;
81/// Utilities for complex fields, amplitude, and wrapped phase.
82pub mod complex;
83pub mod configuration;
84pub mod datasets;
85/// Structured iteration and per-frame reconstruction diagnostics.
86pub mod diagnostics;
87/// Error categories and the crate-wide [`error::Result`] alias.
88pub mod error;
89pub mod evaluation;
90/// Physical optics and illumination geometry compiled into numerical models.
91pub mod experiment;
92/// Bounded physical planar-array calibration configuration, state, and diagnostics.
93pub mod illumination_calibration;
94/// Bright-field circle initialization for bounded physical planar arrays.
95pub mod illumination_initialization;
96mod image_io;
97/// Resident and lazy low-resolution intensity measurement stacks.
98pub mod measurements;
99pub mod metrics;
100/// Compiled image-plane models, Fourier crops, pupils, and forward propagation.
101pub mod model;
102/// Reconstruction problems, state, schedules, runners, results, and checkpoints.
103pub mod reconstruction;
104/// Synthetic objects, camera response, acquisition effects, and simulation.
105pub mod simulation;
106#[cfg(feature = "tabular")]
107pub mod tabular;
108
109#[cfg(feature = "parquet")]
110pub use benchmark_bundle::{BenchmarkBundle, read_benchmark_bundle};
111pub use error::{Error, Result};
112pub use num_complex::Complex64;
113#[cfg(feature = "parquet")]
114pub use reconstruction::{ResultBundle, read_bundle};