Skip to content

Commit

Permalink
Check dimension_names for all zarr.json
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Jul 4, 2024
1 parent e150aa9 commit e12265f
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/JsonValidator/MultiscaleArrays/Multiscale.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
const permitDtypeMismatch = ["0.1", "0.2", "0.3", "0.4"].includes(version);
const checkDimSeparator = ["0.2", "0.3", "0.4"].includes(version);
const allowMissingDimNames = ["0.1", "0.2", "0.3", "0.4"].includes(version);
let successMsg = "dtypes match and shapes are consistent";
if (!allowMissingDimNames) {
successMsg = "dimension_names checked, " + successMsg;
}
function allEqual(items) {
return items.every((value) => value == items[0]);
Expand All @@ -29,11 +34,12 @@
let dimCounts = [];
let shapes = [];
let dimSeparators = [];
let zarrayJsonList = [];
for (let i = 0; i < datasets.length; i++) {
let dataset = datasets[i];
let zarray = await getZarrArrayJson(source + "/" + dataset.path);
console.log('zarray', zarray);
zarrayJsonList.push(zarray);
// Need to handle Zarr v2 and Zarr v3:
dimCounts.push(zarray.shape.length);
dtypes.push(zarray.dtype || zarray.data_type);
Expand Down Expand Up @@ -74,6 +80,24 @@
});
}
});
if (!allowMissingDimNames) {
let axesNames = JSON.stringify(axes.map(axis => axis.name));
zarrayJsonList.forEach((arrData, i) => {
let msg;
if (!arrData.dimension_names) {
msg = `No dimension_names found for dataset ${i}`;
} else {
let dimNames = JSON.stringify(arrData.dimension_names);
if (dimNames != axesNames) {
msg = `dimension_names: ${dimNames} don't match axes names: ${axesNames}`;
}
}
if (msg) {
checks.push({msg});
}
});
}
}
if (checkDimSeparator) {
dimSeparators.forEach((sep) => {
Expand All @@ -97,7 +121,7 @@
<!-- only show X if not valid - no tick if valid -->
<CheckMark valid={false} />
{:else}
<p title="dtypes match and shapes are consistent">
<p title="{successMsg}">
{datasets.length} Datasets checked <span style="color:green"></span>
</p>
{/if}
Expand Down

0 comments on commit e12265f

Please sign in to comment.