Skip to content

Commit 52d8b9a

Browse files
committed
Document metadata better
1 parent 4c3e6d4 commit 52d8b9a

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

doc/tutorial/overview.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,50 @@ As this is fairly common functionality for most plans, we have created a "standa
190190
For more information on callbacks, see
191191
[bluesky callbacks documentation](https://blueskyproject.io/bluesky/main/callbacks.html).
192192

193+
## Metadata
194+
195+
Bluesky provides a number of mechanisms for inserting metadata into a scan. In general, metadata may be any JSON-serialisable object including numbers, strings, lists, dictionaries, and nested combinations of those. The bluesky documentation has an {external+bluesky:doc}`extensive description of metadata mechanisms <metadata>`, but the main options are summarised below.
196+
197+
**Persistently (for this python session)**
198+
```python
199+
RE.md["user"] = "Tom"
200+
RE.md["sample"] = "unobtainium"
201+
```
202+
203+
**For one {py:obj}`RE <ibex_bluesky_core.get_run_engine>` call**:
204+
```python
205+
RE(some_plan(), sample="unobtainium", user="Tom")
206+
```
207+
208+
**Dynamically, within a plan (using {external+bluesky:py:obj}`bluesky.preprocessors.inject_md_wrapper`)**
209+
```python
210+
import bluesky.plan_stubs as bps
211+
from bluesky.preprocessors import inject_md_wrapper
212+
213+
214+
def some_plan(dae):
215+
run_number = yield from bps.rd(dae.current_or_next_run_number_str)
216+
return (yield from inject_md_wrapper(subplan(), {"run_number": run_number}))
217+
```
218+
219+
**Dynamically, within a plan (using {external+bluesky:py:obj}`bluesky.preprocessors.inject_md_decorator`)**
220+
```python
221+
import bluesky.plan_stubs as bps
222+
from bluesky.preprocessors import inject_md_decorator
223+
224+
225+
def some_plan(dae):
226+
run_number = yield from bps.rd(dae.current_or_next_run_number_str)
227+
228+
@inject_md_decorator({"run_number": run_number})
229+
def _inner():
230+
yield from subplan()
231+
232+
yield from _inner()
233+
```
234+
235+
In addition, many built-in bluesky plans (such as {external+bluesky:py:obj}`bluesky.plans.scan`) take an `md` keyword argument, which can also be used to insert additional metadata for one scan.
236+
193237
## See also
194238

195239
**Plans & plan-stubs**

0 commit comments

Comments
 (0)