Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve how ometiff internal metadata is exposed #1806

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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):]

Check warning on line 368 in sources/ometiff/large_image_source_ometiff/__init__.py

View check run for this annotation

Codecov / codecov/patch

sources/ometiff/large_image_source_ometiff/__init__.py#L368

Added line #L368 was not covered by tests
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']

Check warning on line 387 in sources/ometiff/large_image_source_ometiff/__init__.py

View check run for this annotation

Codecov / codecov/patch

sources/ometiff/large_image_source_ometiff/__init__.py#L387

Added line #L387 was not covered by tests
else:
self._reduceInternalMetadata(
result, subval, f'{pkey}:{subidx}'.strip(':'))
elif not isinstance(subval, list):
result[f'{pkey}:{subidx}'.strip(':')] = subval

Check warning on line 392 in sources/ometiff/large_image_source_ometiff/__init__.py

View check run for this annotation

Codecov / codecov/patch

sources/ometiff/large_image_source_ometiff/__init__.py#L392

Added line #L392 was not covered by tests
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 @@

: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

Check warning on line 411 in sources/ometiff/large_image_source_ometiff/__init__.py

View check run for this annotation

Codecov / codecov/patch

sources/ometiff/large_image_source_ometiff/__init__.py#L410-L411

Added lines #L410 - L411 were not covered by tests
return result

def getNativeMagnification(self):
"""
Expand Down