Commit graph

574 commits

Author SHA1 Message Date
jaknapper
46d513d9e6 Catch cancelled and other errors in single line 2025-04-02 18:25:35 +01:00
Joe Knapper
79b396a66f CSM always returns to start on error 2025-04-02 17:54:12 +01:00
Julian Stirling
32f2a7ce70 Fix spurious line endings, don't allow ruff-format to fail anymore 2025-04-02 14:25:22 +01:00
Richard Bowman
83e10b125b Fix return type annotation for autofocus 2024-12-18 14:23:58 +00:00
Richard Bowman
9fd8fc37f1 Formatted with Ruff 2024-12-03 06:46:08 +00:00
Richard Bowman
27aec769a2 Linter fixes
NB I have permitted bare except: blocks in smart_scan. This should be reverted.
2024-12-03 06:43:45 +00:00
Richard Bowman
57177c6a56 Sped up camera and got CSM passing
Using lower resolution helps speed it up, and skipping CSM settling time makes a big difference.
2024-12-03 06:35:16 +00:00
Richard Bowman
1e7069b375 Add more tests, speed up dummy stage
I've sped up the stage motion, to run tests in a more reasonable time.

CSM doesn't yet calibrate in the test - I suspect debugging of capture_array
is needed.
2024-12-03 00:16:26 +00:00
Richard Bowman
bccb1ee923 Stub class for camera protocol
As with the previous commit, this adds a concrete stub Thing to enable
DirectThingClient generation, so we
can depend on the camera.
2024-11-29 12:53:42 +00:00
Richard Bowman
a0fbbc3e40 Convert Stage to a Protocol
The Stage is now implemented as a runtime-checkable Protocol.

Part of this led to the realisation that we can't create a DirectThingClient
based on a Protocol, only on a concrete Thing. While it might be
a good idea to address that in LabThings in due course, for now
we work around it by creating both a Protocol and a stub class. The stub class implements the protocol, and
can be used to declare a dependency.
2024-11-29 12:53:04 +00:00
Richard Bowman
2e2e877d75 JPEGBlob class definition
Static type checking is easier if JPEGBlob is declared as a class, rather than
being created with a function.
2024-11-29 12:19:05 +00:00
Richard Bowman
adbb805556 Formal Protocol for camera interface
I've now split the base camera code into a runtime-checkable Protocol
and a concrete base class (which is optional). This removes the requirement
for cameras to subclass `openflexure_microscope.things.camera.Camera`
and instead uses duck typing that should
work both statically and dynamically.

As part of this, I've moved the commonly-used dependencies
on the camera inside `openflexure_microscope.things.camera` for consistency, and to make it easy to update them if it changes in the future.
2024-11-29 11:26:38 +00:00
Richard Bowman
1ba799de22 Migrate to new Blob type and update imports
This now uses the latest version of labthings-fastapi.
2024-11-28 17:35:56 +00:00
Richard Bowman
868aa0598c Simulation mode
I successfully calibrated and used the camera-stage mapping.
2024-11-02 00:10:25 +00:00
Richard Bowman
2019234ad1 Close OpenCV camera cleanly 2024-08-09 02:50:39 +01:00
Richard Bowman
2268425bf3 Depend only on generic Camera and Stage
I've now defined parent classes for camera and stage, and depend only on those. This allows
proper typing while enabling the actual hardware
classes to be swapped.

The interfaces definitely aren't final - this is a first
draft, largely to enable me to test out the concept
of a configuration server.
2024-08-09 02:41:39 +01:00
Richard Bowman
aa49cfcba3 Search the package for static files
This isn't foolproof: a zipped package will break it.
If that's something we want to support, we might
need to extract the folder to a temp location.
2024-08-09 02:39:04 +01:00
Richard Bowman
e3e248c46e Move server config to a config file
Currently this is "just" a LabThings config file.
2024-08-09 01:51:11 +01:00
Richard Bowman
b7f9f6cbaf Fix import from LabThings 2024-08-09 01:50:46 +01:00
Richard Bowman
5279dffe6a Dummy stage class 2024-08-09 01:12:16 +01:00
Richard Bowman
3f92ed8266 Add a stub OpenCV-based camera
This allows the server to run on a laptop, to some extent. I've not tested if this will make the whole
web app work properly.

As StreamingPiCamera2 is hardcoded in various places, this certainly doesn't make cameras totally
interchangeable - but it is a step towards that.
2024-08-09 00:52:31 +01:00
Richard Bowman
c32b44d1a6 Refactor server into submodule 2024-08-09 00:49:24 +01:00
Joe Knapper
4ea3b5b623 Increase minimum fraction coverage - makes stitching much more reliable 2024-05-30 11:42:25 +00:00
jaknapper
f08840f0e8 Zip a stitched image with the scan name in the filename 2024-03-05 13:38:24 +00:00
jaknapper
43cf7e837a Produce tiff as property 2024-02-21 14:42:52 +00:00
jaknapper
169df15fd1 More restricted range 2024-02-21 14:04:07 +00:00
Joe Knapper
6031280a19 Merge branch 'changes-into-saturation-fix' into verify-focus 2024-02-20 14:17:25 +00:00
Joe Knapper
eafeaca3ff Readd zip name 2024-02-20 12:22:06 +00:00
Joe Knapper
2c8660e01f Capture metadata before image to ensure consistency 2024-02-20 12:11:04 +00:00
jaknapper
e6eb4d419d Live logging (requires unbuffered program output from stitching) 2024-02-20 10:51:32 +00:00
Richard Bowman
41f03958c6 Save images with saturated pixels
If any pixels in the manually processed raw image end up
saturated (>255), this causes an error. I've now manually
clamped the values between 0 and 255 to fix this.

It would probably be a good idea to warn when this happens,
as it does mean we're losing data.
2024-02-15 17:34:29 +00:00
Richard Bowman
82e2a250fc Include colour correction matrix and gamma in saved images
I've replicated more of the camera pipeline in the images
saved during scans - in particular, I've added the colour
correction matrix (increases saturation) and the contrast
agorithm (implements gamma correction).

This slows down saving to ~0.5-2 seconds, but that's still less time than it takes to move.
2024-02-15 16:38:15 +00:00
jaknapper
aed5a22983 Autofocus verify based on sharpness range, removed repetitive logging 2024-02-15 11:02:44 +00:00
Richard Bowman
a16c54d2db Update raw image processing in scan
This matches recent commits in labthings-picamera2
2024-02-14 18:03:13 +00:00
Joe Knapper
f1c315783c Test the success of refocusing 2024-02-13 15:24:42 +00:00
Joe Knapper
f2d85cb891 sleep before capturing 2024-02-09 19:06:58 +00:00
Joe Knapper
61d7712c27 tiff as an option 2024-02-09 19:05:20 +00:00
Richard Bowman
a61ffbf75a WIP: use code from labthings-picamera2 for EXIF writing
I've now switched to using piexif to write the EXIF tag, which
is slower - but still does not seem to work in openflexure-
stitching.
2024-02-05 17:14:56 +00:00
Richard Bowman
bc8db396bf Acquire raw images rather than processed ones
I've swapped `capture_jpeg` for `capture_array`. This will acquire a raw image and process it manually. Currently I've included LST correction, colour balance, but **not** the colour unmixing matrix. In the future we could add this to implement proper correction for saturation.

Currently EXIF data does not seem to be working properly.
2024-02-01 21:55:15 +00:00
Richard Bowman
24a1d9d020 WIP: try just waiting 0.5s rather than using an Event 2024-02-01 17:37:44 +00:00
Richard Bowman
4a18ef729a Parallelise capture of images and the next move 2024-02-01 17:36:05 +00:00
Richard Bowman
6e4e79f2d2 Factor out moving to the next scan point into a method 2024-02-01 16:49:18 +00:00
jaknapper
db51cd8067 Make overlap value consistent 2024-02-01 15:31:14 +00:00
jaknapper
e6e809cea4 Zip files as we scan, saving the regenerated ones to the end
Removed maximum scan size of 750 images

Save json of scan inputs and use it for future stitching (ensures consistent parameters)

Moved looping autofocus to autofocus thing from recentering thing

Rewrote looping autofocus to skip unneeded moves, as if peak is out of range, no need to nicely focus
2024-01-30 18:46:34 +00:00
jaknapper
a0b98a1adc Fixed autofocus to not combine logs 2024-01-29 19:56:24 +00:00
Joe Knapper
528406137f Start autofocus from base of range for speed 2024-01-29 18:10:11 +00:00
Joe Knapper
53eb51e964 Improved default scan values 2024-01-23 15:22:30 +00:00
Richard Bowman
b35db02f34 Improved error handling and zip download
I've swapped out various `logging.exception` calls for
`logging.error` with `exc_info` set to the exception.
My reading of the docs is that the two shoulld be equivalent,
but the former fails with an error related to
message formatting, as if there was an extra (or missing) '%'.

I've changed the format of the downloaded zip file, so that it
now puts the stitched images at the top level (if they exist).

I've also modified the time of the last stitched image so it
returns None if it doesn't exist - this avoids HTTP errors in
the client.
2024-01-17 13:14:43 +00:00
Richard Bowman
65ae6c1f76 Removed a couple of print statements 2024-01-17 12:25:17 +00:00
Richard Bowman
f627d6e2f2 Always generate the preview stitch
The preview stitch is useful even if stitch-as-you-go is not
desired. I've enabled it all the time, not just when the box
is ticked.
2024-01-17 11:59:30 +00:00