Skip to content

Commit

Permalink
Handle 0.5-dev version
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Jun 14, 2024
1 parent 6940281 commit f6de93d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import Modal from "svelte-simple-modal";
import SplashScreen from "./SplashScreen.svelte";
import { getZarrJson } from "./utils";
import { getZarrGroupAttrs } from "./utils";
import CheckMark from "./CheckMark.svelte";
const searchParams = new URLSearchParams(window.location.search);
Expand All @@ -22,7 +22,7 @@
if (source) {
// load JSON to be validated...
console.log("Loading JSON... " + source);
promise = getZarrJson(source);
promise = getZarrGroupAttrs(source);
}
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/JsonValidator/MultiscaleArrays/ZarrArray/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<p>Path <a href="{source + "/" + path} ">{path}</a></p>

{#await promise}
<div>loading array .zarray ...</div>
<div>loading array data ...</div>
{:then zarray}
<table>
<tr>
Expand Down
14 changes: 6 additions & 8 deletions src/JsonValidator/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
CURRENT_VERSION,
getSchemaUrlsForJson,
validate,
getNgffData,
getJson,
getVersion,
getDataType,
Expand All @@ -24,7 +23,6 @@
const msVersion = getVersion(rootAttrs);
const dtype = getDataType(rootAttrs);
const ngffData = getNgffData(rootAttrs);
const schemaUrls = getSchemaUrlsForJson(rootAttrs);
console.log("index.svelte schemaUrls", schemaUrls)
const promise = validate(rootAttrs);
Expand Down Expand Up @@ -82,12 +80,12 @@
{/await}
</article>

{#if ngffData.multiscales}
<MultiscaleArrays {source} rootAttrs={ngffData} />
{:else if ngffData.plate}
<Plate {source} rootAttrs={ngffData} />
{:else if ngffData.well}
<Well {source} rootAttrs={ngffData} />
{#if rootAttrs.multiscales}
<MultiscaleArrays {source} rootAttrs={rootAttrs} />
{:else if rootAttrs.plate}
<Plate {source} rootAttrs={rootAttrs} />
{:else if rootAttrs.well}
<Well {source} rootAttrs={rootAttrs} />
{/if}

<style>
Expand Down
33 changes: 13 additions & 20 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export function getSchemaUrl(schemaName, version) {
if (version == "0.5") {
// TEMP: use open PR branch
return `https://raw.githubusercontent.com/normanrz/ngff/spec-rfc2/latest/schemas/${schemaName}.schema`;
} else if (version == "0.5-dev") {
return `https://raw.githubusercontent.com/d-v-b/ngff/multiple_zarr_versions/0.5-dev1/schemas/${schemaName}.schema`;
}
return `https://raw.githubusercontent.com/ome/ngff/main/${version}/schemas/${schemaName}.schema`;
}
Expand Down Expand Up @@ -80,11 +82,17 @@ export function getZarrArrayAttrsFileName(ngffVersion) {
return "zarr.json";
}

export async function getZarrGroupAttrs(zarr_dir) {
let rawJson = await getZarrJson(zarr_dir, ".zattrs");
let groupAttrs = rawJson.attributes || rawJson;
return groupAttrs;
}

export async function getZarrArrayJson(zarr_dir) {
return getZarrJson(zarr_dir, ".zarray");
}

export async function getZarrJson(zarr_dir, alternative=".zattrs") {
async function getZarrJson(zarr_dir, alternative=".zattrs") {
let zarrJson;
let msg;
// try to load v2 /.zattrs or v3 /zarr.json
Expand Down Expand Up @@ -143,30 +151,15 @@ export async function getSchema(schemaUrl) {
return schemas[schemaUrl];
}

export function getNgffData(jsonData) {
// Handle nesting of NGFF data under namespace key for v0.5+
if (jsonData.attributes) {
for(let v=0; v<NAMESPACED_VERSIONS.length; v++) {
let key = getNamespacedKey(NAMESPACED_VERSIONS[v]);
if (jsonData.attributes.hasOwnProperty(key)) {
return jsonData.attributes[key];
}
}
}
return 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);
export function getVersion(ngffData) {
let version = ngffData.multiscales
? ngffData.multiscales[0].version
: ngffData.plate
? ngffData.plate.version
: ngffData.well
? ngffData.well.version
: undefined;
console.log("version", version);
return version;
}

Expand All @@ -188,8 +181,7 @@ export function getSchemaName(jsonData) {
return names[0];
}

export function getSchemaNames(jsonData) {
let ngffData = getNgffData(jsonData);
export function getSchemaNames(ngffData) {
let names = [];
if (ngffData.multiscales) {
names.push("image");
Expand All @@ -207,6 +199,7 @@ export function getSchemaNames(jsonData) {
}

export function getSchemaUrlsForJson(rootAttrs) {
console.log('getSchemaUrlsForJson rootAttrs', rootAttrs)
const msVersion = getVersion(rootAttrs);
const version = msVersion || CURRENT_VERSION;
// for v0.5 onwards, rootAttrs is nested under attributes.namespace...
Expand Down

0 comments on commit f6de93d

Please sign in to comment.