Skip to content

Include dataset id in visium HD reader #278

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 2 commits into from
Feb 23, 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
19 changes: 12 additions & 7 deletions src/spatialdata_io/readers/visium_hd.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ def _get_bins(path_bins: Path) -> list[str]:
shapes_name = dataset_id + "_" + bin_size_str
radius = scalefactors[VisiumHDKeys.SCALEFACTORS_SPOT_DIAMETER_FULLRES] / 2.0
transformations = {
"global": transform_original,
"downscaled_hires": transform_hires,
"downscaled_lowres": transform_lowres,
dataset_id: transform_original,
f"{dataset_id}_downscaled_hires": transform_hires,
f"{dataset_id}_downscaled_lowres": transform_lowres,
}
circles = ShapesModel.parse(
adata.obsm["spatial"],
Expand Down Expand Up @@ -322,7 +322,10 @@ def _get_bins(path_bins: Path) -> list[str]:
)
set_transformation(
images[dataset_id + "_hires_image"],
{"downscaled_hires": Identity(), "global": transform_hires.inverse()},
{
f"{dataset_id}_downscaled_hires": Identity(),
dataset_id: transform_hires.inverse(),
},
set_all=True,
)

Expand All @@ -340,7 +343,10 @@ def _get_bins(path_bins: Path) -> list[str]:
)
set_transformation(
images[dataset_id + "_lowres_image"],
{"downscaled_lowres": Identity(), "global": transform_lowres.inverse()},
{
f"{dataset_id}_downscaled_lowres": Identity(),
dataset_id: transform_lowres.inverse(),
},
set_all=True,
)

Expand All @@ -365,7 +371,7 @@ def _get_bins(path_bins: Path) -> list[str]:
projective /= projective[2, 2]
if _projective_matrix_is_affine(projective):
affine = Affine(projective, input_axes=("x", "y"), output_axes=("x", "y"))
set_transformation(image, affine, "global")
set_transformation(image, affine, dataset_id)
else:
# the projective matrix is not affine, we will separate the affine part and the projective shift, and apply
# the projective shift to the image
Expand Down Expand Up @@ -413,7 +419,6 @@ def _get_bins(path_bins: Path) -> list[str]:

if annotate_table_by_labels:
for bin_size_str in bin_sizes:

shapes_name = dataset_id + "_" + bin_size_str

# add labels layer (rasterized bins).
Expand Down
Loading