Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ngio projection #866

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Ngio projection #866

wants to merge 6 commits into from

Conversation

lorenzocerrone
Copy link
Collaborator

  • Add ngio to dependecies
  • Refactor projection task to use ngio

Checklist before merging

  • I added an appropriate entry to CHANGELOG.md

Copy link

github-actions bot commented Nov 15, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  fractal_tasks_core/tables
  v1.py
  fractal_tasks_core/tasks
  projection.py 29, 77
Project Total  

This report was generated by python-coverage-comment-action

logger.info(f"{init_args.origin_url=}")
logger.info(f"{zarr_url=}")
logger.info(f"{method=}")
ngio_logger.info(f"{init_args.origin_url=}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the plan to generally transition to using ngio logger in any task that uses ngio?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the plan to generally transition to using ngio logger in any task that uses ngio?

In my opinion we should not do this, and we should rather keep two different loggers - ref #867

@@ -189,5 +142,5 @@ def projection(

run_fractal_task(
Copy link
Collaborator

Choose a reason for hiding this comment

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

To discuss with @tcompa: When does run_fractal_task use the logger name? Is the ngio_logger also a reasonable choice here?

)

roi_list = []
for roi in table.rois:
roi.z_length = roi.z + 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to set roi.z = 0, to avoid getting IndexErrors if roi.z was not 0 before. It should be 0 before in all our cases though

Copy link
Collaborator

Choose a reason for hiding this comment

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

Follow-up: why is roi.z even needed here? That is, why not setting roi.z_length = 1?
Naively, I expect roi.z to be some kind of coordinate, which should not matter when assigning a value to a length.

@jluethi
Copy link
Collaborator

jluethi commented Nov 15, 2024

This is great @lorenzocerrone !

A few brief questions: Have you tried running this projection task on a zyx dataset (no channel or time dimension)? Could we easily add a synthetic test case for that using an ngio generated tiny zyx OME-Zarr. That then closes #840

Also, would we expect this task to already work with time-data, e.g. an tczyx dataset?

How much we should test in tasks-core?
We test separately in tasks core only when there is task logic specifically to those cases

Can we add an option to copy over additional tables (e.g. user can deactivate that, but we copy non-roi tables by default). We'd keep them & ignore edge-cases (like missing label images) for now. TODO Joel: provide example dataset of condition tables for this.
Approach: First copy them as they are (by adding a include_table flag to the derive function or by adding a copy_tables function). Then modify the ROI tables in place in the new Zarr => let's go with a copy_tables function

TODO for myself:

@tcompa tcompa mentioned this pull request Nov 19, 2024
@@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12"]
Copy link
Collaborator

@tcompa tcompa Nov 19, 2024

Choose a reason for hiding this comment

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

Unclear to me: are we planning to keep support for python3.9 in fractal-tasks-core? If so, is there a specific reason for removing from the CI?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, we're planning to drop support for Python 3.9 in fractal-tasks-core

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's also drop it in pyproject.toml

Comment on lines +28 to +29
if TYPE_CHECKING:
from ngio.core import Image
Copy link
Collaborator

@tcompa tcompa Nov 19, 2024

Choose a reason for hiding this comment

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

I am a bit confused by this approach. Any clarification is welcome.

For instance:

  1. Why do we use Image, if this function always receives NgffImage objects? Now I got it, I was mixing up original_ngff_image and original_image
  2. Independently on point 1, does importing Image have any side-effect? If not, is there a special reason for hiding it behind TYPE_CHECKING or is it "only" as a best practice? (e.g. because the import is slow, or if there are circular imports)

Copy link
Collaborator

Choose a reason for hiding this comment

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

TBD: Coming in a separate PR if we want this style across tasks core

# Ends

# Copy over the tables
for roi_table in original_ngff_image.tables.list(table_type="roi_table"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor readability detail:

table = something(roi_table) was very confusing at a first read, before checking what original_ngff_image.tables.list( actually does. I'd suggest renaming roi_table into e.g. roi_table_name or table_name.

new_image.consolidate()
# Ends

# Copy over the tables
Copy link
Collaborator

Choose a reason for hiding this comment

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

Naive question by someone who is not involved in ngio development/integration: where does this feature fit best?

Would it make sense to have something like

ngio.copy_tables(original_ngff_image, new_ngff_image, project_z=True)

or at least

ngio.copy_tables(original_ngff_image, new_ngff_image)
# and then set `z_length` manually

or would it be just additional complexity?

@tcompa
Copy link
Collaborator

tcompa commented Nov 19, 2024

Thanks @lorenzocerrone!
I added a few small comments, but the pattern is often the same (I am no expert in ngio, and then questions pop up frequently independently on the actual PR). I think we are at a stage where it would be useful to briefly discuss this live.

@tcompa tcompa marked this pull request as draft November 19, 2024 10:29
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