-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbeamline-configuration.html
432 lines (316 loc) · 20.5 KB
/
beamline-configuration.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Beamline Configuration — NSLS-II Software Documentation documentation</title>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="top" title="NSLS-II Software Documentation documentation" href="index.html"/>
<link rel="up" title="Deployment Details" href="deployment-details.html"/>
<link rel="next" title="Recommended Resources" href="resources.html"/>
<link rel="prev" title="Fresh Installation" href="fresh-installation.html"/>
<script src="_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="index.html" class="icon icon-home"> NSLS-II Software Documentation
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="architecture-overview.html">Event-Based Architecture</a></li>
<li class="toctree-l1"><a class="reference internal" href="collection-quick-start.html">Data Collection Quick Start</a></li>
<li class="toctree-l1"><a class="reference internal" href="analysis-quick-start.html">Data Analysis Quick Start</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples/index.html">Examples</a></li>
<li class="toctree-l1"><a class="reference internal" href="sandbox.html">Sandbox</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="deployment-details.html">Deployment Details</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="conda.html">Software Deployment with Conda</a></li>
<li class="toctree-l2"><a class="reference internal" href="fresh-installation.html">Fresh Installation</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Beamline Configuration</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#ipython-profiles">IPython profiles</a></li>
<li class="toctree-l3"><a class="reference internal" href="#example-configuration-file">Example Configuration File</a></li>
<li class="toctree-l3"><a class="reference internal" href="#configuring-the-olog">Configuring the Olog</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#essential-configuration">Essential Configuration</a></li>
<li class="toctree-l4"><a class="reference internal" href="#integration-with-bluesky">Integration with Bluesky</a></li>
<li class="toctree-l4"><a class="reference internal" href="#integration-with-ophyd">Integration with Ophyd</a></li>
<li class="toctree-l4"><a class="reference internal" href="#olog-ipython-magics">Olog IPython “Magics”</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#defining-hardware-objects">Defining Hardware Objects</a></li>
<li class="toctree-l3"><a class="reference internal" href="#set-up-default-global-state">Set up Default (“Global State”)</a></li>
<li class="toctree-l3"><a class="reference internal" href="#customizing-ipython">Customizing IPython</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="resources.html">Recommended Resources</a></li>
<li class="toctree-l1"><a class="reference internal" href="technologies.html">Core Technologies</a></li>
</ul>
<p class="caption"><span class="caption-text">Data Collection</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://nsls-ii.github.io/bluesky">bluesky</a></li>
<li class="toctree-l1"><a class="reference external" href="https://nsls-ii.github.io/ophyd">ophyd</a></li>
</ul>
<p class="caption"><span class="caption-text">Data Access</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://nsls-ii.github.io/databroker">databroker</a></li>
</ul>
<p class="caption"><span class="caption-text">Data Munging</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://nsls-ii.github.io/datamuxer">datamuxer</a></li>
</ul>
<p class="caption"><span class="caption-text">Data Export</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://nsls-ii.github.io/suitcase">suitcase</a></li>
</ul>
<p class="caption"><span class="caption-text">GitHub Links</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://github.com/NSLS-II/">NSLS-II repositories</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/NSLS-II/wishlist/issues">Wish List</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/NSLS-II/Bug-Reports/issues">Bug Reports</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">NSLS-II Software Documentation</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> »</li>
<li><a href="deployment-details.html">Deployment Details</a> »</li>
<li>Beamline Configuration</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/beamline-configuration.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="beamline-configuration">
<h1>Beamline Configuration<a class="headerlink" href="#beamline-configuration" title="Permalink to this headline">¶</a></h1>
<div class="section" id="ipython-profiles">
<h2>IPython profiles<a class="headerlink" href="#ipython-profiles" title="Permalink to this headline">¶</a></h2>
<p>Configuration can be done interactively or in a Python script.
At NSLS-II, configuration is done by startup scripts that are part of an
<a class="reference external" href="https://ipython.org/ipython-doc/dev/config/intro.html#profiles">IPython profile</a>
. But note that it is not essential to use IPython or IPython profile in
general – this is just a convenience.</p>
<p>Profiles are stored in (or soft-linked) from <code class="docutils literal"><span class="pre">~/.ipython</span></code> in the user profile
of individual users or shared beamline accounts.</p>
<p>The standard profile is called “collection,” and the startup scripts are
located in <code class="docutils literal"><span class="pre">~/.ipython/profile_collection/startup/</span></code>. As stated in the
quick start page, they can be invoked by typing:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>ipython --profile<span class="o">=</span>collection
</pre></div>
</div>
<p>To refresh a script that has been edited, restart IPython or re-execute the
script using <code class="docutils literal"><span class="pre">%run</span> <span class="pre">-i</span> <span class="pre">~/.ipython/profile_collection/startup/<FILENAME></span></code>.
Do this for any file(s) that have been updated. (There is no way to run
all files at once.)</p>
</div>
<div class="section" id="example-configuration-file">
<h2>Example Configuration File<a class="headerlink" href="#example-configuration-file" title="Permalink to this headline">¶</a></h2>
<p>This is a example IPython profile startup file.:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="c1"># Make ophyd listen to pyepics.</span>
from ophyd import setup_ophyd
setup_ophyd<span class="o">()</span>
<span class="c1"># Subscribe metadatastore to documents.</span>
<span class="c1"># If this is removed, data is not saved to metadatastore.</span>
import metadatastore.commands
from bluesky.global_state import gs
gs.RE.subscribe_lossless<span class="o">(</span><span class="s1">'all'</span>, metadatastore.commands.insert<span class="o">)</span>
<span class="c1"># At the end of every run, verify that files were saved and</span>
<span class="c1"># print a confirmation message.</span>
from bluesky.callbacks.broker import verify_files_saved
gs.RE.subscribe<span class="o">(</span><span class="s1">'stop'</span>, post_run<span class="o">(</span>verify_files_saved<span class="o">))</span>
<span class="c1"># Import matplotlib and put it in interactive mode.</span>
import matplotlib.pyplot as plt
plt.ion<span class="o">()</span>
<span class="c1"># Make plots update live while scans run.</span>
from bluesky.utils import install_qt_kicker
install_qt_kicker<span class="o">()</span>
<span class="c1"># Optional: set any metadata that rarely changes.</span>
<span class="c1"># RE.md['beamline_id'] = 'YOUR_BEAMLINE_HERE'</span>
<span class="c1"># convenience imports</span>
from ophyd.commands import *
from bluesky.callbacks import *
from bluesky.spec_api import *
from bluesky.global_state import gs, abort, stop, resume
from databroker import <span class="o">(</span>DataBroker as db, get_events, get_images,
get_table, get_fields, restream, process<span class="o">)</span>
from <span class="nb">time</span> import sleep
import numpy as np
<span class="nv">RE</span> <span class="o">=</span> gs.RE <span class="c1"># convenience alias</span>
<span class="c1"># Uncomment the following lines to turn on verbose messages for debugging.</span>
<span class="c1"># import logging</span>
<span class="c1"># ophyd.logger.setLevel(logging.DEBUG)</span>
<span class="c1"># logging.basicConfig(level=logging.DEBUG)</span>
</pre></div>
</div>
</div>
<div class="section" id="configuring-the-olog">
<h2>Configuring the Olog<a class="headerlink" href="#configuring-the-olog" title="Permalink to this headline">¶</a></h2>
<div class="section" id="essential-configuration">
<h3>Essential Configuration<a class="headerlink" href="#essential-configuration" title="Permalink to this headline">¶</a></h3>
<p>pyOlog requires a configuration file to specify the connection
settings. As root, create a file at <code class="docutils literal"><span class="pre">/etc/pyOlog.conf</span></code> with the following
contents.:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="o">[</span>DEFAULT<span class="o">]</span>
<span class="nv">url</span> <span class="o">=</span> https://<beamline>-log.cs.nsls2.local:8181/Olog
<span class="nv">logbooks</span> <span class="o">=</span> Commissioning <span class="c1"># use the name of an existing logbook</span>
<span class="nv">username</span> <span class="o">=</span> <username>
<span class="nv">password</span> <span class="o">=</span> <password>
</pre></div>
</div>
<p>where <code class="docutils literal"><span class="pre"><beamline></span></code> is the designation formatted like <code class="docutils literal"><span class="pre">xf23id1</span></code>.</p>
</div>
<div class="section" id="integration-with-bluesky">
<h3>Integration with Bluesky<a class="headerlink" href="#integration-with-bluesky" title="Permalink to this headline">¶</a></h3>
<p>Bluesky automatically logs basic scan information at the start of a
scan. (All of this information is strictly a subset of what is
also stored in metadatastore – this is just a convenience.)</p>
<p>Back in an IPython profile startup file, add:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>from functools import partial
from pyOlog import SimpleOlogClient
from bluesky.callbacks.olog import logbook_cb_factory
<span class="c1"># Set up the logbook. This configures bluesky's summaries of</span>
<span class="c1"># data acquisition (scan type, ID, etc.).</span>
<span class="nv">LOGBOOKS</span> <span class="o">=</span> <span class="o">[</span><span class="s1">'Data Acquisition'</span><span class="o">]</span> <span class="c1"># list of logbook names to publish to</span>
<span class="nv">simple_olog_client</span> <span class="o">=</span> SimpleOlogClient<span class="o">()</span>
<span class="nv">generic_logbook_func</span> <span class="o">=</span> simple_olog_client.log
<span class="nv">configured_logbook_func</span> <span class="o">=</span> partial<span class="o">(</span>generic_logbook_func, <span class="nv">logbooks</span><span class="o">=</span>LOGBOOKS<span class="o">)</span>
<span class="nv">cb</span> <span class="o">=</span> logbook_cb_factory<span class="o">(</span>configured_logbook_func<span class="o">)</span>
RE.subscribe<span class="o">(</span><span class="s1">'start'</span>, cb<span class="o">)</span>
</pre></div>
</div>
</div>
<div class="section" id="integration-with-ophyd">
<h3>Integration with Ophyd<a class="headerlink" href="#integration-with-ophyd" title="Permalink to this headline">¶</a></h3>
<p>Ophyd has as <code class="docutils literal"><span class="pre">log_pos</span></code> method that writes the current position of all
positioners into the log. To enable this, add the following to an IPython
profile startup file, add:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="c1"># This is for ophyd.commands.get_logbook, which simply looks for</span>
<span class="c1"># a variable called 'logbook' in the global IPython namespace.</span>
<span class="nv">logbook</span> <span class="o">=</span> simple_olog_client
</pre></div>
</div>
<p>The log entires will be written into the logbook specified in
<code class="docutils literal"><span class="pre">.pyOlog.conf</span></code> (in our example, “Commissioning”), not the logbook
used by bluesky (in our example, “Data Acquisition”).</p>
</div>
<div class="section" id="olog-ipython-magics">
<h3>Olog IPython “Magics”<a class="headerlink" href="#olog-ipython-magics" title="Permalink to this headline">¶</a></h3>
<p>“Magics” are special IPython commands (not part of Python itself). They
begin with %. There are two IPython magics for conveniently writing to
the Olog.</p>
<ul class="simple">
<li>Type <code class="docutils literal"><span class="pre">%logit</span></code> to quickly type a text log entry.</li>
<li>Type <code class="docutils literal"><span class="pre">%grabit</span></code>, select an area of the screen to capture, and type in a
text caption.</li>
</ul>
<p>These require their own special configuration. In the profile directory, such
as <code class="docutils literal"><span class="pre">~/.ipython/profile_collection</span></code>, edit the file <code class="docutils literal"><span class="pre">ipython_config.py</span></code>.</p>
<p>Add the line:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>c.InteractiveShellApp.extensions <span class="o">=</span> <span class="o">[</span><span class="s1">'pyOlog.cli.ipy'</span><span class="o">]</span>
</pre></div>
</div>
<p>The log entires will be written into the logbook specified in
<code class="docutils literal"><span class="pre">.pyOlog.conf</span></code> (in our example, “Commissioning”), not the logbook
used by bluesky (in our example, “Data Acquisition”).</p>
</div>
</div>
<div class="section" id="defining-hardware-objects">
<h2>Defining Hardware Objects<a class="headerlink" href="#defining-hardware-objects" title="Permalink to this headline">¶</a></h2>
<p>For example:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>from ophyd import EpicsMotor
<span class="c1"># the two-theta motor</span>
<span class="nv">tth</span> <span class="o">=</span> EpicsMotor<span class="o">(</span><span class="s1">'XF:28IDC-ES:1{Dif:1-Ax:2ThI}Mtr'</span>, <span class="nv">name</span><span class="o">=</span><span class="s1">'tth'</span><span class="o">)</span>
</pre></div>
</div>
<p>See the <a class="reference external" href="http://nsls-ii.github.io/ophyd">ophyd documentation</a> for more.</p>
</div>
<div class="section" id="set-up-default-global-state">
<h2>Set up Default (“Global State”)<a class="headerlink" href="#set-up-default-global-state" title="Permalink to this headline">¶</a></h2>
<p>Set attributes of <code class="docutils literal"><span class="pre">gs</span></code>. This can be done interactively or in a startup file.:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>gs.DETS <span class="o">=</span> <span class="o">[</span>det1, det2<span class="o">]</span>
gs.TABLE_COLS <span class="o">=</span> <span class="o">[</span><span class="s1">'det1'</span><span class="o">]</span>
gs.PLOT_Y <span class="o">=</span> <span class="s1">'det1'</span>
</pre></div>
</div>
</div>
<div class="section" id="customizing-ipython">
<h2>Customizing IPython<a class="headerlink" href="#customizing-ipython" title="Permalink to this headline">¶</a></h2>
<p>Running the following</p>
<div class="highlight-ipython"><div class="highlight"><pre><span></span><span class="gp">In [1]: </span><span class="o">%</span><span class="k">config</span> PromptManager.in_template = '\T In [\\#]: '
<span class="gp">In [2]: </span><span class="o">%</span><span class="k">config</span> PromptManager.out_template = '\T Out[\\#]: '
</pre></div>
</div>
<p>will make your terminal look like this:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>10:01:40 In <span class="o">[</span>49<span class="o">]</span>: 1
10:01:42 Out<span class="o">[</span>49<span class="o">]</span>: 1
10:01:42 In <span class="o">[</span>50<span class="o">]</span>:
10:02:21 In <span class="o">[</span>50<span class="o">]</span>: <span class="nv">a</span> <span class="o">=</span> 2
10:02:28 In <span class="o">[</span>51<span class="o">]</span>:
</pre></div>
</div>
<p>It is not much more work to customize that timestamp to be truncated, include
date / day of week etc. See <a class="reference external" href="https://ipython.org/ipython-doc/3/config/details.html#prompts">this section of the IPython documentation</a> for details.</p>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="resources.html" class="btn btn-neutral float-right" title="Recommended Resources" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="fresh-installation.html" class="btn btn-neutral" title="Fresh Installation" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2015 Brookhaven National Lab.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'./',
VERSION:'',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
</body>
</html>