spatialdata
spatialdata copied to clipboard
CosMx data `render_images` after cropping via `query.bounding_box`
Hi @LucaMarconato
great work on spatialdata! I started playing around with this and noticed and error when cropping an image from the CosMx dataset:
import spatialdata as sd
data = sd.read_zarr("data.zarr")
cur_img = data.filter_by_coordinate_system("10")
cropped_img = cur_img.query.bounding_box(
axes=["x", "y"],
min_coordinate=[1000,1500],
max_coordinate=[1500,2000],
target_coordinate_system="10"
)
cropped_img.pl.render_images().pl.show()
returns
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Cell In[119], line 1
----> 1 cropped_img.pl.render_images().pl.show(coordinate_systems="10")
File ~/opt/anaconda3/envs/spatialdata-env/lib/python3.9/site-packages/spatialdata_plot/pl/basic.py:645, in PlotAccessor.show(self, coordinate_systems, legend_fontsize, legend_fontweight, legend_loc, legend_fontoutline, na_in_legend, colorbar, wspace, hspace, ncols, frameon, figsize, dpi, fig, title, share_extent, pad_extent, ax, return_ax, save)
643 if members["has_labels"].values[0]:
644 for key in sdata.labels:
--> 645 sdata.labels[key] = _robust_transform(sdata.labels[key], cs)
647 if members["has_points"].values[0]:
648 for key in sdata.points:
File ~/opt/anaconda3/envs/spatialdata-env/lib/python3.9/site-packages/spatialdata_plot/pl/utils.py:1145, in _robust_transform(element, cs)
1143 for _, t in enumerate(transformations):
1144 if isinstance(t, sd.transformations.transformations.Translation):
-> 1145 element = _translate_image(image=element, translation=t)
1147 elif isinstance(t, sd.transformations.transformations.Affine):
1148 # edge case, waiting for Luca to decompose affine into components
1149 # element = transform(element, t)
(...)
1156 # element = _robust_transform(element, cs)
1157 # print(element.shape)
1158 pass
File ~/opt/anaconda3/envs/spatialdata-env/lib/python3.9/site-packages/spatialdata_plot/pl/utils.py:1099, in _translate_image(image, translation)
...
807 )
809 y_axis_name = "y"
810 if axis_names and "y" in axis_names:
IndexError: tuple index out of range
This is my environment:
abseil-cpp 20211102.0 he9d5cce_0
aiobotocore 2.5.4 pypi_0 pypi
aiofiles 22.1.0 py39hecd8cb5_0
aiohttp 3.8.5 pypi_0 pypi
aioitertools 0.11.0 pypi_0 pypi
aiosignal 1.3.1 pypi_0 pypi
aiosqlite 0.18.0 py39hecd8cb5_0
alabaster 0.7.12 pyhd3eb1b0_0
anndata 0.9.2 pypi_0 pypi
anyio 3.5.0 py39hecd8cb5_0
app-model 0.2.0 pyhd8ed1ab_0 conda-forge
appdirs 1.4.4 pyhd3eb1b0_0
appnope 0.1.2 py39hecd8cb5_1001
argon2-cffi 21.3.0 pyhd3eb1b0_0
argon2-cffi-bindings 21.2.0 py39hca72f7f_0
arrow-cpp 11.0.0 h89a8245_1
asciitree 0.3.3 py_2
asttokens 2.0.5 pyhd3eb1b0_0
async-timeout 4.0.3 pypi_0 pypi
attrs 22.1.0 py39hecd8cb5_0
aws-c-common 0.6.8 h6c40b1e_1
aws-c-event-stream 0.1.6 hcec6c5f_6
aws-checksums 0.1.11 h6c40b1e_2
aws-sdk-cpp 1.8.185 h1a8d504_1
babel 2.11.0 py39hecd8cb5_0
backcall 0.2.0 pyhd3eb1b0_0
beautifulsoup4 4.12.2 py39hecd8cb5_0
blas 1.0 mkl
bleach 4.1.0 pyhd3eb1b0_0
blosc 1.21.3 hcec6c5f_0
bokeh 3.2.1 py39h20db666_0
boost-cpp 1.73.0 hca72f7f_12
botocore 1.31.17 pypi_0 pypi
bottleneck 1.3.5 py39h67323c0_0
brotli 1.0.9 hca72f7f_7
brotli-bin 1.0.9 hca72f7f_7
brotlipy 0.7.0 py39h9ed2024_1003
brunsli 0.1 h23ab428_0
bzip2 1.0.8 h1de35cc_0
c-ares 1.19.0 h6c40b1e_0
ca-certificates 2023.05.30 hecd8cb5_0
cachey 0.2.1 pyh9f0ad1d_0 conda-forge
certifi 2023.7.22 py39hecd8cb5_0
cffi 1.15.1 py39h6c40b1e_3
cfitsio 3.470 hbd21bf8_7
charls 2.2.0 h23ab428_0
charset-normalizer 2.0.4 pyhd3eb1b0_0
click 8.0.4 py39hecd8cb5_0
click-plugins 1.1.1 pypi_0 pypi
cligj 0.7.2 pypi_0 pypi
cloudpickle 2.2.1 py39hecd8cb5_0
colorama 0.4.6 py39hecd8cb5_0
colorcet 3.0.1 pypi_0 pypi
comm 0.1.2 py39hecd8cb5_0
contourpy 1.0.5 py39haf03e11_0
cryptography 41.0.2 py39h3b477ad_0
cycler 0.11.0 pypi_0 pypi
cytoolz 0.12.0 py39hca72f7f_0
dask 2023.6.0 py39hecd8cb5_0
dask-core 2023.6.0 py39hecd8cb5_0
dask-image 2023.8.1 pypi_0 pypi
datashader 0.15.2 pypi_0 pypi
datashape 0.5.2 pypi_0 pypi
debugpy 1.6.7 py39hcec6c5f_0
decorator 5.1.1 pyhd3eb1b0_0
defusedxml 0.7.1 pyhd3eb1b0_0
distributed 2023.6.0 py39hecd8cb5_0
docstring_parser 0.15 pyhd8ed1ab_0 conda-forge
docutils 0.17.1 py39hecd8cb5_1
entrypoints 0.4 py39hecd8cb5_0
executing 0.8.3 pyhd3eb1b0_0
expat 2.4.9 he9d5cce_0
fasteners 0.16.3 pyhd3eb1b0_0
fiona 1.9.4.post1 pypi_0 pypi
fontconfig 2.14.1 hb0a0c50_2
fonttools 4.42.1 pypi_0 pypi
freetype 2.12.1 hd8bbffd_0
freetype-py 2.2.0 pyhd3eb1b0_0
frozenlist 1.4.0 pypi_0 pypi
fsspec 2023.4.0 py39hecd8cb5_0
geopandas 0.13.2 pypi_0 pypi
gflags 2.2.2 h0a44026_0
giflib 5.2.1 h6c40b1e_3
glog 0.5.0 h23ab428_0
greenlet 2.0.2 pypi_0 pypi
grpc-cpp 1.48.2 h4ed1731_1
h5py 3.9.0 pypi_0 pypi
heapdict 1.0.1 pyhd3eb1b0_0
hsluv 5.0.3 py39hecd8cb5_0
icu 58.2 h0a44026_3
idna 3.4 py39hecd8cb5_0
imagecodecs 2021.8.26 py39h8a96914_2
imageio 2.31.1 py39hecd8cb5_0
imagesize 1.4.1 py39hecd8cb5_0
importlib-metadata 6.0.0 py39hecd8cb5_0
importlib-resources 6.0.1 pypi_0 pypi
importlib_metadata 6.0.0 hd3eb1b0_0
in-n-out 0.1.8 pyhd8ed1ab_0 conda-forge
intel-openmp 2023.1.0 ha357a0b_43547
ipykernel 6.25.0 py39h20db666_0
ipython 8.12.2 py39hecd8cb5_0
ipython_genutils 0.2.0 pyhd3eb1b0_1
jedi 0.18.1 py39hecd8cb5_1
jinja2 3.1.2 py39hecd8cb5_0
jmespath 1.0.1 pypi_0 pypi
joblib 1.3.2 pypi_0 pypi
jpeg 9e h6c40b1e_1
json5 0.9.6 pyhd3eb1b0_0
jsonschema 4.17.3 py39hecd8cb5_0
jupyter-cache 0.6.1 pypi_0 pypi
jupyter_client 7.4.9 py39hecd8cb5_0
jupyter_core 5.3.0 py39hecd8cb5_0
jupyter_events 0.6.3 py39hecd8cb5_0
jupyter_server 1.23.4 py39hecd8cb5_0
jupyter_server_fileid 0.9.0 py39hecd8cb5_0
jupyter_server_ydoc 0.8.0 py39hecd8cb5_1
jupyter_ydoc 0.2.4 py39hecd8cb5_0
jupyterlab 3.6.3 py39hecd8cb5_0
jupyterlab_pygments 0.1.2 py_0
jupyterlab_server 2.22.0 py39hecd8cb5_0
jxrlib 1.1 haf1e3a3_2
kiwisolver 1.4.4 py39hcec6c5f_0
krb5 1.20.1 h428f121_1
lazy_loader 0.2 py39hecd8cb5_0
lcms2 2.12 hf1fd2bf_0
lerc 3.0 he9d5cce_0
libaec 1.0.4 hb1e8313_1
libboost 1.73.0 h3fa6bed_12
libbrotlicommon 1.0.9 hca72f7f_7
libbrotlidec 1.0.9 hca72f7f_7
libbrotlienc 1.0.9 hca72f7f_7
libcurl 8.1.1 hf20ceda_2
libcxx 14.0.6 h9765a3e_0
libdeflate 1.17 hb664fd8_0
libedit 3.1.20221030 h6c40b1e_0
libev 4.33 h9ed2024_1
libevent 2.1.12 h04015c4_1
libffi 3.4.4 hecd8cb5_0
libgfortran 5.0.0 11_3_0_hecd8cb5_28
libgfortran5 11.3.0 h9dfd629_28
libiconv 1.16 hca72f7f_2
libnghttp2 1.52.0 h9beae6a_1
libpng 1.6.39 h6c40b1e_0
libprotobuf 3.20.3 hfff2838_0
libsodium 1.0.18 h1de35cc_0
libssh2 1.10.0 h04015c4_2
libthrift 0.15.0 h70b4b81_2
libtiff 4.5.0 hcec6c5f_2
libwebp 1.2.4 hf6ce154_1
libwebp-base 1.2.4 h6c40b1e_1
libxml2 2.10.4 h930c0e2_0
libxslt 1.1.37 h6d1eb0e_0
libzopfli 1.0.3 hb1e8313_0
llvm-openmp 14.0.6 h0dcd299_0
llvmlite 0.40.1 pypi_0 pypi
locket 1.0.0 py39hecd8cb5_0
loguru 0.7.0 pypi_0 pypi
lxml 4.9.2 py39h6c40b1e_0
lz4 4.3.2 py39h6c40b1e_0
lz4-c 1.9.4 hcec6c5f_0
magicgui 0.7.2 pyhd8ed1ab_0 conda-forge
markdown-it-py 2.2.0 py39hecd8cb5_1
markupsafe 2.1.1 py39hca72f7f_0
matplotlib 3.7.2 pypi_0 pypi
matplotlib-inline 0.1.6 py39hecd8cb5_0
matplotlib-scalebar 0.8.1 pypi_0 pypi
mdit-py-plugins 0.3.5 pypi_0 pypi
mdurl 0.1.0 py39hecd8cb5_0
mistune 0.8.4 py39h9ed2024_1000
mkl 2023.1.0 h8e150cf_43559
mkl-service 2.4.0 py39h6c40b1e_1
mkl_fft 1.3.6 py39h07fba90_1
mkl_random 1.2.2 py39h07fba90_1
msgpack-python 1.0.3 py39haf03e11_0
multidict 6.0.4 pypi_0 pypi
multipledispatch 1.0.0 pypi_0 pypi
multiscale-spatial-image 0.11.2 pypi_0 pypi
mypy_extensions 0.4.3 py39hecd8cb5_1
myst-nb 0.17.2 pypi_0 pypi
myst-parser 0.18.1 pypi_0 pypi
napari 0.4.18 pyhd8ed1ab_2 conda-forge
napari-console 0.0.8 pyhd8ed1ab_0 conda-forge
napari-matplotlib 1.0.2 pypi_0 pypi
napari-plugin-engine 0.2.0 pyhd8ed1ab_2 conda-forge
napari-spatialdata 0.2.6 pypi_0 pypi
napari-svg 0.1.10 pyhd8ed1ab_0 conda-forge
natsort 8.4.0 pypi_0 pypi
nbclassic 0.5.5 py39hecd8cb5_0
nbclient 0.5.13 py39hecd8cb5_0
nbconvert 6.5.4 py39hecd8cb5_0
nbformat 5.7.0 py39hecd8cb5_0
ncurses 6.4 hcec6c5f_0
nest-asyncio 1.5.6 py39hecd8cb5_0
networkx 3.1 py39hecd8cb5_0
notebook 6.5.4 py39hecd8cb5_1
notebook-shim 0.2.2 py39hecd8cb5_0
npe2 0.7.2 pyhd8ed1ab_0 conda-forge
numba 0.57.1 pypi_0 pypi
numcodecs 0.11.0 py39hcec6c5f_0
numexpr 2.8.4 py39h47b59a4_1
numpy 1.23.4 pypi_0 pypi
numpydoc 1.5.0 py39hecd8cb5_0
ome-zarr 0.8.0 pypi_0 pypi
openjpeg 2.4.0 h66ea3da_0
openssl 3.0.10 hca72f7f_1
orc 1.7.4 h995b336_1
packaging 23.0 py39hecd8cb5_0
pandas 2.0.3 py39h3ea8b11_0
pandocfilters 1.5.0 pyhd3eb1b0_0
param 1.13.0 pypi_0 pypi
parso 0.8.3 pyhd3eb1b0_0
partd 1.2.0 pyhd3eb1b0_1
patsy 0.5.3 pypi_0 pypi
pexpect 4.8.0 pyhd3eb1b0_3
pickleshare 0.7.5 pyhd3eb1b0_1003
pillow 9.4.0 py39hcec6c5f_0
pims 0.6.1 pypi_0 pypi
pint 0.22 pyhd8ed1ab_1 conda-forge
pip 23.2.1 py39hecd8cb5_0
platformdirs 3.10.0 py39hecd8cb5_0
pooch 1.4.0 pyhd3eb1b0_0
prometheus_client 0.14.1 py39hecd8cb5_0
prompt-toolkit 3.0.36 py39hecd8cb5_0
psutil 5.9.0 py39hca72f7f_0
psygnal 0.9.2 pyhd8ed1ab_0 conda-forge
ptyprocess 0.7.0 pyhd3eb1b0_2
pure_eval 0.2.2 pyhd3eb1b0_0
pyarrow 11.0.0 py39h7122ad0_0
pycparser 2.21 pyhd3eb1b0_0
pyct 0.5.0 pypi_0 pypi
pydantic 1.10.8 py39h6c40b1e_0
pygeos 0.14 pypi_0 pypi
pygments 2.15.1 py39hecd8cb5_1
pynndescent 0.5.10 pypi_0 pypi
pyopengl 3.1.1a1 py39hecd8cb5_0
pyopenssl 23.2.0 py39hecd8cb5_0
pyparsing 3.0.9 pypi_0 pypi
pyproj 3.6.0 pypi_0 pypi
pyproject_hooks 1.0.0 py39hecd8cb5_0
pyqt5 5.15.9 pypi_0 pypi
pyqt5-qt5 5.15.2 pypi_0 pypi
pyqt5-sip 12.12.2 pypi_0 pypi
pyrsistent 0.18.0 py39hca72f7f_0
pysocks 1.7.1 py39hecd8cb5_0
python 3.9.17 h5ee71fb_0
python-build 0.10.0 py39hecd8cb5_0
python-dateutil 2.8.2 pyhd3eb1b0_0
python-fastjsonschema 2.16.2 py39hecd8cb5_0
python-json-logger 2.0.7 py39hecd8cb5_0
python-lmdb 1.4.1 py39hcec6c5f_0
python-tzdata 2023.3 pyhd3eb1b0_0
pytz 2022.7 py39hecd8cb5_0
pywavelets 1.4.1 py39h6c40b1e_0
pyyaml 6.0 py39h6c40b1e_1
pyzmq 23.2.0 py39he9d5cce_0
qtconsole-base 5.4.3 pyha770c72_0 conda-forge
qtpy 2.2.0 py39hecd8cb5_0
re2 2022.04.01 he9d5cce_0
readline 8.2 hca72f7f_0
requests 2.31.0 py39hecd8cb5_0
rfc3339-validator 0.1.4 py39hecd8cb5_0
rfc3986-validator 0.1.1 py39hecd8cb5_0
rich 13.3.5 py39hecd8cb5_0
s3fs 2023.4.0 pypi_0 pypi
scanpy 1.9.3 pypi_0 pypi
scikit-image 0.19.3 py39hcec6c5f_1
scikit-learn 1.3.0 pypi_0 pypi
scipy 1.11.1 py39hdb2ea58_0
seaborn 0.12.2 pypi_0 pypi
send2trash 1.8.0 pyhd3eb1b0_1
session-info 1.0.0 pypi_0 pypi
setuptools 68.0.0 py39hecd8cb5_0
shapely 2.0.1 pypi_0 pypi
shellingham 1.5.0 py39hecd8cb5_0
six 1.16.0 pyhd3eb1b0_1
slicerator 1.1.0 pypi_0 pypi
snappy 1.1.9 he9d5cce_0
sniffio 1.2.0 py39hecd8cb5_1
snowballstemmer 2.2.0 pyhd3eb1b0_0
sortedcontainers 2.4.0 pyhd3eb1b0_0
soupsieve 2.4 py39hecd8cb5_0
spatial-image 0.3.0 pypi_0 pypi
spatialdata 0.0.12 pypi_0 pypi
spatialdata-plot 0.0.4 pypi_0 pypi
sphinx 4.4.0 pyhd3eb1b0_0
sphinx-copybutton 0.5.2 pypi_0 pypi
sphinxcontrib-applehelp 1.0.2 pyhd3eb1b0_0
sphinxcontrib-devhelp 1.0.2 pyhd3eb1b0_0
sphinxcontrib-htmlhelp 2.0.0 pyhd3eb1b0_0
sphinxcontrib-jsmath 1.0.1 pyhd3eb1b0_0
sphinxcontrib-qthelp 1.0.3 pyhd3eb1b0_0
sphinxcontrib-serializinghtml 1.1.5 pyhd3eb1b0_0
sqlalchemy 2.0.20 pypi_0 pypi
sqlite 3.41.2 h6c40b1e_0
stack_data 0.2.0 pyhd3eb1b0_0
statsmodels 0.14.0 pypi_0 pypi
stdlib-list 0.9.0 pypi_0 pypi
superqt 0.5.0 pyh9208f05_0 conda-forge
tabulate 0.9.0 pypi_0 pypi
tbb 2021.8.0 ha357a0b_0
tblib 1.7.0 pyhd3eb1b0_0
terminado 0.17.1 py39hecd8cb5_0
threadpoolctl 3.2.0 pypi_0 pypi
tifffile 2021.7.2 pyhd3eb1b0_2
tinycss2 1.2.1 py39hecd8cb5_0
tk 8.6.12 h5d9f67b_0
tomli 2.0.1 py39hecd8cb5_0
tomli-w 1.0.0 pyhd3eb1b0_0
toolz 0.12.0 py39hecd8cb5_0
tornado 6.3.2 py39h6c40b1e_0
tqdm 4.65.0 py39h01d92e1_0
traitlets 5.7.1 py39hecd8cb5_0
typer 0.9.0 py39hecd8cb5_0
typing-extensions 4.5.0 pypi_0 pypi
tzdata 2023c h04d1e81_0
umap-learn 0.5.3 pypi_0 pypi
urllib3 1.26.16 py39hecd8cb5_0
utf8proc 2.6.1 h9ed2024_0
vispy 0.12.1 py39h3017f15_0
wcwidth 0.2.5 pyhd3eb1b0_0
webencodings 0.5.1 py39hecd8cb5_1
websocket-client 0.58.0 py39hecd8cb5_4
wheel 0.38.4 py39hecd8cb5_0
wrapt 1.14.1 py39hca72f7f_0
xarray 2022.12.0 pypi_0 pypi
xarray-dataclasses 1.6.0 pypi_0 pypi
xarray-datatree 0.0.12 pypi_0 pypi
xarray-schema 0.0.3 pypi_0 pypi
xarray-spatial 0.3.7 pypi_0 pypi
xyzservices 2022.9.0 py39hecd8cb5_1
xz 5.4.2 h6c40b1e_0
y-py 0.5.9 py39h7242b5c_0
yaml 0.2.5 haf1e3a3_0
yarl 1.9.2 pypi_0 pypi
ypy-websocket 0.8.2 py39hecd8cb5_0
zarr 2.13.3 py39hecd8cb5_0
zeromq 4.3.4 h23ab428_0
zfp 0.5.5 he9d5cce_6
zict 2.2.0 py39hecd8cb5_0
zipp 3.11.0 py39hecd8cb5_0
zlib 1.2.13 h4dc903c_0
zstd 1.5.5 hc035e20_0
Hi Nils, thanks for the kind feedback and for reporting this bug.
I think this behavior is due to this bug that I have reported here: https://github.com/scverse/spatialdata-plot/issues/146. In such a case, we are working on the solution and it should be fixed soon 😊
I just checked, the bug is not present anymore, probably thanks to the fix mentioned above.