Skip to content

Commit

Permalink
Handle v0.5-dev2 data
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Jul 3, 2024
1 parent e5b5bef commit fdd8a55
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/JsonValidator/Plate/index.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { CURRENT_VERSION, getVersion, getSchema, getSearchParam, range } from "../../utils";
import { CURRENT_VERSION, getVersion, getSchema, getSchemaUrl, getSearchParam, range } from "../../utils";
import WellContainer from "./WellContainer/index.svelte";
Expand Down Expand Up @@ -30,8 +30,8 @@
// wait for schemas to be cached, so we don't load them multiple times
let schemasPromise = Promise.all([
getSchema(version, "well"),
getSchema(version, "image"),
getSchema(getSchemaUrl("well", version)),
getSchema(getSchemaUrl("image", version)),
]);
function handleSelect(event) {
Expand Down
21 changes: 12 additions & 9 deletions src/JsonValidator/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
export let source;
export let rootAttrs;
// v0.5+ unwrap the attrs under "ome"
const omeAttrs = rootAttrs.ome || rootAttrs;
const msVersion = getVersion(rootAttrs);
const dtype = getDataType(rootAttrs);
const schemaUrls = getSchemaUrlsForJson(rootAttrs);
const dtype = getDataType(omeAttrs);
const schemaUrls = getSchemaUrlsForJson(omeAttrs);
console.log("index.svelte schemaUrls", schemaUrls)
const promise = validate(rootAttrs);
const promise = validate(omeAttrs);
const dirs = source.split("/").filter(Boolean);
const zarrName = dirs[dirs.length - 1];
Expand Down Expand Up @@ -80,12 +83,12 @@
{/await}
</article>

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

<style>
Expand Down
23 changes: 8 additions & 15 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,20 @@
import Ajv from "ajv";

export const CURRENT_VERSION = "0.5";
// versions to check for e.g. attributes['https://ngff.openmicroscopy.org/0.5']
// which start at version 0.5
export const NAMESPACED_VERSIONS = ["0.5"]
export const FILE_NOT_FOUND = "File not found";

const ajv = new Ajv({ strict: false }); // options can be passed, e.g. {allErrors: true}

export function getSchemaUrl(schemaName, version) {
if (version == "0.5") {
if (version == "0.5" || version == "0.5-dev2") {
// TEMP: use open PR branch
return `https://raw.githubusercontent.com/normanrz/ngff/spec-rfc2/latest/schemas/${schemaName}.schema`;
} else if (version == "0.5-dev1") {
https://raw.githubusercontent.com/d-v-b/ngff/multiple_zarr_versions/0.5-dev1/schemas/image.schema
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`;
}

function getNamespacedKey(version) {
if (!version) {
version = CURRENT_VERSION;
}
return `https://ngff.openmicroscopy.org/${version}`;
}


// fetch() doesn't error for 404 etc.
async function fetchHandleError(url) {
Expand Down Expand Up @@ -153,6 +142,10 @@ export async function getSchema(schemaUrl) {
}

export function getVersion(ngffData) {
console.log("getVersion...", ngffData, ngffData.ome?.version)
if (ngffData.ome?.version) {
return ngffData.ome.version;
}
let version = ngffData.multiscales
? ngffData.multiscales[0].version
: ngffData.plate
Expand Down Expand Up @@ -203,9 +196,9 @@ 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...
if (NAMESPACED_VERSIONS.includes(version)) {
rootAttrs = rootAttrs.attributes[getNamespacedKey(version)];
// for v0.5 onwards, rootAttrs is nested under attributes.ome...
if (rootAttrs.ome) {
rootAttrs = rootAttrs.ome;
}
const schemaNames = getSchemaNames(rootAttrs);
return schemaNames.map(name => getSchemaUrl(name, version));
Expand Down

0 comments on commit fdd8a55

Please sign in to comment.