Open alexbaras opened 3 weeks ago
Hi Alex, I followed your example above to get timestamp information from my czi file. At least I think this might be the only way to retrieve that data for every frame.
from io import BytesIO
import czifile
with czifile.CziFile(czi_file.as_posix()) as f:
# get attachment objects
attachments = {a.attachment_entry.name: {'obj': a} for a in f.attachments()}
attachments['TimeStamps']['obj']._fh.seek(attachments['TimeStamps']['obj'].data_offset)
with BytesIO(attachments['TimeStamps']['obj']._fh.read(attachments['TimeStamps']['obj'].data_size)) as fh:
attachments['TimeStamps']['img'] = czifile.CziFile(fh).asarray()
However I am running into this error
ValueError Traceback (most recent call last)
Cell In[1422], line 8
5 attachments['TimeStamps']['obj']._fh.seek(attachments['TimeStamps']['obj'].data_offset)
6 with BytesIO(attachments['TimeStamps']['obj']._fh.read(attachments['TimeStamps']['obj'].data_size)) as fh:
----> 8 attachments['TimeStamps']['img'] = czifile.CziFile(fh).asarray()
File [~/miniconda3/envs/suite2p/lib/python3.9/site-packages/czifile/czifile.py:266](http://localhost:8888/lab/tree/octo_code/calcium_imaging_slices/~/miniconda3/envs/suite2p/lib/python3.9/site-packages/czifile/czifile.py#line=265), in CziFile.__init__(self, arg, multifile, filesize, detectmosaic)
264 try:
265 if self._fh.read(10) != b'ZISRAWFILE':
--> 266 raise ValueError('not a CZI file')
267 self.header = Segment(self._fh, 0).data()
268 except Exception:
ValueError: not a CZI file
Do you have any ideas on how to solve that?
From my perspective the pylibczirw module is one of the only modules that allows for writing czi files. As such, I think it would be important to enable both reading and writing of czi files to include various associated images like slide label and slide / tissue preview.
For now I use czifile for access to the "attachments". I've posted that code example below. I suspect this example and the czifile module code base could be put together to achieve the desired effect.
-Alex
get czi attachments
with czifile.CziFile(czi_files[i_file]) as czi:
get attachment objects