diff --git a/apps/demo/src/Home.tsx b/apps/demo/src/Home.tsx index 351c40ec1..f42ca8009 100644 --- a/apps/demo/src/Home.tsx +++ b/apps/demo/src/Home.tsx @@ -87,16 +87,22 @@ function Home() { group (Argonne National Laboratory).
  • - grove.h5 - a file used - to test the H5GroveProvider provider; it contains - datasets with NaN, Infinity, boolean - and complex values, as well as RGB images and 4D stacks. + grove.h5 - a file + designed to demonstrate the capabilities of{' '} + H5GroveProvider; it contains datasets with{' '} + NaN, Infinity, boolean and complex + values, as well as RGB images and 4D stacks.
  • links.h5 - a file with external links, soft links and a virtual dataset to test link resolution.
  • +
  • + sample.h5 - the file + used to test H5GroveApi and H5WasmApi{' '} + internally. +
  • tall.h5 - the demo file of HSDS. @@ -144,20 +150,24 @@ function Home() { silx.org :{' '} - {['water_224.h5', 'epics.h5', 'grove.h5', 'tall.h5 '].map( - (filename, index) => ( - - {index > 0 && ', '} - - {filename} - - - ), - )} + {[ + 'water_224.h5', + 'epics.h5', + 'grove.h5', + 'sample.h5', + 'tall.h5 ', + ].map((filename, index) => ( + + {index > 0 && ', '} + + {filename} + + + ))}

    diff --git a/packages/h5wasm/create_h5_sample.py b/create_h5_sample.py similarity index 99% rename from packages/h5wasm/create_h5_sample.py rename to create_h5_sample.py index 0bfaf49f1..4457a347a 100644 --- a/packages/h5wasm/create_h5_sample.py +++ b/create_h5_sample.py @@ -7,7 +7,7 @@ raise RuntimeError("Python 2 is not supported") BASE_PATH = os.path.dirname(os.path.realpath(sys.argv[0])) -DIST_PATH = os.path.join(BASE_PATH, "dist-h5") +DIST_PATH = os.path.join(BASE_PATH, "dist") os.makedirs(DIST_PATH, exist_ok=True) h5py.get_config().track_order = True diff --git a/packages/app/src/index.ts b/packages/app/src/index.ts index dae25242d..ee982098d 100644 --- a/packages/app/src/index.ts +++ b/packages/app/src/index.ts @@ -22,5 +22,10 @@ export { assertEnvVar } from '@h5web/shared/guards'; export { default as DataProvider } from './providers/DataProvider'; export { DataProviderApi } from './providers/api'; export type { ValuesStoreParams } from './providers/models'; -export { flattenValue, getNameFromPath, sliceValue } from './providers/utils'; +export { + flattenValue, + getNameFromPath, + sliceValue, + getValueOrError, +} from './providers/utils'; export { assertNonNull } from '@h5web/shared/guards'; diff --git a/packages/app/src/providers/h5grove/__snapshots__/h5grove-api.test.ts.snap b/packages/app/src/providers/h5grove/__snapshots__/h5grove-api.test.ts.snap new file mode 100644 index 000000000..247c44bab --- /dev/null +++ b/packages/app/src/providers/h5grove/__snapshots__/h5grove-api.test.ts.snap @@ -0,0 +1,1088 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`test file matches snapshot 1`] = ` +[ + { + "name": "int8_scalar", + "rawType": "|i1", + "shape": [], + "type": { + "class": "Integer", + "endianness": "little-endian", + "size": 8, + }, + "value": -128, + }, + { + "name": "int8_2D", + "rawType": "|i1", + "shape": [ + 2, + 3, + ], + "type": { + "class": "Integer", + "endianness": "little-endian", + "size": 8, + }, + "value": Int8Array [ + 0, + 1, + 2, + 3, + 4, + 5, + ], + }, + { + "name": "int16_scalar", + "rawType": "i4", + "shape": [], + "type": { + "class": "Integer", + "endianness": "big-endian", + "size": 32, + }, + "value": 0, + }, + { + "name": "int32_2D", + "rawType": "f4", + "shape": [], + "type": { + "class": "Float", + "endianness": "big-endian", + "size": 32, + }, + "value": 0, + }, + { + "name": "float32_2D", + "rawType": "c16", + "shape": [], + "type": { + "class": "Complex", + "imagType": { + "class": "Float", + "endianness": "big-endian", + "size": 64, + }, + "realType": { + "class": "Float", + "endianness": "big-endian", + "size": 64, + }, + }, + "value": [ + 1, + 2, + ], + }, + { + "name": "complex128_2D", + "rawType": "", + }, + { + "name": "reference_region_scalar", + "rawType": "|O", + "shape": [], + "type": { + "charSet": "UTF-8", + "class": "String", + }, + "value": "", + }, + { + "name": "bool_empty", + "rawType": "|b1", + "shape": null, + "type": { + "class": "Boolean", + }, + "value": null, + }, + { + "name": "bool_false_scalar", + "rawType": "|b1", + "shape": [], + "type": { + "class": "Boolean", + }, + "value": false, + }, + { + "name": "bool_true_scalar", + "rawType": "|b1", + "shape": [], + "type": { + "class": "Boolean", + }, + "value": true, + }, + { + "name": "bool_2D", + "rawType": "|b1", + "shape": [ + 2, + 4, + ], + "type": { + "class": "Boolean", + }, + "value": [ + true, + false, + true, + true, + false, + false, + true, + false, + ], + }, + { + "name": "enum_uint8_scalar", + "rawType": "|u1", + "shape": [], + "type": { + "class": "Integer (unsigned)", + "endianness": "little-endian", + "size": 8, + }, + "value": 1, + }, + { + "name": "enum_int32_scalar", + "rawType": " { + const api = new H5GroveApi(H5GROVE_URL, TEST_FILE, { + params: { file: TEST_FILE }, + }); + + const root = await api.getEntity('/'); + assertGroup(root); + assertGroupWithChildren(root); + + const children = await Promise.all( + root.children.map(async (child) => { + assertDataset(child); + const { name, shape, type, rawType } = child; + + const value = hasNonNullShape(child) + ? await getValueOrError(api, child) + : null; + + return { name, shape, type, rawType, value }; + }), + ); + + expect(children).toMatchSnapshot(); +}); diff --git a/packages/app/src/providers/utils.ts b/packages/app/src/providers/utils.ts index b17cbccf7..07a56891a 100644 --- a/packages/app/src/providers/utils.ts +++ b/packages/app/src/providers/utils.ts @@ -11,6 +11,7 @@ import { AxiosError } from 'axios'; import ndarray from 'ndarray'; import { applyMapping } from '../vis-packs/core/utils'; +import type { DataProviderApi } from './api'; export const CANCELLED_ERROR_MSG = 'Request cancelled'; @@ -112,3 +113,14 @@ export function typedArrayFromDType(dtype: DType) { return undefined; } + +export async function getValueOrError( + api: DataProviderApi, + dataset: Dataset, +): Promise { + try { + return await api.getValue({ dataset }); + } catch (error) { + return error; + } +} diff --git a/packages/h5wasm/src/h5wasm-api.test.ts b/packages/h5wasm/src/h5wasm-api.test.ts index 42dc4a1b6..b65aea7c7 100644 --- a/packages/h5wasm/src/h5wasm-api.test.ts +++ b/packages/h5wasm/src/h5wasm-api.test.ts @@ -1,22 +1,19 @@ +import { existsSync } from 'node:fs'; +import { readFile } from 'node:fs/promises'; +import path from 'node:path'; + +import { getValueOrError } from '@h5web/app'; import { assertDataset, assertGroup, assertGroupWithChildren, hasNonNullShape, } from '@h5web/shared/guards'; -import type { - ArrayShape, - Dataset, - ScalarShape, -} from '@h5web/shared/hdf5-models'; -import { existsSync } from 'fs'; -import { readFile } from 'fs/promises'; -import path from 'path'; import { expect, test } from 'vitest'; import { H5WasmApi } from './h5wasm-api'; -const LOCAL_TEST_FILE = path.resolve(__dirname, '../dist-h5/sample.h5'); +const LOCAL_TEST_FILE = path.resolve(process.cwd(), 'dist/sample.h5'); const REMOTE_TEST_FILE = 'http://www.silx.org/pub/h5web/sample.h5'; // `https` would complicate things... async function loadTestFile(): Promise { @@ -28,17 +25,6 @@ async function loadTestFile(): Promise { return resp.arrayBuffer(); } -async function getValueOrError( - api: H5WasmApi, - dataset: Dataset, -): Promise { - try { - return await api.getValue({ dataset }); - } catch (error) { - return error; - } -} - test('test file matches snapshot', async () => { const buffer = await loadTestFile(); const api = new H5WasmApi('sample.h5', buffer);