mirror of
https://github.com/c-sooyoung/fold_slice.git
synced 2026-09-18 00:09:10 +09:00
initial commit
This commit is contained in:
@@ -0,0 +1,208 @@
|
||||
%EXTRACT4SAVING extracts datasets and parameters from p and creates HDF5
|
||||
%structure
|
||||
% ** p p structure
|
||||
% ** append boolean; true if data will be appended to an existing file
|
||||
%
|
||||
% returns:
|
||||
% ++ s structure for save2hdf5
|
||||
%
|
||||
% see also: io.HDF.save2hdf5
|
||||
%
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function [ s ] = extract4saving(p, append)
|
||||
import utils.update_param
|
||||
import math.double2int
|
||||
|
||||
s = [];
|
||||
|
||||
|
||||
|
||||
p = rmfield_safe(p, 'probe');
|
||||
p = rmfield_safe(p, 'positions_temp');
|
||||
p = rmfield_safe(p, 'scanidxs');
|
||||
p = rmfield_safe(p, 'share_pos');
|
||||
|
||||
p.positions = transpose(p.positions);
|
||||
p.positions_real = transpose(p.positions_real);
|
||||
p.positions_orig = transpose(p.positions_orig);
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%
|
||||
%%% measurement %%%
|
||||
%%%%%%%%%%%%%%%%%%%
|
||||
%% external link to data file
|
||||
% should be saved with a relative path
|
||||
% s.measurement.data = ['ext:' p.prepare_data_path p.prepare_data_filename ':/'];
|
||||
|
||||
%% Meta data
|
||||
if ~isempty(p.meta)
|
||||
s.measurement.meta_all = p.meta;
|
||||
end
|
||||
p = rmfield_safe(p, 'meta');
|
||||
|
||||
|
||||
%% Detector settings
|
||||
% s.measurement.detector
|
||||
p = rmfield_safe(p, p.detector.name);
|
||||
|
||||
%% fmask and fmag
|
||||
p = rmfield_safe(p, 'fmask');
|
||||
p = rmfield_safe(p, 'fmag');
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%% reconstruction %%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
%% engines
|
||||
em_indx = 0;
|
||||
for ii=1:length(p.engines)
|
||||
tmp = p.engines{ii};
|
||||
|
||||
% % add object_final
|
||||
% if ~isempty(tmp.object_final)
|
||||
% s.reconstruction.engines{ii}.object_final = tmp.object_final;
|
||||
% end
|
||||
% % add probes_final
|
||||
% if ~isempty(tmp.probes_final)
|
||||
% s.reconstruction.engines{ii}.probes_final = tmp.probes_final;
|
||||
% end
|
||||
if isfield(tmp, 'error_metric_final')
|
||||
for jj=1:length(tmp.error_metric_final)
|
||||
% add error_metric_final
|
||||
if iscell(tmp.error_metric_final)
|
||||
s.reconstruction.p.engines{ii}.error_metric_final.(['em_' num2str(jj-1)]).iteration = tmp.error_metric_final{jj}.iteration;
|
||||
s.reconstruction.p.engines{ii}.error_metric_final.(['em_' num2str(jj-1)]).value = tmp.error_metric_final{jj}.value;
|
||||
s.reconstruction.p.engines{ii}.error_metric_final.(['em_' num2str(jj-1)]).method = tmp.error_metric_final{jj}.method;
|
||||
s.reconstruction.p.engines{ii}.error_metric_final.(['em_' num2str(jj-1)]).err_metric = tmp.error_metric_final{jj}.err_metric;
|
||||
s.reconstruction.p.engines{ii}.error_metric_final.Attributes.MATLAB_class = 'cell';
|
||||
else
|
||||
s.reconstruction.p.engines{ii}.error_metric_final.(['em_' num2str(jj-1)]).iteration = tmp.error_metric_final.iteration;
|
||||
s.reconstruction.p.engines{ii}.error_metric_final.(['em_' num2str(jj-1)]).value = tmp.error_metric_final.value;
|
||||
s.reconstruction.p.engines{ii}.error_metric_final.(['em_' num2str(jj-1)]).method = tmp.error_metric_final.method;
|
||||
s.reconstruction.p.engines{ii}.error_metric_final.(['em_' num2str(jj-1)]).err_metric = tmp.error_metric_final.err_metric;
|
||||
s.reconstruction.p.engines{ii}.error_metric_final.Attributes.MATLAB_class = 'cell';
|
||||
end
|
||||
% add error_metric
|
||||
% s.reconstruction.p.error_metric.(['em_' num2str(em_indx)]) = ['int_soft:/reconstruction/p/engines/' fn{ii} '/error_metric_final/em_' num2str(jj-1)];
|
||||
% em_indx = em_indx + 1;
|
||||
end
|
||||
s.reconstruction.p.engines{ii} = update_param(s.reconstruction.p.engines{ii}, double2int(tmp), 'force_update', 0);
|
||||
|
||||
end
|
||||
|
||||
tmp = rmfield_safe(tmp, 'object_final');
|
||||
tmp = rmfield_safe(tmp, 'probes_final');
|
||||
tmp = rmfield_safe(tmp, 'error_metric_final');
|
||||
tmp = rmfield_safe(tmp, 'fdb');
|
||||
|
||||
end
|
||||
|
||||
p = rmfield_safe(p, 'engines');
|
||||
p = rmfield_safe(p, 'error_metric');
|
||||
% p = rmfield_safe(p, 'err');
|
||||
% p = rmfield_safe(p, 'rfact');
|
||||
|
||||
%% probe (dataset)
|
||||
if ~append
|
||||
for ii=1:p.numprobs
|
||||
s.reconstruction.p.probes.(['probe_' num2str(ii-1)]) = permute(squeeze(p.probes(:,:,ii,:)), [2 1 3]);
|
||||
end
|
||||
end
|
||||
|
||||
p = rmfield_safe(p, 'probes');
|
||||
|
||||
|
||||
|
||||
|
||||
%% object (dataset)
|
||||
if ~append
|
||||
for ii=1:p.numobjs
|
||||
s.reconstruction.p.objects.(['object_' num2str(ii-1)]) = permute(p.object{ii}, [2 1 3 4]);
|
||||
end
|
||||
end
|
||||
p = rmfield_safe(p, 'object');
|
||||
|
||||
|
||||
|
||||
%% probe mask
|
||||
if isfield(p, 'probe_mask')
|
||||
s.reconstruction.p.probe_mask = p.probe_mask;
|
||||
|
||||
p = rmfield_safe(p, 'probe_mask');
|
||||
end
|
||||
|
||||
%% ctr
|
||||
s.reconstruction.p.ctr = uint32(transpose(p.ctr));
|
||||
|
||||
p = rmfield_safe(p, 'ctr');
|
||||
|
||||
%% everything else
|
||||
|
||||
s.reconstruction.p = update_param(s.reconstruction.p, double2int(p), 'force_update', 0);
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
function p = rmfield_safe(p, val)
|
||||
if isfield(p, val)
|
||||
p = rmfield(p, val);
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
%RECONSTRUCTIONS_AS_MAT
|
||||
% Save reconstruction into a h5 file
|
||||
%
|
||||
% ** p p structure
|
||||
% ** final boolean; false for intermediate saving routines
|
||||
%
|
||||
% returns:
|
||||
% ++ p p structure
|
||||
%
|
||||
% see also: core.save.save_results
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function p = reconstructions_as_h5(p, final)
|
||||
import utils.verbose
|
||||
import utils.relative_path
|
||||
import io.HDF.*
|
||||
|
||||
|
||||
if final
|
||||
p.plot.extratitlestring = sprintf(' (%dx%d) - Final', p.asize(2), p.asize(1));
|
||||
end
|
||||
|
||||
% check if last engine was c_solver
|
||||
if strcmpi(p.engines{p.current_engine_id}.name, 'c_solver')
|
||||
append2file = true;
|
||||
else
|
||||
append2file = false;
|
||||
end
|
||||
|
||||
s = core.save.extract4saving(p, append2file);
|
||||
|
||||
|
||||
for ii=1:p.numscans
|
||||
if p.share_object
|
||||
obnum = 1;
|
||||
else
|
||||
obnum = ii;
|
||||
end
|
||||
if p.share_probe
|
||||
prnum = 1;
|
||||
else
|
||||
prnum = ii;
|
||||
end
|
||||
s.reconstruction.object = ['int_soft:/reconstruction/p/objects/object_' num2str(obnum-1)];
|
||||
s.reconstruction.probes = ['int_soft:/reconstruction/p/probes/probe_' num2str(prnum-1)];
|
||||
s.reconstruction.Attributes.obnum = obnum;
|
||||
s.reconstruction.Attributes.prnum = prnum;
|
||||
if isfield(p, 'recon_filename')
|
||||
filename_with_path = p.recon_filename{ii};
|
||||
if p.queue.isreplica
|
||||
[~, fname, ext] = fileparts(p.recon_filename{ii});
|
||||
filename_with_path = fullfile(p.save_path{ii}, [fname ext]);
|
||||
end
|
||||
else
|
||||
recons_filename = sprintf('%s_recons.%s',p.run_name, p.save.output_file);
|
||||
filename_with_path = fullfile(p.save_path{ii}, recons_filename);
|
||||
|
||||
if exist(filename_with_path, 'file')
|
||||
verbose(3,'File %s exists!', filename_with_path);
|
||||
alt_filename = filename_with_path;
|
||||
[~, fbase,f2] = fileparts(filename_with_path);
|
||||
append_number = 0;
|
||||
while exist(alt_filename, 'file')
|
||||
f1 = sprintf('%s_%02d', fbase, append_number);
|
||||
alt_filename = fullfile(p.save_path{ii}, [f1 f2]);
|
||||
append_number = append_number + 1;
|
||||
end
|
||||
filename_with_path = alt_filename;
|
||||
end
|
||||
end
|
||||
|
||||
if ii==1
|
||||
% If the last engine was c_solver, we can use the already existing
|
||||
% h5 file.
|
||||
if append2file
|
||||
movefile(p.recon_filename_c, filename_with_path);
|
||||
end
|
||||
root_file = filename_with_path;
|
||||
s.measurement.data = ['ext:' relative_path(filename_with_path, [p.prepare_data_path p.prepare_data_filename]) ':/'];
|
||||
|
||||
else
|
||||
hdf5_cp_file(relative_path(filename_with_path, root_file), filename_with_path, 'groups', {'/measurement/data'; '/measurement/meta_all'; '/reconstruction/p'});
|
||||
end
|
||||
|
||||
s.measurement.meta = ['int_soft:/measurement/meta_all/meta_all_' num2str(ii-1)];
|
||||
save2hdf5(filename_with_path, s, 'comp', p.io.file_compression);
|
||||
|
||||
try
|
||||
fsz = dir(filename_with_path);
|
||||
verbose(0, 'Reconstructed scan S%05d: %s', p.scan_number(ii), filename_with_path)
|
||||
verbose(2, 'File size: %0.4f MB', fsz.bytes/1e6)
|
||||
catch
|
||||
verbose(0, 'Saved reconstruction to file %s.', filename_with_path);
|
||||
end
|
||||
|
||||
s = [];
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,145 @@
|
||||
%RECONSTRUCTIONS_AS_MAT
|
||||
% Save reconstruction into the MAT file
|
||||
%
|
||||
% ** p p structure
|
||||
% ** final boolean; false for intermediate saving routines
|
||||
%
|
||||
% returns:
|
||||
% ++ p p structure
|
||||
%
|
||||
% see also: core.save.save_results
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
|
||||
function p = reconstructions_as_mat(p, final)
|
||||
import utils.verbose
|
||||
import utils.relative_path
|
||||
import io.HDF.*
|
||||
|
||||
if ~isfield(p.save, 'exclude')
|
||||
p.save.exclude = {'fmag'; 'fmask'};
|
||||
end
|
||||
if final
|
||||
p.plot.extratitlestring = sprintf(' (%dx%d) - Final', p.asize(2), p.asize(1));
|
||||
end
|
||||
|
||||
recons_filename = sprintf('%s_recons.mat',p.run_name);
|
||||
|
||||
for ii = 1:p.numscans
|
||||
if p.share_object
|
||||
obnum = 1;
|
||||
else
|
||||
obnum = ii;
|
||||
end
|
||||
if p.share_probe
|
||||
prnum = 1;
|
||||
else
|
||||
prnum = ii;
|
||||
end
|
||||
|
||||
object = p.object{obnum};
|
||||
probe = p.probes(:,:,prnum,:);
|
||||
|
||||
|
||||
% if isfield(p.meta,'spec')
|
||||
% p.spec = p.meta.spec{ii};
|
||||
% end
|
||||
|
||||
filename_with_path = fullfile(p.save_path{ii}, recons_filename);
|
||||
|
||||
|
||||
if exist(filename_with_path, 'file')
|
||||
verbose(3,'File %s exists!', filename_with_path);
|
||||
alt_filename = filename_with_path;
|
||||
[~, fbase,f2] = fileparts(filename_with_path);
|
||||
append_number = 0;
|
||||
while exist(alt_filename, 'file')
|
||||
f1 = sprintf('%s_%02d', fbase, append_number);
|
||||
alt_filename = fullfile(p.save_path{ii}, [f1 f2]);
|
||||
append_number = append_number + 1;
|
||||
end
|
||||
verbose(1, 'Saving reconstruction to file %s', alt_filename);
|
||||
filename_with_path = alt_filename;
|
||||
end
|
||||
|
||||
% avoid saving unnecesary data => speed up loading during tomography
|
||||
probe = single(squeeze(probe));
|
||||
object = single(object);
|
||||
if ~p.save.save_reconstructions_intermediate
|
||||
for ieng = 1:length(p.engines)
|
||||
p.engines{ieng}.object_final = [];
|
||||
p.engines{ieng}.probes_final = [];
|
||||
end
|
||||
end
|
||||
|
||||
for ex=1:size(p.save.exclude,1)
|
||||
temp.(p.save.exclude{ex}) = p.(p.save.exclude{ex});
|
||||
p.(p.save.exclude{ex}) = [];
|
||||
end
|
||||
% save it to HDF5 without compression (faster saving / loading)
|
||||
save(filename_with_path,'p','object','probe', '-v6' );
|
||||
% note that the -v6 option makes the saving 10x faster and
|
||||
% loading 5x faster compared to option -v7 and 30x faster
|
||||
% saving compared to -v7.3
|
||||
verbose(0, 'Saved reconstruction to file %s.', filename_with_path);
|
||||
|
||||
for ex=1:size(p.save.exclude,1)
|
||||
p.(p.save.exclude{ex}) = temp.(p.save.exclude{ex});
|
||||
end
|
||||
|
||||
clear temp;
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,134 @@
|
||||
%SAVE_RESULTS
|
||||
% Save reconstruction and parameter file
|
||||
%
|
||||
% ** p p structure
|
||||
% ** final boolean; false for intermediate saving routines
|
||||
%
|
||||
% returns:
|
||||
% ++ p p structure
|
||||
%
|
||||
% see also: core.ptycho_recons
|
||||
|
||||
% Academic License Agreement
|
||||
%
|
||||
% Source Code
|
||||
%
|
||||
% Introduction
|
||||
% • This license agreement sets forth the terms and conditions under which the PAUL SCHERRER INSTITUT (PSI), CH-5232 Villigen-PSI, Switzerland (hereafter "LICENSOR")
|
||||
% will grant you (hereafter "LICENSEE") a royalty-free, non-exclusive license for academic, non-commercial purposes only (hereafter "LICENSE") to use the cSAXS
|
||||
% ptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter "PROGRAM").
|
||||
%
|
||||
% Terms and Conditions of the LICENSE
|
||||
% 1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditions
|
||||
% hereinafter set out and until termination of this license as set forth below.
|
||||
% 2. LICENSEE acknowledges that the PROGRAM is a research tool still in the development stage. The PROGRAM is provided without any related services, improvements
|
||||
% or warranties from LICENSOR and that the LICENSE is entered into in order to enable others to utilize the PROGRAM in their academic activities. It is the
|
||||
% LICENSEE’s responsibility to ensure its proper use and the correctness of the results.”
|
||||
% 3. THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
||||
% A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHT
|
||||
% HOLDERS BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE
|
||||
% OF THE PROGRAM OR OTHER DEALINGS IN THE PROGRAM.
|
||||
% 4. LICENSEE agrees that it will use the PROGRAM and any modifications, improvements, or derivatives of PROGRAM that LICENSEE may create (collectively,
|
||||
% "IMPROVEMENTS") solely for academic, non-commercial purposes and that any copy of PROGRAM or derivatives thereof shall be distributed only under the same
|
||||
% license as PROGRAM. The terms "academic, non-commercial", as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken for
|
||||
% profit, or (b) is not intended to produce works, services, or data for commercial use, or (c) is neither conducted, nor funded, by a person or an entity engaged
|
||||
% in the commercial use, application or exploitation of works similar to the PROGRAM.
|
||||
% 5. LICENSEE agrees that it shall make the following acknowledgement in any publication resulting from the use of the PROGRAM or any translation of the code into
|
||||
% another computing language:
|
||||
% "Data processing was carried out using the cSAXS ptychography MATLAB package developed by the Science IT and the coherent X-ray scattering (CXS) groups, Paul
|
||||
% Scherrer Institut, Switzerland."
|
||||
%
|
||||
% Additionally, any publication using the package, or any translation of the code into another computing language should cite for difference map:
|
||||
% P. Thibault, M. Dierolf, A. Menzel, O. Bunk, C. David, F. Pfeiffer, High-resolution scanning X-ray diffraction microscopy, Science 321, 379–382 (2008).
|
||||
% (doi: 10.1126/science.1158573),
|
||||
% for maximum likelihood:
|
||||
% P. Thibault and M. Guizar-Sicairos, Maximum-likelihood refinement for coherent diffractive imaging, New J. Phys. 14, 063004 (2012).
|
||||
% (doi: 10.1088/1367-2630/14/6/063004),
|
||||
% for mixed coherent modes:
|
||||
% P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),
|
||||
% and/or for multislice:
|
||||
% E. H. R. Tsai, I. Usov, A. Diaz, A. Menzel, and M. Guizar-Sicairos, X-ray ptychography with extended depth of field, Opt. Express 24, 29089–29108 (2016).
|
||||
% (doi: 10.1364/OE.24.029089).
|
||||
% 6. Except for the above-mentioned acknowledgment, LICENSEE shall not use the PROGRAM title or the names or logos of LICENSOR, nor any adaptation thereof, nor the
|
||||
% names of any of its employees or laboratories, in any advertising, promotional or sales material without prior written consent obtained from LICENSOR in each case.
|
||||
% 7. Ownership of all rights, including copyright in the PROGRAM and in any material associated therewith, shall at all times remain with LICENSOR, and LICENSEE
|
||||
% agrees to preserve same. LICENSEE agrees not to use any portion of the PROGRAM or of any IMPROVEMENTS in any machine-readable form outside the PROGRAM, nor to
|
||||
% make any copies except for its internal use, without prior written consent of LICENSOR. LICENSEE agrees to place the following copyright notice on any such copies:
|
||||
% © All rights reserved. PAUL SCHERRER INSTITUT, Switzerland, Laboratory for Macromolecules and Bioimaging, 2017.
|
||||
% 8. The LICENSE shall not be construed to confer any rights upon LICENSEE by implication or otherwise except as specifically set forth herein.
|
||||
% 9. DISCLAIMER: LICENSEE shall be aware that Phase Focus Limited of Sheffield, UK has an international portfolio of patents and pending applications which relate
|
||||
% to ptychography and that the PROGRAM may be capable of being used in circumstances which may fall within the claims of one or more of the Phase Focus patents,
|
||||
% in particular of patent with international application number PCT/GB2005/001464. The LICENSOR explicitly declares not to indemnify the users of the software
|
||||
% in case Phase Focus or any other third party will open a legal action against the LICENSEE due to the use of the program.
|
||||
% 10. This Agreement shall be governed by the material laws of Switzerland and any dispute arising out of this Agreement or use of the PROGRAM shall be brought before
|
||||
% the courts of Zürich, Switzerland.
|
||||
|
||||
function [p] = save_results(p, final)
|
||||
import utils.verbose
|
||||
import utils.relative_path
|
||||
import io.HDF.*
|
||||
|
||||
print_FSC = false;
|
||||
if p.plot.calc_FSC
|
||||
if p.numscans ~= 2 && ~(isfield(p, 'simulation')&&isfield(p.simulation, 'obj'))
|
||||
warning('FRC calculation is implemented for 2 scans only.')
|
||||
else
|
||||
try
|
||||
[p, resolution] = core.analysis.calc_FSC(p);
|
||||
print_FSC = true;
|
||||
catch ME
|
||||
if p.verbose_level > 3
|
||||
keyboard
|
||||
else
|
||||
warning('Failed to calculate FSC.')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if p.save.save_reconstructions
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%% Save reconstruction and parameter file %%%%%%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
if strcmpi(p.save.output_file, 'h5') || strcmpi(p.save.output_file, 'cxs')
|
||||
|
||||
p = core.save.reconstructions_as_h5(p, final);
|
||||
|
||||
elseif strcmpi(p.save.output_file, 'mat')
|
||||
|
||||
p = core.save.reconstructions_as_mat(p, final);
|
||||
|
||||
else
|
||||
error('Unknown file extension .%s', p.save.output_file);
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
%%%%%%%%%%%%
|
||||
%%% Plot %%%
|
||||
%%%%%%%%%%%%
|
||||
|
||||
if final && p.save.external && p.verbose_level <=2
|
||||
verbose(2, 'Starting new matlab session to save figures.')
|
||||
|
||||
recons_filename = sprintf('%s_recons.%s',p.run_name, p.save.output_file);
|
||||
filename_with_path = fullfile(p.save_path{1}, recons_filename);
|
||||
|
||||
ext_call = ['addpath(genpath(''../'')); try;' ...
|
||||
'plotting.ptycho_show_recons(''' filename_with_path ''');catch ME;'...
|
||||
'fprintf([ME.getReport ''\n\n\n'']); end; quit'];
|
||||
system(['matlab -nosplash -nodisplay -r "' ext_call '" &']);
|
||||
else
|
||||
if p.use_display||p.save.store_images
|
||||
core.analysis.plot_results(p, 'use_display', p.use_display, 'store_images', p.save.store_images, 'final', final);
|
||||
end
|
||||
end
|
||||
|
||||
if print_FSC
|
||||
fprintf('\n');
|
||||
utils.verbose(2,'Resolution (FSC): (%.2f, %.2f) nm\n', resolution)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user