scverse / spatialdata-plot

Static plotting for spatialdata
BSD 3-Clause "New" or "Revised" License
33 stars 13 forks source link

Import error in spatialdata_plot #289

Closed jnmark closed 3 months ago

jnmark commented 3 months ago

Hello,

I was trying to follow the Xenium data tutorial to plot the morphology image

Screenshot 2024-07-10 at 1 28 01 PM

and I get the following error when trying to import spatialdata_plot:

`

ImportError Traceback (most recent call last) Cell In[9], line 2 1 import matplotlib.pyplot as plt ----> 2 import spatialdata_plot 4 axes = plt.subplots(1, 2, figsize=(10, 10))[1].flatten() 5 sdata.pl.render_images("he_image").pl.show(ax=axes[0], title="H&E image")

File ~/.conda/envs/analysis_env_032024/lib/python3.9/site-packages/spatialdata_plot/init.py:3 1 from importlib.metadata import version ----> 3 from . import pl, pp 5 all = ["pl", "pp"] 7 version = version("spatialdata-plot")

File ~/.conda/envs/analysis_env_032024/lib/python3.9/site-packages/spatialdata_plot/pl/init.py:1 ----> 1 from .basic import PlotAccessor 3 all = [ 4 "PlotAccessor", 5 ]

File ~/.conda/envs/analysis_env_032024/lib/python3.9/site-packages/spatialdata_plot/pl/basic.py:26 23 from spatialdata._core.data_extent import get_extent 25 from spatialdata_plot._accessor import register_spatial_data_accessor ---> 26 from spatialdata_plot.pl.render import ( 27 _render_images, 28 _render_labels, 29 _render_points, 30 _render_shapes, 31 ) 32 from spatialdata_plot.pl.render_params import ( 33 CmapParams, 34 ImageRenderParams, (...) 40 _FontWeight, 41 ) 42 from spatialdata_plot.pl.utils import ( 43 _get_cs_contents, 44 _get_elements_to_be_rendered, (...) 55 save_fig, 56 )

File ~/.conda/envs/analysis_env_032024/lib/python3.9/site-packages/spatialdata_plot/pl/render.py:36 26 from spatialdata_plot._logging import logger 27 from spatialdata_plot.pl.render_params import ( 28 FigParams, 29 ImageRenderParams, (...) 34 ShapesRenderParams, 35 ) ---> 36 from spatialdata_plot.pl.utils import ( 37 _decorate_axs, 38 _get_collection_shape, 39 _get_colors_for_categorical_obs, 40 _get_linear_colormap, 41 _is_coercable_to_float, 42 _map_color_seg, 43 _maybe_set_colors, 44 _multiscale_to_spatial_image, 45 _normalize, 46 _rasterize_if_necessary, 47 _return_list_list_str_none, 48 _return_list_str_none, 49 _set_color_source_vec, 50 to_hex, 51 ) 53 _Normalize = Union[Normalize, abc.Sequence[Normalize]] 56 def _render_shapes( 57 sdata: sd.SpatialData, 58 render_params: ShapesRenderParams, (...) 63 legend_params: LegendParams, 64 ) -> None:

File ~/.conda/envs/analysis_env_032024/lib/python3.9/site-packages/spatialdata_plot/pl/utils.py:57 55 from spatialdata import SpatialData 56 from spatialdata._core.operations.rasterize import rasterize ---> 57 from spatialdata._core.query.relational_query import _get_element_annotators, _locate_value, _ValueOrigin, get_values 58 from spatialdata._types import ArrayLike 59 from spatialdata.models import Image2DModel, Labels2DModel, PointsModel, SpatialElement, TableModel, get_model

ImportError: cannot import name '_get_element_annotators' from 'spatialdata._core.query.relational_query' (/home/jnmark/.conda/envs/analysis_env_032024/lib/python3.9/site-packages/spatialdata/_core/query/relational_query.py) `

Here are the package versions in my environment:


spatialdata 0.2.1 spatialdata-io 0.1.3.post0 spatialdata-plot 0.2.2


LucaMarconato commented 3 months ago

Hi, please update spatialdata-plot to 0.2.3post0; it should fix the issue as this version adds a minimum requirement for the spatialdata library.

timtreis commented 3 months ago

@jnmark does the issue persist?

jnmark commented 3 months ago

Thank you! Yes, it seems to have resolved the issue. But I get a similar error with napari-spatialdata as well, could I try a similar solution there?

On Thu, Jul 11, 2024, 9:49 AM Tim Treis @.***> wrote:

@jnmark https://github.com/jnmark does the issue persist?

— Reply to this email directly, view it on GitHub https://github.com/scverse/spatialdata-plot/issues/289#issuecomment-2222991348, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARKDXM4DBLKIJDSX2VPSISDZL2ENHAVCNFSM6AAAAABKVLVRCSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRSHE4TCMZUHA . You are receiving this because you were mentioned.Message ID: @.***>

LucaMarconato commented 3 months ago

Happy to hear that it worked, closing the issue 😊 Yes, reinstalling napari_spatialdata should make it work as well.