Skip to content

Commit

Permalink
ZarrHeader: Show a bit of .zarray info in var attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
rschmunk committed Mar 29, 2024
1 parent c2674ee commit 208a03a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions cdm/zarr/src/main/java/ucar/nc2/iosp/zarr/ZarrHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ private void makeVariable(RandomAccessDirectoryItem item, long dataOffset, ZArra
int[] shape = zarray.getShape();

if (hasNamedDimensions && shape.length != dimNames.length) {
throw new IllegalArgumentException(
"Var " + vname + " has dimensions attribute count that does not match its rank.");
throw new ZarrFormatException("Array " + vname + " has dimensions attribute count that does not match its rank.");
}

final List<Dimension> dims = new ArrayList<>();
Expand All @@ -311,7 +310,7 @@ private void makeVariable(RandomAccessDirectoryItem item, long dataOffset, ZArra
final Dimension prevd = optd.get();

if (dd.getLength() != prevd.getLength()) {
throw new IllegalArgumentException("Named dimension " + dname + " seen with inconsistent lengths.");
throw new ZarrFormatException("Named dimension " + dname + " seen with inconsistent lengths.");
}
} else {
logger.trace("adding {} to group as a shared dimension", dname);
Expand All @@ -332,6 +331,18 @@ private void makeVariable(RandomAccessDirectoryItem item, long dataOffset, ZArra
zarray.getOrder(), zarray.getSeparator(), zarray.getFilters(), dataOffset, initializedChunks);
var.setSPobject(vinfo);

// Include some info from .zarray file in attributes for display when showing variable detail.
// Possibly add to this fill_value if in .zarray but not .zattrs?
if (attrs == null) {
attrs = new ArrayList<Attribute>();
}
final Filter compressor = zarray.getCompressor();
if (compressor == null) {
attrs.add(new Attribute("_Compressor", "none"));
} else {
attrs.add(new Attribute("_Compressor", zarray.getCompressor().getName()));
}

// add current attributes, if any exist
if (attrs != null) {
var.addAttributes(attrs);
Expand Down

0 comments on commit 208a03a

Please sign in to comment.