dynamo-release icon indicating copy to clipboard operation
dynamo-release copied to clipboard

TypeError: Image data of dtype object cannot be converted to float for Response heatmap

Open hyjforesight opened this issue 3 years ago • 4 comments

Hello Dynamo, I was running the Cell-wise analyses tutorial. It was smooth until the Response heatmap. I got a TypeError: Image data of dtype object cannot be converted to float. Appreciate it if you could help me with this issue. Thanks! Best, YJ

dyn.vf.jacobian(adata, regulators=["SPI1", "GATA1"], effectors=["SPI1", "GATA1"], sample_ncells=1000, basis='pca', Qkey='PCs', method='analytical')
dyn.pl.response(adata, pairs_mat=np.array([["SPI1", "GATA1"], ["GATA1", "SPI1"], ["SPI1", "SPI1"], ["GATA1", "GATA1"]]), ykey="jacobian", log=False, cmap=None, save_show_or_return="show")

Transforming subset Jacobian: 100%|██████████| 1947/1947 [00:00<00:00, 70465.44it/s]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [17], in <cell line: 4>()
      2 get_ipython().run_line_magic('matplotlib', 'inline')
      3 dyn.vf.jacobian(adata, regulators=["SPI1", "GATA1"], effectors=["SPI1", "GATA1"], sample_ncells=1000, basis='pca', Qkey='PCs', method='analytical')
----> 4 dyn.pl.response(adata, pairs_mat=np.array([["SPI1", "GATA1"], ["GATA1", "SPI1"], ["SPI1", "SPI1"], ["GATA1", "GATA1"]]), ykey="jacobian", log=False, cmap=None,
      5                 save_show_or_return="show")

File ~\anaconda3\envs\dynamo\lib\site-packages\dynamo\plot\heatmaps.py:420, in response(adata, pairs_mat, xkey, ykey, log, drop_zero_cells, delay, grid_num, n_row, n_col, cmap, show_ridge, show_rug, zero_indicator, zero_line_style, zero_line_width, mean_style, fit_curve, fit_mode, curve_style, curve_lw, no_degradation, show_extent, ext_format, stacked_fraction, figsize, save_show_or_return, save_kwargs, return_data)
    417 axins = inset_axes(axes[i, j], bbox_transform=axes[i, j].transAxes, **inset_dict)
    419 ext_lim = (min(x_val), max(x_val), min(y_val), max(y_val))
--> 420 im = axes[i, j].imshow(
    421     values,
    422     interpolation="mitchell",
    423     origin="lower",
    424     extent=ext_lim if show_extent else None,
    425     cmap=cmap,
    426 )
    427 cb = fig.colorbar(im, cax=axins)
    428 cb.set_alpha(1)

File ~\anaconda3\envs\dynamo\lib\site-packages\matplotlib\__init__.py:1361, in _preprocess_data.<locals>.inner(ax, data, *args, **kwargs)
   1358 @functools.wraps(func)
   1359 def inner(ax, *args, data=None, **kwargs):
   1360     if data is None:
-> 1361         return func(ax, *map(sanitize_sequence, args), **kwargs)
   1363     bound = new_sig.bind(ax, *args, **kwargs)
   1364     auto_label = (bound.arguments.get(label_namer)
   1365                   or bound.kwargs.get(label_namer))

File ~\anaconda3\envs\dynamo\lib\site-packages\matplotlib\axes\_axes.py:5609, in Axes.imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, filternorm, filterrad, resample, url, **kwargs)
   5604 self.set_aspect(aspect)
   5605 im = mimage.AxesImage(self, cmap, norm, interpolation, origin, extent,
   5606                       filternorm=filternorm, filterrad=filterrad,
   5607                       resample=resample, **kwargs)
-> 5609 im.set_data(X)
   5610 im.set_alpha(alpha)
   5611 if im.get_clip_path() is None:
   5612     # image does not already have clipping set, clip to axes patch

File ~\anaconda3\envs\dynamo\lib\site-packages\matplotlib\image.py:700, in _ImageBase.set_data(self, A)
    696 self._A = cbook.safe_masked_invalid(A, copy=True)
    698 if (self._A.dtype != np.uint8 and
    699         not np.can_cast(self._A.dtype, float, "same_kind")):
--> 700     raise TypeError("Image data of dtype {} cannot be converted to "
    701                     "float".format(self._A.dtype))
    703 if self._A.ndim == 3 and self._A.shape[-1] == 1:
    704     # If just one dimension assume scalar and apply colormap
    705     self._A = self._A[:, :, 0]

TypeError: Image data of dtype object cannot be converted to float

hyjforesight avatar Jul 02 '22 04:07 hyjforesight

@dummyindex can you take a look at this. I am busy this and next week

Also @hyjforesight feel free to dig into the source code more closely (somehow your data generated for the heatmap is object instead of float) and welcome to contribute.

Xiaojieqiu avatar Jul 02 '22 04:07 Xiaojieqiu

Hello @Xiaojieqiu and @dummyindex Thanks for the response and for helping me. Sorry, I'm not professional at coding. I can just report the errors that I met. Hope it also helps Dynamo. Thanks! Best, YJ

hyjforesight avatar Jul 03 '22 02:07 hyjforesight

I met the same issue too. Have you fixed it now? What should I do? Thank you very much. @dummyindex @Xiaojieqiu

%matplotlib inline

dyn.vf.jacobian(adata_labeling, regulators=["SPI1", "GATA1"], effectors=["SPI1", "GATA1"]) dyn.pl.response( adata_labeling, np.array([["SPI1", "GATA1"], ["GATA1", "SPI1"], ["SPI1", "SPI1"], ["GATA1", "GATA1"]]), ykey="jacobian", log=False, drop_zero_cells=True, grid_num=25, figsize=(5, 3), save_show_or_return="show" )

TypeError Traceback (most recent call last) Input In [88], in <cell line: 4>() 1 get_ipython().run_line_magic('matplotlib', 'inline') 3 dyn.vf.jacobian(adata_labeling, regulators=["SPI1", "GATA1"], effectors=["SPI1", "GATA1"]) ----> 4 dyn.pl.response( 5 adata_labeling, 6 np.array([["SPI1", "GATA1"], ["GATA1", "SPI1"], ["SPI1", "SPI1"], ["GATA1", "GATA1"]]), 7 ykey="jacobian", 8 log=False, 9 drop_zero_cells=True, 10 grid_num=25, 11 figsize=(5, 3), 12 save_show_or_return="show" 13 )

File ~\AppData\Roaming\Python\Python39\site-packages\dynamo\plot\heatmaps.py:420, in response(adata, pairs_mat, xkey, ykey, log, drop_zero_cells, delay, grid_num, n_row, n_col, cmap, show_ridge, show_rug, zero_indicator, zero_line_style, zero_line_width, mean_style, fit_curve, fit_mode, curve_style, curve_lw, no_degradation, show_extent, ext_format, stacked_fraction, figsize, save_show_or_return, save_kwargs, return_data) 417 axins = inset_axes(axes[i, j], bbox_transform=axes[i, j].transAxes, **inset_dict) 419 ext_lim = (min(x_val), max(x_val), min(y_val), max(y_val)) --> 420 im = axes[i, j].imshow( 421 values, 422 interpolation="mitchell", 423 origin="lower", 424 extent=ext_lim if show_extent else None, 425 cmap=cmap, 426 ) 427 cb = fig.colorbar(im, cax=axins) 428 cb.set_alpha(1)

File ~\AppData\Roaming\Python\Python39\site-packages\matplotlib_init_.py:1361, in _preprocess_data..inner(ax, data, *args, **kwargs) 1358 @functools.wraps(func) 1359 def inner(ax, *args, data=None, **kwargs): 1360 if data is None: -> 1361 return func(ax, *map(sanitize_sequence, args), **kwargs) 1363 bound = new_sig.bind(ax, *args, **kwargs) 1364 auto_label = (bound.arguments.get(label_namer) 1365 or bound.kwargs.get(label_namer))

File ~\AppData\Roaming\Python\Python39\site-packages\matplotlib\axes_axes.py:5609, in Axes.imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, filternorm, filterrad, resample, url, **kwargs) 5604 self.set_aspect(aspect) 5605 im = mimage.AxesImage(self, cmap, norm, interpolation, origin, extent, 5606 filternorm=filternorm, filterrad=filterrad, 5607 resample=resample, **kwargs) -> 5609 im.set_data(X) 5610 im.set_alpha(alpha) 5611 if im.get_clip_path() is None: 5612 # image does not already have clipping set, clip to axes patch

File ~\AppData\Roaming\Python\Python39\site-packages\matplotlib\image.py:700, in _ImageBase.set_data(self, A) 696 self._A = cbook.safe_masked_invalid(A, copy=True) 698 if (self._A.dtype != np.uint8 and 699 not np.can_cast(self._A.dtype, float, "same_kind")): --> 700 raise TypeError("Image data of dtype {} cannot be converted to " 701 "float".format(self._A.dtype)) 703 if self._A.ndim == 3 and self._A.shape[-1] == 1: 704 # If just one dimension assume scalar and apply colormap 705 self._A = self._A[:, :, 0]

TypeError: Image data of dtype object cannot be converted to float

check https://github.com/aristoteleo/dynamo-release/issues/392

hyjforesight avatar Aug 18 '22 00:08 hyjforesight