Skip to content

Commit d041290

Browse files
Baharisstefsmeets
andauthored
Modify get_movie to display frames as they are collected (#121)
* Add `ClickDispatcher` architecture and setup one in `VideoStreamFrame` * `ClickListener`: make `callback` optional and allow activating via `with` context * Add `typing_extensions` as a dependency * Move potential `typing_extensions` types to `instamatic._typing` * Feature usefulness of new `instamatic._typing.Self` * Exclude changes irrelevant to the `click_service` branch * Add a custom `ClickEvent.__repr__` * Move `instamatic.collections` to `instamatic._collections` * `ClickListener`: call `callback` only after putting event in `self.queue` * `_VS`: rename type variable to a more conventional `VideoStream_T` * `typing_extensions`: uses typing if available so import directly, not via `instamatic._typing` * `CameraSimu.get_movie`: convert into `Generator` * `VideoStream.get_movie`: convert into `Generator` * `VideoStream.get_movie`: Optimize thread release, remove unused event = best fps yet * `VideoStream.get_movie`: Optimize thread release, remove unused event = best fps yet 2 * `TEMController.get_movie`: convert into `Generator` * `ctrl.get_image`: fix `header_keys` could hold only 1 key as `str` not `tuple` * `CalibMovieRate`: first draft of the movie delay calibration * `TEMController.get_movie`: collect common metadata before the main loop for time precision * `TEMController`: move ugly explicit `self.cam` check to a method decorator * `CalibMovieDelays`: simplify and add multi-attempt mechanism * `CalibMovieDelaysMapping`: add a common class for reading/writing mappings * `CalibMovieDelaysMapping`: fix I/O, script, bugs, add custom `CalibError` * `CameraServal.get_movie`: rewrite as generator, streamline by PIL->tifffile * `CameraBase.get_movie`: rewrite as generator * `CameraMerlin.get_movie`: rewrite as generator * `showcase_movie.py`: Add a temp script to feature get_movie streaming feature * `CameraServal.get_movie`: Actually replace previous implementation this time * `CalibMovieDelays`: vastly simplify, do for specific exposure only * `CalibMovieDelays`: fix documentation, warning criteria * Register `instamatic.calibrate.calibrate_movie_delays` as script * Fix bugs, typos * Adapt `test_get_movie` to the new structure * Add Daniel Tchoń to `CITATION.cff` * Wrap generators in `try/finally` to correctly close them when not exhausted * `calibrate_movie_delays.py`: Remove code block comments as requested Co-authored-by: Stef Smeets <stefsmeets@users.noreply.github.com> * `calibrate_movie_delays.py`: Remove code block comments as requestedUpdate src/instamatic/calibrate/calibrate_movie_delays.py Co-authored-by: Stef Smeets <stefsmeets@users.noreply.github.com> * `calibrate_movie_delays.py`: Remove code block comments as requested Co-authored-by: Stef Smeets <stefsmeets@users.noreply.github.com> * `calibrate_movie_delays.py`: Remove code block comments as requested Co-authored-by: Stef Smeets <stefsmeets@users.noreply.github.com> * `calibrate_movie_delays.py` reformat `parser.add_argument` Co-authored-by: Stef Smeets <stefsmeets@users.noreply.github.com> * `main_entry`: reformat `parser.add_argument` calls * `CalibMovieDelaysMapping`: improve readability, docstrings as requested * `CalibMovieDelaysMapping`: save calibrations to yaml instead of json * `calibrate_movie_delays_live`: warn instead of raising `CalibWarning` * `calibrate_movie_delays_live`: clear out dead code, improve docstrings, fix issues * `calibrate_movie_delays_live`: allow passing empty `header_keys(_common)` * `calibrate_movie_delays_live`: vastly improve/expand docstring * `CalibMovieDelays`: add docstrings, raise if conditions not found * `CalibMovieDelaysMapping` de/serialize self from/to a nice yaml list --------- Co-authored-by: Stef Smeets <stefsmeets@users.noreply.github.com>
1 parent 166f25a commit d041290

18 files changed

+769
-140
lines changed

CITATION.cff

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ authors:
2121
family-names: Rainer
2222
given-names: Daniel
2323
orcid: "https://orcid.org/0000-0002-3272-3161"
24+
-
25+
affiliation: "Czech Academy of Sciences"
26+
family-names: Tchoń
27+
given-names: Daniel Mariusz
28+
orcid: "https://orcid.org/0000-0003-4798-867X"
2429
cff-version: "1.1.0"
2530
date-released: 2021-08-09
2631
doi: "10.5281/zenodo.1090388"

docs/programs.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ These tools help calibrate instamatic for some experiments.
2525
- [instamatic.calibrate_beamshift](#instamaticcalibrate_beamshift) (`instamatic.calibrate.calibrate_beamshift:main_entry`)
2626
- [instamatic.calibrate_directbeam](#instamaticcalibrate_directbeam) (`instamatic.calibrate.calibrate_directbeam:main_entry`)
2727
- [instamatic.calibrate_stagematrix](#instamaticcalibrate_stagematrix) (`instamatic.calibrate.calibrate_stagematrix:main_entry`)
28+
- [instamatic.calibrate_movie_delays](#instamaticcalibrate_movie_delays) (`instamatic.calibrate.calibrate_movie_delays:main_entry`)
2829
- [instamatic.flatfield](#instamaticflatfield) (`instamatic.processing.flatfield:main_entry`)
2930
- [instamatic.stretch_correction](#instamaticstretch_correction) (`instamatic.processing.stretch_correction:main_entry`)
3031

@@ -214,6 +215,35 @@ instamatic.calibrate_beamshift [-h] [IMG [IMG ...]]
214215
: Show this help message and exit
215216
216217
218+
## instamatic.calibrate_movie_delays
219+
220+
Program to calibrate the delays associated with `ctrl.get_movie` command.
221+
222+
Intuitively, collecting an N-frame movie with X-second exposure should take N*X seconds. However, the hardware specification and software implementation for each detector differ, leading to deviations. This calibration aims to take this effect into account and allow scheduling movies whose frame time better reflects the request.
223+
224+
**Usage:**
225+
```bash
226+
instamatic.calibrate_movie_delays [-h] [-e E] [-a A] [-c C] [-o O]
227+
```
228+
229+
**Optional arguments:**
230+
231+
`-h`, `--help`
232+
: Show this help message and exit
233+
234+
`-e`, `--exposure`
235+
: Exposure to test the delays for in seconds (default 1.0)
236+
237+
`-a`, `--variable_headers`
238+
: Comma-delimited list of variable header keys to calibrate for (for default, see `src/instamatic/controller.py:MOVIE_HEADER_KEYS_VARIABLE`)
239+
240+
`-c`, `--common_headers`
241+
: Comma-delimited list of common header keys to calibrate for (for default, see `src/instamatic/controller.py:MOVIE_HEADER_KEYS_COMMON`)
242+
243+
`-o`, `--output`
244+
: Path to the directory where calibration file should be output (default `%appdata%/calib` on Windows or `$AppData/calib` on Unix)
245+
246+
217247
## instamatic.calibrate_directbeam
218248
219249
Program to calibrate the diffraction shift (PLA) to correct for beamshift movements (Deprecated).

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ publishing = [
102102
"instamatic.calibrate_beamshift" = "instamatic.calibrate.calibrate_beamshift:main_entry"
103103
"instamatic.calibrate_directbeam" = "instamatic.calibrate.calibrate_directbeam:main_entry"
104104
"instamatic.calibrate_stagematrix" = "instamatic.calibrate.calibrate_stagematrix:main_entry"
105+
"instamatic.calibrate_movie_delays" = "instamatic.calibrate.calibrate_movie_delays:main_entry"
105106
"instamatic.flatfield" = "instamatic.processing.flatfield:main_entry"
106107
"instamatic.stretch_correction" = "instamatic.processing.stretch_correction:main_entry"
107108
# tools

src/instamatic/calibrate/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
from .calibrate_beamshift import CalibBeamShift
44
from .calibrate_brightness import CalibBrightness
55
from .calibrate_directbeam import CalibDirectBeam
6+
from .calibrate_movie_delays import CalibMovieDelays
67
from .calibrate_stage_lowmag import CalibStage
8+
79
# from .calibrate_stage_mag1 import CalibStageMag1

src/instamatic/calibrate/calibrate_beamshift.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def calibrate_beamshift_live(
189189
binsize=binsize,
190190
out=outfile,
191191
comment=comment,
192-
header_keys='BeamShift',
192+
header_keys=('BeamShift',),
193193
)
194194
img = imgscale(img, scale)
195195

src/instamatic/calibrate/calibrate_brightness.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def calibrate_brightness_live(ctrl, step=1000, save_images=False, **kwargs):
110110

111111
comment = f'Calib image {i}: brightness={target}'
112112
img, h = ctrl.get_image(
113-
exposure=exposure, out=outfile, comment=comment, header_keys='Brightness'
113+
exposure=exposure, out=outfile, comment=comment, header_keys=('Brightness',)
114114
)
115115

116116
img, scale = autoscale(img)

src/instamatic/calibrate/calibrate_directbeam.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def calibrate_directbeam_live(
250250

251251
comment = f'Calib image {i}: dx={dx} - dy={dy}'
252252
img, h = ctrl.get_image(
253-
exposure=exposure, binsize=binsize, out=outfile, comment=comment, header_keys=key
253+
exposure=exposure, binsize=binsize, out=outfile, comment=comment, header_keys=(key,)
254254
)
255255
img = imgscale(img, scale)
256256

0 commit comments

Comments
 (0)