flimkit 0.14.3__tar.gz → 0.15.0__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 (119) hide show
  1. {flimkit-0.14.3 → flimkit-0.15.0}/PKG-INFO +4 -4
  2. {flimkit-0.14.3 → flimkit-0.15.0}/README.md +3 -3
  3. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/FLIM/batch.py +17 -1
  4. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/FLIM/fit_tools.py +35 -0
  5. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/FLIM/fitters.py +251 -114
  6. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/FLIM/models.py +66 -40
  7. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/FLIM/nb_freetau.py +12 -5
  8. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/FLIM/nb_freetau_cuda.py +9 -4
  9. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/GPU/_base.py +6 -3
  10. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/GPU/torch_lm.py +8 -3
  11. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/expert_settings.py +29 -0
  12. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/fit_help.py +18 -1
  13. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/fov_preview.py +4 -0
  14. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/gui.py +28 -3
  15. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/phasor_panel.py +4 -0
  16. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/roi_tools.py +33 -4
  17. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/_version.py +4 -2
  18. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/batch_cli.py +11 -2
  19. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/configs.py +3 -41
  20. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/formats/PTU/stitch.py +9 -0
  21. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/interactive.py +55 -3
  22. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/utils/display.py +2 -1
  23. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/utils/misc.py +10 -0
  24. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit.egg-info/PKG-INFO +4 -4
  25. {flimkit-0.14.3 → flimkit-0.15.0}/LICENSE.md +0 -0
  26. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/FLIM/__init__.py +0 -0
  27. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/FLIM/assemble.py +0 -0
  28. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/FLIM/bg_tools.py +0 -0
  29. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/FLIM/irf_tools.py +0 -0
  30. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/FLIM/poisson_fit.py +0 -0
  31. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/GPU/__init__.py +0 -0
  32. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/GPU/cuda.py +0 -0
  33. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/GPU/mlx_backend.py +0 -0
  34. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/GPU/mps.py +0 -0
  35. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/GPU/rocm.py +0 -0
  36. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/GPU/torch_backend.py +0 -0
  37. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/app_state.py +0 -0
  38. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/controller.py +0 -0
  39. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/icon.icns +0 -0
  40. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/icon.ico +0 -0
  41. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/icon.png +0 -0
  42. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/irf_widget.py +0 -0
  43. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/mode_controller.py +0 -0
  44. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/modes/__init__.py +0 -0
  45. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/modes/base.py +0 -0
  46. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/modes/batch_mode.py +0 -0
  47. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/modes/fov_mode.py +0 -0
  48. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/modes/irf_mode.py +0 -0
  49. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/modes/phasor_mode.py +0 -0
  50. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/modes/stitch_mode.py +0 -0
  51. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/progress_window.py +0 -0
  52. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/project_panel.py +0 -0
  53. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/results_panel.py +0 -0
  54. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/UI/utils.py +0 -0
  55. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/__init__.py +0 -0
  56. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/cli.py +0 -0
  57. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/dialogs.py +0 -0
  58. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/formats/BH/__init__.py +0 -0
  59. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/formats/BH/reader.py +0 -0
  60. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/formats/BH/writer.py +0 -0
  61. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/formats/ISS/__init__.py +0 -0
  62. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/formats/ISS/fdflim.py +0 -0
  63. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/formats/ISS/image.py +0 -0
  64. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/formats/ISS/reader.py +0 -0
  65. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/formats/PS/__init__.py +0 -0
  66. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/formats/PS/reader.py +0 -0
  67. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/formats/PTU/__init__.py +0 -0
  68. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/formats/PTU/decode.py +0 -0
  69. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/formats/PTU/phu.py +0 -0
  70. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/formats/PTU/reader.py +0 -0
  71. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/formats/PTU/series.py +0 -0
  72. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/formats/PTU/tools.py +0 -0
  73. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/formats/__init__.py +0 -0
  74. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/formats/flim_file.py +0 -0
  75. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/formats/phasor.py +0 -0
  76. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/formats/signal.py +0 -0
  77. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/image/tools.py +0 -0
  78. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/mpl_backend.py +0 -0
  79. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/phasor/__init__.py +0 -0
  80. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/phasor/export.py +0 -0
  81. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/phasor/filters.py +0 -0
  82. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/phasor/fret.py +0 -0
  83. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/phasor/interactive.py +0 -0
  84. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/phasor/peaks.py +0 -0
  85. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/phasor/signal.py +0 -0
  86. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/phasor_launcher.py +0 -0
  87. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/plugins/__init__.py +0 -0
  88. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/plugins/bindings.py +0 -0
  89. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/plugins/builtin/__init__.py +0 -0
  90. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/plugins/builtin/core_tools.py +0 -0
  91. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/plugins/loader.py +0 -0
  92. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/plugins/registry.py +0 -0
  93. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/project.py +0 -0
  94. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/synth.py +0 -0
  95. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/utils/__init__.py +0 -0
  96. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/utils/app_update.py +0 -0
  97. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/utils/apply_settings.py +0 -0
  98. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/utils/batch_fit.py +0 -0
  99. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/utils/config_manager.py +0 -0
  100. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/utils/config_snapshot.py +0 -0
  101. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/utils/crash_handler.py +0 -0
  102. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/utils/enhanced_outputs.py +0 -0
  103. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/utils/export_png.py +0 -0
  104. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/utils/fancy.py +0 -0
  105. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/utils/lifetime_image.py +0 -0
  106. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/utils/ome_zarr.py +0 -0
  107. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/utils/plotting.py +0 -0
  108. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/utils/roi.py +0 -0
  109. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/utils/session.py +0 -0
  110. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/utils/update_check.py +0 -0
  111. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/utils/xlsx_tools.py +0 -0
  112. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit/utils/xml_utils.py +0 -0
  113. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit.egg-info/SOURCES.txt +0 -0
  114. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit.egg-info/dependency_links.txt +0 -0
  115. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit.egg-info/entry_points.txt +0 -0
  116. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit.egg-info/requires.txt +0 -0
  117. {flimkit-0.14.3 → flimkit-0.15.0}/flimkit.egg-info/top_level.txt +0 -0
  118. {flimkit-0.14.3 → flimkit-0.15.0}/pyproject.toml +0 -0
  119. {flimkit-0.14.3 → flimkit-0.15.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flimkit
3
- Version: 0.14.3
3
+ Version: 0.15.0
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
@@ -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
 
@@ -384,9 +384,9 @@ Thank you to the users who have contributed features and reported problems! Many
384
384
 
385
385
  ## AI Disclosure
386
386
 
387
- FLIMKit is designed, developed, and maintained by Alex Hunt. Anthropic's Claude AI was used as an assistant for parts of the implementation. All scientific design, fitting/phasor methods, validation, and the overall architecture are the author's own work. All AI generated content was reviewed, edited and tested on both real and synthetic FLIM data by the author. The author remains responsible for the submitted implementations and their scientific validity.
387
+ FLIMKit is designed, developed, and maintained by the authors. Anthropic's Claude AI was used as an assistant for parts of the implementation. All scientific design, fitting/phasor methods, validation, and the overall architecture are the authors' own work. All AI generated content was reviewed, edited and tested on both real and synthetic FLIM data by the authors. The authors remain responsible for the submitted implementations and their scientific validity.
388
388
 
389
- Contributions by Zhen Yuan were developed with assistance from OpenAI's GPT-5.6 Sol, operated through Hermes Agent by Nous Research. Zhen Yuan directed and reviewed the work. Both he and Alex Hunt have independently reviewed and tested the AI-assisted contributions to ensure scientific validity and correctness.
389
+ Contributions by Zhen Yuan were developed with assistance from OpenAI's GPT-5.6 Sol, operated through Hermes Agent by Nous Research. Zhen Yuan directed and reviewed the work. The authors have independently reviewed and tested the AI-assisted contributions to ensure scientific validity and correctness.
390
390
 
391
391
 
392
392
  ## Contact
@@ -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
 
@@ -320,9 +320,9 @@ Thank you to the users who have contributed features and reported problems! Many
320
320
 
321
321
  ## AI Disclosure
322
322
 
323
- FLIMKit is designed, developed, and maintained by Alex Hunt. Anthropic's Claude AI was used as an assistant for parts of the implementation. All scientific design, fitting/phasor methods, validation, and the overall architecture are the author's own work. All AI generated content was reviewed, edited and tested on both real and synthetic FLIM data by the author. The author remains responsible for the submitted implementations and their scientific validity.
323
+ FLIMKit is designed, developed, and maintained by the authors. Anthropic's Claude AI was used as an assistant for parts of the implementation. All scientific design, fitting/phasor methods, validation, and the overall architecture are the authors' own work. All AI generated content was reviewed, edited and tested on both real and synthetic FLIM data by the authors. The authors remain responsible for the submitted implementations and their scientific validity.
324
324
 
325
- Contributions by Zhen Yuan were developed with assistance from OpenAI's GPT-5.6 Sol, operated through Hermes Agent by Nous Research. Zhen Yuan directed and reviewed the work. Both he and Alex Hunt have independently reviewed and tested the AI-assisted contributions to ensure scientific validity and correctness.
325
+ Contributions by Zhen Yuan were developed with assistance from OpenAI's GPT-5.6 Sol, operated through Hermes Agent by Nous Research. Zhen Yuan directed and reviewed the work. The authors have independently reviewed and tested the AI-assisted contributions to ensure scientific validity and correctness.
326
326
 
327
327
 
328
328
  ## Contact
@@ -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))