ptycho package documentation¶
-
GPU_batch_solver
- GPU_BATCH_SOLVERmulti GPU batch solveruse parallel toolbox to distribute tasks into several asynchronouslyrunning workers
-
affine_matrix_search
- AFFINE_MATRIX_SEARCHCode to evaluate the affine matrix angle for a series ofreconstructionsEach reconstruction should have preffix ‘affine’ in the nameand contain a field called p.affine_anglesee also aligned_FSC_template
-
affine_test
- close all
-
aligned_FSC_template
- ALIGNED_FSC_TEMPLATEScript to align images and compute FSCReferences relevant to this code:For using this FSC code with ptychography: J. Vila-Comamala, et al., “Characterization of high-resolution diffractive X-ray optics by ptychographic coherent diffractive imaging,” Opt. Express 19, 21333-21344 (2011).For subpixel alignment: M. Guizar-Sicairos, et al., “Efficient subpixel image registration algorithms,” Opt. Lett. 33, 156 (2008).For matching of phase ramp by approximate least squared error: M. Guizar-Sicairos, et al., “Phase tomography from x-ray coherent diffractive imaging projections,” Opt. Express 19, 21345-21357 (2011).
-
colorbar_complex
- colorbar_complex is a script.
-
complex_colorbar
- UNTITLED2 Summary of this class goes hereDetailed explanation goes hereReference page in Doc Centerdoc complex_colorbar
-
create_template
(s, var)¶ - create_template is a function.create_template(s, var)
-
delta_vs_beta
- delta_vs_beta is a script.
-
external_call
- % modify this section %%%
-
find_peaks
- FIND_PEAKSRoutine to find diffraction peaks of a grating and compute its angleand the distance to the detectorBe careful to avoid saturation of the center pixel as it will affectthe calculaton
-
multilens
- settings
-
offline_ptycho_et
- Reconstruction parametersEdit only this sectionReferences in ptycho_recons.mFor 2 detector positionsPut multiple scan numbers e.g. p.scan_number = [5 6];Multiple centers e.g. p.ctr = [100 207;120 217];
-
propagation_test
- propagation_test is a script.
-
ptycho_online
- Reconstruction parametersEdit only this sectionReferences in ptycho_recons.mFor 2 detector positionsPut multiple scan numbers e.g. p.scan_number = [5 6];Multiple centers e.g. p.ctr = [100 207;120 217];
-
ptycho_wrap_offline_28scans_20131023_affine_stitch_500_67_89
- Reconstruction parametersEdit only this sectionReferences in ptycho_recons.mFor 2 detector positionsPut multiple scan numbers e.g. p.scan_number = [5 6];Multiple centers e.g. p.ctr = [100 207;120 217];
-
ref_plot
- ref_plot is a script.
-
setup_recons
(varargin)¶ - SETUP_RECONS MATLAB code for setup_recons.figSETUP_RECONS, by itself, creates a new SETUP_RECONS or raises the existingsingleton*.H = SETUP_RECONS returns the handle to a new SETUP_RECONS or the handle tothe existing singleton*.SETUP_RECONS(‘CALLBACK’,hObject,eventData,handles,…) calls the localfunction named CALLBACK in SETUP_RECONS.M with the given input arguments.SETUP_RECONS(‘Property’,’Value’,…) creates a new SETUP_RECONS or raises theexisting singleton*. Starting from the left, property value pairs areapplied to the GUI before setup_recons_OpeningFcn gets called. Anunrecognized property name or invalid value makes property applicationstop. All inputs are passed to setup_recons_OpeningFcn via varargin.*See GUI Options on GUIDE’s Tools menu. Choose “GUI allows only oneinstance to run (singleton)”.See also: GUIDE, GUIDATA, GUIHANDLES
Returns: varargout
-
setup_remote_recons
()¶ - SETUP_REMOTE_RECONS
-
setup_template
(varargin)¶ - SETUP_TEMPLATE
-
setup_template_backup
- Academic License AgreementSource CodeIntroduction• 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 cSAXSptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter “PROGRAM”).Terms and Conditions of the LICENSE1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditionshereinafter 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, improvementsor 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 theLICENSEE’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 FORA PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHTHOLDERS 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 USEOF 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 samelicense as PROGRAM. The terms “academic, non-commercial”, as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken forprofit, 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 engagedin 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 intoanother 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, PaulScherrer 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 thenames 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 LICENSEEagrees 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 tomake 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 relateto 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 softwarein 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 beforethe courts of Zürich, Switzerland.
-
simple_gui2
- Academic License AgreementSource CodeIntroduction• 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 cSAXSptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter “PROGRAM”).Terms and Conditions of the LICENSE1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditionshereinafter 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, improvementsor 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 theLICENSEE’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 FORA PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHTHOLDERS 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 USEOF 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 samelicense as PROGRAM. The terms “academic, non-commercial”, as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken forprofit, 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 engagedin 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 intoanother 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, PaulScherrer 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 thenames 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 LICENSEEagrees 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 tomake 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 relateto 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 softwarein 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 beforethe courts of Zürich, Switzerland.
-
template_artificial_data
- ARTIFICIAL_DATA parametersSpecify simulation parameters and overwrite fields for a more realisticsimulation.
-
template_conversion
- template_conversion is a script.
-
template_ptycho
- Reconstruction parametersEdit only this sectionReferences in ptycho_recons.mFor 2 detector positionsPut multiple scan numbers e.g. p.scan_number = [5 6];Multiple centers e.g. p.ctr = [100 207;120 217];
-
template_ptycho_Eiger
- Reconstruction parametersEdit only this sectionReferences in ptycho_recons.mFor 2 detector positionsPut multiple scan numbers e.g. p.scan_number = [5 6];Multiple centers e.g. p.ctr = [100 207;120 217];
-
template_ptycho_Eiger_selfie
- Reconstruction parametersEdit only this sectionReferences in ptycho_recons.mFor 2 detector positionsPut multiple scan numbers e.g. p.scan_number = [5 6];Multiple centers e.g. p.ctr = [100 207;120 217];
-
template_ptycho_Eiger_selfie_old
- Reconstruction parametersEdit only this sectionReferences in ptycho_recons.mFor 2 detector positionsPut multiple scan numbers e.g. p.scan_number = [5 6];Multiple centers e.g. p.ctr = [100 207;120 217];
-
template_ptycho_MOENCH_FP
- Reconstruction parametersEdit only this sectionReferences in ptycho_recons.mFor 2 detector positionsPut multiple scan numbers e.g. p.scan_number = [5 6];Multiple centers e.g. p.ctr = [100 207;120 217];
-
template_ptycho_eiger_selfie
- Reconstruction parametersEdit only this sectionReferences in ptycho_recons.mFor 2 detector positionsPut multiple scan numbers e.g. p.scan_number = [5 6];Multiple centers e.g. p.ctr = [100 207;120 217];
-
template_ptycho_loop
- template_ptycho_loop is a script.
-
template_ptycho_pilatus_e16403
- Reconstruction parametersEdit only this sectionReferences in ptycho_recons.mFor 2 detector positionsPut multiple scan numbers e.g. p.scan_number = [5 6];Multiple centers e.g. p.ctr = [100 207;120 217];
-
template_ptycho_pilatus_e16403_new
- Reconstruction parametersEdit only this sectionReferences in ptycho_recons.mFor 2 detector positionsPut multiple scan numbers e.g. p.scan_number = [5 6];Multiple centers e.g. p.ctr = [100 207;120 217];
-
template_ptycho_receiver
- ptycho receiver templateexecute this script on the remote machine
-
template_ptycho_receiver_script
- ptycho receiver templateexecute this script on the remote machine
-
template_ptycho_receiver_test
- ptycho receiver templateexecute this script on the remote machine
-
template_ptycho_test_eiger
- Reconstruction parametersEdit only this sectionReferences in ptycho_recons.mFor 2 detector positionsPut multiple scan numbers e.g. p.scan_number = [5 6];Multiple centers e.g. p.ctr = [100 207;120 217];
-
template_ptycho_test_eiger_single_frame
- Reconstruction parametersEdit only this sectionReferences in ptycho_recons.mFor 2 detector positionsPut multiple scan numbers e.g. p.scan_number = [5 6];Multiple centers e.g. p.ctr = [100 207;120 217];
-
template_ptycho_test_pilatus
- Reconstruction parametersEdit only this sectionReferences in ptycho_recons.mFor 2 detector positionsPut multiple scan numbers e.g. p.scan_number = [5 6];Multiple centers e.g. p.ctr = [100 207;120 217];
-
template_ptycho_test_pilatus_2
- Reconstruction parametersEdit only this sectionReferences in ptycho_recons.mFor 2 detector positionsPut multiple scan numbers e.g. p.scan_number = [5 6];Multiple centers e.g. p.ctr = [100 207;120 217];
-
template_simple
- template_simple is a script.
-
template_wrapper
- For 2 detector positionsPut multiple scan numbers e.g. p.scan_number = [5 6];Multiple centers e.g. p.ctr = [100 207;120 217];
-
test_artificial_data
- Reconstruction parametersEdit only this sectionReferences in ptycho_recons.mFor 2 detector positionsPut multiple scan numbers e.g. p.scan_number = [5 6];Multiple centers e.g. p.ctr = [100 207;120 217];
-
test_mod
- Reconstruction parametersEdit only this sectionReferences in ptycho_recons.mFor 2 detector positionsPut multiple scan numbers e.g. p.scan_number = [5 6];Multiple centers e.g. p.ctr = [100 207;120 217];
-
test_ptychoshelves
- TEST ALL ENGINES IN PTYCHOSHELVES TOOLKIT
+core¶
-
core.
append_engine
(p, new_eng)¶ - APPEND_ENGINE appends engine specified in new_eng to pAdds engines with index, starting at 01st engine: p.engines.engine0
Parameters: - p – p structure
- new_eng – structure containing information about the new engine
Returns: - p - p structure
- new_eng - empty container; useful if one does not want to propagate changes between engines
see also core.ptycho_recons
-
core.
check_prepared_data
(p)¶ - CHECK_PREPARED_DATA compares prepared data file with currentreconstruction parameters. If force_update == true, data preparation willbe forced (see core.ptycho_prepare_scans)
Parameters: p – p structure Returns: force_update - true if data preparation has be done enforced see also core.ptycho_prepare_scans
-
core.
engine_status
(varargin)¶ - ENGINE_STATUS use persisten variables to store error messagesError code: 0 for ‘everything OK’ and ~=0 for ‘error’ (return values of matlab’s system function)usage:engine_status(status) to set persisten variable engine_stat tostatusengine_status to read persisten variables
Returns: eng_stat
-
core.
errorplot
(argin)¶ - Build an errormetric plot vs iteration numberusagee = errorplot Clears the persistent variablee = errorplot(x) Appends x to the persistent variablee = errorplot([]) Only reads the persistent variable
Returns: outerror
-
core.
export4remote
(p)¶ - EXPORT4REMOTEExport the meta data using a .mat file for remote reconstruction
Parameters: p – p structure Returns: p - updated p structure
-
core.
extract4saving
(p, append)¶ - EXTRACT4SAVING extracts datasets and parameters from p and creates HDF5structure
Parameters: - 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
- FIND_SHARED_IDS find which positions belong to each object / probe
Parameters: p – p structure Returns: p - p structure see also core.initialize_ptycho
-
core.
generate_scan_name
(p)¶ - GENERATE_SCAN_NAMEAuxilialy function to generate scan names
Parameters: p – p structure Returns: scan_name - scan names
-
core.
get_projections
(p, object, scan_id, obj_proj)¶ - GET_PROJECTIONS
Parameters: - p – p structure
- object – full-size object
- scan_id – ID of the current scan
- obj_proj – container for object projections
Returns: obj_proj - updated container for object projections
-
core.
hermite_like
(fundam, X, Y, M, N)¶ - HERMITE_LIKEReceives a probe and maximum x and y order M N. Based on the given probeand multiplying by a Hermitian function new modes are computed. The modesare then orthonormalized.
Returns: H
-
core.
initial_checks
(p)¶ - INITIAL_CHECKS set default values for the most common variables
Parameters: p – p structure Returns: p - p structure see also core.initialize_ptycho
-
core.
initialize_ptycho
(p)¶ - INITIALIZE_PTYCHOeverything that needs to be done before triggering the reconstruction. This includesinter alia initial checks, intial guess preparations and loading the data.
Parameters: p – p structure Returns: - p - p structure
- status - status flag
see also core.ptycho_recons
-
core.
prep_h5data
(p)¶ - PREP_H5DATA prepare data and save it to diskprep_h5data expects that fmask and fmag already exist, prepares themfor the C++ code and saves everything to disk.
Parameters: p – p structure see also core.ptycho_prepare_scans
-
core.
prep_initial_object
(p)¶ - PREPARE_INITIAL_OBJECTprepare an initial guess for the object reconstruction
Parameters: p – p structure Returns: p - p structure see also core.prepare_init_guess
-
core.
prepare_init_guess
(p)¶ - PREPARE_INIT_GUESSprepare an initial guess for the object and probe reconstruction
Parameters: p – p structure Returns: p - p structure see also core.prepare_init_guess
-
core.
prepare_probes
(p)¶ - Prepare probe - Only single file supported, either the file has a 3D matrixof many probes or the probe will be repeated for the number of probesneeded for reconstruction
Returns: p
-
core.
probe_modes_ortho
(modes)¶ - ORTHO Orthogonalize the given list of modes using SVD.[pr, I_n, eval] = probe_modes_ortho(modes)pr Orthogonalized (eigen) modesI_n Normalized intensity of the mode (relative contribution to total intensity)eval SVD eigenvalues
Returns: pr, I_n, eval
-
core.
ptycho_adjust_positions
(p)¶ - PTYCHO_ADJUST_POSITIONS
Returns: p
-
core.
ptycho_model_probe
(p)¶ - pout = ptycho_model_probe(p)
Returns: pout
-
core.
ptycho_plot_ptycho
(p, varargin)¶ - % PTYCHO_PLOT_PTYCHO plotting routine for ptychographic reconstructions
Parameters: p – p structure from a ptychographic reconstruction optionalParameters: - use_display – show plots (default: true)
- write_jpegs – write images to disk (default: false)
- final – show all error metrics for a final plot (default: false)
- save_path – change default save_path (p.save_path) for saving jpgs
EXAMPLES:core.ptycho_plot_ptycho(p);core.ptycho_plot_ptycho(p, ‘write_jpegs’, true);core.ptycho_plot_ptycho(p, ‘use_display’, false, ‘write_jpegs’, true);see also plotting.ptycho_show_recons
-
core.
ptycho_prepare_paths
(p, varargin)¶ - PTYCHO_PREPARE_PATHS Prepare paths and check defaults
Returns: p
-
core.
ptycho_prepare_scans
(p)¶ - PTYCHO_PREPARE_SCANS Load data from disk and prepare the scan for theptychographic reconstruction.
Parameters: p – p structure Returns: - p - p structure
- status - status flag
see also core.initialize_ptycho
-
core.
ptycho_recons
(p, prepare_only)¶ - OUT = PTYCHO_RECONS(P, PREPARE_ONLY = false)Runs the reconstruction using parameters in the structure p.
Parameters: p – p structure optionalParameters: prepare_only – stop after the data preparation; default: false out updated p structureReturns: out, status see also template_ptycho
-
core.
remote_cleanup
(p, completed)¶ - REMOTE_CLEANUPremove temporary files on the remote machine and move the reconstructionto the save path on the primary machine
Parameters: - p – p structure
- completed – boolean; true if reconstruction finished properly
Returns: status - status flag
see also core.ptycho_recons
-
core.
remote_status
(p)¶ - REMOTE_STATUSCheck the current status of the remote reconstruction
Parameters: p – p structure Returns: - p - updated p structure
- status - status flag
see also core.ptycho_recons
-
core.
run_data_preparator
(p)¶ - RUN_DATA_PREPARATORprepare the function handle and call the data preparator
Parameters: p – p structure Returns: p - updated p structure see also core.ptycho_prepare_scans
-
core.
run_engine
(p, eng)¶ - RUN_ENGINEcalls engine ‘eng’
Parameters: - p – p structure
- eng – name of the current engine
Returns: - p - update p structure
- fdb - feedback structure of the engine
see also core.ptycho_recons
-
core.
run_receiver
(p)¶ - RUN_RECEIVERmodify p structure and run ptycho_recons.
Parameters: p – p structure see also setup_remote_recons
-
core.
save_fig_ext
(file)¶ - SAVE_FIG_EXT Subsection of ptycho_show_recons to load reconstruction fileand save figures.
Parameters: file – path+file of the reconstruction see also core.save_results
-
core.
save_results
(p, fdb, final)¶ - SAVE_RESULTSSave reconstruction and parameter file
Parameters: - p – p structure
- fdb – feedback structure
- final – boolean; false for intermediate saving routines
Returns: p - p structure
see also core.ptycho_recons
-
core.
set_projections
(p, object, obj_update, scan_id)¶ - SET_PROJETIONS
Parameters: - p – p structure
- object – full-size object
- obj_update – container for object projections
- scan_id – ID of the current scan
Returns: object - updated object
+core/+FPM¶
-
core.FPM.
FP_prealign
(p)¶ - FP_PREALIGN prealign Fourier ptychographic dataFP_prealign is an alignment routine for Fourier ptychographicmeasurements. Due to the changes in frequency content, a globalregistration is not sufficient. We therefore sort the frames such thatimages with similar frequency content can be aligned.
Parameters: p – p structure taken from p.prealign:Parameters: - ctr_sh – shift the center before cropping the final dataset to asize
- crop_dft – crop the images by crop_dft before calculating the dftregistration
- axis – start the alignment procedure along specified axis or rotation (1 or 2)
- numiter – number of iterations
- rad_filt_min – discard positions below rad_filt_min
- rad_filt_max – discard positions beyond rad_filt_max
- mfiles – discard specific data points
- flat_corr – apply a flat-field correction
- filt_align – remove interpolation artifacts
- save_alignment – save final shifts / alignment
- load_alignment – overwrite alignment with previous alignment
- alignment_file – specify path+file
- plot – alignment turn on/off plotting during the alignment
Returns: p - p structure
see also utils.dftregistration
-
core.FPM.
align_data
(par, varargin)¶ - ALIGN_DATA align data along given pathalign_data is a helper function of FP_prealignIt uses utils.dftregistration to achieve a subpixel alignment
Parameters: par – FP_prealign structure Returns: par - updated FP_prealign structure see also core.FPM.FP_prealign
-
core.FPM.
sort_pos
(par, varargin)¶ - SORT_POS sort positionssort_pos is a helper function of FP_prealignit minimizes the path length, similar to the travelling salesman problem,albeit optimized for the peculiarities of a Fourier ptychographic scan
Parameters: par – FP_prealign structure optionalParameters: sort_type – ‘raster’, ‘round’ or ‘raster_lim’ Returns: par - updated FP_prealign structure see also core.FPM.FP_prealign
-
core.FPM.
sort_pos_radii
(par, varargin)¶ - SORT_POS_RADII sort positions along their radial distancesort_pos_radii is a helper function of FP_prealign
Parameters: par – final structure of FP_prealign Returns: par - updated FP_prealign structure see also core.FPM.FP_prealign
+core/private¶
-
core.
load_defaults
(file)¶ - LOAD_DEFAULTS load default p structure from file
Returns: p
-
core.
plot_raw_data
(p)¶ - PLOT_RAW_DATA Simple plotting routine for masked raw data
Parameters: p – p structure see also core.initialize_ptycho
-
core.
ptycho_exit
(p)¶ - PTYCHO_EXITonCleanup function for core.ptycho_recons
Parameters: p – p structure see also core.ptycho_recons
-
core.
write_procID
(p)¶ - WRITE_PROCIDwrites .dat files to utils/.tmp_procID to keep track of currentreconstructions
Parameters: p – p structure
+detector¶
-
detStorage
- DETSTORAGE Matlab class for convenient data access during the datapreparationReference page in Doc Centerdoc detector.detStorage
-
detector.
initialize_detector
(p, ii)¶ - INITIALIZE_DETECTOR run some checks and load the detector settings
Returns: p
-
detector.
load_detector
(p)¶ - LOAD_DETECTORload detector files as specified in p
Returns: p
+detector/+eiger¶
-
detector.eiger.
eiger
(p)¶ - EIGER settings for Eiger detectorThis file is called if you specify p.detector = ‘eiger’.
Parameters: p – p structure Returns: det - detector structure; later accessible via p.detectors(ii).params see also detector.load_detector
+detector/+eiger1p5M¶
-
detector.eiger1p5M.
convert
(scan, raw_data_path)¶ - function convert(scan, raw_data_path)convert .raw files to .cbf
-
detector.eiger1p5M.
convert2hdf5
(scan, raw_data_path)¶ - function convert(scan, raw_data_path)convert .raw files to .hdf5Inputsscan scan numberraw_data_path path to the raw data (optional)
-
detector.eiger1p5M.
eiger1p5M
(p)¶ - EIGER1P5M settings for Eiger 1.5M detectorThis file is called if you specify p.detector = ‘eiger1p5M’
Parameters: p – p structure Returns: det - detector structure; later accessible via p.detectors(ii).params see also detector.load_detector
+detector/+eiger4M_swing¶
-
detector.eiger4M_swing.
eiger4M_swing
(p)¶ - EIGER settings for Eiger detector at the SWING beamline (Soleil)This file is called if you specify p.detector = ‘eiger4M_swing’.
Parameters: p – p structure Returns: det - detector structure; later accessible via p.detectors(ii).params see also detector.load_detector
+detector/+eiger9M¶
-
detector.eiger9M.
eiger9M
(p)¶ - PILATUS settings for Pilatus detectorThis file is called if you specify p.detector = ‘pilatus’
Parameters: p – p structure Returns: det - detector structure; later accessible via p.detectors(ii).params see also detector.load_detector
-
detector.eiger9M.
get_dir_path
(p, ii)¶ - GET_DIR_PATH define directory structure.default scheme for data (scan 68) taken at cSAXS: S00000-00999/S00068/
Returns: data_path
+detector/+moench¶
-
detector.moench.
moench
(p)¶ - MOENCH settings for Moench detectorThis file is called if you specify p.detector = ‘moench’.
Parameters: p – p structure Returns: det - detector structure; later accessible via p.detectors(ii).params see also detector.load_detector
+detector/+oldeiger¶
-
detector.oldeiger.
oldeiger
(p)¶ - EIGER settings for Eiger detectorThis file is called if you specify p.detector = ‘eiger’.
Parameters: p – p structure Returns: det - detector structure; later accessible via p.detectors(ii).params see also detector.load_detector
+detector/+pco_nano¶
-
detector.pco_nano.
pco_nano
(p)¶ - PCO_NANO settings for PCO Edge Nano detectorThis file is called if you specify p.detector = ‘pco_nano’.
Returns: det
+detector/+pilatus¶
-
detector.pilatus.
pilatus
(p)¶ - PILATUS settings for Pilatus detectorThis file is called if you specify p.detector = ‘pilatus’
Parameters: p – p structure Returns: det - detector structure; later accessible via p.detectors(ii).params see also detector.load_detector
+detector/+prep_data¶
-
detector.prep_data.
get_dir_path
(p, ii)¶ - GET_DIR_PATH define directory structure.default scheme for data (scan 68) taken at cSAXS: S00000-00999/S00068/
Returns: data_path
-
detector.prep_data.
update_defaults
(p)¶ - UPDATE_DEFAULTS update parameters with default values that are crucial fora further processing of the data and look for overloaded functions
Returns: p
-
detector.prep_data.
update_funcs
(p, func)¶ - UPDATE_FUNCS Update prepare data functions with overloaded functions fromthe detector directory
Returns: p
+detector/+prep_data/+libDetXR¶
-
detector.prep_data.libDetXR.
libDetXR
(p)¶ - libDetXR prepares and exports data for libDetXR/ptyhon datapreparation.
Parameters: p – p structure Returns: - p - updated p structure
- fdb - feedback structure
see also core.run_data_preparator
+detector/+prep_data/+matlab_ps¶
-
detector.prep_data.matlab_ps.
check_burst
(p)¶ - CHECK_BURST check first file for burst scan
Returns: p
-
detector.prep_data.matlab_ps.
get_center
(p)¶ - GET_CENTER Estimate the center of the diffraction pattern
Returns: p
-
detector.prep_data.matlab_ps.
get_mask
(p)¶ - GET_MASK Mask saturated values as defined in the detector template
Parameters: p – p structure Returns: p - p structure
-
detector.prep_data.matlab_ps.
load_data
(p)¶ - LOAD_DATA prepare filenames and load data
Parameters: p – p structure Returns: p - p structure
-
detector.prep_data.matlab_ps.
mask_geometry
(p)¶ - MASK_GEOMETRY crop mask to fit defined readout geometriesif no geometry is specified, the full mask is used
Parameters: p – p structure Returns: p - p structure
-
detector.prep_data.matlab_ps.
matlab_ps
(p)¶ - MATLAB_PS - Matlab data preparator
Returns: p
-
detector.prep_data.matlab_ps.
postprocess
(p)¶ - POSTPROCESS postprocess functionsapplied to the 4D raw data
Parameters: p – p structure Returns: p - updated p structure
-
detector.prep_data.matlab_ps.
prep_data_matlab
(p, data, fmask)¶ - PREPARE_DATA_MATLAB prepares and normalizes data for matlab engines
Returns: p
-
detector.prep_data.matlab_ps.
prepare_data
(p)¶ - PREPARE_DATA prepare the raw data for the ptychographic reconstruction
Parameters: p – p structure Note:All (default) functions are located in +detector/+prep_data/+matlab_ps. If You wantto add a new detector, please create a new package directory(+detector_name) with a parameter file detector_name.m. Functions in apackage detectory directory will overload similar functions in the default directory.Returns: p - p structure
-
detector.prep_data.matlab_ps.
preprocess
(p)¶ - PREPROCESS preprocess functionse.g. select area before reading from disk
Parameters: p – p structure Returns: p - p structure
+detector/+virtual¶
-
detector.virtual.
get_center
(p)¶ - GET_CENTER Estimate the center of the diffraction pattern
Returns: p
-
detector.virtual.
load_data
(p)¶ - LOAD_DATA prepare filenames and load data
Returns: p
-
detector.virtual.
preprocess
(p)¶ - Academic License AgreementSource CodeIntroduction• 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 cSAXSptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter “PROGRAM”).Terms and Conditions of the LICENSE1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditionshereinafter 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, improvementsor 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 theLICENSEE’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 FORA PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHTHOLDERS 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 USEOF 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 samelicense as PROGRAM. The terms “academic, non-commercial”, as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken forprofit, 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 engagedin 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 intoanother 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, PaulScherrer 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 thenames 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 LICENSEEagrees 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 tomake 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 relateto 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 softwarein 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 beforethe courts of Zürich, Switzerland.
Returns: p
-
detector.virtual.
virtual
(p)¶ - Settings of a virtual detector that creates artificial dataThis file is called if you specify p.detector = ‘virtual’.
Returns: det
+detector/+virtual/private¶
-
detector.virtual.
create_object
(p)¶ - CREATE_OBJECT create object for artificial scansselect object with sim.simulation.dataset in your simulation template
Returns: obj
-
detector.virtual.
fourier_ptycho_data
(sim)¶ - FOURIER_PTYCHO_DATAPrepare and adjust artificial data for Fourier Ptychography
Returns: sim
-
detector.virtual.
randpoisson
(ltthresh)¶ - function out=randpoisson(inarray,thresh);outputs an array of poisson-distributed numbers with mean equal to inarrayFor inarray values above the threshold thresh (default=32),use a quick-and-dirty version of the gaussian method,but with negatives clipped to zeroJ.R. Fienup 10/22/99
Returns: does this k index over r(ind)
+engines¶
-
engines.
DM
(p)¶ - DM Difference-Map algorithmPublications 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, 338–343 (2009)
Returns: p, fdb
-
engines.
DM_MS
(p)¶ - [ p, fdb ] = DM_MS( p )
Returns: p, fdb
-
engines.
GPU
(p)¶ - engines.GPU is a function.[p_out, fdb] = GPU(p)
Returns: p_out, fdb
-
engines.
ML
(p)¶ - ML Maximum Likelihood refinementPublications most relevant to the Maximum Likelihood refinement+ M. Guizar-Sicairos and J. R. Fienup, “Phase retrieval with transversetranslation diversity: a nonlinear optimization approach,” Opt. Express 16, 7264-7278 (2008)+ P. Thibault and M. Guizar-Sicairos, “Maximum-likelihood refinement forcoherent diffractive imaging,” New J. Phys. 14, 063004 (2012).
Returns: p, fdb
-
engines.
ML_MS
(p)¶ - [ p, fdb ] = ML_MS( p )
Returns: p, fdb
-
engines.
ML_MS_rot
(p)¶ - UNTITLED7 Summary of this function goes hereDetailed explanation goes here
Returns: p, fdb
-
engines.
c_solver
(p)¶ - C_SOLVER external C++ code for DM and ML
Parameters: p – p structure 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, 338–343 (2009)Publications most relevant to the Maximum Likelihood refinement+ M. Guizar-Sicairos and J. R. Fienup, “Phase retrieval with transversetranslation diversity: a nonlinear optimization approach,” Opt. Express 16, 7264-7278 (2008)+ P. Thibault and M. Guizar-Sicairos, “Maximum-likelihood refinement forcoherent diffractive imaging,” New J. Phys. 14, 063004 (2012).Returns: - p - p structure
- fdb - feedback structure
-
engines.
presolver
(p)¶ - C_SOLVER external C++ code for DM in lower resolution
Returns: p, fdb
+engines/+DM¶
+engines/+GPU¶
-
engines.GPU.
GPU_DM
(self, par, cache, psi_dash, fourier_error, mode_id, iter)¶ - engines.GPU.GPU_DM is a function.[self, cache, psi_dash, fourier_error] = GPU_DM(self, par, cache, psi_dash, fourier_error, mode_id, iter)
Returns: self, cache, psi_dash, fourier_error
-
engines.GPU.
GPU_LSQML
(self, par, cache, fourier_error, mode_id, iter)¶ - engines.GPU.GPU_LSQML is a function.[self, cache, fourier_error] = GPU_LSQML(self, par, cache, fourier_error, mode_id, iter)
Returns: self, cache, fourier_error
-
engines.GPU.
GPU_PIE
(self, par, cache, fourier_error, mode_id, iter)¶ - engines.GPU.GPU_PIE is a function.[self, cache, fourier_error] = GPU_PIE(self, par, cache, fourier_error, mode_id, iter)
Returns: self, cache, fourier_error
-
engines.GPU.
Garray
(array)¶ - wrap the GPU functions for user so that CPU and GPU code is identical
Returns: array
-
engines.GPU.
Gfun
(varargin)¶ - Description: wrap the arrayfun function so that CPU and GPU code is identical
Returns: varargout
-
engines.GPU.
Ggather
(varargin)¶ - Description: wrap the GPU functions for user so that CPU and GPU code is identical
Returns: varargout
-
engines.GPU.
Gpagefun
(fun, varargin)¶ - wrapper around GPU pagefun function
Returns: out
-
engines.GPU.
Gzeros
(varargin)¶ - Description: wrap the GPU functions for user so that CPU and GPU code is identical
Returns: out
-
engines.GPU.
add_momentum_object
(self, cache, par, object_upd_sum, iter, fourier_error, beta_object)¶ - FUNCTION [self, cache] = add_momentum_object(self, cache, par, object_upd_sum, iter, fourier_error)speed up convergence by adding momentum / integral term into theupdate direction for the MLc method
Returns: self, cache
-
engines.GPU.
add_momentum_probe
(self, cache, par, probe_upd, iter, fourier_error, beta_probe)¶ - FUNCTION [self, cache] = add_momentum_probe(self, cache, par, probe_upd, iter, fourier_error)speed up convergence by adding momentum / integral term into theupdate direction for the MLc method
Returns: self, cache
-
engines.GPU.
apply_SVD_filter
(probe, Nmodes, mode)¶ - the variable probe (OPRP) codefind SVD decomposition and limit the probe into several orthogonalmodesadditional prior knowledge can be also included
Returns: probe, probe_evolution
-
engines.GPU.
apply_probe_contraints
(probe, mode)¶ - Academic License AgreementSource CodeIntroduction• 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 cSAXSptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter “PROGRAM”).Terms and Conditions of the LICENSE1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditionshereinafter 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, improvementsor 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 theLICENSEE’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 FORA PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHTHOLDERS 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 USEOF 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 samelicense as PROGRAM. The terms “academic, non-commercial”, as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken forprofit, 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 engagedin 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 intoanother 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, PaulScherrer 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 mixed coherent modes:P. Thibault and A. Menzel, Reconstructing state mixtures from diffraction measurements, Nature 494, 68–71 (2013). (doi: 10.1038/nature11806),for LSQ-ML methodM. Odstrcil, A. Menzel, M.G. Sicairos, Iterative least-squares solver for generalized maximum-likelihood ptychography, Optics Express, 2018for OPRP methodM. Odstrcil, P. Baksh, S. A. Boden, R. Card, J. E. Chad, J. G. Frey, W. S. Brocklesby, “Ptychographic coherent diffractive imaging with orthogonal probe relaxation.” Optics express 24.8 (2016): 8360-8369and/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).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 thenames 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 LICENSEEagrees 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 tomake 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 relateto 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 softwarein 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 beforethe courts of Zürich, Switzerland.
Returns: probe
-
engines.GPU.
apply_smoothness_constraint
(x, alpha)¶ - simple relaxed smoothness constaint
Returns: x
-
engines.GPU.
back_fourier_proj
(Psi, mode)¶ - Description: back propagate to the sample plane
Returns: Psi
-
engines.GPU.
calculate_conj_grad_dir
(self, x_n, x_0, h, W, cache)¶ - FUNCTION [x_0, h] = calculate_conj_grad_dir(self,x_n, x_0, h, W, cache)
Returns: x_0, h
-
engines.GPU.
check_gpu_memory
(show)¶ - FUNCTION memory_out = check_gpu_memory(show)Description: check and possibly report the available GPU memory
Returns: memory_out
-
engines.GPU.
clean_residua
(self, cache)¶ - FUNCTION self = clean_residua(self)use 2D FFT unwrapping to remove phase residua
Returns: self
-
engines.GPU.
extract_PCA
(x, N)¶ - [X,V] = extract_PCA(x, N)Extract N principal compenents of 3D array x using SVD
Returns: X, V
-
engines.GPU.
find_geom_correction
(self, cache, par, iter, best_mode_id)¶ - FUNCTION [self] = find_geom_correction(self,cache, par, iter,best_mode_id)use current probe positions estimates to update geometry model andimprove the new probe positions
Returns: self
-
engines.GPU.
flip_mirror_scan
(self, align_objects)¶ - FUNCTION self = flip_mirror_scan(self)join two scans obtained at 0 and 180 degrees to get a better estiamteof geometry errors
Returns: self
-
engines.GPU.
fwd_fourier_proj
(Psi, mode)¶ - FUNCTION Psi = fwd_fourier_proj(Psi, mode)Description: forward propagation
Returns: Psi
-
engines.GPU.
get_close_indices
(self, cache, par)¶ - FUNCTION [indices_out, scan_ids_out] = get_close_indices(self, cache, par )Description: simple based method to select indices for DM!! GPU needs the sets to be with similar , ideally the same sizes !!!
Returns: indices_out, scan_ids_out
-
engines.GPU.
get_forward_model
(self, obj_proj, par, cache, g_ind, p_ind, scan_ids, layer_ids)¶ - Academic License AgreementSource CodeIntroduction• 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 cSAXSptychography MATLAB package computer software program and associated documentation furnished hereunder (hereafter “PROGRAM”).Terms and Conditions of the LICENSE1. LICENSOR grants to LICENSEE a royalty-free, non-exclusive license to use the PROGRAM for academic, non-commercial purposes, upon the terms and conditionshereinafter 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, improvementsor 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 theLICENSEE’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 FORA PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. IN NO EVENT SHALL THE LICENSOR, THE AUTHORS OR THE COPYRIGHTHOLDERS 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 USEOF 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 samelicense as PROGRAM. The terms “academic, non-commercial”, as used in this Agreement, mean academic or other scholarly research which (a) is not undertaken forprofit, 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 engagedin 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 intoanother 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, PaulScherrer 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 thenames 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 LICENSEEagrees 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 tomake 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 relateto 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 softwarein 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 beforethe courts of Zürich, Switzerland.
Returns: self, probe, obj_proj, psi
-
engines.GPU.
get_fourier_error
(modF, aPsi, Noise, Mask, likelihood)¶ - FUNCTION Err = get_fourier_error(modF, aPsi, Noise,Mask, likelihood)Description: fast calculation of the Fourier plane
Returns: Err
-
engines.GPU.
get_mask
(self, mask_indices, ind)¶ - FUNCTION mask = get_mask(self,mask_indices, ind)Description: get self.mask for current list of indices ind
Returns: mask
-
engines.GPU.
get_modulus
(self, cache, ind, move_to_gpu, bunch_id)¶ - FUNCTION modF = get_modulus(self, cache, ind, move_to_gpu, bunch_id)load and prepare data for current positions ind
Returns: modF
-
engines.GPU.
get_noise
(self, par, g_ind)¶ - FUNCTION noise = get_noise(self, par, g_ind)load and prepare noise estimate for current positions ind
Returns: noise
-
engines.GPU.
get_nonoverlapping_indices
(self, cache, par)¶ - FUNCTION [indices_out, scan_ids_out] = get_nonoverlapping_indices(self, cache, par )Description: a heuristic based method to select pseudorandom indices of non overlapping regionsNote: It can be slow for large number of scanning positions
Returns: indices_out, scan_ids_out
-
engines.GPU.
get_object_extent
(probe_size, probe_positions, extra)¶ - FUNCTION Np_o_new = get_object_extent(probe_size, probe_positions, extra)Description: estimate the minimal area surrounding all the probe positions
Returns: Np_o_new
-
engines.GPU.
get_optimal_LSQ_step
(self, chi, dO, dP, O, P, p_ind, par)¶ - find optimal step in the LSQ sense
Returns: beta_probe, beta_object
-
engines.GPU.
get_reciprocal_model
(self, Psi, modF, mask, iter, g_ind, par, cache)¶ - FUNCTION [aPsi, aPsi2, cache, self] = get_reciprocal_model(self, Psi, modF, mask,iter, g_ind, par, cache)Description: get estimate of the measured intensity from given electricfield Psi
Returns: aPsi, aPsi2, cache, self
-
engines.GPU.
get_scanning_indices
(self, cache, par)¶ - FUNCTION [indices_out, scan_ids_out] = get_scanning_indices(self, cache, par )Description: simple based method to select indices for DM
Returns: indices_out, scan_ids_out
-
engines.GPU.
get_variable_probe
(probe, probe_evolution, p_ind)¶ - FUNCTION probe = get_variable_probe(probe, probe_evolution, p_ind)Description: calculate variable probe for given mean/var probe and its evolution inputs
Returns: probe
-
engines.GPU.
get_views
(object, obj_proj, layer, ll, ii, cache, scan_ids, skip_ind)¶ - FUNCTION obj_proj = get_views(object, obj_proj,layer,ll, ii, cache, scan_ids, skip_ind)Description: estimate the minimal area surrounding all the probe positions
Returns: obj_proj
-
engines.GPU.
gpu_wrapper
(param)¶ - FUNCTION param= gpu_wrapper(param)Description: wrap the GPU functions for user so that CPU and GPU code is identical
Returns: param
-
engines.GPU.
gradient_NF_propagation_solver
(self, psi, xi, cache, ind)¶ - FUNCTION self = gradient_NF_propagation_solver(self,psi,xi, cache, ind)Description: update estimate of the nearfield propagation distance based on thecurrent update of the wavefront
Returns: self
-
engines.GPU.
gradient_descent_xi_solver
(self, modF, aPsi2, R, mask, ind, beta_chi, cache, Psi, chi)¶ - FUNCTION [beta_chi, find_chi_step] = gradient_descent_xi_solver(self,modF, aPsi2, R,mask, ind, beta_chi, cache, Psi, chi)Description: solve optimal update step for the Poisson noise method
Returns: beta_chi, find_chi_step
-
engines.GPU.
gradient_fourier_position_solver
(xi, O, P, mode, ind)¶ - FUNCTION mode = gradient_fourier_position_solver(xi,O,P,mode, ind)Description: solve position errors in the Fourier space
Returns: mode
-
engines.GPU.
gradient_position_solver
(self, xi, O, P, ind, iter, cache)¶ - FUNCTION pos_update = gradient_position_solver(xi,O,P,ind)Description: solve position errors in the real space
Returns: pos_update, cache
-
engines.GPU.
gradient_projection_solver
(self, xi, O, P, dO, dP, p_ind, par, cache)¶ - FUNCTION [beta_p, beta_o] = gradient_projection_solver(self,xi,O,P,dO,dP,p_ind,par, cache)Description: 1D search for the optimal step in the gradients descent-like methods
Returns: beta_p, beta_o
-
engines.GPU.
initial_checks
(self, par)¶ - FUNCTION [self,par] = initial_checks(self, par)Description: check if the inputs are valid or try to correct them
Returns: self, par
-
initialize
- FUNCTION [param] = initializelist of default parameters
-
engines.GPU.
initialize_solver
(self, par)¶ - FUNCTION [self, cache] = initialize_solver(self,par)initialize GPU ptycho reconstruction, generate cache values, fftshiftdata, etc
Returns: self, cache
-
engines.GPU.
is_method
(par, method)¶ - FUNCTION match = is_method(par, method)try if the method match or at least partially match
Returns: match
-
engines.GPU.
is_used
(param, extension)¶ - FUNCTION used = is_used(param, extension)Description: Check if the extension/extensions is set to be usedExample: is_used(param, {‘ext1’, ‘ext2’})
Returns: used
-
engines.GPU.
modulus_constraint
(modF, aPsi, Psi, mask, noise, relax_noise, likelihood, R_offset)¶ - FUNCTION [chi,R] = modulus_constraint(modF,aPsi ,Psi, mask, noise, relax_noise,likelihood , R_offset)Description: universal fast relaxed modulus constraint
Returns: chi, R
-
engines.GPU.
move_from_gpu
(self, move_from_GPU)¶ - FUNCTION self = move_from_gpu(self, move_from_GPU)Description: move reconstruction back from GPU to RAM
Returns: self
-
engines.GPU.
move_to_gpu
(self, cache, move_data, split_data)¶ - FUNCTION self = move_to_gpu(self,cache, move_data, split_data)Description: move reconstruction from RAM to GPU
Returns: self, cache
-
engines.GPU.
online_FSC_estimate
(self, par, cache, score_0, iter)¶ - score = online_FSC_estimate(self, par, cache, score_0, iter)compare two scans and estimate FSC and other statistics
Returns: score
-
engines.GPU.
plot_background_intensity
(self, probe, background)¶ - FUNCTION plot_background_intensity(self,probe, background)
-
engines.GPU.
plot_frc_analysis
(score, par)¶ - FUNCTION plot_frc_analysis(score, par)plot evolution of the resolution and SNR estimated from the FRC
-
engines.GPU.
plot_geom_corrections
(self, mode, object, iter, par, cache)¶ - FUNCTION plot_geom_corrections(self, mode, object, iter, par, cache)plot positiones updates
-
engines.GPU.
plot_intensity_corr
(self)¶ - FUNCTION plot_geom_corrections(self, mode, object, iter, par, cache)plot intensity correction evolution
-
engines.GPU.
plot_object_modes
(self, cache, ROI)¶ - FUNCTION plot_object{ii}(self, object{ii},par, id, show_ROI, scales, ROI)plot incoherent object{ii} of object{ii} or the probes
-
engines.GPU.
plot_probe_modes
(self, par)¶ - FUNCTION plot_probe(self, probe,par, id, show_ROI, scales, ROI)plot incoherent probe of object or the probes
-
engines.GPU.
plot_results
(self, cache, par, fourier_error, probe_positions)¶ - FUNCTION plot_results(self, cache, par, fourier_error,probe_positions)Description: show current reconstruction and errors during ptychography
-
engines.GPU.
plot_variable_probe
(self, par)¶ - FUNCTION plot_variable_probe(self, par)plot SVD decomposition of the probes to show their differences
-
engines.GPU.
precalculate_ROI
(self, cache, probe)¶ - FUNCTION plot_variable_probe(self, par)Description: precalculate the ROIs area for faster calculations
Returns: cache
-
engines.GPU.
prepare_flyscan_positions
(self, par)¶ - engines.GPU.prepare_flyscan_positions is a function.self = prepare_flyscan_positions(self, par)
Returns: self
-
engines.GPU.
ptycho_solver
(self, par, cache)¶ - FUNCTION plot_variable_probe(self, par)Description: the main loop of ptychography. Call the selected engine
Returns: outputs, fourier_error, fsc_score
-
engines.GPU.
rescale_inputs
(self, Np_p_new, rescale_data)¶ - FUNCTION self = rescale_inputs(self, Np_p_new, rescale_data)multigrid scheme method ,INPUTS:Np_p_new - new size of the rescaled datasetrescale_data = true -> rescale also data + mask + noise arrays
Returns: self
-
engines.GPU.
set_views
(object, object_update, layer, ll, ii, cache, scan_ids, skip_ind)¶ - FUNCTION object = set_views(object, object_update, layer,ll, ii, cache, scan_ids, skip_ind)Description: Reduce stack of projections into one shared object
Returns: object
-
engines.GPU.
set_views_rc
(obj_update, obj_illum, psi_tmp, aprobe, layer, ll, ii, cache, scan_ids, skip_ind)¶ - FUNCTION [obj_update,obj_illum] = set_views_rc(obj_update,obj_illum, psi_tmp,aprobe,layer,ll, ii, cache, scan_ids, skip_ind, Nobjects)Description: update complex and real object at once
Returns: obj_update, obj_illum
-
engines.GPU.
update_variable_probe
(self, probe, probe_evolution, m_probe_update, probe_update, obj_proj, chi, weights, p_ind, g_ind, cache, par)¶ - FUNCTION [probe, probe_evolution] = update_variable_probe(self,probe, probe_evolution, m_probe_update,probe_update, obj_proj, chi, weights, p_ind, g_ind, cache, par)approximation of the OPRP method to get only the first orthogonalvector describing the probe
Returns: probe, probe_evolution
+engines/+GPU/private¶
-
engines.GPU.
cat_struct
(struct, name, ind)¶ - FUNCTION array = cat_struct( struct, name, ind)
Returns: array
-
engines.GPU.
distmat
(a, varargin)¶ - DISTMAT Compute a Distance Matrix for One or Two Sets of PointsCopyright (c) 2015, Joseph KirkAll rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions aremet:* Redistributions of source code must retain the above copyrightnotice, this list of conditions and the following disclaimer.* Redistributions in binary form must reproduce the above copyrightnotice, this list of conditions and the following disclaimer inthe documentation and/or other materials provided with the distributionTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THEIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSEARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BELIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, ORCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OFSUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESSINTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER INCONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THEPOSSIBILITY OF SUCH DAMAGE.
Returns: dmat
-
engines.GPU.
fft2_safe
(x)¶ - FUNCTION x = fft2_safe(x)wrapper around fft2, in case of low memory it will try to repeatNtimes before giving up
Returns: x
-
engines.GPU.
find_reconstruction_ROI
(positions, Np_o, Np_p)¶ - FUNCTION [oROI, oROI_vec, sub_px_shift] = find_reconstruction_ROI( positions,Np_o, Np_p )Description: precalculate the reconstruction regions for CPU and GPU
Returns: oROI, oROI_vec, sub_px_shift
-
engines.GPU.
fourier_ring_correlation
(object_1, object_2, varargin)¶ - FUNCTION [score, object{1}, object{2}] = fourier_ring_correlation(object{1}, object{2}, varargin)simplified but faster version of the FRC code
Returns: score, object
-
engines.GPU.
fsvd
(A, k, i, usePowerMethod)¶ - — help for svd —SVD Singular value decomposition.[U,S,V] = SVD(X) produces a diagonal matrix S, of the samedimension as X and with nonnegative diagonal elements indecreasing order, and unitary matrices U and V so thatX = U*S*V’.S = SVD(X) returns a vector containing the singular values.[U,S,V] = SVD(X,0) produces the “economy size”decomposition. If X is m-by-n with m > n, then only thefirst n columns of U are computed and S is n-by-n.For m <= n, SVD(X,0) is equivalent to SVD(X).[U,S,V] = SVD(X,’econ’) also produces the “economy size”decomposition. If X is m-by-n with m >= n, then it isequivalent to SVD(X,0). For m < n, only the first m columnsof V are computed and S is m-by-m.See also SVDS, GSVD.Reference page in Doc Centerdoc svdOther functions named svdcodistributed/svd frd/svd gpuArray/svd sym/svd
Returns: U, S, V
-
engines.GPU.
get_ROI
(mask, extent, type)¶ - FUNCTION [ROI, range, coord] = get_ROI(mask, extent, type)Description: find optimal rectange containing the mask
Returns: ROI
-
engines.GPU.
get_img_grad
(img)¶ - FUNCTION [dX, dY] = get_img_grad(img)Description: get vertical and horizontal gradient of the image
Returns: dX, dY
-
engines.GPU.
ifft2_safe
(x)¶ - FUNCTION x = ifft2_safe(x)Description: wrapper around fft2, in case of low memory it willtry to repeat 5-times before giving up
Returns: x
-
engines.GPU.
imagesc_hsv
(varargin)¶ - FUNCTION [cax_out, rgb_data] = imagesc_hsv(varargin)Description: imagesc for drawing complex number arrays
Returns: cax_out, rgb_data
-
engines.GPU.
intersections
(x1, y1, x2, y2, robust)¶ - INTERSECTIONS Intersections of curves.Computes the (x,y) locations where two curves intersect. The curvescan be broken with NaNs or have vertical segments.Example:[X0,Y0] = intersections(X1,Y1,X2,Y2,ROBUST);where X1 and Y1 are equal-length vectors of at least two points andrepresent curve 1. Similarly, X2 and Y2 represent curve 2.X0 and Y0 are column vectors containing the points at which the twocurves intersect.ROBUST (optional) set to 1 or true means to use a slight variation of thealgorithm that might return duplicates of some intersection points, andthen remove those duplicates. The default is true, but since thealgorithm is slightly slower you can set it to false if you know thatyour curves don’t intersect at any segment boundaries. Also, the robustversion properly handles parallel and overlapping segments.The algorithm can return two additional vectors that indicate whichsegment pairs contain intersections and where they are:[X0,Y0,I,J] = intersections(X1,Y1,X2,Y2,ROBUST);For each element of the vector I, I(k) = (segment number of (X1,Y1)) +(how far along this segment the intersection is). For example, if I(k) =45.25 then the intersection lies a quarter of the way between the linesegment connecting (X1(45),Y1(45)) and (X1(46),Y1(46)). Similarly forthe vector J and the segments in (X2,Y2).You can also get intersections of a curve with itself. Simply pass inonly one curve, i.e.,[X0,Y0] = intersections(X1,Y1,ROBUST);where, as before, ROBUST is optional.
Returns: x0, y0, iout, jout
-
engines.GPU.
near_field_evolution
(u_0, z, lambda, extent, use_ASM_only)¶ - FUNCTION [u_1, H, h, dH] = near_field_evolution(u_0, z, lambda, extent, use_ASM_only)Description: nearfield evolution function, it automatically swithcbetween ASM and Fraunhofer propagation
Returns: u_1, H, h, dH
-
engines.GPU.
ortho_modes
(x)¶ - FUNCTION x = ortho_modes(x)Description: return orthogonal modes, without any normalization , expect cells
Returns: x
-
engines.GPU.
ortho_modes_eig
(x)¶ - FUNCTION x = ortho_modes_eig(x)Description: orthogonal modes using eigen values
Returns: x
-
engines.GPU.
regulation_multilayers
(self, par, cache)¶ - FUNCTION self = regulation_multilayers(self, par, cache)Description: try to avoid ambiguity in yhr multilayer reconstruction
Returns: self
-
engines.GPU.
shift_probe
(img, shift)¶ - img = shift_probe(img, shift)subpixel probe shifting
Returns: img
-
engines.GPU.
shift_probe_fft
(img, shift)¶ - img = shift_probe_fft(img, shift)fast shifting in fourier space
Returns: img
-
engines.GPU.
show_spatial_distribution
(pos, values, symmetrize, plot_points, range, scale)¶ - FUNCTION show_spatial_distribution(pos, values, symmetrize, plot_points, range, scale )Description: show spatial distribution of some variable, you can also usescatter or scatter_hsv
+engines/+ML¶
-
engines.ML.
brent
(func, x0, dx, a1, a, a2, f1, f, f2, varargin)¶ - one-dimensional minimization by parabolic interpolation & goldensection (does not use the gradient)[a,f] = brent(func,x0,dx,a1,a,a2,f1,f,f2,varargin)func = string name of objective functionx0 = starting point of linesearchdx = direction of linesearcha1,a,a2 = bracketing triplet of steplengths (a1<a<a2)f1,f,f2 = objective function at steplengths a1, a, & a2a = output as final steplengthf = output as objective function at final steplength
Returns: a, f
-
engines.ML.
cgmin1
(func, x, itmax, ftol, xtol, varargin)¶ - conjugate-gradient optimization routineNOTE: linesearch subroutines do not use the gradient[x] = cgmin1(func,x,itmax,ftol,xtol,varargin)func = string name of objective function which returns both theobjective function value and the gradientx = input as initial starting point and output as final pointitmax = maximum number of iterations (empty for default = 50)ftol = relative function tolerance (empty for default = 1e-3)xtol = absolute solution tolerance (empty for default = 1e-3)varargin = extra variables required by objective functionDISCLAIMER: This code is not intended for distribution. I have manyversions of this code and am constantly revising it. I believe thisversion is working properly. However, I will not vouch for the code.Anyone using the code for thesis research has a responsibility to gothrough the code line-by-line and read relevant references to understandthe code completely. In my opinion, you have two options if you want topublish results obtained with the code: (i) go through the code line-by-line and read relevent references to understand how the code works and makesure it is working properly for your application, or (ii) I can sit downwith you an go through this code and the additional code that you havewritten to go along with it and make sure it is working properly. Option(i) is preferred, and I ask that you do NOT acknowledge me in print (first,it would be more appropriate for you to reference “Numerical Recipes”,and second, I prefer not to be named in a paper with which I do not havedetailed knowledge). If you decide to go with option (ii), I would expectto learn the details of your research and be included in the author list.Sam Thurman, May 9, 2005
Returns: x, p
-
engines.ML.
gradient_ptycho
(xopt, p, fmag2, initialerror, fnorm, creg, smooth_gradient)¶ - Main code to compute error metric and gradientJan 09 2013
Returns: func, grad, p
-
engines.ML.
linesearch
(func, x0, f0, df0, dx, a, varargin)¶ - linesearch routine (does not use the gradient)[x,f,a,flg] = linesearch(func,x0,f0,df0,dx,a,varargin)func = string name of objective functionx0 = starting point of searchf0 = objective function at x0df0 = derivative of objective function along dx at x0dx = direction of linesearcha = steplength input as guess output as takenx = final point of searchf = objective function at final pointflg = indicates how step was determined (0 for Armijo step, 1 forbracketing and refining a minimum)
Returns: x, f, a, flg
+engines/+ML_MS¶
-
engines.ML_MS.
fun_ramp_unwrap
(object, asize)¶ - This function (1) removes ramp and (2) unwrap
Returns: object_phase_unwrap
-
engines.ML_MS.
gradient_ptycho_MS
(xopt, p, fmag, fmag2, fmask, ...)¶ - This function is intended to be only a distributor for either only ‘func’, or ‘func’ and‘grad’ calculation.
Returns: func, grad, p
+engines/+c_solver¶
-
engines.c_solver.
prep_initial_conditions
(p)¶ - PREP_INITIAL_CONDITIONS prepares the initial_conditions file for thereconstruction with external C++ codesave2hdf5 is used to save the required datasets and attributes to an h5 file
Parameters: p – p structure see also engines.c_solver
-
engines.c_solver.
prepare_external_call
(p, fdb)¶ - Call the external reconstruction program
Returns: p, fdb
+scans¶
-
scans.
get_filenames_cSAXS
(p)¶ - GET_FILENAMES_CSAXS compile filenames of raw data filesreceives
Returns: p
-
scans.
get_queue
(p, update)¶ - GET_QUEUE call queue functions in package directories
Returns: p, status
-
scans.
read_metadata
(p)¶ - READ_METADATA load meta data and overwrite previous settings
Returns: p
-
scans.
read_positions
(p)¶ - READ_POSITIONS load positions
Returns: p
+scans/+meta¶
-
scans.meta.
artificial
(p)¶ - SPEC load meta data from a spec file
Returns: p
-
scans.meta.
nexus
(p)¶ - NEXUS load meta data from a nexus file
Returns: p
-
scans.meta.
spec
(p)¶ - SPEC load meta data from a spec file
Returns: p
+scans/+positions¶
-
scans.positions.
load_from_file
(p)¶ - Load positions from reconstruction file, useful e.g. when positionrefinement was done in the reconstruction used as a source file
Returns: p
-
scans.positions.
matlab_pos
(p)¶ - MATLAB_POS calculate scan parameters based on the values set in thetemplate
Returns: p
-
scans.positions.
nexus_soleil
(p)¶ - NEXUS_SOLEIL load motor positions from a nexus file
Returns: p
-
scans.positions.
orchestra
(p)¶ - OMNY Load positions from Orchestra scan file
Returns: p
-
scans.positions.
spec
(p)¶ - SPEC load motor positions from spec
Returns: p
+scans/+queue¶
+scans/+queue/+check_queue¶
-
scans.queue.check_queue.
lockfile
(p)¶ - UNTITLED3 Summary of this function goes hereDetailed explanation goes here
Returns: p, status_ok
-
scans.queue.check_queue.
omny
(p)¶ - OMNY Check for file queue for omny
Parameters: p – p structure Returns: - p - p structure
- status_ok - status flag
see also scans.get_queue
-
scans.queue.check_queue.
remote_queue
(p)¶ - REMOTE_QUEUE
Returns: p, status_ok
+scans/+queue/+check_queue/private¶
-
scans.queue.check_queue.
ptycho_parse_omny_dat
(filename, p)¶ - p = ptycho_parse_omny_dat(filename,p)It parses dat files from OMNY or flOMNI to modify a ptychographyp.structure. This allows for instance to change the scan number oranother field. It also allows to define fields that do not exist.Inputsfilename Filename with path of the dat filep Optional input, if it is given the output will be equal to pin all fields that are not modifiedOutputp_out Structure with new, or modified fields.
Returns: p_out
tests¶
-
CPU_binning_test
- TEST TEMPLATE FOR FUNTIONALITY CHECK OF CPU ENGINES1) call standard template to get fresh settings defaults2) generate artificial data that should serve as a standart test “sample”3) call GPU engine with different basic functionalities and test if all still works!! THESE TEST ARE ONLY USEFUL TO FIND CRASHES IN THE CODE, QUALITY DETERIORATION STILL NEED TO BE MEASURED !!
-
CPU_engines_test
- TEST TEMPLATE FOR FUNTIONALITY CHECK OF CPU ENGINES1) call standard template to get fresh settings defaults2) generate artificial data that should serve as a standart test “sample”3) call GPU engine with different basic functionalities and test if all still works!! THESE TEST ARE ONLY USEFUL TO FIND CRASHES IN THE CODE, QUALITY DETERIORATION STILL NEED TO BE MEASURED !!
-
CPU_multilayer_test
- TEST TEMPLATE FOR FUNTIONALITY CHECK OF MULTILAYER EXTENSION IN CPU ENGINES1) call standard template to get fresh settings defaults2) generate artificial data that should serve as a standart test “sample”3) call GPU engine with different basic functionalities and test if all still works!! THESE TEST ARE ONLY USEFUL TO FIND CRASHES IN THE CODE, QUALITY DETERIORATION STILL NEED TO BE MEASURED !!
-
GPU_engines_test
- TEST TEMPLATE FOR FUNTIONALITY CHECK IN GPU ENGINES1) call standard template to get fresh settings defaults2) generate artificial data that should serve as a standart test “sample”3) call GPU engine with different basic functionalities and test if all still works!! THESE TEST ARE ONLY USEFUL TO FIND CRASHES IN THE CODE, QUALITY DETERIORATION STILL NEED TO BE MEASURED !!
-
GPU_multilayer_3D_test
- TEST TEMPLATE FOR FUNTIONALITY CHECK OF MULTILAYER EXTENSION IN GPU ENGINES1) call standard template to get fresh settings defaults2) generate artificial data that should serve as a standart test “sample”3) call GPU engine with different basic functionalities and test if all still works!! THESE TEST ARE ONLY USEFUL TO FIND CRASHES IN THE CODE, QUALITY DETERIORATION STILL NEED TO BE MEASURED !!
-
GPU_multilayer_test
- TEST TEMPLATE FOR FUNTIONALITY CHECK OF MULTILAYER EXTENSION IN GPU ENGINES1) call standard template to get fresh settings defaults2) generate artificial data that should serve as a standart test “sample”3) call GPU engine with different basic functionalities and test if all still works!! THESE TEST ARE ONLY USEFUL TO FIND CRASHES IN THE CODE, QUALITY DETERIORATION STILL NEED TO BE MEASURED !!
-
run_test
- Prepare the reconstruction
-
test_ML3D_data
- template for artificial data generation for tests of multilayerreconstructions
-
test_ML_data
- template for artificial data generation for tests of multilayerreconstructions
-
test_data
- template for artificial data generation for standard methods tests
tests/temp¶
utils¶
-
utils/aligned_FSC(file1, file2, params)
- [resolution stat] = aligned_FSC(file1,file2,params)Receives two filenames with path for ptychography reconstructions and astructure with parameters. The routine reads the reconstructions, matchesthe linear phase between them, registers the images, and returns theresolution estimates based on first and last crossing of the FSC with thethreshold.References relevant to this code:For using this FSC code with ptychography: J. Vila-Comamala, et al., “Characterization of high-resolution diffractive X-ray optics by ptychographic coherent diffractive imaging,” Opt. Express 19, 21333-21344 (2011).For subpixel alignment: M. Guizar-Sicairos, et al., “Efficient subpixel image registration algorithms,” Opt. Lett. 33, 156 (2008).For matching of phase ramp by approximate least squared error: M. Guizar-Sicairos, et al., “Phase tomography from x-ray coherent diffractive imaging projections,” Opt. Express 19, 21345-21357 (2011).Outputs:resolution A two element variable that contains the resolutionobtained from first and last crossing of the FSC curve withthe threshold curve.stat structure containing other statistics such asspectral signal to noise ratio (SSNR), average SNR and area under FSC curveInputs:file1 Filename with path of reconstruction 1file2 Filename with path of reconstruction 2params Structure with parameters as describred belowparams.flipped_images Flip one input image horizontally (= true or false).Useful when comparing 0 and 180 degree projectionsin tomography (default = false).params.crop = ‘’; for using the default half size of the probe= ‘manual’ for using GUI to select region. This will display the range, e.g. {600:800, 600:800}= {600:800, 600:800} for custom vertical and horizontal cropping, respectivelyparams.GUIguess To click for an initial alignment guess, if used it ignoresthe values of params.guessx and params.guessy (default= false)params.guessxparams.guessy An intial guess for x and y alignment (default = [])params.remove_ramp Try to remove linear phase from whole image before initialalignment (default = true)params.image_prop = ‘complex’= ‘phasor’ (phase with unit amplitude, default)= ‘phase’ (Note: phase should not be used if there is phase wrapping)params.taper = 20 (default) Pixels to taper images - Increase until the FSC does not change anymoreparams.plotting Display plots (default = false)params.dispfsc Display FSC plot (default = true)params.SNRt SNR for FSC threshold curveSNRt = 0.2071 for 1/2 bit threshold for resolution of the average of the 2 imagesSNRt = 0.5 for 1 bit threshold for resolution of each individual image (default)params.thickring Thickness of Fourier domain ring for FSC in pixels (default = 1)params.freq_thr To ignore the crossings before freq_thr for determining resolution (default 0.02)params.out_fn Filename of output of jpeg for FSC
Returns: resolution stat
-
utils/break_check(filename)
- [] = break_check(filename)
-
calculate_round_roi
- Data path info
-
change_file_names
- change_file_names.msmall script to remove lock files from certain scans
-
utils/check_option(p, option_name, required_value)
- CHECK_OPTIONcheck if required option exists and is equal to the given value,otherwise return false
Returns: out_value
-
utils/check_scan_interruption(specLogFile, scanno)
- Detect an interruption of the scan in the Log fileFrom spec compile post_scan.mac= 1, if the scan is ready for processing= 0, if the scan was interrupted and is not yet repeated, or if the scanis being repeated now
Returns: out
-
utils/create_file_queue(start, stop, step, varargin)
- CREATE_FILE_QUEUE create directories and .dat files for a file queueonly needed if OMNY/flOMNI is not available
Parameters: - start – start scan number
- stop – stop scan number
- step – reconstruction bundle size
optional given as name/value pairParameters: - dirpath – path to the .dat files directory; default: ‘../’
- prop – structure with parameters that need to be saved to the .dat file
- prop_name – structure name; default: ‘p’
EXAMPLE:s.lockfile = false;s.energy = 6.2015;s.check_2_detpos = 588.734;s.check_nextscan_started = 1;create_file_queue(646, 650, 2, ‘prop’, s)
-
find_file_names
- change_file_names.msmall script to remove lock files from certain scans
-
utils/find_ptycho_filename(base_analysis_path, varargin)
- filename_with_path = find_ptycho_filename(base_analysis_path,scan_number,fileprefix,filesuffix)Looks for a ptychography reconstruction name inside the path given asinitial argument. I will look in the folder given and also try withadding analysis. If the scan_number is given it will compile an analysisfolder and look for it. e.g. find_ptycho_filename(‘~/Data10’,235);Use verbose(2) in order to see all directories and names attempted.Inputsbase_analysis_path % String with path to start lookingscan_number % (optional) Number with the scan number, used tocompile folderfileprefix % String specifying the starting of the namefilesuffix % String specifying the ending of the name
Returns: filename_with_path
-
utils/fun_align_img(img1, img2, asize, pix)
- [resolution] = aligned_FSC(file1,file2,params)Receives two filenames with path for ptychography reconstructions and astructure with parameters. The routine reads the reconstructions, matchesthe linear phase between them, registers the images, and returns theresolution estimates based on first and last crossing of the FSC with thethreshold.References relevant to this code:For using this FSC code with ptychography: J. Vila-Comamala, et al., “Characterization of high-resolution diffractive X-ray optics by ptychographic coherent diffractive imaging,” Opt. Express 19, 21333-21344 (2011).For subpixel alignment: M. Guizar-Sicairos, et al., “Efficient subpixel image registration algorithms,” Opt. Lett. 33, 156 (2008).For matching of phase ramp by approximate least squared error: M. Guizar-Sicairos, et al., “Phase tomography from x-ray coherent diffractive imaging projections,” Opt. Express 19, 21345-21357 (2011).Outputs:resolution A two element variable that contains the resolutionobtained from first and last crossing of the FSC curve withthe threshold curve.Inputs:file1 Filename with path of reconstruction 1file2 Filename with path of reconstruction 2params Structure with parameters as described belowparams.flipped_images Flip one input image horizontally (= true or false).Useful when comparing 0 and 180 degree projectionsin tomography (default = false).params.crop = ‘’; for using the default half size of the probe= ‘manual’ for using GUI to select region. This will display the range, e.g. {600:800, 600:800}= {600:800, 600:800} for custom vertical and horizontal cropping, respectivelyparams.GUIguess To click for an initial alignment guess, if used it ignoresthe values of params.guessx and params.guessy (default= false)params.guessxparams.guessy An intial guess for x and y alignment (default = [])params.remove_ramp Try to remove linear phase from whole image before initialalignment (default = true)params.image_prop = ‘complex’= ‘phasor’ (phase with unit amplitude, default)= ‘phase’ (Note: phase should not be used if there is phase wrapping)params.taper = 20 (default) Pixels to taper images - Increase until the FSC does not change anymoreparams.plotting Display plots (default = false)params.dispfsc Display FSC plot (default = true)params.SNRt SNR for FSC threshold curveSNRt = 0.2071 for 1/2 bit threshold for resolution of the average of the 2 imagesSNRt = 0.5 for 1 bit threshold for resolution of each individual image (default)params.thickring Thickness of Fourier domain ring for FSC in pixels (default = 1)params.freq_thr To ignore the crossings before freq_thr for determining resolution (default 0.02)params.out_fn Filename of output of jpeg for FSC
Returns: img1_aligned, img2_aligned, delta_all
-
utils/integrate_frames(base_path, scan_num, plotfigure, det_num, savedata, maskfile)
- 14-11-2012Integrates frames from a loopscanSyntax:[int] = integrate_frames(base_path,scan_num,plotfigure,det_num,savedata,maskfilename)Needed parameters: base_path (e.g. ‘~/Data10/’)scan_num (scan number)Optional parameters: plotfigure (figure number for fial plot, 0 for no plotting, by default is 0)det_num (detector number, default 1)savedata (=1 to save data in ‘analysis/integrated_frames/’, default 0)maskfilename (valid mask file name. If empty [], no mask used)
Returns: int
-
utils/loopregerror(deltastack, filt_stackFT, xmask, ymask)
- Evaluate registration error in an angle series. Returns the error betweensubsequent images. The last image is evaluated against the first butflipped in x. Recieves image FT with DC in (1,1), the image should havehad the center in center of array.filt_stackFT FT of stack of images, previously filtered if neededdeltastack Estimates of positionsxmax Vector with positions of horizontal edges of rectangularwindow for registrationymax Same as xmax but vertical edges of window
Returns: errorreg grad
-
make_lock_files
- make_lock_files is a script.
-
utils/phase_from_dpc(dpcx, dpcy, varargin)
- Integrates the phase from a combination of x and y gradients.phase_from_dpc(dpcx,dpcy,’fourier’) uses the Fourier method (default),phase_from_dpc(dpcx,dpcy,’finitdiff’) uses a finite difference method.
Returns: p
-
propagate_probe
- propagate_probe.mWarning: Currently working only for square pixels
-
remove_lock_files
- remove_lock_files.msmall script to remove lock files from certain scans
-
remove_lock_files_select
- remove_lock_files.msmall script to remove lock files from certain scans
-
round_roi_new_stxm
- Another script for STXM evaluation of round roi scansDoes not use Gaussians centered on grid points which leads to inaccuaratevalues at the center positions (due to adding up all the Gaussians)but rather uses the Matlab’s “griddata” function.
-
utils/round_roi_numpts(lx, ly, dr, nth)
- Usage:function numpts = round_roi_numpts(lx,ly,dr,nth)Description:Calculates the number of points of a round roi scanfor a set of parameters used in a Spec call.Parameters:lx = horizontal field of view in meterly = vertical field of view in meterdr = radial shell step size in meterdth = angluar intervals in first shellChangelog:2010-12-04, First version.
Returns: numpts
-
utils/set_all_engines(p, parameter, value)
- function p = set_all_engines(p, parameter, value)set given parameter to all engines
Returns: p
-
show_recons
- show recons.mWarning: Currently working only for square pixelsclose all % Recommended if improfile will be used (there is a bug with cursor positioning otherwise)Mayor changes, basically rewritten, made on Oct 19, 2015 in order to accomodate waiting for
-
utils/unwrap_pilatus_weird(frame_low, frame_high, varargin)
- [frame_unwrapped, frame_replaced_from_lowcount] = unwrap_pilatus(frame_low, frame_high, numbad, slope)unwraps the pilatus pixels that had too high intensity.slope and numbad are optional.slope should be (high exposure time / low exposure time), but can beevaluated from the data.numbad is the rough number of bad pixels - it should be greater than the actualvalue. It is used only if the slope needs to be evaluated.The first output is the result of unwrapping the high intensity counts.The second is equal to the high intensity frame with all wrapped valuesreplaced with scaled counts from the low exposure frame. These two shouldbe equal, but the first output is biased by the intensity correction doneby the pilatus.
Returns: varargout
utils/+soleil¶
-
utils/+soleil/soleil.compile_swing_dirname(scan_no)
- COMPILE_SWING_DIRNAME returns the default SWING directory tree for agiven scan numberEXAMPLE:scan_dir = compile_SWING_dirname(10);-> scan_dir = ‘S00000-00999/’
Returns: scan_dir
-
utils/+soleil/soleil.get_filenames_swing(p)
- GET_FILENAMES_SWING compile filenames of raw data filesreceives
Returns: p