Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NCZarr does not read images produced by multiscale-spatial-image #2476

Closed
dzenanz opened this issue Aug 10, 2022 · 4 comments
Closed

NCZarr does not read images produced by multiscale-spatial-image #2476

dzenanz opened this issue Aug 10, 2022 · 4 comments

Comments

@dzenanz
Copy link
Contributor

dzenanz commented Aug 10, 2022

I used the following Python code to convert an image into Zarr format:

from multiscale_spatial_image import to_multiscale, itk_image_to_multiscale, Methods
import itk
import zarr
import sys


def print_help_and_exit(exit_code=1):
    print(f'This is a standalone executable. Invoke it as {sys.argv[0]} input.nrrd output.zarr')
    exit(exit_code)


if __name__ == '__main__':
    if len(sys.argv) != 3:
        print_help_and_exit()
    image = itk.imread(sys.argv[1])

    # Generate Multiscale Image With itk_image_to_multiscale
    axis_units = {dim: "millimeters" for dim in ("x", "y", "z")}
    method = Methods.ITK_GAUSSIAN
    scale_factors = [2, 2]  # isotropic scale factors
    name = 'image'

    itk.auto_progress(0)
    multiscale_image = itk_image_to_multiscale(
        image,
        scale_factors=scale_factors,
        anatomical_axes=True,
        axis_units=axis_units,
        method=method,
        name=name,
    )

    store = zarr.storage.DirectoryStore(sys.argv[2], dimension_separator='/')
    multiscale_image.to_zarr(store)
    print(f'Successfully converted {sys.argv[1]} to {sys.argv[2]}')
else:
    print_help_and_exit()

multiscale-spatial-image is available on GitHub: https://github.com/spatial-image/multiscale-spatial-image.

Images.zip

NCZarr has trouble opening it:

dzenan@corista:~/tester$ /usr/local/bin/ncdump -h file:///media/xeonatorC/Misc/Tester/CBCT_crop1ms.zarr#mode=zarr,file
/usr/local/bin/ncdump: file:///media/xeonatorC/Misc/Tester/CBCT_crop1ms.zarr#mode=zarr,file: NetCDF: internal library error; Please contact Unidata support

Interestingly, if I zip up the resulting directory using 7-zip, NCZarr seems to open it:

dzenan@corista:~/tester$ /usr/local/bin/ncdump -h file:///media/xeonatorC/Misc/Tester/CBCT_crop1ms.zip#mode=zarr,file
netcdf CBCT_crop1ms {
}

Furthermore, both dir and zip fail if I remove the ,file from the "url":

dzenan@corista:~/tester$ /usr/local/bin/ncdump -h file:///media/xeonatorC/Misc/Tester/CBCT_crop1ms.zarr#mode=zarr
Killed
dzenan@corista:~/tester$ /usr/local/bin/ncdump -h file:///media/xeonatorC/Misc/Tester/CBCT_crop1ms.zip#mode=zarr
Killed

Ubuntu 22.04.1 LTS, GCC 11.2.0, netCDF main at b03988e.

@DennisHeimbigner
Copy link
Collaborator

This may be the same problem I am encountering at #2474
I think the problem has to do with using '/' as dimension separator.

@DennisHeimbigner
Copy link
Collaborator

DennisHeimbigner commented Aug 10, 2022

The problem is that you have an attribute of the form below.
I have no idea about how to interpret it and I do not even think it is
technically a legal Zarr attribute. I have a fix of sorts for this, but
it is in the master branch only, and is not in the 4.9.0 release.
Also, it assumes that the attribute value is a dictionary, not an array of arrays.

 "direction": [
        [
            1.0,
            0.0,
            0.0
        ],
        [
            0.0,
            1.0,
            0.0
        ],
        [
            0.0,
            0.0,
            1.0
        ]
    ]

@DennisHeimbigner
Copy link
Collaborator

THis issue appears to be essentially the same as #2474, so comments there will generally apply here.

@dzenanz
Copy link
Contributor Author

dzenanz commented Aug 11, 2022

Closing in favor of #2474.

@dzenanz dzenanz closed this as completed Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants