Skip to content

Commit 4b65177

Browse files
cleaned up initial params and added h5export
1 parent e04feb9 commit 4b65177

5 files changed

Lines changed: 133 additions & 10 deletions

File tree

‎@ptyLab/h5exportRaw.m‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function h5exportRaw(obj, file_name)
2+
3+
hdf5write(file_name, ...
4+
'/ptychogram', obj.ptychogram,...
5+
'/encoder', obj.positions0*obj.dxo,...
6+
'/dxd', obj.dxd,...
7+
'/zo', obj.zo,...
8+
'/wavelength', 2.48e-9);
9+
10+
end

‎@ptyLab/initialParams.m‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
p.addParameter('absObjectSwitch', false) % impose object being real and positiv
77
p.addParameter('absObjectStepSize', 0.05) % step size for absObjectSwitch
88
p.addParameter('batchSize', 10) % fft-block size for parallel engines
9+
p.addParameter('backgroundModeSwitch',false) % contrains mode for background
910
p.addParameter('betaObject',0.25) % mPIE feedback parameter (object)
1011
p.addParameter('betaProbe',0.25) % mPIE feedback parameter (probe)
1112
p.addParameter('comStabilizationSwitch', true)% if true, the probe is centered
@@ -19,6 +20,7 @@
1920
p.addParameter('initialProbe','circ') % choose initial probe ('obes', 'rand')
2021
p.addParameter('intensityConstraint','standard') % ('standard', 'sigmoid')
2122
p.addParameter('makeGIF', false) % probe orthogonalization frequency
23+
p.addParameter('modulusEnforcedProbeSwitch', false) % activates MEP update
2224
p.addParameter('npsm',1) % number of probe state mixtures
2325
p.addParameter('nosm',1) % number of object state mixtures
2426
p.addParameter('numIterations',1) % number of iterations
@@ -27,7 +29,9 @@
2729
p.addParameter('orthogonalizationFrequency', 10) % probe orthogonalization frequency
2830
p.addParameter('positionOrder','random')% position order for sequential solvers ('sequential' or 'random')
2931
p.addParameter('probePowerCorrectionSwitch', true) % switch to indicate if probe power correction is applied
32+
p.addParameter('probeSmoothenessSwitch', false) % imposes probe smootheness
3033
p.addParameter('saveMemory', true) % if true, then the algorithm is run with low memory consumption (e.g. detector error is not saved)
34+
p.addParameter('showObjectSpectrum',false) % show Fourier transform of object
3135
p.addParameter('singleSwitch', true) % if true, data is converted to single to save memory and processing time
3236
p.addParameter('smoothenessSwitch', false) % if true, apply smoothness constraint to object
3337
p.addParameter('objectTVregSwitch', false) % TV regularization
@@ -46,17 +50,21 @@
4650
% algorithmic parameters
4751
obj.params.absorbingProbeBoundary = p.Results.absorbingProbeBoundary;
4852
obj.params.absObjectSwitch = p.Results.absObjectSwitch;
49-
obj.params.positionOrder = p.Results.positionOrder;
53+
obj.params.backgroundModeSwitch = p.Results.backgroundModeSwitch;
54+
obj.params.batchSize = p.Results.batchSize;
55+
obj.params.comStabilizationSwitch = p.Results.comStabilizationSwitch;
56+
obj.params.gpuSwitch = p.Results.gpuSwitch;
5057
obj.params.intensityConstraint = p.Results.intensityConstraint;
58+
obj.params.modulusEnforcedProbeSwitch = p.Results.modulusEnforcedProbeSwitch;
59+
obj.params.positionOrder = p.Results.positionOrder;
5160
obj.params.probePowerCorrectionSwitch = p.Results.probePowerCorrectionSwitch;
61+
obj.params.probeSmoothenessSwitch = p.Results.probeSmoothenessSwitch;
5262
obj.params.smoothenessSwitch = p.Results.smoothenessSwitch;
53-
obj.params.comStabilizationSwitch = p.Results.comStabilizationSwitch;
54-
obj.params.gpuSwitch = p.Results.gpuSwitch;
5563
obj.params.saveMemory = p.Results.saveMemory;
64+
obj.params.objectTVregSwitch = p.Results.objectTVregSwitch;
5665
obj.params.orthogonalizationFrequency = p.Results.orthogonalizationFrequency;
57-
obj.params.batchSize = p.Results.batchSize;
5866
obj.params.zPIEgradientStepSize = p.Results.zPIEgradientStepSize;
59-
obj.params.objectTVregSwitch = p.Results.objectTVregSwitch;
67+
6068
% general parameters
6169
obj.params.npsm = p.Results.npsm;
6270
obj.params.nosm = p.Results.nosm;
@@ -65,6 +73,9 @@
6573
obj.params.deleteFrames = p.Results.deleteFrames;
6674
obj.params.FourierMaskSwitch = p.Results.FourierMaskSwitch;
6775

76+
% monitoring
77+
obj.monitor.showObjectSpectrum = p.Results.showObjectSpectrum;
78+
6879
% reconstruction
6980
obj.params.numIterations = p.Results.numIterations;
7081
obj.params.figureUpdateFrequency = p.Results.figureUpdateFrequency;

‎@ptyLab/showPtychogram.m‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@ function showPtychogram(obj, varargin)
77

88
if isfield(obj.params, 'fftshiftSwitch')
99
if obj.params.fftshiftSwitch
10-
sliceViewer( fftshift(log10(obj.ptychogram + 1)), 'Colormap', cmap );
10+
sliceViewer( gather(fftshift(log10(obj.ptychogram + 1))), 'Colormap', cmap );
1111
else
12-
sliceViewer( log10(obj.ptychogram + 1), 'Colormap', cmap );
12+
sliceViewer( gather(log10(obj.ptychogram + 1)), 'Colormap', cmap );
1313
end
1414
else
15-
sliceViewer( log10(obj.ptychogram + 1), 'Colormap', cmap );
15+
sliceViewer( gather(log10(obj.ptychogram + 1)), 'Colormap', cmap );
1616
end
1717

1818
title('ptychogram')
19-
2019
screen_size = get(0,'screensize');
2120
h = gcf;
2221
h.Position(1:2) = round( min(screen_size(3:4)))/4*[1,1];
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
% preprocessing
2+
3+
clear
4+
restoredefaultpath
5+
tic
6+
7+
set(0,'DefaultFigureWindowStyle','normal')
8+
set(0, 'DefaultAxesFontSize', 18);
9+
set(0, 'DefaultFigureColor', 'w');
10+
set(0,'defaultAxesFontName', 'serif')
11+
12+
% add toolbox folders
13+
directory_info = dir();
14+
toolboxFolder = erase( directory_info(1).folder, 'tutorials\1_getting_started\1_preprocess_and_reconstruct');
15+
16+
%%
17+
cd(toolboxFolder);
18+
addpath(genpath(toolboxFolder))
19+
20+
obj = ptyLab;
21+
obj.export.exportPath = 'C:\Users\Lars Loetgering\Documents\ptyLabExport';
22+
% change this depending on computer used for preprocessing
23+
obj.export.filePath = 'C:\Users\Lars Loetgering\Documents\fracPtyRaw\ptyLab_data\ptyLab_helical_beam.h5';
24+
obj.export.fileName = 'recent'; % this can be defined and determines output file name
25+
obj.params.verboseLevel = 'low';
26+
27+
%% read hdf5 file
28+
29+
tic
30+
disp('read h5 file data')
31+
obj.ptychogram = single(h5read(obj.export.filePath,'/ptychogram'));
32+
obj.params.encoder = h5read(obj.export.filePath,'/encoder');
33+
obj.dxd = h5read(obj.export.filePath,'/dxd');
34+
obj.zo = h5read(obj.export.filePath,'/zo');
35+
obj.wavelength = h5read(obj.export.filePath,'/wavelength');
36+
obj.numFrames = size(obj.ptychogram,3);
37+
toc
38+
39+
%% sampling
40+
41+
% detector coordinates
42+
obj.Nd = size(obj.ptychogram, 1);
43+
obj.Ld = obj.Nd * obj.dxd;
44+
obj.xd = (-obj.Nd/2:obj.Nd/2-1) * obj.dxd;
45+
[obj.Xd, obj.Yd] = meshgrid(obj.xd); % 2D coordinates in detector plane
46+
47+
% object coordinates
48+
obj.dxo = obj.wavelength * obj.zo / obj.Ld; % Fraunhofer/Fresnel
49+
obj.No = 2^11;
50+
obj.Lo = obj.No * obj.dxo;
51+
obj.xo = (-obj.No/2:obj.No/2-1) * obj.dxo;
52+
[obj.Xo, obj.Yo] = meshgrid(obj.xo);
53+
54+
% probe coordinates
55+
obj.dxp = obj.dxo;
56+
obj.Np = obj.Nd;
57+
obj.Lp = obj.Np * obj.dxp;
58+
obj.xp = (-obj.Np/2:obj.Np/2-1)*obj.dxp;
59+
[obj.Xp, obj.Yp] = meshgrid(obj.xp);
60+
61+
%% convert positions
62+
63+
% convert positions into pixels
64+
obj.positions0 = round( (obj.params.encoder) / obj.dxo );
65+
% center within object grid
66+
obj.positions0 = obj.positions0 - floor(mean(obj.positions0, 1)) + obj.No/2 - round(obj.Np/2);
67+
% take only the frames needed (if numFrames smaller than the number of positions in the file)
68+
obj.positions0 = obj.positions0(1:obj.numFrames,:);
69+
70+
% show positions
71+
figure(3)
72+
plot(obj.positions0 (:,2), obj.positions0(:,1),'o-')
73+
axis equal,axis image
74+
set(gcf, 'color', 'w')
75+
76+
%% set entrance pupil diameter
77+
78+
obj.entrancePupilDiameter = obj.Lp/3; % rough beam size estimate
79+
obj.propagator.type = 'Fraunhofer';
80+
81+
%% save memory by converting to single precision
82+
% (saves roughly a factor of 1.5 to 2 in memory and reconstruction speed)
83+
84+
obj.params.singleSwitch = true;
85+
if obj.params.singleSwitch
86+
obj.convert2single;
87+
end
88+
89+
%% export data
90+
obj.export.format = 'mat';
91+
exportBool = true;
92+
if exportBool
93+
obj.export.exportID = [obj.export.fileName];
94+
obj.exportObj
95+
end
96+
obj.showPtychogram
97+
toc
98+

‎tutorials/1_getting_started/1_preprocess_and_reconstruct/preprocess.m‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
% add toolbox folders
1313
directory_info = dir();
1414
toolboxFolder = erase( directory_info(1).folder, 'tutorials\1_getting_started\1_preprocess_and_reconstruct');
15+
16+
%%
1517
cd(toolboxFolder);
1618
addpath(genpath(toolboxFolder))
1719

@@ -26,7 +28,7 @@
2628

2729
tic
2830
disp('read h5 file data')
29-
obj.ptychogram = h5read(obj.export.filePath,'/ptychogram');
31+
obj.ptychogram = single(h5read(obj.export.filePath,'/ptychogram'));
3032
obj.params.encoder = h5read(obj.export.filePath,'/encoder');
3133
obj.dxd = h5read(obj.export.filePath,'/dxd');
3234
obj.zo = h5read(obj.export.filePath,'/zo');
@@ -91,5 +93,8 @@
9193
obj.export.exportID = [obj.export.fileName];
9294
obj.exportObj
9395
end
96+
97+
%% show raw data
98+
obj.showPtychogram
9499
toc
95100

0 commit comments

Comments
 (0)