<jupyter_start><jupyter_text>FPM Reconstruction Script<jupyter_code>%load_ext autoreload
%autoreload 2
%matplotlib notebook

import scipy.io as sio
import scipy.linalg as la
import matplotlib.pyplot as plt
import numpy as np
import os, glob, json

# Backend-independent operations
import llops as yp

# FPM functions
import fpm
from fpm import util<jupyter_output><empty_output><jupyter_text>Generate LED Positions<jupyter_code># Load LED positions
source_list_mat_file_name = './source_list_quasi_dome.mat'
mat = sio.loadmat(source_list_mat_file_name)
source_list_cart = mat['source_list_cart'].copy()<jupyter_output><empty_output><jupyter_text>Load Data<jupyter_code># Single LED Scan
dataset_path = '/Users/zfphil/Dropbox/Datasets/2017-09-29 Multiplex FPM/fpm_2017_09_29_17_10_41'

# Multiplexed LED Scan
# dataset_path = '/Users/zfphil/Dropbox/Datasets/2017-09-29 Multiplex FPM/fpm_2017_09_29_17_17_47'

mat = sio.loadmat(source_list_mat_file_name)


# Define system parameters for our system
system_parameters = {
                         'objective_numerical_aperture': 0.25,
                         'objective_magnification': 10.0,
                         'system_magnification': 1.0,
                         'camera_pixel_size': 6.5e-6,
                         'camera_is_color': False,
                         'illumination_wavelength': 0.53e-6,
                         'illumination_source_position_list_cartesian': mat['source_list_cart'].copy()
                     }

# Load frames
frame_file_list = sorted(glob.glob(os.path.join(dataset_path, '*.tif')))

# Deal with .tiff stack case
if len(frame_file_list) == 1:
    frame_list = util.readMultiPageTiff(frame_file_list[0])
else:
    frame_list = []
    for frame_file in frame_file_list:
        frame_list.append(util.readMultiPageTiff(frame_file))<jupyter_output><empty_output><jupyter_text>Process Data<jupyter_code>fpm_opt = fpm.FpmOptions()

# Define custom options
fpm_opt.roi = iotools.Roi(x_start=225, x_end=275, y_start=225, y_end=275)
fpm_opt.alg_gd_step_size = 1e-1
fpm_opt.alg_nest_alpha = 1e-3
fpm_opt.alg_nest_beta = 1e-4
fpm_opt.led_auto_calib_use_pre = True
fpm_opt.led_auto_calib_enabled = False
fpm_opt.live_plot = True
fpm_opt.max_na = 0.5
fpm_opt.max_it = 25
fpm_opt.lm_delta2 = 5e0
fpm_opt.algorithm = "seq_gd"
fpm_opt.objective_function_type = 'intensity'

# Create FPM solver object and run solver
fpm_obj = fpm.FpmSolver(dataset=fpm_dataset, options=fpm_opt)

# Run Solver
fpm_obj.run()

# Plot Result
fpm_obj.plotResult()<jupyter_output><empty_output><jupyter_text>Update the LED positions and save<jupyter_code>if True:
    mat['source_list_na'] = fpm_obj.source_list_na.copy()
    sio.savemat(source_list_mat_file_name,mat)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09560159941839332, 'fraction_numerical': 0.03162486368593239, 'mean_word_length': 4.364522417153996, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '429740', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1027, 'n_words': 170, 'path': 'notebooks/fpm_main.ipynb', 'repo_name': 'zfphil/pyfpm', 'size': '2751'}