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

Speed up loading or parsing some sources. #1015

Merged
merged 1 commit into from
Dec 16, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
### Improvements
- Better release file handles ([#1007](../../pull/1007))
- Support tiny images from the test source ([#1013](../../pull/1013))
- Speed up loading or parsing some multi sources ([#1015](../../pull/1015))

### Changes
- Don't report filename in internal PIL metadata ([#1006](../../pull/1006))
Expand Down
7 changes: 6 additions & 1 deletion sources/multi/large_image_source_multi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,12 @@ def __init__(self, path, **kwargs):
if start[:1] not in ('{', '#', '-') and (start[:1] < 'a' or start[:1] > 'z'):
raise TileSourceError('File cannot be opened via multi-source reader.')
fptr.seek(0)
self._info = yaml.safe_load(fptr)
try:
import orjson
self._info = orjson.loads(fptr.read())
except Exception:
fptr.seek(0)
self._info = yaml.safe_load(fptr)
except (json.JSONDecodeError, yaml.YAMLError, UnicodeDecodeError):
raise TileSourceError('File cannot be opened via multi-source reader.')
self._validator.validate(self._info)
Expand Down
38 changes: 20 additions & 18 deletions sources/nd2/large_image_source_nd2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,24 +218,26 @@ def getMetadata(self):

:returns: metadata dictionary.
"""
result = super().getMetadata()

sizes = self._nd2.sizes
axes = self._nd2order[:self._nd2order.index('Y')][::-1]
sizes = self._nd2.sizes
result['frames'] = frames = []
for idx in range(self._frameCount):
frame = {'Frame': idx}
basis = 1
ref = {}
for axis in axes:
ref[axis] = (idx // basis) % sizes[axis]
frame['Index' + (axis.upper() if axis.upper() != 'P' else 'XY')] = (
idx // basis) % sizes[axis]
basis *= sizes.get(axis, 1)
frames.append(frame)
self._addMetadataFrameInformation(result, self._channels)
return result
if not hasattr(self, '_computedMetadata'):
result = super().getMetadata()

sizes = self._nd2.sizes
axes = self._nd2order[:self._nd2order.index('Y')][::-1]
sizes = self._nd2.sizes
result['frames'] = frames = []
for idx in range(self._frameCount):
frame = {'Frame': idx}
basis = 1
ref = {}
for axis in axes:
ref[axis] = (idx // basis) % sizes[axis]
frame['Index' + (axis.upper() if axis.upper() != 'P' else 'XY')] = (
idx // basis) % sizes[axis]
basis *= sizes.get(axis, 1)
frames.append(frame)
self._addMetadataFrameInformation(result, self._channels)
self._computedMetadata = result
return self._computedMetadata

def getInternalMetadata(self, **kwargs):
"""
Expand Down