ptycho#
Functions for ptychography.
Solve the ptychography problem. |
|
Solve the ptychography problem using a multi-grid method. |
|
Context manager for online ptychography reconstruction. |
|
Return real-valued detector counts of simulated ptychography data. |
- class tike.ptycho.ptycho.Reconstruction[source]#
Bases:
object
Context manager for online ptychography reconstruction.
New in version 0.22.0.
Uses same parameters as the functional reconstruct API. Using a context manager allows for getting the current result or adding additional data without deallocating memory on the GPU.
Example
Data structure remain allocated on the GPU as long as the context is active. This allows quickly resuming a reconstruction.
with tike.ptycho.Reconstruction( data, parameters, num_gpu, use_mpi, ) as context: # Start reconstructing context.iterate(num_iter) # Check the current solution for the object early_result = context.get_psi() # Continue reconstructing context.iterate() # All datastructures are transferred off the GPU at context close final_result = context.parameters
See also
- __init__(data, parameters, num_gpu=1, use_mpi=False)[source]#
- Parameters
data (numpy.typing.NDArray) –
parameters (PtychoParameters) –
num_gpu (Union[int, Tuple[int, ...]]) –
use_mpi (bool) –
- append_new_data(new_data, new_scan)[source]#
Append new diffraction patterns and positions to existing result.
- Parameters
new_data (numpy.typing.NDArray) –
new_scan (numpy.typing.NDArray) –
- Return type
None
- get_convergence()[source]#
Return the cost function values and times as a tuple.
- Return type
Tuple[List[List[float]], List[float]]
- get_probe()[source]#
Return the current probe, eigen_probe, weights as numpy arrays.
- Return type
Tuple[numpy.array, numpy.array, numpy.array]
- tike.ptycho.ptycho.reconstruct(data, parameters, num_gpu=1, use_mpi=False)[source]#
Solve the ptychography problem.
This functional interface is the simplest to use, but deallocates GPU memory when it returns. Use the context manager API for the ability to get live results without ending the reconsturction.
- Parameters
data ((FRAME, WIDE, HIGH) uint16) – The intensity (square of the absolute value) of the propagated wavefront; i.e. what the detector records. FFT-shifted so the diffraction peak is at the corners.
parameters (
tike.ptycho.solvers.PtychoParameters
) – A class containing reconstruction parameters.num_gpu (int, tuple(int)) – The number of GPUs to use or a tuple of the device numbers of the GPUs to use. If the number of GPUs is less than the requested number, only workers for the available GPUs are allocated.
use_mpi (bool) – Whether to use MPI or not.
- Return type
Changed in version 0.25.0: Removed the model parameter. Use
tike.ptycho.exitwave.ExitwaveOptions
instead.- Raises
ValueError – When shapes are incorrect for various input parameters.
- Returns
result – A class containing reconstruction parameters.
- Return type
- Parameters
data (numpy.typing.NDArray) –
parameters (PtychoParameters) –
num_gpu (Union[int, Tuple[int, ...]]) –
use_mpi (bool) –
- tike.ptycho.ptycho.reconstruct_multigrid(data, parameters, num_gpu=1, use_mpi=False, num_levels=3, interp=<function _resize_fft>)[source]#
Solve the ptychography problem using a multi-grid method.
New in version 0.23.2.
Uses the same parameters as the functional reconstruct API. This function applies a multi-grid approach to the problem by downsampling the real-space input parameters and cropping the diffraction patterns to reduce the computational cost of early iterations.
- Parameters
num_levels (int > 0) – The number of times to reduce the problem by a factor of two.
data (numpy.typing.NDArray) –
parameters (PtychoParameters) –
num_gpu (Union[int, Tuple[int, ...]]) –
use_mpi (bool) –
interp (Callable) –
- Return type
See also
- tike.ptycho.ptycho.simulate(detector_shape, probe, scan, psi, fly=1, eigen_probe=None, eigen_weights=None, **kwargs)[source]#
Return real-valued detector counts of simulated ptychography data.
- Parameters
detector_shape (int) – The pixel width of the detector.
probe ((..., 1, 1, SHARED, WIDE, HIGH) complex64) – The shared complex illumination function amongst all positions.
scan ((..., POSI, 2) float32) – Coordinates of the minimum corner of the probe grid for each measurement in the coordinate system of psi.
psi ((..., WIDE, HIGH) complex64) – The complex wavefront modulation of the object.
fly (int) – The number of scan positions which combine for one detector frame.
eigen_probe ((..., 1, EIGEN, SHARED, WIDE, HIGH) complex64) – The eigen probes for all positions.
eigen_weights ((..., POSI, EIGEN, SHARED) float32) – The relative intensity of the eigen probes at each position.
- Returns
data – The simulated intensity on the detector.
- Return type
(…, FRAME, WIDE, HIGH) float32