Skip to content

Commit

Permalink
Fix issue with nested zarr chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
constantinpape committed Mar 16, 2022
1 parent d314948 commit a2df2f6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
10 changes: 8 additions & 2 deletions include/z5/metadata.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ namespace z5 {
fillValue = static_cast<double>(fillValJson);
}

auto jIt = j.find("dimension_separator");
if(jIt != j.end()) {
zarrDelimiter = *jIt;
} else {
zarrDelimiter = ".";
}

const auto & compressionOpts = j["compressor"];

std::string zarrCompressorId = compressionOpts.is_null() ? "raw" : compressionOpts["id"];
Expand All @@ -156,8 +163,7 @@ namespace z5 {
throw std::runtime_error("z5.DatasetMetadata.fromJsonZarr: wrong compressor for zarr format: " + zarrCompressorId);
}

types::readZarrCompressionOptionsFromJson(compressor, compressionOpts,
compressionOptions);
types::readZarrCompressionOptionsFromJson(compressor, compressionOpts, compressionOptions);
}


Expand Down
16 changes: 16 additions & 0 deletions src/python/test/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,22 @@ def test_nested(self):
res = g['data'][:]
self.assertTrue(np.allclose(data, res))

def test_nested2(self):
f = z5py.ZarrFile(self.path, mode='w', dimension_separator='/')
chunks = (10, 10, 10)
f.create_dataset('data', shape=self.shape, chunks=chunks, dtype='float64')

g = z5py.ZarrFile(self.path, mode='a')
ds = f['data']
data = np.random.rand(*self.shape)
ds[:] = data
self.assertTrue(os.path.exists(
os.path.join(self.path, 'data/0/0/0')
))

res = ds[:]
self.assertTrue(np.allclose(data, res))


class TestN5Dataset(DatasetTestMixin, unittest.TestCase):
data_format = 'n5'
Expand Down

0 comments on commit a2df2f6

Please sign in to comment.