Skip to content

Commit

Permalink
Merge pull request #1806 from girder/ometiff-internal-metadata
Browse files Browse the repository at this point in the history
Improve how ometiff internal metadata is exposed
  • Loading branch information
manthey authored Feb 4, 2025
2 parents 690e0ce + c6acf2d commit 461c699
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

- Improve how we use vips to read lower tile levels ([#1794](../../pull/1794))
- Be more specific in casting when converting images via vips ([#1795](../../pull/1795))
- Improve how ometiff internal metadata is exposed ([#1806](../../pull/1806))

### Bug Fixes

- Fix an issue with lazy tiles that have non power of two scaling ([#1797](../../pull/1797))
- Use zarr.empty not np.empty when creating large zarr sinks ([#1801](../../pull/1801))
- Fix zarr sink addTile when no samples axis is specified ([#1805](../../pull/1805))

## 1.31.0

Expand Down
43 changes: 42 additions & 1 deletion sources/ometiff/large_image_source_ometiff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,41 @@ def getMetadata(self):
self._addMetadataFrameInformation(result, channels)
return result

def _reduceInternalMetadata(self, result, entry, prefix=''): # noqa
starts = ['StructuredAnnotations:OriginalMetadata:Series 0 ',
'StructuredAnnotations:OriginalMetadata:']
for start in starts:
if prefix.startswith(start):
prefix = prefix[len(start):]
if isinstance(entry, dict):
for key, val in entry.items():
pkey = f'{prefix}:{key}'.strip(':')
if pkey in starts or (pkey + ':') in starts:
pkey = ''
if isinstance(val, dict):
if 'ID' in val and 'Value' in val:
self._reduceInternalMetadata(result, val['Value'], prefix)
elif 'Key' in val and 'Value' in val:
result[f'{pkey}:{val["Key"]}'.strip(':')] = val['Value']
else:
self._reduceInternalMetadata(result, val, pkey)
elif isinstance(val, list):
for subidx, subval in enumerate(val):
if isinstance(subval, dict):
if 'ID' in subval and 'Value' in subval:
self._reduceInternalMetadata(result, subval['Value'], prefix)
elif 'Key' in subval and 'Value' in subval:
result[f'{pkey}:{subval["Key"]}'] = subval['Value']
else:
self._reduceInternalMetadata(
result, subval, f'{pkey}:{subidx}'.strip(':'))
elif not isinstance(subval, list):
result[f'{pkey}:{subidx}'.strip(':')] = subval
elif key == 'ID' and str(val).split(':')[0] in prefix:
continue
elif val != '' and pkey:
result[pkey] = val

def getInternalMetadata(self, **kwargs):
"""
Return additional known metadata about the tile source. Data returned
Expand All @@ -368,7 +403,13 @@ def getInternalMetadata(self, **kwargs):
:returns: a dictionary of data or None.
"""
return {'omeinfo': self._omeinfo}
result = {'omeinfo': self._omeinfo}
try:
result['omereduced'] = {}
self._reduceInternalMetadata(result['omereduced'], self._omeinfo)
except Exception:
pass
return result

def getNativeMagnification(self):
"""
Expand Down

0 comments on commit 461c699

Please sign in to comment.