Skip to content

Fix but render_shapes() when coordinate system "global" not present #446

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

Merged
merged 1 commit into from
Apr 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/spatialdata_plot/pl/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def _render_shapes(
sdata_filt.shapes[element].loc[is_point, "geometry"] = _geometry[is_point].buffer(scale.to_numpy())

# apply transformations to the individual points
element_trans = get_transformation(sdata_filt.shapes[element])
element_trans = get_transformation(sdata_filt.shapes[element], to_coordinate_system=coordinate_system)
tm = _get_transformation_matrix_for_datashader(element_trans)
transformed_element = sdata_filt.shapes[element].transform(
lambda x: (np.hstack([x, np.ones((x.shape[0], 1))]) @ tm)[:, :2]
Expand All @@ -195,7 +195,7 @@ def _render_shapes(
)

plot_width, plot_height, x_ext, y_ext, factor = _get_extent_and_range_for_datashader_canvas(
transformed_element, coordinate_system, ax, fig_params
transformed_element, "global", ax, fig_params
Copy link
Member

@LucaMarconato LucaMarconato Apr 21, 2025

Choose a reason for hiding this comment

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

@melonora why "global" here? What if "global" is not used in the dataset that is being plotted?

Copy link
Member

Choose a reason for hiding this comment

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

@melonora why was this merged? I think Lucas concern is valid here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Already talked with Luca (sorry tagging does not work on github app) and it is due to the recent change in which global is not required. This caused errors for datasets not having global. However, here the element first gets transformed and after transform the default cs in case nothing is passed on is global. Hence, second call always uses global.

Copy link
Member

@timtreis timtreis Apr 22, 2025

Choose a reason for hiding this comment

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

But shouldn't we preserve whatever name the user gave the cs? I think we reuse that as the default title for a CS when plotting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will have another look when I am at my laptop again. Note that the 'coordinate_system' parameter itself is not being altered here. The point is that after the transform there is no other cs but global.

Copy link
Member

Choose a reason for hiding this comment

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

At the very end of basic.py we're assigning these as titles here:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just as a last follow up, this is not an issue as the title is still correspondent to the coordinate system used. I would have to follow up but it could be that the coordinate system argument in the second call where now the value by default is "global" can be deprecated.

For now just as final proof of the visium hd example in the notebooks. The following code snippet before was failing:

import spatialdata as sd
import spatialdata_plot
import matplotlib.pyplot as plt

sdata = sd.read_zarr("visium_hd.zarr")

plt.figure(figsize=(10, 10))
ax = plt.gca()

gene_name = "AA986860"
sdata.pl.render_shapes("Visium_HD_Mouse_Small_Intestine_square_016um", color=gene_name, method="datashader").pl.show(
    coordinate_systems="Visium_HD_Mouse_Small_Intestine", ax=ax
)

However, this PR fixes the issue of having the wrong coordinate system as argument in the second call and gives you this plot:
image

)

cvs = ds.Canvas(plot_width=plot_width, plot_height=plot_height, x_range=x_ext, y_range=y_ext)
Expand Down
Loading