Skip to content

Commit

Permalink
Merge for release 0.7.0
Browse files Browse the repository at this point in the history
PtyPy workshop release
  • Loading branch information
bjoernenders committed Jan 9, 2023
2 parents 2358e36 + 8919376 commit 8052ecf
Show file tree
Hide file tree
Showing 24 changed files with 922 additions and 806 deletions.
1 change: 1 addition & 0 deletions dependencies_full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ dependencies:
- mpi4py
- pillow
- pyfftw
- pyyaml
- pip

10 changes: 4 additions & 6 deletions ptypy/accelerate/base/array_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def mass_center(A):
'''
Input will always be real, and 2d or 3d, single precision here
'''
return np.array(ndi.measurements.center_of_mass(A), dtype=A.dtype)
return np.array(ndi.center_of_mass(A), dtype=A.dtype)


def interpolated_shift(c, shift, do_linear=False):
Expand All @@ -84,13 +84,11 @@ def interpolated_shift(c, shift, do_linear=False):
'''
if not do_linear:
return ndi.interpolation.shift(np.real(c), shift, order=3, prefilter=True) + 1j * ndi.interpolation.shift(
return ndi.shift(np.real(c), shift, order=3, prefilter=True) + 1j * ndi.shift(
np.imag(c), shift, order=3, prefilter=True)
else:
return ndi.interpolation.shift(np.real(c), shift, order=1, mode='constant', cval=0,
prefilter=False) + 1j * ndi.interpolation.shift(np.imag(c), shift, order=1,
mode='constant', cval=0,
prefilter=False)
return ndi.shift(np.real(c), shift, order=1, mode='constant', cval=0, prefilter=False) + 1j * ndi.shift(
np.imag(c), shift, order=1, mode='constant', cval=0, prefilter=False)


def clip_complex_magnitudes_to_range(complex_input, clip_min, clip_max):
Expand Down
1 change: 1 addition & 0 deletions ptypy/accelerate/cuda_pycuda/dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies:
- mpi4py
- pillow
- pyfftw
- pyyaml
- reikna
- pycuda
- cudatoolkit-dev
Expand Down
2 changes: 1 addition & 1 deletion ptypy/core/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ class BasicNearfieldPropagator(object):
Basic two step (i.e. two ffts) Nearfield Propagator.
"""

def __init__(self, geo_pars=None, ffttype='fftw', **kwargs):
def __init__(self, geo_pars=None, ffttype='numpy', **kwargs):
"""
Parameters
----------
Expand Down
1 change: 1 addition & 0 deletions ptypy/core/illumination.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ def init_storage(storage, pars, energy=None, **kwargs):
'Attempt to load layer `%s` of probe storage with ID `%s` from `%s`'
% (str(layer), str(ID), p.recon.rfile))
model = u.load_from_ptyr(p.recon.rfile, 'probe', ID, layer)
p.photons = None
# This could be more sophisticated,
# i.e. matching the real space grids etc.
elif str(p.model) == 'stxm':
Expand Down
17 changes: 14 additions & 3 deletions ptypy/core/ptycho.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,9 +700,20 @@ def run(self, label=None, epars=None, engine=None):
'Time %(duration).3f' % info)
logger.info('Errors :: Fourier %.2e, Photons %.2e, '
'Exit %.2e' % tuple(err))
ilog_streamer('%(engine)s: Iteration # %(iteration)d/%(numiter)d :: ' %info +
'Fourier %.2e, Photons %.2e, Exit %.2e' %tuple(err))

imsg = '%(engine)s: Iteration # %(iteration)d/%(numiter)d :: ' %info + \
'Fourier %.2e, Photons %.2e, Exit %.2e' %tuple(err)
if not self.p.io.autoplot.threaded:
if not (info["iteration"] % self.p.io.autoplot.interval):
from IPython import display
from ptypy.utils.plot_client import _JupyterClient
JC = _JupyterClient(self, autoplot_pars=self.p.io.autoplot, layout_pars=self.p.io.autoplot.layout)
JC.runtime.update(self.runtime)
fig = JC.plot(title=imsg)
display.clear_output(wait=True)
display.display(fig)
else:
ilog_streamer(imsg)

parallel.barrier()

ilog_newline()
Expand Down
100 changes: 100 additions & 0 deletions ptypy/experiment/epsic_loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# -*- coding: utf-8 -*-
"""\
Scan loading recipe for the Diamond beamlines.
This file is part of the PTYPY package.
:copyright: Copyright 2014 by the PTYPY team, see AUTHORS.
:license: GPLv2, see LICENSE for details.
"""
import h5py as h5
import numpy as np

from ptypy.utils.verbose import log
from ptypy.experiment import register
from .hdf5_loader import Hdf5Loader, Hdf5LoaderFast


class _Epsic:
"""
Defaults:
[rotation]
default = 0
type = float
help = Rotation of the scanning coordinate system
around the optical access, given in degrees
[stepsize]
default = 0
type = float
help = Step size of raster scan, given in meters
[numpos]
default = 256
type = int
help = Nr. of positions in raster scan along each direction
"""
def _params_check(self):
"""
raise error if essential parameters mising
"""
if None in [self.p.intensities.file,
self.p.intensities.key,
self.p.rotation,
self.p.stepsize,
self.p.numpos]:
raise RuntimeError("Missing some information about either the positions (rotation, stepsize, numpos) or the intensity mapping!")

def _prepare_intensity_and_positions(self):
"""
Prep for loading intensity and position data
"""
self.fhandle_intensities = h5.File(self.p.intensities.file, 'r')
self.intensities = self.fhandle_intensities[self.p.intensities.key]
self.intensities_dtype = self.intensities.dtype
self.data_shape = self.intensities.shape
if self._is_spectro_scan and self.p.outer_index is not None:
self.data_shape = tuple(np.array(self.data_shape)[1:])

pos = self._calculate_scan_positions()
self.fast_axis = pos[1]
self.positions_fast_shape = self.fast_axis.shape
self.slow_axis = pos[0]
self.positions_slow_shape = self.slow_axis.shape

log(3, "The shape of the \n\tdiffraction intensities is: {}\n\tslow axis data:{}\n\tfast axis data:{}".format(self.data_shape,
self.positions_slow_shape,
self.positions_fast_shape))
if self.p.positions.skip > 1:
log(3, "Skipping every {:d} positions".format(self.p.positions.skip))


def _calculate_scan_positions(self):
"""
Calculate theoretical scan possitons for
scanning at ePSIC instrument.
Returns
-------
pos : ndarray
array of shape (2,N1,N2) where N1,N2 are the dimensions
along the slow and fast axis, respectively
"""
step = self.p.stepsize
N = self.p.numpos
beta = self.p.rotation
xx,yy = np.meshgrid((np.arange(N)-N//2)*step, (np.arange(N)-N//2)*step)
rot = beta * np.pi / 180.
R0 = np.matrix([[np.cos(rot), -1 * np.sin(rot)], [np.sin(rot), np.cos(rot)]])
pos = -np.einsum('ji, mni -> jmn', R0, np.dstack([yy, xx]))
return pos


@register()
class EpsicHdf5Loader(_Epsic, Hdf5Loader):
pass

@register()
class EpsicHdf5LoaderFast(_Epsic, Hdf5LoaderFast):
pass

0 comments on commit 8052ecf

Please sign in to comment.