tifffile icon indicating copy to clipboard operation
tifffile copied to clipboard

svs_description_metadata parsing issue

Open ap-- opened this issue 1 year ago • 2 comments

Hi @cgohlke

I ran into another svs file with malformed description metadata that prevents svs_description_metadata to parse it correctly:

import fsspec
from tifffile import TiffFile
from tifffile.tifffile import svs_description_metadata

with fsspec.open("s3://tcga-2-open/00781737-74c2-4e80-b58b-c910f15893a1/TCGA-OY-A56Q-01Z-00-DX1.F1556F26-8845-4962-9004-70F9747B46B7.svs", anon=True) as f:
    tf = TiffFile(f)
    desc = tf.pages[0].description

# malformed part of description:: |Title = Mag = 40X, compression quality =30|
print(svs_description_metadata(desc))

Adding maxsplit=1 here fixes the issue: https://github.com/cgohlke/tifffile/blob/eb79f64e65fdd17fa5722dac9ce32ec6dd224f5d/tifffile/tifffile.py#L19587

Here's the description for tests:

'Aperio Image Library vFS90 01\r\n159712x44759 [0,100 153271x44659] (256x256) JPEG/RGB Q=30|AppMag = 40|StripeWidth = 992|ScanScope ID = SS1475|Filename = 12-0893-1|Title = Mag = 40X, compression quality =30|Date = 11/20/12|Time = 01:06:12|Time Zone = GMT-05:00|User = 8ce982e3-6ea2-4715-8af3-9874e823e6d9|MPP = 0.2472|Left = 19.730396|Top = 15.537785|LineCameraSkew = 0.001417|LineAreaXOffset = 0.014212|LineAreaYOffset = -0.004733|Focus Offset = 0.000000|DSR ID = 152.19.62.167|ImageID = 311112|Exposure Time = 109|Exposure Scale = 0.000001|DisplayColor = 0|OriginalWidth = 159712|OriginalHeight = 44759|ICC Profile = ScanScope v1'

Cheers, Andreas 😃

ap-- avatar Aug 26 '22 12:08 ap--

Thank you! Your fix looks correct and will be in the next version.

cgohlke avatar Aug 26 '22 15:08 cgohlke

Hi @cgohlke,

Here are some more public examples, that will break. Even with the fix above. I'm not sure if changing to split on "=" compared to " = " will cause other problems, but it would fix the parsing for the examples below.

unparsable_svs_metadata = [
  # s3://tcga-2-open/2c0d04d0-aabd-4025-b2aa-68726770b692/TCGA-NF-A4WX-01Z-00-DX1.C7DF8EF9-75C5-4D45-86B5-E2A679062B76.svs
  'Aperio Image Library v11.0.37\r\n60169x38406 (256x256) JPEG/RGB Q=70|Patient=CS-10-SI_HE|Accession=|User=|Date=10/12/2012|Time=04:55:13 PM|Copyright=Hamamatsu Photonics KK|AppMag=20|Webslide Files=5329',
  #  s3://tcga-2-open/fa9e068f-f195-4cf9-90f3-e67fe90a2f65/TCGA-DD-A73B-01Z-00-DX1.11B9A0BD-56CF-48C7-AC39-ABC5D22F0D94.svs
  'Aperio Image Library v12.0.17 \r\n84237x46071 (256x256) J2K/KDU Q=70|Patient=Patient-Key_10236|Accession=|User=|Date=12/12/2013|Time=06:35:13 PM|Copyright=Hamamatsu Photonics KK|AppMag=20|Webslide Files=10397',
  # s3://tcga-2-open/ef7fcc3a-ae85-4753-8ee3-a8e999eee196/TCGA-DD-A73A-01Z-00-DX1.6B409977-53A6-4DD9-9763-2094E5B83942.svs
  'Aperio Image Library v12.0.17 \r\n84237x61433 (256x256) J2K/KDU Q=70|Patient=Patient-Key_10420|Accession=|User=|Date=12/12/2013|Time=03:16:47 PM|Copyright=Hamamatsu Photonics KK|AppMag=20|Webslide Files=12246',
  # s3://tcga-2-open/d7e87a37-b0e2-401f-a2d5-d18020e6ee3b/TCGA-DD-A73F-01Z-00-DX1.94618B17-5501-4011-A634-A0669DDCCD2E.svs
  'Aperio Image Library v12.0.17 \r\n60153x46071 (256x256) J2K/KDU Q=70|Patient=Patient-Key_8013|Accession=|User=|Date=12/12/2013|Time=03:21:44 PM|Copyright=Hamamatsu Photonics KK|AppMag=20|Webslide Files=6420',
  # s3://tcga-2-open/d09bdde7-b5cc-42e6-90e0-bdd5583efd61/TCGA-NF-A4WU-01Z-00-DX1.C50C3F98-470B-41E5-AC20-644EA8B42E22.svs
  'Aperio Image Library v11.0.37\r\n72203x46071 (256x256) JPEG/RGB Q=70|Patient=CS-7-SI_HE|Accession=|User=|Date=10/15/2012|Time=10:36:16 AM|Copyright=Hamamatsu Photonics KK|AppMag=20|Webslide Files=8316',
  # s3://tcga-2-open/ac5ffd5c-441d-4440-ac3b-848ba82f1814/TCGA-DD-A73G-01Z-00-DX1.F5AB3B95-268C-44DA-9D42-7A7B5E1D8516.svs
  'Aperio Image Library v12.0.17 \r\n72187x46071 (256x256) J2K/KDU Q=70|Patient=Patient-Key_3405|Accession=|User=|Date=12/12/2013|Time=04:28:57 PM|Copyright=Hamamatsu Photonics KK|AppMag=20|Webslide Files=7252',
  # s3://tcga-2-open/8d197e5d-fb39-4d40-977b-a96954a7c7bc/TCGA-NF-A4X2-01Z-00-DX1.B09588B4-FBD3-4CED-9E88-6D018F0B5098.svs
  'Aperio Image Library v11.0.37\r\n96271x53752 (256x256) JPEG/RGB Q=70|Patient=CS-15-SI_HE|Accession=|User=|Date=10/15/2012|Time=10:06:58 AM|Copyright=Hamamatsu Photonics KK|AppMag=20|Webslide Files=13051',
  # s3://tcga-2-open/80663216-8ffe-4d52-9cb5-9557d3439b1d/TCGA-DD-A73E-01Z-00-DX1.E80B5E5D-BE89-4BD1-A4E3-EEA26027D6E0.svs
  'Aperio Image Library v12.0.17 \r\n60153x46079 (256x256) J2K/KDU Q=70|Patient=Patient-Key_10246|Accession=|User=|Date=12/12/2013|Time=03:02:16 PM|Copyright=Hamamatsu Photonics KK|AppMag=20|Webslide Files=6335',
  # s3://tcga-2-open/71da1aaa-654e-4530-ae06-68344244d7d1/TCGA-DD-A73D-01Z-00-DX1.455790BB-767B-458D-A90E-046FD47D0A92.svs
  'Aperio Image Library v12.0.17 \r\n60153x38390 (256x256) J2K/KDU Q=70|Patient=Patient-Key_10316|Accession=|User=|Date=12/12/2013|Time=04:34:02 PM|Copyright=Hamamatsu Photonics KK|AppMag=20|Webslide Files=5160',
  # s3://tcga-2-open/a4938bbb-24b4-4cf4-84bf-bb23cee34650/TCGA-NF-A5CP-01Z-00-DX1.FA60B2E0-880E-41FB-92B9-0F61C76A8CF2.svs
  'Aperio Image Library v11.1.9\r\n72203x46071 (256x256) JPEG/RGB Q=30|Patient=CS-23-SI_HE|Accession=|User=|Date=12/11/2012|Time=05:17:37 PM|Copyright=Hamamatsu Photonics KK|AppMag=20|Webslide Files=8301',
  # s3://tcga-2-open/ca63b656-547a-4380-bd80-70f81ea35987/TCGA-DD-A73C-01Z-00-DX1.B31DD97B-0C66-4404-9521-4CE5661CA0C4.svs
  'Aperio Image Library v12.0.17 \r\n72187x53752 (256x256) J2K/KDU Q=70|Patient=Patient-Key_10357|Accession=|User=|Date=12/12/2013|Time=06:42:01 PM|Copyright=Hamamatsu Photonics KK|AppMag=20|Webslide Files=8862',
]

Cheers, Andreas 😃

ap-- avatar Aug 29 '22 11:08 ap--

Fixed in v2022.10.10.

cgohlke avatar Oct 11 '22 16:10 cgohlke