-
Notifications
You must be signed in to change notification settings - Fork 98
Description
I encountered an error when trying to compute image features using sq.im.calculate_image_features
on Visium HD data (downloaded directly from 10x Genomics). The error suggests that the spatial coordinates are out of the expected image bounds.
Here is a minimal reproducible example:
import scanpy as sc
import squidpy as sq
import pandas as pd
import numpy as np
visium_path = 'CRC_FFPE1/binned_outputs/square_016um/'
pd.read_parquet(visium_path+'spatial/tissue_positions.parquet').to_csv(
visium_path+'spatial/tissue_positions_list.csv', index=False
)
adata = sc.read_visium(
visium_path,
genome=None,
count_file='filtered_feature_bc_matrix.h5',
library_id=None,
load_images=True,
source_image_path=None
)
adata.var_names_make_unique()
# Ensure coordinates are float
coor_int = [[float(x[0]), float(x[1])] for x in adata.obsm["spatial"]]
adata.obsm["spatial"] = np.array(coor_int)
library_id = list(adata.uns['spatial'].keys())[0]
scale = adata.uns['spatial'][library_id]['scalefactors']['tissue_hires_scalef']
print(library_id, scale)
img = sq.im.ImageContainer(
adata.uns['spatial'][library_id]['images']['hires'],
scale=scale,
library_id=library_id
)
sq.im.calculate_image_features(
adata,
img,
features="summary",
key_added="image_summary",
n_jobs=1,
scale=scale
)
Observed Error
ValueError: Expected `height` to be in interval `[0, 3886]`, found `-138`.
Additional Context
It seems that the spatial coordinates from Visium HD data (square_016um) may not align with the expected coordinate system in calculate_image_features.
My questions are:
1. Does sq.im.calculate_image_features currently support Visium HD data?
2. Should I manually rescale or transform adata.obsm["spatial"] before running this function?
3. Is there an established preprocessing step for HD data that differs from standard Visium?
Any guidance would be greatly appreciated. Thank you for your work on squidpy!