Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
miniforge-version: latest
- name: Install ${{ matrix.conda-env }} dependencies
run: |
sed -i 's/python/python=${{ matrix.python-version }}/' dependencies_${{ matrix.conda-env }}.yml
sed -i '/- python/d' dependencies_${{ matrix.conda-env }}.yml
conda install -c conda-forge mpich
conda env update --file dependencies_${{ matrix.conda-env }}.yml --name ptypy_env
conda install -c conda-forge flake8 pytest pytest-cov
Expand Down
2 changes: 1 addition & 1 deletion ptypy/core/illumination.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def init_storage(storage, pars, energy=None, **kwargs):
# Ok this is nearfield
curve = 1.0

model = pod.bw(curve * np.sqrt(alldiff))
model = pod.bw(curve * np.sqrt(alldiff).astype(np.complex128))
else:
raise ValueError(
prefix + 'Value to `model` key not understood in probe creation')
Expand Down
24 changes: 24 additions & 0 deletions ptypy/experiment/hdf5_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ class Hdf5Loader(PtyScan):
type = list, ndarray
help = This is the array or list with the re-ordered indices.

[nearfield_defocus]
default = None
type = float
help = Distance from sample to focus (for nearfield only)
doc = If set, magnification will be calculated automatically and applied to detector distance and pixelsize

"""

def __init__(self, pars=None, swmr=False, **kwargs):
Expand Down Expand Up @@ -378,6 +384,10 @@ def __init__(self, pars=None, swmr=False, **kwargs):
if self.p.electron_data:
self.meta.energy = u.m2keV(u.electron_wavelength(self.meta.energy))

# For nearfield data, manipulate distance and psize
if self.p.nearfield_defocus:
self._prepare_nearfield()

# it's much better to have this logic here than in load!
if (self._ismapped and (self._scantype == 'arb')):
log(3, "This scan looks to be a mapped arbitrary trajectory scan.")
Expand Down Expand Up @@ -590,6 +600,20 @@ def _prepare_meta_info(self):
assert self.pad.size == 4, "self.p.padding needs to of size 4"
log(3, "Padding the detector frames by {}".format(self.p.padding))

def _prepare_nearfield(self):
"""
Calculate magnification and modify distance and psize
"""
defocus = self.p.nearfield_defocus
mag = self.meta.distance / defocus
dist_eff = (self.meta.distance - defocus) / mag
psize_eff = self.info.psize / mag
log(3, f"Nearfield: With defocus {defocus} m the magmification is {mag}")
log(3, f"Nearfield: The effective detector distance is {dist_eff}")
log(3, f"Nearfield: The effective pixel size is {psize_eff}")
self.meta.distance = dist_eff
self.info.psize = psize_eff

def _prepare_center(self):
"""
define how data should be loaded (center, cropping)
Expand Down
6 changes: 3 additions & 3 deletions ptypy/utils/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,15 +621,15 @@ def stxm_analysis(storage, probe=None):
pod = list(v.pods.values())[0]
if not pod.active:
continue
t = pod.diff.sum()
t = (pod.diff * pod.mask).sum()
if t > t2:
t2=t
ss = v.slice
# ss = (v.layer,
# slice(v.roi[0,0], v.roi[1,0]),
# slice(v.roi[0,1], v.roi[1,1]))
# bufview = buf[ss]
m = mass_center(pod.diff) # + 1.
m = mass_center(pod.diff * pod.mask) # + 1.
q = pod.di_view.storage._to_phys(m)
dpc_row[ss] += q[0] * v.psize[0] * pr * 2 * np.pi / pod.geometry.lz
dpc_col[ss] += q[1] * v.psize[1] * pr * 2 * np.pi / pod.geometry.lz
Expand Down Expand Up @@ -723,7 +723,7 @@ def phase_from_dpc(dpc_row, dpc_col):

"""
py =- dpc_row
px =- dpc_col
px =+ dpc_col
sh = px.shape
sh = np.asarray(sh)
fac = np.ones_like(sh)
Expand Down
Loading