|
1 | 1 | """This module contains a storage class and codec to support the N5 format.
|
2 | 2 | """
|
3 | 3 | import os
|
| 4 | +import re |
4 | 5 | import struct
|
5 | 6 | import sys
|
6 | 7 | import warnings
|
|
11 | 12 | from numcodecs.registry import get_codec, register_codec
|
12 | 13 |
|
13 | 14 | from .meta import ZARR_FORMAT, json_dumps, json_loads
|
14 |
| -from .storage import NestedDirectoryStore, _prog_ckey, _prog_number, normalize_storage_path |
| 15 | +from .storage import NestedDirectoryStore, _prog_number, normalize_storage_path |
15 | 16 | from .storage import array_meta_key as zarr_array_meta_key
|
16 | 17 | from .storage import attrs_key as zarr_attrs_key
|
17 | 18 | from .storage import group_meta_key as zarr_group_meta_key
|
|
25 | 26 | n5_attrs_key = 'attributes.json'
|
26 | 27 | n5_keywords = ['n5', 'dataType', 'dimensions', 'blockSize', 'compression']
|
27 | 28 |
|
| 29 | +potential_key = re.compile(r'(.*?)/((\d+)(\/\d+)+)$') |
| 30 | + |
| 31 | + |
28 | 32 |
|
29 | 33 | class N5Store(NestedDirectoryStore):
|
30 | 34 | """Storage class using directories and files on a standard file system,
|
@@ -143,6 +147,7 @@ def __setitem__(self, key, value):
|
143 | 147 |
|
144 | 148 | key = invert_chunk_coords(key)
|
145 | 149 |
|
| 150 | + print(key, value) |
146 | 151 | super().__setitem__(key, value)
|
147 | 152 |
|
148 | 153 | def __delitem__(self, key):
|
@@ -538,22 +543,17 @@ def _contains_attrs(self, path):
|
538 | 543 | return len(attrs) > 0
|
539 | 544 |
|
540 | 545 | def is_chunk_key(key):
|
541 |
| - segments = list(key.split('/')) |
542 |
| - if segments: |
543 |
| - last_segment = segments[-1] |
544 |
| - return _prog_ckey.match(last_segment) |
545 |
| - return False # pragma: no cover |
| 546 | + return potential_key.match(key) |
546 | 547 |
|
547 | 548 | def invert_chunk_coords(key):
|
548 |
| - segments = list(key.split('/')) |
549 |
| - if segments: |
550 |
| - last_segment = segments[-1] |
551 |
| - if _prog_ckey.match(last_segment): |
552 |
| - coords = list(last_segment.split('.')) |
553 |
| - last_segment = '.'.join(coords[::-1]) |
554 |
| - segments = segments[:-1] + [last_segment] |
555 |
| - key = '/'.join(segments) |
556 |
| - return key |
| 549 | + |
| 550 | + m = is_chunk_key(key) |
| 551 | + if m is None: |
| 552 | + return key |
| 553 | + |
| 554 | + first = m.group(1) |
| 555 | + last = "/".join(m.group(2).split("/"))[::-1] # Reverse |
| 556 | + return f"{first}/{last}" |
557 | 557 |
|
558 | 558 | def group_metadata_to_n5(group_metadata):
|
559 | 559 | '''Convert group metadata from zarr to N5 format.'''
|
|
0 commit comments