flimkit 0.14.2__tar.gz → 0.14.4__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.2 → flimkit-0.14.4}/PKG-INFO +3 -3
  2. {flimkit-0.14.2 → flimkit-0.14.4}/README.md +2 -2
  3. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/FLIM/nb_freetau.py +12 -5
  4. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/FLIM/nb_freetau_cuda.py +9 -4
  5. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/GPU/_base.py +6 -3
  6. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/GPU/torch_lm.py +8 -3
  7. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/gui.py +44 -134
  8. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/phasor_panel.py +31 -13
  9. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/_version.py +4 -2
  10. flimkit-0.14.4/flimkit/batch_cli.py +337 -0
  11. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/cli.py +8 -0
  12. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/interactive.py +2 -0
  13. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/phasor/export.py +2 -10
  14. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/phasor/filters.py +17 -0
  15. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/phasor_launcher.py +6 -0
  16. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit.egg-info/PKG-INFO +3 -3
  17. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit.egg-info/SOURCES.txt +1 -0
  18. {flimkit-0.14.2 → flimkit-0.14.4}/pyproject.toml +0 -1
  19. {flimkit-0.14.2 → flimkit-0.14.4}/LICENSE.md +0 -0
  20. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/FLIM/__init__.py +0 -0
  21. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/FLIM/assemble.py +0 -0
  22. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/FLIM/batch.py +0 -0
  23. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/FLIM/bg_tools.py +0 -0
  24. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/FLIM/fit_tools.py +0 -0
  25. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/FLIM/fitters.py +0 -0
  26. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/FLIM/irf_tools.py +0 -0
  27. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/FLIM/models.py +0 -0
  28. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/FLIM/poisson_fit.py +0 -0
  29. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/GPU/__init__.py +0 -0
  30. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/GPU/cuda.py +0 -0
  31. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/GPU/mlx_backend.py +0 -0
  32. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/GPU/mps.py +0 -0
  33. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/GPU/rocm.py +0 -0
  34. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/GPU/torch_backend.py +0 -0
  35. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/app_state.py +0 -0
  36. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/controller.py +0 -0
  37. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/expert_settings.py +0 -0
  38. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/fit_help.py +0 -0
  39. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/fov_preview.py +0 -0
  40. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/icon.icns +0 -0
  41. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/icon.ico +0 -0
  42. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/icon.png +0 -0
  43. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/irf_widget.py +0 -0
  44. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/mode_controller.py +0 -0
  45. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/modes/__init__.py +0 -0
  46. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/modes/base.py +0 -0
  47. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/modes/batch_mode.py +0 -0
  48. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/modes/fov_mode.py +0 -0
  49. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/modes/irf_mode.py +0 -0
  50. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/modes/phasor_mode.py +0 -0
  51. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/modes/stitch_mode.py +0 -0
  52. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/progress_window.py +0 -0
  53. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/project_panel.py +0 -0
  54. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/results_panel.py +0 -0
  55. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/roi_tools.py +0 -0
  56. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/UI/utils.py +0 -0
  57. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/__init__.py +0 -0
  58. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/configs.py +0 -0
  59. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/dialogs.py +0 -0
  60. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/formats/BH/__init__.py +0 -0
  61. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/formats/BH/reader.py +0 -0
  62. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/formats/BH/writer.py +0 -0
  63. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/formats/ISS/__init__.py +0 -0
  64. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/formats/ISS/fdflim.py +0 -0
  65. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/formats/ISS/image.py +0 -0
  66. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/formats/ISS/reader.py +0 -0
  67. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/formats/PS/__init__.py +0 -0
  68. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/formats/PS/reader.py +0 -0
  69. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/formats/PTU/__init__.py +0 -0
  70. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/formats/PTU/decode.py +0 -0
  71. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/formats/PTU/phu.py +0 -0
  72. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/formats/PTU/reader.py +0 -0
  73. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/formats/PTU/series.py +0 -0
  74. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/formats/PTU/stitch.py +0 -0
  75. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/formats/PTU/tools.py +0 -0
  76. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/formats/__init__.py +0 -0
  77. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/formats/flim_file.py +0 -0
  78. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/formats/phasor.py +0 -0
  79. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/formats/signal.py +0 -0
  80. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/image/tools.py +0 -0
  81. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/mpl_backend.py +0 -0
  82. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/phasor/__init__.py +0 -0
  83. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/phasor/fret.py +0 -0
  84. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/phasor/interactive.py +0 -0
  85. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/phasor/peaks.py +0 -0
  86. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/phasor/signal.py +0 -0
  87. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/plugins/__init__.py +0 -0
  88. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/plugins/bindings.py +0 -0
  89. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/plugins/builtin/__init__.py +0 -0
  90. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/plugins/builtin/core_tools.py +0 -0
  91. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/plugins/loader.py +0 -0
  92. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/plugins/registry.py +0 -0
  93. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/project.py +0 -0
  94. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/synth.py +0 -0
  95. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/utils/__init__.py +0 -0
  96. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/utils/app_update.py +0 -0
  97. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/utils/apply_settings.py +0 -0
  98. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/utils/batch_fit.py +0 -0
  99. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/utils/config_manager.py +0 -0
  100. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/utils/config_snapshot.py +0 -0
  101. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/utils/crash_handler.py +0 -0
  102. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/utils/display.py +0 -0
  103. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/utils/enhanced_outputs.py +0 -0
  104. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/utils/export_png.py +0 -0
  105. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/utils/fancy.py +0 -0
  106. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/utils/lifetime_image.py +0 -0
  107. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/utils/misc.py +0 -0
  108. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/utils/ome_zarr.py +0 -0
  109. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/utils/plotting.py +0 -0
  110. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/utils/roi.py +0 -0
  111. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/utils/session.py +0 -0
  112. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/utils/update_check.py +0 -0
  113. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/utils/xlsx_tools.py +0 -0
  114. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit/utils/xml_utils.py +0 -0
  115. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit.egg-info/dependency_links.txt +0 -0
  116. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit.egg-info/entry_points.txt +0 -0
  117. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit.egg-info/requires.txt +0 -0
  118. {flimkit-0.14.2 → flimkit-0.14.4}/flimkit.egg-info/top_level.txt +0 -0
  119. {flimkit-0.14.2 → flimkit-0.14.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flimkit
3
- Version: 0.14.2
3
+ Version: 0.14.4
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
@@ -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
@@ -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
@@ -64,19 +64,26 @@ def _evaluate(p, ne, d, w, bg, irf, isum, idx, dt, Y, Z, res, J, want_J):
64
64
  r = math.exp(-dt / tau)
65
65
  drdt[j] = r * dt / (tau * tau)
66
66
  _exp_conv(irf, r, Y[j], Z[j])
67
+ # Poisson maximum likelihood by Fisher scoring: weights come from the current model (not the data),
68
+ # step acceptance uses the Poisson deviance. w (data-based weights) is kept in the signature only.
67
69
  cost = 0.0
68
70
  for q in range(idx.size):
69
71
  i = idx[q]
70
72
  m = bg * isum
71
73
  for j in range(ne):
72
74
  m += p[ne + j] * Y[j, i]
73
- ri = (m - d[i]) / w[i]
74
- cost += ri * ri
75
+ mm = max(m, 1e-12)
76
+ di = d[i]
77
+ if di > 0.0:
78
+ cost += 2.0 * (mm - di + di * math.log(di / mm))
79
+ else:
80
+ cost += 2.0 * mm
75
81
  if want_J == True:
76
- res[q] = ri
82
+ wi = math.sqrt(max(mm, 1.0))
83
+ res[q] = (m - di) / wi
77
84
  for j in range(ne):
78
- J[q, j] = p[ne + j] * Z[j, i] * drdt[j] / w[i]
79
- J[q, ne + j] = Y[j, i] / w[i]
85
+ J[q, j] = p[ne + j] * Z[j, i] * drdt[j] / wi
86
+ J[q, ne + j] = Y[j, i] / wi
80
87
  return cost
81
88
 
82
89
  @nb.njit(cache=True, parallel=True)
@@ -54,13 +54,18 @@ def _evaluate(irf, mask, n, ne, irf_sum, dt, p, data, w_data, b, bg, A, g):
54
54
  z[j] = yp + r[j] * z[j] - n * rn1[j] * ii
55
55
  if mask[i] == 0:
56
56
  continue
57
- wd = w_data[b, i]
58
- wi = math.sqrt(wd if wd > 1.0 else 1.0)
59
57
  m = base
60
58
  for j in range(ne):
61
59
  m += p[ne + j] * y[j]
62
- ri = (m - data[b, i]) / wi
63
- cost += ri * ri
60
+ # Poisson maximum likelihood by Fisher scoring: weights from the current model, cost is the deviance
61
+ mm = m if m > 1e-12 else 1e-12
62
+ di = data[b, i]
63
+ if di > 0.0:
64
+ cost += 2.0 * (mm - di + di * math.log(di / mm))
65
+ else:
66
+ cost += 2.0 * mm
67
+ wi = math.sqrt(mm if mm > 1.0 else 1.0)
68
+ ri = (m - di) / wi
64
69
  for j in range(ne):
65
70
  jq[j] = p[ne + j] * z[j] * drdt[j] / wi
66
71
  jq[ne + j] = y[j] / wi
@@ -345,9 +345,12 @@ class _BackendMixin:
345
345
  full_p, tcspc_res, n_bins, irf_array,
346
346
  n_exp, bg_b, False, False, False,
347
347
  n_sync=n_sync_model)
348
- if win is None:
349
- return (model - decay_b) / wt
350
- return (model[win] - decay_b[win]) / wt[win]
348
+ # Poisson deviance residuals (sum of squares = 2 * Poisson negative log-likelihood ratio)
349
+ m_ = model if win is None else model[win]
350
+ d_ = decay_b if win is None else decay_b[win]
351
+ m_ = np.maximum(m_, 1e-12)
352
+ dev = np.where(d_ > 0, d_ * np.log(np.maximum(d_, 1e-300) / m_), 0.0)
353
+ return np.sign(m_ - d_) * np.sqrt(np.maximum(2.0 * (m_ - d_ + dev), 0.0))
351
354
 
352
355
  try:
353
356
  res = least_squares(_resid, p0, bounds=(lo_px, hi_px),
@@ -21,13 +21,18 @@ def _evaluate(torch, p, ne, data, w, bg, irf_f, irf_sum, idx, dt, n_bins, want_j
21
21
  y, z, drdt = _conv_pair(torch, irf_f, taus, dt, n_bins)
22
22
  y_fit = y[..., idx]
23
23
  model = bg[:, None] * irf_sum + (amps[..., None] * y_fit).sum(dim=1)
24
- res = (model - data) / w
25
- cost = (res * res).sum(dim=1)
24
+ # Poisson maximum likelihood by Fisher scoring: weights come from the current model, cost is the deviance
25
+ mm = torch.clamp(model, min=1e-12)
26
+ pos = data > 0.0
27
+ dev = torch.where(pos, data * torch.log(torch.clamp(data, min=1e-300) / mm), torch.zeros_like(mm))
28
+ cost = (2.0 * (mm - data + dev)).sum(dim=1)
26
29
  if want_jac == False:
27
30
  return cost, None, None
31
+ wm = torch.sqrt(torch.clamp(mm, min=1.0))
32
+ res = (model - data) / wm
28
33
  z_fit = z[..., idx]
29
34
  jac = torch.cat([(amps * drdt)[..., None] * z_fit, y_fit], dim=1)
30
- jac = (jac / w[:, None, :]).transpose(1, 2)
35
+ jac = (jac / wm[:, None, :]).transpose(1, 2)
31
36
  gram = jac.transpose(1, 2) @ jac
32
37
  grad = -(jac.transpose(1, 2) @ res[:, :, None])[:, :, 0]
33
38
  return cost, gram, grad
@@ -2866,8 +2866,27 @@ Anthropic's Claude AI assisted with parts of the GUI implementation.
2866
2866
  correct_pileup = self.bv_batch_correct_pileup.get()
2867
2867
  tvb_ptu_batch = (self.sv_batch_tvb_ptu.get().strip() or None) if hasattr(self, 'sv_batch_tvb_ptu') else None
2868
2868
  expert_overrides = dict(self._expert_overrides)
2869
- from flimkit.interactive import _run_flim_fit
2869
+ from flimkit.batch_cli import fitFov
2870
2870
  import gc, csv as csv_mod
2871
+ bp = argparse.Namespace(
2872
+ nexp=n_exp, dist_type=_batch_model,
2873
+ dist_n_components=(self.iv_ncomp_dist_batch.get() if _batch_model not in ('discrete', 'tail') else 1),
2874
+ fit_t0=expert_overrides.get('fit_t0', False),
2875
+ tau_min=tau_min, tau_max=tau_max,
2876
+ optimizer=expert_overrides.get('optimizer', cfg['Optimizer']),
2877
+ restarts=expert_overrides.get('lm_restarts', cfg['lm_restarts']),
2878
+ de_population=expert_overrides.get('de_population', cfg['de_population']),
2879
+ de_maxiter=expert_overrides.get('de_maxiter', cfg['de_maxiter']),
2880
+ workers=expert_overrides.get('n_workers', cfg['n_workers']),
2881
+ binning=expert_overrides.get('binning_factor', cfg['binning_factor']),
2882
+ min_photons=expert_overrides.get('min_photons', cfg['MIN_PHOTONS_PERPIX']),
2883
+ channel=expert_overrides.get('channels', cfg['channels']),
2884
+ irf_fwhm=expert_overrides.get('irf_fwhm', cfg['IRF_FWHM']),
2885
+ intensity_threshold=thr, correct_pileup=correct_pileup,
2886
+ machine_irf=mirf, estimate_irf='machine_irf', tvb_ptu=tvb_ptu_batch,
2887
+ save_npy=save_npy,
2888
+ irf_align=expert_overrides.get('irf_align', 'steepest_rise'),
2889
+ irf_shift_bins=expert_overrides.get('irf_shift_bins', 2))
2871
2890
  def task(progress_callback, cancel_event):
2872
2891
  csv_path = Path(out_dir) / 'batch_fov_fit_summary.csv'
2873
2892
  header_written = False
@@ -2882,58 +2901,7 @@ Anthropic's Claude AI assisted with parts of the GUI implementation.
2882
2901
  fov_out.mkdir(parents=True, exist_ok=True)
2883
2902
  print(f'\n{'='*50}\n [{idx+1}/{n_total}] {stem}\n{'='*50}')
2884
2903
  try:
2885
- a = argparse.Namespace(
2886
- ptu=str(ptu_path),
2887
- xlsx=None,
2888
- debug_xlsx=False,
2889
- print_config=False,
2890
- irf=None,
2891
- irf_xlsx=None,
2892
- estimate_irf='machine_irf',
2893
- no_xlsx_irf=True,
2894
- machine_irf=mirf,
2895
- irf_bins=cfg['IRF_BINS'],
2896
- irf_fit_width=cfg['IRF_FIT_WIDTH'],
2897
- irf_fwhm=expert_overrides.get('irf_fwhm', cfg['IRF_FWHM']),
2898
- nexp=n_exp,
2899
- dist_type=_batch_model,
2900
- dist_n_components=(self.iv_ncomp_dist_batch.get() if _batch_model not in ('discrete', 'tail') else 1),
2901
- fit_t0=expert_overrides.get('fit_t0', False),
2902
- tau_min=tau_min,
2903
- tau_max=tau_max,
2904
- mode='both',
2905
- binning=expert_overrides.get('binning_factor', cfg['binning_factor']),
2906
- min_photons=expert_overrides.get('min_photons', cfg['MIN_PHOTONS_PERPIX']),
2907
- optimizer=expert_overrides.get('optimizer', cfg['Optimizer']),
2908
- restarts=expert_overrides.get('lm_restarts', cfg['lm_restarts']),
2909
- de_population=expert_overrides.get('de_population', cfg['de_population']),
2910
- de_maxiter=expert_overrides.get('de_maxiter', cfg['de_maxiter']),
2911
- workers=expert_overrides.get('n_workers', cfg['n_workers']),
2912
- no_polish=False,
2913
- channel=expert_overrides.get('channels', cfg['channels']),
2914
- out=str(fov_out / stem),
2915
- no_plots=True,
2916
- cell_mask=False,
2917
- correct_pileup=correct_pileup,
2918
- intensity_threshold=thr,
2919
- irf_align=expert_overrides.get('irf_align', 'steepest_rise'),
2920
- irf_shift_bins=expert_overrides.get('irf_shift_bins', 2),
2921
- tvb_ptu=tvb_ptu_batch,
2922
- tvb_channel=None,
2923
- )
2924
- result = _run_flim_fit(a)
2925
- summary = result.get('global_summary', {})
2926
- pu_pct = result.get('pileup_pct')
2927
- cr_mhz = result.get('count_rate_mhz')
2928
- if not save_npy:
2929
- for f_ in fov_out.glob('*.npy'):
2930
- if not f_.name.endswith('_time_axis_ns.npy'):
2931
- f_.unlink(missing_ok=True)
2932
- gc.collect()
2933
- row = {'fov': stem, 'status': 'OK',
2934
- 'pileup_pct': pu_pct if pu_pct is not None else '',
2935
- 'count_rate_mhz': cr_mhz if cr_mhz is not None else '',
2936
- **summary}
2904
+ row = fitFov(ptu_path, fov_out, bp)
2937
2905
  print(f' OK: {stem}')
2938
2906
  except Exception as exc:
2939
2907
  import traceback; traceback.print_exc()
@@ -2992,11 +2960,28 @@ Anthropic's Claude AI assisted with parts of the GUI implementation.
2992
2960
  correct_pileup = self.bv_batch_correct_pileup.get()
2993
2961
  tvb_ptu_batch = (self.sv_batch_tvb_ptu.get().strip() or None) if hasattr(self, 'sv_batch_tvb_ptu') else None
2994
2962
  expert_overrides = dict(self._expert_overrides)
2995
- from flimkit.formats.PTU.stitch import fit_flim_tiles
2996
- from flimkit.FLIM.assemble import (derive_global_tau, save_assembled_maps,
2997
- assemble_tile_maps)
2998
- from flimkit.utils.lifetime_image import make_lifetime_image, make_component_rgb_tiff
2963
+ from flimkit.batch_cli import fitRoi
2999
2964
  import gc, csv as csv_mod
2965
+ bp = argparse.Namespace(
2966
+ nexp=n_exp, dist_type=_batch_model,
2967
+ dist_n_components=(self.iv_ncomp_dist_batch.get() if _batch_model not in ('discrete', 'tail') else 1),
2968
+ fit_t0=expert_overrides.get('fit_t0', False),
2969
+ tau_min=tau_min, tau_max=tau_max,
2970
+ optimizer=expert_overrides.get('optimizer', 'de'),
2971
+ restarts=expert_overrides.get('lm_restarts', 1),
2972
+ de_population=expert_overrides.get('de_population', cfg['de_population']),
2973
+ de_maxiter=expert_overrides.get('de_maxiter', cfg['de_maxiter']),
2974
+ workers=expert_overrides.get('n_workers', cfg['n_workers']),
2975
+ binning=expert_overrides.get('binning_factor', 1),
2976
+ min_photons=expert_overrides.get('min_photons', cfg['MIN_PHOTONS_PERPIX']),
2977
+ channel=expert_overrides.get('channels', cfg['channels']),
2978
+ irf_fwhm=expert_overrides.get('irf_fwhm', cfg['IRF_FWHM']),
2979
+ intensity_threshold=thr, correct_pileup=correct_pileup,
2980
+ machine_irf=mirf, estimate_irf='machine_irf', tvb_ptu=tvb_ptu_batch,
2981
+ register=register, reg_shift=reg_shift, rotate_tiles=True,
2982
+ tau_lo=tau_lo, tau_hi=tau_hi, int_max=int_max,
2983
+ tau_weighting=('int' if tau_weighting == 'intensity' else 'amp'),
2984
+ gamma=gamma, save_lifetime=save_lifetime, save_rgb=save_rgb, save_npy=save_npy)
3000
2985
  def task(progress_callback, cancel_event):
3001
2986
  csv_path = Path(out_dir) / 'batch_roi_fit_summary.csv'
3002
2987
  header_written = False
@@ -3012,83 +2997,8 @@ Anthropic's Claude AI assisted with parts of the GUI implementation.
3012
2997
  roi_out.mkdir(parents=True, exist_ok=True)
3013
2998
  print(f'\n{'='*50}\n [{idx+1}/{n_total}] {ptu_basename}\n{'='*50}')
3014
2999
  try:
3015
- fit_args = argparse.Namespace(
3016
- nexp=n_exp, dist_type=_batch_model,
3017
- dist_n_components=(self.iv_ncomp_dist_batch.get() if _batch_model not in ('discrete', 'tail') else 1),
3018
- fit_t0=expert_overrides.get('fit_t0', False),
3019
- tau_min=tau_min, tau_max=tau_max,
3020
- optimizer=expert_overrides.get('optimizer', 'de'),
3021
- restarts=expert_overrides.get('lm_restarts', 1),
3022
- de_population=expert_overrides.get('de_population', cfg['de_population']),
3023
- de_maxiter=expert_overrides.get('de_maxiter', cfg['de_maxiter']),
3024
- workers=expert_overrides.get('n_workers', cfg['n_workers']),
3025
- binning=expert_overrides.get('binning_factor', 1),
3026
- min_photons=expert_overrides.get('min_photons', cfg['MIN_PHOTONS_PERPIX']),
3027
- channel=expert_overrides.get('channels', cfg['channels']),
3028
- irf_fwhm=expert_overrides.get('irf_fwhm', cfg['IRF_FWHM']),
3029
- intensity_threshold=thr,
3030
- correct_pileup=correct_pileup,
3031
- register_tiles=register,
3032
- reg_max_shift_px=reg_shift,
3033
- machine_irf=mirf,
3034
- tau_display_min=tau_lo,
3035
- tau_display_max=tau_hi,
3036
- intensity_display_min=0.0,
3037
- intensity_display_max=None,
3038
- irf_xlsx_dir=None, irf_xlsx_map=None,
3039
- ptu_basename=ptu_basename,
3040
- xlif=str(xlif_path),
3041
- ptu_dir=ptu_dir,
3042
- output_dir=str(roi_out),
3043
- no_plots=True, cell_mask=False,
3044
- debug_xlsx=False, print_config=False,
3045
- irf=None, irf_xlsx=None,
3046
- estimate_irf='machine_irf',
3047
- no_xlsx_irf=True,
3048
- tvb_ptu=tvb_ptu_batch,
3049
- tvb_channel=None,
3050
- )
3051
- (tile_results, canvas_h, canvas_w, _, _, _, _, _, _) = fit_flim_tiles(
3052
- xlif_path=xlif_path, ptu_dir=Path(ptu_dir),
3053
- output_dir=roi_out, args=fit_args,
3054
- ptu_basename=ptu_basename, rotate_tiles=True, verbose=True,
3055
- )
3056
- if not tile_results:
3057
- row = {'roi': ptu_basename, 'status': 'No tiles fitted'}
3058
- else:
3059
- canvas = assemble_tile_maps(tile_results, canvas_h, canvas_w, n_exp)
3060
- del tile_results; gc.collect()
3061
- summary = derive_global_tau(canvas, n_exp=n_exp)
3062
- from flimkit.utils.export_png import xlif_field_area_um2
3063
- area_um2 = xlif_field_area_um2(xlif_path, ptu_basename, (canvas_h, canvas_w), fit_args.binning)
3064
- save_assembled_maps(
3065
- canvas=canvas, global_summary=summary,
3066
- output_dir=roi_out, roi_name=roi_clean, n_exp=n_exp,
3067
- tau_display_min=tau_lo, tau_display_max=tau_hi,
3068
- intensity_display_max=int_max,
3069
- tau_weighting=('int' if tau_weighting == 'intensity' else 'amp'),
3070
- field_area_um2=area_um2,
3071
- )
3072
- if save_lifetime:
3073
- make_lifetime_image(
3074
- canvas=canvas, output_dir=roi_out, roi_name=roi_clean,
3075
- tau_min_ns=tau_lo, tau_max_ns=tau_hi,
3076
- smooth_sigma_px=0.0, gamma=gamma, verbose=False,
3077
- tau_key=tau_key, field_area_um2=area_um2,
3078
- )
3079
- if save_rgb:
3080
- make_component_rgb_tiff(
3081
- canvas=canvas, output_dir=roi_out,
3082
- roi_name=roi_clean, n_exp=n_exp, verbose=False,
3083
- field_area_um2=area_um2,
3084
- )
3085
- if not save_npy:
3086
- for f_ in roi_out.glob('*.npy'):
3087
- if not f_.name.endswith('_time_axis_ns.npy'):
3088
- f_.unlink(missing_ok=True)
3089
- del canvas; gc.collect()
3090
- row = {'roi': ptu_basename, 'status': 'OK', **summary}
3091
- print(f' OK: {ptu_basename}')
3000
+ row = fitRoi(xlif_path, ptu_dir, roi_out, bp)
3001
+ print(f' {row["status"]}: {ptu_basename}')
3092
3002
  except Exception as exc:
3093
3003
  import traceback; traceback.print_exc()
3094
3004
  row = {'roi': ptu_basename,
@@ -45,6 +45,9 @@ class PhasorViewPanel:
45
45
  self._filter_method = tk.StringVar(value='none')
46
46
  self._filter_sigma = tk.DoubleVar(value=1.0)
47
47
  self._filter_size = tk.IntVar(value=3)
48
+ self._filter_wavelet = tk.StringVar(value='db4')
49
+ self._filter_level = tk.IntVar(value=1)
50
+ self._filter_threshold = tk.StringVar(value='soft')
48
51
  self._applied_filter = None
49
52
  self._cursors = []
50
53
  self._cursor_artists = []
@@ -145,6 +148,17 @@ class PhasorViewPanel:
145
148
  ttk.Spinbox(self._filt_size_frame, textvariable=self._filter_size,
146
149
  from_=3, to=15, increment=2, width=4).pack(side='left', padx=(2, 6))
147
150
  self._filt_size_frame.pack_forget()
151
+ from flimkit.phasor.filters import THRESHOLD_MODES, WAVELET_NAMES
152
+ self._filt_wavelet_frame = ttk.Frame(row_filt)
153
+ self._filt_wavelet_frame.pack(side='left')
154
+ ttk.Combobox(self._filt_wavelet_frame, textvariable=self._filter_wavelet,
155
+ values=list(WAVELET_NAMES), width=6).pack(side='left', padx=(2, 4))
156
+ ttk.Label(self._filt_wavelet_frame, text='level:').pack(side='left')
157
+ ttk.Spinbox(self._filt_wavelet_frame, textvariable=self._filter_level,
158
+ from_=1, to=6, increment=1, width=3).pack(side='left', padx=(2, 4))
159
+ ttk.Combobox(self._filt_wavelet_frame, textvariable=self._filter_threshold,
160
+ values=list(THRESHOLD_MODES), state='readonly', width=5).pack(side='left', padx=(0, 6))
161
+ self._filt_wavelet_frame.pack_forget()
148
162
  self._filt_apply_btn = ttk.Button(row_filt, text='Apply', command=self._on_filter_apply)
149
163
  self._filt_apply_btn.pack(side='left', padx=(0, 4))
150
164
  ttk.Button(row_filt, text='Reset',
@@ -175,12 +189,17 @@ class PhasorViewPanel:
175
189
  shown = {'sigma'}
176
190
  elif method == 'median':
177
191
  shown = {'size'}
178
- elif method in ('none', 'wavelet'):
192
+ elif method == 'wavelet':
193
+ shown = {'wavelet'}
194
+ elif method == 'none':
179
195
  shown = set()
180
196
  else:
181
197
  shown = self._plugin_filter_params(method)
182
198
  self._filt_sigma_frame.pack_forget()
183
199
  self._filt_size_frame.pack_forget()
200
+ self._filt_wavelet_frame.pack_forget()
201
+ if 'wavelet' in shown:
202
+ self._filt_wavelet_frame.pack(side='left', before=self._filt_apply_btn)
184
203
  if 'sigma' in shown:
185
204
  self._filt_sigma_frame.pack(side='left', before=self._filt_apply_btn)
186
205
  if 'size' in shown:
@@ -194,7 +213,10 @@ class PhasorViewPanel:
194
213
  return
195
214
  spec = dict(method=method,
196
215
  sigma=float(self._filter_sigma.get()),
197
- size=int(self._filter_size.get()))
216
+ size=int(self._filter_size.get()),
217
+ wavelet=self._filter_wavelet.get(),
218
+ level=int(self._filter_level.get()),
219
+ threshold_mode=self._filter_threshold.get())
198
220
  try:
199
221
  self._apply_filter_spec(spec)
200
222
  except Exception as exc:
@@ -216,23 +238,16 @@ class PhasorViewPanel:
216
238
  if method == 'median':
217
239
  return f"median (size={spec['size']})"
218
240
  if method == 'wavelet':
219
- return 'wavelet (db4)'
241
+ return (f"wavelet ({spec.get('wavelet', 'db4')}, level {spec.get('level', 1)}, "
242
+ f"{spec.get('threshold_mode', 'soft')})")
220
243
  return method
221
244
 
222
245
  def _apply_filter_spec(self, spec):
223
- from flimkit.phasor.filters import phasor_filter
246
+ from flimkit.phasor.filters import filter_kwargs, phasor_filter
224
247
  method = spec['method']
225
- kwargs = {}
226
- if method == 'gaussian':
227
- kwargs['sigma'] = float(spec['sigma'])
228
- elif method == 'median':
229
- kwargs['size'] = int(spec['size'])
230
- elif method != 'wavelet':
231
- kwargs['sigma'] = float(spec['sigma'])
232
- kwargs['size'] = int(spec['size'])
233
248
  self._real, self._imag = phasor_filter(
234
249
  self._real_raw.copy(), self._imag_raw.copy(), method,
235
- mean=self._mean, **kwargs)
250
+ mean=self._mean, **filter_kwargs(spec))
236
251
  self._applied_filter = dict(spec)
237
252
 
238
253
  def _on_filter_reset(self):
@@ -329,6 +344,9 @@ class PhasorViewPanel:
329
344
  if spec.get('method', 'none') not in ('none', '', None):
330
345
  self._filter_sigma.set(float(spec.get('sigma', 1.0)))
331
346
  self._filter_size.set(int(spec.get('size', 3)))
347
+ self._filter_wavelet.set(str(spec.get('wavelet', 'db4')))
348
+ self._filter_level.set(int(spec.get('level', 1)))
349
+ self._filter_threshold.set(str(spec.get('threshold_mode', 'soft')))
332
350
  self._filter_method.set(spec['method'])
333
351
  try:
334
352
  self._apply_filter_spec(spec)
@@ -1,5 +1,5 @@
1
- __version__ = '0.14.2'
2
- fitter_version = '25'
1
+ __version__ = '0.14.4'
2
+ fitter_version = '26'
3
3
  app_name = 'FLIMKitDEV' if '+dev' in __version__ else 'FLIMKit'
4
4
 
5
5
  roadmap = '''Flim program roadmap:
@@ -51,5 +51,7 @@ Need to add Phasor once added to the codebase, and update version to 1.0. And ad
51
51
  0.14.0 -> free-tau per-pixel fits run in numba instead of scipy once per pixel, on the CPU and on NVIDIA GPUs through numba.cuda, and on a CUDA or ROCm card through torch as a batched Levenberg-Marquardt, so fitter_version goes to 24. The @fit_backend plugin hook lets an add-on run the per-pixel fits on its own C or CUDA code; flimkit-accelerator-plugin is the worked example and can speed free tau up considerably, though nothing needs it. Fixed two fitting bugs: stitched and batch ROI fits paired each tile's amplitudes with the wrong lifetimes, and CPU free-tau fits used the wrong IRF when the IRF had a fitted tail and the background was fitted. Summed fits report standard errors and, by default, bootstrap errors. Export all, phasor PNG export, an in-app update check and update.py. FLIMKitDEV is built from dev.
52
52
  0.14.1 -> the compiled desktop app starts on Linux again: PIL._tkinter_finder is bundled, so the matplotlib toolbar no longer dies on a missing module. The installation check accepts an add-on fit backend that solves every free-tau pixel itself instead of demanding that some reach the scipy solver. Releases now publish to PyPI on their own: a release created by the build workflow does not trigger the publish workflow, so the build dispatches it. No fitted number changes, so fitter_version stays at 24.
53
53
  0.14.2 -> fixed-tau per-pixel fits with two or more components estimate the amplitudes by Poisson maximum likelihood with a fitted constant offset, so fitter_version goes to 25. The earlier projection stays behind Earlier projection for fixed tau in Expert Settings and --estimator nnls. A fit backend can take the Poisson fit by listing poisson in its estimators attribute. The IRF selector is one dropdown.
54
+ 0.14.3 -> batch tiled ROI and single FOV fits in the terminal UI and as scripts, sharing their code with the GUI batch. The wavelet phasor filter has a wavelet, a level and a threshold setting.
55
+ 0.14.4 -> free-tau per-pixel fits fit the Poisson likelihood instead of a chi-squared weighted by the observed counts, which biased the lifetimes at low counts, so fitter_version goes to 26.
54
56
  1.0.0 -> release version with all core features implemented and tested
55
57
  1.5.0 (or 2.0) -> validation of fitting results with known fluorophores.'''