BCDA-APS / bluesky_training

Bluesky training, including instrument package
https://bcda-aps.github.io/bluesky_training/
Other
12 stars 0 forks source link

extract areadetector runs for analysis #3

Closed prjemian closed 3 years ago

prjemian commented 3 years ago

Use databroker-pack to extract area detector data and runs. Make that available for analysis with #2. See this demonstration notebook.

prjemian commented 3 years ago

Data has been extracted (see README.md).

prjemian commented 3 years ago

working. See:

(class_2021_03) jemian@vm:~$ ipython
Python 3.8.8 (default, Feb 24 2021, 21:46:12) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.21.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import databroker
   ...: list(databroker.catalog)
   ...: cat = databroker.catalog["class_data_examples"]
   ...: print(f"{len(cat) = }")
   ...: run = cat["6255bc8"]
   ...: print(f"{run.metadata['start']['scan_id'] = }")
   ...: image = run.primary.read()["adsimdet_image"]
   ...: 
len(cat) = 59
run.metadata['start']['scan_id'] = 79

In [2]: from scipy import ndimage
   ...: np_frame = image[0][0].to_masked_array()
   ...: com = ndimage.measurements.center_of_mass(np_frame)
   ...: maxp = ndimage.measurements.maximum_position(np_frame)
   ...: print(f"{com = }")
   ...: print(f"{maxp = }")
   ...: 
com = (543.2270948515785, 410.1545941598151)
maxp = (591, 231)

In [3]: def analyze(scan_id):
   ...:     run = cat.search({"scan_id": scan_id})[-1]
   ...:     print(f"{run.metadata['start']['scan_id'] = }")
   ...:     np_frame = run.primary.read()["adsimdet_image"][0][0].to_masked_array()
   ...:     com = ndimage.measurements.center_of_mass(np_frame)
   ...:     maxp = ndimage.measurements.maximum_position(np_frame)
   ...: 
   ...:     print(f"{com = }")
   ...:     print(f"{maxp = }")
   ...: 
   ...: analyze(79)
run.metadata['start']['scan_id'] = 79
com = (543.2270948515785, 410.1545941598151)
maxp = (591, 231)

In [4]: analyze(80)
run.metadata['start']['scan_id'] = 80
com = (443.4099839785622, 444.8162751497467)
maxp = (101, 108)
prjemian commented 3 years ago

This result here:

In [5]: analyze(82)
run.metadata['start']['scan_id'] = 82
com = (499.31197663869756, 470.83827886798076)
maxp = (422, 230)

compares with similar analysis in https://nbviewer.jupyter.org/github/BCDA-APS/bluesky_instrument_training/blob/main/resources/example-data/demonstrate.ipynb (where the notebook example was computed using the algorithm from bluesky.BestEffortCallback PeakStats).

{'centroid_position': 228.98689769845708, 'fwhm': 30.382581241941637, 'crossings': array([213.79560708, 244.17818832]), 'maximum': (229, 43966), 'center_position': 470.83827886798076, 'minimum': (774, 6830)}
{'centroid_position': 427.40783898305085, 'fwhm': 233.9343220338983, 'crossings': array([310.44067797, 544.375     ]), 'maximum': (433, 11759), 'center_position': 499.31197663869756, 'minimum': (891, 6841)}