# This is a dataset acquired on id10 in the small angle regime.
# The experiment used a square with a right angle as a beamstop, blocking many
# pixels around the direct beam.
# Since the object has a known constant thickness, it can be analysed as a real-valued
# object, and the dataset was added a center of symmetry to reduce the masked 
# pixels behind the beamstop

# 0) Set the GPU number in the PYNX_PU if not already done (replace '1' by your trainee number):
export PYNX_PU=.1

# 1) We can start from the already-supplied support:

pynx-cdi-id10 data=logo5mu_20sec.edf support=mask_logo5mu_20sec.edf support_update_period=0 liveplot


# 2) Since 1) is like cheating, let's start from a circular support.
# Unfortunately it is not easy to choose the right parameters for convergence. The
# most critical is the support_threshold. Type 'pynx-id10cdi.py' for help on parameters

pynx-cdi-id10 data=logo5mu_20sec.edf support=circle support_size=70 support_threshold=0.25 detwin positivity liveplot


# 3) This probably was not very successful, so stop wasting time with the live plot
# and try 100 runs, with the threshold randomly chosen between 0.22 and 0.28,
# only keeping the 10 best results
rm -f *LLK*.cxi  # remove old solutions

pynx-cdi-id10 data=logo5mu_20sec.edf support=circle support_size=70 support_threshold=0.22,0.28 detwin positivity nb_hio=800 nb_er=100 verbose=100 nb_run=100 nb_run_keep=10

# 4) Once the results are in, just look at the files with the lowest log-likelihood using silx:

silx view *.cxi

# (also look using the phase-amplitude options, the final object should be flat-phased)

# 5) Decompose the best solutions into modes:
pynx-cdi-analysis *LLK*.cxi modes    # mode analysis
silx view *modes*.h5		    # look at modes analysis
