initial commit

This commit is contained in:
2026-08-07 15:56:42 +09:00
commit 91ad25aca9
1012 changed files with 159314 additions and 0 deletions
@@ -0,0 +1,73 @@
%EIGER settings for Eiger detector
% This file is called if you specify p.detector = 'eiger_APS'.
% ** p p structure
% returns:
% ++ det detector structure; later accessible via p.detectors(ii).params
%
% see also: detector.load_detector
function [ det ] = Pilatus300K_APS( p )
local_path = fileparts(mfilename('fullpath'));
%% parameter
det.pixel_size = 172e-6; % detector pixel size
det.file_extension = 'h5'; % raw data file extension
%det.mask = [local_path, '/eiger_valid_mask.mat']; % detector mask from PSI's detector. Need to change for APS
det.basepath_dir = 'eiger/'; % raw data directory
det.mask_saturated_value = []; % mask pixels above given value
det.mask_below_value = []; % mask pixels below given value
det.data_stored = true; % false == data are generated "onfly", no need to load / store
%det.geometry.sz = [1030 514]; % detector readout size
det.geometry.sz = [1024 1024]; % detector readout size
det.geometry.mask = []; % if the mask is larger than the readout
% geometry (det.geometry.sz), geometry.mask defines the readout for the mask
% e.g. geometry.mask = {[50:500], [50:500]}
det.orientation = [1 0 0]; % [<Transpose> <FlipLR> <FlipUD>]
% additional arguments for image_read
det.image_read_extraargs = {'H5Location', '/eh5/images/'};
%% define directory tree structure
% define a function handle for compiling the scan directory tree. Input
% should be the scan number.
det.read_path = @utils.compile_aps_dirname;
%% filename
% specify funcion for compiling the filename. Input and output should be p and a
% temporary structure, containing information about the currently prepared scan.
% Cf. '+scans/get_filenames_cSAXS.m'
det.get_filename = @scans.get_filenames_aps;
%{
% additional parameters for the filename function (det.get_filename)
det.filename_pattern{1}.str = '%05d';
det.filename_pattern{1}.del = '_';
det.filename_pattern{1}.content = 'scan';
det.filename_pattern{1}.start = 0;
det.filename_pattern{2}.str = '%05d';
det.filename_pattern{2}.del = '_';
% det.filename_pattern{2}.content = 'burst';
det.filename_pattern{2}.start = 0;
det.filename_pattern{3}.str = '%05d';
det.filename_pattern{3}.del = '.';
% det.filename_pattern{3}.content = 'pos';
det.filename_pattern{3}.start = 0;
if ~isfield(p, 'omny_interferometer') || (strcmp(p.omny_interferometer, 'opos_angle') || strcmp(p.omny_interferometer, 'opos'))
det.filename_pattern{2}.content = 'burst';
det.filename_pattern{3}.content = 'pos';
else
det.filename_pattern{2}.content = 'pos';
det.filename_pattern{3}.content = 'burst';
end
%}
end
+125
View File
@@ -0,0 +1,125 @@
%EIGER settings for Eiger detector
% This file is called if you specify p.detector = 'eiger'.
% ** p p structure
% returns:
% ++ det detector structure; later accessible via p.detectors(ii).params
%
% see also: detector.load_detector
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 [ det ] = eiger( p )
local_path = fileparts(mfilename('fullpath'));
%% parameter
det.pixel_size = 75e-6; % detector pixel size
det.file_extension = 'h5'; % raw data file extension
det.mask = [local_path, '/eiger_valid_mask.mat']; % detector mask
det.basepath_dir = 'eiger/'; % raw data directory
det.mask_saturated_value = []; % mask pixels above given value
det.mask_below_value = []; % mask pixels below given value
det.data_stored = true; % false == data are generated "onfly", no need to load / store
det.geometry.sz = [1030 514]; % detector readout size
det.geometry.mask = []; % if the mask is larger than the readout
% geometry (det.geometry.sz), geometry.mask defines the readout for the mask
% e.g. geometry.mask = {[50:500], [50:500]}
det.orientation = [0 0 1]; % [<Transpose> <FlipLR> <FlipUD>]
% additional arguments for image_read
det.image_read_extraargs = {'H5Location', '/eh5/images/'};
%% define directory tree structure
% define a function handle for compiling the scan directory tree. Input
% should be the scan number.
det.read_path = @utils.compile_x12sa_dirname;
%% filename
% specify funcion for compiling the filename. Input and output should be p and a
% temporary structure, containing information about the currently prepared scan.
% Cf. '+scans/get_filenames_cSAXS.m'
det.get_filename = @scans.get_filenames_cSAXS;
% additional parameters for the filename function (det.get_filename)
det.filename_pattern{1}.str = '%05d';
det.filename_pattern{1}.del = '_';
det.filename_pattern{1}.content = 'scan';
det.filename_pattern{1}.start = 0;
det.filename_pattern{2}.str = '%05d';
det.filename_pattern{2}.del = '_';
% det.filename_pattern{2}.content = 'burst';
det.filename_pattern{2}.start = 0;
det.filename_pattern{3}.str = '%05d';
det.filename_pattern{3}.del = '.';
% det.filename_pattern{3}.content = 'pos';
det.filename_pattern{3}.start = 0;
if ~isfield(p, 'omny_interferometer') || (strcmp(p.omny_interferometer, 'opos_angle') || strcmp(p.omny_interferometer, 'opos'))
det.filename_pattern{2}.content = 'burst';
det.filename_pattern{3}.content = 'pos';
else
det.filename_pattern{2}.content = 'pos';
det.filename_pattern{3}.content = 'burst';
end
end
+147
View File
@@ -0,0 +1,147 @@
% function convert(scan, raw_data_path)
% convert .raw files to .cbf
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 convert(scan, raw_data_path)
cbf_maker_path = '/sls/X12SA/data/x12saop/EigerPackage/slsDetectorsPackage/bin/cbfMaker1.5MOMNY';
load_dir = utils.compile_x12sa_dirname(scan);
if exist(['~/Data10/eiger_4/'])
load_dir = ['~/Data10/eiger_4/' load_dir];
elseif exist([raw_data_path,'eiger_4/'])
load_dir = [raw_data_path,'/eiger_4/' load_dir];
elseif exist([raw_data_path,'/eigeromny/'])
load_dir = [raw_data_path,'/eigeromny/' load_dir];
end
if ~exist(load_dir, 'dir')
return
end
testDir = [load_dir, '/deleteMe'];
% test for write permissions by creating a folder and then deleting it
isWritable = mkdir(testDir);
% check if directory creation was successful
if isWritable == 1
rmdir(fullfile(testDir));
end
list_cbf = dir([load_dir, '/run_*.cbf']);
file_sizes = [list_cbf.bytes];
if any(file_sizes < 1e6) % find files < 1MB
warning('CBF files in scan %i seems damaged, generate again ... ', scan)
list_raw = dir([load_dir, '/run_d0_f0000000*.raw']);
if isempty(list_raw)
error('RAW data are missing, data cannot be converted')
else
delete(sprintf('%s/*.cbf',load_dir))
end
list_cbf = dir([load_dir, '/run_*.cbf']);
end
if isempty(list_cbf)
if ~isWritable
warning('Conversion failed because folder %s is not writable', load_dir)
return
end
list_raw = dir([load_dir, '/run_d0_f0000000*.raw']);
Nscans = length(list_raw);
for ii = 1:Nscans
ind_scans(ii) = str2num(list_raw(ii).name(16:17));
end
% if Nscans > 1
% parfor (ii = 1:Nscans, Nscans)
% [~,out] = system(sprintf('%s %s/run_d0_f00000000%02i000_%05i.cbf',cbf_maker_path, load_dir, ind_scans(ii) ,scan));
% end
% else
for ii = 1:Nscans
[~,out] = system(sprintf('%s %s/run_d0_f00000000%02i000_%05i.raw',cbf_maker_path, load_dir, ind_scans(ii) ,scan));
end
% end
list_cbf = dir([load_dir, '/*.cbf']);
nframes_converted = length(list_cbf);
out = splitlines(out);
nframes_expected = str2num(out{end-2}(14:end));
fprintf('Frames expected: %i, frames converted %i \n', nframes_expected, nframes_converted)
if nframes_converted == nframes_expected
% for ii=1:nframes_expected
% thisfile = fullfile(load_dir,list_cbf(ii).name);
% dataaux = io.image_read(thisfile,'RowFrom',1,'RowTo',2,'ColumnFrom',1,'ColumnTo',2);
% data(:,:,ii) = dataaux.data(:,:,1);
% end
fprintf('Scan %i succefully converted to CBF\n', scan);
delete(sprintf('%s/*.raw',load_dir))
else
error('Scan %i WAS NOT CONVERTED to CBF\n', scan)
delete(sprintf('%s/*.cbf',load_dir))
end
end
end
+150
View File
@@ -0,0 +1,150 @@
% function convert(scan, raw_data_path)
% convert .raw files to .hdf5
% Inputs
% scan scan number
% raw_data_path path to the raw data (optional)
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 convert2hdf5(scan, raw_data_path)
convertor_path = '/sls/X12SA/data/x12saop/EigerPackage/slsDetectorsPackage/bin/hdf5MakerOMNY';
load_dir = utils.compile_x12sa_dirname(scan);
if exist('raw_data_path','var')&&exist(fullfile(raw_data_path,load_dir),'dir')
load_dir = fullfile(raw_data_path,load_dir);
elseif exist(['~/Data10/eiger_4/'],'dir')
load_dir = ['~/Data10/eiger_4/' load_dir];
elseif exist([raw_data_path,'eiger_4/'])
load_dir = [raw_data_path,'/eiger_4/' load_dir];
elseif exist([raw_data_path,'/eigeromny/'])
load_dir = [raw_data_path,'/eigeromny/' load_dir];
end
if ~exist(load_dir, 'dir')
warning('Raw data path %s not found', load_dir)
return
end
testDir = [load_dir, '/deleteMe'];
% test for write permissions by creating a folder and then deleting it
isWritable = mkdir(testDir);
% check if directory creation was successful
if isWritable == 1
rmdir(fullfile(testDir));
end
list_h5 = dir([load_dir, '/run_*.h5']);
file_sizes = [list_h5.bytes];
if any(file_sizes < 1e6) % find files < 1MB
warning('H5 files in scan %i seem damaged, generate again ... ', scan)
list_raw = dir([load_dir, '/run_d0_f0000000*.raw']);
if isempty(list_raw)
error('RAW data are missing, data cannot be converted')
else
delete(sprintf('%s/*.h5',load_dir))
end
list_h5 = dir([load_dir, '/run_*.h5']);
end
if isempty(list_h5)
if ~isWritable
warning('Conversion failed because folder %s is not writable', load_dir)
return
end
list_raw = dir(fullfile(load_dir, 'run_d0_f0000000*.raw'));
Nscans = length(list_raw);
for ii = 1:Nscans
ind_scans(ii) = str2num(list_raw(ii).name(16:17));
end
for ii = 1:Nscans
% [~,out] = system([cbf_maker_path ' ' fullfile(load_dir,sprintf('run_d0_f00000000%02i000_%i.raw',ind_scans(ii) ,scan))]);
systemcall = [convertor_path ' ' fullfile(list_raw(1).folder,list_raw(1).name)];
fprintf('%s\n',systemcall);
[~,out] = system(systemcall);
out
end
list_h5 = dir([load_dir, '/*.h5']);
if isempty(list_h5)
error(sprintf('After conversion did not find any h5 in %s\n',load_dir))
return
end
if numel(list_h5)>1
error(sprintf('After conversion I found more than one h5 in %s\n',load_dir))
return
end
h5fileinfo = h5info(fullfile(list_h5.folder,list_h5.name));
nframes_converted = h5fileinfo.Groups.Groups(1).Datasets.Dataspace.Size(3);
out = splitlines(out);
nframes_expected = str2num(out{end-2}(14:end));
fprintf('Frames expected: %i, frames converted %i \n', nframes_expected, nframes_converted)
if nframes_converted == nframes_expected
fprintf('Scan %i succefully converted to H5\n', scan);
delete(sprintf('%s/*.raw',load_dir))
else
error('Scan %i WAS NOT CONVERTED to H5\n', scan)
delete(sprintf('%s/*.h5',load_dir))
end
end
end
+146
View File
@@ -0,0 +1,146 @@
%EIGER1P5M settings for Eiger 1.5M detector
% This file is called if you specify p.detector = 'eiger1p5M'
%
% ** p p structure
% returns:
% ++ det detector structure; later accessible via p.detectors(ii).params
%
% see also: detector.load_detector
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 [ det ] = eiger1p5M( p )
local_path = fileparts(mfilename('fullpath'));
%% parameter
det.pixel_size = 75e-6; % detector pixel size
det.file_extension = 'h5'; % raw data file extension
det.mask = [local_path, '/eiger1p5m_mask.mat']; % detector mask
if exist(fullfile(p.raw_data_path{1}, 'eiger_4'))
det.basepath_dir = 'eiger_4/'; % raw data directory
else
det.basepath_dir = 'eigeromny/'; % raw data directory, legacy, remove in future
end
det.mask_saturated_value = []; % mask pixels above given value
det.mask_below_value = []; % mask pixels below given value
det.data_stored = true; % false == data are generated "onfly", no need to load / store
det.detposmotor = 'dettr'; % name of spec motor used for checking detector position
det.geometry.sz = [1030 1614]; % detector readout size
det.geometry.mask = []; % if the mask is larger than the readout
% geometry (det.geometry.sz), geometry.mask defines the readout for the mask
% e.g. geometry.mask = {[50:500], [50:500]}
% det.orientation = [0 0 1]; % [<Transpose> <FlipLR> <FlipUD>]
% changed from 30/08/2018
det.orientation = [1 0 0]; % [<Transpose> <FlipLR> <FlipUD>]
% additional arguments for image_read
if strcmpi(det.file_extension, 'h5')
det.image_read_extraargs = {'H5Location', '/entry/instrument/eiger_4/data/'};
else
det.image_read_extraargs = {};
end
%% define directory tree structure
% define a function handle for compiling the scan directory tree. Input
% should be the scan number.
det.read_path = @utils.compile_x12sa_dirname;
%% filename
% specify funcion for compiling the filename. Input and output should be p and a
% temporary structure, containing information about the currently prepared scan.
% Cf. '+scans/get_filenames_cSAXS.m'
det.get_filename = @scans.get_filenames_cSAXS;
% additional parameters for the filename function (det.get_filename)
% define filename pattern
% det.read_path_format = '%05d/';
% det.filename_pattern{1}.str = '%05d';
% det.filename_pattern{1}.del = '_';
% det.filename_pattern{1}.content = 'scan';
% det.filename_pattern{1}.start = 1;
% det.filename_pattern{2}.str = '%05d';
% det.filename_pattern{2}.del = '.';
% det.filename_pattern{2}.content = 'pos';
% det.filename_pattern{2}.start = 1;
%
% det.data_prefix = 'run_';
% for scan = p.scan_number
% % if ~isempty(dir(fullfile(p.raw_data_path{1}, 'eiger_4', utils.compile_x12sa_dirname(scan), '*.cbf')))
% % det.file_extension = 'cbf';
% % end
% %%%% convert data from raw to cbf or hdf5
% switch det.file_extension
% case 'cbf'
% detector.eiger1p5M.convert(scan, p.raw_data_path{1});
% case 'h5'
% detector.eiger1p5M.convert2hdf5(scan, p.raw_data_path{1});
% otherwise
% error('Unknown file extension for Eiger 1.5M.')
% end
%
% end
end
+147
View File
@@ -0,0 +1,147 @@
% function convert(scan, raw_data_path)
% convert .raw files to .cbf
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 convert(scan, raw_data_path)
cbf_maker_path = '/sls/X12SA/data/x12saop/EigerPackage/slsDetectorsPackage/bin/cbfMaker1.5MOMNY';
load_dir = utils.compile_x12sa_dirname(scan);
if exist(['~/Data10/eiger_4/'])
load_dir = ['~/Data10/eiger_4/' load_dir];
elseif exist([raw_data_path,'eiger_4/'])
load_dir = [raw_data_path,'/eiger_4/' load_dir];
elseif exist([raw_data_path,'/eigeromny/'])
load_dir = [raw_data_path,'/eigeromny/' load_dir];
end
if ~exist(load_dir, 'dir')
return
end
testDir = [load_dir, '/deleteMe'];
% test for write permissions by creating a folder and then deleting it
isWritable = mkdir(testDir);
% check if directory creation was successful
if isWritable == 1
rmdir(fullfile(testDir));
end
list_cbf = dir([load_dir, '/run_*.cbf']);
file_sizes = [list_cbf.bytes];
if any(file_sizes < 1e6) % find files < 1MB
warning('CBF files in scan %i seems damaged, generate again ... ', scan)
list_raw = dir([load_dir, '/run_d0_f0000000*.raw']);
if isempty(list_raw)
error('RAW data are missing, data cannot be converted')
else
delete(sprintf('%s/*.cbf',load_dir))
end
list_cbf = dir([load_dir, '/run_*.cbf']);
end
if isempty(list_cbf)
if ~isWritable
warning('Conversion failed because folder %s is not writable', load_dir)
return
end
list_raw = dir([load_dir, '/run_d0_f0000000*.raw']);
Nscans = length(list_raw);
for ii = 1:Nscans
ind_scans(ii) = str2num(list_raw(ii).name(16:17));
end
% if Nscans > 1
% parfor (ii = 1:Nscans, Nscans)
% [~,out] = system(sprintf('%s %s/run_d0_f00000000%02i000_%05i.cbf',cbf_maker_path, load_dir, ind_scans(ii) ,scan));
% end
% else
for ii = 1:Nscans
[~,out] = system(sprintf('%s %s/run_d0_f00000000%02i000_%05i.raw',cbf_maker_path, load_dir, ind_scans(ii) ,scan));
end
% end
list_cbf = dir([load_dir, '/*.cbf']);
nframes_converted = length(list_cbf);
out = splitlines(out);
nframes_expected = str2num(out{end-2}(14:end));
fprintf('Frames expected: %i, frames converted %i \n', nframes_expected, nframes_converted)
if nframes_converted == nframes_expected
% for ii=1:nframes_expected
% thisfile = fullfile(load_dir,list_cbf(ii).name);
% dataaux = io.image_read(thisfile,'RowFrom',1,'RowTo',2,'ColumnFrom',1,'ColumnTo',2);
% data(:,:,ii) = dataaux.data(:,:,1);
% end
fprintf('Scan %i succefully converted to CBF\n', scan);
delete(sprintf('%s/*.raw',load_dir))
else
error('Scan %i WAS NOT CONVERTED to CBF\n', scan)
delete(sprintf('%s/*.cbf',load_dir))
end
end
end
@@ -0,0 +1,95 @@
% function convert(scan, raw_data_path)
% convert .raw files to .hdf5
% Inputs
% scan scan number
% raw_data_path path to the raw data (optional)
function convert2hdf5(scan, raw_data_path)
convertor_path = '/sls/X12SA/data/x12saop/EigerPackage/slsDetectorsPackage/bin/hdf5MakerOMNY';
load_dir = utils.compile_x12sa_dirname(scan);
if exist('raw_data_path','var')&&exist(fullfile(raw_data_path,load_dir),'dir')
load_dir = fullfile(raw_data_path,load_dir);
elseif exist(['~/Data10/eiger_4/'],'dir')
load_dir = ['~/Data10/eiger_4/' load_dir];
elseif exist([raw_data_path,'eiger_4/'])
load_dir = [raw_data_path,'/eiger_4/' load_dir];
elseif exist([raw_data_path,'/eigeromny/'])
load_dir = [raw_data_path,'/eigeromny/' load_dir];
end
if ~exist(load_dir, 'dir')
warning('Raw data path %s not found', load_dir)
return
end
testDir = [load_dir, '/deleteMe'];
% test for write permissions by creating a folder and then deleting it
isWritable = mkdir(testDir);
% check if directory creation was successful
if isWritable == 1
rmdir(fullfile(testDir));
end
list_h5 = dir([load_dir, '/run_*.h5']);
file_sizes = [list_h5.bytes];
if any(file_sizes < 1e6) % find files < 1MB
warning('H5 files in scan %i seem damaged, generate again ... ', scan)
list_raw = dir([load_dir, '/run_d0_f0000000*.raw']);
if isempty(list_raw)
error('RAW data are missing, data cannot be converted')
else
delete(sprintf('%s/*.h5',load_dir))
end
list_h5 = dir([load_dir, '/run_*.h5']);
end
if isempty(list_h5)
if ~isWritable
warning('Conversion failed because folder %s is not writable', load_dir)
return
end
list_raw = dir(fullfile(load_dir, 'run_d0_f0000000*.raw'));
Nscans = length(list_raw);
for ii = 1:Nscans
ind_scans(ii) = str2num(list_raw(ii).name(16:17));
end
for ii = 1:Nscans
% [~,out] = system([cbf_maker_path ' ' fullfile(load_dir,sprintf('run_d0_f00000000%02i000_%i.raw',ind_scans(ii) ,scan))]);
systemcall = [convertor_path ' ' fullfile(list_raw(1).folder,list_raw(1).name)];
fprintf('%s\n',systemcall);
[~,out] = system(systemcall);
out
end
list_h5 = dir([load_dir, '/*.h5']);
if isempty(list_h5)
error(sprintf('After conversion did not find any h5 in %s\n',load_dir))
return
end
if numel(list_h5)>1
error(sprintf('After conversion I found more than one h5 in %s\n',load_dir))
return
end
h5fileinfo = h5info(fullfile(list_h5.folder,list_h5.name));
nframes_converted = h5fileinfo.Groups.Groups(1).Datasets.Dataspace.Size(3);
out = splitlines(out);
nframes_expected = str2num(out{end-2}(14:end));
fprintf('Frames expected: %i, frames converted %i \n', nframes_expected, nframes_converted)
if nframes_converted == nframes_expected
fprintf('Scan %i succefully converted to H5\n', scan);
delete(sprintf('%s/*.raw',load_dir))
else
error('Scan %i WAS NOT CONVERTED to H5\n', scan)
delete(sprintf('%s/*.h5',load_dir))
end
end
end
@@ -0,0 +1,92 @@
%EIGER1P5M settings for Eiger 1.5M detector
% This file is called if you specify p.detector = 'eiger1p5M'
%
% ** p p structure
% returns:
% ++ det detector structure; later accessible via p.detectors(ii).params
%
% see also: detector.load_detector
function [ det ] = eiger1p5M_APS( p )
local_path = fileparts(mfilename('fullpath'));
%% parameter
det.pixel_size = 75e-6; % detector pixel size
det.file_extension = 'h5'; % raw data file extension
det.mask = [local_path, '/eiger1p5m_APS_mask.mat']; % detector mask
if exist(fullfile(p.raw_data_path{1}, 'eiger_4'))
det.basepath_dir = 'eiger_4/'; % raw data directory
else
det.basepath_dir = 'eigeromny/'; % raw data directory, legacy, remove in future
end
det.mask_saturated_value = []; % mask pixels above given value
det.mask_below_value = []; % mask pixels below given value
det.data_stored = true; % false == data are generated "onfly", no need to load / store
det.detposmotor = 'dettr'; % name of spec motor used for checking detector position
det.geometry.sz = [1030 1614]; % detector readout size
det.geometry.mask = []; % if the mask is larger than the readout
% geometry (det.geometry.sz), geometry.mask defines the readout for the mask
% e.g. geometry.mask = {[50:500], [50:500]}
% det.orientation = [0 0 1]; % [<Transpose> <FlipLR> <FlipUD>]
% changed from 30/08/2018
det.orientation = [1 0 0]; % [<Transpose> <FlipLR> <FlipUD>]
% additional arguments for image_read
if strcmpi(det.file_extension, 'h5')
det.image_read_extraargs = {'H5Location', '/entry/instrument/eiger_4/data/'};
else
det.image_read_extraargs = {};
end
%% define directory tree structure
% define a function handle for compiling the scan directory tree. Input
% should be the scan number.
det.read_path = @utils.compile_x12sa_dirname;
%% filename
% specify funcion for compiling the filename. Input and output should be p and a
% temporary structure, containing information about the currently prepared scan.
% Cf. '+scans/get_filenames_cSAXS.m'
%det.get_filename = @scans.get_filenames_cSAXS;
det.get_filename = @scans.get_filenames_aps_lynx;
% additional parameters for the filename function (det.get_filename)
% define filename pattern
% det.read_path_format = '%05d/';
% det.filename_pattern{1}.str = '%05d';
% det.filename_pattern{1}.del = '_';
% det.filename_pattern{1}.content = 'scan';
% det.filename_pattern{1}.start = 1;
% det.filename_pattern{2}.str = '%05d';
% det.filename_pattern{2}.del = '.';
% det.filename_pattern{2}.content = 'pos';
% det.filename_pattern{2}.start = 1;
%
% det.data_prefix = 'run_';
% for scan = p.scan_number
% % if ~isempty(dir(fullfile(p.raw_data_path{1}, 'eiger_4', utils.compile_x12sa_dirname(scan), '*.cbf')))
% % det.file_extension = 'cbf';
% % end
% %%%% convert data from raw to cbf or hdf5
% switch det.file_extension
% case 'cbf'
% detector.eiger1p5M.convert(scan, p.raw_data_path{1});
% case 'h5'
% detector.eiger1p5M.convert2hdf5(scan, p.raw_data_path{1});
% otherwise
% error('Unknown file extension for Eiger 1.5M.')
% end
%
% end
end
@@ -0,0 +1,105 @@
%EIGER settings for Eiger detector at the SWING beamline (Soleil)
% This file is called if you specify p.detector = 'eiger4M_swing'.
% ** p p structure
% returns:
% ++ det detector structure; later accessible via p.detectors(ii).params
%
% see also: detector.load_detector
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 [ det ] = eiger4M_swing( p )
local_path = fileparts(mfilename('fullpath'));
%% parameter
det.pixel_size = 75e-6; % detector pixel size
det.file_extension = 'h5'; % raw data file extension
det.mask = [local_path, '/eiger_valid_mask.mat']; % detector mask
det.basepath_dir = 'eiger4M/'; % raw data directory
det.mask_saturated_value = []; % mask pixels above given value
det.mask_below_value = []; % mask pixels below given value
det.data_stored = true; % false == data are generated "onfly", no need to load / store
det.geometry.sz = [1035 1083]; % detector readout size
det.geometry.mask = []; % if the mask is larger than the readout
% geometry (det.geometry.sz), geometry.mask defines the readout for the mask
% e.g. geometry.mask = {[50:500], [50:500]}
det.orientation = [0 0 1]; % [<Transpose> <FlipLR> <FlipUD>]
% additional arguments for image_read
det.image_read_extraargs = {};
%% define directory tree structure
% define a function handle for compiling the scan directory tree. Input
% should be the scan number.
det.read_path = @soleil.compile_swing_dirname;
%% filename
% specify funcion for compiling the filename. Input and output should be p and a
% temporary structure, containing information about the currently prepared scan.
% Cf. '+scans/get_filenames_cSAXS.m'
det.get_filename = @soleil.get_filenames_swing;
% additional parameters for the filename function (det.get_filename)
det.nexus_entry = 'eiger_image';
end
+148
View File
@@ -0,0 +1,148 @@
%PILATUS settings for Pilatus detector
% This file is called if you specify p.detector = 'pilatus'
% ** p p structure
% returns:
% ++ det detector structure; later accessible via p.detectors(ii).params
%
% see also: detector.load_detector
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 [ det ] = eiger9M( p )
local_path = fileparts(mfilename('fullpath'));
%% parameter
det.pixel_size = 75e-6; % detector pixel size
det.file_extension = 'cbf'; % raw data file extension
det.mask = [local_path, '/eiger9m_mask_avgpx.mat']; % detector mask
det.basepath_dir = 'eiger9/'; % raw data directory
det.mask_saturated_value = []; % mask pixels above given value
det.mask_below_value = []; % mask pixels below given value
det.data_stored = true; % false == data are generated "onfly", no need to load / store
det.geometry.sz = [3106 3264]; % detector readout size
det.geometry.mask = []; % if the mask is larger than the readout
% geometry (det.geometry.sz), geometry.mask defines the readout for the mask
% e.g. geometry.mask = {[50:500], [50:500]}
det.orientation = [1 0 0]; % [<Transpose> <FlipLR> <FlipUD>]
% additional arguments for image_read
det.image_read_extraargs = {};
%% define directory tree structure
% define a function handle for compiling the scan directory tree. Input
% should be the scan number.
det.read_path = @utils.compile_x12sa_dirname;
%% filename
% specify funcion for compiling the filename. Input and output should be p and a
% temporary structure, containing information about the currently prepared scan.
% Cf. '+scans/get_filenames_cSAXS.m'
det.get_filename = @scans.get_filenames_cSAXS;
% additional parameters for the filename function (det.get_filename)
det.read_path_format = '%05d/';
det.filename_pattern{1}.str = '%05d';
det.filename_pattern{1}.del = '_';
det.filename_pattern{1}.content = 'scan';
det.filename_pattern{1}.start = 1;
det.filename_pattern{2}.str = '%05d';
det.filename_pattern{2}.del = '.';
det.filename_pattern{2}.content = 'pos';
det.filename_pattern{2}.start = 1;
% if strcmp(p.fromspec, 'opos_angle') || strcmp(p.fromspec, 'opos')
% det.read_path_format = 'S%05d-%05d/S%05d/';
% det.filename_pattern{1}.str = '%05d';
% det.filename_pattern{1}.del = '_';
% det.filename_pattern{1}.content = 'scan';
% det.filename_pattern{1}.start = 0;
% det.filename_pattern{2}.str = '%05d';
% det.filename_pattern{2}.del = '_';
% det.filename_pattern{2}.content = 'burst';
% det.filename_pattern{2}.start = 0;
% det.filename_pattern{3}.str = '%05d';
% det.filename_pattern{3}.del = '.';
% det.filename_pattern{3}.content = 'pos';
% det.filename_pattern{3}.start = 0;
%
% else
% det.read_path_format = 'S%05d-%05d/S%05d/';
% det.filename_pattern{1}.str = '%05d';
% det.filename_pattern{1}.del = '_';
% det.filename_pattern{1}.content = 'scan';
% det.filename_pattern{1}.start = 0;
% det.filename_pattern{2}.str = '%05d';
% det.filename_pattern{2}.del = '_';
% det.filename_pattern{2}.content = 'pos';
% det.filename_pattern{2}.start = 0;
% det.filename_pattern{3}.str = '%05d';
% det.filename_pattern{3}.del = '.';
% det.filename_pattern{3}.content = 'burst';
% det.filename_pattern{3}.start = 0;
%
% end
end
+65
View File
@@ -0,0 +1,65 @@
%GET_DIR_PATH define directory structure.
% default scheme for data (scan 68) taken at cSAXS: S00000-00999/S00068/
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 data_path = get_dir_path(p, ii)
data_path = sprintf([p.raw_data_path{ii} p.detectors(ii).params.basepath_dir p.detectors(ii).params.read_path_format], p.scan_number(ii));
end
+73
View File
@@ -0,0 +1,73 @@
%EIGER settings for Eiger detector
% This file is called if you specify p.detector = 'eiger_APS'.
% ** p p structure
% returns:
% ++ det detector structure; later accessible via p.detectors(ii).params
%
% see also: detector.load_detector
function [ det ] = eiger_APS( p )
local_path = fileparts(mfilename('fullpath'));
%% parameter
det.pixel_size = 75e-6; % detector pixel size
det.file_extension = 'h5'; % raw data file extension
%det.mask = [local_path, '/eiger_valid_mask.mat']; % detector mask from PSI's detector. Need to change for APS
det.basepath_dir = 'eiger/'; % raw data directory
det.mask_saturated_value = []; % mask pixels above given value
det.mask_below_value = []; % mask pixels below given value
det.data_stored = true; % false == data are generated "onfly", no need to load / store
%det.geometry.sz = [1030 514]; % detector readout size
det.geometry.sz = [1024 1024]; % detector readout size
det.geometry.mask = []; % if the mask is larger than the readout
% geometry (det.geometry.sz), geometry.mask defines the readout for the mask
% e.g. geometry.mask = {[50:500], [50:500]}
det.orientation = [1 0 0]; % [<Transpose> <FlipLR> <FlipUD>]
% additional arguments for image_read
det.image_read_extraargs = {'H5Location', '/eh5/images/'};
%% define directory tree structure
% define a function handle for compiling the scan directory tree. Input
% should be the scan number.
det.read_path = @utils.compile_aps_dirname;
%% filename
% specify funcion for compiling the filename. Input and output should be p and a
% temporary structure, containing information about the currently prepared scan.
% Cf. '+scans/get_filenames_cSAXS.m'
det.get_filename = @scans.get_filenames_aps;
%{
% additional parameters for the filename function (det.get_filename)
det.filename_pattern{1}.str = '%05d';
det.filename_pattern{1}.del = '_';
det.filename_pattern{1}.content = 'scan';
det.filename_pattern{1}.start = 0;
det.filename_pattern{2}.str = '%05d';
det.filename_pattern{2}.del = '_';
% det.filename_pattern{2}.content = 'burst';
det.filename_pattern{2}.start = 0;
det.filename_pattern{3}.str = '%05d';
det.filename_pattern{3}.del = '.';
% det.filename_pattern{3}.content = 'pos';
det.filename_pattern{3}.start = 0;
if ~isfield(p, 'omny_interferometer') || (strcmp(p.omny_interferometer, 'opos_angle') || strcmp(p.omny_interferometer, 'opos'))
det.filename_pattern{2}.content = 'burst';
det.filename_pattern{3}.content = 'pos';
else
det.filename_pattern{2}.content = 'pos';
det.filename_pattern{3}.content = 'burst';
end
%}
end
@@ -0,0 +1,73 @@
%EIGER settings for Eiger detector
% This file is called if you specify p.detector = 'eiger_APS'.
% ** p p structure
% returns:
% ++ det detector structure; later accessible via p.detectors(ii).params
%
% see also: detector.load_detector
function [ det ] = eiger_APS_temp( p )
local_path = fileparts(mfilename('fullpath'));
%% parameter
det.pixel_size = 75e-6/2; % detector pixel size
det.file_extension = 'h5'; % raw data file extension
%det.mask = [local_path, '/eiger_valid_mask.mat']; % detector mask from PSI's detector. Need to change for APS
det.basepath_dir = 'eiger/'; % raw data directory
det.mask_saturated_value = []; % mask pixels above given value
det.mask_below_value = []; % mask pixels below given value
det.data_stored = true; % false == data are generated "onfly", no need to load / store
%det.geometry.sz = [1030 514]; % detector readout size
det.geometry.sz = [1024 1024]; % detector readout size
det.geometry.mask = []; % if the mask is larger than the readout
% geometry (det.geometry.sz), geometry.mask defines the readout for the mask
% e.g. geometry.mask = {[50:500], [50:500]}
det.orientation = [1 0 0]; % [<Transpose> <FlipLR> <FlipUD>]
% additional arguments for image_read
det.image_read_extraargs = {'H5Location', '/eh5/images/'};
%% define directory tree structure
% define a function handle for compiling the scan directory tree. Input
% should be the scan number.
det.read_path = @utils.compile_aps_dirname;
%% filename
% specify funcion for compiling the filename. Input and output should be p and a
% temporary structure, containing information about the currently prepared scan.
% Cf. '+scans/get_filenames_cSAXS.m'
det.get_filename = @scans.get_filenames_aps;
%{
% additional parameters for the filename function (det.get_filename)
det.filename_pattern{1}.str = '%05d';
det.filename_pattern{1}.del = '_';
det.filename_pattern{1}.content = 'scan';
det.filename_pattern{1}.start = 0;
det.filename_pattern{2}.str = '%05d';
det.filename_pattern{2}.del = '_';
% det.filename_pattern{2}.content = 'burst';
det.filename_pattern{2}.start = 0;
det.filename_pattern{3}.str = '%05d';
det.filename_pattern{3}.del = '.';
% det.filename_pattern{3}.content = 'pos';
det.filename_pattern{3}.start = 0;
if ~isfield(p, 'omny_interferometer') || (strcmp(p.omny_interferometer, 'opos_angle') || strcmp(p.omny_interferometer, 'opos'))
det.filename_pattern{2}.content = 'burst';
det.filename_pattern{3}.content = 'pos';
else
det.filename_pattern{2}.content = 'pos';
det.filename_pattern{3}.content = 'burst';
end
%}
end
+73
View File
@@ -0,0 +1,73 @@
%EIGER settings for Eiger detector
% This file is called if you specify p.detector = 'eiger_APS'.
% ** p p structure
% returns:
% ++ det detector structure; later accessible via p.detectors(ii).params
%
% see also: detector.load_detector
function [ det ] = empad( p )
local_path = fileparts(mfilename('fullpath'));
%% parameter
det.pixel_size = 1; % detector pixel size
det.file_extension = 'h5'; % raw data file extension
%det.mask = [local_path, '/eiger_valid_mask.mat']; % detector mask from PSI's detector. Need to change for APS
det.basepath_dir = 'eiger/'; % raw data directory
det.mask_saturated_value = []; % mask pixels above given value
det.mask_below_value = []; % mask pixels below given value
det.data_stored = true; % false == data are generated "onfly", no need to load / store
%det.geometry.sz = [1030 514]; % detector readout size
det.geometry.sz = [256 256]; % detector readout size
det.geometry.mask = []; % if the mask is larger than the readout
% geometry (det.geometry.sz), geometry.mask defines the readout for the mask
% e.g. geometry.mask = {[50:500], [50:500]}
det.orientation = [0 0 0]; % [<Transpose> <FlipLR> <FlipUD>]
% additional arguments for image_read
det.image_read_extraargs = {'H5Location', '/eh5/images/'};
%% define directory tree structure
% define a function handle for compiling the scan directory tree. Input
% should be the scan number.
det.read_path = @utils.compile_cu_dirname;
%% filename
% specify funcion for compiling the filename. Input and output should be p and a
% temporary structure, containing information about the currently prepared scan.
% Cf. '+scans/get_filenames_cSAXS.m'
det.get_filename = @scans.get_filenames_cu;
%{
% additional parameters for the filename function (det.get_filename)
det.filename_pattern{1}.str = '%05d';
det.filename_pattern{1}.del = '_';
det.filename_pattern{1}.content = 'scan';
det.filename_pattern{1}.start = 0;
det.filename_pattern{2}.str = '%05d';
det.filename_pattern{2}.del = '_';
% det.filename_pattern{2}.content = 'burst';
det.filename_pattern{2}.start = 0;
det.filename_pattern{3}.str = '%05d';
det.filename_pattern{3}.del = '.';
% det.filename_pattern{3}.content = 'pos';
det.filename_pattern{3}.start = 0;
if ~isfield(p, 'omny_interferometer') || (strcmp(p.omny_interferometer, 'opos_angle') || strcmp(p.omny_interferometer, 'opos'))
det.filename_pattern{2}.content = 'burst';
det.filename_pattern{3}.content = 'pos';
else
det.filename_pattern{2}.content = 'pos';
det.filename_pattern{3}.content = 'burst';
end
%}
end
+73
View File
@@ -0,0 +1,73 @@
%EIGER settings for Eiger detector
% This file is called if you specify p.detector = 'eiger_APS'.
% ** p p structure
% returns:
% ++ det detector structure; later accessible via p.detectors(ii).params
%
% see also: detector.load_detector
function [ det ] = medipix3( p )
local_path = fileparts(mfilename('fullpath'));
%% parameter
det.pixel_size = 55e-6; % detector pixel size
det.file_extension = 'h5'; % raw data file extension
%det.mask = [local_path, '/eiger_valid_mask.mat']; % detector mask from PSI's detector. Need to change for APS
det.basepath_dir = 'eiger/'; % raw data directory
det.mask_saturated_value = []; % mask pixels above given value
det.mask_below_value = []; % mask pixels below given value
det.data_stored = true; % false == data are generated "onfly", no need to load / store
%det.geometry.sz = [1030 514]; % detector readout size
det.geometry.sz = [1024 1024]; % detector readout size
det.geometry.mask = []; % if the mask is larger than the readout
% geometry (det.geometry.sz), geometry.mask defines the readout for the mask
% e.g. geometry.mask = {[50:500], [50:500]}
det.orientation = [1 0 0]; % [<Transpose> <FlipLR> <FlipUD>]
% additional arguments for image_read
det.image_read_extraargs = {'H5Location', '/eh5/images/'};
%% define directory tree structure
% define a function handle for compiling the scan directory tree. Input
% should be the scan number.
det.read_path = @utils.compile_aps_dirname;
%% filename
% specify funcion for compiling the filename. Input and output should be p and a
% temporary structure, containing information about the currently prepared scan.
% Cf. '+scans/get_filenames_cSAXS.m'
det.get_filename = @scans.get_filenames_aps;
%{
% additional parameters for the filename function (det.get_filename)
det.filename_pattern{1}.str = '%05d';
det.filename_pattern{1}.del = '_';
det.filename_pattern{1}.content = 'scan';
det.filename_pattern{1}.start = 0;
det.filename_pattern{2}.str = '%05d';
det.filename_pattern{2}.del = '_';
% det.filename_pattern{2}.content = 'burst';
det.filename_pattern{2}.start = 0;
det.filename_pattern{3}.str = '%05d';
det.filename_pattern{3}.del = '.';
% det.filename_pattern{3}.content = 'pos';
det.filename_pattern{3}.start = 0;
if ~isfield(p, 'omny_interferometer') || (strcmp(p.omny_interferometer, 'opos_angle') || strcmp(p.omny_interferometer, 'opos'))
det.filename_pattern{2}.content = 'burst';
det.filename_pattern{3}.content = 'pos';
else
det.filename_pattern{2}.content = 'pos';
det.filename_pattern{3}.content = 'burst';
end
%}
end
+177
View File
@@ -0,0 +1,177 @@
%MOENCH settings for Moench detector
% This file is called if you specify p.detector = 'moench'.
%
% ** p p structure
% returns:
% ++ det detector structure; later accessible via p.detectors(ii).params
%
% see also: detector.load_detector
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 [ det ] = moench( p )
local_path = fileparts(mfilename('fullpath'));
if ~isfield(p, 'beamline')
p.beamline = 'cSAXS';
end
%% parameter
det.pixel_size = 6.25e-6; % detector pixel size
det.file_extension = 'tiff'; % raw data file extension
det.mask = [local_path, '/moench_valid_mask_nb4.mat']; % detector mask
det.basepath_dir = 'moench/images/'; % raw data directory
det.mask_saturated_value = 150; % mask pixels above given value
det.mask_below_value = 0; % mask pixels below given value
det.data_stored = true; % false == data are generated "onfly", no need to load / store
det.geometry.sz = [1600 1600]; % detector readout size
det.geometry.mask = []; % if the mask is larger than the readout
% geometry (det.geometry.sz), geometry.mask defines the readout for the mask
% e.g. geometry.mask = {[50:500], [50:500]}
det.detposmotor = {'hy'; 'hx'}; % cSAXS hexapod motors
det.filt_pinhole = [];%28e-6.*160/det.pixel_size;
det.noint = false;
det.orientation = [0 1 1]; % [<Transpose> <FlipLR> <FlipUD>]
% additional arguments for image_read
det.image_read_extraargs = {};
%% define directory tree structure
% define a function handle for compiling the scan directory tree. Input
% should be the scan number.
det.read_path = @utils.compile_x12sa_dirname;
%% filename
% specify funcion for compiling the filename. Input and output should be p and a
% temporary structure, containing information about the currently prepared scan.
% Cf. '+scans/get_filenames_cSAXS.m'
det.get_filename = @scans.get_filenames_cSAXS;
% additional parameters for the filename function (det.get_filename)
%cSAXS settings
det.read_path_format = 'S%05d-%05d/S%05d/';
det.filename_pattern{1}.str = '%05d';
det.filename_pattern{1}.del = '_';
det.filename_pattern{1}.content = 'scan';
det.filename_pattern{1}.start = 0;
det.filename_pattern{2}.str = '%05d';
det.filename_pattern{2}.del = '_';
det.filename_pattern{2}.content = 'pos';
det.filename_pattern{2}.start = 0;
if det.noint
det.filename_pattern{3}.str = 'nb4';
det.filename_pattern{3}.del = '_';
det.filename_pattern{3}.content = 'suffix';
det.filename_pattern{3}.start = 0;
det.filename_pattern{4}.str = 'noint';
det.filename_pattern{4}.del = '.';
det.filename_pattern{4}.content = 'suffix';
det.filename_pattern{4}.start = 0;
else
det.filename_pattern{3}.str = 'nb4';
det.filename_pattern{3}.del = '.';
det.filename_pattern{3}.content = 'suffix';
det.filename_pattern{3}.start = 0;
end
if strcmpi(p.beamline, 'TOMCAT')
% TOMCAT settings
det.basepath_dir = 'moench/'; % raw data directory
det.orientation = [1 1 0]; % [<Transpose> <FlipLR> <FlipUD>]
det.image_read_extraargs{2} = det.orientation;
det.detposmotor = {'ES2laser1y'; 'ES2laser1z'}; % TOMCAT motors @ endstation 2
det.read_path_format = 'S%05d-%05d/S%05d/';
det.filename_pattern{1}.str = '%05d';
det.filename_pattern{1}.del = '_';
det.filename_pattern{1}.content = 'scan';
det.filename_pattern{1}.start = 0;
det.filename_pattern{2}.str = '%05d';
det.filename_pattern{2}.del = '_';
det.filename_pattern{2}.content = 'pos';
det.filename_pattern{2}.start = 0;
det.filename_pattern{3}.str = 'd0';
det.filename_pattern{3}.del = '_';
det.filename_pattern{3}.content = 'suffix';
det.filename_pattern{3}.start = 0;
det.filename_pattern{4}.str = 'f000000000000';
det.filename_pattern{4}.del = '_';
det.filename_pattern{4}.content = 'suffix';
det.filename_pattern{4}.start = 0;
det.filename_pattern{5}.str = '0';
det.filename_pattern{5}.del = '_';
det.filename_pattern{5}.content = 'suffix';
det.filename_pattern{5}.start = 0;
det.filename_pattern{6}.str = 'nb4';
det.filename_pattern{6}.del = '.';
det.filename_pattern{6}.content = 'suffix';
det.filename_pattern{6}.start = 0;
end
end
+104
View File
@@ -0,0 +1,104 @@
%EIGER settings for Eiger detector
% This file is called if you specify p.detector = 'eiger'.
% ** p p structure
% returns:
% ++ det detector structure; later accessible via p.detectors(ii).params
%
% see also: detector.load_detector
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 [ det ] = oldeiger( p )
local_path = fileparts(mfilename('fullpath'));
%% parameter
det.pixel_size = 75e-6; % detector pixel size
det.file_extension = 'h5'; % raw data file extension
det.mask = [local_path, '/eiger_valid_mask.mat']; % detector mask
det.basepath_dir = 'eiger/'; % raw data directory
det.mask_saturated_value = []; % mask pixels above given value
det.mask_below_value = []; % mask pixels below given value
det.data_stored = true; % false == data are generated "onfly", no need to load / store
det.geometry.sz = [1030 514]; % detector readout size
det.geometry.mask = []; % if the mask is larger than the readout
% geometry (det.geometry.sz), geometry.mask defines the readout for the mask
% e.g. geometry.mask = {[50:500], [50:500]}
det.orientation = [0 0 1]; % [<Transpose> <FlipLR> <FlipUD>]
% additional arguments for image_read
det.image_read_extraargs = {'H5Location','/eh5/images/'};
%% define directory tree structure
% define a function handle for compiling the scan directory tree. Input
% should be the scan number.
det.read_path = @utils.compile_x12sa_dirname;
%% filename
% specify funcion for compiling the filename. Input and output should be p and a
% temporary structure, containing information about the currently prepared scan.
% Cf. '+scans/get_filenames_cSAXS.m'
det.get_filename = @scans.get_filenames_cSAXS;
% additional parameters for the filename function (det.get_filename)
end
+106
View File
@@ -0,0 +1,106 @@
%PCO_NANO settings for PCO Edge Nano detector
% This file is called if you specify p.detector = 'pco_nano'.
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 [ det ] = pco_nano( p )
%% parameter
det.pixel_size = 6.5e-6; % detector pixel size
det.file_extension = 'tif'; % raw data file extension
det.mask = 'pco_nano_mask.mat'; % detector mask
det.basepath_dir = 'CCD_1/'; % raw data directory
det.mask_saturated_value = []; % mask pixels above given value
det.mask_below_value = []; % mask pixels below given value
det.data_stored = true; % false == data are generated "onfly", no need to load / store
det.geometry.sz = [800 800]; % detector readout size
det.geometry.mask = []; % if the mask is larger than the readout
% geometry (det.geometry.sz), geometry.mask defines the readout for the mask
% e.g. geometry.mask = {[50:500], [50:500]}
% additional arguments for image_read
det.image_read_extraargs = {};
%% define directory tree structure
% define a function handle for compiling the scan directory tree. Input
% should be the scan number.
det.read_path = @utils.compile_x12sa_dirname;
%% filename
% specify funcion for compiling the filename. Input and output should be p and a
% temporary structure, containing information about the currently prepared scan.
% Cf. '+scans/get_filenames_cSAXS.m'
det.get_filename = @scans.get_filenames_cSAXS;
% additional parameters for the filename function (det.get_filename)
det.filename_pattern{1}.str = '%05d';
det.filename_pattern{1}.del = '_';
det.filename_pattern{1}.content = 'scan';
det.filename_pattern{1}.start = 0;
det.filename_pattern{2}.str = '%05d';
det.filename_pattern{2}.del = '.';
det.filename_pattern{2}.content = 'pos';
det.filename_pattern{2}.start = 0;
end
+124
View File
@@ -0,0 +1,124 @@
%PILATUS settings for Pilatus detector
% This file is called if you specify p.detector = 'pilatus'
% ** p p structure
% returns:
% ++ det detector structure; later accessible via p.detectors(ii).params
%
% see also: detector.load_detector
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 [ det ] = pilatus( p )
local_path = fileparts(mfilename('fullpath'));
det.pixel_size = 172e-6; % detector pixel size
det.file_extension = 'cbf'; % raw data file extension
det.mask = [local_path, '/binary_mask_6.2keV.mat']; % detector mask
det.basepath_dir = 'pilatus_1/'; % raw data directory
det.mask_saturated_value = []; % mask pixels above given value
det.mask_below_value = []; % mask pixels below given value
det.data_stored = true; % false == data are generated "onfly", no need to load / store
det.geometry.sz = [1679 1475]; % detector readout size
det.geometry.mask = []; % if the mask is larger than the readout
% geometry (det.geometry.sz), geometry.mask defines the readout for the mask
% e.g. geometry.mask = {[50:500], [50:500]}
det.orientation = [1 1 1]; % [<Transpose> <FlipLR> <FlipUD>]
% additional arguments for image_read
det.image_read_extraargs = {};
%% define directory tree structure
% define a function handle for compiling the scan directory tree. Input
% should be the scan number.
det.read_path = @utils.compile_x12sa_dirname;
%% filename
% specify funcion for compiling the filename. Input and output should be p and a
% temporary structure, containing information about the currently prepared scan.
% Cf. '+scans/get_filenames_cSAXS.m'
det.get_filename = @scans.get_filenames_cSAXS;
% additional parameters for the filename function (det.get_filename)
det.filename_pattern{1}.str = '%05d';
det.filename_pattern{1}.del = '_';
det.filename_pattern{1}.content = 'scan';
det.filename_pattern{1}.start = 0;
det.filename_pattern{2}.str = '%05d';
det.filename_pattern{2}.del = '_';
%det.filename_pattern{2}.content = 'burst';
det.filename_pattern{2}.start = 0;
det.filename_pattern{3}.str = '%05d';
det.filename_pattern{3}.del = '.';
%det.filename_pattern{3}.content = 'pos';
det.filename_pattern{3}.start = 0;
% define filename pattern
if ~isfield(p,'omny_interferometer') || strcmp(p.omny_interferometer, 'opos_angle') || strcmp(p.omny_interferometer, 'opos')
det.filename_pattern{2}.content = 'burst';
det.filename_pattern{3}.content = 'pos';
else
det.filename_pattern{2}.content = 'pos';
det.filename_pattern{3}.content = 'burst';
end
end
@@ -0,0 +1,371 @@
%libDetXR prepares and exports data for libDetXR/ptyhon data
% preparation.
%
% ** p p structure
%
% returns:
% ++ p updated p structure
% ++ fdb feedback structure
%
% see also: core.run_data_preparator
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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] = libDetXR( p )
import utils.verbose
import io.HDF.save2hdf5
import io.mat2json
import beamline.identify_eaccount
verbose(1, 'Preparing data using json/python data preparation.')
if ~isfield(p, 'delete_temp_json_data')
p.delete_temp_json_data = true;
end
% Parameters for reconstruction with external C code
if ~isfield(p, 'initial_conditions_file') || isempty(p.initial_conditions_file)%&&p.external_reconstruction
if ~isempty(p.suffix)
suffix = ['_' p.suffix];
else
suffix = '';
end
p.initial_conditions_file = [core.generate_scan_name(p) sprintf('_initial_conditions_%03dx%03d%s.h5', p.asize(1), p.asize(2), suffix)];
verbose(3, 'C-code initial_conditions_file = %s', p.initial_conditions_file);
end
% path for saving temp data for C code
if isfield(p, 'initial_conditions_path') && ~isempty(p.initial_conditions_path)
if p.prepare_data_path(1) == '~'
p.initial_conditions_path = ['/sls/X12SA/Data10/' identify_eaccount p.prepare_data_path(9:end)];
end
else
p.initial_conditions_path = p.prepare_data_path;
end
if ~isfield(p, 'initial_probe_temp_file')
p.initial_probe_temp_file{1} = [];
end
if ~isfield(p, 'initial_object_temp_file')
p.initial_object_temp_file{1} = [];
end
if isempty(p.initial_probe_temp_file{1})
for ii=1:p.numscans
p.initial_probe_temp_file{ii} = [core.generate_scan_name(p) sprintf('_temp_probe_S%05d_%03dx%03d.mat', p.scan_number(ii), p.asize(1), p.asize(2))];
end
end
if isempty(p.initial_object_temp_file{1})
for ii=1:p.numscans
p.initial_object_temp_file{ii} = [core.generate_scan_name(p) sprintf('_temp_object_S%05d_%03dx%03d.mat', p.scan_number(ii), p.asize(1), p.asize(2))];
end
end
s=struct;
s.glob = struct;
s.detector = struct;
s.measurement = struct;
s.initialCondition = struct;
s.initialCondition.probe = struct;
s.initialCondition.object = struct;
s.initialCondition.param = struct;
for ii = 1:p.numscans
p.scanID = ii;
cid = sprintf('id%d',ii-1);
% Structure begins
s.glob.dst = {'hdf', fullfile(p.prepare_data_path, p.prepare_data_filename)};
s.glob.energy = p.energy;
s.glob.z = p.z;
s.glob.ds = p.ds;
s.detector.(cid) = struct; % id0 means "detector":{"0":
s.detector.(cid).validMsk = p.detectors(ii).params.mask; % Besides a matlab binary valid mask file
% it accepts a definition based on
% module and/or bad pixels
s.detector.(cid).trfMsk = [0,0]; % Transformation for mask, [rot90,fliplr]
% Mask for pilatus frames apparently not needed. Just datapath.
% raw_data_filenamemask =fullfile(p.raw_data_path_full{1},sprintf('%s%05d_*.%s',p.detector.data_prefix,p.scan_number(ii),p.data_extension));
s.measurement.(cid) = struct;
s.measurement.(cid).detector = ii-1; % NEEDS ADAPTATION FOR SHARING
s.measurement.(cid).probe = p.share_probe_ID(ii)-1;
s.measurement.(cid).object = p.share_object_ID(ii)-1;
% extract h5location and reformat it
h5loc = [];
for det_extraargs = 1:length(p.detectors(ii).params.image_read_extraargs)
if strcmpi(p.detectors(ii).params.image_read_extraargs{det_extraargs}, 'H5Location')
h5loc = p.detectors(ii).params.image_read_extraargs{det_extraargs+1}(2:end-1);
end
end
% libDetXR uses 2 different readers: hdf for single h5 file and
% oldEigerH5 for multiple files
p = p.detectors(ii).params.get_filename(p);
if strcmpi(p.detectors(ii).params.file_extension, 'h5')
if numel(p.detectors(ii).detStorage.files)==1
reader = 'hdf';
else
reader = 'oldEigerH5';
end
else
reader = p.detectors(ii).params.file_extension;
end
% bug fix for reading cbfs
if strcmpi(p.detectors(ii).params.file_extension, 'cbf')
h5loc = 'eh5/images';
end
if numel(p.detectors(ii).detStorage.files)==1 && strcmpi(p.detectors(ii).params.file_extension, 'h5')
fname = dir([p.raw_data_path_full{ii} '*.h5']);
file_list = fullfile(fname.folder, fname.name);
else
file_list = p.raw_data_path_full{ii};
end
s.measurement.(cid).src = {reader, file_list, h5loc};
% calculate transformation
trfData = [0 0];
if p.detectors(ii).params.orientation(1) == 1
trfData = trfData+1;
end
if p.detectors(ii).params.orientation(2) == 1
trfData(2) = trfData(2)+1;
end
if p.detectors(ii).params.orientation(3) == 1
trfData = trfData+1;
trfData(1) = trfData(1)+1;
end
% additional transpose for python data prep
trfData = trfData - 1;
% reduce number of fliplr
trfData(2) = mod(trfData(2),2);
s.measurement.(cid).trfData = trfData;
assert(size(p.ctr,1) >= p.numscans, 'one line of p.ctrl is needed for each scan')
s.measurement.(cid).roi = [p.ctr(ii,2)-1, p.ctr(ii,1)-1, p.asize(1), p.asize(1)];
s.measurement.(cid).pos = round(p.positions(p.scanindexrange(ii,1):p.scanindexrange(ii,2),:));
% Besides a list of points the positions
% can be given as omni_pos dat file and in
% that case it allows a transformation
% matrix.
s.initialCondition.dst = {'hdf', fullfile(p.initial_conditions_path,p.initial_conditions_file)};
%
% Also supports hdf "0": ["hdf", "$INDIR/cSAXS_sxdm_2014_07_omny_commissioning/analysis/S00033/S00033_initial_conditions_400x400.h5","probes/probe_0"],
% focusMdl and pinholeMdl are also
% supported but not tested.
end
for ii=unique(p.share_probe_ID)
cid = sprintf('id%d',ii-1);
% Probe may be propagated or interpolated from initial guess, here we
% have to save it to disk in order to be used by the Json ptycho
% preparator
% The probe is adapted in this code, interpolated, propagated or
% created from a model. In order for the Python data preparer to access
% these changes we save a temporary probe file to disk.
verbose(3, 'Temporary probe file for python data prep = %s', p.initial_probe_temp_file{ii});
temp_probe_full_file = fullfile(p.initial_conditions_path, p.initial_probe_temp_file{ii});
%probe = squeeze(p.probes(:,:,1,:));
probe = p.probes(:,:,ii,:);
probe = permute(probe,[4 1 2 3]); % C-code expects probe mode index first.
save(temp_probe_full_file,'probe');
s.initialCondition.probe.(cid) = {'mat', temp_probe_full_file, 'probe'};
end
for ii=unique(p.share_object_ID)
cid = sprintf('id%d',ii-1);
verbose(3, 'Temporary object file for python data prep = %s', p.initial_object_temp_file{ii});
temp_object_full_file = fullfile(p.initial_conditions_path,p.initial_object_temp_file{ii});
object = p.object{ii};
object = squeeze(permute(object,[3 1 2])); % C-code expects probe mode index first.
save(temp_object_full_file,'object', '-v6');
s.initialCondition.object.(cid) = {'mat', temp_object_full_file, 'object'};
end
% set parameters for c_solver engine; if only data preparation is needed,
% use dummy values
if p.external_engine0
s.initialCondition.param.pfft_relaxation = p.engines{1}.pfft_relaxation;
s.initialCondition.param.probe_regularization = p.engines{1}.probe_regularization;
s.initialCondition.param.probe_radius = p.engines{1}.probe_support_radius;
s.initialCondition.param.diffmap_iterations = p.engines{1}.number_iterations;
s.initialCondition.param.max_mlh_iterations = p.engines{1}.opt_iter;
else
s.initialCondition.param.pfft_relaxation = 0.05;
s.initialCondition.param.probe_regularization = 0.1;
s.initialCondition.param.probe_radius = 0.8;
s.initialCondition.param.diffmap_iterations = 200;
s.initialCondition.param.max_mlh_iterations = 100;
end
% Get a JSON string
t=mat2json(s);
% Write the file
if ~isfield(p, 'json_filename') || isempty(p.json_filename{1})
p.json_filename{1} = [core.generate_scan_name(p) sprintf('_json_template_%03dx%03d.json', p.asize(1), p.asize(2))];
end
verbose(3, 'JSON template filename = %s', p.json_filename{1});
json_fullpath_filename = fullfile(p.initial_conditions_path,p.json_filename{1});
verbose(3,sprintf('Writting to file %s',json_fullpath_filename));
h_json = fopen(json_fullpath_filename,'w');
fprintf(h_json,t);
fclose(h_json);
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Python prepare data %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
if ~isfield(p, 'ptychoPrep') || isempty(p.ptychoPrep)
[status hostname] = system('hostname');
fdb.status = core.engine_status(status);
hostname = strsplit(hostname, '-');
switch hostname{1}
case 'ra'
verbose(3, 'Loading python environment for the DaaS cluster.');
p.ptychoPrep = fullfile(p.cSAXS_matlab_path, 'cSAXS_python_env/daas/lib/python2.7/site-packages/libDetXR/procPtycho.py');
case 'x12sa'
verbose(3, 'Loading python environment for the cSAXS beamline.');
p.ptychoPrep = fullfile(p.cSAXS_matlab_path, 'cSAXS_python_env/x12sa/lib/python2.7/site-packages/libDetXR/procPtycho.py');
otherwise
error('Unknown host. Please specify your ptychoPrep or run it on the DaaS / beamline nodes.');
end
end
if verbose > 4
verb_ptychoPrep = ' -v1';
else
verb_ptychoPrep = ' -v0';
end
python_call = ['python ' p.ptychoPrep ' --meta ' json_fullpath_filename verb_ptychoPrep ' --multiproc --cmpr s-zlib4'];
verbose(3,'Calling python prepare data:\n%s', python_call);
for ii = 1:3
try
[status, result] = system(python_call, '-echo');
break
catch ME
warning('Data loading failed with error: %s\n Trying again ', ME.message)
end
end
if status
error('Data loading failed')
end
fdb.status = core.engine_status(status);
if p.delete_temp_json_data
verbose(3,'Removing temporary probe and object files')
for jj=1:length(p.initial_object_temp_file)
if exist([p.initial_conditions_path p.initial_object_temp_file{jj}], 'file')
[status, result] = system(['rm ' p.initial_conditions_path p.initial_object_temp_file{jj}], '-echo');
end
end
for jj=1:length(p.initial_probe_temp_file)
if exist([p.initial_conditions_path p.initial_probe_temp_file{jj}], 'file')
[status, result] = system(['rm ' p.initial_conditions_path p.initial_probe_temp_file{jj}], '-echo');
end
end
else
verbose(2,'Keeping H5 prepared data')
end
verbose(2,'Prepared data: %s', s.glob.dst{2});
verbose(2,'Initial conditions: %s', s.initialCondition.dst{2})
% bug fix for object sharing: procPtycho does not support object sharing,
% thus we have to overwrite the object size in the h5 data file.
if any(p.share_object)
h5_struc = [];
for ii=1:size(p.object_size,1)
h5_struc.objects(:,ii) = uint64(p.object_size(ii,:));
end
save2hdf5(fullfile(p.prepare_data_path, p.prepare_data_filename), h5_struc)
end
end
@@ -0,0 +1,21 @@
%APPLY_CIRCULAR_MASK applies a circular mask to fmask, which will be
%applied to data later
%
% ** p p structure
% returns:
% ++ p updated p structure
%
% see also: detector.prep_data.matlab_ps.matlab_aps
function [ p ] = apply_circular_mask( p )
if isfield(p.detector,'circ_mask') && p.detector.circ_mask>0
utils.verbose(2, 'Apply a circular mask (radius=%d pixels) to diffraction patterns',p.detector.circ_mask)
fmask = p.detectors(p.scanID).detStorage.fmask;
circ_mask = utils.make_circular_mask([size(fmask,1),size(fmask,1)], p.detector.circ_mask);
p.detectors(p.scanID).detStorage.fmask = fmask .*circ_mask;
end
end
@@ -0,0 +1,47 @@
%BINNING postprocess functions
% apply binning or upsampling on the measured data
%
% ** p p structure
% returns:
% ++ p updated p structure
%
% see also: detector.prep_data.matlab_ps.matlab_aps
function [ p ] = binning( p )
data = p.detectors(p.scanID).detStorage.data;
fmask = p.detectors(p.scanID).detStorage.fmask;
%% apply binning or upsampling on the measured data
if isfield(p.detector,'binning')&& p.detector.binning
binning = 2^p.detector.binning;
data = utils.binning_2D(data, binning) * binning^2;
fmask =utils.binning_2D(fmask,binning) == 1; % remove all binned pixel where at least one was masked
end
if isfield(p.detector,'upsampling')&& p.detector.upsampling
upsample = 2^p.detector.upsampling;
utils.verbose(2, 'Upsample diffraction patterns by %d',upsample)
if isfield(p.detector,'upsampling_method') && (strcmp(p.detector.upsampling_method,'bilinear') || strcmp(p.detector.upsampling_method,'bicubic'))
%added by YJ
%disp(p.detector.upsampling_method)
utils.verbose(2, 'Upsample method: imresize with %s interpolation',p.detector.upsampling_method)
data = imresize(data, upsample, p.detector.upsampling_method) / upsample^2;
else
utils.verbose(2, 'Upsample method: utils.unbinning_2D')
data = utils.unbinning_2D(data, upsample) / upsample^2; %PSI method
end
fmask = utils.unbinning_2D(fmask,upsample) == 1; % remove all binned pixel where at least one was masked
end
p.detectors(p.scanID).detStorage.data = data;
p.detectors(p.scanID).detStorage.fmask = fmask;
end
@@ -0,0 +1,84 @@
%CHECK_BURST check first file for burst scan
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 ] = check_burst( p )
import io.image_read
import utils.compile_x12sa_filename
import utils.get_hdr_val
filefirst = compile_x12sa_filename(p.scan_number(1),0,'BasePath',[p.raw_data_path{1} p.(p.detector.name).basepath_dir],'BaseName',p.detector.data_prefix(1:end-2));
x = image_read(filefirst,'IsFmask',1);
if isempty(x.data)
error(['File not found ' filefirst])
end
cutoff = get_hdr_val(x.header{1}, 'Count_cutoff', ' %d', true);
if p.scan.is_cont||~isempty(p.positions_file)
p.(p.detector.name).mask_saturated_value = cutoff;
else
underscore = strfind(filefirst,'_');
point = strfind(filefirst,'.');
x = image_read([filefirst(1:underscore(end)) '*' filefirst(point(end):end)],'IsFmask',1);
if isempty(x.data)
error(['File not found ' [filefirst(1:underscore(end)) '*' filefirst(point(end):end)] ])
end
burst = size(x.data,3);
display(['Detected burst at each point = ' num2str(burst)])
p.(p.detector.name).mask_saturated_value = cutoff*burst;
end
end
@@ -0,0 +1,71 @@
%GET_CENTER Estimate the center of the diffraction pattern
function [ p ] = get_center( p )
import utils.verbose
import io.*
detStorage = p.detectors(p.scanID).detStorage;
ctr = detStorage.ctr;
%{
if verbose>2
verbose(3, 'Loading sample image.')
% read sample image
if p.detectors(p.scanID).params.data_stored % if the data should be loaded from disk
if verbose > 2
[p] = p.detectors(p.scanID).params.get_filename(p);
files = detStorage.files;
if numel(files) == 0
error('Did not find any files.')
end
det.params = p.detectors(p.scanID).params;
sample_file = image_read(files{1}, det.params.image_read_extraargs);
end
end
sz = size(sample_file.data(:,:,1));
f = double(sample_file.data(:,:,1));
% Look for center
[~, cy] = max(sum(f.*detStorage.mask,2));
[~, cx] = max(sum(f.*detStorage.mask,1));
ctr_auto = [cy, cx];
if strcmp(detStorage.check_ctr, 'auto')
ctr = ctr_auto;
verbose(3, sprintf('Using center: (%d, %d)', ctr(1), ctr(2)));
elseif strcmp(detStorage.check_ctr, 'inter')
imagesc(log(detStorage.f));
[cx,cy] = getpts;
close(gcf);
ctr = round([cy, cx]);
verbose(3, sprintf('Using center: (%d, %d) - I would have guessed it is (%d, %d)', ctr(1), ctr(2), ctr_auto(1), ctr_auto(2)));
else
verbose(3, sprintf('Using center: (%d, %d) - I would have guessed it is (%d, %d)', ctr(1), ctr(2), ctr_auto(1), ctr_auto(2)));
end
else
verbose(2, sprintf('Using center: (%d, %d)', ctr(1), ctr(2)));
end
%}
verbose(2, sprintf('Using center: (%d, %d)', ctr(1), ctr(2)));
detStorage.ctr = ctr;
if ~p.prealign_FP
detStorage.lim_inf = ctr-p.asize/2;
detStorage.lim_sup = ctr+p.asize/2-1;
else
detStorage.lim_inf = ctr-p.prealign.asize/2;
detStorage.lim_sup = ctr+p.prealign.asize/2-1;
end
verbose(2, sprintf('Selected region: (''RowFrom'', %d, ''RowTo'', %d, ''ColumnFrom'', %d, ''ColumnTo'', %d)', detStorage.lim_inf(1), detStorage.lim_sup(1), detStorage.lim_inf(2), detStorage.lim_sup(2)));
%{
if verbose>2
if any(detStorage.lim_inf < 1) || any(detStorage.lim_sup > sz)
error('Array size exceeds limit (according to position of center, should be < %d)', max([1-detStorage.lim_inf, detStorage.lim_sup-sz]));
end
end
%}
end
@@ -0,0 +1,96 @@
%GET_MASK Mask saturated values as defined in the detector template
%
% ** p p structure
%
% returns:
% ++ p p structure
%
% see also: detector.prep_data.matlab_ps.prepare_data
%
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 ] = get_mask( p )
%% Mask saturated values, create 3D fmask if detector mask is not empty
% get pointers and local references
detStorage = p.detectors(p.scanID).detStorage;
detParams = p.detectors(p.scanID).params;
if ~isempty(detParams.mask_saturated_value) || ~isempty(detParams.mask_below_value)
if size(detStorage.mask,3)==1
detStorage.fmask = repmat(detStorage.mask(detStorage.lim_inf(1):detStorage.lim_sup(1), detStorage.lim_inf(2):detStorage.lim_sup(2)),[1 1 size(detStorage.data,3)]);
else
detStorage.fmask = detStorage.mask(detStorage.lim_inf(1):detStorage.lim_sup(1), detStorage.lim_inf(2):detStorage.lim_sup(2),1:size(detStorage.data,3));
end
else
detStorage.fmask = detStorage.mask(detStorage.lim_inf(1):detStorage.lim_sup(1), detStorage.lim_inf(2):detStorage.lim_sup(2),:);
end
if ~isempty(detParams.mask_saturated_value)
detStorage.fmask = (detStorage.data < detParams.mask_saturated_value) .* detStorage.fmask;
end
if ~isempty(detParams.mask_below_value)
detStorage.fmask = (detStorage.data > detParams.mask_below_value) .* detStorage.fmask;
end
%% (Fourier ptycho specific option)
if isfield(detParams, 'filt_pinhole') && ~isempty(detParams.filt_pinhole)
detStorage.fmask = detStorage.fmask.*utils.filt2d_pad(800,round(detParams.filt_pinhole*0.9),round(detParams.filt_pinhole*0.9), 'circ');
end
end
@@ -0,0 +1,177 @@
%LOAD_DATA prepare filenames and load data
% ** p p structure
%
% returns:
% ++ p p structure
%
% see also: detector.prep_data.matlab_ps.prepare_data
% written by YJ
function [ p ] = load_data( p )
import utils.find_files
import io.image_read
det.params = p.detectors(p.scanID).params;
detStorage = p.detectors(p.scanID).detStorage;
%% prepare filenames
if isempty(detStorage.files)
[p] = det.params.get_filename(p);
if numel(detStorage.files) == 0
error('Did not find any files.')
end
end
utils.verbose(2, 'Loading raw data of scan %05d.', p.scan_number(p.scanID))
files = detStorage.files;
utils.verbose(2, strcat('HDF5 file name:', files{p.scanID}))
%disp(files{p.scanID})
try
data = h5read(files{p.scanID},'/dp');
catch
error('Failed to load dp from %s', files{p.scanID});
end
data = squeeze(data);
utils.verbose(2, strcat('Loaded data from:', files{p.scanID}))
if det.params.orientation(1)
utils.verbose(2, 'Transposing diffraction patterns')
data = permute(data, [2 1 3]);
end
if det.params.orientation(2) && det.params.orientation(3)
utils.verbose(2, 'Flipping diffraction patterns')
data = rot90(data,2); % merge the fliplr and flipup operations
else
if det.params.orientation(2)
data = fliplr(data);
end
if det.params.orientation(3)
data = flipud(data);
end
end
%{
%% select data loading routine
current_version = version;
ver_str = strsplit(current_version, '.');
ver_num = str2double([ver_str{1} '.' ver_str{2} ver_str{3}]);
if ver_num >= 9.4
c_reader = true;
else
utils.verbose(3, 'Fast data reader is not available for Matlab version %d. Switching to image_read.', ver_num)
c_reader = false;
end
if c_reader && ~ismember(det.params.file_extension, {'h5', 'cbf', 'tiff', 'tif'})
utils.verbose(3, 'Fast data reader is not available for selected file format %s. Switching to image_read.', det.params.file_extension)
c_reader = false;
end
%% load data
if c_reader
% use fast data reader
if strcmpi(det.params.file_extension, 'tif')
det.params.file_extension = 'tiff';
end
if strcmpi(det.params.file_extension, 'tiff')
% keep results consistent with matlab's imread and io.image_read for tiff files
det.params.orientation(1) = ~det.params.orientation(1);
end
% convert PtychoShelves center to raw data center
arg.ctr = detStorage.ctr-1;
sz = det.params.geometry.sz;
if det.params.orientation(3)
arg.ctr(1) = round(sz(1) - arg.ctr(1));
end
if det.params.orientation(2)
arg.ctr(2) = round(sz(2) - arg.ctr(2));
end
if det.params.orientation(1)
arg.ctr = fliplr(arg.ctr);
end
if iscolumn(arg.ctr)
arg.ctr = arg.ctr';
end
% flip XY
arg.ctr = fliplr(arg.ctr);
% create structure for c_reader
arg.data_path = files;
arg.nthreads = p.io.data_nthreads;
arg.precision = p.io.data_precision;
arg.extension = det.params.file_extension;
arg.asize = detStorage.read_size;
arg.data_location = detStorage.h5_group;
assert(all(arg.ctr>0),'Raw data center position has to be positive.')
% load data and permute
utils.verbose(2, 'Loading raw data of scan S%05d.', p.scan_number(p.scanID))
data = io.read_measurement(arg);
data = squeeze(data);
size(data)
if det.params.orientation(1)
data = permute(data, [2 1 3]);
end
if det.params.orientation(2) && det.params.orientation(3)
data = rot90(data,2); % merge the fliplr and flipup operations
else
if det.params.orientation(2)
data = fliplr(data);
end
if det.params.orientation(3)
data = flipud(data);
end
end
else
if isempty(detStorage.h5_group)
if numel(files)==1
% one directory contains single file
dataaux = image_read(files{1}, det.params.image_read_extraargs);
data = dataaux.data;
else
% multiple files per directory
dataaux = image_read(files, det.params.image_read_extraargs);
data = dataaux.data;
end
else
data = zeros([p.asize numel(detStorage.h5_group)]);
if numel(files)==1
if numel(detStorage.h5_group)==1
numel(detStorage.h5_group)
% one hdf5 file; one group
dataaux = image_read(files{1}, det.params.image_read_extraargs{:}, 'H5Location', detStorage.h5_group{1});
data = dataaux.data;
else
% one hdf5 file; multiple groups
for ii=1:numel(detStorage.h5_group)
dataaux = image_read(files{1}, det.params.image_read_extraargs{:}, 'H5Location', detStorage.h5_group{ii});
data(:,:,ii) = dataaux.data;
end
end
else
if numel(detStorage.h5_group)==1
% multiple files, single H5 group
dataaux = image_read(files, det.params.image_read_extraargs{:}, 'H5Location', detStorage.h5_group{1});
data = dataaux.data;
else
% multiple files, but different H5 group
for ii=1:numel(detStorage.h5_group)
dataaux = image_read(files{ii}, det.params.image_read_extraargs{:}, 'H5Location', detStorage.h5_group{ii});
data(:,:,ii) = dataaux.data;
end
end
end
end
end
%}
detStorage.data = data;
end
@@ -0,0 +1,21 @@
%MASK_GEOMETRY crop mask to fit defined readout geometries
% if no geometry is specified, the full mask is used
% ** p p structure
%
% returns:
% ++ p p structure
%
% see also: detector.prep_data.matlab_ps.prepare_data
%
function [ p ] = mask_geometry( p )
scanID = p.scanID;
detStorage = p.detectors(scanID).detStorage;
if isfield(p.detectors(scanID).params, 'geometry') && ~isempty(p.detectors(scanID).params.geometry.mask)
detStorage.mask = detStorage.mask(p.detectors(ii).params.geometry.mask{1},p.detectors(ii).params.geometries.mask{2},:);
end
end
@@ -0,0 +1,46 @@
%MATLAB_APS - Matlab data preparator for APS hdf5 data
% Writtend by YJ
function p = matlab_aps(p)
import utils.*
%% call prepare data function
for ii=1:length(p.scan_number)
p.scanID = ii;
[p] = detector.prep_data.matlab_aps.prepare_data(p);
end
%% combine data structures
data = single([]);
fmask = logical([]);
for ii=1:length(p.scan_number)
data = cat(3,data,p.detectors(ii).detStorage.data);
if size(p.detectors(ii).detStorage.fmask,3) > 1
fmask = cat(3,fmask,logical(round(p.detectors(ii).detStorage.fmask)));
else
fmask = cat(3,fmask,repmat(p.detectors(ii).detStorage.fmask,[1 1 size(p.detectors(ii).detStorage.data,3)]));
end
p.detectors(ii).detStorage.fmask = []; % save memory
p.detectors(ii).detStorage.data = [];
end
for ii = 1:p.numobjs
p.object_size(ii,:) = [size(p.object{ii},1),size(p.object{ii},2)];
end
if (isfield(p.detector,'binning')&& p.detector.binning) || (isfield(p.detector,'upsampling')&& p.detector.upsampling)
p = core.apply_binning(p, 2^(p.detector.binning - p.detector.upsampling)); % modify the p structure after binning
end
p = detector.prep_data.matlab_ps.prep_data_matlab(p, data, fmask);
% Compare number of points and diffraction patterns
num_difpat = size(p.fmag,3);
verbose(2, 'Number of probe positions: %d', sum(p.numpts));
verbose(2, 'Number of diffraction patterns : %d', num_difpat);
if num_difpat ~= sum(p.numpts)
error('Number of probe positions (%d) inconsistent with number of diffraction patterns (%d)', sum(p.numpts), num_difpat);
end
end
@@ -0,0 +1,20 @@
%POSTPROCESS postprocess functions
% applied to the 4D raw data
%
% ** p p structure
% returns:
% ++ p updated p structure
%
% see also: detector.prep_data.matlab_ps.matlab_ps
function [ p ] = postprocess( p )
detStorage = p.detectors(p.scanID).detStorage;
%% apply some custom correction such as background subtraction on detStorage.data
end
@@ -0,0 +1,165 @@
%PREPARE_DATA_MATLAB prepares and normalizes data for matlab engines
function [ p ] = prep_data_matlab( p, data, fmask )
import utils.pshift
import utils.verbose
import utils.get_option
import math.fftshift_2D
scanfirstindex = [1 cumsum(p.numpts)+1]; % First index for scan number
% Region of interest [xmin xmax ymin ymax]
% Warning Not implemented for shared scans
% Need to update p.numpts, p.positions, data, fmask, indices
if isfield(p, 'scan') && isfield(p.scan, 'roi') && ~isempty(p.scan.roi)
% Convert to p.positions centered on the object
if p.share_object
positions_centered = p.positions - p.object_size(1,:)/2 + p.asize(:)/2;
else
for ii = 1:p.numscans
positions_centered(p.scanidxs{ii},:) = p.positions(p.scanidxs{ii},:) - p.object_size(ii,:)/2;
end
end
xmin = p.scan.roi(1)/p.dx_spec(2);
xmax = p.scan.roi(2)/p.dx_spec(2);
ymin = p.scan.roi(3)/p.dx_spec(1);
ymax = p.scan.roi(4)/p.dx_spec(1);
% Quick check
if (xmin>xmax)
error('ROI is empty, xmax<xmin')
elseif (ymin>ymax)
error('ROI is empty, ymax<ymin')
end
% Do the comparison and update accordingly [xmin xmax ymin ymax]
whichtokeep = find( (positions_centered(:,1) > ymin) & ...
(positions_centered(:,1)< ymax) & ...
(positions_centered(:,2) > xmin) & ...
(positions_centered(:,2) < xmax) );
% update p.numpts, positions, data, fmask, indices
data = data(:,:,whichtokeep);
fmask = fmask(:,:,whichtokeep);
p.positions = p.positions(whichtokeep,:);
for ii = 1:p.numscans
% indaux = find(whichtokeep<scanfirstindex(ii+1),'last'); % Finds the last index of scan ii in the new variables
indaux = find((whichtokeep>=scanfirstindex(ii))&(whichtokeep<scanfirstindex(ii+1))); % Finds indices of scan ii in the new variables
if isempty(indaux)
error('ROI: Scan %s has no points in the ROI. Change the ROI or remove this scan from the scan list',p.scan_str{ii})
end
p.numpts(ii) = numel(indaux);
end
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
verbose(2, 'Region of interest reduced number of points from %d to %d', sum(p.numpts_orig), sum(p.numpts));
% Redo a convenient offset
p.positions = p.positions - min(p.positions) + 1;
% Recompute object sizes
p = update_object_size(p);
end
% Skip some data point (for testing reduced dose)
if isfield(p, 'skip_points')
if ~isempty(p.skip_points) && p.skip_points>1
offset = mod(p.scan_number, p.skip_points);
%offset = mod([0 1 2], p.skip_points);
whichtokeep = [1+offset(1):p.skip_points:p.numpts(1)];
for idx = 2:length(p.numpts)
last_idx = sum(p.numpts(1:idx-1));
whichtokeep = [whichtokeep , (last_idx+1+offset(idx)):p.skip_points:(last_idx+p.numpts(idx))];
end
data = data(:,:,whichtokeep);
fmask = fmask(:,:,whichtokeep);
p.positions = p.positions(whichtokeep,:);
for ii = 1:p.numscans
% indaux = find(whichtokeep<scanfirstindex(ii+1),'last'); % Finds the last index of scan ii in the new variables
indaux = find((whichtokeep>=scanfirstindex(ii))&(whichtokeep<scanfirstindex(ii+1))); % Finds indices of scan ii in the new variables
if isempty(indaux)
error('ROI: Scan %s has no points in the ROI. Change the ROI or remove this scan from the scan list',p.scan_str{ii})
end
p.numpts(ii) = numel(indaux);
end
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
verbose(2, 'Region of interest reduced number of points from %d to %d', sum(p.numpts_orig), sum(p.numpts));
% Recompute object sizes
if p.share_object
p.object_size = p.asize + max(p.positions,[],1);
verbose(3, 'Computed object size: %d x %d', p.object_size(1), p.object_size(2));
else
for ii = 1:p.numscans
p.object_size(ii,:) = p.asize + max(p.positions(p.scanindexrange(ii,1):p.scanindexrange(ii,2),:),[],1);
verbose(3, 'Computed object size: %d x %d', p.object_size(ii,1), p.object_size(ii,2));
end
end
end
end
% % padding
% if any(datasize ~= p.asize)
% newdata = zeros([p.asize, num_difpat]);
% offset = floor(.5*(p.asize-datasize));
% newdata(offset(1) + (1:datasize(1)), offset(2) + (1:datasize(2)), :) = data;
% data = newdata;
% clear newdata
% newfmask = ones([p.asize, size(fmask,3)]);
% newfmask(offset(1) + (1:datasize(1)), offset(2) + (1:datasize(2)), :) = fmask;
% fmask = newfmask;
% clear newfmask
% end
% 'auto_center_data' option is useful if detector shifts provided in
% template cannot be trusted, ie for more than 2 joined scans
if get_option(p,'auto_center_data') && ~get_option(p,'get_artificial_data')
for i = 1:p.numscans
ind = p.scanidxs{i};
[x,y] = math.center(mean(data(:,:,ind) .* fmask(:,:,ind),3));
verbose(2,'Auto-shifting diffraction patterns by %i %i px', round(x), round(y))
data(:,:,ind) = utils.imshift_fast(data(:,:,ind), x, y, [], 'nearest');
if size(fmask,3) == size(data,3)
fmask(:,:,ind) = utils.imshift_fast(fmask(:,:,ind), x, y, [], 'nearest');
elseif p.numscans == 1
fmask = utils.imshift_fast(fmask, x, y, [], 'nearest');
else
error('Not implemented mask shifting option')
end
end
end
p.fmask_per_scan = ndims(fmask) == 3;
% Prepare Fourier projections
% normalization ignores valid mask - should modify
for ii=1:p.numscans
p.max_sum(ii) = max(sum(sum(data(:,:,p.scanidxs{ii}),1),2),[],3);
end
max_power = max(p.max_sum) / prod(p.asize);
p.renorm = sqrt(1/max_power);
p.Nphot = sum(data(:).*fmask(:)); % Number of photons for regularization normalization (ML optimization)
% store mask pre-fftshifted
p.fmask = fftshift_2D(fmask);
clear fmask
% precalculate modulus of data, normalize and fftshift
p.fmag = fftshift_2D(sqrt(data)) * p.renorm;
end
@@ -0,0 +1,96 @@
%PREPARE_DATA prepare the raw data for the ptychographic reconstruction
%
% ** p p structure
%
% returns:
% ++ p p structure
%
% *Note:*
% All (default) functions are located in +detector/+prep_data/+matlab_ps. If You want
% to add a new detector, please create a new package directory
% (+detector_name) with a parameter file detector_name.m. Functions in a
% package detectory directory will overload similar functions in the default directory.
%
% see also: detector.prep_data.matlab_ps.matlab_ps
%
%
function [ p ] = prepare_data( p )
import utils.*
import io.image_read
verbose(1, 'Preparing data using matlab APS data preparation.')
%% initialize detector
scanID = p.scanID;
detStorage = p.detectors(scanID).detStorage;
if size(p.ctr,1) == 1
center = p.ctr; % save centers for all diffraction patterns
else
center = p.ctr(scanID,:); % different centers for different diffraction patterns
end
check_ctr = 'auto';
if ~isempty(center)
check_ctr = 'inter';
if ~strcmp(center, 'inter')
detStorage.ctr = center;
verbose(2,['Using supplied center: ', num2str(detStorage.ctr)]);
check_ctr = 'no';
end
end
detStorage.check_ctr = check_ctr;
%% load mask
if isfield(p.detectors(scanID).params, 'mask') && ~isempty(p.detectors(scanID).params.mask)
load(p.detectors(scanID).params.mask);
detStorage.mask = logical(mask);
elseif p.detectors(scanID).params.data_stored
detStorage.mask = ones(p.detectors(scanID).params.geometry.sz, 'logical');
else
detStorage.mask = logical([]);
end
%% crop mask to readout geometry (if necessary)
[p] = p.detectors(scanID).funcs.mask_geometry(p);
%% get center and readout size
[p] = p.detectors(scanID).funcs.get_center(p);
%% preprocess
[p] = p.detectors(scanID).funcs.preprocess(p);
%% load data
[p] = p.detectors(scanID).funcs.load_data(p);
%% process raw data
[p] = p.detectors(scanID).funcs.process_raw_data(p);
%% mask saturated values
[p] = p.detectors(scanID).funcs.get_mask(p);
%% apply a circular mask to diffraction patterns. Added by YJ.
[p] = p.detectors(scanID).funcs.apply_circular_mask(p);
%% apply binning on the measured data / mask
[p] = p.detectors(scanID).funcs.binning(p);
%% final step postprocessing, e.g. background subtraction
[p] = p.detectors(scanID).funcs.postprocess(p);
end
@@ -0,0 +1,34 @@
%PREPROCESS preprocess functions
% e.g. select area before reading from disk
%
% ** p p structure
%
% returns:
% ++ p p structure
%
% see also: detector.prep_data.matlab_ps.prepare_data
%
function [ p ] = preprocess( p )
detStorage = p.detectors(p.scanID).detStorage;
p.detectors(p.scanID).params.image_read_extraargs{end+1} = 'RowFrom';
p.detectors(p.scanID).params.image_read_extraargs{end+1} = detStorage.lim_inf(1);
p.detectors(p.scanID).params.image_read_extraargs{end+1} = 'RowTo';
p.detectors(p.scanID).params.image_read_extraargs{end+1} = detStorage.lim_sup(1);
p.detectors(p.scanID).params.image_read_extraargs{end+1} = 'ColumnFrom';
p.detectors(p.scanID).params.image_read_extraargs{end+1} = detStorage.lim_inf(2);
p.detectors(p.scanID).params.image_read_extraargs{end+1} = 'ColumnTo';
p.detectors(p.scanID).params.image_read_extraargs{end+1} = detStorage.lim_sup(2);
if ~p.prealign_FP
detStorage.read_size = p.asize;
else
detStorage.read_size = p.prealign.asize;
end
end
@@ -0,0 +1,31 @@
%PROCESS_RAW_DATA postprocess functions
% applied to the 4D raw data
%
% ** p p structure
% returns:
% ++ p updated p structure
%
% see also: detector.prep_data.matlab_ps.matlab_ps
function [ p ] = process_raw_data( p )
detStorage = p.detectors(p.scanID).detStorage;
if p.prealign_FP
p = core.FPM.FP_prealign(p);
detStorage.lim_inf = detStorage.ctr-p.asize/2;
detStorage.lim_sup = detStorage.ctr+p.asize/2-1;
end
% sum up data from burst scans
if p.scan.is_cont
detStorage.data = sum(detStorage.data,4);
else
sz = size(detStorage.data);
detStorage.data = reshape(detStorage.data, sz(1), sz(2), []);
end
end
@@ -0,0 +1,21 @@
%APPLY_CIRCULAR_MASK applies a circular mask to fmask, which will be
%applied to data later
%
% ** p p structure
% returns:
% ++ p updated p structure
%
% see also: detector.prep_data.matlab_ps.matlab_aps
function [ p ] = apply_circular_mask( p )
if isfield(p.detector,'circ_mask') && p.detector.circ_mask>0
utils.verbose(2, 'Apply a circular mask (radius=%d pixels) to diffraction patterns',p.detector.circ_mask)
fmask = p.detectors(p.scanID).detStorage.fmask;
circ_mask = utils.make_circular_mask([size(fmask,1),size(fmask,1)], p.detector.circ_mask);
p.detectors(p.scanID).detStorage.fmask = fmask .*circ_mask;
end
end
@@ -0,0 +1,48 @@
%BINNING postprocess functions
% apply binning or upsampling on the measured data
%
% ** p p structure
% returns:
% ++ p updated p structure
%
% see also: detector.prep_data.matlab_ps.matlab_aps
function [ p ] = binning( p )
data = p.detectors(p.scanID).detStorage.data;
fmask = p.detectors(p.scanID).detStorage.fmask;
%% apply binning or upsampling on the measured data
if isfield(p.detector,'binning')&& p.detector.binning
binning = 2^p.detector.binning;
data = utils.binning_2D(data, binning) * binning^2;
fmask =utils.binning_2D(fmask,binning) == 1; % remove all binned pixel where at least one was masked
end
if isfield(p.detector,'upsampling')&& p.detector.upsampling
upsample = 2^p.detector.upsampling;
utils.verbose(2, 'Upsample diffraction patterns by %d',upsample)
if isfield(p.detector,'upsampling_method') && (strcmp(p.detector.upsampling_method,'bilinear') || strcmp(p.detector.upsampling_method,'bicubic'))
%added by YJ
%disp(p.detector.upsampling_method)
utils.verbose(2, 'Upsample method: imresize with %s interpolation',p.detector.upsampling_method)
data = imresize(data, upsample, p.detector.upsampling_method) / upsample^2;
else
utils.verbose(2, 'Upsample method: utils.unbinning_2D')
data = utils.unbinning_2D(data, upsample) / upsample^2; %PSI method
end
fmask = utils.unbinning_2D(fmask,upsample) == 1; % remove all binned pixel where at least one was masked
end
p.detectors(p.scanID).detStorage.data = data;
p.detectors(p.scanID).detStorage.fmask = fmask;
end
@@ -0,0 +1,84 @@
%CHECK_BURST check first file for burst scan
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 ] = check_burst( p )
import io.image_read
import utils.compile_x12sa_filename
import utils.get_hdr_val
filefirst = compile_x12sa_filename(p.scan_number(1),0,'BasePath',[p.raw_data_path{1} p.(p.detector.name).basepath_dir],'BaseName',p.detector.data_prefix(1:end-2));
x = image_read(filefirst,'IsFmask',1);
if isempty(x.data)
error(['File not found ' filefirst])
end
cutoff = get_hdr_val(x.header{1}, 'Count_cutoff', ' %d', true);
if p.scan.is_cont||~isempty(p.positions_file)
p.(p.detector.name).mask_saturated_value = cutoff;
else
underscore = strfind(filefirst,'_');
point = strfind(filefirst,'.');
x = image_read([filefirst(1:underscore(end)) '*' filefirst(point(end):end)],'IsFmask',1);
if isempty(x.data)
error(['File not found ' [filefirst(1:underscore(end)) '*' filefirst(point(end):end)] ])
end
burst = size(x.data,3);
display(['Detected burst at each point = ' num2str(burst)])
p.(p.detector.name).mask_saturated_value = cutoff*burst;
end
end
@@ -0,0 +1,71 @@
%GET_CENTER Estimate the center of the diffraction pattern
function [ p ] = get_center( p )
import utils.verbose
import io.*
detStorage = p.detectors(p.scanID).detStorage;
ctr = detStorage.ctr;
%{
if verbose>2
verbose(3, 'Loading sample image.')
% read sample image
if p.detectors(p.scanID).params.data_stored % if the data should be loaded from disk
if verbose > 2
[p] = p.detectors(p.scanID).params.get_filename(p);
files = detStorage.files;
if numel(files) == 0
error('Did not find any files.')
end
det.params = p.detectors(p.scanID).params;
sample_file = image_read(files{1}, det.params.image_read_extraargs);
end
end
sz = size(sample_file.data(:,:,1));
f = double(sample_file.data(:,:,1));
% Look for center
[~, cy] = max(sum(f.*detStorage.mask,2));
[~, cx] = max(sum(f.*detStorage.mask,1));
ctr_auto = [cy, cx];
if strcmp(detStorage.check_ctr, 'auto')
ctr = ctr_auto;
verbose(3, sprintf('Using center: (%d, %d)', ctr(1), ctr(2)));
elseif strcmp(detStorage.check_ctr, 'inter')
imagesc(log(detStorage.f));
[cx,cy] = getpts;
close(gcf);
ctr = round([cy, cx]);
verbose(3, sprintf('Using center: (%d, %d) - I would have guessed it is (%d, %d)', ctr(1), ctr(2), ctr_auto(1), ctr_auto(2)));
else
verbose(3, sprintf('Using center: (%d, %d) - I would have guessed it is (%d, %d)', ctr(1), ctr(2), ctr_auto(1), ctr_auto(2)));
end
else
verbose(2, sprintf('Using center: (%d, %d)', ctr(1), ctr(2)));
end
%}
verbose(2, sprintf('Using center: (%d, %d)', ctr(1), ctr(2)));
detStorage.ctr = ctr;
if ~p.prealign_FP
detStorage.lim_inf = ctr-p.asize/2;
detStorage.lim_sup = ctr+p.asize/2-1;
else
detStorage.lim_inf = ctr-p.prealign.asize/2;
detStorage.lim_sup = ctr+p.prealign.asize/2-1;
end
verbose(2, sprintf('Selected region: (''RowFrom'', %d, ''RowTo'', %d, ''ColumnFrom'', %d, ''ColumnTo'', %d)', detStorage.lim_inf(1), detStorage.lim_sup(1), detStorage.lim_inf(2), detStorage.lim_sup(2)));
%{
if verbose>2
if any(detStorage.lim_inf < 1) || any(detStorage.lim_sup > sz)
error('Array size exceeds limit (according to position of center, should be < %d)', max([1-detStorage.lim_inf, detStorage.lim_sup-sz]));
end
end
%}
end
@@ -0,0 +1,96 @@
%GET_MASK Mask saturated values as defined in the detector template
%
% ** p p structure
%
% returns:
% ++ p p structure
%
% see also: detector.prep_data.matlab_ps.prepare_data
%
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 ] = get_mask( p )
%% Mask saturated values, create 3D fmask if detector mask is not empty
% get pointers and local references
detStorage = p.detectors(p.scanID).detStorage;
detParams = p.detectors(p.scanID).params;
if ~isempty(detParams.mask_saturated_value) || ~isempty(detParams.mask_below_value)
if size(detStorage.mask,3)==1
detStorage.fmask = repmat(detStorage.mask(detStorage.lim_inf(1):detStorage.lim_sup(1), detStorage.lim_inf(2):detStorage.lim_sup(2)),[1 1 size(detStorage.data,3)]);
else
detStorage.fmask = detStorage.mask(detStorage.lim_inf(1):detStorage.lim_sup(1), detStorage.lim_inf(2):detStorage.lim_sup(2),1:size(detStorage.data,3));
end
else
detStorage.fmask = detStorage.mask(detStorage.lim_inf(1):detStorage.lim_sup(1), detStorage.lim_inf(2):detStorage.lim_sup(2),:);
end
if ~isempty(detParams.mask_saturated_value)
detStorage.fmask = (detStorage.data < detParams.mask_saturated_value) .* detStorage.fmask;
end
if ~isempty(detParams.mask_below_value)
detStorage.fmask = (detStorage.data > detParams.mask_below_value) .* detStorage.fmask;
end
%% (Fourier ptycho specific option)
if isfield(detParams, 'filt_pinhole') && ~isempty(detParams.filt_pinhole)
detStorage.fmask = detStorage.fmask.*utils.filt2d_pad(800,round(detParams.filt_pinhole*0.9),round(detParams.filt_pinhole*0.9), 'circ');
end
end
@@ -0,0 +1,185 @@
%LOAD_DATA prepare filenames and load data
% ** p p structure
%
% returns:
% ++ p p structure
%
% see also: detector.prep_data.matlab_ps.prepare_data
% written by YJ
function [ p ] = load_data( p )
import utils.find_files
import io.image_read
det.params = p.detectors(p.scanID).params;
detStorage = p.detectors(p.scanID).detStorage;
%% prepare filenames
if isempty(detStorage.files)
[p] = det.params.get_filename(p);
if numel(detStorage.files) == 0
error('Did not find any files.')
end
end
utils.verbose(2, 'Loading raw data of scan %05d.', p.scan_number(p.scanID))
files = detStorage.files;
utils.verbose(2, strcat('HDF5 file name:', files{p.scanID}))
%disp(files{p.scanID})
try
data = h5read(files{p.scanID},'/entry/data/eiger_4');
%data = h5read(files{p.scanID},'/entry/data/data');
catch
error('Failed to load dp from %s', files{p.scanID});
end
data = single(squeeze(data));
data = data(detStorage.lim_inf(2):detStorage.lim_sup(2),detStorage.lim_inf(1):detStorage.lim_sup(1),:);
%quick fix for bad detector readouts
data(data<0) = 0;
data(data>1e9) = 0;
utils.verbose(2, strcat('Loaded data from:', files{p.scanID}))
if det.params.orientation(1)
utils.verbose(2, 'Transposing diffraction patterns')
data = permute(data, [2 1 3]);
end
if det.params.orientation(2) && det.params.orientation(3)
utils.verbose(2, 'Flipping diffraction patterns')
data = rot90(data,2); % merge the fliplr and flipup operations
else
if det.params.orientation(2)
data = fliplr(data);
end
if det.params.orientation(3)
data = flipud(data);
end
end
%{
%% select data loading routine
current_version = version;
ver_str = strsplit(current_version, '.');
ver_num = str2double([ver_str{1} '.' ver_str{2} ver_str{3}]);
if ver_num >= 9.4
c_reader = true;
else
utils.verbose(3, 'Fast data reader is not available for Matlab version %d. Switching to image_read.', ver_num)
c_reader = false;
end
if c_reader && ~ismember(det.params.file_extension, {'h5', 'cbf', 'tiff', 'tif'})
utils.verbose(3, 'Fast data reader is not available for selected file format %s. Switching to image_read.', det.params.file_extension)
c_reader = false;
end
%% load data
if c_reader
% use fast data reader
if strcmpi(det.params.file_extension, 'tif')
det.params.file_extension = 'tiff';
end
if strcmpi(det.params.file_extension, 'tiff')
% keep results consistent with matlab's imread and io.image_read for tiff files
det.params.orientation(1) = ~det.params.orientation(1);
end
% convert PtychoShelves center to raw data center
arg.ctr = detStorage.ctr-1;
sz = det.params.geometry.sz;
if det.params.orientation(3)
arg.ctr(1) = round(sz(1) - arg.ctr(1));
end
if det.params.orientation(2)
arg.ctr(2) = round(sz(2) - arg.ctr(2));
end
if det.params.orientation(1)
arg.ctr = fliplr(arg.ctr);
end
if iscolumn(arg.ctr)
arg.ctr = arg.ctr';
end
% flip XY
arg.ctr = fliplr(arg.ctr);
% create structure for c_reader
arg.data_path = files;
arg.nthreads = p.io.data_nthreads;
arg.precision = p.io.data_precision;
arg.extension = det.params.file_extension;
arg.asize = detStorage.read_size;
arg.data_location = detStorage.h5_group;
assert(all(arg.ctr>0),'Raw data center position has to be positive.')
% load data and permute
utils.verbose(2, 'Loading raw data of scan S%05d.', p.scan_number(p.scanID))
data = io.read_measurement(arg);
data = squeeze(data);
size(data)
if det.params.orientation(1)
data = permute(data, [2 1 3]);
end
if det.params.orientation(2) && det.params.orientation(3)
data = rot90(data,2); % merge the fliplr and flipup operations
else
if det.params.orientation(2)
data = fliplr(data);
end
if det.params.orientation(3)
data = flipud(data);
end
end
else
if isempty(detStorage.h5_group)
if numel(files)==1
% one directory contains single file
dataaux = image_read(files{1}, det.params.image_read_extraargs);
data = dataaux.data;
else
% multiple files per directory
dataaux = image_read(files, det.params.image_read_extraargs);
data = dataaux.data;
end
else
data = zeros([p.asize numel(detStorage.h5_group)]);
if numel(files)==1
if numel(detStorage.h5_group)==1
numel(detStorage.h5_group)
% one hdf5 file; one group
dataaux = image_read(files{1}, det.params.image_read_extraargs{:}, 'H5Location', detStorage.h5_group{1});
data = dataaux.data;
else
% one hdf5 file; multiple groups
for ii=1:numel(detStorage.h5_group)
dataaux = image_read(files{1}, det.params.image_read_extraargs{:}, 'H5Location', detStorage.h5_group{ii});
data(:,:,ii) = dataaux.data;
end
end
else
if numel(detStorage.h5_group)==1
% multiple files, single H5 group
dataaux = image_read(files, det.params.image_read_extraargs{:}, 'H5Location', detStorage.h5_group{1});
data = dataaux.data;
else
% multiple files, but different H5 group
for ii=1:numel(detStorage.h5_group)
dataaux = image_read(files{ii}, det.params.image_read_extraargs{:}, 'H5Location', detStorage.h5_group{ii});
data(:,:,ii) = dataaux.data;
end
end
end
end
end
%}
detStorage.data = data;
end
@@ -0,0 +1,21 @@
%MASK_GEOMETRY crop mask to fit defined readout geometries
% if no geometry is specified, the full mask is used
% ** p p structure
%
% returns:
% ++ p p structure
%
% see also: detector.prep_data.matlab_ps.prepare_data
%
function [ p ] = mask_geometry( p )
scanID = p.scanID;
detStorage = p.detectors(scanID).detStorage;
if isfield(p.detectors(scanID).params, 'geometry') && ~isempty(p.detectors(scanID).params.geometry.mask)
detStorage.mask = detStorage.mask(p.detectors(ii).params.geometry.mask{1},p.detectors(ii).params.geometries.mask{2},:);
end
end
@@ -0,0 +1,50 @@
%MATLAB_APS - Matlab data preparator for APS hdf5 data
% Writtend by YJ
function p = matlab_aps_lynx(p)
import utils.*
%% call prepare data function
for ii=1:length(p.scan_number)
p.scanID = ii;
[p] = detector.prep_data.matlab_aps_lynx.prepare_data(p);
end
%% combine data structures
data = single([]);
fmask = logical([]);
for ii=1:length(p.scan_number)
data = cat(3,data,p.detectors(ii).detStorage.data);
if size(p.detectors(ii).detStorage.fmask,3) > 1
fmask = cat(3,fmask,logical(round(p.detectors(ii).detStorage.fmask)));
else
fmask = cat(3,fmask,repmat(p.detectors(ii).detStorage.fmask,[1 1 size(p.detectors(ii).detStorage.data,3)]));
end
p.detectors(ii).detStorage.fmask = []; % save memory
p.detectors(ii).detStorage.data = [];
end
for ii = 1:p.numobjs
p.object_size(ii,:) = [size(p.object{ii},1),size(p.object{ii},2)];
end
if (isfield(p.detector,'binning') && p.detector.binning) || (isfield(p.detector,'upsampling')&& p.detector.upsampling)
p = core.apply_binning(p, 2^(p.detector.binning - p.detector.upsampling)); % modify the p structure after binning
end
p = detector.prep_data.matlab_aps_lynx.prep_data_matlab(p, data, fmask);
% Compare number of points and diffraction patterns
num_difpat = size(p.fmag,3);
verbose(2, 'Number of probe positions: %d', sum(p.numpts));
verbose(2, 'Number of diffraction patterns : %d', num_difpat);
%quick fix for fly-scan data
%only works if # of diffraction patterns >= # of scan points
%{
if num_difpat ~= sum(p.numpts)
error('Number of probe positions (%d) inconsistent with number of diffraction patterns (%d)', sum(p.numpts), num_difpat);
end
%}
end
@@ -0,0 +1,20 @@
%POSTPROCESS postprocess functions
% applied to the 4D raw data
%
% ** p p structure
% returns:
% ++ p updated p structure
%
% see also: detector.prep_data.matlab_ps.matlab_ps
function [ p ] = postprocess( p )
detStorage = p.detectors(p.scanID).detStorage;
%% apply some custom correction such as background subtraction on detStorage.data
end
@@ -0,0 +1,163 @@
%PREPARE_DATA_MATLAB prepares and normalizes data for matlab engines
function [ p ] = prep_data_matlab( p, data, fmask )
import utils.pshift
import utils.verbose
import utils.get_option
import math.fftshift_2D
scanfirstindex = [1 cumsum(p.numpts)+1]; % First index for scan number
% Region of interest [xmin xmax ymin ymax]
% Warning Not implemented for shared scans
% Need to update p.numpts, p.positions, data, fmask, indices
if isfield(p, 'scan') && isfield(p.scan, 'roi') && ~isempty(p.scan.roi)
% Convert to p.positions centered on the object
if p.share_object
positions_centered = p.positions - p.object_size(1,:)/2 + p.asize(:)/2;
else
for ii = 1:p.numscans
positions_centered(p.scanidxs{ii},:) = p.positions(p.scanidxs{ii},:) - p.object_size(ii,:)/2;
end
end
xmin = p.scan.roi(1)/p.dx_spec(2);
xmax = p.scan.roi(2)/p.dx_spec(2);
ymin = p.scan.roi(3)/p.dx_spec(1);
ymax = p.scan.roi(4)/p.dx_spec(1);
% Quick check
if (xmin>xmax)
error('ROI is empty, xmax<xmin')
elseif (ymin>ymax)
error('ROI is empty, ymax<ymin')
end
% Do the comparison and update accordingly [xmin xmax ymin ymax]
whichtokeep = find( (positions_centered(:,1) > ymin) & ...
(positions_centered(:,1)< ymax) & ...
(positions_centered(:,2) > xmin) & ...
(positions_centered(:,2) < xmax) );
% update p.numpts, positions, data, fmask, indices
data = data(:,:,whichtokeep);
fmask = fmask(:,:,whichtokeep);
p.positions = p.positions(whichtokeep,:);
for ii = 1:p.numscans
% indaux = find(whichtokeep<scanfirstindex(ii+1),'last'); % Finds the last index of scan ii in the new variables
indaux = find((whichtokeep>=scanfirstindex(ii))&(whichtokeep<scanfirstindex(ii+1))); % Finds indices of scan ii in the new variables
if isempty(indaux)
error('ROI: Scan %s has no points in the ROI. Change the ROI or remove this scan from the scan list',p.scan_str{ii})
end
p.numpts(ii) = numel(indaux);
end
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
verbose(2, 'Region of interest reduced number of points from %d to %d', sum(p.numpts_orig), sum(p.numpts));
% Redo a convenient offset
p.positions = p.positions - min(p.positions) + 1;
% Recompute object sizes
p = update_object_size(p);
end
% Skip some data point (for testing reduced dose)
if isfield(p, 'skip_points')
if ~isempty(p.skip_points) && p.skip_points>1
offset = mod(p.scan_number, p.skip_points);
%offset = mod([0 1 2], p.skip_points);
whichtokeep = [1+offset(1):p.skip_points:p.numpts(1)];
for idx = 2:length(p.numpts)
last_idx = sum(p.numpts(1:idx-1));
whichtokeep = [whichtokeep , (last_idx+1+offset(idx)):p.skip_points:(last_idx+p.numpts(idx))];
end
data = data(:,:,whichtokeep);
fmask = fmask(:,:,whichtokeep);
p.positions = p.positions(whichtokeep,:);
for ii = 1:p.numscans
% indaux = find(whichtokeep<scanfirstindex(ii+1),'last'); % Finds the last index of scan ii in the new variables
indaux = find((whichtokeep>=scanfirstindex(ii))&(whichtokeep<scanfirstindex(ii+1))); % Finds indices of scan ii in the new variables
if isempty(indaux)
error('ROI: Scan %s has no points in the ROI. Change the ROI or remove this scan from the scan list',p.scan_str{ii})
end
p.numpts(ii) = numel(indaux);
end
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
verbose(2, 'Region of interest reduced number of points from %d to %d', sum(p.numpts_orig), sum(p.numpts));
% Recompute object sizes
if p.share_object
p.object_size = p.asize + max(p.positions,[],1);
verbose(3, 'Computed object size: %d x %d', p.object_size(1), p.object_size(2));
else
for ii = 1:p.numscans
p.object_size(ii,:) = p.asize + max(p.positions(p.scanindexrange(ii,1):p.scanindexrange(ii,2),:),[],1);
verbose(3, 'Computed object size: %d x %d', p.object_size(ii,1), p.object_size(ii,2));
end
end
end
end
% % padding
% if any(datasize ~= p.asize)
% newdata = zeros([p.asize, num_difpat]);
% offset = floor(.5*(p.asize-datasize));
% newdata(offset(1) + (1:datasize(1)), offset(2) + (1:datasize(2)), :) = data;
% data = newdata;
% clear newdata
% newfmask = ones([p.asize, size(fmask,3)]);
% newfmask(offset(1) + (1:datasize(1)), offset(2) + (1:datasize(2)), :) = fmask;
% fmask = newfmask;
% clear newfmask
% end
% 'auto_center_data' option is useful if detector shifts provided in
% template cannot be trusted, ie for more than 2 joined scans
if get_option(p,'auto_center_data') && ~get_option(p,'get_artificial_data')
for i = 1:p.numscans
ind = p.scanidxs{i};
[x,y] = math.center(mean(data(:,:,ind) .* fmask(:,:,ind),3));
verbose(2,'Auto-shifting diffraction patterns by %i %i px', round(x), round(y))
data(:,:,ind) = utils.imshift_fast(data(:,:,ind), x, y, [], 'nearest');
if size(fmask,3) == size(data,3)
fmask(:,:,ind) = utils.imshift_fast(fmask(:,:,ind), x, y, [], 'nearest');
elseif p.numscans == 1
fmask = utils.imshift_fast(fmask, x, y, [], 'nearest');
else
error('Not implemented mask shifting option')
end
end
end
p.fmask_per_scan = ndims(fmask) == 3;
% Prepare Fourier projections
% normalization ignores valid mask - should modify
for ii=1:p.numscans
p.max_sum(ii) = max(sum(sum(data(:,:,p.scanidxs{ii}),1),2),[],3);
end
max_power = max(p.max_sum) / prod(p.asize);
p.renorm = sqrt(1/max_power);
p.Nphot = sum(data(:).*fmask(:)); % Number of photons for regularization normalization (ML optimization)
% store mask pre-fftshifted
p.fmask = fftshift_2D(fmask);
clear fmask
% precalculate modulus of data, normalize and fftshift
p.fmag = fftshift_2D(sqrt(data)) * p.renorm;
end
@@ -0,0 +1,95 @@
%PREPARE_DATA prepare the raw data for the ptychographic reconstruction
%
% ** p p structure
%
% returns:
% ++ p p structure
%
% *Note:*
% All (default) functions are located in +detector/+prep_data/+matlab_ps. If You want
% to add a new detector, please create a new package directory
% (+detector_name) with a parameter file detector_name.m. Functions in a
% package detectory directory will overload similar functions in the default directory.
%
% see also: detector.prep_data.matlab_ps.matlab_ps
%
%
function [ p ] = prepare_data( p )
import utils.*
import io.image_read
verbose(1, 'Preparing data using matlab APS-LYNX data preparation.')
%% initialize detector
scanID = p.scanID;
detStorage = p.detectors(scanID).detStorage;
if size(p.ctr,1) == 1
center = p.ctr; % save centers for all diffraction patterns
else
center = p.ctr(scanID,:); % different centers for different diffraction patterns
end
check_ctr = 'auto';
if ~isempty(center)
check_ctr = 'inter';
if ~strcmp(center, 'inter')
detStorage.ctr = center;
verbose(2,['Using supplied center: ', num2str(detStorage.ctr)]);
check_ctr = 'no';
end
end
detStorage.check_ctr = check_ctr;
%% load mask
if isfield(p.detectors(scanID).params, 'mask') && ~isempty(p.detectors(scanID).params.mask)
load(p.detectors(scanID).params.mask);
detStorage.mask = logical(mask);
elseif p.detectors(scanID).params.data_stored
detStorage.mask = ones(p.detectors(scanID).params.geometry.sz, 'logical');
else
detStorage.mask = logical([]);
end
%% crop mask to readout geometry (if necessary)
[p] = p.detectors(scanID).funcs.mask_geometry(p);
%% get center and readout size
[p] = p.detectors(scanID).funcs.get_center(p);
%% preprocess
[p] = p.detectors(scanID).funcs.preprocess(p);
%% load data
[p] = p.detectors(scanID).funcs.load_data(p);
%% process raw data
[p] = p.detectors(scanID).funcs.process_raw_data(p);
%% mask saturated values
[p] = p.detectors(scanID).funcs.get_mask(p);
%% apply a circular mask to diffraction patterns. Added by YJ.
[p] = p.detectors(scanID).funcs.apply_circular_mask(p);
%% apply binning on the measured data / mask
[p] = p.detectors(scanID).funcs.binning(p);
%% final step postprocessing, e.g. background subtraction
[p] = p.detectors(scanID).funcs.postprocess(p);
end
@@ -0,0 +1,34 @@
%PREPROCESS preprocess functions
% e.g. select area before reading from disk
%
% ** p p structure
%
% returns:
% ++ p p structure
%
% see also: detector.prep_data.matlab_ps.prepare_data
%
function [ p ] = preprocess( p )
detStorage = p.detectors(p.scanID).detStorage;
p.detectors(p.scanID).params.image_read_extraargs{end+1} = 'RowFrom';
p.detectors(p.scanID).params.image_read_extraargs{end+1} = detStorage.lim_inf(1);
p.detectors(p.scanID).params.image_read_extraargs{end+1} = 'RowTo';
p.detectors(p.scanID).params.image_read_extraargs{end+1} = detStorage.lim_sup(1);
p.detectors(p.scanID).params.image_read_extraargs{end+1} = 'ColumnFrom';
p.detectors(p.scanID).params.image_read_extraargs{end+1} = detStorage.lim_inf(2);
p.detectors(p.scanID).params.image_read_extraargs{end+1} = 'ColumnTo';
p.detectors(p.scanID).params.image_read_extraargs{end+1} = detStorage.lim_sup(2);
if ~p.prealign_FP
detStorage.read_size = p.asize;
else
detStorage.read_size = p.prealign.asize;
end
end
@@ -0,0 +1,31 @@
%PROCESS_RAW_DATA postprocess functions
% applied to the 4D raw data
%
% ** p p structure
% returns:
% ++ p updated p structure
%
% see also: detector.prep_data.matlab_ps.matlab_ps
function [ p ] = process_raw_data( p )
detStorage = p.detectors(p.scanID).detStorage;
if p.prealign_FP
p = core.FPM.FP_prealign(p);
detStorage.lim_inf = detStorage.ctr-p.asize/2;
detStorage.lim_sup = detStorage.ctr+p.asize/2-1;
end
% sum up data from burst scans
if p.scan.is_cont
detStorage.data = sum(detStorage.data,4);
else
sz = size(detStorage.data);
detStorage.data = reshape(detStorage.data, sz(1), sz(2), []);
end
end
@@ -0,0 +1,91 @@
%BINNING postprocess functions
% apply binning or upsampling on the measured data
%
% ** p p structure
% returns:
% ++ p updated p structure
%
% see also: detector.prep_data.matlab_ps.matlab_ps
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 ] = binning( p )
data = p.detectors(p.scanID).detStorage.data;
fmask = p.detectors(p.scanID).detStorage.fmask;
%% apply binning or upsampling on the measured data
if isfield(p.detector,'binning')&& p.detector.binning
binning = 2^p.detector.binning;
data = utils.binning_2D(data, binning) * binning^2;
fmask =utils.binning_2D(fmask,binning) == 1; % remove all binned pixel where at least one was masked
end
if isfield(p.detector,'upsampling')&& p.detector.upsampling
upsample = 2^p.detector.upsampling;
data = utils.unbinning_2D(data, upsample) / upsample^2;
fmask =utils.unbinning_2D(fmask,upsample) == 1; % remove all binned pixel where at least one was masked
end
p.detectors(p.scanID).detStorage.data = data;
p.detectors(p.scanID).detStorage.fmask = fmask;
end
@@ -0,0 +1,84 @@
%CHECK_BURST check first file for burst scan
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 ] = check_burst( p )
import io.image_read
import utils.compile_x12sa_filename
import utils.get_hdr_val
filefirst = compile_x12sa_filename(p.scan_number(1),0,'BasePath',[p.raw_data_path{1} p.(p.detector.name).basepath_dir],'BaseName',p.detector.data_prefix(1:end-2));
x = image_read(filefirst,'IsFmask',1);
if isempty(x.data)
error(['File not found ' filefirst])
end
cutoff = get_hdr_val(x.header{1}, 'Count_cutoff', ' %d', true);
if p.scan.is_cont||~isempty(p.positions_file)
p.(p.detector.name).mask_saturated_value = cutoff;
else
underscore = strfind(filefirst,'_');
point = strfind(filefirst,'.');
x = image_read([filefirst(1:underscore(end)) '*' filefirst(point(end):end)],'IsFmask',1);
if isempty(x.data)
error(['File not found ' [filefirst(1:underscore(end)) '*' filefirst(point(end):end)] ])
end
burst = size(x.data,3);
display(['Detected burst at each point = ' num2str(burst)])
p.(p.detector.name).mask_saturated_value = cutoff*burst;
end
end
@@ -0,0 +1,123 @@
%GET_CENTER Estimate the center of the diffraction pattern
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 ] = get_center( p )
import utils.verbose
import io.*
detStorage = p.detectors(p.scanID).detStorage;
ctr = detStorage.ctr;
if verbose>2
verbose(3, 'Loading sample image.')
% read sample image
if p.detectors(p.scanID).params.data_stored % if the data should be loaded from disk
if verbose > 2
[p] = p.detectors(p.scanID).params.get_filename(p);
files = detStorage.files;
if numel(files) == 0
error('Did not find any files.')
end
det.params = p.detectors(p.scanID).params;
sample_file = image_read(files{1}, det.params.image_read_extraargs);
end
end
sz = size(sample_file.data(:,:,1));
f = double(sample_file.data(:,:,1));
% Look for center
[~, cy] = max(sum(f.*detStorage.mask,2));
[~, cx] = max(sum(f.*detStorage.mask,1));
ctr_auto = [cy, cx];
if strcmp(detStorage.check_ctr, 'auto')
ctr = ctr_auto;
verbose(3, sprintf('Using center: (%d, %d)', ctr(1), ctr(2)));
elseif strcmp(detStorage.check_ctr, 'inter')
imagesc(log(detStorage.f));
[cx,cy] = getpts;
close(gcf);
ctr = round([cy, cx]);
verbose(3, sprintf('Using center: (%d, %d) - I would have guessed it is (%d, %d)', ctr(1), ctr(2), ctr_auto(1), ctr_auto(2)));
else
verbose(3, sprintf('Using center: (%d, %d) - I would have guessed it is (%d, %d)', ctr(1), ctr(2), ctr_auto(1), ctr_auto(2)));
end
else
verbose(2, sprintf('Using center: (%d, %d)', ctr(1), ctr(2)));
end
detStorage.ctr = ctr;
if ~p.prealign_FP
detStorage.lim_inf = ctr-p.asize/2;
detStorage.lim_sup = ctr+p.asize/2-1;
else
detStorage.lim_inf = ctr-p.prealign.asize/2;
detStorage.lim_sup = ctr+p.prealign.asize/2-1;
end
verbose(2, sprintf('Selected region: (''RowFrom'', %d, ''RowTo'', %d, ''ColumnFrom'', %d, ''ColumnTo'', %d)', detStorage.lim_inf(1), detStorage.lim_sup(1), detStorage.lim_inf(2), detStorage.lim_sup(2)));
if verbose>2
if any(detStorage.lim_inf < 1) || any(detStorage.lim_sup > sz)
error('Array size exceeds limit (according to position of center, should be < %d)', max([1-detStorage.lim_inf, detStorage.lim_sup-sz]));
end
end
end
@@ -0,0 +1,96 @@
%GET_MASK Mask saturated values as defined in the detector template
%
% ** p p structure
%
% returns:
% ++ p p structure
%
% see also: detector.prep_data.matlab_ps.prepare_data
%
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 ] = get_mask( p )
%% Mask saturated values, create 3D fmask if detector mask is not empty
% get pointers and local references
detStorage = p.detectors(p.scanID).detStorage;
detParams = p.detectors(p.scanID).params;
if ~isempty(detParams.mask_saturated_value) || ~isempty(detParams.mask_below_value)
if size(detStorage.mask,3)==1
detStorage.fmask = repmat(detStorage.mask(detStorage.lim_inf(1):detStorage.lim_sup(1), detStorage.lim_inf(2):detStorage.lim_sup(2)),[1 1 size(detStorage.data,3)]);
else
detStorage.fmask = detStorage.mask(detStorage.lim_inf(1):detStorage.lim_sup(1), detStorage.lim_inf(2):detStorage.lim_sup(2),1:size(detStorage.data,3));
end
else
detStorage.fmask = detStorage.mask(detStorage.lim_inf(1):detStorage.lim_sup(1), detStorage.lim_inf(2):detStorage.lim_sup(2),:);
end
if ~isempty(detParams.mask_saturated_value)
detStorage.fmask = (detStorage.data < detParams.mask_saturated_value) .* detStorage.fmask;
end
if ~isempty(detParams.mask_below_value)
detStorage.fmask = (detStorage.data > detParams.mask_below_value) .* detStorage.fmask;
end
%% (Fourier ptycho specific option)
if isfield(detParams, 'filt_pinhole') && ~isempty(detParams.filt_pinhole)
detStorage.fmask = detStorage.fmask.*utils.filt2d_pad(800,round(detParams.filt_pinhole*0.9),round(detParams.filt_pinhole*0.9), 'circ');
end
end
@@ -0,0 +1,196 @@
%LOAD_DATA prepare filenames and load data
% ** p p structure
%
% returns:
% ++ p p structure
%
% see also: detector.prep_data.matlab_ps.prepare_data
%
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 ] = load_data( p )
import utils.find_files
import io.image_read
det.params = p.detectors(p.scanID).params;
detStorage = p.detectors(p.scanID).detStorage;
%% prepare filenames
if isempty(detStorage.files)
[p] = det.params.get_filename(p);
if numel(detStorage.files) == 0
error('Did not find any files.')
end
end
files = detStorage.files;
%% select data loading routine
current_version = version;
ver_str = strsplit(current_version, '.');
ver_num = str2double([ver_str{1} '.' ver_str{2} ver_str{3}]);
if ver_num >= 9.4
c_reader = true;
else
utils.verbose(3, 'Fast data reader is not available for Matlab version %d. Switching to image_read.', ver_num)
c_reader = false;
end
if c_reader && ~ismember(det.params.file_extension, {'h5', 'cbf', 'tiff', 'tif'})
utils.verbose(3, 'Fast data reader is not available for selected file format %s. Switching to image_read.', det.params.file_extension)
c_reader = false;
end
%% load data
if c_reader
% use fast data reader
if strcmpi(det.params.file_extension, 'tif')
det.params.file_extension = 'tiff';
end
if strcmpi(det.params.file_extension, 'tiff')
% keep results consistent with matlab's imread and io.image_read for tiff files
det.params.orientation(1) = ~det.params.orientation(1);
end
% convert PtychoShelves center to raw data center
arg.ctr = detStorage.ctr-1;
sz = det.params.geometry.sz;
if det.params.orientation(3)
arg.ctr(1) = round(sz(1) - arg.ctr(1));
end
if det.params.orientation(2)
arg.ctr(2) = round(sz(2) - arg.ctr(2));
end
if det.params.orientation(1)
arg.ctr = fliplr(arg.ctr);
end
if iscolumn(arg.ctr)
arg.ctr = arg.ctr';
end
% flip XY
arg.ctr = fliplr(arg.ctr);
% create structure for c_reader
arg.data_path = files;
arg.nthreads = p.io.data_nthreads;
arg.precision = p.io.data_precision;
arg.extension = det.params.file_extension;
arg.asize = detStorage.read_size;
arg.data_location = detStorage.h5_group;
assert(all(arg.ctr>0),'Raw data center position has to be positive.')
% load data and permute
utils.verbose(2, 'Loading raw data of scan S%05d.', p.scan_number(p.scanID))
data = io.read_measurement(arg);
data = squeeze(data);
if det.params.orientation(1)
data = permute(data, [2 1 3]);
end
if det.params.orientation(2) && det.params.orientation(3)
data = rot90(data,2); % merge the fliplr and flipup operations
else
if det.params.orientation(2)
data = fliplr(data);
end
if det.params.orientation(3)
data = flipud(data);
end
end
else
if isempty(detStorage.h5_group)
if numel(files)==1
% one directory contains single file
dataaux = image_read(files{1}, det.params.image_read_extraargs);
data = dataaux.data;
else
% multiple files per directory
dataaux = image_read(files, det.params.image_read_extraargs);
data = dataaux.data;
end
else
data = zeros([p.asize numel(detStorage.h5_group)]);
if numel(files)==1
if numel(detStorage.h5_group)==1
% one hdf5 file; one group
dataaux = image_read(files{1}, det.params.image_read_extraargs{:}, 'H5Location', detStorage.h5_group{1});
data = dataaux.data;
else
% one hdf5 file; multiple groups
for ii=1:numel(detStorage.h5_group)
dataaux = image_read(files{1}, det.params.image_read_extraargs{:}, 'H5Location', detStorage.h5_group{ii});
data(:,:,ii) = dataaux.data;
end
end
else
if numel(detStorage.h5_group)==1
% multiple files, single H5 group
dataaux = image_read(files, det.params.image_read_extraargs{:}, 'H5Location', detStorage.h5_group{1});
data = dataaux.data;
else
% multiple files, but different H5 group
for ii=1:numel(detStorage.h5_group)
dataaux = image_read(files{ii}, det.params.image_read_extraargs{:}, 'H5Location', detStorage.h5_group{ii});
data(:,:,ii) = dataaux.data;
end
end
end
end
end
detStorage.data = data;
end
@@ -0,0 +1,75 @@
%MASK_GEOMETRY crop mask to fit defined readout geometries
% if no geometry is specified, the full mask is used
% ** p p structure
%
% returns:
% ++ p p structure
%
% see also: detector.prep_data.matlab_ps.prepare_data
%
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 ] = mask_geometry( p )
scanID = p.scanID;
detStorage = p.detectors(scanID).detStorage;
if isfield(p.detectors(scanID).params, 'geometry') && ~isempty(p.detectors(scanID).params.geometry.mask)
detStorage.mask = detStorage.mask(p.detectors(ii).params.geometry.mask{1},p.detectors(ii).params.geometries.mask{2},:);
end
end
@@ -0,0 +1,101 @@
%MATLAB_PS - Matlab data preparator
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 = matlab_ps(p)
import utils.*
%% call prepare data function
for ii=1:length(p.scan_number)
p.scanID = ii;
[p] = detector.prep_data.matlab_ps.prepare_data(p);
end
%% combine data structures
data = single([]);
fmask = logical([]);
for ii=1:length(p.scan_number)
data = cat(3,data,p.detectors(ii).detStorage.data);
if size(p.detectors(ii).detStorage.fmask,3) > 1
fmask = cat(3,fmask,logical(round(p.detectors(ii).detStorage.fmask)));
else
fmask = cat(3,fmask,repmat(p.detectors(ii).detStorage.fmask,[1 1 size(p.detectors(ii).detStorage.data,3)]));
end
p.detectors(ii).detStorage.fmask = []; % save memory
p.detectors(ii).detStorage.data = [];
end
for ii = 1:p.numobjs
p.object_size(ii,:) = [size(p.object{ii},1),size(p.object{ii},2)];
end
if (isfield(p.detector,'binning')&& p.detector.binning) || (isfield(p.detector,'upsampling')&& p.detector.upsampling)
p = core.apply_binning(p, 2^(p.detector.binning - p.detector.upsampling)); % modify the p structure after binning
end
p = detector.prep_data.matlab_ps.prep_data_matlab(p, data, fmask);
% Compare number of points and diffraction patterns
num_difpat = size(p.fmag,3);
verbose(3, 'Number of probe positions: %d', sum(p.numpts));
verbose(3, 'Number of diffraction patterns : %d', num_difpat);
if num_difpat ~= sum(p.numpts)
error('Number of probe positions (%d) inconsistent with number of diffraction patterns (%d)', sum(p.numpts), num_difpat);
end
end
@@ -0,0 +1,73 @@
%POSTPROCESS postprocess functions
% applied to the 4D raw data
%
% ** p p structure
% returns:
% ++ p updated p structure
%
% see also: detector.prep_data.matlab_ps.matlab_ps
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 ] = postprocess( p )
detStorage = p.detectors(p.scanID).detStorage;
%% apply some custom correction such as background subtraction on detStorage.data
end
@@ -0,0 +1,220 @@
%PREPARE_DATA_MATLAB prepares and normalizes data for matlab engines
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 ] = prep_data_matlab( p, data, fmask )
import utils.pshift
import utils.verbose
import utils.get_option
import math.fftshift_2D
scanfirstindex = [1 cumsum(p.numpts)+1]; % First index for scan number
% Region of interest [xmin xmax ymin ymax]
% Warning Not implemented for shared scans
% Need to update p.numpts, p.positions, data, fmask, indices
if isfield(p, 'scan') && isfield(p.scan, 'roi') && ~isempty(p.scan.roi)
% Convert to p.positions centered on the object
if p.share_object
positions_centered = p.positions - p.object_size(1,:)/2 + p.asize(:)/2;
else
for ii = 1:p.numscans
positions_centered(p.scanidxs{ii},:) = p.positions(p.scanidxs{ii},:) - p.object_size(ii,:)/2;
end
end
xmin = p.scan.roi(1)/p.dx_spec(2);
xmax = p.scan.roi(2)/p.dx_spec(2);
ymin = p.scan.roi(3)/p.dx_spec(1);
ymax = p.scan.roi(4)/p.dx_spec(1);
% Quick check
if (xmin>xmax)
error('ROI is empty, xmax<xmin')
elseif (ymin>ymax)
error('ROI is empty, ymax<ymin')
end
% Do the comparison and update accordingly [xmin xmax ymin ymax]
whichtokeep = find( (positions_centered(:,1) > ymin) & ...
(positions_centered(:,1)< ymax) & ...
(positions_centered(:,2) > xmin) & ...
(positions_centered(:,2) < xmax) );
% update p.numpts, positions, data, fmask, indices
data = data(:,:,whichtokeep);
fmask = fmask(:,:,whichtokeep);
p.positions = p.positions(whichtokeep,:);
for ii = 1:p.numscans
% indaux = find(whichtokeep<scanfirstindex(ii+1),'last'); % Finds the last index of scan ii in the new variables
indaux = find((whichtokeep>=scanfirstindex(ii))&(whichtokeep<scanfirstindex(ii+1))); % Finds indices of scan ii in the new variables
if isempty(indaux)
error('ROI: Scan %s has no points in the ROI. Change the ROI or remove this scan from the scan list',p.scan_str{ii})
end
p.numpts(ii) = numel(indaux);
end
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
verbose(2, 'Region of interest reduced number of points from %d to %d', sum(p.numpts_orig), sum(p.numpts));
% Redo a convenient offset
p.positions = p.positions - min(p.positions) + 1;
% Recompute object sizes
p = update_object_size(p);
end
% Skip some data point (for testing reduced dose)
if isfield(p, 'skip_points')
if ~isempty(p.skip_points) && p.skip_points>1
offset = mod(p.scan_number, p.skip_points);
%offset = mod([0 1 2], p.skip_points);
whichtokeep = [1+offset(1):p.skip_points:p.numpts(1)];
for idx = 2:length(p.numpts)
last_idx = sum(p.numpts(1:idx-1));
whichtokeep = [whichtokeep , (last_idx+1+offset(idx)):p.skip_points:(last_idx+p.numpts(idx))];
end
data = data(:,:,whichtokeep);
fmask = fmask(:,:,whichtokeep);
p.positions = p.positions(whichtokeep,:);
for ii = 1:p.numscans
% indaux = find(whichtokeep<scanfirstindex(ii+1),'last'); % Finds the last index of scan ii in the new variables
indaux = find((whichtokeep>=scanfirstindex(ii))&(whichtokeep<scanfirstindex(ii+1))); % Finds indices of scan ii in the new variables
if isempty(indaux)
error('ROI: Scan %s has no points in the ROI. Change the ROI or remove this scan from the scan list',p.scan_str{ii})
end
p.numpts(ii) = numel(indaux);
end
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
verbose(2, 'Region of interest reduced number of points from %d to %d', sum(p.numpts_orig), sum(p.numpts));
% Recompute object sizes
if p.share_object
p.object_size = p.asize + max(p.positions,[],1);
verbose(3, 'Computed object size: %d x %d', p.object_size(1), p.object_size(2));
else
for ii = 1:p.numscans
p.object_size(ii,:) = p.asize + max(p.positions(p.scanindexrange(ii,1):p.scanindexrange(ii,2),:),[],1);
verbose(3, 'Computed object size: %d x %d', p.object_size(ii,1), p.object_size(ii,2));
end
end
end
end
% % padding
% if any(datasize ~= p.asize)
% newdata = zeros([p.asize, num_difpat]);
% offset = floor(.5*(p.asize-datasize));
% newdata(offset(1) + (1:datasize(1)), offset(2) + (1:datasize(2)), :) = data;
% data = newdata;
% clear newdata
% newfmask = ones([p.asize, size(fmask,3)]);
% newfmask(offset(1) + (1:datasize(1)), offset(2) + (1:datasize(2)), :) = fmask;
% fmask = newfmask;
% clear newfmask
% end
% 'auto_center_data' option is useful if detector shifts provided in
% template cannot be trusted, ie for more than 2 joined scans
if get_option(p,'auto_center_data') && ~get_option(p,'get_artificial_data')
for i = 1:p.numscans
ind = p.scanidxs{i};
[x,y] = math.center(mean(data(:,:,ind) .* fmask(:,:,ind),3));
verbose(2,'Auto-shifting diffraction patterns by %i %i px', round(x), round(y))
data(:,:,ind) = utils.imshift_fast(data(:,:,ind), x, y, [], 'nearest');
if size(fmask,3) == size(data,3)
fmask(:,:,ind) = utils.imshift_fast(fmask(:,:,ind), x, y, [], 'nearest');
elseif p.numscans == 1
fmask = utils.imshift_fast(fmask, x, y, [], 'nearest');
else
error('Not implemented mask shifting option')
end
end
end
p.fmask_per_scan = ndims(fmask) == 3;
% Prepare Fourier projections
% normalization ignores valid mask - should modify
for ii=1:p.numscans
p.max_sum(ii) = max(sum(sum(data(:,:,p.scanidxs{ii}),1),2),[],3);
end
max_power = max(p.max_sum) / prod(p.asize);
p.renorm = sqrt(1/max_power);
p.Nphot = sum(data(:).*fmask(:)); % Number of photons for regularization normalization (ML optimization)
% store mask pre-fftshifted
p.fmask = fftshift_2D(fmask);
clear fmask
% precalculate modulus of data, normalize and fftshift
p.fmag = fftshift_2D(sqrt(data)) * p.renorm;
end
@@ -0,0 +1,149 @@
%PREPARE_DATA prepare the raw data for the ptychographic reconstruction
%
% ** p p structure
%
% returns:
% ++ p p structure
%
% *Note:*
% All (default) functions are located in +detector/+prep_data/+matlab_ps. If You want
% to add a new detector, please create a new package directory
% (+detector_name) with a parameter file detector_name.m. Functions in a
% package detectory directory will overload similar functions in the default directory.
%
% see also: detector.prep_data.matlab_ps.matlab_ps
%
%
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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_data( p )
import utils.*
import io.image_read
verbose(1, 'Preparing data using matlab data preparation.')
%% initialize detector
scanID = p.scanID;
detStorage = p.detectors(scanID).detStorage;
if size(p.ctr,1) == 1
center = p.ctr;
else
center = p.ctr(scanID,:);
end
check_ctr = 'auto';
if ~isempty(center)
check_ctr = 'inter';
if ~strcmp(center, 'inter')
detStorage.ctr = center;
verbose(2,['Using supplied center: ', num2str(detStorage.ctr)]);
check_ctr = 'no';
end
end
detStorage.check_ctr = check_ctr;
%% load mask
if isfield(p.detectors(scanID).params, 'mask') && ~isempty(p.detectors(scanID).params.mask)
load(p.detectors(scanID).params.mask);
detStorage.mask = logical(mask);
elseif p.detectors(scanID).params.data_stored
detStorage.mask = ones(p.detectors(scanID).params.geometry.sz, 'logical');
else
detStorage.mask = logical([]);
end
%% crop mask to readout geometry (if necessary)
[p] = p.detectors(scanID).funcs.mask_geometry(p);
%% get center and readout size
[p] = p.detectors(scanID).funcs.get_center(p);
%% preprocess
[p] = p.detectors(scanID).funcs.preprocess(p);
%% load data
[p] = p.detectors(scanID).funcs.load_data(p);
%% process raw data
[p] = p.detectors(scanID).funcs.process_raw_data(p);
%% mask saturated values
[p] = p.detectors(scanID).funcs.get_mask(p);
%% apply binning on the measured data / mask
[p] = p.detectors(scanID).funcs.binning(p);
%% final step postprocessing, e.g. background subtraction
[p] = p.detectors(scanID).funcs.postprocess(p);
end
@@ -0,0 +1,88 @@
%PREPROCESS preprocess functions
% e.g. select area before reading from disk
%
% ** p p structure
%
% returns:
% ++ p p structure
%
% see also: detector.prep_data.matlab_ps.prepare_data
%
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 ] = preprocess( p )
detStorage = p.detectors(p.scanID).detStorage;
p.detectors(p.scanID).params.image_read_extraargs{end+1} = 'RowFrom';
p.detectors(p.scanID).params.image_read_extraargs{end+1} = detStorage.lim_inf(1);
p.detectors(p.scanID).params.image_read_extraargs{end+1} = 'RowTo';
p.detectors(p.scanID).params.image_read_extraargs{end+1} = detStorage.lim_sup(1);
p.detectors(p.scanID).params.image_read_extraargs{end+1} = 'ColumnFrom';
p.detectors(p.scanID).params.image_read_extraargs{end+1} = detStorage.lim_inf(2);
p.detectors(p.scanID).params.image_read_extraargs{end+1} = 'ColumnTo';
p.detectors(p.scanID).params.image_read_extraargs{end+1} = detStorage.lim_sup(2);
if ~p.prealign_FP
detStorage.read_size = p.asize;
else
detStorage.read_size = p.prealign.asize;
end
end
@@ -0,0 +1,84 @@
%PROCESS_RAW_DATA postprocess functions
% applied to the 4D raw data
%
% ** p p structure
% returns:
% ++ p updated p structure
%
% see also: detector.prep_data.matlab_ps.matlab_ps
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 ] = process_raw_data( p )
detStorage = p.detectors(p.scanID).detStorage;
if p.prealign_FP
p = core.FPM.FP_prealign(p);
detStorage.lim_inf = detStorage.ctr-p.asize/2;
detStorage.lim_sup = detStorage.ctr+p.asize/2-1;
end
% sum up data from burst scans
if p.scan.is_cont
detStorage.data = sum(detStorage.data,4);
else
sz = size(detStorage.data);
detStorage.data = reshape(detStorage.data, sz(1), sz(2), []);
end
end
@@ -0,0 +1,65 @@
%GET_DIR_PATH define directory structure.
% default scheme for data (scan 68) taken at cSAXS: S00000-00999/S00068/
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 data_path = get_dir_path(p, ii)
data_path = [p.raw_data_path{ii} p.detectors(ii).params.basepath_dir p.detectors(ii).params.read_path(p.scan_number(ii))];
end
@@ -0,0 +1,141 @@
%UPDATE_DEFAULTS update parameters with default values that are crucial for
% a further processing of the data and look for overloaded functions
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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_defaults( p )
import utils.verbose
%% update fields
p = check_fields(p, 'mask_saturated_value', []);
p = check_fields(p, 'mask_below_value', []);
p = check_fields(p, 'read_path_format', 'S%05d-%05d/S%05d/');
%% fill the image_read_extraargs list with default parameters for image_read function
for ii = 1:length(p.detectors)
p.detectors(ii).params.image_read_extraargs(end+(1:6)) =...
{'IsFmask', false, ...
'Orientation', p.detectors(ii).params.orientation, ...
'OrientByExtension', 0};
end
% check if a different detector mask has been specified in template_ptycho
if ~isempty(p.io.default_mask_file)
p.detectors(p.detID).params.mask = p.io.default_mask_file;
end
%% update all default functions
func_path = fullfile(p.ptycho_matlab_path, '+detector', '+prep_data');
if ~exist(func_path, 'dir')
error('Could not find detector functions in %s', func_path)
end
priv = dir([func_path]);
for ii=1:size(priv,1)
if priv(ii).name(1)=='.'
continue
end
if priv(ii).isdir
%subdir search
if strcmpi(priv(ii).name, ['+' p.prepare.data_preparator])
func_path_sub = fullfile(p.ptycho_matlab_path, '+detector', '+prep_data', ['+' p.prepare.data_preparator]);
priv_sub = dir([func_path_sub]);
for jj=1:size(priv_sub,1)
[~, fname, ext] = fileparts(fullfile(priv_sub(jj).folder, priv_sub(jj).name));
if strcmpi(ext, '.m')
p = detector.prep_data.update_funcs(p, fname, ext);
end
end
else
end
else
[~, fname, ext] = fileparts(fullfile(priv(ii).folder, priv(ii).name));
if strcmpi(ext, '.m')
p = detector.prep_data.update_funcs(p, fname, ext);
end
end
end
end
function [p] = check_fields(p, field, val, varargin)
import utils.verbose
if ~isfield(p.detectors(p.detID).params,field)
verbose(3, [field ' not defined for ' p.detectors(p.detID).name '. Using default value.'])
p.detectors(p.detID).params.(field) = val;
end
if nargin > 3
is_func = varargin{1};
else
is_func = 0;
end
if is_func
p = update_funcs(p, field);
end
end
@@ -0,0 +1,72 @@
%UPDATE_FUNCS Update prepare data functions with overloaded functions from
%the detector directory
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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_funcs( p, func, ext )
if exist(fullfile(p.ptycho_matlab_path, '+detector', ['+' p.detector.name], [func ext]), 'file')
p.detectors(p.detID).funcs.(func) = str2func(['detector.' p.detector.name '.' func]);
else
if exist(fullfile(p.ptycho_matlab_path, '+detector', '+prep_data', [func ext]), 'file')
p.detectors(p.detID).funcs.(func) = str2func(['detector.prep_data.' func]);
else
p.detectors(p.detID).funcs.(func) = str2func(['detector.prep_data.' p.prepare.data_preparator '.' func]);
end
end
end
+122
View File
@@ -0,0 +1,122 @@
%CREATE_OBJECT create object for artificial scans
% select object with p.simulation.dataset in your simulation template
%
% [obj,ref_index] = create_object(p)
%
% Inputs:
% ** p - p-struct
% *Outputs*
% ++ obj - generate real-valued positive image
% ++ ref_index - refractive index of the simulated sample
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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,ref_index] = create_object(p)
import utils.crop_pad
import utils.get_ref_index
%% get refractive index
if ~isfield(p.simulation, 'ref_index')
for ii = 1:size(p.simulation.material,2)
ref = get_ref_index(p.simulation.material{ii}, p.energy, p.simulation.material_density(ii));
delta(ii) = ref(2);
beta(ii) = ref(3);
end
else
delta = -real(p.simulation.ref_index-1);
beta = -imag(p.simulation.ref_index);
end
ref_index = 1 - delta - 1i*beta;
%% load object
img_path = fullfile(p.ptycho_matlab_path, 'utils', 'imgs');
for jj = 1:p.numscans
Npix = p.object_size(min(jj,end),:);
if isstr(p.simulation.dataset{jj})
% apply rotation of provided
if isfield(p, 'rotation_angle') && ~isempty(p.rotation_angle)
rotate = p.rotation_angle(min(end,jj));
elseif isfield(p.simulation, 'rotation_angle') && ~isempty(p.simulation.rotation_angle)
rotate = p.simulation.rotation_angle(min(end,jj));
else
rotate = [];
end
obj{jj}(:,:,1,:) = generate_virtual_object(p, p.simulation.dataset{jj},img_path, Npix , rotate);
else
for ii = 1:length(p.simulation.dataset{jj})
obj{jj}(:,:,1,ii) = generate_virtual_object(p, p.simulation.dataset{jj}(ii),img_path, Npix,[]);
end
end
obj{jj} = rot90(exp(1i*(2*pi/p.lambda)*(1i*beta-delta)*(1-obj{jj})*p.simulation.objheight / size(obj{jj},4)),2);
% remove offset caused by positioning padding due to variable
% object_size, if p.positions_pad == 0 , it will have no effect
% the missing values will be filled by fully transparent value
if any(p.positions_pad)
obj{jj} = reshape(utils.imshift_fast(obj{jj}, p.positions_pad(1),p.positions_pad(2),[],'nearest',1), size(obj{jj}));
end
% emulate 0 vs 180 deg scan
if ~isempty(p.simulation.flip_objects_180deg) && p.simulation.flip_objects_180deg(min(end,jj)) == true
obj{jj} = fliplr(obj{jj});
obj{jj} = obj{jj}(:,:,1,end:-1:1);
end
end
end
+67
View File
@@ -0,0 +1,67 @@
%GET_CENTER Estimate the center of the diffraction pattern
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 ] = get_center( p )
import utils.verbose
detStorage = p.detectors(p.scanID).detStorage;
detStorage.lim_inf = [1,1];
detStorage.lim_sup = p.asize;
end
+290
View File
@@ -0,0 +1,290 @@
%LOAD_DATA prepare filenames and load data
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 ] = load_data( p )
import math.*
import utils.*
detStorage = p.detectors(p.scanID).detStorage;
%% VIRTUAL LOADING FUNCTION THAT GENERATES ARTIFICIAL DATA
%% adjust positions , apply affine corrections from template and distorsion from p.simulation.affine_matrix
if isempty(p.affine_matrix)
p.affine_matrix = [1,0;0,1];
end
if ~isfield(p.simulation, 'affine_matrix') || isempty(p.simulation.affine_matrix)
p.simulation.affine_matrix = [1,0;0,1];
end
%% calculate the positions
positions_0 = p.positions; % store the p.positions and return the values at the end of this function
tmp = p;
tmp.affine_matrix = -p.simulation.affine_matrix * inv(p.affine_matrix); % first remove the already applied affine matrix and then apply affine matrix from simulation
for ii = 1:p.numscans
% add there a small random global offset for the positions
rng(p.scan_number(ii)) % reset randomization to guarantee repeatability
offset = 0.3; % times average step
avg_step = sqrt(prod(max(tmp.positions_real(p.scanidxs{ii},:)) - min(tmp.positions_real(p.scanidxs{ii},:))) / p.numpts(ii));
tmp.positions_real(p.scanidxs{ii},:) = tmp.positions_real(p.scanidxs{ii},:) + randn(1,2) * avg_step * offset;
end
% standard farfield ptychography
if check_option(p.simulation, 'z') && strcmpi(p.prop_regime, 'farfield')
tmp.dx_spec = tmp.lambda*tmp.simulation.z ./ (p.asize*p.ds); % resolution in the specimen plane
tmp.dx_spec = tmp.dx_spec ./ cosd(tmp.sample_rotation_angles(1:2)); % account for a tilted sample ptychography
end
tmp.share_object_ID = ones(p.numscans,1);
tmp = core.ptycho_adjust_positions( tmp );
if p.simulation.position_uncertainty > 0
tmp.positions = tmp.positions + randn(sum(p.numpts),2)*p.simulation.position_uncertainty*mean(p.dx_spec);
utils.verbose(3, 'Included position errors, std=%3.2gnm , %3.2gpx', p.simulation.position_uncertainty*1e9, p.simulation.position_uncertainty / mean(p.dx_spec) );
end
% Extra offset of positions given in simulation -> subtract padding
% provided in p structure and instead add padding from simulation structure
p.simulation.positions = tmp.positions;
p.simulation.positions_real = tmp.positions_real;
%% create object
if ~check_option(p.simulation, 'positions_pad')
p.simulation.positions_pad = [0,0];
end
% Compute object sizes
if p.share_object
p.object_size = ceil(p.asize + max(p.simulation.positions) + p.positions_pad+ p.simulation.positions_pad(1,:));
else
for ii = 1:p.numscans
p.object_size(ii,:) = ceil(p.asize + max(p.simulation.positions(p.scanidxs{ii},:)) + p.positions_pad + p.simulation.positions_pad(min(end,ii),:));
end
end
% Generate object using parameters from artificial data template
[p.simulation.obj, p.simulation.ref_index] = detector.virtual.create_object(p);
if get_option(p, 'fourier_ptycho')
warning('FIXME')
keyboard
p = fourier_ptycho_data(p);
end
p.simulation.probe = p.probes;
if ~p.simulation.apply_sub_px_shifts
p.positions = round(p.positions);
p.simulation.positions = round(p.simulation.positions);
end
p.positions = p.simulation.positions;
if p.simulation.sample_rotation_angles
% modify the scanning positions to account for the tilted sample geometry
p.positions = p.positions .* cosd(p.simulation.sample_rotation_angles([1,2]));
end
sub_px_shift = p.positions-round(p.positions);
if any(p.simulation.sample_rotation_angles)
% get propagators to the tilted plane or plane rotated around beam axis
[fwd_propag_fun, back_propag_fun] = get_tilted_plane_propagators(p.probes, p.simulation.sample_rotation_angles,...
p.lambda, p.dx_spec);
end
%% calculate views
Nlayers = size(p.simulation.obj{p.scanID},4);
if p.share_object
obnum = 1;
else
obnum = p.scanID;
end
verbose(0, 'Creating artificial dataset')
% auxiliar windows for subpixel shifting
win = 0.1+0.9*tukeywin(p.asize(1),0.05) .* tukeywin(p.asize(2), 0.05)';
iter = zeros([p.asize, length(p.scanidxs{obnum}), p.probe_modes*p.object_modes], 'like', p.simulation.obj{p.scanID});
for prmode = 1:p.probe_modes
for obmode = 1:p.object_modes
p.simulation.obj{obnum} = single(p.simulation.obj{obnum});
iter_mode_ind = prmode+(obmode-1)*p.probe_modes;
probe = p.probes(:,:,1,prmode);
if check_option(p, 'use_gpu')
probe = utils.Garray(probe);
end
if strcmpi(p.prop_regime, 'farfield')
% in farfield is the probe and object shift equivalent in nearfield not anymore !!
probe = imshift_fft(probe,sub_px_shift(p.scanidxs{p.scanID},[2,1]));
end
if Nlayers > 1 && p.simulation.thickness > 0
% assume that the provided probe is in center plane of the sample
probe = prop_free_nf(probe, p.lambda, -p.simulation.thickness/2, p.dx_spec(1));
end
if any(p.simulation.sample_rotation_angles(1:2))
% propagate the probe to the tilted plane
probe = fwd_propag_fun(probe);
end
if p.simulation.thickness == 0
% thin object
obj = prod(p.simulation.obj{obnum}(:,:,obmode,:),4);
else
obj = p.simulation.obj{obnum}(:,:,obmode,:);
end
obj_proj = core.get_projections(p, obj(:,:,obmode,1) , p.scanID);
proj = probe .* obj_proj;
if p.simulation.thickness > 0
% thick object
[~,H] = prop_free_nf(probe, p.lambda, p.simulation.thickness / (Nlayers-1), p.dx_spec);
for layer = 2:Nlayers
if Nlayers > 2 && utils.verbose >= 0; utils.progressbar(layer-1, Nlayers-1); end
proj = ifft2(H.*fft2(proj));
obj_proj = core.get_projections(p, p.simulation.obj{obnum}(:,:,obmode,layer), p.scanID, obj_proj);
if strcmpi(p.prop_regime, 'nearfield')
% in farfield is the probe and object shift equivalent in nearfield not anymore !!
obj_proj = imshift_fft(obj_proj .* win,-sub_px_shift(p.scanidxs{p.scanID},[2,1])) ./ win;
end
proj = proj .* obj_proj;
end
else
proj = bsxfun(@times, probe, obj_proj);
end
iter(:,:,:,iter_mode_ind) = proj;
end
end
if any(p.simulation.sample_rotation_angles)
% perform propagation back to the plane parallel with detector
iter = back_propag_fun(iter);
end
%% create data
if check_option(p, 'prop_regime', 'nearfield')
diffraction = abs(prop_free_nf(iter, p.lambda, p.z, p.dx_spec)).^2;
elseif p.simulation.prop_from_focus
% calculate intensities
diffraction = abs(prop_free_nf(ifftshift_2D(fft2(fftshift_2D(iter))), p.lambda, -p.simulation.prop_from_focus, p.ds)).^2;
else% standard farfield propagation
diffraction = fftshift_2D(abs(fft2(iter)).^2);
end
diffraction = sum(diffraction,4);
%% add incoherence-like blur
if p.simulation.incoherence_blur
diffraction = utils.imgaussfilt3_conv(diffraction, [p.simulation.incoherence_blur,p.simulation.incoherence_blur,0]);
verbose(3,'- Adding incoherence blur %3.2gpx', p.simulation.incoherence_blur);
end
%% add noise
if ~isinf(p.simulation.photons_per_pixel)
illum_sum = sum(diffraction(:));
% calculate the total number of photons per scan
total_dose = p.simulation.photons_per_pixel * prod(p.object_size-p.asize);
% calculate correction of the intensity
corr_ratio = sum(total_dose) / illum_sum;
% set identical number of photons to diffr. pattern
diffraction = diffraction * corr_ratio;
p.simulation.probe = p.simulation.probe * sqrt(mean(corr_ratio));
verbose(3,'- Adding Poisson noise');
% add noise, it is some faster approximation
diffraction = randpoisson(diffraction);
else
% keep the values close to real X-ray data
max_value = 1e3;
corr_ratio = max_value / max(diffraction(:));
diffraction = diffraction * corr_ratio;
p.simulation.probe = p.simulation.probe * sqrt(corr_ratio);
verbose(3,'- No noise added');
end
if check_option(p, 'use_gpu')
diffraction = gather(diffraction);
p.simulation.probe = gather(p.simulation.probe);
for ii = 1:p.numscans
p.simulation.obj{ii} = gather(p.simulation.obj{ii});
end
end
detStorage.data = double(diffraction);
detStorage.mask = true(size(diffraction));
p.positions = positions_0;
end
+60
View File
@@ -0,0 +1,60 @@
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 ] = preprocess( p )
end
@@ -0,0 +1,83 @@
%FOURIER_PTYCHO_DATA
% Prepare and adjust artificial data for Fourier Ptychography
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 [ sim ] = fourier_ptycho_data( sim )
import utils.*
%% first create the illumination of the sample in real-space
sz = size(sim.simulation.obj{1});
objpix = sim.lambda*sim.z_lens./(sim.asize.*sim.dx_spec);
illum_dim = round(sim.simulation.illumination/2./objpix);
maxdim = round(max([sz illum_dim]));
if maxdim == max(illum_dim)
maxdim = round(maxdim *1.1);
end
aperture = prop_free_nf(fftshift(filt2d_pad(maxdim, illum_dim(1), illum_dim(1)-3, 'circ')), sim.lambda, 1e-3, objpix);
illum = crop_pad(aperture, sz);
%% propagate to the objective lens
if sim.simulation.prop_from_focus
sim.simulation.obj{1} = fftshift(prop_free_nf(fft2(ifftshift(sim.simulation.obj{1} .* illum)),sim.lambda, sim.prop_from_focus, sim.dx_spec))./sqrt(sz(1)*sz(2));
else
sim.simulation.obj{1} = fftshift(fft2(ifftshift(sim.simulation.obj{1} .* illum)))./sqrt(sz(1)*sz(2));
end
end
@@ -0,0 +1,216 @@
% [object] = generate_virtual_object(dataset, img_path, Npix, angle)
% create a virtual thickness map that can be used to generate test object
% for ptycho
% Inputs:
% dataset - number or string with name
% img_path - path to folder with source images
% Npix - size of the output ptrojections
% angle - rotation of the 3D object
% Outputs:
% object - normalized thickness map
% Publications most relevant to the Difference-Map implementation
% + P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer,
% "High-Resolution Scanning X-ray Diffraction Microscopy," Science 321, 379-382 (2008)
% + P. Thibault, M. Dierolf, O. Bunk, A. Menzel, F. Pfeiffer,
% "Probe retrieval in ptychographic coherent diffractive imaging,"
% Ultramicroscopy 109, 338343 (2009)
%
% Publications most relevant to the Maximum Likelihood refinement
% + M. Guizar-Sicairos and J. R. Fienup, "Phase retrieval with transverse
% translation diversity: a nonlinear optimization approach," Opt. Express 16, 7264-7278 (2008)
% + P. Thibault and M. Guizar-Sicairos, "Maximum-likelihood refinement for
% coherent diffractive imaging," New J. Phys. 14, 063004 (2012).
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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] = generate_virtual_object(p, dataset, img_path, Npix, angle)
%% preload some artificial object
switch dataset
case 1
%% MONA LISA
object = imread(fullfile(img_path, 'ML512.jpg'));
object = double(object(:,:,1));
object = double(object)./double(max(object(:)));
case 2
%% autumn
object = imread('autumn.tif');
object = double(object(:,:,1));
object = double(object)./double(max(object(:)));
case 3
%% camera man
object = imread('autumn.tif');
object = double(object(:,:,1));
object = double(object)./double(max(object(:)));
case 4
%% test pattern
object = imread('testpat1.png');
object = double(object(:,:,1));
object = double(object)./double(max(object(:)));
case 5
%% USAF target
object = 255-imread(fullfile(img_path, 'USAF-1951.png'));
object = single(object(:,:,1) < 128);
case 6
%% MANDRIL
object = imread(fullfile(img_path, 'mandrill.png'));
object = double(object)./double(max(object(:)));
case 7
%% CHIP
object = imread(fullfile(img_path, 'chip_phantom.png'));
object = single(object(:,:,1)) / 255;
case 8
%% Snellen chart
object = imread(fullfile(img_path, 'Snellen_chart.png'));
object = single(object(1:2:end,1:2:end,1) > 50);
object = utils.crop_pad(object, size(object)+10,1);
case '3D_phantom'
%% create a phantom that looks like a porous material and henerate projections from it,
import utils.*
import math.*
% Nx = ceil(Npix(1)/128)*128;
% Nz = ceil(Npix(2)/128)*128;
% Ny = Nx;
Nx = 512;
Ny = 512;
Nz = 512;
if check_option(p, 'use_gpu')
dtype = gpuArray.ones(1,'single');
verbose(0,'Processing phantom on GPU')
else
dtype = ones(1,'single');
end
phantom_filename = fullfile(img_path, sprintf('glass_data_%ipx.mat', Nx));
try
d = load(phantom_filename);
volData = single(d.volData)/255; % convert from uint8 to singles
[Nx, Ny, Nlayers] = size(volData);
catch
verbose(0, 'Cached phantom not availible in %s', phantom_filename)
disp('Creating phantom')
% create a phantom that looks like a porous material
rng default
volData = randn([Nx, Ny, Nz],'like', dtype);
utils.progressbar(1,6);
volData = imgaussfilt3_fft(volData, 2);
utils.progressbar(2, 6);
volData = volData / max(abs(volData(:)));
utils.progressbar(3,6);
volData = single(volData <= 0);
utils.progressbar(5, 6);
% volData = volData*0.2 + 0.8; % add some background
% store as uint8 to save space
volData = uint8(volData/max(volData(:)) * 255);
if isa(volData, 'gpuArray')
volData = gather(volData);
end
try; save('-v6', phantom_filename, 'volData'); end
volData = single(volData)/255;
utils.progressbar(6, 6);
end
if ~isempty(angle)
verbose(0,'Phantom volume is rotated by %6.3g degrees', angle)
if check_option(p, 'use_gpu')
volData = gpuArray(volData);
end
% apply circular mask
xgrid = -Nx/2+1 : Nx/2;
ygrid = -Ny/2+1 : Ny/2;
[X,Y] = meshgrid(ygrid, xgrid);
air_gap = 200; % pixels
volData = volData .* imgaussfilt(single(X.^2+Y.^2 < (Nx/2 - air_gap/2)^2), 3);
% rotate the volume using FFT (volData is real valued at this point)
volData = utils.imrotate_ax_fft(volData, angle, 3);
volData = max(0,min(volData,1));
end
object = 1-permute(volData, [3,1,2]);
otherwise
error('Sorry, sample %d is missing. Feel free to add it!', dataset)
end
if size(object,3) == 1
% in case of a simple 2D object replicate the pattern to avoid void
% space around
object = repmat(object, 5,5);
end
%% adjust the object to the requested size and surround by empty space
object = utils.crop_pad(object, Npix, mean(mean(mean(object(:,[1,end],:)))));
object = reshape(object,size(object,1), size(object,2),1,size(object,3));
end
@@ -0,0 +1 @@
function out=randpoisson(inarray,thresh);% function out=randpoisson(inarray,thresh);% outputs an array of poisson-distributed numbers with mean equal to inarray% For inarray values above the threshold thresh (default=32),% use a quick-and-dirty version of the gaussian method,% but with negatives clipped to zero% J.R. Fienup 10/22/99if nargin < 1, error('Requires at least one input argument.'); endif exist('thresh')~=1, thresh=32; endout=inarray;% High-count pixels - use Gaussian approachgtthresh=find(inarray>thresh);if ~isempty(gtthresh), out(gtthresh)=inarray(gtthresh) + sqrt(inarray(gtthresh)).*randn(size(inarray(gtthresh))); out(gtthresh)=round(max(0,out(gtthresh)));end% Low-count pixels - this goes into the counting-experiment methodltthresh=find(inarray<=thresh);if ~isempty(ltthresh) lamda=inarray(ltthresh); % segregate low-value pixels to speed computation % Now dealing with a 1-D column vector that will merge into n-D array out later on %Initialize r to zero. r = zeros(size(lamda)); % output array for ltthresh pixels p = zeros(size(lamda)); ind = true(size(lamda)); while any(ind) p(ind) = p(ind) - log(rand(length(ind),1)); % note, do repeatedly calculate over all of lamda ind = find(p < lamda); % Q: does this k index over r(ind) = r(ind) + 1; end % Return NaN if lamda is not positive -- to do this, un-comment what follows (gives zero now). % tmp = NaN;% if any(any(any(lamda <= 0)));% if prod(size(lamda) == 1), % i.e., a single pixel?% r = tmp(ones(size(lamda)));% else% k = find(lamda <= 0);% r(k) = tmp(ones(size(k)));% end% end out(ltthresh)=r; % Merge low-value-pixel results with large-value-pixel results end; % of if length(ltthresh)>0end
+78
View File
@@ -0,0 +1,78 @@
% Settings of a virtual detector that creates artificial data
% This file is called if you specify p.detector = 'virtual'.
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 [ det ] = virtual( p )
%% parameter
if ~isfield(p.simulation, 'det_pixel_size')
det.pixel_size = 75e-6; % detector pixel size
utils.verbose(2, 'Setting default pixel size for virtual detector = %.2um', det.pixel_size)
else
det.pixel_size = p.simulation.det_pixel_size; % detector pixel size
end
det.geometries = [];
det.lambda = 1.2398e-9/p.energy; % wavelength
det.data_stored = false; % false == data are generated "onfly", no need to load / store
% additional arguments for image_read
det.image_read_extraargs = {};
det.orientation = [0 0 0]; % [<Transpose> <FlipLR> <FlipUD>]
end
+74
View File
@@ -0,0 +1,74 @@
%DETSTORAGE Matlab class for convenient data access during the data
%preparation
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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.
classdef detStorage < dynamicprops
properties
data = []
fmask = logical([])
ctr
check_ctr
mask
lim_inf
lim_sup
read_size
files
h5_group
end
end
+116
View File
@@ -0,0 +1,116 @@
%INITIALIZE_DETECTOR run some checks and load the detector settings
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 ] = initialize_detector( p , ii)
import utils.verbose
import io.spec_read
%%% Check that p.ctr and dettrx are consistent, otherwise swap p.ctr
if (~isempty(p.detector.check_2_detpos))
if isfield(p.meta{1}, 'spec')
% Set default motor dettrx for backward compatibility
if ~isfield(p.detectors(ii).params,'detposmotor')
p.detectors(ii).params.detposmotor = 'dettrx';
end
detposmotor = p.detectors(ii).params.detposmotor;
currentdetpos = getfield(p.meta{ii}.spec,detposmotor);
% p.meta{ii}.spec.dettr
% det.detposmotor = 'dettr';
if (length(p.scan_number)==2)&&(ii==1)
p.dettrxfirst = currentdetpos;
if (currentdetpos < p.detector.check_2_detpos)&&(p.ctr(1,2)>p.ctr(2,2))
verbose(2,'Detector positions seem ok (combination 12)')
elseif (currentdetpos < p.detector.check_2_detpos)&&(p.ctr(1,2)<p.ctr(2,2))
verbose(2,'Detector positions are swapped, correcting (combination 21)')
aux = p.ctr;
p.ctr(1,:) = aux(2,:);
p.ctr(2,:) = aux(1,:);
elseif (currentdetpos > p.detector.check_2_detpos)&&(p.ctr(1,2)<p.ctr(2,2))
verbose(2,'Detector positions seem ok (combination 12)')
elseif (currentdetpos > p.detector.check_2_detpos)&&(p.ctr(1,2)>p.ctr(2,2))
verbose(2,'Detector positions are swapped, correcting (combination 21)')
aux = p.ctr;
p.ctr(1,:) = aux(2,:);
p.ctr(2,:) = aux(1,:);
else
error('Unexpected detector position combination')
end
end
if (length(p.scan_number)==2)&&(ii==2)
% Check that the detpos is not repeated
if (currentdetpos < p.detector.check_2_detpos)&&(p.dettrxfirst < p.detector.check_2_detpos)
error('Repeated detector position detected')
elseif (currentdetpos > p.detector.check_2_detpos)&&(p.dettrxfirst > p.detector.check_2_detpos)
error('Repeated detector position detected')
end
end
else
error('check_2_detpos only works with spec data. Please set p.src_metadata = ''spec''.')
end
end
if p.detectors(ii).params.data_stored
p.raw_data_path_full{ii} = p.detectors(ii).funcs.get_dir_path(p, ii);
end
end
+90
View File
@@ -0,0 +1,90 @@
% LOAD_DETECTOR
% load detector files as specified in p
% 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
% LICENSEEs 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, 379382 (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, 6871 (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, 2908929108 (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 ] = load_detector( p )
import utils.verbose
if iscell(p.detector.name)
% multiple detectors
keyboard
else
p .detectors = struct(); % first clean anything stored in the detector structure
for ii=1:length(p.scan_number)
p.detID = ii;
detector_func = str2func(['detector.' p.detector.name '.' p.detector.name]);
verbose(2, 'Loading preferences for %s detector.', p.detector.name)
p.detectors(p.detID).params = detector_func(p);
p.detectors(p.detID).name = p.detector.name;
p.detectors(p.detID).detStorage = detector.detStorage;
p = detector.prep_data.update_defaults(p);
end
end
% cleanup
p = rmfield(p, 'detID');
for ii=1:length(p.scan_number)
p = detector.initialize_detector(p, ii);
end
end