First, setup the environment so that we have graphics

In [1]:
%matplotlib inline
from pylab import rcParams
rcParams['figure.figsize'] = (12, 8)  # Figure size for inline display
import os

Import pynx classes

In [2]:
from pynx.ptycho.runner.id01 import PtychoRunnerScanID01, params
print('Import OK')
WARNING:fabioimage:PIL is not installed ... trying to do without
WARNING:tifimage:PIL is not installed ... trying to do without
WARNING:bruker100image:PIL is not installed ... trying to do without
WARNING:xsdimage:lxml library is probably not part of your python installation: disabling xsdimage format
gpyfft version: 0.7.0
Using SILX for spec access!
Import OK

First, make sure all results will be saved in your sub-directory, so that all results don't collide !

In [3]:
params['saveprefix']='vincent/ResultsScan%04d/Run%04d'

Set the parameters for the optimization. Since the probe in this case is relatively small, it is critical to start not too far from a correct size.

In [4]:
params['specfile']='../201606id01-FZP/align.spec'
params['scan']=13
params['imgname']='../201606id01-FZP/mpx4/data_mpx4_%05d.edf.gz'
params['probe']='60e-6x200e-6,0.09'  # Starting from a simulated probe, here described as gaussian
params['defocus']=100e-6        #Defocus the calculated initial probe by 100 microns
params['detectordistance']=1.386
params['ptychomotors']='pix,piz,-x,y'
params['algorithm'] = '20DM'    # Begin with difference map, object only
params['object'] = 'random,0.8,1,0,0.5'
params['verbose'] = 10          # Print every 10 cycles
params['loadmask'] = 'maxipix'  # This masks the maxipix gaps
params['liveplot'] = True       # Liveplot updated at the end of each cell.
#params['moduloframe'] =2,0      # Take only half frames (faster, less memory used)
In [5]:
ws = PtychoRunnerScanID01(params, params['scan'])
In [6]:
ws.load_data()  # Load all frames from a maxipix detector using CXI/HDF5 data
Read scan: 13  spiralscan pix piz 0.1 1024 1
SPEC date: Jun 15 22:11:30 2016 -> 2016-06-15T22:11:30+0200  1466021490
Reading nrj monotz=4.0mm,monorz=245.197mrad,monoty=-5.1mm,mononrj=8.000keV,monoth=14.309deg,monobof=19.749mm,  dcm2rol=0.899deg,dcm2pit=1.156deg,dcm2ty=10.2mm,dcm2rlf=19.728deg,dcm2pf=14.310deg
Reading frames: 0 20 40 60 80 100 120 140 160 180 200 220 240 260 280 300 320 340 360 380 400 420 440 460 480 500 520 540 560 580 600 620 640 660 680 700 720 740 760 780 800 820 840 860 880 900 920 940 960 980 1000 1020 

Time to read all frames: 10.3s [26.47 Mpixel/s]
In [7]:
ws.center_crop_data()  # Auto-crop the data
ws.prepare()  # This will prepare the initial object
Loaded MASK from:  maxipix
Initialized mask with 6156 ( 2.312%) bad pixels
Center of diffraction: X=206.65 Y=209.09
Largest prime number acceptable for FFT size: 13
E= 8.000keV, zdetector= 1.386m, pixel size= 55.00um, pixel size(object)=   9.8nm
Using random object type with amplitude range:  0.80- 1.00 and phase range:  0.00- 0.50
Computing FFT speed for all available GPU:
                 GeForce GTX TITAN X [platform: NVIDIA CUDA]: GPU mem: 12287.81Mb [max alloc.:  3071.95Mb],  250.26 Gflop/s (FFT shape: (16, 400, 400) )
####################  WARNING: given GPU not found  ####################
No GPU given, or listed ones not available. Auto-selecting:  ['GeForce GTX TITAN X']
In [8]:
ws.run()  # Run the optimization,as defined in params['algorithm']
 #################################################################################################### 
# 
#         Run: 12
#
 ####################################################################################################
Using double precision for simulation.
Updating defaults values for object.
Simulating object: random
Making obj: (760, 768) 760 768
Updating defaults values for probe.
Simulating probe: focus
Using OpenCL device(s):
   Device: GeForce GTX TITAN X [platform=NVIDIA CUDA] [frame range: 0-1025] [FFT speed:   272.25Gflop/s]
Number of frames is not a multiple of 16, adding 15 null frames
Pure FFT performance[nz=16x1, ny=400, nx=400]: dt=0.001551s (2fft => 0.099331s/cycle for 1x1 frames),  285.43 Gflop/s

 #################################################################################################### 
# 
#         Run: 12 , Algorithm: 20DM
#
 ####################################################################################################

## Beginning Difference Map optimisation of:  object

Number of frames is not a multiple of 16, adding 15 null frames
DM/o, cycle=    1/20: LLK= 4.0935e+02 [dt/cycle =  0.480s]
DM/o, cycle=   10/20: LLK= 7.8624e+02 [dt/cycle =  0.320s]
DM/o, cycle=   20/20: LLK= 9.3922e+02 [dt/cycle =  0.320s]

 #################################################################################################### 
# 
#         Finished Run: 12, saving obj and probe to: vincent/ResultsScan0013/Run0012.npz
#
 ####################################################################################################

 #################################################################################################### 

Probe statistics at sample position:
  FWHM (peak intensity):   204.30nm(H) x   78.61nm(V)
  FW @20% intensity    :   296.41nm(H) x  210.74nm(V)
  FWHM (statistical)   :   160.61nm