Commit 834dc296 authored by Matthijs's avatar Matthijs
Browse files

work towards a completely working 3d phase retrieval algorithm

parent 48b89094
......@@ -11,6 +11,10 @@ def data_processor(config):
inp = imread(config['data_filename'])
# Load measurement sensitivity, determine data_zeros
sensitivity = imread(config['sensitivity_filename'])
if 'crop data' in config:
cy, cx, cz = config['crop data']
inp = inp[cy:-1 - cy, cx:-1 - cx, cz:-1 - cz]
sensitivity = sensitivity[cy:-1 - cy, cx:-1 - cx, cz:-1 - cz]
# Add the negative K_z part to determine a real-valued orbital?
if 'add_negative_kz' in config and config['add_negative_kz']:
if 'kz_dimension' not in config:
......@@ -39,13 +43,15 @@ def data_processor(config):
assert config['data_zeros'].shape == config['data'].shape, 'Non-matching sensitivity and data arrays'
# Calculate electric field
# Calculate electric field amplitude
if 'from intensity data' in config and config['from intensity data']:
# avoid sqrt of negative numbers (due to background subtraction)
config['data'] = np.where(config['data'] > 0,
np.sqrt(abs(config['data'])),
np.zeros_like(config['data']))
# Calculate the norm of the data, estimating a correction for the lack of data given by data_zeros
config['norm_data'] = np.sqrt(np.sum(config['data'] ** 2))
config["norm_data"] /= np.mean((1 - config['data_zeros']))
# Object support determination
if config['constraint'] in ['support only', 'real and support', 'nonnegative and support']:
......@@ -66,7 +72,7 @@ def data_processor(config):
config['threshold for support'] = 0.1
config['sparsity_support'] = support_from_autocorrelation(config['data'],
threshold=config['threshold for support'],
binary_dilate_support=1)
binary_dilate_support=5)
# Initial guess
ph_init = 2 * np.pi * np.random.random_sample(config['data'].shape)
......@@ -83,6 +89,7 @@ def data_processor(config):
config['support viewer'] = support_viewer # the reference keeps the matplotlib object alive
if 'fourier_shift_arrays' in config and config['fourier_shift_arrays']:
print('Fourier shifting the arrays')
for key in ['u_0', 'support', 'sparsity_support', 'data', 'data_zeros']:
if key in config:
config[key] = np.fft.fftshift(config[key])
......
......@@ -13,7 +13,8 @@ new_config = {
'from intensity data': False, # File gives field amplitudes
'sensitivity_filename': 'pentacene_3d_arpes_sensitivity.tif',
'add_negative_kz': False,
'kz_dimension': 0, # integer indicating the kz-axis
'kz_dimension': 0, # integer indicating the kz-axis
'crop data': (0, 20, 20),
# What type of object are we working with?
# Options are: 'phase', 'real', 'nonnegative', 'complex'
......
......@@ -69,7 +69,7 @@ class P_M_masked(P_M):
-------
array_like - p_M: the projection IN THE PHYSICAL (time) DOMAIN
"""
fourier_space_iterate = np.fft.fft2(u, axes=None)
constrained = magproj(fourier_space_iterate, self.M)
fourier_space_iterate = np.fft.fftn(u, axes=None)
constrained = magproj(fourier_space_iterate.copy(), self.M)
update = np.where(self.mask, fourier_space_iterate, constrained)
return np.fft.ifft2(update, axes=None)
return np.fft.ifftn(update, axes=None)
......@@ -143,7 +143,7 @@ class P_Sparsity_Line(P_Sparsity):
def dim_proj(arr):
return np.sqrt(np.sum(abs(arr) ** 2, axis=config['unconstrained dimension']))
else: # default to linear
else: # default to linear
def dim_proj(arr):
return np.sum(arr, axis=config['unconstrained dimension'])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment