mirror of
https://github.com/c-sooyoung/fold_slice.git
synced 2026-09-17 19:39:08 +09:00
initial commit
This commit is contained in:
@@ -0,0 +1,348 @@
|
||||
%% FP_PREALIGN prealign Fourier ptychographic data
|
||||
% [p] = FP_prealign(p)
|
||||
% FP_prealign is an alignment routine for Fourier ptychographic
|
||||
% measurements. Due to the changes in frequency content, a global
|
||||
% registration is not sufficient. We therefore sort the frames such that
|
||||
% images with similar frequency content can be aligned.
|
||||
%
|
||||
% ** p p structure
|
||||
%
|
||||
% *taken from p.prealign:*
|
||||
% ** ctr_sh shift the center before cropping the final dataset to asize
|
||||
% ** crop_dft crop the images by crop_dft before calculating the dftregistration
|
||||
% ** axis start the alignment procedure along specified axis or rotation (1 or 2)
|
||||
% ** numiter number of iterations
|
||||
% ** rad_filt_min discard positions below rad_filt_min
|
||||
% ** rad_filt_max discard positions beyond rad_filt_max
|
||||
% ** mfiles discard specific data points
|
||||
% ** flat_corr apply a flat-field correction
|
||||
% ** filt_align remove interpolation artifacts
|
||||
% ** save_alignment save final shifts / alignment
|
||||
% ** load_alignment overwrite alignment with previous alignment
|
||||
% ** alignment_file specify path+file
|
||||
% ** plot alignment turn on/off plotting during the alignment
|
||||
%
|
||||
% returns:
|
||||
% ++ p p structure
|
||||
%
|
||||
% see also: <base> utils.dftregistration
|
||||
%
|
||||
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function [p] = FP_prealign(p)
|
||||
|
||||
import utils.*
|
||||
|
||||
%% initial checks
|
||||
|
||||
par = p.prealign;
|
||||
|
||||
% parse inputs
|
||||
check_input = @(x) islogical(x) || isnumeric(x);
|
||||
parse_par = inputParser;
|
||||
parse_par.KeepUnmatched = true;
|
||||
|
||||
parse_par.addParameter('ctr_sh', [0 0], @isnumeric)
|
||||
parse_par.addParameter('crop_dft', 1, @isnumeric)
|
||||
parse_par.addParameter('axis', 1, @isnumeric)
|
||||
parse_par.addParameter('numiter', 3, @isnumeric)
|
||||
parse_par.addParameter('rad_filt_min', 0, @isnumeric)
|
||||
parse_par.addParameter('rad_filt_max',Inf, @isnumeric)
|
||||
parse_par.addParameter('mfiles', [], @isnumeric)
|
||||
parse_par.addParameter('save_alignment', false, check_input)
|
||||
parse_par.addParameter('load_alignment', false, check_input)
|
||||
parse_par.addParameter('plot_alignment', false, check_input)
|
||||
parse_par.addParameter('sort_pos_radii', false, check_input)
|
||||
parse_par.addParameter('mag_est', [], @isnumeric)
|
||||
|
||||
parse_par.parse(par);
|
||||
par = utils.update_param(par, parse_par.Results);
|
||||
|
||||
if isempty(par.mag_est)
|
||||
warning('The magnification was not specified. I will assume mag_est=100.')
|
||||
par.mag_est = 100;
|
||||
end
|
||||
|
||||
%% load data and optimize position arangement
|
||||
|
||||
detStorage = p.detectors(p.scanID).detStorage;
|
||||
detParams = p.detectors(p.scanID).params;
|
||||
|
||||
if p.scanID==1
|
||||
if ~isfield(detParams, 'detposmotor')
|
||||
error('Please specify the detector motor (det.detposmotor) in your detector template.')
|
||||
end
|
||||
p.positions_real = p.positions_orig;
|
||||
p.det_pos = p.positions_real(p.scanidxs{p.scanID},:);
|
||||
if (~isempty(p.spec.motor.coarse_motors))
|
||||
% adjust the positions in case of coarse stage movements
|
||||
coarse_pos = [];
|
||||
for ii = 1:length(p.scan_number)
|
||||
coarse_pos = [coarse_pos; [p.meta{ii}.spec.(p.spec.motor.coarse_motors{2}).*1e-3 p.meta{ii}.spec.(p.spec.motor.coarse_motors{1}).*1e-3]];
|
||||
end
|
||||
coarse_cen = [(max(coarse_pos(:,1)) - min(coarse_pos(:,1)))./2 (max(coarse_pos(:,2))-min(coarse_pos(:,2)))./2];
|
||||
for ii = 1:length(p.scan_number)
|
||||
p.positions_real(p.scanidxs{ii},1) = p.positions_real(p.scanidxs{ii},1)+p.meta{ii}.spec.(p.coarsey)*1e-3-min(coarse_pos(:,1))-coarse_cen(1);
|
||||
p.positions_real(p.scanidxs{ii},2) = p.positions_real(p.scanidxs{ii},2)+p.meta{ii}.spec.(p.coarsex)*1e-3-min(coarse_pos(:,2))-coarse_cen(2);
|
||||
p.det_pos(p.scanidxs{ii},1) = p.meta{ii}.spec.hy;
|
||||
p.det_pos(p.scanidxs{ii},2) = p.meta{ii}.spec.hx;
|
||||
end
|
||||
p.coarsex = [];
|
||||
p.coarsey = [];
|
||||
else
|
||||
% load the detector positions
|
||||
for ii=1:length(p.scan_number)
|
||||
p.det_pos(p.scanidxs{ii},1) = p.meta{ii}.spec.(detParams.detposmotor{1});
|
||||
p.det_pos(p.scanidxs{ii},2) = p.meta{ii}.spec.(detParams.detposmotor{2});
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
par.det_pos = p.det_pos(p.scanidxs{p.scanID},:);
|
||||
pos = p.positions_real(p.scanidxs{p.scanID},:);
|
||||
|
||||
|
||||
data = detStorage.data;
|
||||
|
||||
% remove unwanted files
|
||||
if ~isempty(par.mfiles)
|
||||
pos(par.mfiles,:) = [];
|
||||
data(:,:,par.mfiles) = [];
|
||||
end
|
||||
|
||||
% remove files out of range
|
||||
indx = [];
|
||||
for ii=1:size(pos,1)
|
||||
if sqrt(pos(ii,1)^2 + pos(ii,2)^2)<par.rad_filt_min || sqrt(pos(ii,1)^2 + pos(ii,2)^2)>par.rad_filt_max %|| pos(ii,2)>35e-6
|
||||
indx = [indx ii];
|
||||
end
|
||||
end
|
||||
|
||||
pos(indx,:) = [];
|
||||
par.det_pos(indx,:) = [];
|
||||
data(:,:,indx) = [];
|
||||
% if p.scanID>1
|
||||
% p.positions_real(indx+sum(p.numpts(1:tmp.ii-1)),:) = [];
|
||||
% end
|
||||
|
||||
|
||||
par.pos = pos;
|
||||
par.pos_orig = pos;
|
||||
|
||||
%%% update p values with new positions %%%
|
||||
tmp_append_pos = p.positions_real([p.scanidxs{min(p.scanID+1, length(p.numpts)+1):end}],:);
|
||||
tmp_append_det = p.det_pos([p.scanidxs{min(p.scanID+1, length(p.numpts)+1):end}],:);
|
||||
|
||||
p.numpts(p.scanID) = size(par.pos,1);
|
||||
scanfirstindex = [1 cumsum(p.numpts)+1]; % First index for scan number
|
||||
for ii = 1:p.numscans
|
||||
p.scanindexrange(ii,:) = [scanfirstindex(ii) scanfirstindex(ii+1)-1];
|
||||
end
|
||||
for ii = 1:p.numscans
|
||||
p.scanidxs{ii} = p.scanindexrange(ii,1):p.scanindexrange(ii,2);
|
||||
end
|
||||
|
||||
|
||||
% adjust positions container
|
||||
|
||||
p.positions_real([p.scanidxs{p.scanID:end}],:) = [];
|
||||
p.positions_real(p.scanidxs{p.scanID},:) = par.pos;
|
||||
p.positions_real = [p.positions_real; tmp_append_pos];
|
||||
|
||||
p.det_pos([p.scanidxs{p.scanID:end}],:) = [];
|
||||
p.det_pos(p.scanidxs{p.scanID},:) = par.det_pos;
|
||||
p.det_pos = [p.det_pos; tmp_append_det];
|
||||
|
||||
|
||||
|
||||
|
||||
par.data = data;
|
||||
|
||||
|
||||
par.sz = size(par.data);
|
||||
|
||||
|
||||
|
||||
fft_mask = ones(par.asize);
|
||||
fft_mask(round(par.asize(1)/4)-5:round(par.asize(1)/4)+5,:) = 0;
|
||||
fft_mask(:,round(par.asize(2)/4)-5:round(par.asize(2)/4)+5) = 0;
|
||||
fft_mask(:,round(par.asize(2)*3/4)-5:round(par.asize(2)*3/4)+5) = 0;
|
||||
fft_mask(round(par.asize(1)*3/4)-5:round(par.asize(1)*3/4)+5,:) = 0;
|
||||
|
||||
if ~isempty(detParams.mask_saturated_value)
|
||||
par.data = (abs(ifft2(fftshift(fft_mask).*fft2(par.data.*(par.data<detParams.mask_saturated_value)))));
|
||||
else
|
||||
par.data = (abs(ifft2(fftshift(fft_mask).*fft2(par.data))));
|
||||
end
|
||||
|
||||
clear data;
|
||||
|
||||
par.orig_data = (abs(ifft2(fftshift(fft_mask).*fft2(par.data))));%par.data;
|
||||
|
||||
if par.prealign_data
|
||||
par.sum_shift_total = zeros(par.sz(3), 2);
|
||||
|
||||
for ii=1:par.numiter*length(par.type)
|
||||
par.iterii = ii;
|
||||
verbose(2, 'Iteration %d/%d', ii, par.numiter*length(par.type))
|
||||
|
||||
% sort positions
|
||||
verbose(3, 'Sorting positions.')
|
||||
sort_type = par.type{mod(ii+1,length(par.type))+1};
|
||||
par = core.FPM.sort_pos(par, sort_type);
|
||||
|
||||
verbose(4, 'Aligning data along sorted positions.')
|
||||
% align along sorted positions
|
||||
par = core.FPM.align_data(par);
|
||||
|
||||
fig30 = plotting.smart_figure(30);
|
||||
clf;
|
||||
set(groot,'CurrentFigure',fig30);
|
||||
imagesc(mean(par.data,3));
|
||||
colormap(bone(256))
|
||||
title(sprintf('Alignment after %d iteration(s)', ii))
|
||||
drawnow()
|
||||
|
||||
if ~mod(ii,length(par.type))
|
||||
if par.axis==1
|
||||
par.axis = 2;
|
||||
else
|
||||
par.axis = 1;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
if par.sort_pos_radii
|
||||
par = core.FPM.sort_pos_radii(par);
|
||||
end
|
||||
|
||||
|
||||
|
||||
% use distortion matrix or load alignment from disk
|
||||
|
||||
if par.save_alignment
|
||||
sum_shift_total = par.sum_shift_total;
|
||||
save(sprintf('alignment_S%05d.mat', p.scan_number(p.scanID)), 'sum_shift_total');
|
||||
end
|
||||
|
||||
if par.use_distortion_corr && isempty(par.distortion_corr)
|
||||
par.distortion_corr = core.FPM.distortion_matrix(p, par.sum_shift_total, par.det_pos, par.mag_est);
|
||||
elseif ischar(par.distortion_corr)
|
||||
f = io.load_ptycho_recons(par.distorion_corr);
|
||||
par.distortion_corr = f.p.prealign.distortion_corr;
|
||||
end
|
||||
|
||||
if par.use_distortion_corr
|
||||
p.prealign.distortion_corr = par.distortion_corr;
|
||||
pos = core.FPM.get_positions(par.distortion_corr, par.pos.*1e3);
|
||||
sum_shift_total = (pos - par.det_pos)./p.ds./1e3;
|
||||
elseif par.load_alignment
|
||||
if isempty(par.alignment_file) || ~exist(par.alignment_file, 'file')
|
||||
error('Could not load specified alignment file.')
|
||||
end
|
||||
f = load(par.alignment_file);
|
||||
sum_shift_total = f.sum_shift_total;
|
||||
else
|
||||
sum_shift_total = par.sum_shift_total;
|
||||
end
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%
|
||||
% apply shifts %
|
||||
%%%%%%%%%%%%%%%%
|
||||
|
||||
mask = zeros([size(detStorage.mask) p.numpts(p.scanID)]);
|
||||
utils.verbose(2, 'Applying shifts to image stack and mask.');
|
||||
for ii=1:p.numpts(p.scanID)
|
||||
data(:,:,ii) = ifftshift(utils.crop_pad(abs(utils.shiftpp2(par.orig_data(:,:,ii), sum_shift_total(ii,1), sum_shift_total(ii,2))), p.asize));
|
||||
mask(:,:,ii) = abs(utils.shiftpp2(detStorage.mask, round(sum_shift_total(ii,1)), round(sum_shift_total(ii,2))));
|
||||
end
|
||||
|
||||
|
||||
if utils.verbose > 2
|
||||
fig30 = plotting.smart_figure(30);
|
||||
clf;
|
||||
set(groot,'CurrentFigure',fig30);
|
||||
imagesc(fftshift(mean(data,3)));
|
||||
colormap(bone(256))
|
||||
title('Alignment')
|
||||
drawnow()
|
||||
end
|
||||
|
||||
detStorage.data = data;
|
||||
detStorage.mask = round(mask);
|
||||
|
||||
% if par.prealign_data
|
||||
p.positions_real(p.scanidxs{p.scanID},1) = p.positions_real(p.scanidxs{p.scanID},1);
|
||||
p.positions_real(p.scanidxs{p.scanID},2) = p.positions_real(p.scanidxs{p.scanID},2);
|
||||
% end
|
||||
|
||||
|
||||
if p.scanID==length(p.numpts)
|
||||
p = core.ptycho_adjust_positions(p);
|
||||
p = core.prepare_initial_guess(p);
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
%ALIGN_DATA align data along given path
|
||||
% par = align_data(par, varargin)
|
||||
%
|
||||
% align_data is a helper function of FP_prealign
|
||||
% It uses utils.dftregistration to achieve a subpixel alignment
|
||||
%
|
||||
% ** par FP_prealign structure
|
||||
%
|
||||
% returns:
|
||||
% ++ par updated FP_prealign structure
|
||||
%
|
||||
%
|
||||
% see also: core.FPM.FP_prealign
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
|
||||
function par = align_data(par, varargin)
|
||||
|
||||
%% start optimization
|
||||
crop_fct = 4;
|
||||
import utils.dftregistration
|
||||
import utils.shiftpp2
|
||||
import utils.progressbar
|
||||
|
||||
align_tic = tic;
|
||||
for ii=1:length(par.align_section)
|
||||
N = size(par.align_section{ii},1);
|
||||
par.shift_cal = zeros(N,2);
|
||||
par.shift_sum = zeros(N,2);
|
||||
if par.plot_alignment
|
||||
fig2 = plotting.smart_figure(2);
|
||||
clf;
|
||||
end
|
||||
|
||||
crop = par.crop_dft;
|
||||
data = par.data;
|
||||
alid = par.alid{ii};
|
||||
iterii = par.iterii;
|
||||
|
||||
data_fft = fft2(data(crop:end-crop,crop:end-crop,:));
|
||||
for jj = 1:size(alid,2)-1
|
||||
reg = dftregistration(data_fft(:,:,alid(jj)), data_fft(:,:,alid(jj+1)), 100*iterii);
|
||||
if abs(reg(3))>25 || abs(reg(4))>25
|
||||
fprintf('%d cropped registration %d and %d\n', jj, alid(jj), alid(jj+1))
|
||||
for rep_ii=1:20
|
||||
sh = [round(rand()*crop*crop_fct) round(rand()*crop*crop_fct)];
|
||||
reg = dftregistration(fft2(data(crop*crop_fct+sh(1):end-crop*crop_fct+sh(1),crop*crop_fct+sh(2):end-crop*crop_fct+sh(2),alid(jj))), fft2(data(crop*crop_fct+sh(1):end-crop*crop_fct+sh(1),crop*crop_fct+sh(2):end-crop*crop_fct+sh(2),alid(jj+1))), 100*iterii);
|
||||
if abs(reg(3))<20 && abs(reg(4))<20
|
||||
break;
|
||||
end
|
||||
reg = [0 0 0 0];
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
% plot alignment
|
||||
par.shift_cal(jj,:) = [reg(3) reg(4)];
|
||||
if par.plot_alignment
|
||||
shift = sum(par.shift_cal(par.align_section{ii}(1):jj,:),1);
|
||||
temp = par.data(crop:end-crop,crop:end-crop,par.alid{ii}(jj+1));
|
||||
set(groot,'CurrentFigure',fig2);
|
||||
imagesc(abs(shiftpp2(temp, -shift(1),-shift(2))));
|
||||
title(sprintf('Aligned frame %d', par.alid{ii}(jj)));
|
||||
% fprintf('shift: %f, %f\n', -shift(1),-shift(2))
|
||||
drawnow()
|
||||
end
|
||||
if utils.verbose >= 2
|
||||
progressbar(jj,N-1)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
utils.verbose(2, 'Mean shift: %0.3f px', mean(sqrt(sum(abs(par.shift_cal).^2,2))))
|
||||
utils.verbose(2, 'Max shift: %0.3f px', max(sqrt(sum(abs(par.shift_cal).^2,2))))
|
||||
|
||||
for jj = 1:size(par.alid{ii},2)-1
|
||||
shift = sum(par.shift_cal(par.align_section{ii}(1):jj,:),1);
|
||||
par.sum_shift_total(par.alid{ii}(jj+1),:) = par.sum_shift_total(par.alid{ii}(jj+1),:) - shift;
|
||||
par.data(:,:,par.alid{ii}(jj+1)) = abs(shiftpp2(par.data(:,:,par.alid{ii}(jj+1)), -shift(1), -shift(2)));
|
||||
% par.raw_data(:,:,par.alid{ii}(jj+1)) = abs(shiftpp2(par.raw_data(:,:,par.alid{ii}(jj+1)), -shift(1), -shift(2)));
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
align_time = toc(align_tic);
|
||||
utils.verbose(3, 'Elapsed time for alignment: %0.3f s.', align_time);
|
||||
|
||||
end
|
||||
@@ -0,0 +1,107 @@
|
||||
%DISTORTION_MATRIX
|
||||
% C = distortion_matrix(p, shift, det_pos, mag_est, varargin)
|
||||
% calculate the coefficients of distortion matrix of a Fourier
|
||||
% ptychographic setup
|
||||
%
|
||||
% ** p p structure
|
||||
% ** shift estimated shift
|
||||
% ** det_pos detector position
|
||||
% ** mag_est estimation of the magnification
|
||||
%
|
||||
% returns:
|
||||
% ++ C distortion matrix coefficients
|
||||
%
|
||||
% see also: core.FPM.FP_prealign
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function C = distortion_matrix(p, shift, det_pos, mag_est, varargin)
|
||||
import utils.verbose
|
||||
|
||||
pos = p.positions_real(p.scanidxs{p.scanID},:);
|
||||
|
||||
det_pos_aligned = det_pos + shift.*p.ds.*1e3;
|
||||
pos = pos.*1e3;
|
||||
|
||||
C0(8) = 0;
|
||||
C0(1) = mag_est;
|
||||
|
||||
err_fun = @(C)( mean( sqrt(abs(nansum(abs(det_pos_aligned - core.FPM.get_positions(C, pos)).^2,2)))));
|
||||
|
||||
opt.MaxFunEvals = 500000;
|
||||
if utils.verbose > 3
|
||||
opt.Display = 'final';
|
||||
end
|
||||
|
||||
[C, fval] = fminsearch( err_fun, C0, opt);
|
||||
|
||||
utils.verbose(2, ['Calc. correction: ', repmat('%3.5g ', 1,length(C))], C)
|
||||
utils.verbose(2, 'Mean error: %d', fval)
|
||||
|
||||
|
||||
if utils.verbose > 2
|
||||
pos_ret = core.FPM.get_positions(C, pos);
|
||||
|
||||
plotting.smart_figure(20)
|
||||
clf
|
||||
hold on
|
||||
plot(pos_ret(:,1), pos_ret(:,2), 'rx')
|
||||
plot(det_pos_aligned(:,1), det_pos_aligned(:,2), 'bx')
|
||||
axis equal tight
|
||||
hold off
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
%GET_POSITIONS
|
||||
% new_pos = get_positions(C, pos)
|
||||
% helper function for core.FPM.FP_prealign and core.FPM.distortion_matrix
|
||||
%
|
||||
% ** C distortion matrix coeffs
|
||||
% ** pos positions vector
|
||||
%
|
||||
% returns:
|
||||
% new_pos updated positions vector
|
||||
%
|
||||
% see also: core.FPM.distortion_matrix
|
||||
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function new_pos = get_positions(C, pos)
|
||||
|
||||
new_pos = (((C(1))*[1-C(4), (-C(2))/180*pi;(C(2)+C(3))/180*pi,1]*(pos' + (C([7,8]))*fliplr(pos)'))' + C([5,6]));
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,301 @@
|
||||
%SORT_POS sort positions
|
||||
% par = sort_pos(par, varargin)
|
||||
%
|
||||
% sort_pos is a helper function of FP_prealign
|
||||
% it minimizes the path length, similar to the travelling salesman problem,
|
||||
% albeit optimized for the peculiarities of a Fourier ptychographic scan
|
||||
%
|
||||
% ** par FP_prealign structure
|
||||
%
|
||||
% *optional*
|
||||
% ** sort_type 'raster', 'round' or 'raster_lim'
|
||||
%
|
||||
% returns:
|
||||
% ++ par updated FP_prealign structure
|
||||
%
|
||||
%
|
||||
% see also: core.FPM.FP_prealign
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function par = sort_pos(par, varargin)
|
||||
pos = par.pos;
|
||||
sel_axis = par.axis;
|
||||
|
||||
if nargin > 1
|
||||
sort_type = varargin{1};
|
||||
else
|
||||
sort_type = 'raster';
|
||||
end
|
||||
|
||||
if strcmp(sort_type, 'raster')
|
||||
|
||||
% first find highest and lowest measurements
|
||||
pos_min = min(pos(:,1));
|
||||
pos_max = max(pos(:,1));
|
||||
offset = 2e-6;
|
||||
stepsz = 10e-6;
|
||||
|
||||
% now select rows of with width of stepsz
|
||||
|
||||
stpindx = 0;
|
||||
offset = offset + stepsz;
|
||||
row = {};
|
||||
while true
|
||||
lb = pos_min-offset + stpindx*stepsz;
|
||||
tb = pos_min-offset + (stpindx+1)*stepsz;
|
||||
if pos_max-tb<stepsz
|
||||
tb = tb + stepsz;
|
||||
end
|
||||
if lb >= pos_max
|
||||
break;
|
||||
end
|
||||
row{stpindx+1} = [];
|
||||
for i=1:size(pos,1)
|
||||
|
||||
if (pos(i,sel_axis)>=lb) && (pos(i,sel_axis)<tb)
|
||||
row{stpindx+1} = [row{stpindx+1} i];
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
stpindx = stpindx + 1;
|
||||
|
||||
end
|
||||
|
||||
% get pos in correct order for alignment
|
||||
ascend=true;
|
||||
alid = [];
|
||||
if sel_axis==1
|
||||
axsort = 2;
|
||||
else
|
||||
axsort=1;
|
||||
end
|
||||
for i=1:size(row,2)
|
||||
if isempty(row{i})
|
||||
continue
|
||||
else
|
||||
if ascend
|
||||
direction = 'ascend';
|
||||
else
|
||||
direction = 'descend';
|
||||
end
|
||||
[~,I] = sort(pos(row{i}, axsort), direction);
|
||||
row_sel = row{i};
|
||||
alid = [alid row_sel(I)];
|
||||
ascend = ~ascend;
|
||||
end
|
||||
|
||||
end
|
||||
elseif strcmp(sort_type, 'round')
|
||||
clear alid;
|
||||
alid{1} = [];
|
||||
if sel_axis==1
|
||||
ascend = true;
|
||||
else
|
||||
ascend = false;
|
||||
end
|
||||
dr = 10e-6;
|
||||
radii = sqrt(par.pos(:,1).^2 + par.pos(:,2).^2);
|
||||
|
||||
rad_max = max(radii);
|
||||
rad_min = min(radii);
|
||||
|
||||
stepindx = 0;
|
||||
shell = {};
|
||||
last_run = false;
|
||||
% find positions in shell
|
||||
while true
|
||||
lb = rad_min + stepindx*dr;
|
||||
tb = rad_min + (stepindx+1)*dr;
|
||||
if rad_max-tb<dr
|
||||
tb = tb + dr;
|
||||
last_run = true;
|
||||
end
|
||||
|
||||
shell{stepindx+1} = [];
|
||||
for ii=1:size(par.pos,1)
|
||||
if radii(ii)>=lb && radii(ii)<tb
|
||||
shell{stepindx+1} = [shell{stepindx+1} ii];
|
||||
end
|
||||
end
|
||||
stepindx = stepindx + 1;
|
||||
if last_run
|
||||
break;
|
||||
end
|
||||
end
|
||||
|
||||
% get pos in correct order for alignment
|
||||
for shindx=1:size(shell,2)
|
||||
if isempty(shell{shindx})
|
||||
fprintf('Warning: Empty shell in path optimization!')
|
||||
continue
|
||||
else
|
||||
if ascend
|
||||
direction = 'ascend';
|
||||
else
|
||||
direction = 'descend';
|
||||
end
|
||||
[~,I] = sort(atan2(par.pos(shell{shindx},1),par.pos(shell{shindx},2)), direction);
|
||||
shell_sel = shell{shindx};
|
||||
alid{1} = [alid{1} shell_sel(I)];
|
||||
ascend = ~ascend;
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
par.align_section = [];
|
||||
par.align_section{1} = 1:par.sz(3)-1;
|
||||
par.align_section{1} = par.align_section{1}';
|
||||
|
||||
elseif strcmp(sort_type, 'raster_lim')
|
||||
|
||||
|
||||
clear alid;
|
||||
alid{1} = [];
|
||||
|
||||
% split positions into 4 subsections
|
||||
par.align_section{1} = find(par.pos(:,mod(sel_axis,2)+1)<-par.rad_filt_min);
|
||||
par.align_section{2} = find(par.pos(:,mod(sel_axis,2)+1)>par.rad_filt_min);
|
||||
par.align_section{3} = find(par.pos(:,mod(sel_axis+1,2)+1)<-par.rad_filt_min);
|
||||
par.align_section{4} = find(par.pos(:,mod(sel_axis+1,2)+1)>par.rad_filt_min);
|
||||
|
||||
offset = 2e-6;
|
||||
stepsz = 10e-6;
|
||||
|
||||
|
||||
|
||||
% now select rows of with width of stepsz
|
||||
for jj=1:length(par.align_section)
|
||||
|
||||
% first find highest and lowest measurements
|
||||
pos_min = min(pos(par.align_section{jj},sel_axis));
|
||||
pos_max = max(pos(par.align_section{jj},sel_axis));
|
||||
stpindx = 0;
|
||||
offset = offset + stepsz;
|
||||
row = {};
|
||||
last_run = false;
|
||||
while true
|
||||
lb = pos_min-offset + stpindx*stepsz;
|
||||
tb = pos_min-offset + (stpindx+1)*stepsz;
|
||||
if pos_max-tb<stepsz
|
||||
tb = tb + stepsz;
|
||||
last_run = true;
|
||||
end
|
||||
row{stpindx+1} = [];
|
||||
for ii=par.align_section{jj}'
|
||||
|
||||
if (pos(ii,sel_axis)>=lb) && (pos(ii,sel_axis)<tb)
|
||||
row{stpindx+1} = [row{stpindx+1} ii];
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
stpindx = stpindx + 1;
|
||||
|
||||
if last_run
|
||||
break;
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
% get pos in correct order for alignment
|
||||
ascend=true;
|
||||
alid{jj} = [];
|
||||
if sel_axis==1
|
||||
axsort = 2;
|
||||
else
|
||||
axsort=1;
|
||||
end
|
||||
for ii=1:size(row,2)
|
||||
if isempty(row{ii})
|
||||
continue
|
||||
else
|
||||
if ascend
|
||||
direction = 'ascend';
|
||||
else
|
||||
direction = 'descend';
|
||||
end
|
||||
[~,I] = sort(pos(row{ii}, axsort), direction);
|
||||
row_sel = row{ii};
|
||||
alid{jj} = [alid{jj} row_sel(I)];
|
||||
ascend = ~ascend;
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if par.plot_alignment
|
||||
fig1 = plotting.smart_figure(1);
|
||||
clf;
|
||||
hold on
|
||||
plot(pos(:,1), pos(:,2))
|
||||
title('Alignment')
|
||||
colors = jet(length(par.align_section));
|
||||
for jj=1:length(par.align_section)
|
||||
for ii=1:size(alid{jj},2)-1
|
||||
set(groot,'CurrentFigure',fig1);
|
||||
plot(pos(alid{jj}(ii),1), pos(alid{jj}(ii),2), 'Color', colors(jj,:), 'Marker', 'x')
|
||||
pause(0.01)
|
||||
end
|
||||
end
|
||||
hold off
|
||||
end
|
||||
par.alid = [];
|
||||
par.alid = alid;
|
||||
|
||||
end
|
||||
@@ -0,0 +1,87 @@
|
||||
%SORT_POS_RADII sort positions along their radial distance
|
||||
% par = sort_pos_radii(par, varargin)
|
||||
%
|
||||
% sort_pos_radii is a helper function of FP_prealign
|
||||
%
|
||||
% ** par final structure of FP_prealign
|
||||
%
|
||||
% returns:
|
||||
% ++ par updated FP_prealign structure
|
||||
%
|
||||
% see also: core.FPM.FP_prealign
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function par = sort_pos_radii(par, varargin)
|
||||
pos = par.pos;
|
||||
radii = sqrt(pos(:,1).^2 + pos(:,2).^2);
|
||||
|
||||
[~, I] = sort(radii);
|
||||
orig_data_temp = par.orig_data;
|
||||
pos_temp = pos;
|
||||
shift_temp = par.sum_shift_total;
|
||||
det_pos_temp = par.det_pos;
|
||||
for ii=1:size(pos,1)
|
||||
orig_data_temp(:,:,ii) = par.orig_data(:,:,I(ii));
|
||||
pos_temp(ii,:) = pos(I(ii),:);
|
||||
shift_temp(ii,:) = par.sum_shift_total(I(ii),:);
|
||||
det_pos_temp(ii,:) = par.det_pos(I(ii),:);
|
||||
end
|
||||
par.pos = pos_temp;
|
||||
par.sum_shift_total = shift_temp;
|
||||
par.orig_data = orig_data_temp;
|
||||
par.det_pos = det_pos_temp;
|
||||
|
||||
end
|
||||
@@ -0,0 +1,204 @@
|
||||
%ALIGNED_FSC_TEMPLATE
|
||||
% Script to align images and compute FSC
|
||||
%
|
||||
% References relevant to this code:
|
||||
% For using this FSC code with ptychography: J. Vila-Comamala, et al., "Characterization of high-resolution diffractive X-ray optics by ptychographic coherent diffractive imaging," Opt. Express 19, 21333-21344 (2011).
|
||||
% For subpixel alignment: M. Guizar-Sicairos, et al., "Efficient subpixel image registration algorithms," Opt. Lett. 33, 156 (2008).
|
||||
% For matching of phase ramp by approximate least squared error: M. Guizar-Sicairos, et al., "Phase tomography from x-ray coherent diffractive imaging projections," Opt. Express 19, 21345-21357 (2011).
|
||||
%
|
||||
|
||||
addpath ../base/
|
||||
% clear;
|
||||
% close all;
|
||||
params = struct;
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%% Reconstruction files %%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
openwithGUI = 1; % Use GUI for choosing files, otherwise specify parameters below
|
||||
scan1 = [89]; % Scan number of first image
|
||||
scan2 = [90]; % Scan number of second image
|
||||
sample_name = ''; % File prefix
|
||||
suffix = 'test_1_recons.h5'; % File suffix
|
||||
analysis_folder = '../../analysis/'; % /mnt/das-gpfs/work/p12345/analysis/ % /sls/X12SA/Data10/e12345/analysis/
|
||||
filenamewithpath1 = ['image1.tif']; % Give the full filename and path - Overrides the parameters above; Can be in .mat or any format supported by 'imread'
|
||||
filenamewithpath2 = ['image2.tif']; % Give the full filename and path - Overrides the parameters above; Can be in .mat or any format supported by 'imread'
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%% Alignment parameters %%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
params.verbose_level = 3; % adjust output level
|
||||
params.plotting = 2; % (3) show everything, (2) show aligned images + FSC, (1) show FSC, (0) none
|
||||
params.remove_ramp = 1; % Try to remove ramp from whole image before initial alignment
|
||||
params.image_prop = 'phasor'; % = 'complex' or = 'phasor' (phase with unit amplitude) or = 'phase' (Note: phase should not be used if there is phase wrapping)
|
||||
params.crop = 'manual';
|
||||
% '' for using the default half size of the probe
|
||||
% 'manual' for using GUI to select region. This will display the range, e.g. {600:800, 600:800}
|
||||
% {600:800, 600:800} for custom vertical and horizontal cropping, respectively
|
||||
params.flipped_images = 0; % If images are taken with a horizontal flip, e.g. 0 & 180 for tomography
|
||||
params.GUIguess = 0; % To click for an initial alignment guess, ignores the values below
|
||||
params.guessx = []; % Some initial guess for x alignment
|
||||
params.guessy = [];
|
||||
%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%% FSC parameters %%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%
|
||||
params.taper = 20; % Pixels of image tapering (smoothing at edges) - Increase until the FSC does not change anymore
|
||||
params.SNRt = 0.5; % SNRt = 0.2071 for 1/2 bit threshold for resolution of the average of the 2 images
|
||||
% SNRt = 0.5 for 1 bit threshold for resolution of each individual image
|
||||
params.thickring = 10; % Thickness of Fourier domain ring for FSC in pixels
|
||||
params.freq_thr = 0.05; % (default 0.05) To ignore the crossings before freq_thr for determining resolution
|
||||
|
||||
|
||||
%%%%%%%%%%%%
|
||||
%%% misc %%%
|
||||
%%%%%%%%%%%%
|
||||
params.prop_obj = false; % propagation distance at the sample plane; leave empty to use the value from the reconstruction p structure; set to "false" for no propagation
|
||||
params.apod = []; % if true, applies an apodization before propagating by params.prop_obj, the apodization border is around the valid reconstruction region; leave empty to use the value from the reconstruction p structure
|
||||
params.lambda = []; % wavelength; needed for propagating the object; leave empty to use the value from the reconstruction p structure
|
||||
params.pixel_size = []; % pixel size at the object plane; leave empty to use the value from the reconstruction p structure
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%
|
||||
%%% FP parameter %%%
|
||||
%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
%%% the following parameters are ignored, unless p.fourier_ptycho==true %%%
|
||||
params.filter_FFT = true; % apply a circular mask to the reconstructed spectrum (needs p.plot_maskdim)
|
||||
params.crop_factor = 0.9; % crop final image by the given factor
|
||||
params.crop_asize = [800 800]; % crop object before applying the FFT
|
||||
params.z_lens = 49.456e-3; % FZP focal distance
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%% Do not modify below %%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
caller = dbstack;
|
||||
if length(caller)==1
|
||||
|
||||
addpath('utils')
|
||||
scanfolder1 = utils.compile_x12sa_dirname(scan1(1)); % Looks for the file in this folder, I leave a variable so that the folder can be overriden
|
||||
scanfolder2 = utils.compile_x12sa_dirname(scan2(1));
|
||||
%%% Opening file %%%
|
||||
if openwithGUI
|
||||
disp('Using GUI open mode')
|
||||
if exist([analysis_folder scanfolder1],'dir')
|
||||
uipath1 = [analysis_folder scanfolder1];
|
||||
else
|
||||
uipath1 = [];
|
||||
end
|
||||
if exist([analysis_folder scanfolder2],'dir')
|
||||
uipath2 = [analysis_folder scanfolder2];
|
||||
else
|
||||
uipath2 = [];
|
||||
end
|
||||
filetypes = {'*.h5;*.mat','Reconstruction files (*.h5,*.mat)'; '*.*', 'All Files (*.*)'};
|
||||
[filename, pathname] = uigetfile(filetypes,'Open first reconstruction', uipath1);
|
||||
file{1} = fullfile(pathname,filename);
|
||||
|
||||
[filename, pathname] = uigetfile(filetypes,'Open second reconstruction', uipath2);
|
||||
file{2} = fullfile(pathname,filename);
|
||||
else
|
||||
% Checking recons 1 %
|
||||
if ~isempty(filenamewithpath1)
|
||||
file{1} = filenamewithpath1;
|
||||
else
|
||||
file{1} = fullfile(analysis_folder,scanfolder1,[sample_name '*' suffix]);
|
||||
D = dir(file{1});
|
||||
if numel(D) == 0
|
||||
error(['I did not find any file: ' file{1}])
|
||||
elseif numel(D) > 1
|
||||
warning(['I found many files with the mask: ' file{1}]);
|
||||
warning(['I selected ' D(1).name]);
|
||||
end
|
||||
file{1} = fullfile(analysis_folder,scanfolder1,D(1).name);
|
||||
end
|
||||
|
||||
% Checking recons 2 %
|
||||
if ~isempty(filenamewithpath2)
|
||||
file{2} = filenamewithpath2;
|
||||
else
|
||||
file{2} = fullfile(analysis_folder,scanfolder2,[sample_name '*' suffix]);
|
||||
D = dir(file{2});
|
||||
if numel(D) == 0
|
||||
error(['I did not find any file: ' file{2}])
|
||||
elseif numel(D) > 1
|
||||
warning(['I found many files with the mask: ' file{2}]);
|
||||
warning(['I selected ' D(1).name]);
|
||||
end
|
||||
file{2} = fullfile(analysis_folder,scanfolder2,D(1).name);
|
||||
end
|
||||
end
|
||||
|
||||
% Making a JPEG of FSC
|
||||
[~,filename] = fileparts(file{1});
|
||||
params.out_fn = sprintf('%sonline/ptycho/%s_FSC.jpg', analysis_folder, filename);
|
||||
|
||||
[resolution] = aligned_FSC(file{1}, file{2}, params);
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the PtychoShelves
|
||||
% computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the PtychoShelves package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite
|
||||
% K. Wakonig, H.-C. Stadler, M. Odstrčil, E.H.R. Tsai, A. Diaz, M. Holler, I. Usov, J. Raabe, A. Menzel, M. Guizar-Sicairos, PtychoShelves, a versatile
|
||||
% high-level framework for high-performance analysis of ptychographic data, J. Appl. Cryst. 53(2) (2020). (doi: 10.1107/S1600576720001776)
|
||||
% and for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for LSQ-ML:
|
||||
% M. Odstrčil, A. Menzel, and M. Guizar-Sicairos, Iterative least-squares solver for generalized maximum-likelihood ptychography, Opt. Express 26(3), 3108 (2018).
|
||||
% (doi: 10.1364/OE.26.003108),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089),
|
||||
% and/or for OPRP:
|
||||
% M. Odstrcil, P. Baksh, S. A. Boden, R. Card, J. E. Chad, J. G. Frey, W. S. Brocklesby, Ptychographic coherent diffractive imaging with orthogonal probe relaxation.
|
||||
% Opt. Express 24.8 (8360-8369) 2016. (doi: 10.1364/OE.24.008360).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
@@ -0,0 +1,121 @@
|
||||
%CALC_FSC calculate the FRC for the reconstructed scans
|
||||
% ** p p structure
|
||||
%
|
||||
% returns:
|
||||
% ++ p updated p structure
|
||||
% ++ resolution FSC resolution
|
||||
%
|
||||
% see also: aligned_FSC
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function [p, resolution] = calc_FSC(p)
|
||||
|
||||
% get parameters from template
|
||||
run('aligned_FSC_template')
|
||||
|
||||
crop = round(p.object_size(1,:)*0.1);
|
||||
ob_good_range = {p.asize(1)/2+crop(1):p.object_size(1,1)-p.asize(1)/2-crop(1), p.asize(2)/2+crop(2):p.object_size(1,2)-p.asize(2)/2-crop(2)};
|
||||
|
||||
% store verbose level
|
||||
verbose_lvl = utils.verbose;
|
||||
% adjust structure
|
||||
params.plotting = (p.plot.show_FSC+max(utils.verbose-2, 0))*p.use_display;
|
||||
params.crop = ob_good_range;
|
||||
params.pixel_size = p.dx_spec;
|
||||
params.asize = p.asize;
|
||||
params.apod = p.plot.obj_apod;
|
||||
params.thickring = ceil(min(min(p.object_size-p.asize))/100); % 100 rings should be enough
|
||||
params.show_summary = utils.verbose > 2;
|
||||
|
||||
params.image_prop = 'variation'; %% seems to provide better alignement stability then the original phasor option
|
||||
utils.verbose(struct('prefix', {'analysis'}))
|
||||
utils.verbose(0, 'Calculating FSC ...')
|
||||
|
||||
|
||||
% if the original object is available, use it for comparison
|
||||
if isfield(p, 'simulation') && isfield(p.simulation, 'obj')
|
||||
params.fname{1} = 'Reconstruction';
|
||||
params.fname{2} = 'Model';
|
||||
obj{1} = prod(p.object{1}(:,:,1,:),4);
|
||||
obj{2} = prod(p.simulation.obj{1}(:,:,1,:),4);
|
||||
else
|
||||
params.fname{1} = sprintf('S%05u', p.scan_number(1));
|
||||
params.fname{2} = sprintf('S%05u', p.scan_number(2));
|
||||
for ii=1:p.numobjs
|
||||
obj{ii} = prod(p.object{ii}(:,:,1,:),4);
|
||||
end
|
||||
end
|
||||
|
||||
if verbose_lvl < 3
|
||||
params.verbose_level = 1;
|
||||
end
|
||||
|
||||
|
||||
% update params if needed
|
||||
if isfield(p, 'FSC')
|
||||
params = utils.update_param(params, p.FSC);
|
||||
end
|
||||
|
||||
resolution = aligned_FSC(obj{1}, obj{2}, params);
|
||||
|
||||
% restore verbose level
|
||||
utils.verbose(verbose_lvl);
|
||||
utils.verbose(struct('prefix', {'saving'}))
|
||||
|
||||
p.FSC.resolution = resolution;
|
||||
p.FSC.params = params;
|
||||
end
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
%PLOT_ERROR_METRIC plot evolution of the provided error metric
|
||||
% ** p p structure
|
||||
% ** final bool - indicates if it is final plot
|
||||
% ** use_display if false, do not open figures to plot the results
|
||||
%
|
||||
% *returns*
|
||||
% ++fig - image handle
|
||||
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
|
||||
function fig4 = plot_error_metric(p, final, use_display)
|
||||
|
||||
if ~use_display
|
||||
fig4 = plotting.smart_figure('Visible', 'off');
|
||||
else
|
||||
if p.plot.windowautopos && ~ishandle(4) && isfield(p.plot, 'scrsz') % position it only if the window does not exist
|
||||
fig4 = plotting.smart_figure(4);
|
||||
set(gcf,'Outerposition',[1 1 ceil(p.plot.scrsz(4)/p.plot.horz_fact) ceil(p.plot.scrsz(4)/2)]) %[left, bottom, width, height
|
||||
else
|
||||
fig4 = plotting.smart_figure(4);
|
||||
end
|
||||
|
||||
end
|
||||
% if p.numobjs==1; clf; end
|
||||
|
||||
Neng = length(p.engines);
|
||||
Nrows = 1+p.plot.positions;
|
||||
|
||||
|
||||
if final
|
||||
eng_id = 0;
|
||||
err_final = [];
|
||||
for ieng=1:Neng
|
||||
eng = p.engines{ieng};
|
||||
if ~isfield(eng, 'error_metric_final'); continue; end
|
||||
iieng = 1;
|
||||
if ~iscell(eng.error_metric_final)
|
||||
err_final(eng_id+1).iteration = eng.error_metric_final.iteration;
|
||||
err_final(eng_id+1).value = eng.error_metric_final.value;
|
||||
err_final(eng_id+1).method = eng.error_metric_final.method;
|
||||
err_final(eng_id+1).err_metric = eng.error_metric_final.err_metric;
|
||||
else
|
||||
for iieng=1:length(eng.error_metric_final)
|
||||
err_final(eng_id+iieng).iteration = eng.error_metric_final{iieng}.iteration;
|
||||
err_final(eng_id+iieng).value = eng.error_metric_final{iieng}.value;
|
||||
err_final(eng_id+iieng).method = eng.error_metric_final{iieng}.method;
|
||||
err_final(eng_id+iieng).err_metric = eng.error_metric_final{iieng}.err_metric;
|
||||
end
|
||||
end
|
||||
eng_id = eng_id + iieng;
|
||||
end
|
||||
|
||||
for ieng = 1:length(err_final)
|
||||
subplot(Nrows,length(err_final),ieng);
|
||||
cla()
|
||||
plot(err_final(ieng).iteration,err_final(ieng).value);
|
||||
if ~isvector(err_final(ieng).value) % error values for each position -> plot also average
|
||||
hold on
|
||||
plot(err_final(ieng).iteration, mean(err_final(ieng).value,2), '-k', 'LineWidth',2)
|
||||
hold off
|
||||
end
|
||||
title(err_final(ieng).method,'interpreter','none');
|
||||
legend(err_final(ieng).err_metric)
|
||||
grid on
|
||||
axis tight
|
||||
xlabel('Iteration')
|
||||
if p.plot.log_scale(1)
|
||||
set(gca, 'xscale', 'log')
|
||||
end
|
||||
if p.plot.log_scale(2)
|
||||
if all(err_final(ieng).value > 0); set(gca, 'yscale', 'log'); end
|
||||
end
|
||||
if ~isempty(err_final(ieng).iteration)
|
||||
xlim([0, err_final(ieng).iteration(end)])
|
||||
end
|
||||
end
|
||||
plotting.suptitle(replace(sprintf('error: %s %s', p.plot.errtitlestring, p.plot.extratitlestring),'_', '-'), ...
|
||||
'Interpreter', 'none');
|
||||
|
||||
|
||||
elseif isfield(p, 'error_metric') && ~isempty(p.error_metric)
|
||||
err = p.error_metric;
|
||||
if p.plot.positions
|
||||
subplot(2,1,1);
|
||||
end
|
||||
cla()
|
||||
if iscell(err)
|
||||
err = cell2mat(err);
|
||||
end
|
||||
if ~isempty(err(1).iteration)&&size(err,1)==2
|
||||
|
||||
try
|
||||
subplot(2,2,1);
|
||||
plot(err(1).iteration, err(1).value); grid on; title(sprintf('error\n'),'interpreter','none');
|
||||
if p.plot.log_scale(1)
|
||||
set(gca, 'xscale', 'log')
|
||||
end
|
||||
if p.plot.log_scale(2)
|
||||
if all(err > 0); set(gca, 'yscale', 'log'); end
|
||||
end
|
||||
subplot(2,2,2);
|
||||
plot(err(1).iteration(end)+err(2).iteration, log10(err(2).value),'r'); grid on
|
||||
if p.plot.log_scale(1)
|
||||
set(gca, 'xscale', 'log')
|
||||
end
|
||||
if p.plot.log_scale(2)
|
||||
if all(err > 0); set(gca, 'yscale', 'log'); end
|
||||
end
|
||||
catch
|
||||
end
|
||||
else
|
||||
|
||||
subplot(2,2,[1 2]);
|
||||
plot(err(1).iteration,err(1).value,'r'); grid on
|
||||
if p.plot.log_scale(1)
|
||||
set(gca, 'xscale', 'log')
|
||||
end
|
||||
if p.plot.log_scale(2)
|
||||
if all(err(1).value > 0); set(gca, 'yscale', 'log'); end
|
||||
end
|
||||
axis tight
|
||||
end
|
||||
|
||||
plotting.suptitle(sprintf('error: %s %s\n', p.plot.errtitlestring, p.plot.extratitlestring), 'Interpreter', 'none');
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
@@ -0,0 +1,127 @@
|
||||
%PLOT_OBJECT_SPECTRUM
|
||||
% plot fourier transformation of the reconstructed object
|
||||
%
|
||||
% ** p p structure
|
||||
% ** use_display if false, dont plot results on screen
|
||||
%
|
||||
% *returns*
|
||||
% ++fig - image handle
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
|
||||
|
||||
function fig6 = plot_object_spectrum(p, use_display)
|
||||
|
||||
count_plotobj = 1;
|
||||
|
||||
[objpix] = get_object_pixel_size(p);
|
||||
|
||||
for obnum = 1:p.numobjs
|
||||
for obmode = 1:p.object_modes
|
||||
|
||||
ob_plot = p.object{obnum}(:,:,obmode,:);
|
||||
ob_plot = prod(ob_plot,4); % make one eDoF image
|
||||
if ~p.fourier_ptycho
|
||||
ob_plot = fftshift(fft2(ob_plot));
|
||||
end
|
||||
|
||||
|
||||
absob = abs(ob_plot);
|
||||
|
||||
if ~use_display && count_plotobj == 1
|
||||
fig6 = plotting.smart_figure('Visible', 'off');
|
||||
else
|
||||
if count_plotobj == 1
|
||||
if p.plot.windowautopos && ~ishandle(6) % position it only if the window does not exist
|
||||
fig6 = plotting.smart_figure(6);
|
||||
set(gcf,'Outerposition',[ceil(p.plot.scrsz(4)*2/p.plot.horz_fact)+1 ceil(p.plot.scrsz(4)/2) ceil(p.plot.scrsz(4)/p.plot.horz_fact) ceil(p.plot.scrsz(4)/2)]) %[left, bottom, width, height
|
||||
else
|
||||
fig6 = plotting.smart_figure(6);
|
||||
end
|
||||
else
|
||||
set(groot,'CurrentFigure',fig6);
|
||||
end
|
||||
end
|
||||
|
||||
ax_abs(count_plotobj)=subplot(p.plot.subplwinobj(1),p.plot.subplwinobj(2),count_plotobj);
|
||||
|
||||
good_fov(1) = (p.object_size(obnum,1)/2 - p.asize(1)/2) .*p.dx_spec(1)*1e6;
|
||||
good_fov(2) = (p.object_size(obnum,2)/2 - p.asize(2)/2) .*p.dx_spec(2)*1e6;
|
||||
|
||||
if ~p.plot.realaxes
|
||||
imagesc(log10(absob));
|
||||
else
|
||||
obj_ax = {([1 p.object_size(obnum,2)]-floor(p.object_size(obnum,2)/2)+1)*objpix(2)*1e6,([1 p.object_size(obnum,1)]-floor(p.object_size(obnum,1)/2)+1)*objpix(1)*1e6};
|
||||
imagesc(obj_ax{:},log10(absob));
|
||||
xlabel('\mum')
|
||||
ylabel('\mum')
|
||||
end
|
||||
|
||||
colorbar
|
||||
axis image xy tight
|
||||
|
||||
if p.share_object
|
||||
title(sprintf('log10 object spectrum: %s %s', p.plot.obtitlestring, p.plot.extratitlestring),'interpreter','none');
|
||||
else
|
||||
title(sprintf('log10 object spectrum: %s %s', p.scan_str{obnum}, p.plot.extratitlestring),'interpreter','none');
|
||||
end
|
||||
|
||||
|
||||
count_plotobj = count_plotobj + 1;
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,350 @@
|
||||
%PLOT_OBJECTS plot reconstructed objects and layers
|
||||
% ** p p structure
|
||||
% ** use_display if false, dont plot results on screen
|
||||
% *returns*
|
||||
% ++fig - image handle
|
||||
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
|
||||
function [fig1, fig2] = plot_objects(p, use_display)
|
||||
|
||||
import math.*
|
||||
import utils.*
|
||||
|
||||
% prepare quadratic phase for FP backpropagation and calculate the pixel
|
||||
% size
|
||||
[objpix, FP_pre_phase_factor] = get_object_pixel_size(p);
|
||||
|
||||
% mask for backpropagation (FP only)
|
||||
if p.fourier_ptycho && p.plot.filt
|
||||
for ii=1:p.numobjs
|
||||
ob_mask{ii} = ifftshift(filt2d_pad(p.object_size(ii,:), round(p.plot.FP_maskdim/p.dx_spec(1)*1.2), round(p.plot.FP_maskdim/p.dx_spec(1)), 'circ'));
|
||||
end
|
||||
end
|
||||
|
||||
if length(unique(p.share_object_ID)) ~= length(p.object)
|
||||
% the GPU engine allows to modify the sharing within the engine and it
|
||||
% can cause inconsitencies during plotting
|
||||
utils.verbose(0,'Number of object does not correspond to the number of share_object_ID, resetting ... ')
|
||||
if length(p.object) == 1
|
||||
% assume shared scans
|
||||
p.share_object_ID(:) = 1;
|
||||
elseif length(p.object) == length(p.share_object_ID)
|
||||
% assume unshared scans
|
||||
p.share_object_ID(:) = 1:length(p.object);
|
||||
else
|
||||
error('Correct settings of the shared objects could not be determined')
|
||||
end
|
||||
end
|
||||
|
||||
count_plotobj = 1;
|
||||
|
||||
%modified by YJ for electron pty
|
||||
if isfield(p,'beam_source') && strcmp(p.beam_source, 'electron')
|
||||
unitFactor = 0.1;
|
||||
unitLabel = 'nm';
|
||||
else %X-ray
|
||||
unitFactor = 1e6;
|
||||
unitLabel = '\mum';
|
||||
end
|
||||
|
||||
for obmode = 1:p.object_modes
|
||||
for obnum = 1:p.numobjs
|
||||
|
||||
% number of layers for multilayer object reconstruction
|
||||
Nlayers = size(p.object{obnum},4);
|
||||
|
||||
% get the new object - 2D or 3D array
|
||||
ob_plot = p.object{obnum}(:,:,obmode,:);
|
||||
|
||||
% enforce update of the object_size
|
||||
object_size(obnum,:) = [size(ob_plot,1), size(ob_plot,2)];
|
||||
|
||||
% get the actual reconstructed area and calculate the corresponding
|
||||
% mask
|
||||
ob_good_range = {p.asize(1)/2:object_size(obnum,1)-p.asize(1)/2, p.asize(2)/2:object_size(obnum,2)-p.asize(2)/2};
|
||||
plot_mask = false(object_size(obnum,:));
|
||||
plot_mask(ob_good_range{:},:) = true;
|
||||
|
||||
|
||||
% remove phase offset and phase ramp (if requested)
|
||||
ob_plot = utils.stabilize_phase(ob_plot, 'weight', plot_mask, ...
|
||||
'remove_ramp', p.plot.remove_phase_ramp);
|
||||
|
||||
|
||||
if p.fourier_ptycho
|
||||
% propagate from lens plane to object plane
|
||||
ob_plot = ifft2(ifftshift(ob_plot.*ob_mask{obnum}))*p.object_size(obnum,1).*ifftshift(FP_pre_phase_factor{obnum});
|
||||
else
|
||||
|
||||
if p.plot.show_layers
|
||||
if ~p.plot.show_layers_stack
|
||||
% plot multiple layers next to each other
|
||||
ob_plot = reshape(ob_plot,object_size(obnum,1), object_size(obnum,2)* Nlayers);
|
||||
object_size(obnum,:) = size(ob_plot);
|
||||
plot_mask = repmat(plot_mask,1,Nlayers);
|
||||
else
|
||||
% 3D object for imagesc3D
|
||||
ob_plot = squeeze(ob_plot);
|
||||
end
|
||||
|
||||
else
|
||||
% plot single eDOF image
|
||||
ob_plot = prod(ob_plot,4); % show extended depth of focus images
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
% apply apodization
|
||||
if p.plot.obj_apod
|
||||
try
|
||||
filt_size = [size(ob_good_range{1},2) size(ob_good_range{2},2)];
|
||||
ob_plot_size = [size(ob_plot,1),size(ob_plot,2)];
|
||||
ob_plot = ob_plot.*fftshift(utils.filt2d_pad(ob_plot_size, max(1,filt_size), max(1,filt_size-min(floor(filt_size.*0.05)))));
|
||||
catch
|
||||
utils.verbose(2, 'Failed to apply apodization.')
|
||||
end
|
||||
end
|
||||
|
||||
% propagate object
|
||||
if p.plot.prop_obj ~= 0
|
||||
ob_plot = utils.prop_free_nf(ob_plot, p.lambda, p.plot.prop_obj, objpix);
|
||||
end
|
||||
|
||||
% get complex conjugate
|
||||
if p.plot.conjugate
|
||||
ob_plot = conj(ob_plot);
|
||||
end
|
||||
|
||||
|
||||
% precalculate absorption and phase
|
||||
absob = abs(ob_plot);
|
||||
phob = angle(ob_plot);
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%
|
||||
%%% AMPLITUDE %%%
|
||||
%%%%%%%%%%%%%%%%%
|
||||
|
||||
% prepare figure handle for absorption images
|
||||
if ~use_display && count_plotobj == 1
|
||||
fig1 = plotting.smart_figure('Visible', 'off');
|
||||
else
|
||||
if count_plotobj == 1
|
||||
if p.plot.windowautopos && ~ishandle(1) % position it only if the window does not exist
|
||||
fig1 = plotting.smart_figure(1);
|
||||
set(gcf,'Outerposition',[ceil(p.plot.scrsz(4)/p.plot.horz_fact)+1 ceil(p.plot.scrsz(4)/2) ceil(p.plot.scrsz(4)/p.plot.horz_fact) ceil(p.plot.scrsz(4)/2)]) %[left, bottom, width, height
|
||||
else
|
||||
fig1 = plotting.smart_figure(1);
|
||||
end
|
||||
clf;
|
||||
else
|
||||
set(groot,'CurrentFigure',fig1);
|
||||
end
|
||||
end
|
||||
|
||||
ax_abs(count_plotobj)=subplot(p.plot.subplwinobj(1),p.plot.subplwinobj(2),count_plotobj);
|
||||
|
||||
|
||||
range = [min(p.positions([p.scanidxs{p.share_object_ID == obnum}],:)), ...
|
||||
max(p.positions([p.scanidxs{p.share_object_ID == obnum}],:))];
|
||||
|
||||
% FOV [xmin, ymin, xmax, ymax]
|
||||
good_fov(1) = -(p.object_size(obnum,1)/2 - p.asize(1)/2-range(1));
|
||||
good_fov(2) = -(p.object_size(obnum,2)/2 - p.asize(2)/2-range(2));
|
||||
good_fov(3) = good_fov(1) + range(3)-range(1);
|
||||
good_fov(4) = good_fov(2) + range(4)-range(2);
|
||||
good_fov = good_fov.*p.dx_spec([1,2,1,2])*unitFactor;
|
||||
fov_box = [good_fov(2),good_fov(1),good_fov(4)-good_fov(2), good_fov(3)-good_fov(1)]; % [xmin, ymin, W, H] coordinates of the FOV box
|
||||
|
||||
% plot the absorption
|
||||
if ~p.plot.realaxes
|
||||
plotting.imagesc3D(absob);
|
||||
if p.plot.fov_box && ~(p.plot.show_layers && ~p.plot.show_layers_stack && Nlayers > 1)
|
||||
rectangle('Position',[p.asize([2,1])/2 , p.object_size([2,1]) - p.asize([2,1])], 'EdgeColor', p.plot.fov_box_color)
|
||||
end
|
||||
else
|
||||
obj_ax = {([1 object_size(obnum,2)]-floor(object_size(obnum,2)/2)+1)*objpix(2)*unitFactor,([1 object_size(obnum,1)]-floor(object_size(obnum,1)/2)+1)*objpix(1)*unitFactor};
|
||||
plotting.imagesc3D(obj_ax{:},absob);
|
||||
xlabel(unitLabel)
|
||||
ylabel(unitLabel)
|
||||
if p.plot.fov_box && p.plot.show_layers && ~p.plot.show_layers_stack && Nlayers > 1
|
||||
% plot bar around each layer
|
||||
for layer = 1:Nlayers
|
||||
rectangle('Position', [good_fov(2) + (layer-(Nlayers+1)/2)*p.object_size(obnum,2).*p.dx_spec(1)*unitFactor ,good_fov(1), good_fov(4)-good_fov(2),good_fov(3)-good_fov(1)], 'EdgeColor', p.plot.fov_box_color)
|
||||
end
|
||||
elseif p.plot.fov_box
|
||||
rectangle('Position',fov_box, 'EdgeColor', p.plot.fov_box_color)
|
||||
end
|
||||
end
|
||||
|
||||
% calculate a proper colorbar range
|
||||
try
|
||||
amp_range = sp_quantile(absob(plot_mask),[1e-4,1-1e-4], 10);
|
||||
catch
|
||||
keyboard
|
||||
end
|
||||
if amp_range(1) < amp_range(2)
|
||||
caxis(amp_range);
|
||||
end
|
||||
|
||||
colormap(bone(256)); colorbar
|
||||
axis image xy tight
|
||||
|
||||
if check_option(p, 'show_only_FOV') && p.plot.realaxes
|
||||
axis([good_fov(2) good_fov(4) good_fov(1) good_fov(3)])
|
||||
elseif check_option(p, 'show_only_FOV') && ~p.plot.realaxes
|
||||
axis([p.asize(2)/2, object_size(obnum,2) - p.asize(2)/2, p.asize(1)/2, object_size(obnum,1) - p.asize(1)/2, ])
|
||||
end
|
||||
|
||||
% prepare title strings
|
||||
if p.share_object
|
||||
title(sprintf('amplitude: %s %s', p.plot.obtitlestring, p.plot.extratitlestring),'interpreter','none');
|
||||
else
|
||||
title(sprintf('amplitude: %s %s', p.scan_str{obnum}, p.plot.extratitlestring),'interpreter','none');
|
||||
end
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%
|
||||
%%%%%% PHASE %%%%%%
|
||||
%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
% prepare figure handle for phase images
|
||||
if ~use_display && count_plotobj == 1
|
||||
fig2 = plotting.smart_figure('Visible', 'off');
|
||||
else
|
||||
if count_plotobj == 1
|
||||
if p.plot.windowautopos && ~ishandle(2) % position it only if the window does not exist
|
||||
fig2 = plotting.smart_figure(2);
|
||||
set(gcf,'Outerposition',[1 ceil(p.plot.scrsz(4)/2) ceil(p.plot.scrsz(4)/p.plot.horz_fact) ceil(p.plot.scrsz(4)/2)]) %[left, bottom, width, height
|
||||
else
|
||||
fig2 = plotting.smart_figure(2);
|
||||
end
|
||||
clf;
|
||||
else
|
||||
set(groot,'CurrentFigure',fig2);
|
||||
end
|
||||
end
|
||||
|
||||
if check_option(p.plot, 'residua') && ~check_option(p, 'fourier_ptycho')
|
||||
% find residua to plot and avoid plotting residua in not illuminated regions
|
||||
residues = plot_mask(2:end, 2:end) & (abs(utils.findresidues(ob_plot)) > 0.1);
|
||||
[residues_ind{1}, residues_ind{2}] = find(residues);
|
||||
end
|
||||
|
||||
|
||||
ax_phase(count_plotobj)=subplot(p.plot.subplwinobj(1),p.plot.subplwinobj(2),count_plotobj);
|
||||
|
||||
% plot the phase
|
||||
if ~p.plot.realaxes
|
||||
plotting.imagesc3D(phob);
|
||||
if p.plot.fov_box && ~(p.plot.show_layers && ~p.plot.show_layers_stack && Nlayers > 1)
|
||||
rectangle('Position',[p.asize([2,1])/2 , p.object_size([2,1]) - p.asize([2,1])], 'EdgeColor', p.plot.fov_box_color)
|
||||
end
|
||||
if check_option(p.plot, 'residua')
|
||||
hold all
|
||||
plot(residues_ind{[2,1]},'or')
|
||||
hold off
|
||||
end
|
||||
else
|
||||
plotting.imagesc3D(obj_ax{:},phob);
|
||||
xlabel(unitLabel)
|
||||
ylabel(unitLabel)
|
||||
if p.plot.fov_box && p.plot.show_layers && ~p.plot.show_layers_stack && Nlayers > 1
|
||||
% plot bar around each layer
|
||||
for layer = 1:Nlayers
|
||||
rectangle('Position', [good_fov(2) + (layer-(Nlayers+1)/2)*p.object_size(obnum,2).*p.dx_spec(1)*unitFactor ,good_fov(1), good_fov(4)-good_fov(2),good_fov(3)-good_fov(1)], 'EdgeColor', p.plot.fov_box_color)
|
||||
end
|
||||
elseif p.plot.fov_box
|
||||
rectangle('Position',fov_box, 'EdgeColor', p.plot.fov_box_color)
|
||||
end
|
||||
if check_option(p.plot, 'residua')
|
||||
hold all
|
||||
plot((residues_ind{2}-size(ob_plot,2)/2)*objpix(2)*unitFactor,(residues_ind{1}-size(ob_plot,1)/2)*objpix(1)*unitFactor,'or')
|
||||
hold off
|
||||
end
|
||||
end
|
||||
p_range = sp_quantile(phob(plot_mask),[1e-4,1-1e-4], 10);
|
||||
if p_range(1) < p_range(2)
|
||||
caxis(p_range);
|
||||
end
|
||||
|
||||
colormap(bone(256));colorbar
|
||||
if p.share_object
|
||||
title(sprintf('phase: %s %s', p.plot.obtitlestring, p.plot.extratitlestring),'interpreter','none');
|
||||
else
|
||||
title(sprintf('phase: %s %s', p.scan_str{obnum}, p.plot.extratitlestring),'interpreter','none');
|
||||
end
|
||||
axis image xy tight
|
||||
if check_option(p, 'show_only_FOV') && p.plot.realaxes
|
||||
axis([-good_fov(2) good_fov(2) -good_fov(1) good_fov(1)])
|
||||
elseif check_option(p, 'show_only_FOV') && ~p.plot.realaxes
|
||||
axis([p.asize(2)/2, object_size(obnum,2) - p.asize(2)/2, p.asize(1)/2, object_size(obnum,1) - p.asize(1)/2, ])
|
||||
end
|
||||
count_plotobj = count_plotobj + 1;
|
||||
end
|
||||
|
||||
if use_display
|
||||
% link axes in case of zooming
|
||||
try linkaxes([ax_abs, ax_phase], 'xy'); end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
% PLOT_POSITIONS
|
||||
% plot positions of the illumination with respect to the object
|
||||
%
|
||||
% ** p p structure
|
||||
%
|
||||
%
|
||||
%
|
||||
%
|
||||
|
||||
function plot_positions(p)
|
||||
|
||||
%modified by YJ for electron pty
|
||||
if isfield(p,'beam_source') && strcmp(p.beam_source, 'electron')
|
||||
unitFactor = 0.1;
|
||||
unitLabel = 'nm';
|
||||
else %X-ray
|
||||
unitFactor = 1e6;
|
||||
unitLabel = '\mum';
|
||||
end
|
||||
|
||||
% NOTE: the positions are appended to fig 4 (cf. plot_error_metric)
|
||||
numscans = length(p.scan_number);
|
||||
scanfirstindex = [1 cumsum(p.numpts)+1]; % First index for scan number
|
||||
for ii = 1:numscans
|
||||
p.scanidxs{ii} = scanfirstindex(ii):(scanfirstindex(ii+1)-1);
|
||||
end
|
||||
|
||||
subplot(2,2,[3 4]);
|
||||
for ii = 1:numscans
|
||||
idx = min(ii,p.numobjs);
|
||||
positions_centered(p.scanidxs{ii},:) = p.positions(p.scanidxs{ii},:) - p.object_size(idx,:)/2 + p.asize/2;
|
||||
end
|
||||
cla()
|
||||
if p.plot.realaxes
|
||||
scale = p.dx_spec*unitFactor;
|
||||
else
|
||||
% plot positions in pixels, useful for grazing incidence ptycho
|
||||
scale = [1,1];
|
||||
end
|
||||
hold all
|
||||
for ii = 1:numscans
|
||||
plot(positions_centered(p.scanidxs{ii},2).*scale(2), ...
|
||||
positions_centered(p.scanidxs{ii},1).*scale(1),...
|
||||
'x:','markersize',4);
|
||||
end
|
||||
|
||||
grid on;
|
||||
if numscans==1
|
||||
title('positions','interpreter','none');
|
||||
else
|
||||
title('positions (red 1st, blue 2nd)','interpreter','none');
|
||||
end
|
||||
if p.plot.realaxes
|
||||
xlabel(unitLabel);
|
||||
ylabel(unitLabel);
|
||||
else
|
||||
xlabel('pixels');
|
||||
ylabel('pixels');
|
||||
end
|
||||
axis tight equal;
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
%PLOT_PROBES plot reconstructed probes
|
||||
% ** p p structure
|
||||
% ** use_display if false, dont plot results on screen
|
||||
%
|
||||
% *returns*
|
||||
% fig - image handle
|
||||
|
||||
function fig3 = plot_probes(p, use_display)
|
||||
import utils.rmphaseramp
|
||||
import plotting.c2image
|
||||
|
||||
%modified by YJ for electron pty
|
||||
if isfield(p,'beam_source') && strcmp(p.beam_source, 'electron')
|
||||
unitFactor = 0.1;
|
||||
unitLabel = 'nm';
|
||||
else %X-ray
|
||||
unitFactor = 1e6;
|
||||
unitLabel = '\mum';
|
||||
end
|
||||
|
||||
count_plotprb = 1;
|
||||
for prmode = 1:p.probe_modes
|
||||
for prnum = 1:p.numprobs
|
||||
aux = p.probes(:,:,prnum,:);
|
||||
E = sum(abs(aux(:)).^2);
|
||||
if ~use_display && count_plotprb == 1
|
||||
fig3 = plotting.smart_figure('Visible', 'off');
|
||||
else
|
||||
if count_plotprb == 1
|
||||
if p.plot.windowautopos && ~ishandle(3) % position it only if the window does not exist
|
||||
fig3 = plotting.smart_figure(3);
|
||||
set(gcf,'Outerposition',[ceil(p.plot.scrsz(4)/p.plot.horz_fact) 1 ceil(p.plot.scrsz(4)/p.plot.horz_fact) ceil(p.plot.scrsz(4)/2)]) %[left, bottom, width, height
|
||||
else
|
||||
fig3 = plotting.smart_figure(3);
|
||||
end
|
||||
clf;
|
||||
else
|
||||
set(groot,'CurrentFigure',fig3);
|
||||
end
|
||||
end
|
||||
probe = p.probes(:,:,prnum,prmode);
|
||||
if p.plot.remove_phase_ramp
|
||||
probe = rmphaseramp(rmphaseramp(probe,'abs'),'abs');
|
||||
end
|
||||
|
||||
subplot(p.plot.subplwinprob(1),p.plot.subplwinprob(2),count_plotprb)
|
||||
if ~p.plot.realaxes
|
||||
imagesc(c2image(probe));
|
||||
else
|
||||
iaxis{1} = ([1 p.asize(2)]-floor(p.asize(2)/2)+1)*p.dx_spec(2)*unitFactor;
|
||||
iaxis{2} = ([1 p.asize(1)]-floor(p.asize(1)/2)+1)*p.dx_spec(1)*unitFactor;
|
||||
imagesc(iaxis{:},c2image(probe));
|
||||
xlabel(unitLabel)
|
||||
ylabel(unitLabel)
|
||||
end
|
||||
if p.share_probe
|
||||
titlestring = sprintf('probe: %s %s', p.plot.prtitlestring, p.plot.extratitlestring);
|
||||
else
|
||||
titlestring = sprintf('probe: %s %s',p.scan_str{prnum}, p.plot.extratitlestring);
|
||||
end
|
||||
if p.probe_modes > 1
|
||||
Ethis = sum(sum(abs(p.probes(:,:,prnum,prmode)).^2));
|
||||
Ethis = Ethis/E;
|
||||
titlestring = [titlestring sprintf(' %.1f%%',Ethis*100)];
|
||||
end
|
||||
title(titlestring,'interpreter','none');
|
||||
axis image xy tight
|
||||
|
||||
count_plotprb = count_plotprb + 1;
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,66 @@
|
||||
% PLOT_PROBES_AT_DETECTOR
|
||||
% plot reconstructed probes propagated to the detector
|
||||
%
|
||||
% ** p p structure
|
||||
% ** use_display if false, do now show plots
|
||||
%
|
||||
% *returns*
|
||||
% ++fig - image handle
|
||||
%
|
||||
%
|
||||
|
||||
function fig5 = plot_probes_at_detector(p, use_display)
|
||||
|
||||
count_plotprb = 1;
|
||||
for prmode = 1:p.probe_modes
|
||||
for prnum = 1:p.numprobs
|
||||
aux = p.probes(:,:,prnum,:);
|
||||
E = sum(abs(aux(:)).^2);
|
||||
if ~use_display && count_plotprb == 1
|
||||
fig5 = plotting.smart_figure('Visible', 'off');
|
||||
else
|
||||
if count_plotprb == 1
|
||||
if p.plot.windowautopos && ~ishandle(5) % position it only if the window does not exist
|
||||
fig5 = plotting.smart_figure(5);
|
||||
set(gcf,'Outerposition',[ceil(p.plot.scrsz(4)*2/p.plot.horz_fact) 1 ceil(p.plot.scrsz(4)/p.plot.horz_fact) ceil(p.plot.scrsz(4)/2)]) %[left, bottom, width, height
|
||||
else
|
||||
fig5 = plotting.smart_figure(5);
|
||||
end
|
||||
clf;
|
||||
else
|
||||
set(groot,'CurrentFigure',fig5);
|
||||
end
|
||||
end
|
||||
subplot(p.plot.subplwinprob(1),p.plot.subplwinprob(2),count_plotprb)
|
||||
af_probe = abs(fftshift(fft2(p.probes(:,:,prnum,prmode)))).^2;
|
||||
max_af_probe = max(af_probe(:));
|
||||
if isfield(p, 'renorm')
|
||||
af_probe = af_probe / single(p.renorm).^2;
|
||||
end
|
||||
if ~p.plot.realaxes
|
||||
imagesc(log10(1e-2*max_af_probe+af_probe));
|
||||
else
|
||||
imagesc(([1 p.asize(2)]-floor(p.asize(2)/2)+1)*p.ds*1e3,([1 p.asize(1)]-floor(p.asize(1)/2)+1)*p.ds*1e3,log10(1e-2*max_af_probe+af_probe));
|
||||
xlabel('mm')
|
||||
ylabel('mm')
|
||||
end
|
||||
if p.share_probe
|
||||
titlestring = sprintf('log10 FFT probe: %s %s', p.plot.prtitlestring, p.plot.extratitlestring);
|
||||
else
|
||||
titlestring = sprintf('log10 FFT probe: %s %s',p.scan_str{prnum}, p.plot.extratitlestring);
|
||||
end
|
||||
if p.probe_modes > 1
|
||||
Ethis = sum(sum(abs(p.probes(:,:,prnum,prmode)).^2));
|
||||
Ethis = Ethis/E;
|
||||
titlestring = [titlestring sprintf(' %.1f%%',Ethis*100)];
|
||||
end
|
||||
title(titlestring,'interpreter','none');
|
||||
axis image xy tight
|
||||
colormap(plotting.franzmap)
|
||||
colorbar
|
||||
count_plotprb = count_plotprb + 1;
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
%PLOT_RAW_DATA Simple plotting routine for masked raw data
|
||||
%
|
||||
% ** p p structure
|
||||
%
|
||||
% see also: core.initialize_ptycho
|
||||
function plot_raw_data(p)
|
||||
import utils.verbose
|
||||
|
||||
magnitude = p.fmag .* p.fmask;
|
||||
|
||||
max_intensity = (max(max(magnitude))/p.renorm).^2;
|
||||
|
||||
verbose(1, 'Plotting prepared data.')
|
||||
kk = 1;
|
||||
title_list = cell(1,size(p.fmag,3));
|
||||
for jj=1:p.numscans
|
||||
for ii = p.scanidxs{jj}
|
||||
title_list{kk} = sprintf('Scan S%0.5d - Point (%d) maximal intensity:%.4g',p.scan_number(jj), ii, max_intensity(kk));
|
||||
kk = kk +1 ;
|
||||
end
|
||||
end
|
||||
|
||||
% really enforce popup of this figure, it gets very annoying when running somewhere in background
|
||||
if ishandle(10)
|
||||
close(10);
|
||||
end
|
||||
fig = figure(10);
|
||||
|
||||
if ~p.fourier_ptycho
|
||||
plt_fnct = @(x)(log10(0.1+math.fftshift_2D(x / p.renorm).^2));
|
||||
else
|
||||
plt_fnct = @(x)((x / p.renorm).^2);
|
||||
end
|
||||
|
||||
plotting.imagesc3D(magnitude, 'title_list', title_list, 'fnct', plt_fnct);
|
||||
if ~p.fourier_ptycho
|
||||
caxis([-1, log10(max(max_intensity))])
|
||||
else
|
||||
caxis(math.sp_quantile((magnitude/p.renorm).^2, [1e-6 1-1e-6], 10))
|
||||
end
|
||||
|
||||
c = colorbar;
|
||||
ylabel(c, 'log10 counts')
|
||||
ax = fig.CurrentAxes;
|
||||
axis(ax, 'xy', 'equal', 'image')
|
||||
colormap(ax, 'plotting.franzmap')
|
||||
if p.plot.windowautopos
|
||||
horiz_fact = 2.5;
|
||||
if check_option(p.plot, 'object_spectrum')
|
||||
pos = 3;
|
||||
else
|
||||
pos = 2;
|
||||
end
|
||||
set(gcf,'Outerposition',[ceil(min(p.plot.scrsz(3)-ceil(p.plot.scrsz(4)/2), ceil(p.plot.scrsz(4)*pos/horiz_fact))) ceil(p.plot.scrsz(4)/2) ceil(p.plot.scrsz(4)/horiz_fact) ceil(p.plot.scrsz(4)/2)]) %[left, bottom, width, height
|
||||
end
|
||||
|
||||
ax.play(ax);
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,322 @@
|
||||
%%% PLOT_RESULTS plotting routine for ptychographic reconstructions
|
||||
% ** p p structure from a ptychographic reconstruction
|
||||
%
|
||||
% *optional*
|
||||
% ** use_display show plots (default: true)
|
||||
% ** store_images write images to disk (default: false)
|
||||
% ** final show all error metrics for a final plot (default: false)
|
||||
% ** save_path change default save_path (p.save_path) for saving jpgs
|
||||
%
|
||||
% EXAMPLES:
|
||||
% core.analysis.plot_results(p);
|
||||
% core.analysis.plot_results(p, 'store_images', true);
|
||||
% core.analysis.plot_results(p, 'use_display', false, 'store_images', true);
|
||||
%
|
||||
%
|
||||
% see also: plotting.ptycho_show_recons
|
||||
%
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function plot_results(p, varargin)
|
||||
import plotting.*
|
||||
import utils.*
|
||||
import math.sp_quantile
|
||||
|
||||
|
||||
% parse p.plot inputs
|
||||
check_input = @(x) islogical(x) || isnumeric(x);
|
||||
parse_p = inputParser;
|
||||
parse_p.KeepUnmatched = true;
|
||||
|
||||
parse_p.addParameter('fourier_ptycho', false, check_input)
|
||||
parse_p.addParameter('object_spectrum', [], check_input)
|
||||
parse_p.addParameter('filt', true, check_input)
|
||||
parse_p.addParameter('plot_layers', true, check_input)
|
||||
parse_p.addParameter('plot_layers_stack', true, check_input)
|
||||
parse_p.addParameter('remove_phase_ramp', false, check_input)
|
||||
parse_p.addParameter('prop_obj',0, check_input)
|
||||
parse_p.addParameter('plot_conj', false, check_input)
|
||||
parse_p.addParameter('obj_apod', false, check_input)
|
||||
|
||||
parse_p.parse(p.plot);
|
||||
p.plot = utils.update_param(p.plot, parse_p.Results);
|
||||
|
||||
% parse p.save
|
||||
parse_p = inputParser;
|
||||
parse_p.KeepUnmatched = true;
|
||||
parse_p.addParameter('store_images_format', 'png', @(x)ismember(x, {'png', 'jpg'}))
|
||||
parse_p.addParameter('store_images_dpi', 150, @math.isint)
|
||||
parse_p.parse(p.save);
|
||||
p.save = utils.update_param(p.save, parse_p.Results);
|
||||
|
||||
|
||||
if isempty(varargin) || ischar(varargin{1})
|
||||
par = inputParser;
|
||||
par.addParameter('use_display', true, check_input)
|
||||
par.addParameter('store_images', false, check_input)
|
||||
par.addParameter('final', false, check_input)
|
||||
par.addParameter('save_path',[], @ischar)
|
||||
|
||||
par.parse(varargin{:})
|
||||
vars = par.Results;
|
||||
end
|
||||
|
||||
|
||||
if p.fourier_ptycho
|
||||
p.plot.fov_box = false;
|
||||
end
|
||||
|
||||
if isempty(p.plot.object_spectrum)
|
||||
p.plot.object_spectrum = (utils.verbose>=3);
|
||||
end
|
||||
|
||||
if ~isfield(p.plot, 'log_scale')
|
||||
p.plot.log_scale = [false false];
|
||||
elseif isscalar(p.plot.log_scale)
|
||||
p.plot.log_scale = repmat(p.plot.log_scale,1,2);
|
||||
end
|
||||
|
||||
|
||||
|
||||
% Subplot geometry
|
||||
% p.subplwin = [floor(sqrt(p.numscans)) ceil(p.numscans/floor(sqrt(p.numscans)))];
|
||||
numwinobj = p.numobjs*p.object_modes;
|
||||
p.plot.subplwinobj = [floor(sqrt(numwinobj)) ceil(numwinobj/floor(sqrt(numwinobj)))];
|
||||
if p.numprobs == 1 || p.probe_modes == 1
|
||||
% distribute as efficiently as possible
|
||||
numwinprob = p.numprobs*p.probe_modes;
|
||||
p.plot.subplwinprob = [floor(sqrt(numwinprob)) ceil(numwinprob/floor(sqrt(numwinprob)))];
|
||||
else
|
||||
% show scans in columns and probe modes in rows
|
||||
p.plot.subplwinprob = [p.probe_modes, p.numprobs];
|
||||
end
|
||||
|
||||
|
||||
if check_option(p.plot, 'subplwinobj_dir', 'vertical') || (p.plot.show_layers && size(p.object{1},4) > 1)
|
||||
% prefer to stack the object verticaly , useful for multilayer object plotting
|
||||
p.plot.subplwinobj = sort(p.plot.subplwinobj, 'descend');
|
||||
end
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%%% OBJECTS %%%%%
|
||||
%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
[fig1, fig2] = core.analysis.plot_objects(p, vars.use_display);
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%%% PROBES %%%%%%
|
||||
%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
fig3 = core.analysis.plot_probes(p, vars.use_display);
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%%% ERROR METRIC %%%%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
try
|
||||
|
||||
fig4 = core.analysis.plot_error_metric(p, vars.final, vars.use_display);
|
||||
|
||||
catch ME
|
||||
warning('Failed to plot error metrics.')
|
||||
disp([ME.getReport]);
|
||||
fig4 = plotting.smart_figure(4);
|
||||
end
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%%% POSITIONS %%%%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
if p.plot.positions
|
||||
core.analysis.plot_positions(p);
|
||||
end
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%%% PROBES @ DETECTOR %%%%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
if p.plot.probe_spectrum
|
||||
fig5 = core.analysis.plot_probes_at_detector(p, vars.use_display);
|
||||
end
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%%% OBJECT SPECTRUM %%%%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
if p.plot.object_spectrum
|
||||
fig6 = core.analysis.plot_object_spectrum(p, vars.use_display);
|
||||
end
|
||||
|
||||
|
||||
drawnow;
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%% Write in figures folder %%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% If you configured to dump it also saves the figures in
|
||||
% analysis/online/ptycho
|
||||
if vars.store_images
|
||||
|
||||
|
||||
if isempty(vars.save_path)
|
||||
% split the save_path and find the last occurrence of 'analysis'
|
||||
tmpPath = strsplit(p.save_path{1}, '/');
|
||||
analysisPos = find(strcmpi(tmpPath, 'analysis'));
|
||||
save_path_online = strjoin(tmpPath(1:max(1,analysisPos(end)-1)),'/');
|
||||
|
||||
if ~isfield(p, 'datasetID')
|
||||
p.datasetID = 0;
|
||||
end
|
||||
|
||||
|
||||
% load sample name if provided in .dat files and append it to the
|
||||
% save name suffix
|
||||
if isfield(p, 'samplename')
|
||||
suffix = sprintf('dset_%s_%05d', p.samplename, p.datasetID);
|
||||
else
|
||||
suffix = sprintf('dset_%05d', p.datasetID);
|
||||
end
|
||||
subdir = fullfile(save_path_online,'analysis/online/ptycho/', suffix);
|
||||
gallery = fullfile(save_path_online,'analysis/online/ptycho/gallery/');
|
||||
|
||||
else
|
||||
subdir = vars.save_path;
|
||||
gallery = fullfile(subdir,'/gallery/');
|
||||
end
|
||||
|
||||
|
||||
if ~exist(gallery,'dir')
|
||||
mkdir(gallery);
|
||||
end
|
||||
if ~exist(subdir,'dir')
|
||||
mkdir(subdir);
|
||||
end
|
||||
|
||||
utils.verbose(0, 'Saving images to %s', subdir)
|
||||
|
||||
% ignore prefix in the run name -> make sorting by name equivalent to
|
||||
% sorting by scan number -> easier preview and browsing through image
|
||||
% gallery
|
||||
image_name = p.run_name(1+length(p.prefix):end);
|
||||
|
||||
width = 6*p.plot.subplwinobj(2);
|
||||
height = 4*p.plot.subplwinobj(1);
|
||||
|
||||
if any(p.save.store_images_ids == 1)
|
||||
fig1.PaperPosition = [3 3 width height]; % adjust size of the resulting image
|
||||
save_figs(fig1, '%s_amplitude.%s', image_name, subdir, gallery, p.save);
|
||||
end
|
||||
if any(p.save.store_images_ids == 2)
|
||||
fig2.PaperPosition = [3 3 width height]; % adjust size of the resulting image
|
||||
save_figs(fig2, '%s_phase.%s', image_name, subdir, gallery, p.save);
|
||||
end
|
||||
if any(p.save.store_images_ids == 6)
|
||||
fig6.PaperPosition = [3 3 width height]; % adjust size of the resulting image
|
||||
save_figs(fig6, '%s_object_spectrum.%s', image_name, subdir, gallery, p.save);
|
||||
end
|
||||
|
||||
width = 4*p.plot.subplwinprob(2);
|
||||
height = 4*p.plot.subplwinprob(1);
|
||||
if any(p.save.store_images_ids == 3)
|
||||
fig3.PaperPosition = [3 3 width height]; % adjust size of the resulting image
|
||||
save_figs(fig3, '%s_probe.%s', image_name, subdir, gallery, p.save);
|
||||
end
|
||||
if any(p.save.store_images_ids == 4)
|
||||
save_figs(fig4, '%s_err.%s', image_name, subdir, gallery, p.save);
|
||||
end
|
||||
if any(p.save.store_images_ids == 5)
|
||||
fig5.PaperPosition = [3 3 width height]; % adjust size of the resulting image
|
||||
save_figs(fig5, '%s_probe_spectrum.%s', image_name, subdir, gallery, p.save);
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function save_figs(fig_handle, fname,run_name, subdir, gallery, params)
|
||||
try
|
||||
|
||||
fname = sprintf(fname,run_name, params.store_images_format);
|
||||
utils.verbose(3, 'saving %s',fullfile(subdir,fname));
|
||||
|
||||
switch params.store_images_format
|
||||
case 'png' , printer = '-dpng';
|
||||
case 'jpg' , printer = '-djpeg';
|
||||
otherwise, error('Unsupported image extension')
|
||||
end
|
||||
print(fig_handle, printer,['-r', num2str(params.store_images_dpi)],fullfile(subdir,fname));
|
||||
% trim borders around the images
|
||||
system(sprintf('convert -trim %s %s', fullfile(subdir,fname), fullfile(subdir,fname)));
|
||||
% make a symbolic link to a gallery folder
|
||||
system(sprintf('ln -sf %s %s', fullfile(subdir,fname), fullfile(gallery, fname)));
|
||||
catch err
|
||||
warning('Saving plot handle fig%i failed: %s',fig_handle.Number, err.message)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
%GET_OBJECT_PIXEL_SIZE
|
||||
% calculate object pixel size, for conventional ptycho it is p.dx_spec
|
||||
%
|
||||
% ** p p structure
|
||||
%
|
||||
% Outputs:
|
||||
% ++
|
||||
%
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
|
||||
function [objpix, FP_pre_phase_factor] = get_object_pixel_size(p)
|
||||
import utils.get_grid
|
||||
|
||||
if p.fourier_ptycho
|
||||
k = 2*pi/p.lambda;
|
||||
objpix = p.lambda*p.z_lens./(p.object_size.*p.dx_spec);
|
||||
for ii=1:p.numobjs
|
||||
[Xp,Yp] = get_grid(p.object_size(ii,:), objpix(1));
|
||||
FP_pre_phase_factor{ii} = exp(1i*k*((Xp).^2+(Yp).^2)/(2*p.z_lens));
|
||||
end
|
||||
else
|
||||
objpix = p.dx_spec;
|
||||
FP_pre_phase_factor = [];
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,208 @@
|
||||
%EXTRACT4SAVING extracts datasets and parameters from p and creates HDF5
|
||||
%structure
|
||||
% ** p p structure
|
||||
% ** append boolean; true if data will be appended to an existing file
|
||||
%
|
||||
% returns:
|
||||
% ++ s structure for save2hdf5
|
||||
%
|
||||
% see also: io.HDF.save2hdf5
|
||||
%
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function [ s ] = extract4saving(p, append)
|
||||
import utils.update_param
|
||||
import math.double2int
|
||||
|
||||
s = [];
|
||||
|
||||
|
||||
|
||||
p = rmfield_safe(p, 'probe');
|
||||
p = rmfield_safe(p, 'positions_temp');
|
||||
p = rmfield_safe(p, 'scanidxs');
|
||||
p = rmfield_safe(p, 'share_pos');
|
||||
|
||||
p.positions = transpose(p.positions);
|
||||
p.positions_real = transpose(p.positions_real);
|
||||
p.positions_orig = transpose(p.positions_orig);
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%
|
||||
%%% measurement %%%
|
||||
%%%%%%%%%%%%%%%%%%%
|
||||
%% external link to data file
|
||||
% should be saved with a relative path
|
||||
% s.measurement.data = ['ext:' p.prepare_data_path p.prepare_data_filename ':/'];
|
||||
|
||||
%% Meta data
|
||||
if ~isempty(p.meta)
|
||||
s.measurement.meta_all = p.meta;
|
||||
end
|
||||
p = rmfield_safe(p, 'meta');
|
||||
|
||||
|
||||
%% Detector settings
|
||||
% s.measurement.detector
|
||||
p = rmfield_safe(p, p.detector.name);
|
||||
|
||||
%% fmask and fmag
|
||||
p = rmfield_safe(p, 'fmask');
|
||||
p = rmfield_safe(p, 'fmag');
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%% reconstruction %%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
%% engines
|
||||
em_indx = 0;
|
||||
for ii=1:length(p.engines)
|
||||
tmp = p.engines{ii};
|
||||
|
||||
% % add object_final
|
||||
% if ~isempty(tmp.object_final)
|
||||
% s.reconstruction.engines{ii}.object_final = tmp.object_final;
|
||||
% end
|
||||
% % add probes_final
|
||||
% if ~isempty(tmp.probes_final)
|
||||
% s.reconstruction.engines{ii}.probes_final = tmp.probes_final;
|
||||
% end
|
||||
if isfield(tmp, 'error_metric_final')
|
||||
for jj=1:length(tmp.error_metric_final)
|
||||
% add error_metric_final
|
||||
if iscell(tmp.error_metric_final)
|
||||
s.reconstruction.p.engines{ii}.error_metric_final.(['em_' num2str(jj-1)]).iteration = tmp.error_metric_final{jj}.iteration;
|
||||
s.reconstruction.p.engines{ii}.error_metric_final.(['em_' num2str(jj-1)]).value = tmp.error_metric_final{jj}.value;
|
||||
s.reconstruction.p.engines{ii}.error_metric_final.(['em_' num2str(jj-1)]).method = tmp.error_metric_final{jj}.method;
|
||||
s.reconstruction.p.engines{ii}.error_metric_final.(['em_' num2str(jj-1)]).err_metric = tmp.error_metric_final{jj}.err_metric;
|
||||
s.reconstruction.p.engines{ii}.error_metric_final.Attributes.MATLAB_class = 'cell';
|
||||
else
|
||||
s.reconstruction.p.engines{ii}.error_metric_final.(['em_' num2str(jj-1)]).iteration = tmp.error_metric_final.iteration;
|
||||
s.reconstruction.p.engines{ii}.error_metric_final.(['em_' num2str(jj-1)]).value = tmp.error_metric_final.value;
|
||||
s.reconstruction.p.engines{ii}.error_metric_final.(['em_' num2str(jj-1)]).method = tmp.error_metric_final.method;
|
||||
s.reconstruction.p.engines{ii}.error_metric_final.(['em_' num2str(jj-1)]).err_metric = tmp.error_metric_final.err_metric;
|
||||
s.reconstruction.p.engines{ii}.error_metric_final.Attributes.MATLAB_class = 'cell';
|
||||
end
|
||||
% add error_metric
|
||||
% s.reconstruction.p.error_metric.(['em_' num2str(em_indx)]) = ['int_soft:/reconstruction/p/engines/' fn{ii} '/error_metric_final/em_' num2str(jj-1)];
|
||||
% em_indx = em_indx + 1;
|
||||
end
|
||||
s.reconstruction.p.engines{ii} = update_param(s.reconstruction.p.engines{ii}, double2int(tmp), 'force_update', 0);
|
||||
|
||||
end
|
||||
|
||||
tmp = rmfield_safe(tmp, 'object_final');
|
||||
tmp = rmfield_safe(tmp, 'probes_final');
|
||||
tmp = rmfield_safe(tmp, 'error_metric_final');
|
||||
tmp = rmfield_safe(tmp, 'fdb');
|
||||
|
||||
end
|
||||
|
||||
p = rmfield_safe(p, 'engines');
|
||||
p = rmfield_safe(p, 'error_metric');
|
||||
% p = rmfield_safe(p, 'err');
|
||||
% p = rmfield_safe(p, 'rfact');
|
||||
|
||||
%% probe (dataset)
|
||||
if ~append
|
||||
for ii=1:p.numprobs
|
||||
s.reconstruction.p.probes.(['probe_' num2str(ii-1)]) = permute(squeeze(p.probes(:,:,ii,:)), [2 1 3]);
|
||||
end
|
||||
end
|
||||
|
||||
p = rmfield_safe(p, 'probes');
|
||||
|
||||
|
||||
|
||||
|
||||
%% object (dataset)
|
||||
if ~append
|
||||
for ii=1:p.numobjs
|
||||
s.reconstruction.p.objects.(['object_' num2str(ii-1)]) = permute(p.object{ii}, [2 1 3 4]);
|
||||
end
|
||||
end
|
||||
p = rmfield_safe(p, 'object');
|
||||
|
||||
|
||||
|
||||
%% probe mask
|
||||
if isfield(p, 'probe_mask')
|
||||
s.reconstruction.p.probe_mask = p.probe_mask;
|
||||
|
||||
p = rmfield_safe(p, 'probe_mask');
|
||||
end
|
||||
|
||||
%% ctr
|
||||
s.reconstruction.p.ctr = uint32(transpose(p.ctr));
|
||||
|
||||
p = rmfield_safe(p, 'ctr');
|
||||
|
||||
%% everything else
|
||||
|
||||
s.reconstruction.p = update_param(s.reconstruction.p, double2int(p), 'force_update', 0);
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
function p = rmfield_safe(p, val)
|
||||
if isfield(p, val)
|
||||
p = rmfield(p, val);
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
%RECONSTRUCTIONS_AS_MAT
|
||||
% Save reconstruction into a h5 file
|
||||
%
|
||||
% ** p p structure
|
||||
% ** final boolean; false for intermediate saving routines
|
||||
%
|
||||
% returns:
|
||||
% ++ p p structure
|
||||
%
|
||||
% see also: core.save.save_results
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function p = reconstructions_as_h5(p, final)
|
||||
import utils.verbose
|
||||
import utils.relative_path
|
||||
import io.HDF.*
|
||||
|
||||
|
||||
if final
|
||||
p.plot.extratitlestring = sprintf(' (%dx%d) - Final', p.asize(2), p.asize(1));
|
||||
end
|
||||
|
||||
% check if last engine was c_solver
|
||||
if strcmpi(p.engines{p.current_engine_id}.name, 'c_solver')
|
||||
append2file = true;
|
||||
else
|
||||
append2file = false;
|
||||
end
|
||||
|
||||
s = core.save.extract4saving(p, append2file);
|
||||
|
||||
|
||||
for ii=1:p.numscans
|
||||
if p.share_object
|
||||
obnum = 1;
|
||||
else
|
||||
obnum = ii;
|
||||
end
|
||||
if p.share_probe
|
||||
prnum = 1;
|
||||
else
|
||||
prnum = ii;
|
||||
end
|
||||
s.reconstruction.object = ['int_soft:/reconstruction/p/objects/object_' num2str(obnum-1)];
|
||||
s.reconstruction.probes = ['int_soft:/reconstruction/p/probes/probe_' num2str(prnum-1)];
|
||||
s.reconstruction.Attributes.obnum = obnum;
|
||||
s.reconstruction.Attributes.prnum = prnum;
|
||||
if isfield(p, 'recon_filename')
|
||||
filename_with_path = p.recon_filename{ii};
|
||||
if p.queue.isreplica
|
||||
[~, fname, ext] = fileparts(p.recon_filename{ii});
|
||||
filename_with_path = fullfile(p.save_path{ii}, [fname ext]);
|
||||
end
|
||||
else
|
||||
recons_filename = sprintf('%s_recons.%s',p.run_name, p.save.output_file);
|
||||
filename_with_path = fullfile(p.save_path{ii}, recons_filename);
|
||||
|
||||
if exist(filename_with_path, 'file')
|
||||
verbose(3,'File %s exists!', filename_with_path);
|
||||
alt_filename = filename_with_path;
|
||||
[~, fbase,f2] = fileparts(filename_with_path);
|
||||
append_number = 0;
|
||||
while exist(alt_filename, 'file')
|
||||
f1 = sprintf('%s_%02d', fbase, append_number);
|
||||
alt_filename = fullfile(p.save_path{ii}, [f1 f2]);
|
||||
append_number = append_number + 1;
|
||||
end
|
||||
filename_with_path = alt_filename;
|
||||
end
|
||||
end
|
||||
|
||||
if ii==1
|
||||
% If the last engine was c_solver, we can use the already existing
|
||||
% h5 file.
|
||||
if append2file
|
||||
movefile(p.recon_filename_c, filename_with_path);
|
||||
end
|
||||
root_file = filename_with_path;
|
||||
s.measurement.data = ['ext:' relative_path(filename_with_path, [p.prepare_data_path p.prepare_data_filename]) ':/'];
|
||||
|
||||
else
|
||||
hdf5_cp_file(relative_path(filename_with_path, root_file), filename_with_path, 'groups', {'/measurement/data'; '/measurement/meta_all'; '/reconstruction/p'});
|
||||
end
|
||||
|
||||
s.measurement.meta = ['int_soft:/measurement/meta_all/meta_all_' num2str(ii-1)];
|
||||
save2hdf5(filename_with_path, s, 'comp', p.io.file_compression);
|
||||
|
||||
try
|
||||
fsz = dir(filename_with_path);
|
||||
verbose(0, 'Reconstructed scan S%05d: %s', p.scan_number(ii), filename_with_path)
|
||||
verbose(2, 'File size: %0.4f MB', fsz.bytes/1e6)
|
||||
catch
|
||||
verbose(0, 'Saved reconstruction to file %s.', filename_with_path);
|
||||
end
|
||||
|
||||
s = [];
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,145 @@
|
||||
%RECONSTRUCTIONS_AS_MAT
|
||||
% Save reconstruction into the MAT file
|
||||
%
|
||||
% ** p p structure
|
||||
% ** final boolean; false for intermediate saving routines
|
||||
%
|
||||
% returns:
|
||||
% ++ p p structure
|
||||
%
|
||||
% see also: core.save.save_results
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
|
||||
function p = reconstructions_as_mat(p, final)
|
||||
import utils.verbose
|
||||
import utils.relative_path
|
||||
import io.HDF.*
|
||||
|
||||
if ~isfield(p.save, 'exclude')
|
||||
p.save.exclude = {'fmag'; 'fmask'};
|
||||
end
|
||||
if final
|
||||
p.plot.extratitlestring = sprintf(' (%dx%d) - Final', p.asize(2), p.asize(1));
|
||||
end
|
||||
|
||||
recons_filename = sprintf('%s_recons.mat',p.run_name);
|
||||
|
||||
for ii = 1:p.numscans
|
||||
if p.share_object
|
||||
obnum = 1;
|
||||
else
|
||||
obnum = ii;
|
||||
end
|
||||
if p.share_probe
|
||||
prnum = 1;
|
||||
else
|
||||
prnum = ii;
|
||||
end
|
||||
|
||||
object = p.object{obnum};
|
||||
probe = p.probes(:,:,prnum,:);
|
||||
|
||||
|
||||
% if isfield(p.meta,'spec')
|
||||
% p.spec = p.meta.spec{ii};
|
||||
% end
|
||||
|
||||
filename_with_path = fullfile(p.save_path{ii}, recons_filename);
|
||||
|
||||
|
||||
if exist(filename_with_path, 'file')
|
||||
verbose(3,'File %s exists!', filename_with_path);
|
||||
alt_filename = filename_with_path;
|
||||
[~, fbase,f2] = fileparts(filename_with_path);
|
||||
append_number = 0;
|
||||
while exist(alt_filename, 'file')
|
||||
f1 = sprintf('%s_%02d', fbase, append_number);
|
||||
alt_filename = fullfile(p.save_path{ii}, [f1 f2]);
|
||||
append_number = append_number + 1;
|
||||
end
|
||||
verbose(1, 'Saving reconstruction to file %s', alt_filename);
|
||||
filename_with_path = alt_filename;
|
||||
end
|
||||
|
||||
% avoid saving unnecesary data => speed up loading during tomography
|
||||
probe = single(squeeze(probe));
|
||||
object = single(object);
|
||||
if ~p.save.save_reconstructions_intermediate
|
||||
for ieng = 1:length(p.engines)
|
||||
p.engines{ieng}.object_final = [];
|
||||
p.engines{ieng}.probes_final = [];
|
||||
end
|
||||
end
|
||||
|
||||
for ex=1:size(p.save.exclude,1)
|
||||
temp.(p.save.exclude{ex}) = p.(p.save.exclude{ex});
|
||||
p.(p.save.exclude{ex}) = [];
|
||||
end
|
||||
% save it to HDF5 without compression (faster saving / loading)
|
||||
save(filename_with_path,'p','object','probe', '-v6' );
|
||||
% note that the -v6 option makes the saving 10x faster and
|
||||
% loading 5x faster compared to option -v7 and 30x faster
|
||||
% saving compared to -v7.3
|
||||
verbose(0, 'Saved reconstruction to file %s.', filename_with_path);
|
||||
|
||||
for ex=1:size(p.save.exclude,1)
|
||||
p.(p.save.exclude{ex}) = temp.(p.save.exclude{ex});
|
||||
end
|
||||
|
||||
clear temp;
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,134 @@
|
||||
%SAVE_RESULTS
|
||||
% Save reconstruction and parameter file
|
||||
%
|
||||
% ** p p structure
|
||||
% ** final boolean; false for intermediate saving routines
|
||||
%
|
||||
% returns:
|
||||
% ++ p p structure
|
||||
%
|
||||
% see also: core.ptycho_recons
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function [p] = save_results(p, final)
|
||||
import utils.verbose
|
||||
import utils.relative_path
|
||||
import io.HDF.*
|
||||
|
||||
print_FSC = false;
|
||||
if p.plot.calc_FSC
|
||||
if p.numscans ~= 2 && ~(isfield(p, 'simulation')&&isfield(p.simulation, 'obj'))
|
||||
warning('FRC calculation is implemented for 2 scans only.')
|
||||
else
|
||||
try
|
||||
[p, resolution] = core.analysis.calc_FSC(p);
|
||||
print_FSC = true;
|
||||
catch ME
|
||||
if p.verbose_level > 3
|
||||
keyboard
|
||||
else
|
||||
warning('Failed to calculate FSC.')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if p.save.save_reconstructions
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%% Save reconstruction and parameter file %%%%%%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
if strcmpi(p.save.output_file, 'h5') || strcmpi(p.save.output_file, 'cxs')
|
||||
|
||||
p = core.save.reconstructions_as_h5(p, final);
|
||||
|
||||
elseif strcmpi(p.save.output_file, 'mat')
|
||||
|
||||
p = core.save.reconstructions_as_mat(p, final);
|
||||
|
||||
else
|
||||
error('Unknown file extension .%s', p.save.output_file);
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
%%%%%%%%%%%%
|
||||
%%% Plot %%%
|
||||
%%%%%%%%%%%%
|
||||
|
||||
if final && p.save.external && p.verbose_level <=2
|
||||
verbose(2, 'Starting new matlab session to save figures.')
|
||||
|
||||
recons_filename = sprintf('%s_recons.%s',p.run_name, p.save.output_file);
|
||||
filename_with_path = fullfile(p.save_path{1}, recons_filename);
|
||||
|
||||
ext_call = ['addpath(genpath(''../'')); try;' ...
|
||||
'plotting.ptycho_show_recons(''' filename_with_path ''');catch ME;'...
|
||||
'fprintf([ME.getReport ''\n\n\n'']); end; quit'];
|
||||
system(['matlab -nosplash -nodisplay -r "' ext_call '" &']);
|
||||
else
|
||||
if p.use_display||p.save.store_images
|
||||
core.analysis.plot_results(p, 'use_display', p.use_display, 'store_images', p.save.store_images, 'final', final);
|
||||
end
|
||||
end
|
||||
|
||||
if print_FSC
|
||||
fprintf('\n');
|
||||
utils.verbose(2,'Resolution (FSC): (%.2f, %.2f) nm\n', resolution)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
%APPEND_ENGINE appends engine specified in new_eng to p
|
||||
% Adds engines with index, starting at 1
|
||||
% 1st engine: p.engines{1}
|
||||
%
|
||||
% ** p p structure
|
||||
% ** new_eng structure containing information about the new engine
|
||||
%
|
||||
% returns:
|
||||
% ++ p p structure
|
||||
% ++ new_eng empty container; useful if one does not want to propagate changes between engines
|
||||
%
|
||||
% see also: core.ptycho_recons
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function [p, new_eng] = append_engine(p, new_eng )
|
||||
|
||||
% check if it is the first engine, otherwise get the current index
|
||||
if ~isfield(p, 'engines')
|
||||
p.engines = {};
|
||||
end
|
||||
|
||||
% append engine
|
||||
p.engines{end+1} = new_eng;
|
||||
|
||||
% clear engine structure
|
||||
new_eng = struct();
|
||||
|
||||
|
||||
end
|
||||
@@ -0,0 +1,50 @@
|
||||
% APPLY_BINNING apply binning / upsampling on all relevant parameters except data and mask
|
||||
%
|
||||
% p = apply_binning(p, bin_data)
|
||||
%
|
||||
% ** p p structure
|
||||
% ** binning if binning > 1, then data are binned , if binning < 1, data will be upsampled
|
||||
% returns:
|
||||
% ++ p p structure
|
||||
%
|
||||
|
||||
function p = apply_binning(p, binning)
|
||||
% apply binning / upsampling on all relevant parameters except data and mask
|
||||
if binning > 0
|
||||
assert(all(rem(p.asize, binning)==0), 'Array size cannot be divided for binning')
|
||||
end
|
||||
|
||||
% Modify variables for binning
|
||||
p.ds = p.ds*binning;
|
||||
|
||||
if check_option(p,'prop_regime', 'farfield')
|
||||
p.object_size = p.object_size + ( 1/binning-1)*p.asize ;
|
||||
for ii = 1:p.numobjs
|
||||
p.object{ii} = utils.crop_pad(p.object{ii},p.object_size(ii,:)); % crop_pad is better when if the binned reconstruction is loaded from file as an initial guess
|
||||
end
|
||||
|
||||
p.asize = p.asize/binning;
|
||||
|
||||
|
||||
%% always assume that no binning was applied on the provided probes
|
||||
p.probe_initial = utils.crop_pad( p.probe_initial, p.asize);
|
||||
p.probes = utils.crop_pad( p.probes, p.asize);
|
||||
else
|
||||
p.object_size = ceil(p.object_size / binning);
|
||||
for ii = 1:p.numobjs
|
||||
p.object{ii} = utils.interpolateFT(p.object{ii},p.object_size(ii,:)); % crop_pad is better when if the binned reconstruction is loaded from file as an initial guess
|
||||
end
|
||||
|
||||
p.asize = p.asize/binning;
|
||||
|
||||
|
||||
%% always assume that no binning was applied on the provided probes
|
||||
p.probe_initial = utils.interpolateFT( p.probe_initial, p.asize);
|
||||
p.probes = utils.interpolateFT( p.probes, p.asize);
|
||||
|
||||
p.dx_spec = p.dx_spec * binning;
|
||||
p.positions = p.positions / binning; % in nearfield the pixel size also changes
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,166 @@
|
||||
%CHECK_PREPARED_DATA compares prepared data file with current
|
||||
%reconstruction parameters. If force_update == true, data preparation will
|
||||
%be forced (see core.ptycho_prepare_scans)
|
||||
% ** p p structure
|
||||
%
|
||||
% returns:
|
||||
% ++ force_update true if data preparation has be done enforced
|
||||
%
|
||||
% see also: core.ptycho_prepare_scans
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function [ force_update ] = check_prepared_data( p )
|
||||
|
||||
|
||||
force_update = false;
|
||||
|
||||
file = fullfile(p.prepare_data_path, p.prepare_data_filename);
|
||||
|
||||
if ~exist(file, 'file')
|
||||
error('Prepared data file %s does not exist!', file);
|
||||
end
|
||||
|
||||
h = h5info(file);
|
||||
|
||||
if ~isempty(find(contains({h.Attributes.Name}, 'format'),1)) && h.Attributes(find(contains({h.Attributes.Name}, 'format'),1)).Value==2
|
||||
h5format = 'LibDetXR';
|
||||
else
|
||||
h5format = 'Matlab';
|
||||
end
|
||||
|
||||
switch h5format
|
||||
case 'LibDetXR'
|
||||
|
||||
% check for sharing, asize and numpts
|
||||
idx = contains({h.Groups.Name}, '/measurement');
|
||||
fn = length(h.Groups(idx).Groups);
|
||||
probe_ID = zeros(1,fn);
|
||||
object_ID = zeros(1,fn);
|
||||
data_size = zeros(fn,3);
|
||||
for ii=1:fn
|
||||
group = h.Groups(idx).Groups;
|
||||
idx_sub = ismember({group.Name}, ['/measurement/n' num2str(ii-1)]);
|
||||
attrib = group(idx_sub).Attributes;
|
||||
idx_pr = ismember({attrib.Name}, 'probe');
|
||||
probe_ID(ii) = attrib(idx_pr).Value + 1;
|
||||
idx_ob = ismember({attrib.Name}, 'object');
|
||||
object_ID(ii) = attrib(idx_ob).Value + 1;
|
||||
data_size(ii,:) = group(idx_sub).Datasets(find(contains({group(idx_sub).Datasets.Name}, 'data'),1)).Dataspace.Size;
|
||||
|
||||
end
|
||||
|
||||
if any(data_size(1,[2,1])~=p.asize/2^p.detector.binning)
|
||||
force_update = true;
|
||||
end
|
||||
|
||||
if (size(data_size,1) ~= length(p.numpts) || any(data_size(:,3)'~=p.numpts)) && ~p.fourier_ptycho
|
||||
force_update = true;
|
||||
end
|
||||
|
||||
if length(unique(probe_ID))~=length(unique(p.share_probe_ID)) || any(probe_ID~=p.share_probe_ID)
|
||||
force_update = true;
|
||||
end
|
||||
|
||||
if length(unique(object_ID))~=length(unique(p.share_object_ID)) || any(object_ID~=p.share_object_ID)
|
||||
force_update = true;
|
||||
end
|
||||
|
||||
|
||||
case 'Matlab'
|
||||
|
||||
idx = contains({h.Groups.Name}, '/measurements');
|
||||
fn = length(h.Groups(idx).Groups);
|
||||
probe_ID = zeros(1,fn);
|
||||
object_ID = zeros(1,fn);
|
||||
scan_ID = zeros(1,fn);
|
||||
for ii=1:fn
|
||||
idx_pr = contains({h.Groups(idx).Groups(ii).Attributes.Name}, 'probe');
|
||||
idx_det = contains({h.Groups(idx).Groups(ii).Attributes.Name}, 'detector');
|
||||
idx_ob = contains({h.Groups(idx).Groups(ii).Attributes.Name}, 'object');
|
||||
scan_ID(ii) = h.Groups(idx).Groups(ii).Attributes(idx_det).Value + 1;
|
||||
probe_ID(ii) = h.Groups(idx).Groups(ii).Attributes(idx_pr).Value + 1;
|
||||
object_ID(ii) = h.Groups(idx).Groups(ii).Attributes(idx_ob).Value + 1;
|
||||
|
||||
end
|
||||
numscans = unique(scan_ID);
|
||||
numpts = zeros(1,numel(numscans));
|
||||
for ii=1:numel(numscans)
|
||||
numpts(ii) = sum(scan_ID==numscans(ii));
|
||||
if ~all(object_ID(scan_ID==numscans(ii)) == p.share_object_ID(ii)) || ~all(probe_ID(scan_ID==numscans(ii)) == p.share_probe_ID(ii))
|
||||
force_update = true;
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if (numel(numpts) ~= numel(p.numpts)) || any(numpts~=p.numpts)
|
||||
force_update = true;
|
||||
end
|
||||
|
||||
% asize
|
||||
asize = hdf5_load(file, '/probes');
|
||||
asize = asize(1:2);
|
||||
if any(asize ~= p.asize)
|
||||
force_update = true;
|
||||
end
|
||||
|
||||
otherwise
|
||||
error('Unknown prepared data format')
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
% ENGINE_STATUS use persisten variables to store error messages
|
||||
% Error code: 0 for 'everything OK' and ~=0 for 'error' (return values of matlab's system function)
|
||||
%
|
||||
% *usage:*
|
||||
% engine_status(status) to set persisten variable engine_stat to
|
||||
% status
|
||||
%
|
||||
% engine_status to read persisten variables
|
||||
%
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function [eng_stat] = engine_status(varargin)
|
||||
|
||||
persistent engine_stat
|
||||
persistent engine_stat_ln
|
||||
|
||||
|
||||
if isempty(engine_stat)
|
||||
engine_stat = 0;
|
||||
end
|
||||
if isempty(engine_stat_ln)
|
||||
engine_stat_ln = [];
|
||||
end
|
||||
|
||||
eng_stat.status = engine_stat;
|
||||
eng_stat.ln = engine_stat_ln;
|
||||
|
||||
if nargin == 0
|
||||
return
|
||||
end
|
||||
|
||||
if nargin == 1
|
||||
if ischar(varargin{1})
|
||||
engine_stat = str2num(varargin{1});
|
||||
else
|
||||
engine_stat = varargin{1};
|
||||
end
|
||||
if engine_stat ~= 0
|
||||
engine_stat_ln = dbstack(1);
|
||||
end
|
||||
eng_stat.status = engine_stat;
|
||||
eng_stat.ln = engine_stat_ln;
|
||||
return
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
% Build an errormetric plot vs iteration number
|
||||
%
|
||||
% *usage*
|
||||
% e = errorplot Clears the persistent variable
|
||||
% e = errorplot(x) Appends x to the persistent variable
|
||||
% e = errorplot([]) Only reads the persistent variable
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function outerror = errorplot(argin)
|
||||
|
||||
persistent errormetric,
|
||||
|
||||
if exist('argin') == 0,
|
||||
errormetric = [];
|
||||
else
|
||||
errormetric = [errormetric ; argin];
|
||||
end
|
||||
|
||||
outerror = errormetric;
|
||||
end
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
%EXPORT4REMOTE
|
||||
% Export the meta data using a .mat file for remote reconstruction
|
||||
%
|
||||
% ** p p structure
|
||||
%
|
||||
% returns:
|
||||
% ++ p updated p structure
|
||||
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function p = export4remote(p)
|
||||
import utils.verbose
|
||||
|
||||
if ~isfield(p.queue, 'remote_path') || isempty(p.queue.remote_path)
|
||||
error('Shared directory for remote host has to be specified.')
|
||||
end
|
||||
|
||||
if ~exist(p.queue.remote_path, 'dir')
|
||||
try
|
||||
mkdir(fullfile(p.queue.remote_path))
|
||||
catch
|
||||
error('Failed to create remote queue directory.')
|
||||
end
|
||||
end
|
||||
|
||||
if ~exist(fullfile(p.queue.remote_path,'in_progress'))
|
||||
mkdir(fullfile(p.queue.remote_path,'in_progress'));
|
||||
end
|
||||
if ~exist(fullfile(p.queue.remote_path,'failed'))
|
||||
mkdir(fullfile(p.queue.remote_path,'failed'));
|
||||
end
|
||||
if ~exist(fullfile(p.queue.remote_path,'done'))
|
||||
mkdir(fullfile(p.queue.remote_path,'done'));
|
||||
end
|
||||
p = core.ptycho_prepare_paths(p);
|
||||
|
||||
recons_filename = sprintf('%s_recons.%s',p.run_name, p.save.output_file);
|
||||
for ii=1:numel(p.scan_number)
|
||||
filename_with_path = fullfile(p.save_path{ii}, recons_filename);
|
||||
|
||||
if exist(filename_with_path, 'file')
|
||||
verbose(3,'File %s exists!', filename_with_path);
|
||||
alt_filename = filename_with_path;
|
||||
[~, fbase,f2] = fileparts(filename_with_path);
|
||||
append_number = 0;
|
||||
while exist(alt_filename, 'file')
|
||||
f1 = sprintf('%s_%02d', fbase, append_number);
|
||||
alt_filename = fullfile(p.save_path{ii}, [f1 f2]);
|
||||
append_number = append_number + 1;
|
||||
end
|
||||
filename_with_path = alt_filename;
|
||||
end
|
||||
p.recon_filename{ii} = filename_with_path;
|
||||
end
|
||||
|
||||
p.queue.remote_file_this_recons = fullfile(p.queue.remote_path, [p.run_name '.mat']);
|
||||
save(fullfile(p.queue.remote_path, [p.run_name '.mat']), 'p', '-v6');
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
%FIND_BASE_PACKAGE
|
||||
% finds the path to the cSAXS base package by looking for a specific file (+math)
|
||||
%
|
||||
% returns:
|
||||
% ++ base_package_path path to the cSAXS base package
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
|
||||
|
||||
function base_package_path = find_base_package()
|
||||
maxdepth = 3;
|
||||
test_path = '+math'; % one file to find them all
|
||||
|
||||
lvl = 1;
|
||||
cpath = '';
|
||||
ret = '';
|
||||
while isempty(ret) && ~contains(strtrim(ret), test_path)
|
||||
[~, ret] = system(sprintf('find %s -maxdepth 2 -type d -name "%s"', cpath, test_path));
|
||||
if lvl > maxdepth
|
||||
break
|
||||
end
|
||||
lvl = lvl + 1;
|
||||
cpath = [cpath '../'];
|
||||
end
|
||||
ret = split(ret);
|
||||
base_package_path = strtrim(ret{1});
|
||||
base_package_path = base_package_path(1:end-length(test_path));
|
||||
|
||||
end
|
||||
@@ -0,0 +1,133 @@
|
||||
%FIND_SHARED_IDS find which positions belong to each object / probe
|
||||
%
|
||||
% ** p p structure
|
||||
% returns:
|
||||
% ++ p p structure
|
||||
%
|
||||
% see also: core.initialize_ptycho
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function [ p ] = find_shared_IDs( p )
|
||||
|
||||
|
||||
|
||||
% Shared scans
|
||||
if all(p.share_object==0)
|
||||
p.share_object_ID = 1:p.numscans;
|
||||
else
|
||||
for ii=1:length(p.share_object)
|
||||
if ~p.share_object(ii)
|
||||
p.share_object_ID(ii) = ii;
|
||||
else
|
||||
p.share_object_ID(ii) = p.share_object(ii);
|
||||
end
|
||||
end
|
||||
if length(p.share_object)<p.numscans
|
||||
for ii=length(p.share_object)+1:p.numscans
|
||||
p.share_object_ID = [p.share_object_ID p.share_object_ID(end)];
|
||||
end
|
||||
elseif length(p.share_object)>p.numscans
|
||||
p.share_object_ID(p.numscans+1:end) = [];
|
||||
end
|
||||
if max(p.share_object_ID)> length(p.scan_number)
|
||||
error('Shared object ID must be in the range of length(scan_number)')
|
||||
end
|
||||
end
|
||||
p.share_object_ID = squeeze_num(p.share_object_ID);
|
||||
p.numobjs = length(unique(p.share_object_ID));
|
||||
|
||||
if all(p.share_probe==0)
|
||||
p.share_probe_ID = 1:p.numscans;
|
||||
else
|
||||
for ii=1:length(p.share_probe)
|
||||
if ~p.share_probe(ii)
|
||||
p.share_probe_ID(ii) = ii;
|
||||
else
|
||||
p.share_probe_ID(ii) = p.share_probe(ii);
|
||||
end
|
||||
end
|
||||
|
||||
if length(p.share_probe)<p.numscans
|
||||
for ii=length(p.share_probe)+1:p.numscans
|
||||
p.share_probe_ID = [p.share_probe_ID p.share_probe_ID(end)];
|
||||
end
|
||||
elseif length(p.share_probe)>p.numscans
|
||||
p.share_probe_ID(p.numscans+1:end) = [];
|
||||
end
|
||||
if max(p.share_probe_ID)> length(p.scan_number)
|
||||
error('Shared object ID must be in the range of length(scan_number)')
|
||||
end
|
||||
end
|
||||
p.share_probe_ID = squeeze_num(p.share_probe_ID);
|
||||
p.numprobs = length(unique(p.share_probe_ID));
|
||||
|
||||
end
|
||||
|
||||
|
||||
function ret = squeeze_num(n)
|
||||
% squeeze number to be consecutive
|
||||
uval = unique(n);
|
||||
if length(n)==length(uval)
|
||||
ret = n;
|
||||
else
|
||||
ret = n;
|
||||
for ii=1:length(n)
|
||||
if ~any(n==ii)
|
||||
ret(ret>ii) = ret(ret>ii)-1;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,87 @@
|
||||
%GENERATE_SCAN_NAME
|
||||
% Auxilialy function to generate scan names
|
||||
%
|
||||
% ** p p structure
|
||||
%
|
||||
% returns:
|
||||
% ++ scan_name scan names
|
||||
%
|
||||
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
|
||||
function scan_name = generate_scan_name(p)
|
||||
if length(p.scan_number) <= 2
|
||||
% original naming conventioon
|
||||
scan_name = sprintf('S%05d_',p.scan_number);
|
||||
else
|
||||
% in case of large scans with continuous scan range use a
|
||||
% shorter name notation to avoid filesystem errors
|
||||
scan_range_start = setdiff(p.scan_number, p.scan_number+1);
|
||||
scan_range_end = setdiff(p.scan_number, p.scan_number-1);
|
||||
|
||||
scan_name = '';
|
||||
|
||||
for ii = 1:length(scan_range_start)
|
||||
if scan_range_start(ii) ~= scan_range_end(ii)
|
||||
scan_name = [scan_name, sprintf('S%05d-S%05d_',scan_range_start(ii), scan_range_end(ii))];
|
||||
else
|
||||
scan_name = [scan_name, sprintf('S%05d_',scan_range_start(ii))];
|
||||
end
|
||||
end
|
||||
end
|
||||
scan_name = scan_name(1:end-1);
|
||||
end
|
||||
@@ -0,0 +1,106 @@
|
||||
%GET_PROJECTIONS
|
||||
%
|
||||
% ** p p structure
|
||||
% ** object full-size object
|
||||
% ** scan_id ID of the current scan
|
||||
% ** obj_proj container for object projections
|
||||
%
|
||||
% returns:
|
||||
% ++ obj_proj updated container for object projections
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function obj_proj = get_projections(p, object, scan_id, obj_proj)
|
||||
import utils.verbose
|
||||
|
||||
Npos = length(p.scanidxs{scan_id});
|
||||
Nmodes = size(object,4);
|
||||
if nargin < 4
|
||||
obj_proj = zeros([p.asize, Npos, Nmodes], 'like', object);
|
||||
end
|
||||
if any(max(round(p.positions(p.scanidxs{scan_id},:)))+p.asize > [size(object,1),size(object,2)])
|
||||
error('Object is too small for given positions')
|
||||
end
|
||||
|
||||
if Nmodes == 1 && (isa(object, 'gpuArray') || isa(obj_proj, 'gpuArray'))
|
||||
% use function from GPU engine
|
||||
cache.skip_ind = [];
|
||||
positions = round(p.positions(p.scanidxs{scan_id},:));
|
||||
cache.oROI_s{1}{1} = uint32(positions(:,1));
|
||||
cache.oROI_s{1}{2} = uint32(positions(:,2));
|
||||
obj_proj = engines.GPU.shared.get_views(object, obj_proj, 1,1,int32(1:Npos),cache);
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
if Nmodes == 1 && ~verLessThan('matlab', '9.4')
|
||||
% faster MEX based function
|
||||
positions = int32(p.positions(p.scanidxs{scan_id},:));
|
||||
indices = int32(1:Npos);
|
||||
obj_proj = utils.get_from_3D_projection(obj_proj,object,positions,indices);
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
verbose(3, 'Using slow nonMEX version of get_projections')
|
||||
id_0 = p.scanidxs{scan_id}(1)-1;
|
||||
for jj = p.scanidxs{scan_id}
|
||||
Indy = round(p.positions(jj,1)) + (1:p.asize(1));
|
||||
Indx = round(p.positions(jj,2)) + (1:p.asize(2));
|
||||
obj_proj(:,:,jj-id_0,:) = object(Indy,Indx,:);
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
@@ -0,0 +1,110 @@
|
||||
%HERMITE_LIKE
|
||||
% Receives a probe and maximum x and y order M N. Based on the given probe
|
||||
% and multiplying by a Hermitian function new modes are computed. The modes
|
||||
% are then orthonormalized.
|
||||
%
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function H = hermite_like(fundam,X,Y,M,N)
|
||||
import plotting.c2image
|
||||
|
||||
% corresponding to this. Returns all
|
||||
|
||||
m = [0:M];
|
||||
n = [0:N];
|
||||
|
||||
% fundam = abs(probe);
|
||||
|
||||
cenx = sum(sum(X.*abs(fundam).^2))/sum(sum(abs(fundam).^2));
|
||||
ceny = sum(sum(Y.*abs(fundam).^2))/sum(sum(abs(fundam).^2));
|
||||
varx = sum(sum((X-cenx).^2.*abs(fundam).^2))/sum(sum(abs(fundam).^2));
|
||||
vary = sum(sum((Y-ceny).^2.*abs(fundam).^2))/sum(sum(abs(fundam).^2));
|
||||
|
||||
counter = 1;
|
||||
|
||||
% Create basis
|
||||
for nii = n
|
||||
for mii = m
|
||||
auxfunc = ((X-cenx).^mii).*((Y-ceny).^nii).*fundam;
|
||||
if counter == 1
|
||||
auxfunc = auxfunc/sqrt(sum(abs(auxfunc(:)).^2));
|
||||
else
|
||||
auxfunc = auxfunc.*exp(-((X-cenx).^2/(2*varx))-((Y-ceny).^2/(2*vary)));
|
||||
auxfunc = auxfunc/sqrt(sum(abs(auxfunc(:)).^2));
|
||||
end
|
||||
|
||||
% Now make it orthogonal to the previous ones
|
||||
for ii = 1:counter-1 % The other ones
|
||||
auxfunc = auxfunc - H(:,:,ii)*sum(sum(H(:,:,ii).*conj(auxfunc),1),2);
|
||||
end
|
||||
auxfunc = auxfunc/sqrt(sum(abs(auxfunc(:)).^2));
|
||||
H(:,:,counter) = auxfunc;
|
||||
index(counter,:) = [mii nii];
|
||||
|
||||
% figure(1)
|
||||
% subplot(3,3,counter)
|
||||
% imagesc(c2image(H(:,:,counter)));
|
||||
% title(num2str(index(counter,:)))
|
||||
% axis xy equal tight
|
||||
|
||||
counter = counter+1;
|
||||
end
|
||||
end
|
||||
|
||||
% hermite_gauss - Recieves X, Y and gaussian waist (w) and computes the
|
||||
% Hermite Gauss beam
|
||||
end
|
||||
|
||||
@@ -0,0 +1,351 @@
|
||||
%INITIAL_CHECKS set default values for the most common variables
|
||||
%
|
||||
% ** p p structure
|
||||
%
|
||||
% returns:
|
||||
% ++ p p structure
|
||||
%
|
||||
% see also: core.initialize_ptycho
|
||||
%
|
||||
|
||||
function [p] = initial_checks(p)
|
||||
|
||||
|
||||
import utils.*
|
||||
import io.*
|
||||
|
||||
%%%%%%%%%%%%%
|
||||
%% General %%
|
||||
%%%%%%%%%%%%%
|
||||
|
||||
% check matlab version
|
||||
check_matlab_version('9.3');
|
||||
|
||||
if ~isfield(p, 'use_display') || isempty(p.use_display)
|
||||
if verbose > 1
|
||||
p.use_display = true;
|
||||
else
|
||||
p.use_display = false;
|
||||
end
|
||||
end
|
||||
|
||||
if ~usejava('desktop')
|
||||
% test if matlab was called with -nodisplay option, if yes then
|
||||
% use_display should be false
|
||||
p.use_display = false;
|
||||
end
|
||||
|
||||
% check if fourier ptycho recon is needed
|
||||
if ~isfield(p, 'fourier_ptycho')
|
||||
p.fourier_ptycho = false;
|
||||
end
|
||||
|
||||
if ~isfield(p, 'sample_rotation_angles')
|
||||
p.sample_rotation_angles = [0,0,0]; % 3x1 vector rotation around [X,Y,beam] axes in degrees , apply a correction accounting for tilted plane oR the sample and ewald sphere curvature (high NA correction)
|
||||
end
|
||||
|
||||
|
||||
%%% Derived quantities %%%
|
||||
assert(~isempty(p.energy), 'Provide p.energy or source of metadata p.src_metadata')
|
||||
|
||||
% modified by YJ for electron pty
|
||||
if isfield(p,'beam_source') && strcmp(p.beam_source, 'electron')
|
||||
%use relativistic corrected formula for electron pty
|
||||
p.lambda = 12.3986/sqrt((2*511.0+p.energy).*p.energy); %angstrom
|
||||
else
|
||||
p.lambda = 1.23984193e-9/p.energy; % wavelength
|
||||
end
|
||||
if isscalar(p.asize); p.asize = [p.asize p.asize]; end
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%
|
||||
%% Scan meta data %%
|
||||
%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
% calculate fourier ptycho geometry
|
||||
if p.fourier_ptycho
|
||||
if ~isfield(p, 'FP_focal_distance')
|
||||
error('For running Fourier Ptychography, please specify the focal length of your objective lens (p.FP_focal_distance)');
|
||||
end
|
||||
if ~get_option(p, 'z_lens')
|
||||
p.z_lens = 1/(1/(p.FP_focal_distance)-1/(p.z));
|
||||
end
|
||||
end
|
||||
|
||||
%%%%%%%%%%%%%%%%
|
||||
%% Scan queue %%
|
||||
%%%%%%%%%%%%%%%%
|
||||
|
||||
% number of attempts to reconstruct the given dataset
|
||||
if ~isfield(p.queue, 'max_attempts')
|
||||
p.queue.max_attempts = 5;
|
||||
end
|
||||
|
||||
% lock files
|
||||
if ~isfield(p.queue, 'lockfile') || isempty(p.queue.lockfile)
|
||||
if verbose > 2
|
||||
p.queue.lockfile = false;
|
||||
else
|
||||
p.queue.lockfile = true;
|
||||
end
|
||||
end
|
||||
|
||||
if ~isfield(p.queue, 'file_queue_timeout')
|
||||
p.queue.file_queue_timeout = 10; % time to wait for a new dataset in queue
|
||||
end
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%
|
||||
%% Data preparation %%
|
||||
%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
% data prefix
|
||||
if isempty(p.detector.data_prefix)
|
||||
import beamline.identify_eaccount %% not included in the ptychoshelves package
|
||||
eaccount = identify_eaccount;
|
||||
if ~isempty(eaccount) && eaccount(1) == 'e'
|
||||
% default setting for cSAXS beamline
|
||||
p.detector.data_prefix = [eaccount '_1_'];
|
||||
else
|
||||
verbose(3,'p.detector.data_prefix is not defined')
|
||||
end
|
||||
end
|
||||
|
||||
% suffix for prepared data file
|
||||
if ~isfield(p.prepare, 'prep_data_suffix')
|
||||
p.prepare.prep_data_suffix = '';
|
||||
end
|
||||
|
||||
if p.asize(1) ~= p.asize(2) && (~isfield(p.prepare, 'data_preparator') || any(strcmpi(p.prepare.data_preparator, {'python', 'libDetXR','json'})))
|
||||
p.prepare.data_preparator = 'matlab_ps';
|
||||
verbose(1, 'Python preparator does not support asymmetric probe dimensions, switching to matlab_ps')
|
||||
end
|
||||
|
||||
if p.asize(1) ~= p.asize(2) && p.prepare.force_preparation_data == false
|
||||
verbose(1, 'Loading prepared data is not supported for asymmetric p.asize, enforce load from raw data ')
|
||||
p.prepare.force_preparation_data = true;
|
||||
end
|
||||
|
||||
|
||||
% data preparator
|
||||
if ~isfield(p.prepare, 'data_preparator') || any(strcmpi(p.prepare.data_preparator, {'python', 'libDetXR','json'}))
|
||||
p.prepare.data_preparator = 'libDetXR';
|
||||
verbose(3, 'Using python data preparator.')
|
||||
elseif any(strcmpi(p.prepare.data_preparator, {'matlab', 'matlab_ps','mex'}))
|
||||
p.prepare.data_preparator = 'matlab_ps';
|
||||
verbose(3, 'Using matlab data preparator.')
|
||||
elseif any(strcmpi(p.prepare.data_preparator, {'matlab_aps'})) %% adde by YJ
|
||||
p.prepare.data_preparator = 'matlab_aps';
|
||||
verbose(3, 'Using matlab APS data preparator.')
|
||||
elseif any(strcmpi(p.prepare.data_preparator, {'matlab_aps_lynx'})) %% adde by YJ
|
||||
p.prepare.data_preparator = 'matlab_aps_lynx';
|
||||
verbose(3, 'Using matlab APS-LYNX data preparator.')
|
||||
|
||||
else
|
||||
error('Unknown data preparator %s', p.prepare.data_preparator);
|
||||
end
|
||||
|
||||
|
||||
if ~isfield(p.prepare,'data_preparator') || isempty(p.prepare.data_preparator)
|
||||
error(' p.prepare.data_preparator is not set')
|
||||
end
|
||||
|
||||
if strcmpi(p.prepare.data_preparator, 'matlab')
|
||||
p.prepare.data_preparator = 'matlab_ps';
|
||||
elseif strcmpi(p.prepare.data_preparator, 'python')
|
||||
p.prepare.data_preparator = 'libDetXR';
|
||||
end
|
||||
|
||||
% binning is only supported by Matlab data preparation
|
||||
if isfield(p.detector,'binning')&& p.detector.binning
|
||||
p.prepare.data_preparator = 'matlab_ps';
|
||||
verbose(1, 'Using binning %ix%i, switching to matlab data loading', 2^p.detector.binning, 2^p.detector.binning)
|
||||
else
|
||||
p.detector.binning = false;
|
||||
end
|
||||
|
||||
% binning is only supported by Matlab data preparation
|
||||
if isfield(p.detector,'upsampling') && p.detector.upsampling
|
||||
if strcmp(p.prepare.data_preparator,'matlab_ps')
|
||||
%p.prepare.data_preparator = 'matlab_ps';
|
||||
p.prepare.data_preparator = 'matlab_aps'; %modified by YJ for APS data
|
||||
end
|
||||
verbose(1, 'Using data upsampling %ix%i, switching to matlab data loading', 2^p.detector.upsampling, 2^p.detector.upsampling)
|
||||
else
|
||||
p.detector.upsampling = false;
|
||||
end
|
||||
|
||||
% prealignment for Fourier Ptychography
|
||||
if check_option(p, 'FP_focal_distance')
|
||||
p. fourier_ptycho = true; % set to true for Fourier Ptychography
|
||||
else
|
||||
p. fourier_ptycho = false;
|
||||
end
|
||||
|
||||
if ~isfield(p, 'prealign_FP')
|
||||
p.prealign_FP = false;
|
||||
end
|
||||
|
||||
% Fourier Ptycho is only supported by Matlab data preparation
|
||||
if p.fourier_ptycho
|
||||
p.prepare.data_preparator = 'matlab_ps';
|
||||
verbose(1, 'Switching to matlab data loading for Fourier Ptycho.')
|
||||
|
||||
% set prealign_data to true if not distortion correction is available
|
||||
if p.prealign_FP && ~p.prealign.prealign_data && isempty(p.prealign.distortion_corr)
|
||||
p.prealign.prealign_data = true;
|
||||
end
|
||||
end
|
||||
|
||||
% set defaults for matlab_ps
|
||||
if strcmpi(p.prepare.data_preparator, 'matlab_ps')
|
||||
if ~isfield(p.io, 'data_precision')
|
||||
p.io.data_precision = 'single';
|
||||
end
|
||||
if ~isfield(p.io, 'data_nthreads')
|
||||
p.io.data_nthreads = 2;
|
||||
end
|
||||
end
|
||||
|
||||
if isfield(p, 'prop_regime') && ~ismember(p.prop_regime, {'nearfield', 'farfield'})
|
||||
error(['Nonexistent propagation regime ', p.prop_regime ])
|
||||
end
|
||||
|
||||
% store prepared data
|
||||
if ~isfield(p.prepare, 'store_prepared_data')
|
||||
p.prepare.store_prepared_data = true;
|
||||
end
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%
|
||||
%% Scan positions %%
|
||||
%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
% load positions from prepared file
|
||||
if ~isfield(p.io, 'load_prep_pos')
|
||||
p.io.load_prep_pos = false;
|
||||
end
|
||||
|
||||
%%%%%%%%%
|
||||
%% I/O %%
|
||||
%%%%%%%%%
|
||||
|
||||
% file compression
|
||||
if ~isfield(p.io, 'file_compression')
|
||||
p.io.file_compression = 0;
|
||||
end
|
||||
if ~isfield(p.io, 'data_compression')
|
||||
p.io.data_compression = 3;
|
||||
end
|
||||
|
||||
|
||||
% run name
|
||||
if ~check_option(p, 'run_name')
|
||||
% check if prefix is defined
|
||||
if isempty(p.prefix)
|
||||
if iscell(p.scan_str)
|
||||
p.prefix = p.scan_str{1};
|
||||
else
|
||||
p.prefix = p.scan_str;
|
||||
end
|
||||
end
|
||||
p.run_name = sprintf('%s_%s', p.prefix, datestr(now, 'yyyy_mm_dd'));
|
||||
end
|
||||
verbose(3, 'run_name = %s', p.run_name);
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%
|
||||
%% Reconstruction %%
|
||||
%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
% backward compatibilty for initial_iterate
|
||||
if isfield(p, 'initial_iterate') && ~isfield(p, 'initial_iterate_object')
|
||||
p.initial_iterate_object = p.initial_iterate;
|
||||
p = rmfield(p, 'initial_iterate');
|
||||
end
|
||||
if isfield(p, 'initial_iterate_file') && ~isfield(p, 'initial_iterate_object_file')
|
||||
p.initial_iterate_object_file = p.initial_iterate_file;
|
||||
p = rmfield(p, 'initial_iterate_file');
|
||||
end
|
||||
|
||||
% model probe
|
||||
if ~isfield(p.model, 'probe_central_stop')
|
||||
p.model.probe_central_stop = false;
|
||||
end
|
||||
|
||||
if ~isfield(p.model, 'probe_central_stop_diameter') && p.model.probe_central_stop
|
||||
p.model.probe_central_stop_diameter = 50e-6;
|
||||
end
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%
|
||||
%% Plot and save %%
|
||||
%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
% plot prepared data
|
||||
if ~isfield(p.plot, 'prepared_data') || (isfield(p.plot, 'prepared_data')&& isempty(p.plot.prepared_data))
|
||||
if p.verbose_level > 2
|
||||
p.plot.prepared_data = true;
|
||||
else
|
||||
p.plot.prepared_data = false;
|
||||
end
|
||||
end
|
||||
|
||||
% plotting
|
||||
if ~isfield(p.plot, 'interval') || isempty(p.plot.interval)
|
||||
if verbose > 2
|
||||
p.plot.interval = 10;
|
||||
else
|
||||
p.plot.interval = 200;
|
||||
end
|
||||
end
|
||||
|
||||
% external call to save figures
|
||||
if ~isfield(p.save, 'external')
|
||||
p.save.external = false;
|
||||
end
|
||||
|
||||
% propagation and apodization
|
||||
if ~isfield(p.plot, 'obj_apod')
|
||||
p.plot.obj_apod = false;
|
||||
end
|
||||
if ~isfield(p.plot, 'prop_obj')
|
||||
p.plot.prop_obj = 0;
|
||||
end
|
||||
|
||||
% calculate FSC
|
||||
if ~isfield(p.plot, 'calc_FSC')
|
||||
p.plot.calc_FSC = false;
|
||||
end
|
||||
if ~isfield(p.plot, 'show_FSC')
|
||||
p.plot.show_FSC = utils.verbose>2;
|
||||
end
|
||||
if ~isfield(p.plot, 'probe_spectrum')|| isempty(p.plot.probe_spectrum)
|
||||
p.plot.probe_spectrum = utils.verbose>2;
|
||||
end
|
||||
if ~isfield(p.plot, 'object_spectrum')|| isempty(p.plot.object_spectrum)
|
||||
p.plot.object_spectrum = utils.verbose>2;
|
||||
end
|
||||
if ~isfield(p.save, 'store_images_ids' )|| isempty(p.save.store_images_ids)
|
||||
p.save.store_images_ids = 1:4;
|
||||
end
|
||||
|
||||
|
||||
%%%%%%%%%%%%%
|
||||
%% Engines %%
|
||||
%%%%%%%%%%%%%
|
||||
|
||||
% at least one engine has to be specified
|
||||
if ~isfield(p, 'engines')
|
||||
error('At least one reconstruction engine has to be selected. Please check your template.')
|
||||
end
|
||||
|
||||
|
||||
|
||||
% first engine is external
|
||||
p.external_engine0 = strcmpi(p.engines{1}.name, 'c_solver') || ...
|
||||
(isfield(p.engines{1}, 'external') && p.engines{1}.external);
|
||||
|
||||
if ~isfield(p,'remove_scaling_ambiguity')
|
||||
% if true. try to keep norm(probe) constant during the reconstruction
|
||||
p.remove_scaling_ambiguity = true;
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
%INITIALIZE_PTYCHO
|
||||
% everything that needs to be done before triggering the reconstruction. This includes
|
||||
% inter alia initial checks, intial guess preparations and loading the data.
|
||||
%
|
||||
% ** p p structure
|
||||
%
|
||||
% returns:
|
||||
% ++ p p structure
|
||||
% ++ status status flag
|
||||
%
|
||||
%
|
||||
% see also: core.ptycho_recons
|
||||
%
|
||||
% Based on cSAXS code, modified by Yi Jiang
|
||||
|
||||
function [ p, status ] = initialize_ptycho( p )
|
||||
|
||||
import utils.*
|
||||
import io.*
|
||||
|
||||
%%% read meta data %%%
|
||||
if ~isfield(p, 'src_metadata')
|
||||
verbose(0,' p.src_metadata is not set, using default p.src_metadata = ''spec''')
|
||||
p. src_metadata = 'spec'; % load meta data from file; currently only 'spec' is supported;
|
||||
end
|
||||
|
||||
% check store_images flag
|
||||
if ~isfield(p.save, 'store_images')
|
||||
p.save.store_images = true;
|
||||
end
|
||||
if ~p.save.store_images
|
||||
close all
|
||||
end
|
||||
|
||||
% prepare container for meta data
|
||||
assert( isnumeric(p.scan_number), 'p.scan_number has to contain an integer number')
|
||||
p.numscans = length(p.scan_number); % Number of scans
|
||||
p.meta = cell(1,length(p.scan_number));
|
||||
|
||||
p = scans.read_metadata(p);
|
||||
|
||||
for ii = 1:p.numscans
|
||||
p. scan_str{ii} = sprintf(p.scan_string_format, p.scan_number(ii)); % Scan string
|
||||
end
|
||||
|
||||
% write procID
|
||||
write_procID(p);
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%% Checks and defaults %%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
p = core.initial_checks(p);
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%%%%%%%%%%%%%%% LOAD DATA %%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
%%% prepare paths, note that it was already initialized in ptycho_recons %%%
|
||||
|
||||
p = core.ptycho_prepare_paths(p);
|
||||
|
||||
|
||||
%%% load detector settings %%%
|
||||
p = detector.load_detector(p);
|
||||
|
||||
|
||||
if isfield(p, 'ds') && ~isempty(p.ds)
|
||||
warning(['Defining ds in the template is not supported anymore and ' ...
|
||||
'will not change the pixel size. Please make sure '...
|
||||
'that it is set correctly in +detector/+%s/%s.m and remove ds from your template.'], p.detector, p.detector)
|
||||
end
|
||||
for ii=1:length(p.detectors)
|
||||
assert(p.detectors(1).params.pixel_size==p.detectors(ii).params.pixel_size, 'Different detector pixel sizes are not supported at the moment.')
|
||||
end
|
||||
p.ds = p.detectors(1).params.pixel_size;
|
||||
|
||||
|
||||
if check_option(p, 'prop_regime', 'nearfield')
|
||||
% nearfield ptychography
|
||||
assert(check_option(p,'focus_to_sample_distance'), 'Undefined p.focus_to_sample_distance that is required for nearfield ptychography')
|
||||
p.nearfield_magnification = (p.z-p.focus_to_sample_distance)/p.focus_to_sample_distance;
|
||||
verbose(1, 'Propagation in nearfield regime, magnification = %g', p.nearfield_magnification)
|
||||
p.dx_spec = [p.ds,p.ds] / p.nearfield_magnification;
|
||||
p.z = p.z / p.nearfield_magnification;
|
||||
else
|
||||
% standard farfield ptychography
|
||||
% modified by YJ for electron pty
|
||||
if isfield(p,'beam_source') && strcmp(p.beam_source, 'electron')
|
||||
if isfield(p,'dk') %A^-1/pix
|
||||
p.dx_spec = 1./p.asize./p.dk; %angstrom
|
||||
elseif isfield(p,'d_alpha') % mrad/pix
|
||||
p.dx_spec = 1./p.asize./(p.d_alpha/1e3/p.lambda); %angstrom
|
||||
else
|
||||
error('dk or d_alpha are not speficied!')
|
||||
end
|
||||
else
|
||||
p.dx_spec = p.lambda*p.z ./ (p.asize*p.ds); % resolution in the specimen plane
|
||||
end
|
||||
p.dx_spec = p.dx_spec ./ cosd(p.sample_rotation_angles(1:2)); % account for a tilted sample ptychography
|
||||
end
|
||||
|
||||
|
||||
%%% prepare positions %%%
|
||||
p = scans.read_positions(p);
|
||||
|
||||
%%% find which positions belongs to each object
|
||||
p = core.find_shared_IDs(p);
|
||||
|
||||
|
||||
%%% prepare positions
|
||||
% Prepare positions, note the output is already in probe positions which
|
||||
% are different from object (scan) positions by a minus sign
|
||||
p = core.ptycho_adjust_positions(p);
|
||||
% p.positions_orig = p.positions;
|
||||
% p.numpts_orig = p.numpts;
|
||||
p.numpos = sum(p.numpts);
|
||||
|
||||
|
||||
p.asize_nobin = p.asize;
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%% prepare scans %%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
% make sure that all scans have a ctr
|
||||
numctr = size(p.ctr,1);
|
||||
if p.numscans > numctr
|
||||
for ii=numctr+1:p.numscans
|
||||
p.ctr(end+1,:) = p.ctr(numctr,:);
|
||||
end
|
||||
elseif p.numscans < numctr
|
||||
p.ctr(p.numscans+1:end,:) = [];
|
||||
end
|
||||
|
||||
%%%% load data, mask and generate initial estimate of the probe
|
||||
if p.prepare.auto_prepare_data
|
||||
[p, status]=core.ptycho_prepare_scans(p);
|
||||
else
|
||||
if ~isa(p.prepare.prepare_data_function, 'function_handle')
|
||||
error(['Expected function handle as p.prepare.prepare_data_function. '...
|
||||
'Please update p.prepare.auto_prepare_data or set p.prepare.auto_prepare_data=true.'])
|
||||
else
|
||||
[p, status] = p.prepare.prepare_data_function(p);
|
||||
end
|
||||
end
|
||||
if ~status
|
||||
return
|
||||
end
|
||||
|
||||
% Added by YJ: remove bad data with very low counts
|
||||
% p.avg_photon_threshold is defined same as the one in GPU engines
|
||||
if isfield(p, 'avg_photon_threshold') && p.avg_photon_threshold > 0
|
||||
diffraction = (single(p.fmag .* p.fmask) / single(p.renorm) ).^2;
|
||||
good_dp_ind = squeeze(sum(sum(diffraction)) / prod(p.asize) >= p.avg_photon_threshold);
|
||||
|
||||
%remove bad scan points from p
|
||||
p.positions_real = p.positions_real(good_dp_ind,:);
|
||||
p.positions_orig = p.positions_orig(good_dp_ind,:);
|
||||
p.positions = p.positions(good_dp_ind,:);
|
||||
p.fmag = p.fmag(:,:,good_dp_ind);
|
||||
p.fmask = p.fmask(:,:,good_dp_ind);
|
||||
|
||||
low_count_dp_ind = find((1-good_dp_ind)==1);
|
||||
for ii=1:length(p.scanidxs)
|
||||
scan_ind_temp = p.scanidxs{ii};
|
||||
N_scan_pts = length(scan_ind_temp);
|
||||
[val, pos]=intersect(scan_ind_temp,low_count_dp_ind);
|
||||
num_bad_pts = length(val); % get the # of bad pts for current scan
|
||||
p.share_pos{ii}(pos,:) = []; %remove positions for current scan
|
||||
if ii == 1
|
||||
scanidxs_lb = 1;
|
||||
else
|
||||
scanidxs_lb = p.scanidxs{ii-1}(end)+1;
|
||||
end
|
||||
p.numpts(ii) = N_scan_pts-num_bad_pts;
|
||||
p.scanindexrange(ii,:) = [scanidxs_lb, scanidxs_lb+p.numpts(ii)-1];
|
||||
p.scanidxs{ii} = p.scanindexrange(ii,1):p.scanindexrange(ii,2);
|
||||
end
|
||||
|
||||
p.numpos = sum(p.numpts);
|
||||
|
||||
%store indices for bad data
|
||||
p.low_count_dp = 1-good_dp_ind;
|
||||
|
||||
if any(p.low_count_dp)
|
||||
verbose(1, 'Remove %d diffraction pattern(s) with low counts', sum(p.low_count_dp))
|
||||
end
|
||||
end
|
||||
|
||||
% Added by YJ: remove bad data with very high counts
|
||||
% p.avg_photon_threshold_ub is defined similar to p.avg_photon_threshold
|
||||
if isfield(p, 'avg_photon_threshold_ub') && p.avg_photon_threshold_ub > 0 && p.avg_photon_threshold_ub < inf
|
||||
diffraction = (single(p.fmag .* p.fmask) / single(p.renorm) ).^2;
|
||||
good_dp_ind = squeeze(sum(sum(diffraction)) / prod(p.asize) <= p.avg_photon_threshold_ub);
|
||||
|
||||
%remove bad scan points from p
|
||||
p.positions_real = p.positions_real(good_dp_ind,:);
|
||||
p.positions_orig = p.positions_orig(good_dp_ind,:);
|
||||
p.positions = p.positions(good_dp_ind,:);
|
||||
p.fmag = p.fmag(:,:,good_dp_ind);
|
||||
p.fmask = p.fmask(:,:,good_dp_ind);
|
||||
|
||||
high_count_dp_ind = find((1-good_dp_ind)==1);
|
||||
for ii=1:length(p.scanidxs)
|
||||
scan_ind_temp = p.scanidxs{ii};
|
||||
N_scan_pts = length(scan_ind_temp);
|
||||
[val, pos]=intersect(scan_ind_temp,high_count_dp_ind);
|
||||
num_bad_pts = length(val); % get the # of bad pts for current scan
|
||||
p.share_pos{ii}(pos,:) = []; %remove positions for current scan
|
||||
if ii == 1
|
||||
scanidxs_lb = 1;
|
||||
else
|
||||
scanidxs_lb = p.scanidxs{ii-1}(end)+1;
|
||||
end
|
||||
p.numpts(ii) = N_scan_pts-num_bad_pts;
|
||||
p.scanindexrange(ii,:) = [scanidxs_lb, scanidxs_lb+p.numpts(ii)-1];
|
||||
p.scanidxs{ii} = p.scanindexrange(ii,1):p.scanindexrange(ii,2);
|
||||
end
|
||||
|
||||
p.numpos = sum(p.numpts);
|
||||
|
||||
%store indices for bad data
|
||||
p.high_count_dp = 1-good_dp_ind;
|
||||
|
||||
if any(p.high_count_dp)
|
||||
verbose(1, 'Remove %d diffraction pattern(s) with high counts', sum(p.high_count_dp))
|
||||
end
|
||||
end
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%% plot prepared data %%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
if p.plot.prepared_data && p.use_display
|
||||
core.analysis.plot_raw_data(p)
|
||||
end
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%% Plot initial guess %%%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
% Define combined strings for figure title
|
||||
p.plot.obtitlestring = '';
|
||||
p.plot.prtitlestring = '';
|
||||
p.plot.errtitlestring = '';
|
||||
if p.share_object
|
||||
p.plot.obtitlestring = [core.generate_scan_name(p) ' '];
|
||||
end
|
||||
if p.share_probe
|
||||
p.plot.prtitlestring = [core.generate_scan_name(p) ' '];
|
||||
end
|
||||
p.plot.errtitlestring = [core.generate_scan_name(p) ' '];
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%% Plot initial guess %%%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
if p.use_display
|
||||
p.plot.extratitlestring = sprintf(' (%dx%d) - Initial guess', p.asize(2), p.asize(1));
|
||||
core.analysis.plot_results(p, 'use_display', p.use_display);
|
||||
end
|
||||
p.plot.extratitlestring = sprintf(' (%dx%d)', p.asize(2), p.asize(1));
|
||||
|
||||
if ~isfield(p.plot, 'windowautopos')
|
||||
p.plot.windowautopos = false; % So resizing after first time display is respected
|
||||
end
|
||||
|
||||
verbose(1, 'Finished data preparation and initialization.')
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
%PREP_H5DATA prepare data and save it to disk
|
||||
% prep_h5data expects that fmask and fmag already exist, prepares them
|
||||
% for the C++ code and saves everything to disk.
|
||||
%
|
||||
% ** p p structure
|
||||
%
|
||||
% see also: core.ptycho_prepare_scans
|
||||
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function prep_h5data(p)
|
||||
import utils.verbose
|
||||
import io.HDF.save2hdf5
|
||||
|
||||
|
||||
fmask = p.fmask;
|
||||
fmag = p.fmag;
|
||||
|
||||
single_mask = true;
|
||||
for ii=1:size(fmask,3)-1
|
||||
if ~isequaln(fmask(:,:,ii),fmask(:,:,ii+1))
|
||||
single_mask = false;
|
||||
break;
|
||||
end
|
||||
end
|
||||
|
||||
%%%%% Prepare object and probe for hdf5 file %%%%%
|
||||
for obnum = p.share_object_ID
|
||||
object_c(obnum) = struct('data',p.object{obnum}(:,:,1));
|
||||
end
|
||||
for prnum = p.share_probe_ID
|
||||
probe_c(prnum) = struct('data',p.probes(:,:,prnum));
|
||||
end
|
||||
|
||||
|
||||
%%%%% Prepare data for hdf5 file %%%%%
|
||||
bad_pixels = cell(p.numscans,1);
|
||||
bad_pixels_index = cell(p.numscans,1);
|
||||
% Assumes that detector position is the same within a scan
|
||||
for ii = 1:p.numscans % loop over scans
|
||||
|
||||
|
||||
% Prepare structure for detector %
|
||||
% Here I detect the module gaps, can be later given by the
|
||||
% prepare_data function
|
||||
fmaski = fmask(:,:,p.scanindexrange(ii,1)); % First mask to detect modules (gaps)
|
||||
auxmodxo = any(fmaski,1);
|
||||
if auxmodxo(1)
|
||||
indbeginmodx = 1;
|
||||
else
|
||||
indbeginmodx = [];
|
||||
end
|
||||
auxmodx = diff(auxmodxo);
|
||||
indbeginmodx = [indbeginmodx find(auxmodx==1)+1];
|
||||
nummodx = length(indbeginmodx);
|
||||
indendmodx = find(auxmodx==-1);
|
||||
if auxmodxo(end)
|
||||
indendmodx = [indendmodx p.asize(2)];
|
||||
end
|
||||
|
||||
auxmodyo = any(fmaski,2);
|
||||
if auxmodyo(1)
|
||||
indbeginmody = 1;
|
||||
else
|
||||
indbeginmody = [];
|
||||
end
|
||||
auxmody = diff(auxmodyo);
|
||||
indbeginmody = [indbeginmody find(auxmody==1).'+1];
|
||||
nummody = length(indbeginmody);
|
||||
indendmody = find(auxmody==-1).';
|
||||
if auxmodyo(end)
|
||||
indendmody = [indendmody p.asize(1)];
|
||||
end
|
||||
|
||||
modulearray = zeros(nummody*nummodx,4);
|
||||
fmaskdet = zeros(p.asize); % Module mask for current detector position
|
||||
counter = 0;
|
||||
for kk = 1:nummody
|
||||
for jj = 1:nummodx
|
||||
counter = counter+1;
|
||||
numrows = indendmody(kk) - indbeginmody(kk) + 1;
|
||||
numcols = indendmodx(jj) - indbeginmodx(jj) + 1;
|
||||
fmaskdet(indbeginmody(kk):indendmody(kk),indbeginmodx(jj):indendmodx(jj))=1;
|
||||
modulearray(counter,:) = [numrows,numcols,indbeginmody(kk)-1,indbeginmodx(jj)-1]; %% Minus one to go to indexing convention in C
|
||||
end
|
||||
end
|
||||
|
||||
verbose(3,['Detected ' num2str(nummodx*nummody) ' modules'])
|
||||
if verbose >= 3
|
||||
disp([num2str(modulearray)])
|
||||
end
|
||||
|
||||
%%% Here there is the posibility to add bad pixels that are common
|
||||
%%% to all diffraction patterns. Could be identified in prepare
|
||||
%%% data
|
||||
%detector(ii) = struct('rows', uint32(192), 'columns', uint32(192), 'modules', transpose(uint32([192,192,0,0])), 'bad_pixels', transpose(uint32([9,10; 11,12; 13,14])));
|
||||
detector(ii) = struct('rows', uint32(p.asize(1)), 'columns', uint32(p.asize(2)),...
|
||||
'modules', transpose(uint32(modulearray)),'bad_pixels',uint32([]));
|
||||
|
||||
if ~single_mask
|
||||
idx = 0;
|
||||
for jj = p.scanindexrange(ii,1):p.scanindexrange(ii,2) % loop over corresponding diffraction patterns
|
||||
[y, x] = find(1+fmask(:,:,jj)-fmaskdet==0);
|
||||
bps = transpose(reshape([y, x], length(x), 2))-1;
|
||||
idx = length(bps)+idx;
|
||||
bad_pixels_index{ii} = [bad_pixels_index{ii} idx];
|
||||
bad_pixels{ii} = [bad_pixels{ii} bps];
|
||||
end
|
||||
else
|
||||
[y, x] = find(1+fmaski-fmaskdet==0);
|
||||
bad_pixels{ii} = transpose(reshape([y, x], length(x), 2))-1;
|
||||
end
|
||||
|
||||
% Prepare structure for measurement %
|
||||
% for jj = p.scanindexrange(ii,1):p.scanindexrange(ii,2) % loop over corresponding diffraction patterns
|
||||
% %%%%% Prepare bad pixels %%%%%
|
||||
% [y, x] = find(1+fmaski-fmaskdet==0);
|
||||
% bad_pixels(jj) = transpose(reshape([y, x], length(x), 2))-1;
|
||||
% measurement(jj) = struct('data', fmag(:,:,jj), 'position', uint32((p.positions(jj,:))),...
|
||||
% 'object', uint32(p.share_object_ID(ii)-1), 'probe', uint32(p.share_probe_ID(ii)-1),...
|
||||
% 'detector', uint32(ii-1));
|
||||
% end
|
||||
end
|
||||
|
||||
|
||||
%% prepare output
|
||||
|
||||
h5_struc = [];
|
||||
h5_struc.Attributes.format = 2;
|
||||
for ii=1:size(probe_c,2)
|
||||
h5_struc.probes(:,ii) = uint64(size(probe_c(ii).data));
|
||||
end
|
||||
for ii=1:size(object_c,2)
|
||||
h5_struc.objects(:,ii) = uint64(size(object_c(ii).data));
|
||||
end
|
||||
|
||||
|
||||
%% detectors
|
||||
h5_struc.detector = [];
|
||||
for ii=1:p.numscans
|
||||
temp = detector(ii);
|
||||
h5_struc.detector.(['n' num2str(ii-1)]).Attributes.rows = temp.rows;
|
||||
h5_struc.detector.(['n' num2str(ii-1)]).Attributes.columns = temp.columns;
|
||||
if single_mask && ~isempty(bad_pixels{ii})
|
||||
h5_struc.detector.(['n' num2str(ii-1)]).bad_pixels = bad_pixels{ii};
|
||||
end
|
||||
h5_struc.detector.(['n' num2str(ii-1)]).modules = temp.modules;
|
||||
|
||||
end
|
||||
|
||||
%% measurements
|
||||
h5_struc.measurement = [];
|
||||
h5_struc.measurement.Attributes.max_power = 1/p.renorm^2;
|
||||
|
||||
for ii=1:p.numscans
|
||||
% attributes
|
||||
h5_struc.measurement.(['n' num2str(ii-1)]).Attributes.detector = uint32(ii-1);
|
||||
h5_struc.measurement.(['n' num2str(ii-1)]).Attributes.probe = uint32(p.share_probe_ID(ii)-1);
|
||||
h5_struc.measurement.(['n' num2str(ii-1)]).Attributes.object = uint32(p.share_object_ID(ii)-1);
|
||||
h5_struc.measurement.(['n' num2str(ii-1)]).Attributes.max_sum = uint32(p.max_sum(ii));
|
||||
|
||||
% datasets
|
||||
h5_struc.measurement.(['n' num2str(ii-1)]).positions = uint32(transpose(round(p.positions(p.scanidxs{ii},:))));
|
||||
h5_struc.measurement.(['n' num2str(ii-1)]).data = permute((fmag(:,:,p.scanidxs{ii})/p.renorm).^2, [2 1 3]);
|
||||
if ~single_mask
|
||||
h5_struc.measurement.(['n' num2str(ii-1)]).bad_pixels = bad_pixels{ii};
|
||||
h5_struc.measurement.(['n' num2str(ii-1)]).bad_pixels_index.Value = uint64(transpose(bad_pixels_index{ii}));
|
||||
h5_struc.measurement.(['n' num2str(ii-1)]).bad_pixels_index.Attributes.save2hdf5DataShape = size(uint64(transpose(bad_pixels_index{ii})),1);
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
%% save to disk
|
||||
if ~exist(p.prepare_data_path, 'dir')
|
||||
mkdir(p.prepare_data_path)
|
||||
end
|
||||
verbose(2,'Writing H5 data file: %s',[p.prepare_data_path p.prepare_data_filename]);
|
||||
save2hdf5([p.prepare_data_path p.prepare_data_filename], h5_struc, 'overwrite', true, 'comp', p.io.data_compression);
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
%PREPARE_INITIAL_GUESS
|
||||
% prepare an initial guess for the object and probe reconstruction
|
||||
%
|
||||
% ** p p structure
|
||||
%
|
||||
% returns:
|
||||
% ++ p p structure
|
||||
%
|
||||
% see also: core.prepare_initial_guess
|
||||
%
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function [p] = prepare_initial_guess(p)
|
||||
import utils.verbose
|
||||
|
||||
verbose(1, 'Preparing initial guess.')
|
||||
|
||||
%% prepare objects
|
||||
|
||||
p = core.update_object_size(p);
|
||||
|
||||
p = core.prepare_initial_object(p);
|
||||
|
||||
%% prepare probes
|
||||
p = core.prepare_initial_probes(p);
|
||||
|
||||
if ~isfield(p,'center_probe')
|
||||
p.center_probe = false;
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
%PREPARE_INITIAL_OBJECT
|
||||
% prepare an initial guess for the object reconstruction
|
||||
%
|
||||
% ** p p structure
|
||||
%
|
||||
% returns:
|
||||
% ++ p p structure
|
||||
%
|
||||
% see also: core.prepare_initial_guess
|
||||
%
|
||||
|
||||
function [ p ] = prepare_initial_object( p )
|
||||
import utils.verbose
|
||||
import utils.crop_pad
|
||||
import utils.interpolateFT
|
||||
|
||||
if p.model_object
|
||||
switch p.model.object_type
|
||||
case 'rand'
|
||||
verbose(2,'Using random object as initial guess.')
|
||||
case 'amplitude'
|
||||
% create dummy object which will be overwritten once the
|
||||
% prepared data is available
|
||||
assert(p.fourier_ptycho, 'An initial guess based on the prepared data is only suited for Fourier ptychography.')
|
||||
end
|
||||
for obnum = 1:p.numobjs
|
||||
p.object{obnum} = (1+1i*1e-6*rand([p.object_size(obnum,:) p.object_modes])).*ones([p.object_size(obnum,:) p.object_modes]);
|
||||
end
|
||||
else
|
||||
if isfield(p, 'initial_iterate_object')
|
||||
warning('Loading initial object guess from file given by p.initial_iterate_object_file.')
|
||||
end
|
||||
verbose(2,'Using loaded object as initial guess.')
|
||||
|
||||
if numel(p.initial_iterate_object_file) ~= p.numobjs
|
||||
verbose(2,'Number of initial iterate files and number of objects does not match')
|
||||
for ii=numel(p.initial_iterate_object_file):p.numobjs
|
||||
p.initial_iterate_object_file{ii} = p.initial_iterate_object_file{end};
|
||||
end
|
||||
end
|
||||
|
||||
% make a bit smarter the use of initial_iterate_object_file and allow
|
||||
% some automatic patten filling + file search
|
||||
for obnum = unique(p.share_object_ID)
|
||||
% if string allows it, fill in the scan numbers
|
||||
p.initial_iterate_object_file{obnum} = sprintf(p.initial_iterate_object_file{obnum}, p.scan_number(obnum));
|
||||
if contains(p.initial_iterate_object_file{obnum}, '*') % if string contains wild character *, try to find the file
|
||||
fpath = dir(p.initial_iterate_object_file{obnum}) ;
|
||||
if isempty(fpath)
|
||||
warning('No file corresponding to pattern %s was found, using random initial guess', p.initial_iterate_object_file{obnum})
|
||||
p.object{obnum} = (1+1i*1e-6*rand([p.object_size(obnum,:) p.object_modes])).*ones([p.object_size(obnum,:) p.object_modes]);
|
||||
p.initial_iterate_object_file{obnum} = [];
|
||||
continue
|
||||
elseif length(fpath) > 1
|
||||
warning('Too many files corresponding to pattern %s were found, using the last', p.initial_iterate_object_file{obnum})
|
||||
fpath = fpath(end);
|
||||
end
|
||||
p.initial_iterate_object_file{obnum} = [fpath.folder,'/',fpath.name];
|
||||
end
|
||||
end
|
||||
|
||||
% load data from disk
|
||||
for ii = unique(p.share_object_ID) % avoid loading datasets twice
|
||||
if isempty(p.initial_iterate_object_file{ii})
|
||||
continue
|
||||
end
|
||||
if ~exist(p.initial_iterate_object_file{ii}, 'file')
|
||||
error(['Did not find initial iterate: ' p.initial_iterate_object_file{ii}])
|
||||
end
|
||||
|
||||
verbose(2,'Loading object %d from: %s',ii,p.initial_iterate_object_file{ii})
|
||||
S = io.load_ptycho_recons(p.initial_iterate_object_file{ii});
|
||||
object = double(S.object);
|
||||
% reinterpolate to the right pixel size
|
||||
if isfield(S, 'p') && any(S.p.dx_spec ~= p.dx_spec)
|
||||
verbose(2, 'Warning: Reinterpolate loaded object to new pixels size')
|
||||
object = interpolateFT(object, ceil(size(object(:,:,1)).*S.p.dx_spec./p.dx_spec));
|
||||
end
|
||||
|
||||
%%% check the object size
|
||||
if ~isequal(size(squeeze(object(:,:,1))), squeeze(p.object_size(ii,:)))
|
||||
% if the loaded dataset does not have the expected object size,
|
||||
% crop/pad it to p.object_size
|
||||
verbose(2, 'Warning: Object taken from file %s does not have the expected size of %d x %d.', ...
|
||||
p.initial_iterate_object_file{ii}, p.object_size(ii,1), ...
|
||||
p.object_size(ii,2))
|
||||
p.object{ii} = crop_pad(object, p.object_size(ii,:));
|
||||
else
|
||||
% the the object sizes are the same, just copy everything
|
||||
% to p.object
|
||||
p.object{ii} = object;
|
||||
end
|
||||
|
||||
% now let's check the object modes
|
||||
mode_diff = p.object_modes-size(object,3);
|
||||
if mode_diff > 0
|
||||
% add (random) object modes
|
||||
p.object{ii}(:,:,size(object,3)+1:p.object_modes,:) = (1+1i*1e-6*rand([p.object_size(ii,:) mode_diff])).*ones([p.object_size(ii,:) mode_diff]);
|
||||
elseif mode_diff < 0
|
||||
% modified by YJ. keep all layers for multi-layer object
|
||||
if isfield(p,'multiple_layers_obj') && p.multiple_layers_obj
|
||||
%add an extra axis that is needed by GPU_MS
|
||||
object_temp(:,:,1,:) = p.object{ii};
|
||||
p.object{ii} = object_temp;
|
||||
else
|
||||
% remove object modes
|
||||
p.object{ii}(:,:,p.object_modes+1:size(object,3),:) = [];
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,157 @@
|
||||
% Prepare probe - Only single file supported, either the file has a 3D matrix
|
||||
% of many probes or the probe will be repeated for the number of probes
|
||||
% needed for reconstruction
|
||||
|
||||
function [ p ] = prepare_initial_probes( p )
|
||||
|
||||
p = core.ptycho_model_probe(p);
|
||||
|
||||
p.probes = double(p.probe_initial);
|
||||
if size(p.probes,3) ~= p.numprobs
|
||||
p.probes = repmat(p.probes,[1 1 p.numprobs]);
|
||||
end
|
||||
% If prepared without modes, but reconstruction needs modes
|
||||
% allocate initial guess.
|
||||
if size(p.probes,4) ~= p.probe_modes
|
||||
% Determine mode energies
|
||||
Emod = zeros(p.probe_modes,1);
|
||||
for jj = 1:numel(Emod)-1
|
||||
if jj <= numel(p.mode_start_pow)
|
||||
Emod(jj+1) = p.mode_start_pow(jj);
|
||||
else
|
||||
Emod(jj+1) = p.mode_start_pow(end);
|
||||
end
|
||||
end
|
||||
% if (numel(p.mode_start_pow) == 1)||(numel(p.mode_start_pow) == p.probe_modes-1)
|
||||
% Emod(2:end) = p.mode_start_pow;
|
||||
if sum(Emod) > 1
|
||||
error('Energy distribution between modes exceeds 1, see p.mode_start_pow')
|
||||
else
|
||||
Emod(1) = 1-sum(Emod);
|
||||
end
|
||||
Emod_init = Emod;
|
||||
%disp(p.numprobs)
|
||||
for prnum = 1:p.numprobs
|
||||
% Determine the total energy of the probe first mode
|
||||
aux = p.probes(:,:,prnum,1);
|
||||
Etot = sum(abs(aux(:)).^2);
|
||||
Emod = Emod_init*Etot; % Now Emod has really the expected total sum
|
||||
|
||||
if strcmpi(p.mode_start,'rand')
|
||||
for prmode = 2:p.probe_modes
|
||||
p.probes(:,:,prnum,prmode) = p.probes(:,:,prnum,1).*(2*rand(p.asize)-1);
|
||||
end
|
||||
elseif strfind(p.mode_start,'herm')
|
||||
if strcmpi(p.mode_start,'herm')
|
||||
M = ceil(sqrt(p.probe_modes))-1;
|
||||
N = ceil(p.probe_modes/(M+1))-1;
|
||||
elseif strcmpi(p.mode_start,'hermver')
|
||||
M = 0;
|
||||
N = p.probe_modes-1;
|
||||
elseif strcmpi(p.mode_start,'hermhor')
|
||||
M = p.probe_modes-1;
|
||||
N = 0;
|
||||
else
|
||||
error('Unknown p.mode_start')
|
||||
end
|
||||
x = [1:size(p.probes,2)]-size(p.probes,2)/2;
|
||||
y = [1:size(p.probes,1)]-size(p.probes,1)/2;
|
||||
[X Y] = meshgrid(x,y);
|
||||
|
||||
H = core.hermite_like(squeeze(p.probes(:,:,prnum,1)),X,Y,M,N);
|
||||
if prnum == 1
|
||||
p.probes(:,:,:,2:p.probe_modes) = 0;
|
||||
end
|
||||
p.probes(:,:,prnum,2:p.probe_modes) = reshape(H(:,:,2:p.probe_modes),size(p.probes(:,:,prnum,2:p.probe_modes)));
|
||||
else
|
||||
error('Undefined p.mode_start')
|
||||
end
|
||||
% Normalization
|
||||
for prmode = 1:p.probe_modes
|
||||
p.probes(:,:,prnum,prmode) = p.probes(:,:,prnum,prmode)*sqrt(Emod(prmode)/(sum(sum(abs(p.probes(:,:,prnum,prmode)).^2))));
|
||||
end
|
||||
|
||||
% p. mode_start_pow = [0.02] ; % Integrated intensity on modes. Can be a number (all modes equal) or a vector
|
||||
% p. mode_start = 'rand' % (for probe) = 'rand', = 'her' (Hermitian-like base), = 'herver' (vertical modes only), = 'herhor' (horizontal modes only)
|
||||
% p. mode_her_ord = []; % (for probe) Specify a 2xn vector with the (m,n) starting orders, leave = [] for default
|
||||
% p.probes(:,:,:,prmode) = p.probes(:,:,:,1).*(1+0.01.*rand(p.asize))*0.5;
|
||||
% p.probes(:,:,:,prmode) = p.probes(:,:,:,1).*exp(1i*0.1*pi.*rand(p.asize))*0.1;
|
||||
% p.probes(:,:,:,prmode) = p.probes(:,:,:,1).*(2*rand(p.asize)-1)*5;
|
||||
end
|
||||
end
|
||||
|
||||
%Added by YJ. Force orthogonalization of initial probes
|
||||
if isfield(p,'ortho_init_probes') && p.ortho_init_probes
|
||||
% Determine mode energies
|
||||
Emod = zeros(p.probe_modes,1);
|
||||
for jj = 1:numel(Emod)-1
|
||||
if jj <= numel(p.mode_start_pow)
|
||||
Emod(jj+1) = p.mode_start_pow(jj);
|
||||
else
|
||||
Emod(jj+1) = p.mode_start_pow(end);
|
||||
end
|
||||
end
|
||||
% if (numel(p.mode_start_pow) == 1)||(numel(p.mode_start_pow) == p.probe_modes-1)
|
||||
% Emod(2:end) = p.mode_start_pow;
|
||||
if sum(Emod) > 1
|
||||
error('Energy distribution between modes exceeds 1, see p.mode_start_pow')
|
||||
else
|
||||
Emod(1) = 1-sum(Emod);
|
||||
end
|
||||
Emod_init = Emod;
|
||||
for prnum = 1:p.numprobs
|
||||
% Determine the total energy of the probe first mode
|
||||
aux = p.probes(:,:,prnum,1);
|
||||
Etot = sum(abs(aux(:)).^2);
|
||||
Emod = Emod_init*Etot; % Now Emod has really the expected total sum
|
||||
|
||||
if strcmpi(p.mode_start,'rand')
|
||||
for prmode = 2:p.probe_modes
|
||||
p.probes(:,:,prnum,prmode) = p.probes(:,:,prnum,1).*(2*rand(p.asize)-1);
|
||||
end
|
||||
elseif strcmpi(p.mode_start,'zeros') %added by YJ
|
||||
for prmode = 2:p.probe_modes
|
||||
p.probes(:,:,prnum,prmode) = ones(p.asize)*eps;
|
||||
end
|
||||
elseif strfind(p.mode_start,'herm')
|
||||
if strcmpi(p.mode_start,'herm')
|
||||
M = ceil(sqrt(p.probe_modes))-1;
|
||||
N = ceil(p.probe_modes/(M+1))-1;
|
||||
elseif strcmpi(p.mode_start,'hermver')
|
||||
M = 0;
|
||||
N = p.probe_modes-1;
|
||||
elseif strcmpi(p.mode_start,'hermhor')
|
||||
M = p.probe_modes-1;
|
||||
N = 0;
|
||||
else
|
||||
error('Unknown p.mode_start')
|
||||
end
|
||||
x = [1:size(p.probes,2)]-size(p.probes,2)/2;
|
||||
y = [1:size(p.probes,1)]-size(p.probes,1)/2;
|
||||
[X Y] = meshgrid(x,y);
|
||||
H = core.hermite_like(squeeze(p.probes(:,:,prnum,1)),X,Y,M,N);
|
||||
%disp(size(H))
|
||||
|
||||
if prnum == 1
|
||||
p.probes(:,:,:,2:p.probe_modes) = 0;
|
||||
end
|
||||
p.probes(:,:,prnum,2:p.probe_modes) = reshape(H(:,:,2:p.probe_modes),size(p.probes(:,:,prnum,2:p.probe_modes)));
|
||||
else
|
||||
error('Undefined p.mode_start')
|
||||
end
|
||||
% Normalization
|
||||
for prmode = 1:p.probe_modes
|
||||
p.probes(:,:,prnum,prmode) = p.probes(:,:,prnum,prmode)*sqrt(Emod(prmode)/(sum(sum(abs(p.probes(:,:,prnum,prmode)).^2))));
|
||||
end
|
||||
|
||||
% p. mode_start_pow = [0.02] ; % Integrated intensity on modes. Can be a number (all modes equal) or a vector
|
||||
% p. mode_start = 'rand' % (for probe) = 'rand', = 'her' (Hermitian-like base), = 'herver' (vertical modes only), = 'herhor' (horizontal modes only)
|
||||
% p. mode_her_ord = []; % (for probe) Specify a 2xn vector with the (m,n) starting orders, leave = [] for default
|
||||
% p.probes(:,:,:,prmode) = p.probes(:,:,:,1).*(1+0.01.*rand(p.asize))*0.5;
|
||||
% p.probes(:,:,:,prmode) = p.probes(:,:,:,1).*exp(1i*0.1*pi.*rand(p.asize))*0.1;
|
||||
% p.probes(:,:,:,prmode) = p.probes(:,:,:,1).*(2*rand(p.asize)-1)*5;
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
Compilation from Matlab:
|
||||
maybe a tiny bit faster code is generated by
|
||||
mex -largeArrayDims 'CFLAGS="\$CFLAGS -std=c99 -fopenmp"' LDFLAGS="\$LDFLAGS -fopenmp" get_projections_cpu_mex.c
|
||||
|
||||
Usage from Matlab:
|
||||
set_projections_cpu_mex(probe,object,positions, Npos);
|
||||
|
||||
This code in matlab:
|
||||
asize = size(probe);
|
||||
for i=1:Npos
|
||||
Indy = positions(i,1) + (1:asize(1));
|
||||
Indx = positions(i,2) + (1:asize(2));
|
||||
ob(Indy,Indx) = ob(Indy,Indx) + probe;
|
||||
end
|
||||
|
||||
Academic License Agreement
|
||||
|
||||
Source Code
|
||||
|
||||
Introduction
|
||||
• This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
|
||||
Terms and Conditions of the LICENSE
|
||||
1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
hereinafter set out and until termination of this license as set forth below.
|
||||
2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
"IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
another computing language:
|
||||
"Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
Scherrer Institut, Switzerland."
|
||||
|
||||
Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
(doi: 10.1126/science.1158573),
|
||||
for maximum likelihood:
|
||||
P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
(doi: 10.1088/1367-2630/14/6/063004),
|
||||
for mixed coherent modes:
|
||||
P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
and/or for multislice:
|
||||
E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
(doi: 10.1364/OE.24.029089).
|
||||
6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
© All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
the courts of Zürich, Switzerland.
|
||||
*/
|
||||
|
||||
#include "mex.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <omp.h>
|
||||
|
||||
void mexFunction(int nlhs, mxArray *plhs[],
|
||||
int nrhs, const mxArray *prhs[])
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Check for proper number of arguments. */
|
||||
if (nrhs != 4)
|
||||
mexErrMsgTxt("Four input arguments required: set_projections_cpu_mex(probe,object,positions,Npos)");
|
||||
else if (nlhs != 0)
|
||||
mexErrMsgTxt("No output argument has to be specified.");
|
||||
|
||||
/* Input must be of type single. */
|
||||
for (i=0; i < 2; i++) {
|
||||
if (mxIsSingle(prhs[i]) != 1){
|
||||
printf("Input %d is not single\n",i+1);
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","Inputs must be of correct type.");
|
||||
}
|
||||
}
|
||||
/* Input must be of type int32. */
|
||||
for (i=2; i<nrhs; i++){
|
||||
if (mxIsInt32(prhs[i]) != 1){
|
||||
printf("Input %d is not integer\n",i+1);
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","Inputs must be of correct type.");
|
||||
}
|
||||
}
|
||||
|
||||
/* It cannot be one-dimensional */
|
||||
if(mxGetNumberOfDimensions(prhs[0]) < 2) {
|
||||
printf("The 1st input argument must have at least two dimensions.");
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","wrong number of dimensions");
|
||||
}
|
||||
/* It cannot be more than 3-dimensional */
|
||||
if(mxGetNumberOfDimensions(prhs[0]) > 3) {
|
||||
printf("The 1st input argument must have at most three dimensions.");
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","wrong number of dimensions");
|
||||
}
|
||||
/* Check that arrays are complex */
|
||||
if(mxIsComplex(prhs[0]) != 1) {
|
||||
printf("object input argument must be complex-valued.");
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","Expected complex arrays");
|
||||
}
|
||||
if(mxIsComplex(prhs[1]) != 1) {
|
||||
printf("probe input argument must be complex-valued.");
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","Expected complex arrays");
|
||||
}
|
||||
|
||||
float const *object_r, *object_i;
|
||||
float *projection_r,*projection_i;
|
||||
const int *positions, *ind_ok;
|
||||
|
||||
ind_ok = (int*)mxGetData(prhs[3]);
|
||||
positions = (int*)mxGetData(prhs[2]);
|
||||
object_r = (float*)mxGetData(prhs[0]);
|
||||
projection_r = (float*)mxGetData(prhs[1]);
|
||||
|
||||
/* get pointers to input data */
|
||||
object_i = (float*)mxGetImagData(prhs[0]);
|
||||
projection_i = (float*)mxGetImagData(prhs[1]);
|
||||
|
||||
|
||||
|
||||
/* Get dimension of probe and object */
|
||||
mwSize const * dims;
|
||||
mwSize const Ndims = mxGetNumberOfDimensions(prhs[1]);
|
||||
dims = mxGetDimensions(prhs[1]);
|
||||
mwSize const No_y = mxGetM(prhs[0]);
|
||||
mwSize const No_x = mxGetN(prhs[0]);
|
||||
mwSize const Np_y = dims[0];
|
||||
mwSize const Np_x = dims[1];
|
||||
mwSize const Npos = mxGetNumberOfElements(prhs[3]);
|
||||
|
||||
if((mxGetM(prhs[3]) > dims[2])) {
|
||||
printf("wrong size of update / positions %i", Ndims);
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","wrong size of update / positions");
|
||||
}
|
||||
|
||||
int id_small, id_large, pos, col, row, p;
|
||||
|
||||
#pragma omp parallel for private(p,pos,col, row, id_small, id_large)
|
||||
for (p=0;p<Npos;p++){
|
||||
pos = ind_ok[p]-1;
|
||||
for (col=0;col<Np_x;col++) {
|
||||
for (row=0;row<Np_y;row++) {
|
||||
id_small = row + col*Np_y + Np_y*Np_x*pos;
|
||||
id_large = row + positions[pos] + (col+positions[pos+Npos])*No_y;
|
||||
projection_r[id_small] = object_r[id_large];
|
||||
projection_i[id_small] = object_i[id_large];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
Compilation from Matlab:
|
||||
maybe a tiny bit faster code is generated by
|
||||
mex -largeArrayDims 'CFLAGS="\$CFLAGS -std=c99 -fopenmp"' LDFLAGS="\$LDFLAGS -fopenmp" get_projections_cpu_mex_double.c
|
||||
|
||||
Usage from Matlab:
|
||||
set_projections_cpu_mex(probe,object,positions, Npos);
|
||||
|
||||
This code in matlab:
|
||||
asize = size(probe);
|
||||
for i=1:Npos
|
||||
Indy = positions(i,1) + (1:asize(1));
|
||||
Indx = positions(i,2) + (1:asize(2));
|
||||
ob(Indy,Indx) = ob(Indy,Indx) + probe;
|
||||
end
|
||||
|
||||
Academic License Agreement
|
||||
|
||||
Source Code
|
||||
|
||||
Introduction
|
||||
• This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
|
||||
Terms and Conditions of the LICENSE
|
||||
1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
hereinafter set out and until termination of this license as set forth below.
|
||||
2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
"IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
another computing language:
|
||||
"Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
Scherrer Institut, Switzerland."
|
||||
|
||||
Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
(doi: 10.1126/science.1158573),
|
||||
for maximum likelihood:
|
||||
P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
(doi: 10.1088/1367-2630/14/6/063004),
|
||||
for mixed coherent modes:
|
||||
P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
and/or for multislice:
|
||||
E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
(doi: 10.1364/OE.24.029089).
|
||||
6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
© All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
the courts of Zürich, Switzerland.
|
||||
*/
|
||||
|
||||
#include "mex.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <omp.h>
|
||||
|
||||
void mexFunction(int nlhs, mxArray *plhs[],
|
||||
int nrhs, const mxArray *prhs[])
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Check for proper number of arguments. */
|
||||
if (nrhs != 4)
|
||||
mexErrMsgTxt("Four input arguments required: set_projections_cpu_mex(probe,object,positions,Npos)");
|
||||
else if (nlhs != 0)
|
||||
mexErrMsgTxt("No output argument has to be specified.");
|
||||
|
||||
/* Input must be of type double. */
|
||||
for (i=0; i < 2; i++) {
|
||||
if (mxIsDouble(prhs[i]) != 1){
|
||||
printf("Input %d is not double\n",i+1);
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","Inputs must be of correct type.");
|
||||
}
|
||||
}
|
||||
/* Input must be of type int32. */
|
||||
for (i=2; i<nrhs; i++){
|
||||
if (mxIsInt32(prhs[i]) != 1){
|
||||
printf("Input %d is not integer\n",i+1);
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","Inputs must be of correct type.");
|
||||
}
|
||||
}
|
||||
|
||||
/* It cannot be one-dimensional */
|
||||
if(mxGetNumberOfDimensions(prhs[0]) < 2) {
|
||||
printf("The 1st input argument must have at least two dimensions.");
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","wrong number of dimensions");
|
||||
}
|
||||
/* It cannot be more than 3-dimensional */
|
||||
if(mxGetNumberOfDimensions(prhs[0]) > 3) {
|
||||
printf("The 1st input argument must have at most three dimensions.");
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","wrong number of dimensions");
|
||||
}
|
||||
/* Check that arrays are complex */
|
||||
if(mxIsComplex(prhs[0]) != 1) {
|
||||
printf("object input argument must be complex-valued.");
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","Expected complex arrays");
|
||||
}
|
||||
if(mxIsComplex(prhs[1]) != 1) {
|
||||
printf("probe input argument must be complex-valued.");
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","Expected complex arrays");
|
||||
}
|
||||
|
||||
double const *object_r, *object_i;
|
||||
double *projection_r,*projection_i;
|
||||
int *positions, *ind_ok;
|
||||
|
||||
ind_ok = (int*)mxGetData(prhs[3]);
|
||||
positions = (int*)mxGetData(prhs[2]);
|
||||
object_r = (double*)mxGetData(prhs[0]);
|
||||
projection_r = (double*)mxGetData(prhs[1]);
|
||||
|
||||
/* get pointers to input data */
|
||||
object_i = (double*)mxGetImagData(prhs[0]);
|
||||
projection_i = (double*)mxGetImagData(prhs[1]);
|
||||
|
||||
|
||||
/* Get dimension of probe and object */
|
||||
mwSize const * dims;
|
||||
mwSize const Ndims = mxGetNumberOfDimensions(prhs[1]);
|
||||
dims = mxGetDimensions(prhs[1]);
|
||||
mwSize const No_y = mxGetM(prhs[0]);
|
||||
mwSize const No_x = mxGetN(prhs[0]);
|
||||
mwSize const Np_y = dims[0];
|
||||
mwSize const Np_x = dims[1];
|
||||
mwSize const Npos = mxGetNumberOfElements(prhs[3]);
|
||||
|
||||
if((mxGetM(prhs[3]) > dims[2])) {
|
||||
printf("wrong size of update / positions %i", Ndims);
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","wrong size of update / positions");
|
||||
}
|
||||
|
||||
int id_small, id_large, pos, col, row, p;
|
||||
|
||||
#pragma omp parallel for private(p,pos,col, row, id_small, id_large)
|
||||
for (p=0;p<Npos;p++){
|
||||
pos = ind_ok[p]-1;
|
||||
for (col=0;col<Np_x;col++) {
|
||||
for (row=0;row<Np_y;row++) {
|
||||
id_small = row + col*Np_y + Np_y*Np_x*pos;
|
||||
id_large = row + positions[pos] + (col+positions[pos+Npos])*No_y;
|
||||
projection_r[id_small] = object_r[id_large];
|
||||
projection_i[id_small] = object_i[id_large];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
%PTYCHO_EXIT
|
||||
%onCleanup function for core.ptycho_recons
|
||||
%
|
||||
% ** p p structure
|
||||
%
|
||||
% see also: core.ptycho_recons
|
||||
% modified by YJ
|
||||
|
||||
function ptycho_exit(p)
|
||||
import utils.*
|
||||
|
||||
if ~isfield(p.io,'data_descriptor')
|
||||
p.io.data_descriptor = '';
|
||||
end
|
||||
|
||||
if isfield(p.getReport, 'crashed') && p.getReport.crashed
|
||||
fprintf('\n\n\n###############################################################\n')
|
||||
fprintf('########################## PONG! ##############################\n')
|
||||
fprintf('###############################################################\n')
|
||||
disp([p.getReport.ME.getReport '\n\n\n']);
|
||||
|
||||
fprintf('Reconstruction stopped! Set verbose level to >3 for debugging. \n')
|
||||
if ~p.getReport.completed
|
||||
if ~isempty(p.io.phone_number) && p.io.send_crashed_recon_SMS
|
||||
%modified by YJ
|
||||
|
||||
subject = 'Ptycho recon crashed!';
|
||||
message = sprintf('User %s''s ptycho recon of %s scan%s crashed on %s', io.get_user_name(), ...
|
||||
p.io.data_descriptor, num2str(p.scan_number), io.get_host_name());
|
||||
if isfield(p.engines{1},'use_gpu') && p.engines{1}.use_gpu
|
||||
message = strcat(message,'(GPU id ',num2str(p.engines{1}.gpu_id),')');
|
||||
end
|
||||
io.sendSMS(p.io.phone_number, subject, message);
|
||||
end
|
||||
if isfield(p.queue, 'file_this_recons')
|
||||
disp('test test test test')
|
||||
try
|
||||
fprintf('Moving queue file file back to %s.\n', fullfile(p.queue.path, p.queue.file_this_recons))
|
||||
|
||||
% get log file name
|
||||
[~, ~, fext] = fileparts(p.queue.file_this_recons);
|
||||
log_dir = fullfile(p.queue.path, 'failed', 'log');
|
||||
if ~exist(log_dir, 'dir')
|
||||
mkdir(log_dir)
|
||||
end
|
||||
log_file = fullfile(log_dir, strrep(p.queue.file_this_recons, fext, '.log'));
|
||||
|
||||
% check if log file extists and update its content; move
|
||||
% queue file back to in_progess
|
||||
if exist(log_file, 'file')
|
||||
fid = fopen(log_file);
|
||||
log_line = fgetl(fid);
|
||||
fclose(fid);
|
||||
log_int = strtrim(strsplit(log_line, ':'));
|
||||
log_int = log_int{end};
|
||||
log_int = str2double(log_int);
|
||||
if ~isfield(p, 'queue_max_attempts')
|
||||
p.queue.max_attempts = 5;
|
||||
fprintf('Code crashed before parsing p.queue.max_attempts.\n')
|
||||
end
|
||||
if log_int >= p.queue.max_attempts
|
||||
io.movefile_fast(fullfile(p.queue.path,'in_progress', p.queue.file_this_recons),fullfile(p.queue.path, 'failed', p.queue.file_this_recons))
|
||||
fid = fopen(log_file, 'w');
|
||||
fprintf(fid, [p.getReport.ME.getReport '\n\n\n']);
|
||||
fprintf('Failed more than %u times. Moving file to ''failed''.\n', p.queue.max_attempts);
|
||||
fclose(fid);
|
||||
if ~isempty(p.io.phone_number) && p.io.send_failed_scans_SMS
|
||||
io.sendSMS(p.io.phone_number, sprintf('Failed to reconstruct scan %s. I will move it to "failed".', num2str(p.scan_number)), 'sleep', p.SMS_sleep, 'logfile', fullfile(log_dir, 'sendSMS.log'));
|
||||
end
|
||||
else
|
||||
io.movefile_fast(fullfile(p.queue.path,'in_progress', p.queue.file_this_recons),fullfile(p.queue.path, p.queue.file_this_recons));
|
||||
fid = fopen(log_file, 'w');
|
||||
fprintf(fid, 'failed attempts: %u\n\n', log_int+1);
|
||||
fprintf(fid, [p.getReport.ME.getReport '\n\n\n']);
|
||||
fclose(fid);
|
||||
end
|
||||
else
|
||||
fid = fopen(log_file, 'w');
|
||||
fprintf(fid, 'failed attempts: 1');
|
||||
fclose(fid);
|
||||
io.movefile_fast(fullfile(p.queue.path,'in_progress', p.queue.file_this_recons),fullfile(p.queue.path, p.queue.file_this_recons))
|
||||
end
|
||||
|
||||
catch
|
||||
fprintf('Failed to move file back to queue search path.\n')
|
||||
end
|
||||
end
|
||||
if isfield(p.queue, 'lockfile')
|
||||
if isempty(p.queue.lockfile)
|
||||
if verbose > 2
|
||||
p.queue.lockfile = false;
|
||||
else
|
||||
p.queue.lockfile = true;
|
||||
end
|
||||
end
|
||||
if p.queue.lockfile
|
||||
if isempty(p.save_path{1})
|
||||
try
|
||||
for ii = 1:length(p.scan_number)
|
||||
p.scan_str{ii} = sprintf(p.scan_string_format, p.scan_number(ii)); % Scan string
|
||||
end
|
||||
p = core.ptycho_prepare_paths(p);
|
||||
catch
|
||||
fprintf('Could not find lock file. \n')
|
||||
end
|
||||
end
|
||||
for ii=1:length(p.save_path)
|
||||
lock_filename = [p.save_path{ii} '/' p.run_name '_lock'];
|
||||
if exist(lock_filename, 'file')
|
||||
try
|
||||
unix(['rm ' lock_filename]);
|
||||
fprintf('Removing lock file %s\n',lock_filename)
|
||||
catch
|
||||
fprintf('Removing lock file %s failed\n',lock_filename)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if isfield(p.queue, 'remote_recons') && p.queue.remote_recons
|
||||
keyboard
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
fprintf('Pausing for 5 seconds.\n')
|
||||
fprintf('###############################################################\n\n')
|
||||
pause(5);
|
||||
|
||||
elseif ~p.getReport.completed
|
||||
if isfield(p, 'remote_failed') && p.remote_failed
|
||||
try
|
||||
io.movefile_fast(fullfile(p.queue.path,'in_progress', p.queue.file_this_recons),fullfile(p.queue.path, 'failed', p.queue.file_this_recons));
|
||||
catch
|
||||
fprintf('Failed to move file to failed.\n')
|
||||
end
|
||||
elseif isfield(p.queue, 'file_this_recons')
|
||||
try
|
||||
fprintf('Reconstruction stopped, moving file to %s.\n', fullfile(p.queue.path, p.queue.file_this_recons))
|
||||
io.movefile_fast(fullfile(p.queue.path,'in_progress', p.queue.file_this_recons),fullfile(p.queue.path, p.queue.file_this_recons))
|
||||
catch
|
||||
fprintf('Failed to move file back to queue search path.\n')
|
||||
end
|
||||
end
|
||||
if isfield(p.queue, 'lockfile')
|
||||
if isempty(p.queue.lockfile)
|
||||
if verbose > 2
|
||||
p.queue.lockfile = false;
|
||||
else
|
||||
p.queue.lockfile = true;
|
||||
end
|
||||
end
|
||||
if p.queue.lockfile
|
||||
if isempty(p.save_path{1})
|
||||
try
|
||||
for ii = 1:length(p.scan_number)
|
||||
p.scan_str{ii} = sprintf(p.scan_string_format, p.scan_number(ii)); % Scan string
|
||||
end
|
||||
p = core.ptycho_prepare_paths(p);
|
||||
catch
|
||||
fprintf('Could not find lock file. \n')
|
||||
end
|
||||
end
|
||||
if isfield(p, 'run_name') && ~isempty(p.run_name)
|
||||
for ii=1:length(p.save_path)
|
||||
lock_filename = [p.save_path{ii} '/' p.run_name '_lock'];
|
||||
if exist(lock_filename, 'file')
|
||||
try
|
||||
delete(lock_filename);
|
||||
fprintf('Removing lock file %s\n',lock_filename)
|
||||
catch
|
||||
fprintf('Removing lock file %s failed\n',lock_filename)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if isfield(p, 'remote_file_this_recons')
|
||||
try
|
||||
fprintf('Removing remote file.\n')
|
||||
if exist(p.queue.remote_file_this_recons, 'file')
|
||||
delete(p.queue.remote_file_this_recons)
|
||||
end
|
||||
|
||||
[~, this_file] = fileparts(p.queue.remote_file_this_recons);
|
||||
if p.queue.isreplica
|
||||
system(['touch ' fullfile(p.queue.remote_path, [this_file '.crash'])]);
|
||||
end
|
||||
|
||||
this_file = [this_file '.mat'];
|
||||
|
||||
if exist(fullfile(p.queue.remote_path, 'in_progress', this_file), 'file')
|
||||
delete(fullfile(p.queue.remote_path, 'in_progress', this_file));
|
||||
end
|
||||
if exist(fullfile(p.queue.remote_path, 'done', this_file), 'file')
|
||||
delete(fullfile(p.queue.remote_path, 'done', this_file));
|
||||
end
|
||||
if exist(fullfile(p.queue.remote_path, 'done', this_file), 'file')
|
||||
delete(fullfile(p.queue.remote_path, 'done', this_file));
|
||||
end
|
||||
|
||||
catch
|
||||
fprintf('Failed to remove remote file.\n')
|
||||
end
|
||||
end
|
||||
|
||||
if ~isempty(p.io.phone_number) && p.io.send_crashed_recon_SMS
|
||||
%modified by YJ
|
||||
subject = 'Ptycho recon crashed!';
|
||||
message = sprintf('User %s''s ptycho recon of %s scan%s crashed on %s', io.get_user_name(), ...
|
||||
p.io.data_descriptor, num2str(p.scan_number), io.get_host_name());
|
||||
|
||||
if isfield(p.engines{1},'use_gpu') && p.engines{1}.use_gpu
|
||||
message = strcat(message,'(GPU id ',num2str(p.engines{1}.gpu_id),')');
|
||||
end
|
||||
|
||||
io.sendSMS(p.io.phone_number, subject, message);
|
||||
end
|
||||
end
|
||||
|
||||
pid = [p.ptycho_matlab_path './utils/.tmp_procID/proc_' num2str(feature('getpid')) '.dat'];
|
||||
if exist(pid, 'file')
|
||||
delete(pid)
|
||||
end
|
||||
|
||||
if ~isempty(p.io.phone_number) && p.io.send_finished_recon_SMS && p.getReport.completed
|
||||
%modified by YJ
|
||||
subject = 'Ptycho recon completed!';
|
||||
message = sprintf('User %s''s ptycho recon of %s scan%s completed on %s', io.get_user_name(), ...
|
||||
p.io.data_descriptor, num2str(p.scan_number), io.get_host_name());
|
||||
|
||||
if isfield(p.engines{1},'use_gpu') && p.engines{1}.use_gpu
|
||||
message = strcat(message,'(GPU id ',num2str(p.engines{1}.gpu_id),')');
|
||||
end
|
||||
|
||||
io.sendSMS(p.io.phone_number, subject, message);
|
||||
end
|
||||
|
||||
try
|
||||
verbose(struct('prefix', {[]}))
|
||||
catch
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
Compilation from Matlab:
|
||||
maybe a tiny bit faster code is generated by
|
||||
mex -largeArrayDims 'CFLAGS="\$CFLAGS -std=c99 -fopenmp"' LDFLAGS="\$LDFLAGS -fopenmp" set_projections_cpu_mex.c
|
||||
|
||||
Usage from Matlab:
|
||||
set_projections_cpu_mex(probe,object,positions, Npos);
|
||||
|
||||
This code in matlab:
|
||||
asize = size(probe);
|
||||
for i=1:Npos
|
||||
Indy = positions(i,1) + (1:asize(1));
|
||||
Indx = positions(i,2) + (1:asize(2));
|
||||
ob(Indy,Indx) = ob(Indy,Indx) + probe;
|
||||
end
|
||||
|
||||
Academic License Agreement
|
||||
|
||||
Source Code
|
||||
|
||||
Introduction
|
||||
• This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
|
||||
Terms and Conditions of the LICENSE
|
||||
1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
hereinafter set out and until termination of this license as set forth below.
|
||||
2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
"IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
another computing language:
|
||||
"Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
Scherrer Institut, Switzerland."
|
||||
|
||||
Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
(doi: 10.1126/science.1158573),
|
||||
for maximum likelihood:
|
||||
P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
(doi: 10.1088/1367-2630/14/6/063004),
|
||||
for mixed coherent modes:
|
||||
P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
and/or for multislice:
|
||||
E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
(doi: 10.1364/OE.24.029089).
|
||||
6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
© All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
the courts of Zürich, Switzerland.
|
||||
*/
|
||||
|
||||
#include "mex.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <omp.h>
|
||||
|
||||
|
||||
void mexFunction(int nlhs, mxArray *plhs[],
|
||||
int nrhs, const mxArray *prhs[])
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Check for proper number of arguments. */
|
||||
if (nrhs != 4)
|
||||
mexErrMsgTxt("Four input arguments required: set_projections_cpu_mex(probe,object,positions,Npos)");
|
||||
else if (nlhs != 0)
|
||||
mexErrMsgTxt("No output argument has to be specified.");
|
||||
|
||||
/* Input must be of type double. */
|
||||
for (i=0; i < 2; i++) {
|
||||
if (mxIsSingle(prhs[i]) != 1){
|
||||
printf("Input %d is not single\n",i+1);
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","Inputs must be of correct type.");
|
||||
}
|
||||
}
|
||||
/* Input must be of type int32. */
|
||||
for (i=2; i<nrhs; i++){
|
||||
if (mxIsInt32(prhs[i]) != 1){
|
||||
printf("Input %d is not integer\n",i+1);
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","Inputs must be of correct type.");
|
||||
}
|
||||
}
|
||||
|
||||
/* It cannot be one-dimensional */
|
||||
if(mxGetNumberOfDimensions(prhs[0]) < 2) {
|
||||
printf("The 1st input argument must have at least two dimensions.");
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","wrong number of dimensions");
|
||||
}
|
||||
/* It cannot be more than 3-dimensional */
|
||||
if(mxGetNumberOfDimensions(prhs[0]) > 3) {
|
||||
printf("The 1st input argument must have at most three dimensions.");
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","wrong number of dimensions");
|
||||
}
|
||||
// /* Check that arrays are complex */
|
||||
// if(mxIsComplex(prhs[0]) != 1) {
|
||||
// printf("object input argument must be complex-valued.");
|
||||
// mexErrMsgIdAndTxt("MexError:ptycho","Expected complex arrays");
|
||||
// }
|
||||
// if(mxIsComplex(prhs[1]) != 1) {
|
||||
// printf("probe input argument must be complex-valued.");
|
||||
// mexErrMsgIdAndTxt("MexError:ptycho","Expected complex arrays");
|
||||
// }
|
||||
|
||||
float *object_r, *object_i, *probe_r,*probe_i;
|
||||
int *positions, *ind_ok;
|
||||
bool cprobe, cobject;
|
||||
|
||||
cobject = mxIsComplex(prhs[0]);
|
||||
cprobe = mxIsComplex(prhs[1]);
|
||||
if( cobject != cobject)
|
||||
{
|
||||
printf("probe/object input argument must be complex/real-valued.");
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","Expected both complex / real arrays");
|
||||
}
|
||||
|
||||
ind_ok = (int*)mxGetData(prhs[3]);
|
||||
positions = (int*)mxGetData(prhs[2]);
|
||||
object_r = (float*)mxGetData(prhs[0]);
|
||||
probe_r = (float*)mxGetData(prhs[1]);
|
||||
if(cprobe)
|
||||
{
|
||||
/* get pointers to input data */
|
||||
object_i = (float*)mxGetImagData(prhs[0]);
|
||||
probe_i = (float*)mxGetImagData(prhs[1]);
|
||||
}
|
||||
|
||||
|
||||
/* Get dimension of probe and object */
|
||||
mwSize const Ndims = mxGetNumberOfDimensions(prhs[1]);
|
||||
mwSize const * dims = mxGetDimensions(prhs[1]);
|
||||
mwSize const No_y = mxGetM(prhs[0]);
|
||||
mwSize const No_x = mxGetN(prhs[0]);
|
||||
mwSize const Np_y = dims[0];
|
||||
mwSize const Np_x = dims[1];
|
||||
mwSize const Npos = mxGetNumberOfElements(prhs[3]);
|
||||
|
||||
if((mxGetM(prhs[2]) != dims[2]) && (Ndims == 3)) {
|
||||
printf("wrong size of update / positions %i", Ndims);
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","wrong size of update / positions");
|
||||
}
|
||||
|
||||
mwSize id_small, id_large, pos, col, row, o, p;
|
||||
bool flat_probe = Ndims == 2;
|
||||
|
||||
#pragma omp parallel for private(p,pos, col, row, id_small, id_large)
|
||||
for (p=0;p<Npos;p++){
|
||||
pos = ind_ok[p]-1;
|
||||
for (col=0;col<Np_x;col++) {
|
||||
for (row=0;row<Np_y;row++) {
|
||||
if(flat_probe)
|
||||
id_small = row + col*Np_y;
|
||||
else
|
||||
id_small = row + col*Np_y + Np_y*Np_x*pos;
|
||||
|
||||
id_large = row + positions[pos] + (col+positions[pos+Npos])*No_y;
|
||||
#pragma omp atomic
|
||||
object_r[id_large] += probe_r[id_small];
|
||||
if(cprobe) {
|
||||
#pragma omp atomic
|
||||
object_i[id_large] += probe_i[id_small];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
Compilation from Matlab:
|
||||
maybe a tiny bit faster code is generated by
|
||||
mex -largeArrayDims 'CFLAGS="\$CFLAGS -std=c99 -fopenmp"' LDFLAGS="\$LDFLAGS -fopenmp" set_projections_cpu_mex_double.c
|
||||
|
||||
Usage from Matlab:
|
||||
set_projections_cpu_mex(probe,object,positions, Npos);
|
||||
|
||||
This code in matlab:
|
||||
asize = size(probe);
|
||||
for i=1:Npos
|
||||
Indy = positions(i,1) + (1:asize(1));
|
||||
Indx = positions(i,2) + (1:asize(2));
|
||||
ob(Indy,Indx) = ob(Indy,Indx) + probe;
|
||||
end
|
||||
|
||||
Academic License Agreement
|
||||
|
||||
Source Code
|
||||
|
||||
Introduction
|
||||
• This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
|
||||
Terms and Conditions of the LICENSE
|
||||
1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
hereinafter set out and until termination of this license as set forth below.
|
||||
2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
"IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
another computing language:
|
||||
"Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
Scherrer Institut, Switzerland."
|
||||
|
||||
Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
(doi: 10.1126/science.1158573),
|
||||
for maximum likelihood:
|
||||
P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
(doi: 10.1088/1367-2630/14/6/063004),
|
||||
for mixed coherent modes:
|
||||
P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
and/or for multislice:
|
||||
E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
(doi: 10.1364/OE.24.029089).
|
||||
6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
© All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
the courts of Zürich, Switzerland.
|
||||
*/
|
||||
|
||||
#include "mex.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <omp.h>
|
||||
|
||||
|
||||
void mexFunction(int nlhs, mxArray *plhs[],
|
||||
int nrhs, const mxArray *prhs[])
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Check for proper number of arguments. */
|
||||
if (nrhs != 4)
|
||||
mexErrMsgTxt("Four input arguments required: set_projections_cpu_mex(probe,object,positions,Npos)");
|
||||
else if (nlhs != 0)
|
||||
mexErrMsgTxt("No output argument has to be specified.");
|
||||
|
||||
/* Input must be of type double. */
|
||||
for (i=0; i < 2; i++) {
|
||||
if (mxIsDouble(prhs[i]) != 1){
|
||||
printf("Input %d is not double\n",i+1);
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","Inputs must be of correct type.");
|
||||
}
|
||||
}
|
||||
/* Input must be of type int32. */
|
||||
for (i=2; i<nrhs; i++){
|
||||
if (mxIsInt32(prhs[i]) != 1){
|
||||
printf("Input %d is not integer\n",i+1);
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","Inputs must be of correct type.");
|
||||
}
|
||||
}
|
||||
|
||||
/* It cannot be one-dimensional */
|
||||
if(mxGetNumberOfDimensions(prhs[0]) < 2) {
|
||||
printf("The 1st input argument must have at least two dimensions.");
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","wrong number of dimensions");
|
||||
}
|
||||
/* It cannot be more than 3-dimensional */
|
||||
if(mxGetNumberOfDimensions(prhs[0]) > 3) {
|
||||
printf("The 1st input argument must have at most three dimensions.");
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","wrong number of dimensions");
|
||||
}
|
||||
// /* Check that arrays are complex */
|
||||
// if(mxIsComplex(prhs[0]) != 1) {
|
||||
// printf("object input argument must be complex-valued.");
|
||||
// mexErrMsgIdAndTxt("MexError:ptycho","Expected complex arrays");
|
||||
// }
|
||||
// if(mxIsComplex(prhs[1]) != 1) {
|
||||
// printf("probe input argument must be complex-valued.");
|
||||
// mexErrMsgIdAndTxt("MexError:ptycho","Expected complex arrays");
|
||||
// }
|
||||
|
||||
double *object_r, *object_i, *probe_r,*probe_i;
|
||||
int *positions, *ind_ok;
|
||||
bool cprobe, cobject;
|
||||
|
||||
cobject = mxIsComplex(prhs[0]);
|
||||
cprobe = mxIsComplex(prhs[1]);
|
||||
if( cobject != cobject)
|
||||
{
|
||||
printf("probe/object input argument must be complex/real-valued.");
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","Expected both complex / real arrays");
|
||||
}
|
||||
|
||||
ind_ok = (int*)mxGetData(prhs[3]);
|
||||
positions = (int*)mxGetData(prhs[2]);
|
||||
object_r = (double*)mxGetData(prhs[0]);
|
||||
probe_r = (double*)mxGetData(prhs[1]);
|
||||
if(cprobe)
|
||||
{
|
||||
/* get pointers to input data */
|
||||
object_i = (double*)mxGetImagData(prhs[0]);
|
||||
probe_i = (double*)mxGetImagData(prhs[1]);
|
||||
}
|
||||
|
||||
|
||||
/* Get dimension of probe and object */
|
||||
mwSize const Ndims = mxGetNumberOfDimensions(prhs[1]);
|
||||
mwSize const * dims = mxGetDimensions(prhs[1]);
|
||||
mwSize const No_y = mxGetM(prhs[0]);
|
||||
mwSize const No_x = mxGetN(prhs[0]);
|
||||
mwSize const Np_y = dims[0];
|
||||
mwSize const Np_x = dims[1];
|
||||
mwSize const Npos = mxGetNumberOfElements(prhs[3]);
|
||||
|
||||
if((mxGetM(prhs[2]) != dims[2]) && (Ndims == 3)) {
|
||||
printf("wrong size of update / positions %i", Ndims);
|
||||
mexErrMsgIdAndTxt("MexError:ptycho","wrong size of update / positions");
|
||||
}
|
||||
|
||||
mwSize id_small, id_large, pos, col, row, o, p;
|
||||
bool flat_probe = Ndims == 2;
|
||||
|
||||
#pragma omp parallel for private(p,pos, col, row, id_small, id_large)
|
||||
for (p=0;p<Npos;p++){
|
||||
pos = ind_ok[p]-1;
|
||||
for (col=0;col<Np_x;col++) {
|
||||
for (row=0;row<Np_y;row++) {
|
||||
if(flat_probe)
|
||||
id_small = row + col*Np_y;
|
||||
else
|
||||
id_small = row + col*Np_y + Np_y*Np_x*pos;
|
||||
|
||||
id_large = row + positions[pos] + (col+positions[pos+Npos])*No_y;
|
||||
#pragma omp atomic
|
||||
object_r[id_large] += probe_r[id_small];
|
||||
if(cprobe) {
|
||||
#pragma omp atomic
|
||||
object_i[id_large] += probe_i[id_small];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
%WRITE_PROCID
|
||||
% writes .dat files to utils/.tmp_procID to keep track of current
|
||||
% reconstructions
|
||||
% ** p p structure
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function write_procID(p)
|
||||
try
|
||||
if ~exist(fullfile(p.ptycho_matlab_path, 'utils', '.tmp_procID'), 'dir')
|
||||
mkdir(fullfile(p.ptycho_matlab_path, 'utils', '.tmp_procID'))
|
||||
end
|
||||
if ispc
|
||||
hostname = getenv('COMPUTERNAME');
|
||||
else
|
||||
hostname = getenv('HOSTNAME');
|
||||
end
|
||||
% calling system('hostname') has large overhead, try to avoid if not needed
|
||||
if isempty(hostname)
|
||||
[~, hostname] = system('hostname');
|
||||
hostname = hostname(1:end-1);
|
||||
end
|
||||
|
||||
caller = dbstack;
|
||||
|
||||
f = fopen(fullfile(p.ptycho_matlab_path, 'utils', '.tmp_procID', ['proc_' num2str(feature('getpid')) '.dat']), 'w');
|
||||
fprintf(f, [hostname ' ' strrep(num2str(p.scan_number), ' ', '-') ' ' datestr(datetime('now')) ' ' caller(end).name]);
|
||||
fclose(f);
|
||||
catch
|
||||
utils.verbose(0, 'Failed to write process ID.')
|
||||
end
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
% ORTHO Orthogonalize the given list of modes using SVD.
|
||||
% [pr, I_n, eval] = probe_modes_ortho(modes)
|
||||
% pr Orthogonalized (eigen) modes
|
||||
% I_n Normalized intensity of the mode (relative contribution to total intensity)
|
||||
% eval SVD eigenvalues
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function [pr, I_n, eval] = probe_modes_ortho(modes)
|
||||
% SVD decomposition of matrix M
|
||||
% M = U S V*
|
||||
% where U is a unitary matrix, S is a diagonal matrix with singular
|
||||
% values and V* is a unitary matrix.
|
||||
%
|
||||
% M M* = U S V* V S* U* = U (S S*) U*
|
||||
% M* M = V S* U* U S V* = V (S* S) V*
|
||||
|
||||
% If probes are given as a 4D array, it will be assumed that the 3rd axis
|
||||
% is the scan index
|
||||
if ndims(modes)==4
|
||||
|
||||
nscans = size(modes,3);
|
||||
I_n = cell(nscans,1);
|
||||
eval = cell(nscans,1);
|
||||
N = size(modes,4);
|
||||
pr = zeros(size(modes));
|
||||
|
||||
for scanindx=1:nscans
|
||||
[pr(:,:,scanindx,:), I_n{scanindx}, eval{scanindx}] = core.probe_modes_ortho(squeeze(modes(:,:,scanindx,:)));
|
||||
end
|
||||
|
||||
|
||||
else
|
||||
%% calculate M M* and its eigenvectors
|
||||
N = size(modes,3);
|
||||
|
||||
A = zeros(N,N,'like',modes);
|
||||
|
||||
for ii=1:N
|
||||
p2 = modes(:,:,ii);
|
||||
for jj=1:N
|
||||
p1 = modes(:,:,jj);
|
||||
A(ii,jj) = sum(dot(p2,p1));
|
||||
end
|
||||
end
|
||||
A(isnan(A)) = 0;
|
||||
[evec,eval] = eig(A);
|
||||
|
||||
%% sort modes by their contribution
|
||||
[~,I] = sort(diag(eval), 'descend');
|
||||
|
||||
%% orthogonalize probes
|
||||
pr = zeros(size(modes,1), size(modes,2), N, 'like', modes);
|
||||
for jj = 1:N
|
||||
for ii = 1:N
|
||||
pr(:,:,jj) = pr(:,:,jj) + modes(:,:,ii) * evec(ii,I(jj));
|
||||
end
|
||||
end
|
||||
|
||||
%% calculate intensity contribution
|
||||
I_n = zeros(N,1, 'like', modes);
|
||||
|
||||
for ii = 1:N
|
||||
I_n(ii,:) = sum(sum(abs(pr(:,:,ii)).^2));
|
||||
end
|
||||
I_n = I_n ./ sum(I_n(:));
|
||||
|
||||
end
|
||||
@@ -0,0 +1,132 @@
|
||||
%PTYCHO_ADJUST_POSITIONS
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function [ p ] = ptycho_adjust_positions( p )
|
||||
|
||||
p.positions_real = -p.positions_real;
|
||||
|
||||
% Affine transform on probe positions (this will modify the object
|
||||
% according to the transformation matrix)
|
||||
if isfield(p,'affine_matrix')&&(~isempty(p.affine_matrix))&&any(any(p.affine_matrix ~= eye(2)))
|
||||
utils.verbose(1, 'Applying custom affine matrix to measured positions')
|
||||
p.positions_real = p.affine_matrix*p.positions_real.';
|
||||
p.positions_real = p.positions_real.';
|
||||
end
|
||||
|
||||
%Add coarse translation for slow axis (substract because we are in probe
|
||||
%positions)
|
||||
if isfield(p, 'spec') && (check_option(p.spec.motor,'coarse_motors') && length(p.spec.motor.coarse_motors) == 2)
|
||||
assert(check_option(p.spec.motor,'coarse_motors_scale'), 'Provide scale of the coarse motors in p.spec.motor.coarse_motors_scale ')
|
||||
for ii = 1:length(p.scan_number)
|
||||
p.positions_real(p.scanidxs{ii},1) = p.positions_real(p.scanidxs{ii},1)-getfield(p.meta{ii}.spec,p.spec.motor.coarse_motors{2})*p.spec.motor.coarse_motors_scale(min(end,2));
|
||||
p.positions_real(p.scanidxs{ii},2) = p.positions_real(p.scanidxs{ii},2)-getfield(p.meta{ii}.spec,p.spec.motor.coarse_motors{1})*p.spec.motor.coarse_motors_scale(1);
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
% Convert to pixels
|
||||
p.positions = p.positions_real./p.dx_spec;
|
||||
|
||||
% prepare positions offset
|
||||
if ~isfield(p, 'positions_pad')
|
||||
p.positions_pad = [0 0];
|
||||
else
|
||||
if size(p.positions_pad,2) == 1
|
||||
p.positions_pad = [p.positions_pad p.positions_pad];
|
||||
end
|
||||
end
|
||||
|
||||
% compute positions for shared reconstruction
|
||||
share_pos{length(unique(p.share_object_ID))} = [];
|
||||
for jj=1:p.numscans
|
||||
if isempty(share_pos{p.share_object_ID(jj)})
|
||||
share_pos{p.share_object_ID(jj)} = p.positions(p.scanidxs{jj},:);
|
||||
else
|
||||
tmp = share_pos{p.share_object_ID(jj)};
|
||||
share_pos{p.share_object_ID(jj)} = [];
|
||||
share_pos{p.share_object_ID(jj)} = cat(1, tmp, p.positions(p.scanidxs{jj},:));
|
||||
end
|
||||
end
|
||||
|
||||
% Convenient offset of positions
|
||||
if length(unique(p.share_object_ID))==1
|
||||
p.positions = p.positions - min(p.positions) + p.positions_pad;
|
||||
else
|
||||
for ii=1:length(p.scan_number)
|
||||
p.positions(p.scanidxs{ii},:) = ...
|
||||
p.positions(p.scanidxs{ii},:) - ...
|
||||
min(share_pos{p.share_object_ID(ii)}) + p.positions_pad;
|
||||
end
|
||||
end
|
||||
|
||||
% update shared positions with new positions
|
||||
clear share_pos;
|
||||
share_pos{length(unique(p.share_object_ID))} = [];
|
||||
for jj=1:p.numscans
|
||||
if isempty(share_pos{p.share_object_ID(jj)})
|
||||
share_pos{p.share_object_ID(jj)} = p.positions(p.scanidxs{jj},:);
|
||||
else
|
||||
tmp = share_pos{p.share_object_ID(jj)};
|
||||
share_pos{p.share_object_ID(jj)} = [];
|
||||
share_pos{p.share_object_ID(jj)} = cat(1, tmp, p.positions(p.scanidxs{jj},:));
|
||||
end
|
||||
end
|
||||
p.share_pos = share_pos;
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
% pout = ptycho_model_probe(p)
|
||||
|
||||
function pout = ptycho_model_probe(p)
|
||||
import utils.*
|
||||
import io.*
|
||||
|
||||
% Define often-used variables
|
||||
lambda = p.lambda;
|
||||
asize = p.asize; % Diffr. patt. array size
|
||||
% added by YJ for up-sampled diffraction patterns.
|
||||
if p.detector.upsampling >0
|
||||
asize = asize*2^p.detector.upsampling;
|
||||
end
|
||||
dx_spec = p.dx_spec;
|
||||
a2 = prod(asize);
|
||||
|
||||
if check_option(p, 'prop_regime', 'nearfield')
|
||||
% for this task use original values of the pixel sizes
|
||||
dx_spec = p.lambda*p.z*p.nearfield_magnification ./ (p.asize*p.ds);
|
||||
end
|
||||
|
||||
% Prepare probe
|
||||
if p.model_probe
|
||||
% STEM probe: based on Eq.(2.10) in Advanced Computing in Electron
|
||||
% Microscopy (2nd edition) by Dr.Kirkland
|
||||
if isfield(p,'beam_source') && strcmp(p.beam_source, 'electron')
|
||||
df = p.model.probe_df;
|
||||
alpha_max = p.model.probe_alpha_max;
|
||||
amax = alpha_max*1e-3; %in rad
|
||||
amin = 0;
|
||||
|
||||
klimitmax = amax/lambda;
|
||||
klimitmin = amin/lambda;
|
||||
N = asize(1);
|
||||
dk = 1/(dx_spec(1)*N);
|
||||
|
||||
kx = linspace(-floor(N/2),ceil(N/2)-1,N);
|
||||
[kX,kY] = meshgrid(kx,kx);
|
||||
|
||||
kX = kX.*dk;
|
||||
kY = kY.*dk;
|
||||
kR = sqrt(kX.^2+kY.^2);
|
||||
theta = atan2(kY,kX);
|
||||
|
||||
mask = single(kR<=klimitmax).*single(kR>=klimitmin);
|
||||
chi = -pi*lambda*kR.^2*df;
|
||||
%third-order spherical aberration in angstrom
|
||||
if isfield(p.model,'probe_c3') && p.model.probe_c3~=0
|
||||
chi = chi + pi/2*p.model.probe_c3*lambda^3*kR.^4;
|
||||
end
|
||||
%fifth-order spherical aberration in angstrom
|
||||
if isfield(p.model,'probe_c5') && p.model.probe_c5~=0
|
||||
chi = chi + pi/3*p.model.probe_c5*lambda^5*kR.^6;
|
||||
end
|
||||
%seventh-order spherical aberration in angstrom
|
||||
if isfield(p.model,'probe_c7') && p.model.probe_c7~=0
|
||||
chi = chi + pi/4*p.model.probe_c7*lambda^7*kR.^8;
|
||||
end
|
||||
%twofold astigmatism in angstrom & azimuthal orientation in radian
|
||||
if isfield(p.model,'probe_f_a2') && isfield(p.model,'probe_theta_a2') && p.model.probe_f_a2~=0
|
||||
chi = chi + pi*p.model.probe_f_a2*lambda*kR.^2*sin(2*(theta-p.model.probe_theta_a2));
|
||||
end
|
||||
%threefold astigmatism in angstrom & azimuthal orientation in radian
|
||||
if isfield(p.model,'probe_f_a3') && isfield(p.model,'probe_theta_a3') && p.model.probe_f_a3~=0
|
||||
chi = chi + 2*pi/3*p.model.probe_f_a3*lambda^2*kR.^3*sin(3*(theta-p.model.probe_theta_a3));
|
||||
end
|
||||
%coma in angstrom & azimuthal orientation in radian
|
||||
if isfield(p.model,'probe_f_c3') && isfield(p.model,'probe_theta_c3') && p.model.probe_f_c3~=0
|
||||
chi = chi + 2*pi/3*p.model.probe_f_c3*lambda^2*kR.^3*sin(theta-p.model.probe_theta_c3);
|
||||
end
|
||||
|
||||
probe = mask.*exp(-1i.*chi);
|
||||
probe = fftshift(ifft2(ifftshift(probe)));
|
||||
probe = probe/sum(sum(abs(probe)));
|
||||
else %X-ray probe
|
||||
if p.model.probe_is_focused
|
||||
verbose(2, 'Using focused probe as initial model.');
|
||||
if asize(1) ~= asize(2)
|
||||
error('Focused probe modeling is only implemented for square arrays (please feel free to change that).');
|
||||
end
|
||||
|
||||
if isempty(p.model.probe_zone_plate_diameter) || isempty(p.model.probe_outer_zone_width)
|
||||
zp_f = p.model.probe_focal_length;
|
||||
verbose(3, 'Using model.probe_focal_length for modeled probe.');
|
||||
else
|
||||
zp_f = p.model.probe_zone_plate_diameter * p.model.probe_outer_zone_width / lambda;
|
||||
end
|
||||
|
||||
% The probe is generated in a larger array to avoid aliasing
|
||||
upsample = p.model.probe_upsample;
|
||||
|
||||
defocus = p.model.probe_propagation_dist;
|
||||
Nprobe = upsample*asize(1); % Array dimension for the simulation
|
||||
dx = (zp_f+defocus)*lambda/(Nprobe*dx_spec(1)); % pixel size in the pupil plane
|
||||
r1_pix = p.model.probe_diameter / dx; % size in pixels of first pinhole
|
||||
r2_pix = p.model.probe_central_stop_diameter / dx; % size in pixels of central stop
|
||||
|
||||
|
||||
% Pupil
|
||||
[x,y] = meshgrid(-Nprobe/2:floor((Nprobe-1)/2),-Nprobe/2:floor((Nprobe-1)/2));
|
||||
r2 = x.^2 + y.^2;
|
||||
% w = (r2 < (r1_pix)^2);
|
||||
if upsample*asize(1) < round(r1_pix)-5
|
||||
error(sprintf('For this experimental parameters asize must be at least %d in order for the lens to fit in the window.',ceil((round(r1_pix)-5)./upsample+1)))
|
||||
end
|
||||
w = fftshift(filt2d_pad(upsample*asize(1), round(r1_pix)+5, round(r1_pix)-5, 'circ'));
|
||||
if p.model.probe_central_stop
|
||||
w = w .*(1-fftshift(filt2d_pad(upsample*asize(1), round(r2_pix)+2, round(r2_pix-2), 'circ')));
|
||||
end
|
||||
if isfield(p.model,'probe_structured_illum_power') && p.model.probe_structured_illum_power
|
||||
%rng default
|
||||
r = utils.imgaussfilt2_fft(randn(upsample*p.asize),upsample*2);
|
||||
r = r / math.norm2(r);
|
||||
r = exp(1i*r*p.model.probe_structured_illum_power);
|
||||
w = imgaussfilt(w,upsample/2).*r;
|
||||
end
|
||||
|
||||
% Propagation
|
||||
probe_hr = prop_free_ff(w .* exp(-1i * pi * r2 * dx^2 / (lambda * zp_f)), lambda, zp_f + defocus, dx);
|
||||
|
||||
% Cropping back to field of view
|
||||
probe = crop_pad(probe_hr, asize);
|
||||
|
||||
% prevent unreal sharp edges from the cropped tails in probe
|
||||
[probe] = utils.apply_3D_apodization(probe, 0);
|
||||
|
||||
probe = probe .* sqrt(1e5/sum(sum(abs(probe).^2)));
|
||||
clear x y r2 w probe_hr
|
||||
|
||||
else
|
||||
verbose(2, 'Using circular pinhole as initial model.');
|
||||
[x1,x2] = ndgrid(-asize(1)/2:floor((asize(1)-1)/2),-asize(2)/2:floor((asize(2)-1)/2));
|
||||
probe = ( (x1 * dx_spec(1)).^2 + (x2 * dx_spec(2)).^2 < (p.model.probe_diameter/2)^2);
|
||||
probe = prop_free_nf(double(probe), lambda, p.model.probe_propagation_dist, dx_spec);
|
||||
clear x1 x2
|
||||
end
|
||||
end
|
||||
verbose(3, 'Successfully generated model probe.');
|
||||
else
|
||||
if ~isfield(p,'probe_file_propagation')
|
||||
p.probe_file_propagation = [];
|
||||
end
|
||||
verbose(2, 'Using previous run as initial probe.');
|
||||
|
||||
% if string allows it, fill in the scan numbers
|
||||
p.initial_probe_file = sprintf(replace(p.initial_probe_file,'\','\\'), p.scan_number(1));
|
||||
|
||||
for searchpath = {'', p.ptycho_matlab_path}
|
||||
fpath = dir(fullfile(searchpath{1},p.initial_probe_file));
|
||||
% check if only one unique file is found
|
||||
if length(fpath) > 1
|
||||
error('Too many paths corresponding to patterns %s were found', p.initial_probe_file)
|
||||
elseif length(fpath) == 1
|
||||
p.initial_probe_file = fullfile(fpath.folder, fpath.name);
|
||||
break
|
||||
end
|
||||
end
|
||||
if isempty(fpath)
|
||||
error(['Did not find initial probe file: ' p.initial_probe_file])
|
||||
end
|
||||
|
||||
fileokflag = 0;
|
||||
while ~fileokflag
|
||||
try
|
||||
S = load_ptycho_recons(p.initial_probe_file, 'probe'); % avoid object loading when it is not needed
|
||||
probe = S.probe;
|
||||
probe = probe(:,:,:,1); %%added by YJ. Force to ignore the 4-th dimension (used for storing OPR modes)
|
||||
%disp(size(probe))
|
||||
S = load_ptycho_recons(p.initial_probe_file, 'p');
|
||||
fileokflag = 1;
|
||||
verbose(2, 'Loaded probe from: %s',p.initial_probe_file );
|
||||
|
||||
%% check if the loaded probe was binned or no
|
||||
if isfield(S, 'p') && isfield(S.p, 'binning')
|
||||
binning = S.p.binning;
|
||||
elseif isfield(S, 'p') && isfield(S.p, 'detector') && isfield(S.p.detector, 'binning')
|
||||
binning = S.p.detector.binning;
|
||||
else
|
||||
if verbose() > 0
|
||||
binning = [];
|
||||
while isempty(binning)
|
||||
binning = str2num(input('Define binning factor 2^x for loaded initial probe (i.e. 0 for no binning):','s'));
|
||||
end
|
||||
% save provided binning option to the loaded probe file
|
||||
S.p.detector.binning = binning;
|
||||
save(p.initial_probe_file, '-append', '-struct', 'S')
|
||||
else
|
||||
% prevent stopping code if automatic reconstructions are running
|
||||
verbose(0, 'Initial probe binning could not be determined, assuming no binning')
|
||||
binning = 0;
|
||||
end
|
||||
end
|
||||
% modify the loaded probe into a nonbinned version
|
||||
probe = crop_pad(probe, [size(probe,1),size(probe,2)]*2^binning);
|
||||
catch err
|
||||
disp(['File corrupt: ' p.initial_probe_file])
|
||||
disp(err.message)
|
||||
disp('Retrying')
|
||||
|
||||
pause(1)
|
||||
end
|
||||
end
|
||||
if ndims(probe)==3
|
||||
sz_pr = size(probe);
|
||||
probe = reshape(probe, [sz_pr(1) sz_pr(2) 1 sz_pr(3)]);
|
||||
end
|
||||
verbose(3, 'File %s loaded successfully.', p.initial_probe_file);
|
||||
|
||||
if ~all([size(probe,1) size(probe,2)] == asize)
|
||||
verbose(2,'Loaded probe has the wrong size.');
|
||||
if isfield(p,'crop_pad_init_probe') && p.crop_pad_init_probe %added by YJ
|
||||
verbose(2,'Crop/pad probe in file %s, from (%d,%d) to (%d,%d).', p.initial_probe_file,size(probe,1),size(probe,2),asize(1),asize(2));
|
||||
probe = crop_pad(probe, asize);
|
||||
else
|
||||
verbose(2,'Interpolating probe in file %s, from (%d,%d) to (%d,%d).', p.initial_probe_file,size(probe,1),size(probe,2),asize(1),asize(2));
|
||||
probe = interpolateFT(probe,asize);
|
||||
end
|
||||
end
|
||||
if ~isempty(p.probe_file_propagation) && any(p.probe_file_propagation ~= 0)
|
||||
verbose(2,'Propagating probe from file by %f mm',p.probe_file_propagation*1e3);
|
||||
probe= prop_free_nf(double(probe), lambda, p.probe_file_propagation, dx_spec);
|
||||
end
|
||||
|
||||
end
|
||||
if isfield(p,'normalize_init_probe') %%added by YJ
|
||||
if p.normalize_init_probe
|
||||
probe = probe .* sqrt(a2 ./ sum(sum(abs(probe).^2)));
|
||||
end
|
||||
else
|
||||
probe = probe .* sqrt(a2 ./ sum(sum(abs(probe).^2)));
|
||||
end
|
||||
pout = p;
|
||||
pout.probe_initial = probe;
|
||||
@@ -0,0 +1,312 @@
|
||||
%PTYCHO_PREPARE_PATHS Prepare paths and check defaults
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function [ p ] = ptycho_prepare_paths( p, varargin)
|
||||
import utils.*
|
||||
|
||||
|
||||
if nargin > 1
|
||||
init = varargin{1};
|
||||
else
|
||||
init = false;
|
||||
end
|
||||
|
||||
if init
|
||||
verbose(p.verbose_level);
|
||||
|
||||
verbose(1, 'Preparing paths.')
|
||||
|
||||
% base paths
|
||||
if isempty(p.base_path)
|
||||
p.base_path = './';
|
||||
verbose(3, 'Using default value for base_path: %s', p.base_path)
|
||||
end
|
||||
|
||||
p.base_path = abspath(p.base_path);
|
||||
|
||||
|
||||
% specfile
|
||||
if isfield(p, 'specfile')
|
||||
if isempty(p.specfile) && isfield(p, 'src_metadata') && strcmp(p.src_metadata, 'spec')
|
||||
p.specfile = p.base_path;
|
||||
verbose(3, 'Using default value for specfile: %s', p.specfile )
|
||||
end
|
||||
p.specfile = abspath(p.specfile);
|
||||
end
|
||||
|
||||
|
||||
% ptycho path
|
||||
if isempty(p.ptycho_matlab_path)
|
||||
% find template_ptycho and assume that the base path is there
|
||||
p.ptycho_matlab_path = fileparts(which('template_ptycho.m'));
|
||||
verbose(3, 'Using default value for ptycho_matlab_path: %s', p.ptycho_matlab_path )
|
||||
end
|
||||
|
||||
% base package path
|
||||
if isempty(p.cSAXS_matlab_path)
|
||||
if exist(fullfile(p.base_path,'matlab'), 'dir')
|
||||
p.cSAXS_matlab_path = fullfile(p.base_path,'matlab');
|
||||
verbose(3, 'Using default value for cSAXS_matlab_path: %s', p.cSAXS_matlab_path )
|
||||
end
|
||||
end
|
||||
|
||||
% do some basic corrections of the paths
|
||||
for path = {'base_path', 'ptycho_matlab_path', 'cSAXS_matlab_path', 'prepare_data_path', 'positions_file'}
|
||||
if isfield(p, path{1}) && ~isempty(p.(path{1}))
|
||||
p.(path{1}) = abspath(p.(path{1}));
|
||||
end
|
||||
end
|
||||
|
||||
%% add paths, but only if not included already
|
||||
|
||||
if exist(p.ptycho_matlab_path, 'dir') && ~exist(fullfile('+core', 'get_projections.m'),'file')
|
||||
addpath(p.ptycho_matlab_path)
|
||||
% check if ptycho_matlab_path is already included
|
||||
elseif ~exist( fullfile('+core', 'get_projections.m'), 'file')
|
||||
verbose(1,'Nonexistent ptycho_matlab_path: "%s"', p.ptycho_matlab_path)
|
||||
end
|
||||
|
||||
if exist(fullfile(p.ptycho_matlab_path, 'utils'), 'dir') && ~exist(fullfile('aligned_FSC.m'),'file')
|
||||
addpath(fullfile(p.ptycho_matlab_path, 'utils'))
|
||||
% check if ptycho_matlab_path/utils is already included
|
||||
elseif ~exist(fullfile('aligned_FSC.m'),'file')
|
||||
verbose(1,'Nonexistent ptycho_matlab_path: "%s/utils"', p.ptycho_matlab_path)
|
||||
end
|
||||
|
||||
if exist(p.cSAXS_matlab_path, 'dir') && ~exist(fullfile('+math', 'argmax.m'), 'file')
|
||||
addpath(p.cSAXS_matlab_path);
|
||||
% check if cSAXS_matlab_path is already included
|
||||
elseif ~exist(fullfile('+math', 'argmax.m'), 'file')
|
||||
verbose(1,'Nonexistent cSAXS_matlab_path: "%s"', p.cSAXS_matlab_path)
|
||||
end
|
||||
verbose(p.verbose_level);
|
||||
|
||||
|
||||
else
|
||||
|
||||
% base path
|
||||
if ~exist(p.base_path, 'dir')
|
||||
error('base_path = %s : Base directory does not exist.', p.base_path);
|
||||
end
|
||||
verbose(2, 'base_path = %s', p.base_path);
|
||||
|
||||
% Save data path
|
||||
for ii = 1:length(p.scan_number)
|
||||
p. scan_str{ii} = sprintf(p.scan_string_format, p.scan_number(ii)); % Scan string
|
||||
end
|
||||
|
||||
if isempty(p.save_path) || iscell(p.save_path)&&isempty(p.save_path{1})
|
||||
verbose(3, 'Using default save_path');
|
||||
for ii = 1:length(p.scan_number)
|
||||
p.save_path{ii} = fullfile(p.base_path, 'analysis',utils.compile_aps_dirname(p.scan_number(ii)),'');
|
||||
if ~exist(p.save_path{ii}, 'dir')
|
||||
mkdir(p.save_path{ii})
|
||||
end
|
||||
verbose(2, 'save_path = %s', p.save_path{ii});
|
||||
end
|
||||
else
|
||||
% not enough save paths; replicate
|
||||
if length(p.scan_number) > length(p.save_path)
|
||||
verbose(1, 'Number of save paths does not match number of scans. I will use only the first save path.')
|
||||
|
||||
if contains(p.save_path{1}, '%')
|
||||
% fill in the scan number if needed
|
||||
container = p.save_path{1};
|
||||
for ii=1:length(p.scan_number)
|
||||
p.save_path{ii} = sprintf(container, p.scan_number(ii));
|
||||
end
|
||||
else
|
||||
% if there is no variable to fill, append the scan number to
|
||||
% the given path
|
||||
container = p.save_path{1};
|
||||
for ii=1:length(p.scan_number)
|
||||
p.save_path{ii} = fullfile(container, p.scan_str{ii});
|
||||
end
|
||||
end
|
||||
clear container
|
||||
|
||||
else
|
||||
if contains(p.save_path{1}, '%')
|
||||
% fill in the scan number if needed
|
||||
for ii=1:length(p.scan_number)
|
||||
p.save_path{ii} = sprintf(p.save_path{ii}, p.scan_number(ii));
|
||||
end
|
||||
else
|
||||
% if there is no variable to fill, append the scan number to
|
||||
% the given path
|
||||
for ii=1:length(p.scan_number)
|
||||
p.save_path{ii} = fullfile(p.save_path{ii}, p.scan_str{ii});
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for ii = 1:length(p.scan_number)
|
||||
p.save_path{ii} = rm_delimiter(p.save_path{ii});
|
||||
if ~exist(p.save_path{ii}, 'dir')
|
||||
mkdir(p.save_path{ii})
|
||||
end
|
||||
verbose(2, 'save_path = %s', p.save_path{ii});
|
||||
end
|
||||
|
||||
end
|
||||
% Prepare data path
|
||||
if isempty(p.prepare_data_path)|| iscell(p.prepare_data_path)&&isempty(p.prepare_data_path{1})
|
||||
verbose(3, 'Using default prepared data path');
|
||||
p.prepare_data_path = p.save_path{1};
|
||||
else
|
||||
if iscell(p.prepare_data_path)
|
||||
p.prepare_data_path = cell2str(p.prepare_data_path);
|
||||
end
|
||||
if contains(p.prepare_data_path, '%')
|
||||
% fill in the scan number if needed
|
||||
p.prepare_data_path = sprintf(p.prepare_data_path, p.scan_number(1));
|
||||
else
|
||||
% if there is no variable to fill, append the scan number to
|
||||
% the given path
|
||||
p.prepare_data_path = fullfile(p.prepare_data_path, p.scan_str{1});
|
||||
end
|
||||
end
|
||||
p.prepare_data_path = replace(p.prepare_data_path,'\','\\');
|
||||
p.prepare_data_path = add_delimiter(p.prepare_data_path);
|
||||
if ~exist(p.prepare_data_path, 'dir')
|
||||
mkdir(p.prepare_data_path)
|
||||
end
|
||||
verbose(2, 'prepare_data_path = %s', p.prepare_data_path);
|
||||
|
||||
|
||||
|
||||
% prepare data filename
|
||||
if isempty(p.prepare_data_filename)
|
||||
verbose(3, 'Using default prepared data filename');
|
||||
if ~p.detector.binning
|
||||
p.prepare_data_filename = [sprintf('S%05d_data_%03dx%03d',p.scan_number(1), p.asize(1), p.asize(2)) p.prepare.prep_data_suffix '.h5'];
|
||||
else
|
||||
p.prepare_data_filename = [sprintf('S%05d_data_%03dx%03d_b%i',p.scan_number(1), p.asize(1), p.asize(2),p.detector.binning) p.prepare.prep_data_suffix '.h5'];
|
||||
end
|
||||
verbose(2, 'prepare_data_filename = %s', p.prepare_data_filename);
|
||||
end
|
||||
|
||||
|
||||
% raw data path
|
||||
if p.prepare.auto_prepare_data
|
||||
if isempty(p.raw_data_path) || iscell(p.raw_data_path)&&isempty(p.raw_data_path{1})
|
||||
for ii = 1:length(p.scan_number)
|
||||
p.raw_data_path{ii} = p.base_path;
|
||||
%disp(p.raw_data_path{ii})
|
||||
end
|
||||
else
|
||||
if length(p.raw_data_path) ~= length(p.scan_number)
|
||||
if ~iscell(p.raw_data_path)
|
||||
p = str2cell(p, 'raw_data_path');
|
||||
end
|
||||
for ii = 2:length(p.scan_number)
|
||||
p.raw_data_path{ii} = p.raw_data_path{1};
|
||||
end
|
||||
end
|
||||
end
|
||||
% do some basic replacement to get the real path
|
||||
for ii = 1:length( p.raw_data_path)
|
||||
p.raw_data_path{ii} = abspath(p.raw_data_path{ii});
|
||||
p.raw_data_path{ii} = sprintf(replace(p.raw_data_path{ii},'\','\\') , p.scan_number(1));
|
||||
end
|
||||
else
|
||||
prepare_data_full_filename = fullfile(p.prepare_data_path, p.prepare_data_filename);
|
||||
if ~exist(prepare_data_full_filename, 'file'); error('prepared data file does not exist (%s).', prepare_data_full_filename); end
|
||||
end
|
||||
|
||||
% do some basic corrections of the paths
|
||||
for path = {'base_path', 'specfile', 'ptycho_matlab_path', 'cSAXS_matlab_path', 'prepare_data_path'}
|
||||
p.(path{1}) = abspath(p.(path{1}));
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
% convert single cell entry to string
|
||||
function p = cell2str(p, fn)
|
||||
tmp = p.(fn){1};
|
||||
p = rmfield(p, fn);
|
||||
p.(fn) = tmp;
|
||||
|
||||
end
|
||||
|
||||
% convert string to cell
|
||||
function p = str2cell(p, fn)
|
||||
tmp = p.(fn);
|
||||
p = rmfield(p, fn);
|
||||
p.(fn){1} = tmp;
|
||||
|
||||
end
|
||||
|
||||
% make sure that the path does not end with /
|
||||
function path = rm_delimiter(path)
|
||||
if ~isempty(path) && any(strcmp(path(end), {'\', '/'}))
|
||||
path = path(1:end-1);
|
||||
end
|
||||
end
|
||||
|
||||
% make sure that the path ends with /
|
||||
function path = add_delimiter(path)
|
||||
if ispc
|
||||
delimiter = '\';
|
||||
else
|
||||
delimiter = '/';
|
||||
end
|
||||
if ~isempty(path) && ~strcmp(path(end), delimiter)
|
||||
path = [path, delimiter];
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,241 @@
|
||||
%PTYCHO_PREPARE_SCANS Load data from disk and prepare the scan for the
|
||||
%ptychographic reconstruction.
|
||||
%
|
||||
% ** p p structure
|
||||
%
|
||||
% returns:
|
||||
% ++ p p structure
|
||||
% ++ status status flag
|
||||
%
|
||||
%
|
||||
% see also: core.initialize_ptycho
|
||||
%
|
||||
%
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function [ p, status] = ptycho_prepare_scans( p )
|
||||
import utils.verbose
|
||||
import utils.get_option
|
||||
|
||||
status=1;
|
||||
|
||||
% legacy
|
||||
if ~check_option(p.prepare, 'legacy')
|
||||
p.prepare.legacy = false;
|
||||
end
|
||||
|
||||
|
||||
%% check for lock file
|
||||
for ii = 1:length(p.scan_number)
|
||||
% Write lock file
|
||||
if p.queue.lockfile
|
||||
lock_filename = [p.save_path{ii} '/' p.run_name '_lock'];
|
||||
if exist(lock_filename, 'file')
|
||||
verbose(1,sprintf('%s locked by other instance of this script. Continue with next scan.', p.scan_str{ii}));
|
||||
out = [];
|
||||
status = 0;
|
||||
p.getReport.completed = true;
|
||||
return
|
||||
else
|
||||
if ~exist(p.save_path{ii},'dir')
|
||||
mkdir(p.save_path{ii});
|
||||
end
|
||||
verbose(2, 'Creating lock file: %s', lock_filename);
|
||||
unix(['touch ' lock_filename]);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
%% prepare data
|
||||
|
||||
% check prepared data file
|
||||
if ~p.prepare.force_preparation_data
|
||||
if ~exist(fullfile(p.prepare_data_path, p.prepare_data_filename), 'file')
|
||||
verbose(1,'Missing prepared data %s, Forcing data preparation',fullfile(p.prepare_data_path, p.prepare_data_filename) )
|
||||
p.prepare.force_preparation_data = true;
|
||||
else
|
||||
try
|
||||
if core.check_prepared_data(p)
|
||||
verbose(2, 'Prepared data does not match reconstruction parameters. Forcing data preparation.')
|
||||
p.prepare.force_preparation_data = true;
|
||||
end
|
||||
catch ME
|
||||
verbose(2, [ME.getReport '\n']);
|
||||
verbose(2, 'Prepared data check failed. Forcing data preparation.')
|
||||
p.prepare.force_preparation_data = true;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
% check if we need to prepare the data
|
||||
if p.prepare.auto_prepare_data && (~exist(fullfile(p.prepare_data_path, p.prepare_data_filename),'file')||p.prepare.force_preparation_data)
|
||||
prepare_data_bool = true;
|
||||
else
|
||||
prepare_data_bool = false;
|
||||
end
|
||||
|
||||
% prepare initial object and probes
|
||||
p = core.prepare_initial_guess(p);
|
||||
|
||||
if prepare_data_bool && ~p.prepare.legacy
|
||||
verbose(2, 'Loading raw data')
|
||||
p = core.run_data_preparator(p);
|
||||
elseif p.prepare.legacy
|
||||
%% prepare.legacy mode to load prepared data from mat files
|
||||
% Prepare data path
|
||||
error('Loading from .mat files is not supported anymore.')
|
||||
end
|
||||
|
||||
%% convert function handles to strings
|
||||
for jj=1:length(p.detectors)
|
||||
fn = fieldnames(p.detectors(jj).params);
|
||||
for ii=1:length(fn)
|
||||
if isa(p.detectors(jj).params.(fn{ii}) , 'function_handle')
|
||||
p.detectors(jj).params.(fn{ii}) = func2str(p.detectors(jj).params.(fn{ii}));
|
||||
end
|
||||
end
|
||||
|
||||
funcs_nm = fieldnames(p.detectors(jj).funcs);
|
||||
for ii=1:length(funcs_nm)
|
||||
p.detectors(jj).funcs.(funcs_nm{ii}) = func2str(p.detectors(jj).funcs.(funcs_nm{ii}));
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
% cleanup detector storage
|
||||
if isfield(p.detectors, 'detStorage')
|
||||
p.detectors = rmfield(p.detectors, 'detStorage');
|
||||
end
|
||||
|
||||
p.detectors = struct2cell(p.detectors);
|
||||
|
||||
|
||||
|
||||
%% output
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%% save/load prepared data to/from disk %%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
if p.prepare.store_prepared_data && (prepare_data_bool || p.prepare.legacy) && ~strcmpi(p.prepare.data_preparator, 'libDetXR')
|
||||
core.prep_h5data(p);
|
||||
end
|
||||
|
||||
% check if data needs to be loaded from disk
|
||||
if (~isfield(p,'fmag') || isempty(p.fmag) )&& (p.plot.prepared_data || ~p.external_engine0 || check_option(p, 'force_prepare_h5_files'))
|
||||
|
||||
%% TO BE DELETED
|
||||
% if (~p.external_engine0 && (~isfield(p,'fmag')) ) || p.external_engine0 && ...
|
||||
% (isfield(p.engines{1}, 'force_prepare_h5_files') && p.engines{1}.force_prepare_h5_files) || ...
|
||||
% (prepare_data_bool && strcmpi(p.prepare.data_preparator,'libDetXR') && p.plot.prepared_data && ~p.prepare.legacy)|| ...
|
||||
% (~prepare_data_bool && p.plot.prepared_data) || (p.model_object && strcmpi(p.model_object_type, 'prep_data') && ~prepare_data_bool)
|
||||
|
||||
verbose(2, 'Loading already prepared data.');
|
||||
[p.fmag, p.fmask, pos, max_power, scanindexrange, p.max_sum] = io.load_prepared_data(fullfile(p.prepare_data_path ,p.prepare_data_filename));
|
||||
|
||||
p.renorm = sqrt(1/max_power);
|
||||
p.Nphot = sum((p.fmag(:)/p.renorm).^2.*p.fmask(:));
|
||||
p.fmask_per_scan = (length(size(p.fmask)) == 3);
|
||||
|
||||
% shall the positions be overwritten?
|
||||
if p.io.load_prep_pos
|
||||
verbose(2,'Overwriting positions with values from prepared data.')
|
||||
p.positions = pos;
|
||||
p.scanindexrange = scanindexrange;
|
||||
p.numpts = diff(reshape(scanindexrange', 2, []),1);
|
||||
p.numpts(1) = p.numpts(1)+1; % scanindexrange starts at 1
|
||||
for ii = 1:p.numscans
|
||||
p.scanidxs{ii} = scanindexrange(ii,1):scanindexrange(ii,2);
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
% if not yet done,
|
||||
% apply binning on all relevant
|
||||
% parameters except data and mask that are already done
|
||||
if (p.detector.binning || p.detector.upsampling) && any(p.asize ~= (p.asize_nobin .* 2^-p.detector.binning * 2^p.detector.upsampling))
|
||||
if p.detector.binning
|
||||
p = core.apply_binning(p, 2^p.detector.binning);
|
||||
end
|
||||
if p.detector.upsampling
|
||||
% just reverse operation to the binning
|
||||
p = core.apply_binning(p, 2^(-p.detector.upsampling) );
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
% initial guess for Fourier ptychography
|
||||
if p.model_object && strcmpi(p.model.object_type, 'amplitude')
|
||||
k = 2*pi/p.lambda;
|
||||
objpix = p.lambda*p.z_lens./(p.asize.*p.dx_spec);
|
||||
for ii=1:length(p.object)
|
||||
[Xp,Yp] = utils.get_grid(p.object_size(ii,:), objpix(1));
|
||||
pre_phase_factor = exp(-1i*k*((Xp./(p.object_size(ii,2)/(p.asize(2)))).^2+(Yp./(p.object_size(ii,1)/(p.asize(1)))).^2)/(2*p.z_lens));
|
||||
init_guess = rot90(mean(p.fmag,3),2);
|
||||
init_guess = init_guess./(max(max(init_guess)))./(p.asize(1).*p.asize(2)).*p.numpts;
|
||||
|
||||
p.object{ii} = fftshift(fft2(ifft2(ifftshift(utils.crop_pad(fftshift(fft2(init_guess.*exp(-1j.*(init_guess./(max(max(init_guess))).*2*pi-pi)))), p.object_size(ii,:)))).*fftshift(pre_phase_factor)));
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,309 @@
|
||||
% [OUT, STATUS] = PTYCHO_RECONS(P, PREPARE_ONLY = false)
|
||||
% Runs the reconstruction using parameters in the structure p.
|
||||
% Returns a structure OUT containing all necessary information.
|
||||
%
|
||||
% ** p p structure
|
||||
%
|
||||
% *optional*
|
||||
% ** prepare_only stop after the data preparation; default: false
|
||||
%
|
||||
% returns:
|
||||
% out updated p structure
|
||||
%
|
||||
% see also: template_ptycho
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function [out,status] = ptycho_recons(p, prepare_only)
|
||||
|
||||
if ~exist('+math/argmax.m','file')
|
||||
if exist(p.cSAXS_matlab_path, 'dir') %% avoid repeated loading by testing availibility of argmax.m file
|
||||
addpath(p.cSAXS_matlab_path);
|
||||
elseif ~isempty(p.cSAXS_matlab_path)
|
||||
warning('Nonexistent cSAXS_matlab_path: "%s"', p.cSAXS_matlab_path)
|
||||
end
|
||||
end
|
||||
import utils.*
|
||||
|
||||
if nargin < 2
|
||||
prepare_only = false;
|
||||
end
|
||||
|
||||
caller = dbstack;
|
||||
p.caller = caller(end).name;
|
||||
|
||||
if ~isfield(p, 'queue')
|
||||
p.queue = struct();
|
||||
end
|
||||
if ~isfield(p, 'io')
|
||||
p.io = struct();
|
||||
end
|
||||
|
||||
if ~isfield(p.io, 'SMS_sleep')
|
||||
p.io.SMS_sleep = 1800;
|
||||
end
|
||||
|
||||
if ~isfield(p.io, 'phone_number')
|
||||
p.io.phone_number = [];
|
||||
end
|
||||
|
||||
if ~isfield(p.io, 'send_failed_scans_SMS')
|
||||
p.io.send_failed_scans_SMS = false;
|
||||
end
|
||||
if ~isfield(p.io, 'send_finished_recon_SMS')
|
||||
p.io.send_finished_recon_SMS = false;
|
||||
end
|
||||
if ~isfield(p.io, 'send_crashed_recon_SMS')
|
||||
p.io.send_crashed_recon_SMS = false;
|
||||
end
|
||||
|
||||
utils.verbose(struct('prefix', {'init'}))
|
||||
p. run_name = '';
|
||||
|
||||
p.getReport.completed = false;
|
||||
|
||||
p = core.ptycho_prepare_paths(p, true);
|
||||
|
||||
if isfield(p.queue,'path')&&~isempty(p.queue.path) && ~isfield(p.queue, 'name')
|
||||
verbose(0,'Missing setting of p.queue.name, using default p.queue.name=''filelist'' ')
|
||||
p.queue.name = 'filelist';
|
||||
end
|
||||
|
||||
if ~isfield(p.queue, 'isreplica')
|
||||
p.queue.isreplica = false;
|
||||
end
|
||||
if ~isfield(p.queue, 'remote_recons')
|
||||
p.queue.remote_recons = false;
|
||||
end
|
||||
|
||||
p.recon_success = false; %% added by YJ
|
||||
|
||||
% the existence of this file will cancel the calculation,
|
||||
% CTRL-C replacement, checked each iteration
|
||||
p.io.break_check_name = '/tmp/break_ptycho';
|
||||
% Function for clean exit, currently used to exit matlab to clean memory
|
||||
% from MEX upon Ctrl-c
|
||||
% c = onCleanup(@()ptycho_exit);
|
||||
|
||||
% Check screen size
|
||||
try
|
||||
p.plot.scrsz = get(0,'ScreenSize');
|
||||
catch
|
||||
p.plot.scrsz = [1 1 2560 1024];
|
||||
end
|
||||
|
||||
finishup = utils.onCleanup(@(x) ptycho_exit(x), p);
|
||||
|
||||
function ptycho_call()
|
||||
import utils.*
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%% Check for file queue %%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
[p, status] = scans.get_queue(p, false);
|
||||
if ~status
|
||||
return
|
||||
end
|
||||
|
||||
p. run_name = [p.prefix core.generate_scan_name(p) '_' num2str(p.asize(1)/2^p.detector.binning) 'x' num2str(p.asize(2)/2^p.detector.binning) '_b' num2str(p.detector.binning) '_' p.suffix]; % If empty: automatically generated
|
||||
|
||||
finishup.update(p);
|
||||
|
||||
if ~p.queue.remote_recons || p.queue.isreplica
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
% initialize ptycho and prepare object and probe
|
||||
[p, status] = core.initialize_ptycho(p); %p.positions are created here. unit: pxiel
|
||||
|
||||
if ~status || prepare_only
|
||||
finishup.update(p);
|
||||
out = {p};
|
||||
return;
|
||||
end
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
verbose(struct('prefix', {'ptycho'}))
|
||||
verbose(0, ['Reconstructing ' repmat('S%05d ', 1, numel(p.scan_number))], p.scan_number)
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%%%%%%%%%%%%%%% MAIN PTYCHOGRAPHY CODE %%%%%%%%%%%%%%%%%%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
% get all engines
|
||||
verbose(struct('prefix', {'ptycho'}))
|
||||
for ieng=1:length(p.engines)
|
||||
etic = tic();
|
||||
p.current_engine_id = ieng;
|
||||
|
||||
% engine call
|
||||
verbose(1, 'Calling engine %s', p.engines{ieng}.name)
|
||||
verbose(struct('prefix', {p.engines{ieng}.name}))
|
||||
|
||||
|
||||
[p, fdb] = core.run_engine(p,ieng);
|
||||
if fdb.status.status ~= 0
|
||||
error('Engine %s returned with exit status %d from %s [%d].\n', p.engines{ieng}.name, fdb.status.status, fdb.status.ln(1).name, fdb.status.ln(1).line);
|
||||
end
|
||||
|
||||
fdb = [];
|
||||
|
||||
if p.ortho_probes && size(p.probes,4)>1
|
||||
% orthogonalize probes
|
||||
p.probes = core.probe_modes_ortho(p.probes);
|
||||
end
|
||||
|
||||
% save reconstructed object, probe and feedback in the p structure of
|
||||
% the currently used engine
|
||||
p.engines{ieng}.object_final = p.object;
|
||||
p.engines{ieng}.probes_final = p.probes;
|
||||
p.engines{ieng}.error_metric_final = p.error_metric;
|
||||
|
||||
% store images of current engine
|
||||
if p.save.store_images_intermediate
|
||||
p = core.save.save_results(p, 0);
|
||||
end
|
||||
|
||||
if ieng~=length(p.engines) && p.use_display
|
||||
% intermediate results, not yet final plotting
|
||||
core.analysis.plot_results(p);
|
||||
end
|
||||
|
||||
etoc = toc(etic);
|
||||
verbose(struct('prefix', {'ptycho'}))
|
||||
verbose(1, 'Elapsed time for engine %s: %0.1f s', p.engines{ieng}.name, etoc)
|
||||
|
||||
end
|
||||
|
||||
|
||||
verbose(struct('prefix', {'saving'}))
|
||||
try
|
||||
p = core.save.save_results(p, 1);
|
||||
catch ME
|
||||
if p.verbose_level > 3
|
||||
keyboard
|
||||
else
|
||||
disp('####### Failed to save data. ##########');
|
||||
rethrow(ME)
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
% remote reconstruction
|
||||
% p.queue.isreplica = false;
|
||||
p = core.export4remote(p);
|
||||
finishup.update(p);
|
||||
[p, status] = core.remote_status(p);
|
||||
if ~status
|
||||
core.remote_cleanup(p, status);
|
||||
finishup.update(p);
|
||||
out = {p};
|
||||
return;
|
||||
end
|
||||
end
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
if p.queue.remote_recons
|
||||
status = core.remote_cleanup(p, true);
|
||||
end
|
||||
|
||||
[p, status] = scans.get_queue(p, true);
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
p.getReport.completed = true;
|
||||
|
||||
finishup.update(p);
|
||||
end
|
||||
|
||||
if p.verbose_level > 3
|
||||
fprintf('\n###############################################################\n')
|
||||
fprintf('########################## DEBUG MODE #########################\n')
|
||||
fprintf('###############################################################\n')
|
||||
ptycho_call();
|
||||
else
|
||||
try
|
||||
ptycho_call();
|
||||
p.recon_success = true; %% added by YJ
|
||||
|
||||
catch ME
|
||||
p.getReport.ME = ME;
|
||||
p.getReport.crashed = true;
|
||||
finishup.update(p);
|
||||
status = false;
|
||||
p.recon_success = false; %% added by YJ
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
out = p;
|
||||
return
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
%REMOTE_CLEANUP
|
||||
% remove temporary files on the remote machine and move the reconstruction
|
||||
% to the save path on the primary machine
|
||||
%
|
||||
% ** p p structure
|
||||
% ** completed boolean; true if reconstruction finished properly
|
||||
%
|
||||
% returns:
|
||||
% ++ status status flag
|
||||
%
|
||||
% see also: core.ptycho_recons
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function status = remote_cleanup(p, completed)
|
||||
import utils.verbose
|
||||
|
||||
logfile = [p.run_name '.mat'];
|
||||
|
||||
status = 1;
|
||||
|
||||
if ~completed
|
||||
try
|
||||
if exist(fullfile(p.queue.remote_path, 'failed', logfile), 'file')
|
||||
delete(fullfile(p.queue.remote_path, 'failed', logfile))
|
||||
delete(fullfile(p.queue.remote_path, 'failed', [p.run_name '.log']))
|
||||
end
|
||||
catch
|
||||
status = false;
|
||||
verbose(1, 'Failed to remove logfile.')
|
||||
end
|
||||
else
|
||||
% copy reconstruction to output directory
|
||||
for ii = 1:length(p.scan_number)
|
||||
p. scan_str{ii} = sprintf(p.scan_string_format, p.scan_number(ii)); % Scan string
|
||||
end
|
||||
% Save data path
|
||||
if isempty(p.save_path) || iscell(p.save_path)&&isempty(p.save_path{1})
|
||||
verbose(3, 'Using default save_path');
|
||||
for ii = 1:length(p.scan_number)
|
||||
p.save_path{ii} = fullfile(p.base_path, 'analysis',p.scan_str{ii},'');
|
||||
if ~exist(p.save_path{ii}, 'dir')
|
||||
mkdir(p.save_path{ii})
|
||||
end
|
||||
verbose(2, 'save_path = %s', p.save_path{ii});
|
||||
end
|
||||
else
|
||||
if length(p.scan_number) ~= length(p.save_path)
|
||||
error('Number of specified save paths does not match the scan number.')
|
||||
else
|
||||
for ii = 1:length(p.scan_number)
|
||||
if ~exist(p.save_path{ii}, 'dir')
|
||||
mkdir(p.save_path{ii})
|
||||
end
|
||||
verbose(2, 'save_path = %s', p.save_path{ii});
|
||||
end
|
||||
end
|
||||
end
|
||||
for ii=1:numel(p.scan)
|
||||
system(['mv ' fullfile(p.queue.tmp_dir_remote, 'analysis', p.scan_str{ii}, '*') ' ' p.save_path{ii}]);
|
||||
end
|
||||
verbose(2, 'Deleting remote logfile.')
|
||||
delete(fullfile(p.queue.remote_path, 'done', logfile))
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
@@ -0,0 +1,122 @@
|
||||
%REMOTE_STATUS
|
||||
% Check the current status of the remote reconstruction
|
||||
%
|
||||
% ** p p structure
|
||||
%
|
||||
% returns:
|
||||
% ++ p updated p structure
|
||||
% ++ status status flag
|
||||
%
|
||||
% see also: core.ptycho_recons
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
|
||||
function [p, status] = remote_status(p)
|
||||
import utils.verbose
|
||||
|
||||
status = 1;
|
||||
|
||||
logfile = [p.run_name '.mat'];
|
||||
|
||||
if exist(fullfile(p.queue.remote_path, logfile), 'file')
|
||||
verbose(2, 'Waiting for remote replica to start the reconstruction.')
|
||||
end
|
||||
|
||||
recon_started = false;
|
||||
log_int_prev = 0;
|
||||
while true
|
||||
if ~recon_started && exist(fullfile(p.queue.remote_path, 'in_progress', logfile), 'file')
|
||||
verbose(2, 'Reconstruction started...')
|
||||
recon_started = true;
|
||||
end
|
||||
if exist(fullfile(p.queue.remote_path, 'done', logfile), 'file')
|
||||
verbose(2, 'Reconstruction finished on remote replica.')
|
||||
break;
|
||||
elseif exist(fullfile(p.queue.remote_path, 'failed', logfile), 'file')
|
||||
verbose(2, 'Reconstruction failed on remote replica.')
|
||||
p.remote_failed = true;
|
||||
status = 0;
|
||||
break;
|
||||
else
|
||||
if exist(fullfile(p.queue.remote_path, 'failed', strrep(logfile, 'mat', 'log')), 'file')
|
||||
fid = fopen(fullfile(p.queue.remote_path, 'failed', strrep(logfile, 'mat', 'log')));
|
||||
log_line = fgetl(fid);
|
||||
fclose(fid);
|
||||
log_int = strtrim(strsplit(log_line, ':'));
|
||||
log_int = log_int{end};
|
||||
log_int = str2double(log_int);
|
||||
if log_int>log_int_prev
|
||||
verbose(2, 'Reconstruction failed on remote replica %u time(s).', log_int)
|
||||
log_int_prev = log_int;
|
||||
end
|
||||
end
|
||||
if exist(fullfile(p.queue.remote_path, strrep(logfile, 'mat', 'crash')), 'file')
|
||||
delete(fullfile(p.queue.remote_path, strrep(logfile, 'mat', 'crash')));
|
||||
status=0;
|
||||
break;
|
||||
end
|
||||
|
||||
pause(0.5)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
%RUN_DATA_PREPARATOR
|
||||
% prepare the function handle and call the data preparator
|
||||
%
|
||||
% ** p p structure
|
||||
%
|
||||
% returns:
|
||||
% ++ p updated p structure
|
||||
%
|
||||
% see also: core.ptycho_prepare_scans
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function p = run_data_preparator(p)
|
||||
import utils.verbose
|
||||
|
||||
%% run data preparator
|
||||
|
||||
data_prep_func = str2func(sprintf('detector.prep_data.%s.%s', p.prepare.data_preparator, p.prepare.data_preparator));
|
||||
p = data_prep_func(p);
|
||||
|
||||
|
||||
|
||||
end
|
||||
@@ -0,0 +1,106 @@
|
||||
%RUN_ENGINE
|
||||
% calls engine 'eng'
|
||||
%
|
||||
% ** p p structure
|
||||
% ** eng name of the current engine
|
||||
%
|
||||
% returns:
|
||||
% ++ p update p structure
|
||||
% ++ fdb feedback structure of the engine
|
||||
%
|
||||
% see also: core.ptycho_recons
|
||||
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function [p, fdb] = run_engine(p, ieng)
|
||||
|
||||
if isfield(p, 'error_metric')
|
||||
p_eng = rmfield(p, 'error_metric');
|
||||
else
|
||||
p_eng = p;
|
||||
end
|
||||
%% load settings from engine structure to the param structure
|
||||
[p_eng, items] = update_structure(p_eng, p_eng.engines{ieng});
|
||||
|
||||
%% call engine
|
||||
core.engine_status(0);
|
||||
engine_fnct = str2func(['engines.' p.engines{ieng}.name]);
|
||||
[p_eng, fdb] = engine_fnct(p_eng);
|
||||
%% adjust output, remove items in p.engines{ieng} from p
|
||||
for item=1:size(items,1)
|
||||
if isfield(p_eng, items{item})
|
||||
p_eng = rmfield(p_eng, items{item});
|
||||
end
|
||||
end
|
||||
p = utils.update_param(p, p_eng, 'force_update', 2);
|
||||
end
|
||||
|
||||
function [struct_0, items] = update_structure(struct_0, struct_new)
|
||||
% recursively update structures and values in the struct_0 by values
|
||||
% in struct_new. Return updated struct_0 and list of the updated field
|
||||
% in the ground level
|
||||
|
||||
items = fieldnames(struct_new);
|
||||
for item=1:size(items,1)
|
||||
if ~isstruct(struct_new.(items{item}))
|
||||
struct_0.(items{item}) = struct_new.(items{item});
|
||||
else
|
||||
struct_0.(items{item}) = update_structure(struct_0.(items{item}), struct_new.(items{item}));
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
% RUN_RECEIVER
|
||||
% modify p structure and run ptycho_recons.
|
||||
%
|
||||
% ** p p structure
|
||||
%
|
||||
% see also: setup_remote_recons
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function run_receiver(p)
|
||||
|
||||
if isempty(p.cSAXS_matlab_path)
|
||||
error('p.cSAXS_matlab_path has to be specified for the remote reconstruction.')
|
||||
end
|
||||
if isempty(p.ptycho_matlab_path)
|
||||
error('p.ptycho_matlab_path has to be specified for the remote reconstruction.')
|
||||
end
|
||||
if isempty(p.queue.remote_path)
|
||||
error('p.queue.remote_path has to be specified for the remote reconstruction.')
|
||||
end
|
||||
|
||||
p.queue.name = 'remote_queue';
|
||||
p.queue.isreplica = true;
|
||||
p.save_path = '';
|
||||
p.queue.path = p.queue.remote_path;
|
||||
core.ptycho_recons(p);
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
%SET_PROJETIONS
|
||||
%
|
||||
% ** p p structure
|
||||
% ** object full-size object
|
||||
% ** obj_update container for object projections
|
||||
% ** scan_id ID of the current scan
|
||||
%
|
||||
% return:
|
||||
% ++ object updated object
|
||||
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function object = set_projections(p, object, obj_update, scan_id)
|
||||
import utils.verbose
|
||||
|
||||
Npos = length(p.scanidxs{scan_id});
|
||||
Nmodes = size(object,4);
|
||||
|
||||
if any(double(max(round(p.positions(p.scanidxs{scan_id},:))))+(p.asize) > size(object))
|
||||
error('Object is too small for given positions')
|
||||
end
|
||||
|
||||
if Nmodes == 1 && (isa(object, 'gpuArray') || isa(obj_update, 'gpuArray'))
|
||||
% use function from GPU engine
|
||||
cache.skip_ind = [];
|
||||
positions = round(p.positions(p.scanidxs{scan_id},:));
|
||||
cache.oROI_s{1}{1} = uint32(positions(:,1));
|
||||
cache.oROI_s{1}{2} = uint32(positions(:,2));
|
||||
object = engines.GPU.shared.set_views(object, obj_update, 1,1,int32(1:Npos),cache);
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
if Nmodes == 1
|
||||
% faster MEX based function
|
||||
positions = int32(p.positions(p.scanidxs{scan_id},:));
|
||||
indices = int32(1:Npos);
|
||||
object = utils.add_to_3D_projection(obj_update,object,positions,indices, true);
|
||||
else
|
||||
verbose(3, 'Using slow nonMEX version of set_projections')
|
||||
id_0 = p.scanidxs{scan_id}(1)-1;
|
||||
for jj = p.scanidxs{scan_id}
|
||||
Indy = round(p.positions(jj,1)) + (1:p.asize(1));
|
||||
Indx = round(p.positions(jj,2)) + (1:p.asize(2));
|
||||
object(Indy,Indx,:) = object(Indy,Indx,:) + obj_update(:,:,min(jj-id_0,end),:);
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,79 @@
|
||||
%UPDATE_OBJECT_SIZE updates size of the object so that all probe positions
|
||||
%are withing this regions
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
|
||||
function p = update_object_size(p)
|
||||
import utils.verbose
|
||||
|
||||
% Compute object sizes
|
||||
if length(unique(p.share_object_ID))==1 || strcmp(p.engines{1}.name,'ML_MS') % If the other scans have different object sizes as that of the first scan, else matlab-ML_MS crashes
|
||||
%p.object_size = p.asize + max(round(p.positions),[],1) + p.positions_pad;
|
||||
%modified by YJ s.t. object_size is consistent with the one
|
||||
%calculated by GPU engine
|
||||
p.object_size = p.asize + max(ceil(p.positions),[],1) + p.positions_pad;
|
||||
|
||||
verbose(2, 'Computed object size: %d x %d', p.object_size(1), p.object_size(2));
|
||||
else
|
||||
for ii = unique(p.share_object_ID)
|
||||
p.object_size(ii,:) = p.asize + max(round(p.share_pos{ii}),[],1) + p.positions_pad;
|
||||
verbose(2, 'Computed object size: %d x %d', p.object_size(ii,1), p.object_size(ii,2));
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user