Nanostring-Biostats / CosMx-Analysis-Scratch-Space

This repository is an exploratory resource to accelerate opensource analysis of CosMx® Spatial Molecular Imager (SMI) data. Contained here are and writeups and vignettes addressing a variety of topics discussed when analyzing single-cell spatial data.
https://nanostring-biostats.github.io/CosMx-Analysis-Scratch-Space/
Other
32 stars 3 forks source link

Napari-cosmx save error #102

Closed pfren1998 closed 1 week ago

pfren1998 commented 2 months ago

When I use the napari-cosmx plugin with the demo data, I want to export the DNA images to tiff file, and the error is shown as following, do you have any idea on this?

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/Library/napari-0.5.1/envs/napari-0.5.1/lib/python3.9/site-packages/napari/_qt/menus/file_menu.py in ?()
---> 73                 'slot': lambda: window._qt_viewer._save_layers_dialog(
     74                     selected=True
     75                 ),

~/Library/napari-0.5.1/envs/napari-0.5.1/lib/python3.9/site-packages/napari/_qt/qt_viewer.py in ?(self=<napari._qt.qt_viewer.QtViewer(0x600003d0d880)>, selected=True)
    780                 saved = self.viewer.layers.save(
    781                     filename, selected=selected, _writer=writer
    782                 )
    783                 logging.debug('Saved %s', saved)
--> 784                 error_messages = "\n".join(str(x.message.args[0]) for x in wa)
    785 
    786             if not saved:
    787                 raise OSError(

~/Library/napari-0.5.1/envs/napari-0.5.1/lib/python3.9/site-packages/napari/components/layerlist.py in ?(self=[<Image layer 'DNA' at 0x2daab20d0>, <Labels lay...430>, <Shapes layer 'FOV labels' at 0x2ee9f3e20>], path='/Users/morsouron/Desktop/Project/benchmark/data/DAPI/xenium/HCC/test.tif', selected=True, plugin=None, _writer=WriterContribution(command='napari.write_image',...'.sgi', '.stk', '.tga'], display_name='lossless'))
    476         if not layers:
    477             warnings.warn(msg)
    478             return []
    479 
--> 480         return save_layers(path, layers, plugin=plugin, _writer=_writer)

~/Library/napari-0.5.1/envs/napari-0.5.1/lib/python3.9/site-packages/napari/plugins/io.py in ?(path='/Users/morsouron/Desktop/Project/benchmark/data/DAPI/xenium/HCC/test.tif', layers=[<Image layer 'DNA'>], plugin=None, _writer=WriterContribution(command='napari.write_image',...'.sgi', '.stk', '.tga'], display_name='lossless'))
    225         written, writer_name = _write_multiple_layers_with_plugins(
    226             path, layers, plugin_name=plugin, _writer=_writer
    227         )
    228     elif len(layers) == 1:
--> 229         _written, writer_name = _write_single_layer_with_plugins(
    230             path, layers[0], plugin_name=plugin, _writer=_writer
    231         )
    232         written = [_written] if _written else []

~/Library/napari-0.5.1/envs/napari-0.5.1/lib/python3.9/site-packages/napari/plugins/io.py in ?(path='/Users/morsouron/Desktop/Project/benchmark/data/DAPI/xenium/HCC/test.tif', layer=<Image layer 'DNA'>, plugin_name=None, _writer=WriterContribution(command='napari.write_image',...'.sgi', '.stk', '.tga'], display_name='lossless'))
    438         Name of the plugin selected to write the data.
    439     """
    440 
    441     # Try to use NPE2 first
--> 442     written_paths, writer_name = _npe2.write_layers(
    443         path, [layer], plugin_name, _writer
    444     )
    445     if writer_name:

~/Library/napari-0.5.1/envs/napari-0.5.1/lib/python3.9/site-packages/napari/plugins/_npe2.py in ?(path='/Users/morsouron/Desktop/Project/benchmark/data/DAPI/xenium/HCC/test.tif', layers=[<Image layer 'DNA'>], plugin_name=None, writer=WriterContribution(command='napari.write_image',...'.sgi', '.stk', '.tga'], display_name='lossless'))
    117             return paths, writer.plugin_name
    118 
    119     n = sum(ltc.max() for ltc in writer.layer_type_constraints())
    120     args = (path, *layer_data[0][:2]) if n <= 1 else (path, layer_data)
--> 121     res = writer.exec(args=args)
    122     if isinstance(
    123         res, str
    124     ):  # pragma: no cover # it shouldn't be... bad plugin.

~/Library/napari-0.5.1/envs/napari-0.5.1/lib/python3.9/site-packages/npe2/manifest/utils.py in ?(self=WriterContribution(command='napari.write_image',...'.sgi', '.stk', '.tga'], display_name='lossless'), args=('/Users/morsouron/Desktop/Project/benchmark/data/DAPI/xenium/HCC/test.tif', <MultiScaleData at 0x2b86dc9d0. 4 levels, 'uint1..., 4256), (2128, 2128), (1064, 1064), (532, 532))>, {'affine': <class 'numpy.ndarray'> (3, 3) float64, 'attenuation': 0.05, 'blending': 'additive', 'colormap': 'blue', 'contrast_limits': [10, 94], 'custom_interpolation_kernel_2d': <class 'numpy.ndarray'> (1, 1) float32, 'depiction': 'volume', 'experimental_clipping_planes': [], 'gamma': 1, 'interpolation2d': 'nearest', ...}), kwargs={}, _registry=None)
     57     ) -> R:
     58         if kwargs is None:
     59             kwargs = {}
     60         reg = _registry or kwargs.pop("_registry", None)
---> 61         return self.get_callable(reg)(*args, **kwargs)

~/Library/napari-0.5.1/envs/napari-0.5.1/lib/python3.9/site-packages/napari_builtins/io/_write.py in ?(path='/Users/morsouron/Desktop/Project/benchmark/data/DAPI/xenium/HCC/test.tif', data=<MultiScaleData at 0x2b86dc9d0. 4 levels, 'uint1..., 4256), (2128, 2128), (1064, 1064), (532, 532))>, meta={'affine': <class 'numpy.ndarray'> (3, 3) float64, 'attenuation': 0.05, 'blending': 'additive', 'colormap': 'blue', 'contrast_limits': [10, 94], 'custom_interpolation_kernel_2d': <class 'numpy.ndarray'> (1, 1) float32, 'depiction': 'volume', 'experimental_clipping_planes': [], 'gamma': 1, 'interpolation2d': 'nearest', ...})
    120         path += '.tif'
    121         ext = '.tif'
    122 
    123     if ext in imsave_extensions():
--> 124         imsave(path, data)
    125         return path
    126 
    127     return None

~/Library/napari-0.5.1/envs/napari-0.5.1/lib/python3.9/site-packages/napari/utils/io.py in ?(filename='/Users/morsouron/Desktop/Project/benchmark/data/DAPI/xenium/HCC/test.tif', data=<MultiScaleData at 0x2b86dc9d0. 4 levels, 'uint1..., 4256), (2128, 2128), (1064, 1064), (532, 532))>)
     42 
     43         if compression_instead_of_compress:
     44             # 'compression' scheme is more complex. See:
     45             # https://forum.image.sc/t/problem-saving-generated-labels-in-cellpose-napari/54892/8
---> 46             tifffile.imwrite(filename, data, compression=('zlib', 1))
     47         else:  # older version of tifffile since 2021.6.6  this is deprecated
     48             tifffile.imwrite(filename, data, compress=1)
     49     else:

~/Library/napari-0.5.1/envs/napari-0.5.1/lib/python3.9/site-packages/tifffile/tifffile.py in ?(file='/Users/morsouron/Desktop/Project/benchmark/data/DAPI/xenium/HCC/test.tif', data=<MultiScaleData at 0x2b86dc9d0. 4 levels, 'uint1..., 4256), (2128, 2128), (1064, 1064), (532, 532))>, mode=None, bigtiff=False, byteorder=None, imagej=False, ome=None, shaped=None, append=False, shape=None, dtype=None, photometric=None, planarconfig=None, extrasamples=None, volumetric=False, tile=None, rowsperstrip=None, bitspersample=None, compression=('zlib', 1), compressionargs=None, predictor=None, subsampling=None, jpegtables=None, iccprofile=None, colormap=None, description=None, datetime=None, resolution=None, resolutionunit=None, subfiletype=None, software=None, metadata={}, extratags=None, contiguous=False, truncate=False, align=None, maxworkers=None, buffersize=None, returnoffset=False)
   1437         imagej=imagej,
   1438         ome=ome,
   1439         shaped=shaped,
   1440     ) as tif:
-> 1441         result = tif.write(
   1442             data,
   1443             shape=shape,
   1444             dtype=dtype,

~/Library/napari-0.5.1/envs/napari-0.5.1/lib/python3.9/site-packages/tifffile/tifffile.py in ?(self=<tifffile.TiffWriter 'test.tif'>, data=<MultiScaleData at 0x2b86dc9d0. 4 levels, 'uint1..., 4256), (2128, 2128), (1064, 1064), (532, 532))>, shape=None, dtype=None, photometric=None, planarconfig=None, extrasamples=None, volumetric=False, tile=None, rowsperstrip=None, bitspersample=None, compression=('zlib', 1), compressionargs=None, predictor=None, subsampling=None, jpegtables=None, iccprofile=None, colormap=None, description=None, datetime=None, resolution=None, resolutionunit=None, subfiletype=None, software=None, subifds=None, metadata={}, extratags=None, contiguous=False, truncate=False, align=None, maxworkers=None, buffersize=None, returnoffset=False)
   2163             dataarray = data
   2164             datadtype = numpy.dtype(data.dtype).newbyteorder(byteorder)
   2165             if not hasattr(data, 'reshape'):
   2166                 # zarr array cannot be shape-normalized
-> 2167                 dataarray = numpy.asarray(data, datadtype, 'C')
   2168             else:
   2169                 try:
   2170                     # numpy array must be C contiguous

TypeError: __array__() takes 1 positional argument but 2 were given
eveilyeverafter commented 2 months ago

Are you trying to save a screen shot as a TIFF file or do you want to convert the zarr to an (ome)tiff file? If the former, could you provide the code that you used to save the screenshot?

pfren1998 commented 1 month ago

Are you trying to save a screen shot as a TIFF file or do you want to convert the zarr to an (ome)tiff file? If the former, could you provide the code that you used to save the screenshot?

Hi I want to save the full resolution image after stitching all the fovs in the tiff format, and I did not use code to save, instead, I just click on the Save selected layers in the file menu. Thanks!

image
eveilyeverafter commented 1 month ago

I'm not sure if there's an issue with napari in general or if it's specific to the plugin but it appears that saving tiff files with that GUI indeed does not work. Have you had a chance to try saving a view/layer in the ipython console?