-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
find_devices() from polartools.utils #502
Comments
def find_devices(scan, db, name, query=None):
# so, for instance, if you give the name "lakeshore"
# it will return all the devices with that string.
table = load_databroker(scan, db, stream="baseline", query=query)
output = []
for col in table.columns:
if name in col:
output.append(col)
return output
def read_baseline(scan, db, devices, query=None):
table = load_databroker(scan, db, stream="baseline", query=query)
return table[devices].mean()
def read_devices(scan, db, name, query=None):
# companion to find_devices() above
devices = find_devices(scan, db, name, query=query)
return read_baseline(scan, db, devices)
def load_databroker(scan_id, db, stream="primary", query=None, use_db_v1=True):
_db = db_query(db, query) if query else db
if use_db_v1:
return _db.v1[scan_id].table(stream_name=stream)
else:
return getattr(_db.v2[scan_id], stream).read().to_dataframe() |
The names seem rather broad. For example, |
Since |
Need definition of |
Compare with |
def lookup_position(db, scan, search_string="", query=None):
"""
Lookup positioner values in past scans.
Parameters
----------
db : databroker database
Searcheable database
scan : integer
Scan numbers or uids.
search_string : string
Full or part of positioner name.
query: dict
Search parameters.
Returns
-------
output: list
"""
db_range = db_query(db, query=query) if query else db
baseline = load_databroker(scan, db_range, "baseline", use_db_v1=True)
if len(baseline["time"]) == 2:
date1 = baseline["time"][1].strftime("%m/%d/%y %H:%M:%S")
date2 = baseline["time"][2].strftime("%m/%d/%y %H:%M:%S")
print("=".center(100, "="))
print(f"{'Positioner':>50}{date1:>25}{date2:>25}")
print("-".center(100, "-"))
for key in baseline.keys():
if search_string in key:
if isinstance(baseline[key][1], list):
print(f"{key:>50}{baseline[key][1]}{baseline[key][2]}")
else:
print(
f"{key:>50}{baseline[key][1]:>25}{baseline[key][2]:>25}"
)
else:
date1 = baseline["time"][1].strftime("%m/%d/%y %H:%M:%S")
print("=".center(100, "="))
print(f"{'Positioner':>50}{date1:>25}")
print("-".center(100, "-"))
for key in baseline.keys():
if search_string in key:
if isinstance(baseline[key][1], list):
print(f"{key:>50}{baseline[key][1]}")
else:
print(f"{key:>50}{baseline[key][1]:>25}")
print("-".center(100, "-")) |
The index numbers 1 .. 2, ... are "sequence numbers" because baseline is a pandas DataFrame. Example: In [1]: import databroker
d
In [2]: cat = databroker.catalog["training"]
In [3]: run = cat.v1[-1]
In [5]: baseline = run.table(stream_name="baseline")
In [6]: baseline["time"]
Out[6]:
seq_num
1 2021-06-02 18:36:29.552511215
2 2021-06-02 18:36:34.705037355
Name: time, dtype: datetime64[ns]
In [7]: type(_)
Out[7]: pandas.core.series.Series
In [8]: |
Awesome! |
In discussions with 4ID-Polar today, they showed a new utility to identify ophyd devices/signals that share a common string. This tool (now) looks in the baseline stream for items which match (full or partial) a string.
Example: find
m1
in the most recent run:Consider adding this to
apstools.utils
.Thanks @strempfer & @gfabbris !
from https://github.com/APS-4ID-POLAR/polartools/blob/main/polartools/load_data.py
The text was updated successfully, but these errors were encountered: