ClearAnatomics / ClearMap

ClearMap 2 with WobblyStitcher, TubeMap and CellMap
https://clearanatomics.github.io/ClearMapDocumentation/
GNU General Public License v3.0
114 stars 45 forks source link

TypeError: key must be an int, slice, or sequence #109

Closed Xiaoyan3333 closed 1 year ago

Xiaoyan3333 commented 2 years ago

Hello! I am trying to p3d.plot to read ".tif" files, but it encountered a TypeError.

p3d.plot('test.tif') the test.file was downloaded from https://osf.io/b6kxw/ 【Traceback (most recent call last):

File "", line 1, in runfile('/home/zhuhongyan/zhy_tool/zhy_clearmap/ClearMap2master/spyder_test1.py', wdir='/home/zhuhongyan/zhy_tool/zhy_clearmap/ClearMap2master')

File "/home/zhuhongyan/anaconda3/envs/ClearMap/lib/python3.6/site-packages/spyder_kernels/customize/spydercustomize.py", line 827, in runfile execfile(filename, namespace)

File "/home/zhuhongyan/anaconda3/envs/ClearMap/lib/python3.6/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "/home/zhuhongyan/zhy_tool/zhy_clearmap/ClearMap2master/spyder_test1.py", line 24, in p3d.plot(ws.filename('raw'))

File "/home/zhuhongyan/zhy_tool/zhy_clearmap/ClearMap2master/ClearMap/Visualization/Qt/Plot3d.py", line 60, in plot return multi_plot(source, axis=axis, scale=scale, title=title, invert_y=invert_y, min_max=min_max, screen=screen);

File "/home/zhuhongyan/zhy_tool/zhy_clearmap/ClearMap2master/ClearMap/Visualization/Qt/Plot3d.py", line 96, in multi_plot invertY=invert_y, minMax=min_max) for s,t in zip(sources, title)];

File "/home/zhuhongyan/zhy_tool/zhy_clearmap/ClearMap2master/ClearMap/Visualization/Qt/Plot3d.py", line 96, in invertY=invert_y, minMax=min_max) for s,t in zip(sources, title)];

File "/home/zhuhongyan/zhy_tool/zhy_clearmap/ClearMap2master/ClearMap/Visualization/Qt/DataViewer.py", line 220, in init self.image_items = [pg.ImageItem(s[self.source_slice[:s.ndim]], **image_options) for s in self.sources];

File "/home/zhuhongyan/zhy_tool/zhy_clearmap/ClearMap2master/ClearMap/Visualization/Qt/DataViewer.py", line 220, in self.image_items = [pg.ImageItem(s[self.source_slice[:s.ndim]], **image_options) for s in self.sources];

File "/home/zhuhongyan/zhy_tool/zhy_clearmap/ClearMap2master/ClearMap/IO/TIF.py", line 103, in getitem array = self._tif.asarray(key = slicing_z, maxworkers=processes);

File "/home/zhuhongyan/anaconda3/envs/ClearMap/lib/python3.6/site-packages/tifffile/tifffile.py", line 1882, in asarray raise TypeError('key must be an int, slice, or sequence')

TypeError: key must be an int, slice, or sequence】

I am new in scripe, so i really don't know how to deal with it. Thank you very much if you can help me on this matter!!!

andrewsilberfeld commented 2 years ago

I have this too. Did you ever solve it? I think its specific to installing ClearMap2 from the ClearMap_stable.yml file. Is this what you did? I originally installed from the ClearMap.yml file and didn't have this error but recently I messed up the environment and could only re-install from the ClearMap_stable.yml file. When I did this, I encountered this problem with viewing tif files.

Xiaoyan3333 commented 2 years ago

I found that convert the file's format can help. Using 'io.convert_files()' to change format(.tiff to .npy), then you can view it directly using p3d.plot('x.npy').

andrewsilberfeld commented 2 years ago

Thanks. The viewer should work with tifs though but it may be a bug with one of the versions of the python packages. Just curious, did you install the python environment from the ClearMap_stable.yml file?

andrewsilberfeld commented 2 years ago

Okay I figured this out! The problem is that the tifffile version (0.1.5) in the clearmap2_stable.yml is not compatible with the p3d.plot viewer when running tif files... the tifffile version 2020.5.30 is. I solvevd by making a new python environment using a modified ClearMap2_stable.yml file in which I deleted the whole tifffile library from the file. Then install the clearmap2 environment without tifffile and activate the environment. Then run: pip install tifffile==2020.5.30 in the new environment. Resume with normal install and try viewing your tif files in the p3d viewer.

That rescued my p3d viewer for showing tifs when it previously wasn't!

image

crousseau commented 1 year ago

The exact specification is tifffile<2020.9.22

This is now included in the 2 environments ClearMapUi.yml and ClearMapUi39.yml