Skip to content

PxA-Labs/Project-RIPRA

Repository files navigation

Project RIPRA (ऋप्र)

Project RIPRA Logo

Developing and optimizing algorithms for Wavefront Reconstruction and Turbulence Characterization using Shack-Hartmann Wavefront Sensor (SH-WFS) time-series data.

Note: For a comprehensive analysis of the project results, detailed mathematical formulations, and the complete gallery of all 11 simulation telemetry plots, please refer to our GitHub Discussion: End-to-End Wavefront Reconstruction & Control Benchmarks.


Description

Turbulence in the atmosphere distorts a plane-parallel wavefront propagating through it. A Shack-Hartmann Wavefront Sensor (SH-WFS) samples this distorted wavefront using an array of small lenslets (Microlens Array - MLA). The MLA creates a spot-field on the camera detector, and the spatial deviation of these spots from their reference positions is used to derive the reconstructed wavefront and its associated Zernike coefficients.

The conjugate of this reconstructed wavefront is typically used to generate an actuator command map (in units of actuator stroke length) which is then fed to a Deformable Mirror (DM) to correct for this distortion in real-time.

System Schematic


Interactive Jupyter Notebooks

The calculations, rendering, training, and compilation suites detailed in this project are fully interactive and can be executed via the notebooks located in the notebook/ folder:

  1. kaggle_synthetic_shwfs_generator.ipynb:
    • Rebuilds the end-to-end WFS pipeline. Renders physical frames, configures system directories, trains the ML reconstructors, and compiles/executes the C POSIX integration test suites.
  2. V1_Simulation_TEST.ipynb:
    • The reference execution notebook housing pre-calculated outputs and static telemetry diagrams.
  3. Kaggle_RIPRA_WFS_Predictive_AO_Pipeline.ipynb:
    • Implements the deep-learning sequence model pipeline, training LSTM predictors for loop lag compensation, turbulence regime classification, and parameter estimation.
  4. Kaggle_RIPRA_ML_Pipeline.ipynb:
    • Training pipeline to map centroid displacements to Zernike modal coefficients.
  5. Kaggle_RIPRA_ML_Pipeline_baseline.ipynb:
    • Training pipeline for baseline model configurations.

Wavefront Diagnostics and Telemetry Highlights

Below are the key visual outcomes of the physical simulation and closed-loop control loops.

1. Wavefront Optical Path Difference (OPD) Phase Map

Wavefront Telemetry

  • Description: Renders the 2D reconstructed phase screen ($W(x,y)$) alongside a 3D elevation map showing peaks (positive phase delay) and valleys (negative phase delay) of the optical aberration.
  • Impact: Confirms high-fidelity reconstruction of low-order modes (Tip, Tilt, Defocus) across the circular pupil boundary.

2. Deep Learning Reconstructor Accuracy Benchmarks

ML Dashboard

  • Description: Displays MLP vs. CNN training loss convergence, defocus mode regression accuracy, and mode-by-mode Pearson correlation comparison.
  • Impact: The Conv2D CNN reconstructor achieves a test MSE of $0.001957$ (mean correlation of $99.97%$), representing a $4.6\times$ accuracy gain over the MLP baseline.

3. Predictive AO Lag Compensation

Predictive AO

  • Description: Trains an LSTM predictor on historical Zernike sequences. Under 1-frame latency, a standard integrator control loop diverges (green curve), whereas the LSTM predictor (blue curve) remains stable, reducing residual RMS error by $6.6%$.
  • Impact: Prevents loop instability in high-speed optical systems operating under hardware delay.

Real-Time Processing Performance Benchmarks

The real-time pipeline executes in sub-milliseconds on standard CPU threads, making it fully qualified for high-frequency ($1\text{ kHz}$) closed-loop control:

Pipeline Phase Algorithm Latency ($\mu\text{s}$)
Centroiding Thresholded Center of Gravity (TCoG) $482,\mu\text{s}$
Reconstruction Fried Geometry Zonal Matrix Solver $194,\mu\text{s}$
DM Actuator Mapping Influence Coupling Matrix multiplication $85,\mu\text{s}$
Total Latency End-to-End Loop $761,\mu\text{s}$

Installation and Execution Guide

1. Build the POSIX C Library

Compile the static archive librippra.a and the integration tests using GCC with OpenMP support:

cd rippra
mkdir -p build
# Compile object files
gcc -O2 -fopenmp -c src/io.c -o build/io.o -Iinclude
gcc -O2 -fopenmp -c src/la.c -o build/la.o -Iinclude
gcc -O2 -fopenmp -c src/centroid.c -o build/centroid.o -Iinclude
gcc -O2 -fopenmp -c src/recon.c -o build/recon.o -Iinclude
gcc -O2 -fopenmp -c src/rippra_api.c -o build/rippra_api.o -Iinclude

# Link static archive
ar rcs build/librippra.a build/io.o build/la.o build/centroid.o build/recon.o build/rippra_api.o

# Build test suites
gcc -O2 -fopenmp tests/test_full_pipeline.c build/io.o build/la.o build/centroid.o build/recon.o build/rippra_api.o -Iinclude -lm -o build/test_full_pipeline
gcc -O2 -fopenmp tests/test_recon.c build/io.o build/la.o build/centroid.o build/recon.o build/rippra_api.o -Iinclude -lm -o build/test_recon

2. Run the C Verification Tests

Verify centroiding accuracy, zonal/modal solvers, and closed-loop DM convergence:

./build/test_full_pipeline
./build/test_recon

3. Run the ML Pipeline

Install dependencies and launch the Jupyter Notebook environment:

pip install torch numpy matplotlib pandas scipy
jupyter notebook

Open notebook/kaggle_synthetic_shwfs_generator.ipynb to customize parameters, render new calibration frames, or train models.


Problem Statement Visualizations

1. Example of Wavefront Sensor (WFS) Frame

WFS Frame

2. Spot Deviation on Detector due to Distorted Wavefront

Spot Deviation

About

Algorithms for Wavefront Reconstruction, Turbulence Characterization, and Deformable Mirror Actuator Mapping using Shack-Hartmann WFS time-series data.

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors