Skip to content

Transformations with flipped y-axis #381

Open
@Sonja-Stockhaus

Description

@Sonja-Stockhaus

Sth I encountered while working on #337: when using datashader, transformations of points and shapes need to be applied before rendering. I think the flipping of the y-axis leads to an inconsistency when applying Affine transformations (might also be for other transformations, that's just where I noticed it).

Say we are applying an affine transformation to our blobs polygons, namely a rotation 90° to the right (around 0/0), and then render:

from spatialdata.transformations import Affine
from spatialdata.datasets import blobs
from spatialdata.transformations._utils import _set_transformations

rotation = Affine(
    [
        [0, -1, 0],
        [1, 0, 0],
        [0, 0, 1],
    ],
    input_axes=("x", "y"),
    output_axes=("x", "y"),
)

blob = blobs()
_set_transformations(blob["blobs_polygons"], {"global": rotation})
blob.pl.render_shapes("blobs_polygons", method="matplotlib", outline_alpha=1.0).pl.show()

If I get this correctly, a point can be transformed by performing matrix multiplication with the affine matrix of the transformation, such as np.array([1, 1]) @ np.array([[0, -1], [1, 0]]) which gives [1, -1], therefore rotation by 90° to the right around the point 0/0.

The original image of the blobs polygons without any transformation looks like this:
Image

And the code above (using matplotlib) gives us
Image
Which looks like a rotation to the right around 0/0. However, my question here is that when you flip the y-axis, wouldn't any rotation to the right look like a rotation to the left instead?

My current solution for datashader simply performs the matrix multiplication of all points of the polygons with the transformation matrix. This is all in a "normal", not flipped coordinate system, so when you flip the axes, you would get something like this:
Image
(Looks like a rotation to the left, because the y-axis is flipped).

@LucaMarconato since you're the master of transformations, could you have a look and tell me what you think about it? Is this intended behavior since it is more intuitive for the user?
If yes: do you know an easy way how to get the affine matrix to do the transformation in the y-axis-not-flipped scenario (especially thinking about sequences of transformations...)
If no: the matplotlib version would be "incorrect" and I think get_extent() as well, since it gives us exactly the values that we see in the matplotlib plot (and that's a problem, because in the very end of basic.show(), the axis limits are adapted according to the extent - I only got the datashader plot above by manually overwriting the extent).

(cc: @timtreis)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions