mirror of
https://github.com/cdtools-developers/cdtools.git
synced 2026-09-10 05:22:41 +02:00
38 lines
1.2 KiB
Python
38 lines
1.2 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()
|
|
|
|
# We run the reconstruction
|
|
for loss in model.Adam_optimize(100, 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
|
|
model.inspect()
|
|
|
|
# We open a comparison of the simulated and measured data
|
|
model.compare(dataset)
|
|
plt.show()
|