STOmics / Stereopy

A toolkit of spatial transcriptomic analysis.
MIT License
180 stars 59 forks source link

two slice can not be use for time serise page analysis,It getting error with ms_data.plt.paga_time_series_plot funciton #231

Closed honghh2018 closed 6 months ago

honghh2018 commented 6 months ago

Hi developer,

I get the error when runing ms_data.plt.paga_time_series_plot( use_col='annotation', batch_col='batch',

dpt_col='diffmap_evals', # this is optional

    height=10
    )

in two slices. the detail error lying below: [2023-12-31 12:43:23][Stereo][71199][MainThread][47184420927872][ms_pipeline][129][INFO]: register plot_func paga_time_series_plot to <class 'stereo.core.stereo_exp_data.StereoExpData'>-47195215844976 /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/numpy/core/fromnumeric.py:3432: RuntimeWarning: Mean of empty slice. return _methods._mean(a, axis=axis, dtype=dtype, /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/numpy/core/_methods.py:190: RuntimeWarning: invalid value encountered in double_scalars ret = ret.dtype.type(ret / rcount)

IndexError Traceback (most recent call last) Cell In[128], line 1 ----> 1 ms_data.plt.paga_time_series_plot( 2 use_col='annotation', 3 batch_col='batch', 4 # dpt_col='diffmap_evals', # this is optional 5 height=10 6 ) 7 plt.savefig("ggg.png") use this code or not ,it show me same below error:

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/stereopy-1.0.0-py3.8.egg/stereo/core/ms_pipeline.py:240, in MSDataPipeLine.getattr..temp(*args, *kwargs) 238 else: 239 if self.ms_data.merged_data: --> 240 return self._use_integrate_method(item, args, **kwargs) 241 else: 242 raise Exception( 243 "mode integrate should merge first, using ms_data.integrate" 244 )

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/stereopy-1.0.0-py3.8.egg/stereo/core/ms_pipeline.py:130, in MSDataPipeLine._use_integrate_method(self, item, *args, kwargs) 128 if new_attr: 129 logger.info(f'register plot_func {item} to {type(merged_data)}-{id(merged_data)}') --> 130 return new_attr(*args, *kwargs) 132 logger.info(f'data_obj(idx=0) in ms_data start to run {item}') 133 return new_attr( 134 ms_data_view.merged_data.getattribute(self.class.ATTR_NAME), 135 args, 136 kwargs 137 )

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/stereopy-1.0.0-py3.8.egg/stereo/plots/decorator.py:47, in download..wrapped(*args, *kwargs) 45 dpi = kwargs['out_dpi'] 46 del kwargs['out_dpi'] ---> 47 fig: Figure = func(args, **kwargs) 48 if type(fig) is not Figure: 49 return fig

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/stereopy-1.0.0-py3.8.egg/stereo/plots/decorator.py:139, in reorganize_coordinate..wrapped(*args, *kwargs) 133 if reorganize_coordinate: 134 data.position, data.position_offset, data.position_min = \ 135 reorganize_data_coordinates( 136 data.cells.batch, data.position, data.position_offset, data.position_min, 137 reorganize_coordinate, horizontal_offset_additional, vertical_offset_additional 138 ) --> 139 res = func(args, **kwargs) 140 data.reset_position() 141 return res

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/stereopy-1.0.0-py3.8.egg/stereo/plots/plot_time_series.py:355, in PlotTimeSeries.paga_time_series_plot(self, use_col, batch_col, groups, height, width, palette, link_alpha, spot_size, dpt_col) 353 tmp_left = tmp[(np.percentile(tmp[:, 0], 40) <= tmp[:, 0]) & (tmp[:, 0] <= np.percentile(tmp[:, 0], 60))] 354 tmp_right = tmp[(np.percentile(tmp[:, 0], 40) <= tmp[:, 0]) & (tmp[:, 0] <= np.percentile(tmp[:, 0], 60))] --> 355 min_vertex_left[x[0]] = [np.mean(tmp_left[:, 0]), 0 - np.percentile(tmp_left[:, 1], 10)] 356 min_vertex_right[x[0]] = [np.mean(tmp_right[:, 0]), 0 - np.percentile(tmp_right[:, 1], 10)] 357 max_vertex_left[x[0]] = [np.mean(tmp_left[:, 0]), 0 - np.percentile(tmp_left[:, 1], 90)]

File <__array_function__ internals>:180, in percentile(*args, **kwargs)

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/numpy/lib/function_base.py:4166, in percentile(a, q, axis, out, overwrite_input, method, keepdims, interpolation) 4164 if not _quantile_is_valid(q): 4165 raise ValueError("Percentiles must be in the range [0, 100]") -> 4166 return _quantile_unchecked( 4167 a, q, axis, out, overwrite_input, method, keepdims)

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/numpy/lib/function_base.py:4424, in _quantile_unchecked(a, q, axis, out, overwrite_input, method, keepdims) 4416 def _quantile_unchecked(a, 4417 q, 4418 axis=None, (...) 4421 method="linear", 4422 keepdims=False): 4423 """Assumes that q is in [0, 1], and is an ndarray""" -> 4424 r, k = _ureduce(a, 4425 func=_quantile_ureduce_func, 4426 q=q, 4427 axis=axis, 4428 out=out, 4429 overwrite_input=overwrite_input, 4430 method=method) 4431 if keepdims: 4432 return r.reshape(q.shape + k)

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/numpy/lib/function_base.py:3725, in _ureduce(a, func, *kwargs) 3722 else: 3723 keepdim = (1,) a.ndim -> 3725 r = func(a, **kwargs) 3726 return r, keepdim

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/numpy/lib/function_base.py:4593, in _quantile_ureduce_func(a, q, axis, out, overwrite_input, method) 4591 else: 4592 arr = a.copy() -> 4593 result = _quantile(arr, 4594 quantiles=q, 4595 axis=axis, 4596 method=method, 4597 out=out) 4598 return result

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/numpy/lib/function_base.py:4699, in _quantile(arr, quantiles, axis, method, out) 4691 arr.partition( 4692 np.unique(np.concatenate(([0, -1], 4693 previous_indexes.ravel(), 4694 next_indexes.ravel(), 4695 ))), 4696 axis=DATA_AXIS) 4697 if np.issubdtype(arr.dtype, np.inexact): 4698 slices_having_nans = np.isnan( -> 4699 take(arr, indices=-1, axis=DATA_AXIS) 4700 ) 4701 else: 4702 slices_having_nans = None

File <__array_function__ internals>:180, in take(*args, **kwargs)

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/numpy/core/fromnumeric.py:190, in take(a, indices, axis, out, mode) 93 @array_function_dispatch(_take_dispatcher) 94 def take(a, indices, axis=None, out=None, mode='raise'): 95 """ 96 Take elements from an array along an axis. 97 (...) 188 [5, 7]]) 189 """ --> 190 return _wrapfunc(a, 'take', indices, axis=axis, out=out, mode=mode)

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/numpy/core/fromnumeric.py:57, in _wrapfunc(obj, method, *args, kwds) 54 return _wrapit(obj, method, *args, *kwds) 56 try: ---> 57 return bound(args, kwds) 58 except TypeError: 59 # A TypeError occurs if the object does have such a method in its 60 # class, but its signature is not identical to that of NumPy's. This (...) 64 # Call _wrapit from within the except clause to ensure a potential 65 # exception has a traceback chain. 66 return _wrapit(obj, method, *args, **kwds)

IndexError: cannot do a non-empty take from an empty axes.

ValueError Traceback (most recent call last) File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/IPython/core/formatters.py:340, in BaseFormatter.call(self, obj) 338 pass 339 else: --> 340 return printer(obj) 341 # Finally look for special method names 342 method = get_real_method(obj, self.print_method)

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/IPython/core/pylabtools.py:152, in print_figure(fig, fmt, bbox_inches, base64, kwargs) 149 from matplotlib.backend_bases import FigureCanvasBase 150 FigureCanvasBase(fig) --> 152 fig.canvas.print_figure(bytes_io, kw) 153 data = bytes_io.getvalue() 154 if fmt == 'svg':

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/matplotlib/backend_bases.py:2366, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, kwargs) 2362 try: 2363 # _get_renderer may change the figure dpi (as vector formats 2364 # force the figure dpi to 72), so we need to set it again here. 2365 with cbook._setattr_cm(self.figure, dpi=dpi): -> 2366 result = print_method( 2367 filename, 2368 facecolor=facecolor, 2369 edgecolor=edgecolor, 2370 orientation=orientation, 2371 bbox_inches_restore=_bbox_inches_restore, 2372 kwargs) 2373 finally: 2374 if bbox_inches and restore_bbox:

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/matplotlib/backend_bases.py:2232, in FigureCanvasBase._switch_canvas_and_return_print_method..(*args, kwargs) 2228 optional_kws = { # Passed by print_figure for other renderers. 2229 "dpi", "facecolor", "edgecolor", "orientation", 2230 "bbox_inches_restore"} 2231 skip = optional_kws - {inspect.signature(meth).parameters} -> 2232 print_method = functools.wraps(meth)(lambda args, kwargs: meth( 2233 *args, **{k: v for k, v in kwargs.items() if k not in skip})) 2234 else: # Let third-parties do as they see fit. 2235 print_method = meth

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:509, in FigureCanvasAgg.print_png(self, filename_or_obj, metadata, pil_kwargs) 462 def print_png(self, filename_or_obj, , metadata=None, pil_kwargs=None): 463 """ 464 Write the figure to a PNG file. 465 (...) 507 metadata*, including the default 'Software' key. 508 """ --> 509 self._print_pil(filename_or_obj, "png", pil_kwargs, metadata)

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:457, in FigureCanvasAgg._print_pil(self, filename_or_obj, fmt, pil_kwargs, metadata) 452 def _print_pil(self, filename_or_obj, fmt, pil_kwargs, metadata=None): 453 """ 454 Draw the canvas, then save it using .image.imsave (to which 455 pil_kwargs and metadata are forwarded). 456 """ --> 457 FigureCanvasAgg.draw(self) 458 mpl.image.imsave( 459 filename_or_obj, self.buffer_rgba(), format=fmt, origin="upper", 460 dpi=self.figure.dpi, metadata=metadata, pil_kwargs=pil_kwargs)

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:394, in FigureCanvasAgg.draw(self) 392 def draw(self): 393 # docstring inherited --> 394 self.renderer = self.get_renderer() 395 self.renderer.clear() 396 # Acquire a lock on the shared font cache.

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/matplotlib/_api/deprecation.py:384, in delete_parameter..wrapper(*inner_args, inner_kwargs) 379 @functools.wraps(func) 380 def wrapper(*inner_args, *inner_kwargs): 381 if len(inner_args) <= name_idx and name not in inner_kwargs: 382 # Early return in the simple, non-deprecated case (much faster than 383 # calling bind()). --> 384 return func(inner_args, inner_kwargs) 385 arguments = signature.bind(*inner_args, **inner_kwargs).arguments 386 if is_varargs and arguments.get(name):

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:411, in FigureCanvasAgg.get_renderer(self, cleared) 409 reuse_renderer = (self._lastKey == key) 410 if not reuse_renderer: --> 411 self.renderer = RendererAgg(w, h, self.figure.dpi) 412 self._lastKey = key 413 elif cleared:

File /share/apps/virtualEnv/miniconda3-py38/envs/huadaStereopy-st/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:84, in RendererAgg.init(self, width, height, dpi) 82 self.width = width 83 self.height = height ---> 84 self._renderer = _RendererAgg(int(width), int(height), dpi) 85 self._filter_renderers = [] 87 self._update_methods()

ValueError: Image size of 11091904x15708878 pixels is too large. It must be less than 2^16 in each direction. <Figure size 990.446x1000 with 1 Axes>

This code runing on jupyter notebook python environment The paga result output: msdata.mss['scope[0,1]']['paga'] {'connectivities': <32x32 sparse matrix of type '<class 'numpy.float64'>' with 534 stored elements in Compressed Sparse Row format>, 'connectivities_tree': <32x32 sparse matrix of type '<class 'numpy.float64'>' with 31 stored elements in Compressed Sparse Row format>, 'annotation_sizes': array([4081, 1078, 1044, 1032, 998, 827, 825, 610, 516, 514, 399, 3565, 377, 297, 292, 250, 221, 219, 168, 156, 145, 131, 2075, 128, 125, 100, 1928, 1618, 1587, 1533, 1527, 1523]), 'groups': 'annotation'}

The stereo version was 1.0.0 the python was 3.8 the platform was centos7.9

any advice would be appreciated, best hanhuihong

honghh2018 commented 6 months ago

any advice for this issue?

honghh2018 commented 6 months ago

Had anyone hear this error ?

Zhenbin24 commented 6 months ago

Hello, this problem has been fixed and will be released in the next version. If you want to use it now, you can refer to the work branch.