MouseLand / suite2p

cell detection in calcium imaging recordings
http://www.suite2p.org
GNU General Public License v3.0
344 stars 240 forks source link

tifffile Errors Logged with tifffile.read_uic_tag in ome.tif #974

Closed jmdelahanty closed 1 year ago

jmdelahanty commented 1 year ago

The newest version of suite2p (suite2p v0.13.0) is spitting out many tifffile messages while attempting to run on a dataset. None of my labmates have seen this behavior yet and I haven't seen any issues related to it here. It doesn't seem to be a bug since it appears that things are still running normally, but I get many error messages logged like this one:

>>>ERROR<<<
<tifffile.read_uic_tag> failed reading CreateTime with ValueError: no datetime before year 1 (julianday=0)
<tifffile.read_uic_tag> failed reading LastSavedTime with ValueError: no datetime before year 1 (julianday=0)
<tifffile.read_uic_tag> failed reading CreateTime with ValueError: no datetime before year 1 (julianday=0)
<tifffile.read_uic_tag> failed reading LastSavedTime with ValueError: no datetime before year 1 (julianday=0)
<tifffile.read_uic_tag> failed reading CreateTime with ValueError: no datetime before year 1 (julianday=0)
<tifffile.read_uic_tag> failed reading LastSavedTime with ValueError: no datetime before year 1 (julianday=0)
<tifffile.read_uic_tag> failed reading CreateTime with ValueError: no datetime before year 1 (julianday=0)
<tifffile.read_uic_tag> failed reading LastSavedTime with ValueError: no datetime before year 1 (julianday=0)
>>>ERROR<<<
<tifffile.read_uic_tag> failed reading CreateTime with ValueError: no datetime before year 1 (julianday=0)
<tifffile.read_uic_tag> failed reading LastSavedTime with ValueError: no datetime before year 1 (julianday=0)
>>>ERROR<<<
<tifffile.read_uic_tag> failed reading CreateTime with ValueError: no datetime before year 1 (julianday=0)
<tifffile.read_uic_tag> failed reading LastSavedTime with ValueError: no datetime before year 1 (julianday=0)
<tifffile.read_uic_tag> failed reading CreateTime with ValueError: no datetime before year 1 (julianday=0)
<tifffile.read_uic_tag> failed reading LastSavedTime with ValueError: no datetime before year 1 (julianday=0)
<tifffile.read_uic_tag> failed reading CreateTime with ValueError: no datetime before year 1 (julianday=0)
<tifffile.read_uic_tag> failed reading LastSavedTime with ValueError: no datetime before year 1 (julianday=0)

I think it's doing this for every image in the recording it attempts to load. Examining an individual tiff like this using tifffile installed in my suite2p environment:

from tifffile import TiffFile

with TiffFile("20230303_CSE034_plane1_-330.75_raw-353_Cycle00001_Ch2_013423.ome.tif") as tif:
    tag = tif.pages[0].tags['UIC2tag']
    x = tag.value
    print(x['TimeCreated'])

Gives me the same error, like this:

<tifffile.read_uic_tag> failed reading CreateTime with ValueError: no datetime before year 1 (julianday=0)
<tifffile.read_uic_tag> failed reading LastSavedTime with ValueError: no datetime before year 1 (julianday=0)
<tifffile.read_uic_tag> failed reading CreateTime with ValueError: no datetime before year 1 (julianday=0)
<tifffile.read_uic_tag> failed reading LastSavedTime with ValueError: no datetime before year 1 (julianday=0)
/home/jdelahanty/miniconda3/envs/suite2p/lib/python3.8/site-packages/tifffile/tifffile.py:19148: RuntimeWarning: invalid value encountered in divide
  'ZDistance': values[:, 0] / values[:, 1],
[0]

Looking through a couple different recordings shows that Bruker's .ome.tif output simply puts a value of [0] in the time created tag.

I found a similar issue elsewhere describing this as a fatal error in the past, but Christophe Gohlke resolved it. Funny enough it references PrairieView doing something odd as the reason it was raised in the first place.

A solution for avoiding logging these kinds of things could be just to ignore these types of warnings, but I don't know what best practices are or if its even worth it. Not sure why I or my labmates haven't encountered this using previous versions of suite2p either.

EDIT ~I think this could possibly impact performance, it at least "feels" like its taking longer than normal on a machine I know is quite speedy for getting things into binary. Once I have some numbers comparing a dataset with these errors vs an instance where I don't I'll post them here...~

It does not influence performance.

carsen-stringer commented 1 year ago

Previously suite2p depended on scanimage-tiff-reader, but it was no longer supported on pypi. Thanks to Lawrence Niu (MBF Bioscience engineer) this is now fixed! Please pip install scanimage-tiff-reader and see if that removes the warnings. I think it may not install on Mac still, but it's working on Windows and Linux.

jmdelahanty commented 1 year ago

This worked! Errors are no more.