-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from PolarizedLightFieldMicroscopy/mbl_2024
MBL September 2024
- Loading branch information
Showing
37 changed files
with
792 additions
and
549 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"n_epochs": 100, | ||
"num_iterations": 100, | ||
"regularization_weight": 0.1, | ||
"lr": 1e-3, | ||
"lr_birefringence": 1e-3, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# %% Importing necessary libraries | ||
import os | ||
import numpy as np | ||
import torch | ||
from VolumeRaytraceLFM.abstract_classes import BackEnds | ||
from VolumeRaytraceLFM.simulations import ForwardModel | ||
from VolumeRaytraceLFM.birefringence_implementations import BirefringentVolume | ||
from VolumeRaytraceLFM.volumes import volume_args | ||
from VolumeRaytraceLFM.setup_parameters import ( | ||
setup_optical_parameters, | ||
setup_iteration_parameters, | ||
) | ||
from VolumeRaytraceLFM.reconstructions import ReconstructionConfig, Reconstructor | ||
from VolumeRaytraceLFM.utils.file_utils import ( | ||
create_unique_directory, | ||
) | ||
|
||
# %% Configuration paramters to be changed | ||
simulate = True | ||
|
||
# Volume creation arguments, see src/VolumeRaytraceLFM/volumes/volume_args.py for more options | ||
volume_gt_creation_args = volume_args.voxel_args | ||
volume_initial_creation_args = volume_args.random_pos_args | ||
|
||
# Paths to the optical and iteration configuration files | ||
optical_config_file = os.path.join("..", "config", "optical_config_voxel.json") | ||
iter_config_file = os.path.join("..", "config", "iter_config_reg.json") | ||
|
||
# Path to the directory where the reconstruction will be saved | ||
recon_output_dir = os.path.join("..", "reconstructions", "voxel") | ||
recon_output_dir_postfix = "postfix" | ||
recon_directory = create_unique_directory(recon_output_dir, postfix=recon_output_dir_postfix) | ||
|
||
# Whether to continue a previous reconstruction | ||
continue_recon = False | ||
recon_file_path = r"to be alterned.h5" | ||
|
||
# For loading forward images that were saved in a previous reconstruction folder | ||
measurement_dir = os.path.join(recon_output_dir, "to be altered") | ||
|
||
BACKEND = BackEnds.PYTORCH | ||
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu") | ||
|
||
print(f"Using device: {DEVICE}") | ||
|
||
# %% Simulate or load forward images | ||
optical_info = setup_optical_parameters(optical_config_file) | ||
|
||
if simulate: | ||
optical_system = {"optical_info": optical_info} | ||
simulator = ForwardModel(optical_system, backend=BACKEND) | ||
volume_GT = BirefringentVolume( | ||
backend=BACKEND, | ||
optical_info=optical_info, | ||
volume_creation_args=volume_gt_creation_args, | ||
) | ||
simulator.forward_model(volume_GT) | ||
simulator.view_images() | ||
ret_image_meas = simulator.ret_img.detach().numpy() | ||
azim_image_meas = simulator.azim_img.detach().numpy() | ||
else: | ||
ret_image_meas = np.load(os.path.join(measurement_dir, "ret_image.npy")) | ||
azim_image_meas = np.load(os.path.join(measurement_dir, "azim_image.npy")) | ||
volume_GT = None | ||
|
||
# %% Run reconstruction | ||
recon_optical_info = optical_info.copy() | ||
iteration_params = setup_iteration_parameters(iter_config_file) | ||
if continue_recon: | ||
initial_volume = BirefringentVolume.init_from_file(recon_file_path, BACKEND, recon_optical_info) | ||
else: | ||
initial_volume = BirefringentVolume( | ||
backend=BACKEND, | ||
optical_info=recon_optical_info, | ||
volume_creation_args=volume_initial_creation_args, | ||
) | ||
recon_config = ReconstructionConfig( | ||
recon_optical_info, | ||
ret_image_meas, | ||
azim_image_meas, | ||
initial_volume, | ||
iteration_params, | ||
gt_vol=volume_GT | ||
) | ||
recon_config.save(recon_directory) | ||
reconstructor = Reconstructor( | ||
recon_config, | ||
output_dir=recon_directory, | ||
device=DEVICE | ||
) | ||
reconstructor.reconstruct(plot_live=True) | ||
print("Reconstruction complete") | ||
|
||
# %% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.