flimkit 0.14.4__tar.gz → 0.15.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. {flimkit-0.14.4 → flimkit-0.15.1}/PKG-INFO +3 -3
  2. {flimkit-0.14.4 → flimkit-0.15.1}/README.md +2 -2
  3. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/FLIM/batch.py +17 -1
  4. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/FLIM/fit_tools.py +35 -0
  5. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/FLIM/fitters.py +274 -125
  6. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/FLIM/models.py +66 -40
  7. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/GPU/_base.py +19 -1
  8. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/GPU/mlx_backend.py +11 -10
  9. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/GPU/torch_backend.py +11 -9
  10. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/expert_settings.py +29 -0
  11. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/fit_help.py +18 -1
  12. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/fov_preview.py +8 -6
  13. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/gui.py +55 -61
  14. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/phasor_panel.py +8 -0
  15. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/project_panel.py +0 -1
  16. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/roi_tools.py +37 -4
  17. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/utils.py +2 -0
  18. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/_version.py +4 -2
  19. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/batch_cli.py +11 -2
  20. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/configs.py +3 -41
  21. flimkit-0.15.1/flimkit/formats/ICS/__init__.py +1 -0
  22. flimkit-0.15.1/flimkit/formats/ICS/reader.py +266 -0
  23. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/formats/PTU/stitch.py +13 -0
  24. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/formats/flim_file.py +14 -0
  25. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/interactive.py +80 -109
  26. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/project.py +9 -6
  27. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/utils/apply_settings.py +1 -1
  28. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/utils/config_manager.py +6 -10
  29. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/utils/display.py +2 -1
  30. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/utils/misc.py +10 -0
  31. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/utils/session.py +18 -6
  32. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit.egg-info/PKG-INFO +3 -3
  33. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit.egg-info/SOURCES.txt +2 -0
  34. {flimkit-0.14.4 → flimkit-0.15.1}/LICENSE.md +0 -0
  35. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/FLIM/__init__.py +0 -0
  36. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/FLIM/assemble.py +0 -0
  37. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/FLIM/bg_tools.py +0 -0
  38. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/FLIM/irf_tools.py +0 -0
  39. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/FLIM/nb_freetau.py +0 -0
  40. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/FLIM/nb_freetau_cuda.py +0 -0
  41. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/FLIM/poisson_fit.py +0 -0
  42. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/GPU/__init__.py +0 -0
  43. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/GPU/cuda.py +0 -0
  44. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/GPU/mps.py +0 -0
  45. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/GPU/rocm.py +0 -0
  46. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/GPU/torch_lm.py +0 -0
  47. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/app_state.py +0 -0
  48. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/controller.py +0 -0
  49. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/icon.icns +0 -0
  50. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/icon.ico +0 -0
  51. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/icon.png +0 -0
  52. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/irf_widget.py +0 -0
  53. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/mode_controller.py +0 -0
  54. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/modes/__init__.py +0 -0
  55. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/modes/base.py +0 -0
  56. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/modes/batch_mode.py +0 -0
  57. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/modes/fov_mode.py +0 -0
  58. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/modes/irf_mode.py +0 -0
  59. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/modes/phasor_mode.py +0 -0
  60. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/modes/stitch_mode.py +0 -0
  61. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/progress_window.py +0 -0
  62. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/UI/results_panel.py +0 -0
  63. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/__init__.py +0 -0
  64. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/cli.py +0 -0
  65. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/dialogs.py +0 -0
  66. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/formats/BH/__init__.py +0 -0
  67. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/formats/BH/reader.py +0 -0
  68. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/formats/BH/writer.py +0 -0
  69. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/formats/ISS/__init__.py +0 -0
  70. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/formats/ISS/fdflim.py +0 -0
  71. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/formats/ISS/image.py +0 -0
  72. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/formats/ISS/reader.py +0 -0
  73. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/formats/PS/__init__.py +0 -0
  74. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/formats/PS/reader.py +0 -0
  75. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/formats/PTU/__init__.py +0 -0
  76. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/formats/PTU/decode.py +0 -0
  77. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/formats/PTU/phu.py +0 -0
  78. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/formats/PTU/reader.py +0 -0
  79. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/formats/PTU/series.py +0 -0
  80. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/formats/PTU/tools.py +0 -0
  81. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/formats/__init__.py +0 -0
  82. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/formats/phasor.py +0 -0
  83. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/formats/signal.py +0 -0
  84. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/image/tools.py +0 -0
  85. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/mpl_backend.py +0 -0
  86. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/phasor/__init__.py +0 -0
  87. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/phasor/export.py +0 -0
  88. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/phasor/filters.py +0 -0
  89. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/phasor/fret.py +0 -0
  90. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/phasor/interactive.py +0 -0
  91. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/phasor/peaks.py +0 -0
  92. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/phasor/signal.py +0 -0
  93. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/phasor_launcher.py +0 -0
  94. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/plugins/__init__.py +0 -0
  95. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/plugins/bindings.py +0 -0
  96. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/plugins/builtin/__init__.py +0 -0
  97. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/plugins/builtin/core_tools.py +0 -0
  98. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/plugins/loader.py +0 -0
  99. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/plugins/registry.py +0 -0
  100. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/synth.py +0 -0
  101. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/utils/__init__.py +0 -0
  102. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/utils/app_update.py +0 -0
  103. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/utils/batch_fit.py +0 -0
  104. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/utils/config_snapshot.py +0 -0
  105. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/utils/crash_handler.py +0 -0
  106. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/utils/enhanced_outputs.py +0 -0
  107. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/utils/export_png.py +0 -0
  108. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/utils/fancy.py +0 -0
  109. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/utils/lifetime_image.py +0 -0
  110. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/utils/ome_zarr.py +0 -0
  111. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/utils/plotting.py +0 -0
  112. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/utils/roi.py +0 -0
  113. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/utils/update_check.py +0 -0
  114. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/utils/xlsx_tools.py +0 -0
  115. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit/utils/xml_utils.py +0 -0
  116. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit.egg-info/dependency_links.txt +0 -0
  117. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit.egg-info/entry_points.txt +0 -0
  118. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit.egg-info/requires.txt +0 -0
  119. {flimkit-0.14.4 → flimkit-0.15.1}/flimkit.egg-info/top_level.txt +0 -0
  120. {flimkit-0.14.4 → flimkit-0.15.1}/pyproject.toml +0 -0
  121. {flimkit-0.14.4 → flimkit-0.15.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flimkit
3
- Version: 0.14.4
3
+ Version: 0.15.1
4
4
  Summary: Fluorescence lifetime imaging analysis: reading, fitting, phasors and stitching
5
5
  Author-email: Alex Hunt <alexander.hunt@ed.ac.uk>
6
6
  License-Expression: MIT
@@ -168,7 +168,7 @@ docker run -d \
168
168
  alex1075/flimkit:latest
169
169
  ```
170
170
 
171
- Then open http://localhost:14500 and log in as `flimkit` with that password.
171
+ Then open http://localhost:14500 and log in as `flimkit` with that password. The image won't start without a password.
172
172
 
173
173
  The images are built in [flimkit-docker](https://github.com/FLIMKit/flimkit-docker), which lists the tags (Cellpose, CUDA, ROCm, the noVNC desktop and the headless bridge images), the settings, the compose file for a TrueNAS SCALE custom app, and how to build one yourself.
174
174
 
@@ -312,7 +312,7 @@ Per-pixel fitting uses a batched matrix solver that runs on GPU when a supported
312
312
 
313
313
  `python install.py` detects your hardware and installs the right backend automatically. No extra flags needed at runtime.
314
314
 
315
- **Limitations:** `--free-tau-perpixel` with two or more components prepares the batch on the GPU but fits each pixel with SciPy on the CPU, so a GPU gains little there. `fit_summed` (single global fit) is always CPU, and fast enough not to matter.
315
+ **Limitations:** `--free-tau-perpixel` with two or more components prepares the batch on the GPU but fits each pixel with SciPy on the CPU, so a GPU gains little there. `fit_summed` (single global fit) is always CPU. On 10 known-truth tri-exponential decays at 10^6 photons, fitted with the paired measured IRF, the median errors on the long, mid and short lifetimes are 0.4, 2.1 and 3.3 %, against 0.4, 2.8 and 3.3 % from LAS X. Below about 10^5 photons the components of a tri-exponential decay can't be resolved by any fit; FLIMKit then leads with the mean lifetimes and can fix the lifetimes from the image fit. See [Tri-exponential accuracy and DE starts](https://github.com/FLIMKit/FLIMKit/wiki/Configuration-Reference#tri-exponential-accuracy-and-de-starts) and [Low photon counts](https://github.com/FLIMKit/FLIMKit/wiki/Configuration-Reference#low-photon-counts).
316
316
 
317
317
  **Compiled app and GPU:** The compiled app bundles whatever GPU libraries are installed on the *build* machine. A binary built on Apple Silicon will have MLX/MPS; one built on a CUDA machine will have CUDA. If you need GPU in the compiled app, build it yourself on the target hardware. See [Compiled App](#compiled-app-macos--windows--linux).
318
318
 
@@ -104,7 +104,7 @@ docker run -d \
104
104
  alex1075/flimkit:latest
105
105
  ```
106
106
 
107
- Then open http://localhost:14500 and log in as `flimkit` with that password.
107
+ Then open http://localhost:14500 and log in as `flimkit` with that password. The image won't start without a password.
108
108
 
109
109
  The images are built in [flimkit-docker](https://github.com/FLIMKit/flimkit-docker), which lists the tags (Cellpose, CUDA, ROCm, the noVNC desktop and the headless bridge images), the settings, the compose file for a TrueNAS SCALE custom app, and how to build one yourself.
110
110
 
@@ -248,7 +248,7 @@ Per-pixel fitting uses a batched matrix solver that runs on GPU when a supported
248
248
 
249
249
  `python install.py` detects your hardware and installs the right backend automatically. No extra flags needed at runtime.
250
250
 
251
- **Limitations:** `--free-tau-perpixel` with two or more components prepares the batch on the GPU but fits each pixel with SciPy on the CPU, so a GPU gains little there. `fit_summed` (single global fit) is always CPU, and fast enough not to matter.
251
+ **Limitations:** `--free-tau-perpixel` with two or more components prepares the batch on the GPU but fits each pixel with SciPy on the CPU, so a GPU gains little there. `fit_summed` (single global fit) is always CPU. On 10 known-truth tri-exponential decays at 10^6 photons, fitted with the paired measured IRF, the median errors on the long, mid and short lifetimes are 0.4, 2.1 and 3.3 %, against 0.4, 2.8 and 3.3 % from LAS X. Below about 10^5 photons the components of a tri-exponential decay can't be resolved by any fit; FLIMKit then leads with the mean lifetimes and can fix the lifetimes from the image fit. See [Tri-exponential accuracy and DE starts](https://github.com/FLIMKit/FLIMKit/wiki/Configuration-Reference#tri-exponential-accuracy-and-de-starts) and [Low photon counts](https://github.com/FLIMKit/FLIMKit/wiki/Configuration-Reference#low-photon-counts).
252
252
 
253
253
  **Compiled app and GPU:** The compiled app bundles whatever GPU libraries are installed on the *build* machine. A binary built on Apple Silicon will have MLX/MPS; one built on a CUDA machine will have CUDA. If you need GPU in the compiled app, build it yourself on the target hardware. See [Compiled App](#compiled-app-macos--windows--linux).
254
254
 
@@ -7,7 +7,7 @@ import matplotlib.pyplot as plt
7
7
  from pathlib import Path
8
8
  from flimkit.formats import FLIMFile
9
9
  from ..FLIM.fitters import fit_summed, fit_per_pixel
10
- from ..FLIM.fit_tools import find_irf_peak_bin
10
+ from ..FLIM.fit_tools import find_irf_peak_bin, resolve_rep_period_ns
11
11
  from ..utils.lifetime_image import make_lifetime_image, make_component_rgb_tiff
12
12
  from ..utils.export_png import flim_field_area_um2, tiff_resolution
13
13
  from ..utils.plotting import plot_summed
@@ -102,6 +102,9 @@ def fit_timelapse(ptu_dir, output_dir, args,
102
102
  n_ts = sum(len(pos) for pos in frame_positions.values())
103
103
  print(f'\n[1] Pooling photons across {n_ts} PTU files…')
104
104
  pooled_decay, tcspc_res, n_bins = pool_decays(frame_positions, channel=channel)
105
+ _rep_period = resolve_rep_period_ns(
106
+ getattr(args, 'rep_period_ns', None),
107
+ lambda: FLIMFile(str(next(iter(next(iter(frame_positions.values())).values()))), verbose=False))
105
108
  print(f' Total photons: {pooled_decay.sum():,.0f}')
106
109
  irf_prompt, has_tail, fit_bg, fit_sigma, sigma_max = build_irf(
107
110
  pooled_decay, tcspc_res, n_bins, args)
@@ -132,10 +135,12 @@ def fit_timelapse(ptu_dir, output_dir, args,
132
135
  de_popsize=getattr(args, 'de_population', de_population),
133
136
  de_maxiter=getattr(args, 'de_maxiter', de_maxiter),
134
137
  workers=getattr(args, 'workers', n_workers),
138
+ n_starts=getattr(args, 'n_starts', None), seed=getattr(args, 'seed', 42),
135
139
  polish=not getattr(args, 'no_polish', False),
136
140
  cost_function=getattr(args, 'cost_function', 'poisson'),
137
141
  sigma_max=sigma_max,
138
142
  **_window_kwargs(args),
143
+ rep_period_ns=_rep_period,
139
144
  )
140
145
  print(f' Reference fit: {time.time() - t0:.1f} s')
141
146
  taus_ns = global_summary.get('taus_ns', global_popt[:args.nexp] * 1e9)
@@ -199,6 +204,7 @@ def fit_timelapse(ptu_dir, output_dir, args,
199
204
  fit_idx=global_summary.get('fit_idx'),
200
205
  progress_callback=None,
201
206
  free_tau=False,
207
+ rep_period_ns=_rep_period,
202
208
  )
203
209
  redox = compute_redox_metrics(pixel_maps, args.nexp,
204
210
  compute_bound_fraction=compute_bound_fraction)
@@ -243,10 +249,12 @@ def fit_timelapse(ptu_dir, output_dir, args,
243
249
  de_popsize=getattr(args, 'de_population', de_population),
244
250
  de_maxiter=getattr(args, 'de_maxiter', de_maxiter),
245
251
  workers=getattr(args, 'workers', n_workers),
252
+ n_starts=getattr(args, 'n_starts', None), seed=getattr(args, 'seed', 42),
246
253
  polish=not getattr(args, 'no_polish', False),
247
254
  cost_function=getattr(args, 'cost_function', 'poisson'),
248
255
  sigma_max=sigma_max,
249
256
  **_window_kwargs(args),
257
+ rep_period_ns=_rep_period,
250
258
  )
251
259
  plot_summed(
252
260
  tile_decay, tile_summary, ptu, None,
@@ -422,6 +430,9 @@ def fit_zstack(ptu_dir, output_dir, args,
422
430
  print(f'\n[1] Pooling photons across {n_z} z-slices (one FOV)…')
423
431
  pool_input = {z: {0: p} for z, p in zslices.items()}
424
432
  pooled_decay, tcspc_res, n_bins = pool_decays(pool_input, channel=channel)
433
+ _rep_period = resolve_rep_period_ns(
434
+ getattr(args, 'rep_period_ns', None),
435
+ lambda: FLIMFile(str(next(iter(next(iter(pool_input.values())).values()))), verbose=False))
425
436
  print(f' Total photons: {pooled_decay.sum():,.0f}')
426
437
  irf_prompt, has_tail, fit_bg, fit_sigma, sigma_max = build_irf(
427
438
  pooled_decay, tcspc_res, n_bins, args)
@@ -448,10 +459,12 @@ def fit_zstack(ptu_dir, output_dir, args,
448
459
  de_popsize=getattr(args, 'de_population', de_population),
449
460
  de_maxiter=getattr(args, 'de_maxiter', de_maxiter),
450
461
  workers=getattr(args, 'workers', n_workers),
462
+ n_starts=getattr(args, 'n_starts', None), seed=getattr(args, 'seed', 42),
451
463
  polish=not getattr(args, 'no_polish', False),
452
464
  cost_function=getattr(args, 'cost_function', 'poisson'),
453
465
  sigma_max=sigma_max,
454
466
  **_window_kwargs(args),
467
+ rep_period_ns=_rep_period,
455
468
  )
456
469
  print(f' Reference fit: {time.time() - t0:.1f} s')
457
470
  taus_ns = global_summary.get('taus_ns', global_popt[:args.nexp] * 1e9)
@@ -533,6 +546,7 @@ def fit_zstack(ptu_dir, output_dir, args,
533
546
  fit_idx=global_summary.get('fit_idx'),
534
547
  progress_callback=None,
535
548
  free_tau=False,
549
+ rep_period_ns=_rep_period,
536
550
  )
537
551
  redox = compute_redox_metrics(pixel_maps, args.nexp,
538
552
  compute_bound_fraction=compute_bound_fraction)
@@ -577,10 +591,12 @@ def fit_zstack(ptu_dir, output_dir, args,
577
591
  de_popsize=getattr(args, 'de_population', de_population),
578
592
  de_maxiter=getattr(args, 'de_maxiter', de_maxiter),
579
593
  workers=getattr(args, 'workers', n_workers),
594
+ n_starts=getattr(args, 'n_starts', None), seed=getattr(args, 'seed', 42),
580
595
  polish=not getattr(args, 'no_polish', False),
581
596
  cost_function=getattr(args, 'cost_function', 'poisson'),
582
597
  sigma_max=sigma_max,
583
598
  **_window_kwargs(args),
599
+ rep_period_ns=_rep_period,
584
600
  )
585
601
  plot_summed(
586
602
  tile_decay, tile_summary, ptu, None,
@@ -299,6 +299,41 @@ def propagate_uncertainty(fn, popt, unc, rel_step=1e-4):
299
299
  var = float(grad @ unc['cov'][np.ix_(idx, idx)] @ grad)
300
300
  return float(np.sqrt(var)) if np.isfinite(var) and var >= 0 else np.nan
301
301
 
302
+ def resolve_rep_period_ns(value, reader=None):
303
+ if value is None or str(value).strip() in ('', '0', 'off', 'none', 'None'):
304
+ return None
305
+ if str(value).strip().lower() == 'auto':
306
+ if callable(reader):
307
+ reader = reader()
308
+ period = float(getattr(reader, 'period_ns', 0) or 0)
309
+ if period <= 0:
310
+ raise ValueError('The pulse period is set to auto, but this file does not record the laser '
311
+ 'repetition rate. Enter the period in ns instead (12.5 for 80 MHz).')
312
+ print(f' Pulse period from the file: {period:.3f} ns')
313
+ return period
314
+ period = float(value)
315
+ if period <= 0:
316
+ raise ValueError(f'The pulse period must be a positive number of ns or auto, got {value!r}.')
317
+ return period
318
+
319
+ FAST_COMPONENT_MAX_FRACTION = 0.05
320
+ FAST_COMPONENT_IRF_MULTIPLE = 3.0
321
+
322
+ def fast_component_warnings(taus_ns, fractions, irf_fwhm_ns):
323
+ taus_ns = np.atleast_1d(np.asarray(taus_ns, dtype=float))
324
+ fractions = np.atleast_1d(np.asarray(fractions, dtype=float))
325
+ if len(taus_ns) < 2 or not irf_fwhm_ns or not np.isfinite(irf_fwhm_ns):
326
+ return []
327
+ light = fractions * taus_ns
328
+ light = light / light.sum() if light.sum() > 0 else light
329
+ notes = []
330
+ for i, (tau, frac) in enumerate(zip(taus_ns, light), start=1):
331
+ if tau < FAST_COMPONENT_IRF_MULTIPLE * irf_fwhm_ns and frac < FAST_COMPONENT_MAX_FRACTION:
332
+ notes.append(f'τ{i} is short and small ({tau:.3g} ns, {100 * frac:.1f}% of the photons, '
333
+ f'IRF FWHM {irf_fwhm_ns:.3g} ns): an IRF that does not match the data often '
334
+ f'produces a component like this, so check the IRF before reading it as sample')
335
+ return notes
336
+
302
337
  def uncertainty_warnings(taus_ns, taus_err_ns, tau_corr, rel_limit=0.1, corr_limit=0.95):
303
338
  notes = []
304
339
  taus_ns = np.atleast_1d(np.asarray(taus_ns, dtype=float))