dynamo-release
dynamo-release copied to clipboard
Image data of dtype object cannot be converted to float
Hello dynamo. I met this issue when trying to run the scNT-seq human hematopoiesis. What should I do to change the dtype from object to float? Thank you very much.
`%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`
I found something
Changing object to float. Another issue.
Thanks for this question. Are you able to running the following code without problem?
adata = dyn.sample_data.hematopoiesis()
dyn.vf.jacobian(adata, regulators=["SPI1", "GATA1"], effectors=["SPI1", "GATA1"])
dyn.pl.response(
adata,
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"
)
When I try to use dyn.sample, it reports like this. So I downloaded the data from url directly.
TimeoutError Traceback (most recent call last) File E:\anaconda\lib\urllib\request.py:1346, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args) 1345 try: -> 1346 h.request(req.get_method(), req.selector, req.data, headers, 1347 encode_chunked=req.has_header('Transfer-encoding')) 1348 except OSError as err: # timeout error
File E:\anaconda\lib\http\client.py:1285, in HTTPConnection.request(self, method, url, body, headers, encode_chunked) 1284 """Send a complete request to the server.""" -> 1285 self._send_request(method, url, body, headers, encode_chunked)
File E:\anaconda\lib\http\client.py:1331, in HTTPConnection._send_request(self, method, url, body, headers, encode_chunked) 1330 body = _encode(body, 'body') -> 1331 self.endheaders(body, encode_chunked=encode_chunked)
File E:\anaconda\lib\http\client.py:1280, in HTTPConnection.endheaders(self, message_body, encode_chunked) 1279 raise CannotSendHeader() -> 1280 self._send_output(message_body, encode_chunked=encode_chunked)
File E:\anaconda\lib\http\client.py:1040, in HTTPConnection._send_output(self, message_body, encode_chunked) 1039 del self._buffer[:] -> 1040 self.send(msg) 1042 if message_body is not None: 1043 1044 # create a consistent interface to message_body
File E:\anaconda\lib\http\client.py:980, in HTTPConnection.send(self, data) 979 if self.auto_open: --> 980 self.connect() 981 else:
File E:\anaconda\lib\http\client.py:1447, in HTTPSConnection.connect(self) 1445 "Connect to a host on a given (SSL) port." -> 1447 super().connect() 1449 if self._tunnel_host:
File E:\anaconda\lib\http\client.py:946, in HTTPConnection.connect(self) 945 """Connect to the host and port specified in init.""" --> 946 self.sock = self._create_connection( 947 (self.host,self.port), self.timeout, self.source_address) 948 # Might fail in OSs that don't implement TCP_NODELAY
File E:\anaconda\lib\socket.py:844, in create_connection(address, timeout, source_address) 843 try: --> 844 raise err 845 finally: 846 # Break explicitly a reference cycle
File E:\anaconda\lib\socket.py:832, in create_connection(address, timeout, source_address) 831 sock.bind(source_address) --> 832 sock.connect(sa) 833 # Break explicitly a reference cycle
TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
During handling of the above exception, another exception occurred:
URLError Traceback (most recent call last) Input In [67], in <cell line: 1>() ----> 1 adata = dyn.sample_data.hematopoiesis() 2 dyn.vf.jacobian(adata, regulators=["SPI1", "GATA1"], effectors=["SPI1", "GATA1"]) 3 dyn.pl.response( 4 adata, 5 np.array([["SPI1", "GATA1"], ["GATA1", "SPI1"], ["SPI1", "SPI1"], ["GATA1", "GATA1"]]), (...) 11 save_show_or_return="show" 12 )
File ~\AppData\Roaming\Python\Python39\site-packages\dynamo\sample_data.py:300, in hematopoiesis(url, filename) 298 """https://pitt.box.com/v/hematopoiesis-processed""" 299 main_info("Downloading processed hematopoiesis adata") --> 300 adata = get_adata(url, filename) 301 return adata
File ~\AppData\Roaming\Python\Python39\site-packages\dynamo\sample_data.py:41, in get_adata(url, filename) 27 def get_adata(url, filename=None): 28 """Download example data to local folder. 29 30 Parameters (...) 38 an Annodata object. 39 """ ---> 41 file_path = download_data(url, filename) 42 if Path(file_path).suffixes[-1][1:] == "loom": 43 adata = read_loom(filename=file_path)
File ~\AppData\Roaming\Python\Python39\site-packages\dynamo\sample_data.py:22, in download_data(url, file_path, dir) 19 os.mkdir("data") 21 # download the data ---> 22 urlretrieve(url, file_path, reporthook=LoggerManager.get_main_logger().request_report_hook) 24 return file_path
File E:\anaconda\lib\urllib\request.py:239, in urlretrieve(url, filename, reporthook, data) 222 """ 223 Retrieve a URL into a temporary location on disk. 224 (...) 235 data file as well as the resulting HTTPMessage object. 236 """ 237 url_type, path = _splittype(url) --> 239 with contextlib.closing(urlopen(url, data)) as fp: 240 headers = fp.info() 242 # Just return the local path and the "headers" for file:// 243 # URLs. No sense in performing a copy unless requested.
File E:\anaconda\lib\urllib\request.py:214, in urlopen(url, data, timeout, cafile, capath, cadefault, context) 212 else: 213 opener = _opener --> 214 return opener.open(url, data, timeout)
File E:\anaconda\lib\urllib\request.py:523, in OpenerDirector.open(self, fullurl, data, timeout) 521 for processor in self.process_response.get(protocol, []): 522 meth = getattr(processor, meth_name) --> 523 response = meth(req, response) 525 return response
File E:\anaconda\lib\urllib\request.py:632, in HTTPErrorProcessor.http_response(self, request, response) 629 # According to RFC 2616, "2xx" code indicates that the client's 630 # request was successfully received, understood, and accepted. 631 if not (200 <= code < 300): --> 632 response = self.parent.error( 633 'http', request, response, code, msg, hdrs) 635 return response
File E:\anaconda\lib\urllib\request.py:555, in OpenerDirector.error(self, proto, *args) 553 http_err = 0 554 args = (dict, proto, meth_name) + args --> 555 result = self._call_chain(*args) 556 if result: 557 return result
File E:\anaconda\lib\urllib\request.py:494, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args) 492 for handler in handlers: 493 func = getattr(handler, meth_name) --> 494 result = func(*args) 495 if result is not None: 496 return result
File E:\anaconda\lib\urllib\request.py:747, in HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers) 744 fp.read() 745 fp.close() --> 747 return self.parent.open(new, timeout=req.timeout)
File E:\anaconda\lib\urllib\request.py:523, in OpenerDirector.open(self, fullurl, data, timeout) 521 for processor in self.process_response.get(protocol, []): 522 meth = getattr(processor, meth_name) --> 523 response = meth(req, response) 525 return response
File E:\anaconda\lib\urllib\request.py:632, in HTTPErrorProcessor.http_response(self, request, response) 629 # According to RFC 2616, "2xx" code indicates that the client's 630 # request was successfully received, understood, and accepted. 631 if not (200 <= code < 300): --> 632 response = self.parent.error( 633 'http', request, response, code, msg, hdrs) 635 return response
File E:\anaconda\lib\urllib\request.py:555, in OpenerDirector.error(self, proto, *args) 553 http_err = 0 554 args = (dict, proto, meth_name) + args --> 555 result = self._call_chain(*args) 556 if result: 557 return result
File E:\anaconda\lib\urllib\request.py:494, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args) 492 for handler in handlers: 493 func = getattr(handler, meth_name) --> 494 result = func(*args) 495 if result is not None: 496 return result
File E:\anaconda\lib\urllib\request.py:747, in HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers) 744 fp.read() 745 fp.close() --> 747 return self.parent.open(new, timeout=req.timeout)
File E:\anaconda\lib\urllib\request.py:517, in OpenerDirector.open(self, fullurl, data, timeout) 514 req = meth(req) 516 sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method()) --> 517 response = self._open(req, data) 519 # post-process response 520 meth_name = protocol+"_response"
File E:\anaconda\lib\urllib\request.py:534, in OpenerDirector._open(self, req, data) 531 return result 533 protocol = req.type --> 534 result = self._call_chain(self.handle_open, protocol, protocol + 535 '_open', req) 536 if result: 537 return result
File E:\anaconda\lib\urllib\request.py:494, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args) 492 for handler in handlers: 493 func = getattr(handler, meth_name) --> 494 result = func(*args) 495 if result is not None: 496 return result
File E:\anaconda\lib\urllib\request.py:1389, in HTTPSHandler.https_open(self, req) 1388 def https_open(self, req): -> 1389 return self.do_open(http.client.HTTPSConnection, req, 1390 context=self._context, check_hostname=self._check_hostname)
File E:\anaconda\lib\urllib\request.py:1349, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args) 1346 h.request(req.get_method(), req.selector, req.data, headers, 1347 encode_chunked=req.has_header('Transfer-encoding')) 1348 except OSError as err: # timeout error -> 1349 raise URLError(err) 1350 r = h.getresponse() 1351 except:
URLError: <urlopen error [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。>
I used
adata_labeling = dyn.read_h5ad(r"E:\dynamo\pythonProject2\data\hematopoiesis_v1.h5ad")
and only the function 'dyn.pl.response' reports this issue.
@Xiaojieqiu
I used
adata_labeling = dyn.read_h5ad(r"E:\dynamo\pythonProject2\data\hematopoiesis_v1.h5ad")
and only the function 'dyn.pl.response' reports this issue.
@Xiaojieqiu Hi, where did you download hematopoiesis.h5ad from, the URL given by the author can no longer be opened
I am sorry but I still cannot reproduce the bug from my end. This seems like a system issue or matplotlib issue. Windows is a not a great system for scientific programming, I strongly recommend using either Linux or mac iOS.
Please also try using matplotlib version 3.5.2
.
Our data is hosted in dropbox which may be blocked in China unfortunately, so please consider using a vpn or other avenues. Thanks
Thank you for trying to help me @Xiaojieqiu .I used my vmware-station to run it but it still reported the same problem.
@ergezhenshuai
https://dl2.boxclo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NmTR92HwMxNil5p8q_ysUxxFhwQM3ecC0RquEUtbrCZQy9F0eCctMnR8KsY-wJZ_N8GdIJBEWx0auQGbfhAn7P6isdK9rZ4YXHZ2yl8lLzNWulMrVLT58osFxX5H5x-Zf4Y5c5Y2MBI7vlUJkYVpqMBK-SAkT040uElvOsSBG3lZnmAjgVOJJq6b6p7cwzEDZpZPvBvKCwgdCQiM-U0__PHwC_pX6bRlkd1pNBioHiMQ5BG3_ZHSqMKRzE9JArBbyjHoVqk9xRVZkmKEf-qfQr9Un4Un8ZKmdQDEGxVu2-fpABM8YmR379vjAgz4QtUTdlCDZT5SiQwmGL2zy682DjB/download
@ergezhenshuai @stupidstupidstupidstupid it should be from this data link as implemented in dynamo: https://www.dropbox.com/s/n9mx9trv1h78q0r/hematopoiesis_v1.h5ad?dl=1 see https://github.com/aristoteleo/dynamo-release/blob/d92f5678a913108524839c5783a54033ce9762f1/dynamo/sample_data.py#L294 Can you try this dataset instead @stupidstupidstupidstupid ?
I am sorry but I still cannot reproduce the bug from my end. This seems like a system issue or matplotlib issue. Windows is a not a great system for scientific programming, I strongly recommend using either Linux or mac iOS.
Please also try using
matplotlib version 3.5.2
.Our data is hosted in dropbox which may be blocked in China unfortunately, so please consider using a vpn or other avenues. Thanks
hello @Xiaojieqiu , does dynamo now support matplotlib v3.5.2?
I used this dataset but the error remained.
your matplotlib version seems fine and you are using the same input as me, and I don't have any issue, so this is very puzzling.
just one further thought, have you used python setup.py install
to install the latest dynamo version from github?
Secondly, can you let me know can you actually create the jacobian plot?
adata = dyn.sample_data.hematopoiesis()
dyn.vf.jacobian(adata, regulators=["SPI1", "GATA1"])
dyn.pl.jacobian(adata, regulators=["SPI1", "GATA1"])
if the above works, you will need to use pycharm or other tools to step in and debug the code and see what is happening near these lines of code as I cannot reproduce the error in my hand:
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,
)
in the code
Thank you for trying to help me.I used
dyn.tl.dynamics(adata)
The following error occurs:
dyn.tl.dynamics(adata) File "D:\anaconda\conda\envs\python\lib\site-packages\dynamo\tools\dynamics.py", line 413, in dynamics NTR_vel, File "D:\anaconda\conda\envs\python\lib\site-packages\dynamo\tools\utils.py", line 987, in get_data_for_kin_params_estimation subset_adata.layers["M_us"].T, File "D:\anaconda\conda\envs\python\lib\site-packages\anndata\_core\aligned_mapping.py", line 113, in __getitem__ _subset(self.parent_mapping[key], self.subset_idx), File "D:\anaconda\conda\envs\python\lib\site-packages\anndata\_core\aligned_mapping.py", line 148, in __getitem__ return self._data[key] KeyError: 'M_us'
@ergezhenshuai this seems a completely separate question, please consider open an new github issue and describe the details of how you are running your analyses. Looks to me your data either don't have spliced/unspliced layers to start with or you are not following standard way to analysis as the M_us
should always get created if following the routine pipeline we use in a typical dynamo analysis for splicing data.
jacobian plot can be successfully created @Xiaojieqiu
I found something in debug Should “A” be a float or object? @Xiaojieqiu
After using the code
A = A.astype(np.float32),
the bug has disappeared
Thank you again @Xiaojieqiu for your instruction.
Very great result.
hello @stupidstupidstupidstupid, so we should add A = A.astype(np.float32)
in the code script?
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]
You must run debug first@hyjforesight
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 14 days