Reputation: 41
I'm reading CZI images with the first code block, successfully. I want to read xx.czi.gz with the second code block, but failed. How can I read 'czi.gz' in to an array?
Thanks a lot!
from czifile import CziFile
import gzip
fname='xxx.czi'
with CziFile(fname) as czi:
image_arrays = czi.asarray()
fname2='xxx.czi.gz'
with gzip.open(fname2, 'rb') as f:
with CziFile(f) as czi:
image_arrays = czi.asarray()
Upvotes: 0
Views: 290
Reputation: 25299
I think @Nico238 is correct - you need to unzip the file first. However, you don't need to do that manually. You can do it with your Python program. That would look like this:
import shutils
import gzip
from czifile import CziFile
fname='xxx.czi'
fname2='xxx.czi.gz'
# decompress fname2 and put it in fname
with gzip.open(fname2, 'rb') as f_in:
with open(fname, 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
with CziFile(fname) as czi:
image_arrays = czi.asarray()
(Source.)
Upvotes: 0
Reputation:
I think the problem is that CziFile expect a file path. In case 2, you give it a file descriptor. I didn't see a method to initialize from a stream/fd. You might have to unzip then save the gz before reading the czi
Upvotes: 1