bioio-devs / bioio-lif

A BioIO reader plugin for reading LIF (Leica Image File) images.
GNU General Public License v3.0
0 stars 0 forks source link

`physical_pixel_sizes` is not not updated after changing scene #14

Open lorenzocerrone opened 1 week ago

lorenzocerrone commented 1 week ago

Describe the Bug

I have a .lif project with two scenes at a different scale. The physical_pixel_sizes property is not updated unless I manually trigger the Reader._read_immediate() method (or any method that calls ._read_immediate() internally).

Expected Behavior

When changing the scene using the set_scene method, I expected the Reader state to be updated.

Please let me know if you would welcome a contribution to fix this issue. I am happy to draft a PR to fix this issue.

Reproduction

img_bio = BioImage(path, reader=bioio_lif.Reader)
img_bio.set_scene("TileScan 1")
print(f"scene 1: {img_bio.physical_pixel_sizes=}")
img_bio.set_scene("Series001")
print(f"scene 2 before: {img_bio.physical_pixel_sizes=}")
img_bio.set_scene("Series001")
xdata = img_bio.reader._read_immediate()
print(f"scene 2 after: {img_bio.physical_pixel_sizes=}")

Output

scene 1: img_bio.physical_pixel_sizes=PhysicalPixelSizes(Z=None, Y=4.5588235294117645, X=4.5588235294117645)
scene 2 before: img_bio.physical_pixel_sizes=PhysicalPixelSizes(Z=None, Y=4.5588235294117645, X=4.5588235294117645)
scene 2 after: img_bio.physical_pixel_sizes=PhysicalPixelSizes(Z=1.3003362, Y=0.3969663405088063, X=0.3969663405088063)
evamaxfield commented 1 week ago

Wow. Yes. That info needs to be reset on set scene update.

Ping @toloudis @SeanLeRoy have either of you encountered this in other readers?

I just checked bioio-base and in the base reader spec we default return a tuple of None. Which is fine but the base reader spec should probably be the place where we fix this by standardizing the delayed loading of physical pixel sizes and their resetting on scene update.

Thank you for finding and documenting @lorenzocerrone !!

toloudis commented 1 week ago

we have a _reset_self that happens in the base class reader on scene change (and on multiresolution level change). But the base reader doesn't expect physical pixel size to be cached, it's up to each reader to get it right.