Skip to content

Optimizations, closes #1070#1071

Open
Teranis wants to merge 57 commits intomainfrom
optimizations
Open

Optimizations, closes #1070#1071
Teranis wants to merge 57 commits intomainfrom
optimizations

Conversation

@Teranis
Copy link
Copy Markdown
Member

@Teranis Teranis commented Apr 7, 2026

  • updated RP to
    • Cache centroids
    • Estimate centroids based on bbox if exact is not important
    • Ability to update only the cutout of the entire lab (GUI can use bbox of "old" obj before change, current view or custom bbox
      • handles border touching correctly (ignore if specific IDs are provided and not part of it, otherwise label them with mask)
    • Apply assignment changes (Just ID swaps, for example, from tracker) and avoid recomputing RP altogether
    • Apply deletions (similar to assignments)
  • updated CellACDC trackers to
    • return assignments for real-time tracking
    • Handle tracking for only a subset of IDs inside the tracker itself
  • updated GUI:
    • Integration of new RP functionality
    • Left some comments to review together with @ElpadoCan
    • Updated swapping and assigning IDs to use RP (merge safe!)
    • Clear border uses its own implementation
    • Set Lost centroids now look for the closest pixel with the correct ID
    • Loading optimisation from acdc_df (minor, but nice for 3D)
    • Segm metadata, loading of data if applicable
  • Updated debugutils to have a line benchmark decorator for nice execution time stats
  • Drawing missing IDs now uses bulk, significant speedup and memory save for many new obj

Questions:
Is update_rp always called? Also, when modifying unvisited frames?

Teranis and others added 27 commits April 6, 2026 20:16
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
@Teranis Teranis marked this pull request as ready for review April 27, 2026 17:54
@Teranis Teranis requested review from ElpadoCan and Copilot April 27, 2026 17:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 24 out of 39 changed files in this pull request and generated 5 comments.

Comments suppressed due to low confidence (1)

cellacdc/workers.py:185

  • These accesses assume data_dict['regionprops'] is an acdcRegionprops with .IDs/.IDs_set. If older/alternate code paths still store a plain skimage.measure.regionprops list here, this will raise AttributeError even when lab is present. Consider using a small helper like IDs = rp.IDs if hasattr(rp, 'IDs') else [obj.label for obj in rp] (and similarly for IDs_set).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cellacdc/__init__.py Outdated
Comment on lines +811 to +826
precompiled_import_success = False
try:
from cellacdc.precompiled.precompiled_functions import (
find_all_objects_2D,
find_all_objects_3D,
calc_IoA_matrix_2D,
calc_IoA_matrix_3D,
)
precompiled_import_success = True
except Exception as err:
import traceback
print('[WARNING]: could not import precompiled functions, falling back to pure python versions. ')
traceback.print_exc()

if precompiled_import_success:
print('Precompiled functions imported successfully.') No newline at end of file
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importing cellacdc now prints to stdout/stderr (warning + full traceback on ImportError, and a success message on success). Import-time prints are noisy in CLI/GUI contexts and can break tools that rely on clean stdout. Consider using the project logger (or warnings.warn) and avoid printing tracebacks unless an explicit debug flag/environment variable is enabled.

Copilot uses AI. Check for mistakes.
Comment thread cellacdc/workers.py
Comment on lines +5188 to 5190
IDs = data_dict['regionprops'].IDs
checker = core.CcaIntegrityChecker(cca_df, lab, IDs)

Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDs = data_dict['regionprops'].IDs assumes regionprops is an acdcRegionprops. If it is ever a plain list of RegionProperties (e.g., legacy cached state), this will raise AttributeError and prevent integrity checks from running. Use the same fallback pattern as elsewhere (e.g., hasattr(rp, 'IDs')).

Copilot uses AI. Check for mistakes.
Comment thread cellacdc/myutils.py Outdated
Comment thread cellacdc/myutils.py Outdated
Comment thread cellacdc/regionprops.py
self.ID_to_idx = {obj.label: idx for idx, obj in enumerate(self._rp)}
# Update IDs and IDs_set separately and explicitly
self.IDs_set = set(self.ID_to_idx)
self.IDs = list(self.IDs_set)
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_attributes builds self.IDs from list(self.IDs_set). Since sets are unordered, this makes rp.IDs nondeterministic between runs, which can lead to flaky behavior in callers that iterate rp.IDs. Prefer preserving region order (e.g., list(self.ID_to_idx) / [obj.label for obj in self._rp]) or explicitly sorting.

Suggested change
self.IDs = list(self.IDs_set)
self.IDs = list(self.ID_to_idx)

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 24 out of 39 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cellacdc/trackers/CellACDC/CellACDC_tracker.py
Comment thread cellacdc/regionprops.py
Comment thread cellacdc/regionprops.py
Comment thread cellacdc/load.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants