soft-matter/pims

Problem with cine.py

malopez00 opened this issue · 4 comments

Hi, I just wanted to point out that, after updating Pims I started to have problems while using the .get_frame() function in cine.py

I managed to track down the error to the call to function get_time_to_trigger:

531, in get_frame
    'time_to_trigger': self.get_time_to_trigger(j),

I get the error:

File "C:\Users\malopez\miniconda3\envs\desarrollo\lib\site-packages\pims\cine.py", line 707, in get_time_to_trigger
    tt = tt['datetime'].timestamp() + tt['second_fraction']

OSError: [Errno 22] Invalid argument

I managed to bypass this issue by just deleting the 'time_to_trigger' attribute of the metadata (deleting line 531) but that is just a hotfix. Maybe you guys can figure out which is the problem. Maybe my cine files are old and don't work with new versions of Pims.

Thanks

Same problem here.
It can read the file using pims.open, but if I want to call one frame
file = pims.open('file.cine')
plt.imshow(file[0])

The same message showed up.
tt = tt['datetime'].timestamp() + tt['second_fraction']
[Errno 22] Invalid argument

I am using anaconda, Python 3.11.5 with win 10. I attached a file that failed to work with the code.
tt.zip

Thanks for the bug reports! After corresponding with @schen44 we're pretty sure that pims can't properly interpret the timestamp(s) in these Cine files, which fails silently on Mac (and results in nonsense timestamps), but raises an error on Windows. It's more likely that your cine files are too new — I'm pretty sure timestamps were working correctly several years ago. We're now trying to track down an updated version of the file format documentation — any leads would be helpful.

I can confirm that the two cine files included with pims, in the pims/tests/data directory, both have trigger timestamps that can be properly read by pims. They are from 2008 and 2019. I believe the 2019 file was saved by PCC version 3.3 (see #317). So there is a new format for this timestamp (or that location in the file is now being used for something else, and the timestamp is stored in a new location).

The issue seems to be that the "bad" files' trigger time is interpreted as being around 1970. So a possible crude workaround (besides editing the code) is to manually change the raw value to be something less surprising, for example:

cinefile = pims.open('filename.cine')
cinefile.header_dict['trigger_time'] = int(6e18)

I'll be interested to know if this works!

Yes, this works! Thank you so much.

cinefile = pims.open(name)
cinefile.header_dict['trigger_time'] = int(6e18)
print(cinefile[0])