mirror of
https://github.com/cdtools-developers/cdtools.git
synced 2026-09-09 21:12:42 +02:00
- Switch panel plots to use subfigures with constrained_layout for better layout management - Add plot_loss_history method to CDIModel base class - Fix matplotlib compatibility for older versions (interactive backend detection) - Make CUDA usage conditional in examples - Add panel_plot_mode and plot_level params to FancyPtycho constructor - Default plot_level filtering to 1 instead of 0 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
"""
|
|
Runs a very simple reconstruction using the SimplePtycho model, which was
|
|
designed to be an easy introduction to show how the models are made and used.
|
|
|
|
For a more realistic example of how to use cdtools for real-world data,
|
|
look at fancy_ptycho.py and gold_ball_ptycho.py, both of which use the
|
|
more powerful FancyPtycho model and include more information on how to
|
|
correct for common sources of error.
|
|
"""
|
|
import cdtools
|
|
import torch as t
|
|
from matplotlib import pyplot as plt
|
|
|
|
# We load an example dataset from a .cxi file
|
|
filename = 'example_data/lab_ptycho_data.cxi'
|
|
dataset = cdtools.datasets.Ptycho2DDataset.from_cxi(filename)
|
|
|
|
# We create a ptychography model from the dataset
|
|
model = cdtools.models.SimplePtycho.from_dataset(dataset)
|
|
|
|
# We move the model to the GPU, if possible
|
|
if t.cuda.is_available():
|
|
model.to(device='cuda')
|
|
dataset.get_as(device='cuda')
|
|
|
|
model.inspect(dataset)
|
|
print('hi')
|
|
# We run the reconstruction
|
|
for loss in model.Adam_optimize(30, dataset, batch_size=10):
|
|
# We print a quick report of the optimization status
|
|
print(model.report())
|
|
# And liveplot the updates to the model as they happen
|
|
if model.epoch % 10 == 0:
|
|
model.inspect(dataset)
|
|
|
|
# We study the results
|
|
model.inspect(dataset, replot_all=True)
|
|
model.compare(dataset)
|
|
plt.show()
|