Skip to content

Commit

Permalink
Read scales from some OME tiff files parsed with the tifffile source
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed Jul 19, 2024
1 parent 2cc5ebf commit 6d7ee31
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

### Improvements

- Improve plottable data endpoint to better fetch adjacent items and annotations ([#1573](../../pull/1573), [#1574](../../pull/1574), [#1575](../../pull/1575), [#1580](../../pull/1580))
- Improve plottable data endpoint to better fetch adjacent items and annotations ([#1573](../../pull/1573), [#1574](../../pull/1574), [#1575](../../pull/1575), [#1580](../../pull/1580), [#1583](../../pull/1583))
- Support Girder flat-mount paths ([#1576](../../pull/1576))
- Lazily import some modules to speed up large_image import speed ([#1577](../../pull/1577))
- Create or check large images for each item in a folder ([#1572](../../pull/1572))
- Support multiprocessing and pickling with a zarr sink ([#1551](../../pull/1551))
- Allow checking for geospatial sources to use a specific source list ([#1582](../../pull/1582))
- Read scales from some OME tiff files parsed with the tifffile source ([#1584](../../pull/1584))

### Changes
- Remove old code that handled old pyproj packages ([#1581](../../pull/1581))
Expand Down
57 changes: 57 additions & 0 deletions sources/tifffile/large_image_source_tifffile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,63 @@ def _handle_svs(self):
except Exception:
pass

def _handle_ome(self):
"""
For OME Tiff, if we didn't parse the mangification elsewhere, try to
parse it here.
"""
import xml.etree.ElementTree

import large_image.tilesource.utilities

_omeUnitsToMeters = {
'Ym': 1e24,
'Zm': 1e21,
'Em': 1e18,
'Pm': 1e15,
'Tm': 1e12,
'Gm': 1e9,
'Mm': 1e6,
'km': 1e3,
'hm': 1e2,
'dam': 1e1,
'm': 1,
'dm': 1e-1,
'cm': 1e-2,
'mm': 1e-3,
'\u00b5m': 1e-6,
'nm': 1e-9,
'pm': 1e-12,
'fm': 1e-15,
'am': 1e-18,
'zm': 1e-21,
'ym': 1e-24,
'\u00c5': 1e-10,
}

try:
root = xml.etree.ElementTree.fromstring(self._tf.pages[0].description)
self._xml = large_image.tilesource.utilities.etreeToDict(root)
except Exception:
return
try:
try:
base = self._xml['OME']['Image'][0]['Pixels']
except Exception:
base = self._xml['OME']['Image']['Pixels']
if self._mm_x is None and 'PhysicalSizeX' in base:
self._mm_x = (
float(base['PhysicalSizeX']) * 1e3 *
_omeUnitsToMeters[base.get('PhysicalSizeXUnit', '\u00b5m')])
if self._mm_y is None and 'PhysicalSizeY' in base:
self._mm_y = (
float(base['PhysicalSizeY']) * 1e3 *
_omeUnitsToMeters[base.get('PhysicalSizeYUnit', '\u00b5m')])
self._mm_x = self._mm_x or self._mm_y
self._mm_y = self._mm_y or self._mm_x
except Exception:
pass

def getNativeMagnification(self):
"""
Get the magnification at a particular level.
Expand Down

0 comments on commit 6d7ee31

Please sign in to comment.