Skip to content

Cases not currently covered by the aggergation #216

Open

Description

@LucaMarconato

Overview issue listing all the remaining cases that need to be implemented in aggregation; tests need to be added for each of them.

  • aggregate points by labels. See dedicated issue here: Aggregate points by labels #209
    • subtask, handle the case in which the labels are multiscale
  • aggregate labels by labels
    • subtask, handle the case in which the labels are multiscale
  • aggregate shapes by labels
    • subtask, handle the case in which the labels are multiscale
  • aggregate labels by shapes
    • subtask, handle the case in which the labels are multiscale
  • aggregate images by shapes
    • subtask, handle the case in which the images are multiscale

Additional points to consider:

  • Allow aggregation of raster with different resolution or non-overlapping areas (affine transform). To do this the strategy is to call rasterize() on all the raster elements involved into a common resolution. Non-overlapping areas are padded with 0 (background) by default by rasterize().
    • I think also the case in which two raster objects contain translations is not covered (for instance having two images with the same resolution, but with different translations/rotations, so that the overlap is actually smaller). I would wait for the new coordinate systems refactoring to be ready before implementing this.
  • The 3D case needs to be handled. I would add the implementation (and a corresponding Github issue to track) in the future, but I would already add all the if-else branches in the code that lead to these cases, with NotImplementedError()

Activity

  1. MeyerBender commented on Aug 3, 2026

    @MeyerBender
    Contributor

    Hi @LucaMarconato,

    I would like to come back to this. Right now I have an object that contains an image as well as some shapes. I am trying to compute features such as the mean marker intensity per cell. To do so, I was thinking of using rasterize() and aggregate(), however, I am having issues in making this work.

    For a start, I cannot even properly rasterize my shapes. This is what I would like to do:

    cell_boundaries_rasterized = sd.rasterize(
        sdata["cell_boundaries"],
        min_coordinate=[0, 0],
        max_coordinate=[15_000, 40_000],
        axes=("x", "y"),
        target_coordinate_system="global",
        target_unit_to_pixels=1,
    )
    sdata.labels["cell_boundaries_rasterized"] = sd.models.Labels2DModel.parse(cell_boundaries_rasterized)
    

    I have several questions about this. First, is it possible to infer the min and max coordinate dynamically? Putting these in manually seems prone to introduce bugs, especially when transformations are present in the object. Furthermore, rasterize() returns the dimensions ('c', 'y', 'x'). To parse them into a Labels2DModel, the c coordinate should not be present here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions