-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from will-moore/dataset_array_checks
Check datasets shape and dtype
- Loading branch information
Showing
7 changed files
with
136 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<script> | ||
export let valid; | ||
</script> | ||
|
||
{#if valid} | ||
<div class="valid">✓</div> | ||
{:else} | ||
<div class="invalid">×</div> | ||
{/if} | ||
|
||
<style> | ||
.invalid, | ||
.valid { | ||
border-radius: 50%; | ||
padding: 10px; | ||
margin: 10px auto; | ||
color: white; | ||
width: 100px; | ||
height: 100px; | ||
font-size: 50px; | ||
text-align: center; | ||
padding: 15px; | ||
} | ||
.invalid { | ||
background-color: red; | ||
border: solid red 1px; | ||
} | ||
.valid { | ||
background-color: green; | ||
border: solid green 1px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<script> | ||
import { getJson } from "../../utils"; | ||
import CheckMark from "../../CheckMark.svelte"; | ||
export let source; | ||
export let multiscale; | ||
// We check that all multiscale Datasets have same dtype and | ||
// shape.length (number of dimensions) | ||
// If multiscale.axes (version > 0.3) check it matches shape | ||
const {axes, datasets, version} = multiscale; | ||
// TODO: add "0.4" to this list once tested! | ||
const checkDtypes = !["0.1", "0.2", "0.3"].includes(version); | ||
const checkDimSeparator = ["0.2", "0.3", "0.4"].includes(version); | ||
function allEqual(items) { | ||
return items.every((value) => value == items[0]); | ||
} | ||
async function loadAndValidate() { | ||
let dtypes = []; | ||
let dimCounts = []; | ||
let shapes = []; | ||
let dimSeparators = []; | ||
for (let i = 0; i < datasets.length; i++) { | ||
let dataset = datasets[i]; | ||
let zarray = await getJson(source + dataset.path + "/.zarray"); | ||
dimCounts.push(zarray.shape.length); | ||
dtypes.push(zarray.dtype); | ||
shapes.push(zarray.shape); | ||
dimSeparators.push(zarray.dimension_separator); | ||
} | ||
let errors = []; | ||
if (dtypes.length === 0) { | ||
errors.push("No multiscale datasets") | ||
} | ||
if (checkDtypes && !allEqual(dtypes)) { | ||
errors.push(`dtypes mismatch: ${dtypes.join(", ")}`) | ||
} | ||
if (!allEqual(dimCounts)) { | ||
errors.push(`number of dimensions mismatch: ${dimCounts.join(", ")}`) | ||
} | ||
if (axes) { | ||
shapes.forEach((shape) => { | ||
if (shape.length != axes.length) { | ||
errors.push(`Shape (${shape.join(", ")}) doesn't match axes length: ${axes.length}`) | ||
} | ||
}); | ||
} | ||
if (checkDimSeparator) { | ||
dimSeparators.forEach((sep) => { | ||
if (sep != "/") { | ||
errors.push(`Dimension separator must be / for version ${version}`) | ||
} | ||
}); | ||
} | ||
return errors; | ||
} | ||
const promise = loadAndValidate(); | ||
</script> | ||
|
||
{#await promise} | ||
<p>loading...</p> | ||
{:then errors} | ||
{#if errors.length > 0} | ||
<!-- only show X if not valid - no tick if valid --> | ||
<CheckMark valid={false} /> | ||
{#each errors as error} | ||
<p style="color: red">Error: {error}</p> | ||
{/each} | ||
{:else} | ||
<p title="dtypes match and shapes are consistent"> | ||
{datasets.length} Datasets checked <span style="color:green">✓</span> | ||
</p> | ||
{/if} | ||
{:catch error} | ||
<p style="color: red">{error.message}</p> | ||
{/await} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters