-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial implementation of from_databroker * Put from_databroker in docs toctree * docstring * Changelog * dev requirements * correct uid source * `__all__`
- Loading branch information
Showing
7 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
__all__ = ["from_databroker"] | ||
|
||
from ._data import Data | ||
|
||
|
||
def from_databroker(run, dataset="primary"): | ||
"""Import a dataset from a bluesky run into the WrightTools Data format. | ||
Parameters | ||
---------- | ||
run: BlueskyRun | ||
The bluesky run as returned by e.g. catalog["<uid>"] | ||
dataset: str | ||
The string identifier of the stream to import from the bluesky run. | ||
By default "primary" is used, but e.g. "baseline" is also common | ||
""" | ||
describe = run.describe() | ||
md = describe["metadata"] | ||
start = md["start"] | ||
ds = run[dataset].read() | ||
shape = start.get("shape", (len(ds.time),)) | ||
|
||
detectors = start.get("detectors", []) | ||
|
||
data = Data(name=start["uid"]) | ||
for var in ds: | ||
if var == "uid": | ||
continue | ||
if var.endswith("_busy"): | ||
continue | ||
if any(var.startswith(d) for d in detectors): | ||
data.create_channel(var, values=ds[var].data.reshape(shape)) | ||
else: | ||
# TODO units, once they are in the dataset metadata | ||
data.create_variable(var, values=ds[var].data.reshape(shape)) | ||
|
||
transform = [x[0] for x, ds_name in start["hints"]["dimensions"] if ds_name == dataset] | ||
data.transform(*transform) | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pathlib | ||
|
||
from databroker.v2 import temp | ||
import msgpack | ||
|
||
import WrightTools as wt | ||
|
||
catalog = temp() | ||
|
||
__here__ = pathlib.Path(__file__).parent | ||
|
||
for child in (__here__ / "bluesky_data").iterdir(): | ||
with child.open("rb") as f: | ||
unpack = msgpack.Unpacker(f) | ||
for item in unpack: | ||
catalog.v1.insert(*item) | ||
|
||
|
||
def test_2d_data(): | ||
run = catalog["3dbdd402-434b-4aac-b004-447a2f026d73"] | ||
data = wt.data.from_databroker(run) | ||
assert data.shape == (10, 11) | ||
assert "d1_readback" in data | ||
assert "d1_setpoint" in data | ||
assert data.channel_names == ("daq_random_walk",) | ||
assert data.d1_readback.min() == 0 | ||
assert data.d1_readback.max() == 1 |