Skip to content

Re-stage to allow variable sized chunks.#5

Merged
danielballan merged 4 commits intomasterfrom
restage-to-allow-variable-sized-chunks
Aug 24, 2020
Merged

Re-stage to allow variable sized chunks.#5
danielballan merged 4 commits intomasterfrom
restage-to-allow-variable-sized-chunks

Conversation

@danielballan
Copy link
Copy Markdown
Contributor

Error report from @xianghuix:

The two routines you like to compare are fly_scan in 40-scan.py, and fly_scan2 in 98-user_scan.py. fly_scan2 is the new routine. Here is the problem description

One example data set is that with uid ‘ec0d583d’. The command used for this scan is
RE(fly_scan2(0.1, relative_rot_angle=200, period=0.1, chunk_size=360, out_x=600, out_y=None, out_z=None, out_r=None, rs=6, relative_move_flag=1, note=’fly_test’, binning=[1, 1], simu=True)
With this command, it is supposed to save 360 sample images as a single chunk, then 20 background images and 20 dark images. I checked the HDF5 writer plugin during scan and saw it saved all total 400 images. However, in bluesky, I checked the images with command
imgs = list(db[‘ec0d583d’].data(“Andor_image”))
and found ‘imgs’ is composed of three elements, each of them includes 20 images. The first element in imgs should include 360 images. Where do other images go?
The reason I think it save 20 images in each group is that the Andor camera ‘Andor.cam.num_images’ was set to 20. However, HDF5 writer indeed streamed 360 images in the first group. Why does db only find 20 of them?

I believe @cryos and I understand the cause. In chronological order:

  1. Before fly_scan2 is run, the detector's num_images is 20 (left as it was at the end of the previous scan).
  2. The detector is staged. Its num_images is read at this point (still 20) and written down in a Resource document. See 'frame_per_point': 20 below.
{'spec': 'AD_HDF5',
'resource_path': '2020/08/12/d5ad62cb-0a36-4d34-b1ca_000000.h5',
'root': '/NSLS2/xf18id1/DATA/Andor',
'resource_kwargs': {'frame_per_point': 20},
'path_semantics': 'posix',
'uid': 'a8879517-9e90-4a66-b11a-91fec639ee4a',
'run_start': 'ec0d583d-37af-445a-95f9-f6dae5014ed2'},
  1. The detector's num_images is set to 360 and then images are acquired. All 360 frames are written via the HDF5 plugin, but databroker will only be "aware" of 20 of them.
  2. The detector's num_images is set to 20, and 20 frames each of background and dark are taken.

I believe that this issue has come up before. It led to the prototype bluesky/area-detector-handlers#11 which would allow one HDF5 to contain chunks of unequal sizes (e.g. [360, 20, 20] in this case). That work hasn't yet been pushed through to completion (cc @tacaswell @mrakitin).

In this PR, I propose changes to fly_scan2 that workaround the issue. By paying a small performance penalty (likely ~1 second) we can write the 360 frames to a different HDF5 file from the rest. A better fix would be to complete and deploy bluesky/area-detector-handlers#11, but I offer this possibility as a short-term workaround.

I have not tested this as I don't have access to an Andor for testing. Please give it a try.

@xianghuix
Copy link
Copy Markdown

xianghuix commented Aug 13, 2020 via email

@danielballan
Copy link
Copy Markdown
Contributor Author

danielballan commented Aug 13, 2020

No, not at all. It's still one plan, and it still generates one "Run" (one entry in databroker). It just happens to write to two different HDF5 files. That detail will not change how you execute the plan or how you access its data from databroker.

Copy link
Copy Markdown
Contributor

@mrakitin mrakitin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice workaround! I suggested one correction to a typo in a comment.

danielballan and others added 2 commits August 13, 2020 21:07
Co-authored-by: Maksim Rakitin <mrakitin@users.noreply.github.com>
@danielballan danielballan merged commit 126d534 into master Aug 24, 2020
@mrakitin mrakitin deleted the restage-to-allow-variable-sized-chunks branch January 16, 2026 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants