One create a "generic" DatasetAttributes instance, and use that with any N5Writer to create a dataset and write blocks with it. For example, this works:
ZarrKeyValueWriter zarr = ...
DatasetAttributes attrs = new DatasetAttributes(...
zarr.createDataset(path, attrs)
zarr.writeBlock(path, attrs, block);
and internally "converts" from the generic to a format-specific DatasetAttributes instance (in this case ZarrDatasetAttributes) using default values when appropriate (in this case, for "fill_value" and "dimension_separator").
One (minor) downside of this is that we pay an extra cost to check and possibly convert the attributes every time a block is
written (see the current ZarrKeyValueWriter.writeBlock.
Another downside is the maintenance burden. So far it has been minimal, but is now more challenging given that we have a public DatasetAttributes constructor with a BlockCodecInfo argument. This means that the BlockCodecInfo needs to be inspected and possibly replaced with an appropriate replacement in order to write data correctly for a specific format.
For example
new DatasetAttributes(
dimensions, blockSize, dataType,
new N5BlockCodecInfo(),
new GzipCompression());
would naively produce wrong zarr blocks if the N5BlockCodecInfo is used.
Similarly
new DatasetAttributes(
dimensions, blockSize, dataType,
new RawBlockCodecInfo(),
new GzipCompression());
would naively produce wrong n5 blocks if the RawBlockCodecInfo is used.
writeBlock attribute conversion cost
we pay an extra cost to check and possibly convert the attributes every time a block is
written
this is technically avoidable with:
ZarrKeyValueWriter zarr = ...
DatasetAttributes attrs = new DatasetAttributes(...
zarr.createDataset(path, attrs)
DatasetAttributes actualAttrs = zarr.getDatasetAttributes(path);
zarr.writeBlock(path, actualAttrs, block);
but is ugly, and no one should or will do this.
One create a "generic"
DatasetAttributesinstance, and use that with any N5Writer to create a dataset and write blocks with it. For example, this works:and internally "converts" from the generic to a format-specific
DatasetAttributesinstance (in this caseZarrDatasetAttributes) using default values when appropriate (in this case, for "fill_value" and "dimension_separator").One (minor) downside of this is that we pay an extra cost to check and possibly convert the attributes every time a block is
written (see the current ZarrKeyValueWriter.writeBlock.
Another downside is the maintenance burden. So far it has been minimal, but is now more challenging given that we have a public DatasetAttributes constructor with a BlockCodecInfo argument. This means that the BlockCodecInfo needs to be inspected and possibly replaced with an appropriate replacement in order to write data correctly for a specific format.
For example
would naively produce wrong zarr blocks if the N5BlockCodecInfo is used.
Similarly
would naively produce wrong n5 blocks if the RawBlockCodecInfo is used.
writeBlock attribute conversion cost
this is technically avoidable with:
but is ugly, and no one should or will do this.