diff --git a/.gitignore b/.gitignore index 7f7cccc..d5038d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +mecl3616_output/ +xppl3716_output/ + # ---> Python # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/.ipynb_checkpoints/HOW-TO-checkpoint.ipynb b/.ipynb_checkpoints/HOW-TO-checkpoint.ipynb new file mode 100644 index 0000000..286dcb3 --- /dev/null +++ b/.ipynb_checkpoints/HOW-TO-checkpoint.ipynb @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/HOW-TO.html b/HOW-TO.html new file mode 100644 index 0000000..17278e3 --- /dev/null +++ b/HOW-TO.html @@ -0,0 +1,15765 @@ + + + +HOW-TO + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+
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.703428TOTAL NCALL = 331NCALLS = 331
EDM = 8.820816855092605GOAL EDM = 1e-05 + UP = 1.0
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ValidValid ParamAccurate CovarPosDefMade PosDef
FalseTrueTrueTrueFalse
Hesse FailHasCovAbove EDMReach calllim
FalseTrueTrueFalse
+ +
+ +
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+NameValueParab ErrorMinos Error-Minos Error+Limit-Limit+FIXED
1intensity0.113461.91572e-0600
2igauss1cen512200FIXED
3igauss1sig4000200FIXED
4iblur14.6170.00037373000.020.0
5scalex0.60.05000.41.2FIXED
6scaley10.05000.81.2FIXED
7rotation0.010.00500-0.060.06FIXED
8transx120.7930.00022078100-400.0400.0
9transy-3.337980.00012679200-50.050.0
10shear0.010.00100-0.20.2FIXED
11igauss2cen512200FIXED
12igauss2sig4000200FIXED
+ + + +
+ +
+ +
+ +
+
+
+ +
+ +
+ +
+
+
+ +
+ +
+ +
+ + + + + + + + + + + + +
FCN = 366891588.18902636TOTAL NCALL = 1466NCALLS = 1466
EDM = 5.111809229073948GOAL EDM = 1e-05 + UP = 1.0
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ValidValid ParamAccurate CovarPosDefMade PosDef
FalseTrueFalseFalseTrue
Hesse FailHasCovAbove EDMReach calllim
FalseTrueTrueFalse
+ +
+ +
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+NameValueParab ErrorMinos Error-Minos Error+Limit-Limit+FIXED
1intensity0.1078231.62851e-0600
2igauss1cen512200FIXED
3igauss1sig4000200FIXED
4iblur11.736550.000144802000.020.0
5scalex0.6331689.92501e-07000.41.2
6scaley1.029115.15605e-06000.81.2
7rotation-0.01235411.75243e-0600-0.060.06
8transx98.56470.00077699600-400.0400.0
9transy4.060220.00031002100-50.050.0
10shear-0.005410152.00018e-0500-0.20.2
11igauss2cen512200FIXED
12igauss2sig4000200FIXED
+ + + +
+ +
+ +
+ +
+
+
+ +
+ +
+ + + +
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+ +
+
+
+
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
+
+
+
+ +
+
+ +
+
+
+ + diff --git a/HOW-TO.ipynb b/HOW-TO.ipynb new file mode 100644 index 0000000..88bd081 --- /dev/null +++ b/HOW-TO.ipynb @@ -0,0 +1,3985 @@ +{ + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.5.1+" + }, + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "code", + "collapsed": true, + "input": [ + "# BEFORE GETTING STARTED\n", + "# 1. if at LCLS load the anaconda session\n", + "# source ~marcoc/setups/ana-marco3k-setup.sh\n", + "# 2. start ipython\n", + "# ipython3" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "# there are two files:\n", + "# 1. alignment.py (deals with images)\n", + "# 2. xanes_analyzeRun.py (deals with run and images reading)\n", + "\n", + "# the experiment name is defined in xanes_analyzeRun.py\n", + "# change to the right value before loading" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 2 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "%matplotlib nbagg\n", + "import matplotlib\n", + "import matplotlib.pylab as plt\n", + "matplotlib.style.use(\"ggplot\")\n", + "import pprint\n", + "import numpy as np\n", + "np.warnings.simplefilter('ignore')\n", + "\n", + "import xanes_analyzeRun\n", + "import alignment" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Reading configuration file /home/marco/IPR/LCLS/xppll37/mc/x3py/x3py_config\n", + "Reading configuration file ./x3py_config\n", + "Using /home/marco/.cache/x3py as cache folder, current size 304.21 MB\n", + "Working on experiment" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " xppl3716 (beamline xpp)\n", + " folder data \u2192 /home/marco/temp\n", + " folder init_pars \u2192 xppl3716_init_pars/\n", + " folder outout \u2192 xppl3716_output/\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Doing first alignment on \"hole\"" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# define starting parameters for analysis; passed directly to iminuit so things like\n", + "# limits, or fix_scalex=True, etc. can be used\n", + "pars = dict( scalex = 0.6, intensity = 0.1, iblur1=2,fix_iblur1 = False )\n", + "# default parameters can be found in alignment.g_fit_default_kw\n", + "# you can have a look by uncommenting the following line:\n", + "# pprint.pprint(alignment.g_fit_default_kw)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 2 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# define the run object\n", + "#### NOTE : for mec run swapx=True,swapy=False\n", + "r = xanes_analyzeRun.AnalyzeRun(190,initAlign=pars,swapx=True,swapy=False)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "OSError", + "evalue": "Unable to open file (Unable to open file: name = '/home/marco/temp/xppl3716-r0190.h5', errno = 2, error message = 'no such file or directory', flags = 0, o_flags = 0)", + "output_type": "pyerr", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mOSError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# define the run object\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;31m#### NOTE : for mec run swapx=True,swapy=False\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mxanes_analyzeRun\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mAnalyzeRun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m190\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0minitAlign\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mpars\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mswapx\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mswapy\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m/home/marco/IPR/LCLS/xppll37/mc/xanes_analyzeRun.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, run, initAlign, swapx, swapy)\u001b[0m\n\u001b[1;32m 102\u001b[0m \u001b[0mswapy\u001b[0m\u001b[0;31m \u001b[0m\u001b[0;31m\u2192\u001b[0m \u001b[0mswap\u001b[0m \u001b[0my\u001b[0m \u001b[0maxis\u001b[0m \u001b[0mof\u001b[0m \u001b[0mfirst\u001b[0m \u001b[0mspectrometer\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 103\u001b[0m \"\"\"\n\u001b[0;32m--> 104\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0md\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mreadDataset\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrun\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 105\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrun\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 106\u001b[0m \u001b[0mrun\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m \u001b[0mre\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msearch\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"\\d{3,4}\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mrun\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgroup\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/home/marco/IPR/LCLS/xppll37/mc/xanes_analyzeRun.py\u001b[0m in \u001b[0;36mreadDataset\u001b[0;34m(fnameOrRun, force, doBkgSub)\u001b[0m\n\u001b[1;32m 64\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfnameOrRun\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 65\u001b[0m \u001b[0mfnameOrRun\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mg_folder_data\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;34m\"/\"\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mg_exp\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;34m\"-r%04d.h5\"\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mfnameOrRun\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 66\u001b[0;31m \u001b[0md\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mx3py\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDataset\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfnameOrRun\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mdetectors\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"opal0\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\"opal1\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\"fee_spec\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\"opal2\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 67\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mg_bml\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"xpp\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 68\u001b[0m \u001b[0md\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mspec1\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0md\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopal0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/home/marco/IPR/LCLS/xppll37/mc/x3py/x3py.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, inputFilesOrExpRunTuple, matchTimeStamps, detectors, exclude_dets, load_cache)\u001b[0m\n\u001b[1;32m 20\u001b[0m ):\n\u001b[1;32m 21\u001b[0m x3py.lclsH5.H5.__init__(self,inputFilesOrExpRunTuple,detectors=detectors,\\\n\u001b[0;32m---> 22\u001b[0;31m exclude=exclude_dets)\n\u001b[0m\u001b[1;32m 23\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdetectors\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mconfig\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdetectors\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 24\u001b[0m \u001b[0msetattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mconfig\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\"h5handles\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mh5\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m;\u001b[0m \u001b[0;31m# useful for getting this info in other classes\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/home/marco/IPR/LCLS/xppll37/mc/x3py/lclsH5.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, fnames, detectors, exclude, mode, driver)\u001b[0m\n\u001b[1;32m 62\u001b[0m \u001b[0mfnames\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0miterfy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfnames\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 63\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 64\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mh5\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mh5py\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mFile\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfname\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mmode\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmode\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mdriver\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdriver\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mfname\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mfnames\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 65\u001b[0m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mCodeBlock\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Building paths list of HDF5 file(s)\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 66\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_h5list\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_pathlist\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmakeLists\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mh5\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/home/marco/IPR/LCLS/xppll37/mc/x3py/lclsH5.py\u001b[0m in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 62\u001b[0m \u001b[0mfnames\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0miterfy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfnames\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 63\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 64\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mh5\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mh5py\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mFile\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfname\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mmode\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmode\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mdriver\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdriver\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mfname\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mfnames\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 65\u001b[0m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mCodeBlock\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Building paths list of HDF5 file(s)\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 66\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_h5list\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_pathlist\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmakeLists\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mh5\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/lib/python3/dist-packages/h5py/_hl/files.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, name, mode, driver, libver, userblock_size, swmr, **kwds)\u001b[0m\n\u001b[1;32m 270\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 271\u001b[0m \u001b[0mfapl\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmake_fapl\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdriver\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlibver\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 272\u001b[0;31m \u001b[0mfid\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmake_fid\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0muserblock_size\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfapl\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mswmr\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mswmr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 273\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 274\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mswmr_support\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/lib/python3/dist-packages/h5py/_hl/files.py\u001b[0m in \u001b[0;36mmake_fid\u001b[0;34m(name, mode, userblock_size, fapl, fcpl, swmr)\u001b[0m\n\u001b[1;32m 90\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mswmr\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mswmr_support\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 91\u001b[0m \u001b[0mflags\u001b[0m \u001b[0;34m|=\u001b[0m \u001b[0mh5f\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mACC_SWMR_READ\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 92\u001b[0;31m \u001b[0mfid\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mh5f\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mflags\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfapl\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mfapl\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 93\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mmode\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'r+'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 94\u001b[0m \u001b[0mfid\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mh5f\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mh5f\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mACC_RDWR\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfapl\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mfapl\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/lib/python3/dist-packages/h5py/_objects.cpython-35m-x86_64-linux-gnu.so\u001b[0m in \u001b[0;36mh5py._objects.with_phil.wrapper (/build/h5py-WO0lFc/h5py-2.6.0/h5py/_objects.c:2577)\u001b[0;34m()\u001b[0m\n", + "\u001b[0;32m/usr/lib/python3/dist-packages/h5py/_objects.cpython-35m-x86_64-linux-gnu.so\u001b[0m in \u001b[0;36mh5py._objects.with_phil.wrapper (/build/h5py-WO0lFc/h5py-2.6.0/h5py/_objects.c:2536)\u001b[0;34m()\u001b[0m\n", + "\u001b[0;32m/usr/lib/python3/dist-packages/h5py/h5f.cpython-35m-x86_64-linux-gnu.so\u001b[0m in \u001b[0;36mh5py.h5f.open (/build/h5py-WO0lFc/h5py-2.6.0/h5py/h5f.c:1811)\u001b[0;34m()\u001b[0m\n", + "\u001b[0;31mOSError\u001b[0m: Unable to open file (Unable to open file: name = '/home/marco/temp/xppl3716-r0190.h5', errno = 2, error message = 'no such file or directory', flags = 0, o_flags = 0)" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# data are d.spec1 and d.spec2 (spec1 is the one **upbeam**)\n", + "# align one shot\n", + "\n", + "# show = True: show only output; showInit=True: show also starting parameters\n", + "r0fit=r.doShot(shot=0,calib=0,showInit=True,doFit=True)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "javascript": [ + "/* Put everything inside the global mpl namespace */\n", + "window.mpl = {};\n", + "\n", + "mpl.get_websocket_type = function() {\n", + " if (typeof(WebSocket) !== 'undefined') {\n", + " return WebSocket;\n", + " } else if (typeof(MozWebSocket) !== 'undefined') {\n", + " return MozWebSocket;\n", + " } else {\n", + " alert('Your browser does not have WebSocket support.' +\n", + " 'Please try Chrome, Safari or Firefox \u2265 6. ' +\n", + " 'Firefox 4 and 5 are also supported but you ' +\n", + " 'have to enable WebSockets in about:config.');\n", + " };\n", + "}\n", + "\n", + "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", + " this.id = figure_id;\n", + "\n", + " this.ws = websocket;\n", + "\n", + " this.supports_binary = (this.ws.binaryType != undefined);\n", + "\n", + " if (!this.supports_binary) {\n", + " var warnings = document.getElementById(\"mpl-warnings\");\n", + " if (warnings) {\n", + " warnings.style.display = 'block';\n", + " warnings.textContent = (\n", + " \"This browser does not support binary websocket messages. \" +\n", + " \"Performance may be slow.\");\n", + " }\n", + " }\n", + "\n", + " this.imageObj = new Image();\n", + "\n", + " this.context = undefined;\n", + " this.message = undefined;\n", + " this.canvas = undefined;\n", + " this.rubberband_canvas = undefined;\n", + " this.rubberband_context = undefined;\n", + " this.format_dropdown = undefined;\n", + "\n", + " this.image_mode = 'full';\n", + "\n", + " this.root = $('
');\n", + " this._root_extra_style(this.root)\n", + " this.root.attr('style', 'display: inline-block');\n", + "\n", + " $(parent_element).append(this.root);\n", + "\n", + " this._init_header(this);\n", + " this._init_canvas(this);\n", + " this._init_toolbar(this);\n", + "\n", + " var fig = this;\n", + "\n", + " this.waiting = false;\n", + "\n", + " this.ws.onopen = function () {\n", + " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", + " fig.send_message(\"send_image_mode\", {});\n", + " fig.send_message(\"refresh\", {});\n", + " }\n", + "\n", + " this.imageObj.onload = function() {\n", + " if (fig.image_mode == 'full') {\n", + " // Full images could contain transparency (where diff images\n", + " // almost always do), so we need to clear the canvas so that\n", + " // there is no ghosting.\n", + " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", + " }\n", + " fig.context.drawImage(fig.imageObj, 0, 0);\n", + " };\n", + "\n", + " this.imageObj.onunload = function() {\n", + " this.ws.close();\n", + " }\n", + "\n", + " this.ws.onmessage = this._make_on_message_function(this);\n", + "\n", + " this.ondownload = ondownload;\n", + "}\n", + "\n", + "mpl.figure.prototype._init_header = function() {\n", + " var titlebar = $(\n", + " '
');\n", + " var titletext = $(\n", + " '
');\n", + " titlebar.append(titletext)\n", + " this.root.append(titlebar);\n", + " this.header = titletext[0];\n", + "}\n", + "\n", + "\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", + "\n", + "}\n", + "\n", + "\n", + "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", + "\n", + "}\n", + "\n", + "mpl.figure.prototype._init_canvas = function() {\n", + " var fig = this;\n", + "\n", + " var canvas_div = $('
');\n", + "\n", + " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", + "\n", + " function canvas_keyboard_event(event) {\n", + " return fig.key_event(event, event['data']);\n", + " }\n", + "\n", + " canvas_div.keydown('key_press', canvas_keyboard_event);\n", + " canvas_div.keyup('key_release', canvas_keyboard_event);\n", + " this.canvas_div = canvas_div\n", + " this._canvas_extra_style(canvas_div)\n", + " this.root.append(canvas_div);\n", + "\n", + " var canvas = $('');\n", + " canvas.addClass('mpl-canvas');\n", + " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", + "\n", + " this.canvas = canvas[0];\n", + " this.context = canvas[0].getContext(\"2d\");\n", + "\n", + " var rubberband = $('');\n", + " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", + "\n", + " var pass_mouse_events = true;\n", + "\n", + " canvas_div.resizable({\n", + " start: function(event, ui) {\n", + " pass_mouse_events = false;\n", + " },\n", + " resize: function(event, ui) {\n", + " fig.request_resize(ui.size.width, ui.size.height);\n", + " },\n", + " stop: function(event, ui) {\n", + " pass_mouse_events = true;\n", + " fig.request_resize(ui.size.width, ui.size.height);\n", + " },\n", + " });\n", + "\n", + " function mouse_event_fn(event) {\n", + " if (pass_mouse_events)\n", + " return fig.mouse_event(event, event['data']);\n", + " }\n", + "\n", + " rubberband.mousedown('button_press', mouse_event_fn);\n", + " rubberband.mouseup('button_release', mouse_event_fn);\n", + " // Throttle sequential mouse events to 1 every 20ms.\n", + " rubberband.mousemove('motion_notify', mouse_event_fn);\n", + "\n", + " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", + " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", + "\n", + " canvas_div.on(\"wheel\", function (event) {\n", + " event = event.originalEvent;\n", + " event['data'] = 'scroll'\n", + " if (event.deltaY < 0) {\n", + " event.step = 1;\n", + " } else {\n", + " event.step = -1;\n", + " }\n", + " mouse_event_fn(event);\n", + " });\n", + "\n", + " canvas_div.append(canvas);\n", + " canvas_div.append(rubberband);\n", + "\n", + " this.rubberband = rubberband;\n", + " this.rubberband_canvas = rubberband[0];\n", + " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", + " this.rubberband_context.strokeStyle = \"#000000\";\n", + "\n", + " this._resize_canvas = function(width, height) {\n", + " // Keep the size of the canvas, canvas container, and rubber band\n", + " // canvas in synch.\n", + " canvas_div.css('width', width)\n", + " canvas_div.css('height', height)\n", + "\n", + " canvas.attr('width', width);\n", + " canvas.attr('height', height);\n", + "\n", + " rubberband.attr('width', width);\n", + " rubberband.attr('height', height);\n", + " }\n", + "\n", + " // Set the figure to an initial 600x600px, this will subsequently be updated\n", + " // upon first draw.\n", + " this._resize_canvas(600, 600);\n", + "\n", + " // Disable right mouse context menu.\n", + " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", + " return false;\n", + " });\n", + "\n", + " function set_focus () {\n", + " canvas.focus();\n", + " canvas_div.focus();\n", + " }\n", + "\n", + " window.setTimeout(set_focus, 100);\n", + "}\n", + "\n", + "mpl.figure.prototype._init_toolbar = function() {\n", + " var fig = this;\n", + "\n", + " var nav_element = $('
')\n", + " nav_element.attr('style', 'width: 100%');\n", + " this.root.append(nav_element);\n", + "\n", + " // Define a callback function for later on.\n", + " function toolbar_event(event) {\n", + " return fig.toolbar_button_onclick(event['data']);\n", + " }\n", + " function toolbar_mouse_event(event) {\n", + " return fig.toolbar_button_onmouseover(event['data']);\n", + " }\n", + "\n", + " for(var toolbar_ind in mpl.toolbar_items) {\n", + " var name = mpl.toolbar_items[toolbar_ind][0];\n", + " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", + " var image = mpl.toolbar_items[toolbar_ind][2];\n", + " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", + "\n", + " if (!name) {\n", + " // put a spacer in here.\n", + " continue;\n", + " }\n", + " var button = $('');\n", + " button.click(method_name, toolbar_event);\n", + " button.mouseover(tooltip, toolbar_mouse_event);\n", + " nav_element.append(button);\n", + " }\n", + "\n", + " // Add the status bar.\n", + " var status_bar = $('');\n", + " nav_element.append(status_bar);\n", + " this.message = status_bar[0];\n", + "\n", + " // Add the close button to the window.\n", + " var buttongrp = $('
');\n", + " var button = $('');\n", + " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", + " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", + " buttongrp.append(button);\n", + " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", + " titlebar.prepend(buttongrp);\n", + "}\n", + "\n", + "mpl.figure.prototype._root_extra_style = function(el){\n", + " var fig = this\n", + " el.on(\"remove\", function(){\n", + "\tfig.close_ws(fig, {});\n", + " });\n", + "}\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function(el){\n", + " // this is important to make the div 'focusable\n", + " el.attr('tabindex', 0)\n", + " // reach out to IPython and tell the keyboard manager to turn it's self\n", + " // off when our div gets focus\n", + "\n", + " // location in version 3\n", + " if (IPython.notebook.keyboard_manager) {\n", + " IPython.notebook.keyboard_manager.register_events(el);\n", + " }\n", + " else {\n", + " // location in version 2\n", + " IPython.keyboard_manager.register_events(el);\n", + " }\n", + "\n", + "}\n", + "\n", + "mpl.figure.prototype._key_event_extra = function(event, name) {\n", + " var manager = IPython.notebook.keyboard_manager;\n", + " if (!manager)\n", + " manager = IPython.keyboard_manager;\n", + "\n", + " // Check for shift+enter\n", + " if (event.shiftKey && event.which == 13) {\n", + " this.canvas_div.blur();\n", + " event.shiftKey = false;\n", + " // Send a \"J\" for go to next cell\n", + " event.which = 74;\n", + " event.keyCode = 74;\n", + " manager.command_mode();\n", + " manager.handle_keydown(event);\n", + " }\n", + "}\n", + "\n", + "mpl.figure.prototype.handle_save = function(fig, msg) {\n", + " fig.ondownload(fig, null);\n", + "}\n", + "\n", + "\n", + "mpl.find_output_cell = function(html_output) {\n", + " // Return the cell and output element which can be found *uniquely* in the notebook.\n", + " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", + " // IPython event is triggered only after the cells have been serialised, which for\n", + " // our purposes (turning an active figure into a static one), is too late.\n", + " var cells = IPython.notebook.get_cells();\n", + " var ncells = cells.length;\n", + " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", + " data = data.data;\n", + " }\n", + " if (data['text/html'] == html_output) {\n", + " return [cell, data, j];\n", + " }\n", + " }\n", + " }\n", + " }\n", + "}\n", + "\n", + "// Register the function which deals with the matplotlib target/channel.\n", + "// The kernel may be null if the page has been refreshed.\n", + "if (IPython.notebook.kernel != null) {\n", + " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", + "}\n" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + }, + { + "html": [ + "" + ], + "metadata": {}, + "output_type": "display_data", + "text": [ + "" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "analyze another run using previous alignment" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "rShot = xanes_analyzeRun.AnalyzeRun(192,initAlign=\"mecl3616_init_pars/run0190_transform.npy\",swapx=True,swapy=False)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Building paths list of HDF5 file(s)...done 0.02 s\n", + "Defining fee_spec.....(as general detector).....done 0.00 s\n", + "Defining opal2.....(as general detector).....done 0.00 s\n", + "Time stamp matching started ......done 0.00 s\n", + "init transform and ROIs from mecl3616_init_pars/run0190_transform.npy\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "out = rShot.doShots(slice(0,5))\n", + "ratios = out[\"ratio\"]\n", + "plt.figure()\n", + "for i,r in enumerate(ratios):\n", + " plt.plot(r/ref,label=\"Shot %d\"%i)\n", + "trash = plt.ylim(0,1)\n", + "trash = plt.legend(loc=2)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "FOM for best alignment 0.32\n" + ] + }, + { + "javascript": [ + "/* Put everything inside the global mpl namespace */\n", + "window.mpl = {};\n", + "\n", + "mpl.get_websocket_type = function() {\n", + " if (typeof(WebSocket) !== 'undefined') {\n", + " return WebSocket;\n", + " } else if (typeof(MozWebSocket) !== 'undefined') {\n", + " return MozWebSocket;\n", + " } else {\n", + " alert('Your browser does not have WebSocket support.' +\n", + " 'Please try Chrome, Safari or Firefox \u2265 6. ' +\n", + " 'Firefox 4 and 5 are also supported but you ' +\n", + " 'have to enable WebSockets in about:config.');\n", + " };\n", + "}\n", + "\n", + "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", + " this.id = figure_id;\n", + "\n", + " this.ws = websocket;\n", + "\n", + " this.supports_binary = (this.ws.binaryType != undefined);\n", + "\n", + " if (!this.supports_binary) {\n", + " var warnings = document.getElementById(\"mpl-warnings\");\n", + " if (warnings) {\n", + " warnings.style.display = 'block';\n", + " warnings.textContent = (\n", + " \"This browser does not support binary websocket messages. \" +\n", + " \"Performance may be slow.\");\n", + " }\n", + " }\n", + "\n", + " this.imageObj = new Image();\n", + "\n", + " this.context = undefined;\n", + " this.message = undefined;\n", + " this.canvas = undefined;\n", + " this.rubberband_canvas = undefined;\n", + " this.rubberband_context = undefined;\n", + " this.format_dropdown = undefined;\n", + "\n", + " this.image_mode = 'full';\n", + "\n", + " this.root = $('
');\n", + " this._root_extra_style(this.root)\n", + " this.root.attr('style', 'display: inline-block');\n", + "\n", + " $(parent_element).append(this.root);\n", + "\n", + " this._init_header(this);\n", + " this._init_canvas(this);\n", + " this._init_toolbar(this);\n", + "\n", + " var fig = this;\n", + "\n", + " this.waiting = false;\n", + "\n", + " this.ws.onopen = function () {\n", + " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", + " fig.send_message(\"send_image_mode\", {});\n", + " fig.send_message(\"refresh\", {});\n", + " }\n", + "\n", + " this.imageObj.onload = function() {\n", + " if (fig.image_mode == 'full') {\n", + " // Full images could contain transparency (where diff images\n", + " // almost always do), so we need to clear the canvas so that\n", + " // there is no ghosting.\n", + " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", + " }\n", + " fig.context.drawImage(fig.imageObj, 0, 0);\n", + " };\n", + "\n", + " this.imageObj.onunload = function() {\n", + " this.ws.close();\n", + " }\n", + "\n", + " this.ws.onmessage = this._make_on_message_function(this);\n", + "\n", + " this.ondownload = ondownload;\n", + "}\n", + "\n", + "mpl.figure.prototype._init_header = function() {\n", + " var titlebar = $(\n", + " '
');\n", + " var titletext = $(\n", + " '
');\n", + " titlebar.append(titletext)\n", + " this.root.append(titlebar);\n", + " this.header = titletext[0];\n", + "}\n", + "\n", + "\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", + "\n", + "}\n", + "\n", + "\n", + "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", + "\n", + "}\n", + "\n", + "mpl.figure.prototype._init_canvas = function() {\n", + " var fig = this;\n", + "\n", + " var canvas_div = $('
');\n", + "\n", + " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", + "\n", + " function canvas_keyboard_event(event) {\n", + " return fig.key_event(event, event['data']);\n", + " }\n", + "\n", + " canvas_div.keydown('key_press', canvas_keyboard_event);\n", + " canvas_div.keyup('key_release', canvas_keyboard_event);\n", + " this.canvas_div = canvas_div\n", + " this._canvas_extra_style(canvas_div)\n", + " this.root.append(canvas_div);\n", + "\n", + " var canvas = $('');\n", + " canvas.addClass('mpl-canvas');\n", + " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", + "\n", + " this.canvas = canvas[0];\n", + " this.context = canvas[0].getContext(\"2d\");\n", + "\n", + " var rubberband = $('');\n", + " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", + "\n", + " var pass_mouse_events = true;\n", + "\n", + " canvas_div.resizable({\n", + " start: function(event, ui) {\n", + " pass_mouse_events = false;\n", + " },\n", + " resize: function(event, ui) {\n", + " fig.request_resize(ui.size.width, ui.size.height);\n", + " },\n", + " stop: function(event, ui) {\n", + " pass_mouse_events = true;\n", + " fig.request_resize(ui.size.width, ui.size.height);\n", + " },\n", + " });\n", + "\n", + " function mouse_event_fn(event) {\n", + " if (pass_mouse_events)\n", + " return fig.mouse_event(event, event['data']);\n", + " }\n", + "\n", + " rubberband.mousedown('button_press', mouse_event_fn);\n", + " rubberband.mouseup('button_release', mouse_event_fn);\n", + " // Throttle sequential mouse events to 1 every 20ms.\n", + " rubberband.mousemove('motion_notify', mouse_event_fn);\n", + "\n", + " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", + " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", + "\n", + " canvas_div.on(\"wheel\", function (event) {\n", + " event = event.originalEvent;\n", + " event['data'] = 'scroll'\n", + " if (event.deltaY < 0) {\n", + " event.step = 1;\n", + " } else {\n", + " event.step = -1;\n", + " }\n", + " mouse_event_fn(event);\n", + " });\n", + "\n", + " canvas_div.append(canvas);\n", + " canvas_div.append(rubberband);\n", + "\n", + " this.rubberband = rubberband;\n", + " this.rubberband_canvas = rubberband[0];\n", + " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", + " this.rubberband_context.strokeStyle = \"#000000\";\n", + "\n", + " this._resize_canvas = function(width, height) {\n", + " // Keep the size of the canvas, canvas container, and rubber band\n", + " // canvas in synch.\n", + " canvas_div.css('width', width)\n", + " canvas_div.css('height', height)\n", + "\n", + " canvas.attr('width', width);\n", + " canvas.attr('height', height);\n", + "\n", + " rubberband.attr('width', width);\n", + " rubberband.attr('height', height);\n", + " }\n", + "\n", + " // Set the figure to an initial 600x600px, this will subsequently be updated\n", + " // upon first draw.\n", + " this._resize_canvas(600, 600);\n", + "\n", + " // Disable right mouse context menu.\n", + " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", + " return false;\n", + " });\n", + "\n", + " function set_focus () {\n", + " canvas.focus();\n", + " canvas_div.focus();\n", + " }\n", + "\n", + " window.setTimeout(set_focus, 100);\n", + "}\n", + "\n", + "mpl.figure.prototype._init_toolbar = function() {\n", + " var fig = this;\n", + "\n", + " var nav_element = $('
')\n", + " nav_element.attr('style', 'width: 100%');\n", + " this.root.append(nav_element);\n", + "\n", + " // Define a callback function for later on.\n", + " function toolbar_event(event) {\n", + " return fig.toolbar_button_onclick(event['data']);\n", + " }\n", + " function toolbar_mouse_event(event) {\n", + " return fig.toolbar_button_onmouseover(event['data']);\n", + " }\n", + "\n", + " for(var toolbar_ind in mpl.toolbar_items) {\n", + " var name = mpl.toolbar_items[toolbar_ind][0];\n", + " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", + " var image = mpl.toolbar_items[toolbar_ind][2];\n", + " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", + "\n", + " if (!name) {\n", + " // put a spacer in here.\n", + " continue;\n", + " }\n", + " var button = $('