Skip to content

Commit

Permalink
Fix display of .zarray .zattrs and zarr.json in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Jun 12, 2024
1 parent 23d9b26 commit 190c0b7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/JsonValidator/MultiscaleArrays/ZarrArray/index.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<script>
import { getZarrArrayJson, formatBytes, getChunkShape, getArrayDtype } from "../../../utils";
import { getJson, formatBytes, getChunkShape, getArrayDtype } from "../../../utils";
import Cube3D from "./Cube3D.svelte";
import ChunkLoader from "./ChunkLoader.svelte";
export let source;
export let path;
const promise = getZarrArrayJson(source + "/" + path);
const promise = getJson(source + "/" + path);
function totalChunkCount(zarray) {
return chunkCounts(zarray).reduce((prev, curr) => prev * curr, 1);
Expand All @@ -28,7 +28,7 @@
</script>

<div class="array">
<p>Path <a href="{source + "/" + path + '/.zarray'} ">{path + "/.zarray"}</a></p>
<p>Path <a href="{source + "/" + path} ">{path}</a></p>

{#await promise}
<div>loading array .zarray ...</div>
Expand Down Expand Up @@ -64,7 +64,7 @@
<Cube3D {zarray} />

<details>
<summary>{path}/.zarray</summary>
<summary>{path}</summary>
<pre><code>{JSON.stringify(zarray, null, 2)}</code></pre>
</details>
{:catch error}
Expand Down
6 changes: 5 additions & 1 deletion src/JsonValidator/MultiscaleArrays/index.svelte
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
<script>
import ZarrArray from "./ZarrArray/index.svelte";
import Multiscale from "./Multiscale.svelte";
import {getVersion, getZarrArrayAttrsFileName} from "../../utils";
export let source;
export let rootAttrs;
const msVersion = getVersion(rootAttrs);
const zarrAttrsFileName = getZarrArrayAttrsFileName(msVersion);
</script>

{#each rootAttrs.multiscales as multiscale, idx}
<article>
<h2>Multiscale {idx}</h2>
<Multiscale {source} {multiscale} />
{#each multiscale.datasets as dataset}
<ZarrArray {source} path={dataset.path} />
<ZarrArray {source} path={dataset.path + "/" + zarrAttrsFileName} />
{/each}
</article>
{/each}
Expand Down
6 changes: 4 additions & 2 deletions src/JsonValidator/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
getJson,
getVersion,
getDataType,
getZarrGroupAttrsFileName,
} from "../utils";
export let source;
Expand All @@ -32,12 +33,13 @@
const zarrName = dirs[dirs.length - 1];
// check for labels/.zattrs
const labelsPromise = getJson(source + '/labels/.zattrs');
const zarrAttrsFileName = getZarrGroupAttrsFileName(msVersion);
const labelsPromise = getJson(source + '/labels/' + zarrAttrsFileName);
</script>

<article>
<p>
Validating: <a href={source}>/{zarrName}/.zattrs</a>
Validating: <a href={source}>/{zarrName}/{zarrAttrsFileName}</a>
</p>

{#if !msVersion}No version found. Using {CURRENT_VERSION}<br />{/if}
Expand Down
14 changes: 14 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ async function fetchHandleError(url) {
throw Error(msg);
}

export function getZarrGroupAttrsFileName(ngffVersion) {
if (["0.1", "0.2", "0.3", "0.4"].includes(ngffVersion)) {
return ".zattrs";
}
return "zarr.json";
}

export function getZarrArrayAttrsFileName(ngffVersion) {
if (["0.1", "0.2", "0.3", "0.4"].includes(ngffVersion)) {
return ".zarray";
}
return "zarr.json";
}

export async function getZarrArrayJson(zarr_dir) {
return getZarrJson(zarr_dir, ".zarray");
Expand Down Expand Up @@ -145,6 +158,7 @@ export function getNgffData(jsonData) {

export function getVersion(jsonData) {
let ngffData = getNgffData(jsonData);
// TODO: v0.5 won't likely have version at multiscales[0].version
console.log("getVersion", jsonData, ngffData);
let version = ngffData.multiscales
? ngffData.multiscales[0].version
Expand Down

0 comments on commit 190c0b7

Please sign in to comment.