Changes for murko found from beamline testing#809
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #809 +/- ##
=======================================
Coverage 95.58% 95.59%
=======================================
Files 125 125
Lines 5419 5422 +3
=======================================
+ Hits 5180 5183 +3
Misses 239 239 ☔ View full report in Codecov by Sentry. |
| done_status = AsyncStatus( | ||
| asyncio.wait_for(self._stop_flag.wait(), timeout=self.TIMEOUT) | ||
| ) | ||
| async for image_uuid in observe_value(self.counter, done_status=done_status): |
There was a problem hiding this comment.
this counter signal, is it really a counter? It looks like it's actually uuids? Or are they not really uuids and are just sequence numbers?
There was a problem hiding this comment.
Q: How frequently does this signal update, is it guaranteed that we will see every frame id that we need to collect?
There was a problem hiding this comment.
This is the frame counter on the device. We can use it as a UUID as it increments with every frame and we're only using the one camera so will be unique. I suspect there is a roll-over at something around the max int value but given we don't keep data more than a week I think it's unlikely to affect us.
It updates at the rate of the camera (~15Hz). You're right that we may end up missing some, though experimentally we haven't yet, but even if we do it's not critical we catch every frame.
Legitimate questions though, thanks for raising them, I will add some comments in the code to this affect.
There was a problem hiding this comment.
Re: uniqueness of the UUID
Unsure if it is overkill but can envisage during some operational issue a few camera IOC restarts could be needed. It is possible the counter always starts at one from IOC restart. In a combination of IOC restarts plus same sampleID being loaded and data collected on the same frame number (very unlikely combinations) then a UUID collision could technically happen. A possible solution would be to add a prefix of some kind randomly generated.
But unsure if it is worth the effort.
There was a problem hiding this comment.
Good point, thanks. I will add a proper UUID section in too as a precaution.
rtuck99
left a comment
There was a problem hiding this comment.
Looks good apart from maybe change the name of the counter and also query about whether we might get all the frames.
| jpeg_bytes = await get_next_jpeg(response) | ||
| self.uuid_setter(image_uuid := str(uuid.uuid4())) | ||
| img = Image.open(io.BytesIO(jpeg_bytes)) | ||
| image_data = pickle.dumps(np.asarray(img)) |
There was a problem hiding this comment.
Before we move forward and forget would like 5 minutes look and maybe A comment left in the code why we make this decision now (allo5wing to change in the future if necessary).
First we decided to not store numpy arrays of the raw images (jpg decompressed) after realising it would occupy enormous amounts of DB space with no real benefit on speed.
Question on current implementation: there 3 ways to store binary jpg into redis
I) directly as an bytesIO object using data.getvalues()
II) serialising it (as we make here with pickle)
III) using a redis optimize structure called redis bitmap for such objects
Happy we stay with (II) as I don't fully know disadvantages of the other ones Vs this one but maybe leave a comment this could be relooked if necessary in the future?
There was a problem hiding this comment.
Agreed, will add a comment and make an issue to look at a follow-up if we think useful
There was a problem hiding this comment.
Issue at DiamondLightSource/mx-bluesky#592 to investigate
There was a problem hiding this comment.
Ah, I actually think this PR already removes the pickling and just stores the raw bytes. I will add a comment though.
Fixes DiamondLightSource/mx-bluesky#530 and DiamondLightSource/mx-bluesky#147
Built on top of #808 so review/merge that first
Additionally this PR:
Instructions to reviewer on how to test:
dodal connect i04Checks for reviewer
dodal connect ${BEAMLINE}