In [1]:
# BEFORE GETTING STARTED
# 1. if at LCLS load the anaconda session
# source ~marcoc/setups/ana-marco3k-setup.sh
# 2. start ipython
# ipython3
In [2]:
# there are two files:
# 1. alignment.py (deals with images)
# 2. xanes_analyzeRun.py (deals with run and images reading)

# the experiment name is defined in xanes_analyzeRun.py
# change to the right value before loading
In [3]:
%matplotlib nbagg
import matplotlib
import matplotlib.pylab as plt
matplotlib.style.use("ggplot")
import pprint
import numpy as np
np.warnings.simplefilter('ignore')

import xanes_analyzeRun
import alignment
Reading configuration file /home/marco/programs/mylibs/python_modules/x3py/x3py_config
Reading configuration file ./x3py_config
Using /home/marco/.cache/x3py as cache folder, current size 304.08 MB
Working on experiment mecl3616 (beamline mec)
 folder data      → /home/marco/temp
 folder init_pars → mecl3616_init_pars/
 folder outout    → mecl3616_output/

Doing first alignment on "hole"

In [4]:
# define starting parameters for analysis; passed directly to iminuit so things like
# limits, or fix_scalex=True, etc. can be used
pars = dict( scalex = 0.6, intensity = 0.1, iblur1=2,fix_iblur1 = False )
# default parameters can be found in alignment.g_fit_default_kw
# you can have a look by uncommenting the following line:
# pprint.pprint(alignment.g_fit_default_kw)
In [5]:
# define the run object
#### NOTE : for mec run swapx=True,swapy=False
r = xanes_analyzeRun.AnalyzeRun(190,initAlign=pars,swapx=True,swapy=False)
Building paths list of HDF5 file(s)...done 0.02 s
Defining fee_spec.....(as general detector).....done 0.00 s
Defining opal2.....(as general detector).....done 0.00 s
Time stamp matching started ......done 0.00 s
In [6]:
# data are d.spec1 and d.spec2 (spec1 is the one **upbeam**)
# align one shot

# show = True: show only output; showInit=True: show also starting parameters
r0fit=r.doShot(shot=0,calib=0,showInit=True,doFit=True)
Enter to start fit

FCN = 647820214.703428 TOTAL NCALL = 331 NCALLS = 331
EDM = 8.820816855092605 GOAL EDM = 1e-05 UP = 1.0
Valid Valid Param Accurate Covar PosDef Made PosDef
False True True True False
Hesse Fail HasCov Above EDM Reach calllim
False True True False
+ Name Value Parab Error Minos Error- Minos Error+ Limit- Limit+ FIXED
1 intensity 0.11346 1.91572e-06 0 0
2 igauss1cen 512 2 0 0 FIXED
3 igauss1sig 4000 2 0 0 FIXED
4 iblur1 4.617 0.00037373 0 0 0.0 20.0
5 scalex 0.6 0.05 0 0 0.4 1.2 FIXED
6 scaley 1 0.05 0 0 0.8 1.2 FIXED
7 rotation 0.01 0.005 0 0 -0.06 0.06 FIXED
8 transx 120.793 0.000220781 0 0 -400.0 400.0
9 transy -3.33798 0.000126792 0 0 -50.0 50.0
10 shear 0.01 0.001 0 0 -0.2 0.2 FIXED
11 igauss2cen 512 2 0 0 FIXED
12 igauss2sig 4000 2 0 0 FIXED


FCN = 366891588.18902636 TOTAL NCALL = 1466 NCALLS = 1466
EDM = 5.111809229073948 GOAL EDM = 1e-05 UP = 1.0
Valid Valid Param Accurate Covar PosDef Made PosDef
False True False False True
Hesse Fail HasCov Above EDM Reach calllim
False True True False
+ Name Value Parab Error Minos Error- Minos Error+ Limit- Limit+ FIXED
1 intensity 0.107823 1.62851e-06 0 0
2 igauss1cen 512 2 0 0 FIXED
3 igauss1sig 4000 2 0 0 FIXED
4 iblur1 1.73655 0.000144802 0 0 0.0 20.0
5 scalex 0.633168 9.92501e-07 0 0 0.4 1.2
6 scaley 1.02911 5.15605e-06 0 0 0.8 1.2
7 rotation -0.0123541 1.75243e-06 0 0 -0.06 0.06
8 transx 98.5647 0.000776996 0 0 -400.0 400.0
9 transy 4.06022 0.000310021 0 0 -50.0 50.0
10 shear -0.00541015 2.00018e-05 0 0 -0.2 0.2
11 igauss2cen 512 2 0 0 FIXED
12 igauss2sig 4000 2 0 0 FIXED

In [7]:
# save as default transformation for run (used when reloading without initAlign keywork)
r.saveTransform();
Saving roi and transformation parameter to mecl3616_init_pars//run0190_transform.npy
In [8]:
# do more shots without fitting (using last r.initAlign)
# the return value is a list with lots of stuff for each shot
res = r.doShots(slice(100),doFit=False)
print(list(res.keys()))
FOM for best alignment 0.11
['parameters', 'p2', 'p1', 'fom', 'ratio']
In [9]:
print(list(res["parameters"].keys()))
['igauss1cen', 'scalex', 'transx', 'intensity', 'igauss2cen', 'shear', 'iblur1', 'scaley', 'rotation', 'igauss1sig', 'transy', 'igauss2sig']
In [10]:
alignment.plotRatios(res["ratio"])
ref = np.nanmedian(res["ratio"],axis=0)
trash = plt.xlim(400,600)
trash = plt.ylim(0,2)

analyze another run using previous alignment

In [11]:
rShot = xanes_analyzeRun.AnalyzeRun(192,initAlign="mecl3616_init_pars/run0190_transform.npy",swapx=True,swapy=False)
Building paths list of HDF5 file(s)...done 0.02 s
Defining fee_spec.....(as general detector).....done 0.00 s
Defining opal2.....(as general detector).....done 0.00 s
Time stamp matching started ......done 0.00 s
init transform and ROIs from mecl3616_init_pars/run0190_transform.npy
In [12]:
out = rShot.doShots(slice(0,5))
ratios = out["ratio"]
plt.figure()
for i,r in enumerate(ratios):
  plt.plot(r/ref,label="Shot %d"%i)
trash = plt.ylim(0,1)
trash = plt.legend(loc=2)
FOM for best alignment 0.32
In [13]:
# save results in hdf file for Andy's happiness
rShot.save(overwrite=True)
Saving results to mecl3616_output//run0192_analysis.h5