Skip to content

Commit

Permalink
Fetch boolean data from h5grove as binary
Browse files Browse the repository at this point in the history
  • Loading branch information
axelboc committed Aug 29, 2024
1 parent ac0b148 commit cd9174e
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 35 deletions.
4 changes: 2 additions & 2 deletions packages/app/src/providers/h5grove/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ describe('parseDType', () => {
parseDType({
class: 8,
size: 2,
base: { class: 0, size: 1, order: 0, sign: 0 },
base: { class: 0, size: 1, order: 0, sign: 1 },
members: { FALSE: 0, TRUE: 1 },
}),
).toStrictEqual(boolType());
).toStrictEqual(boolType(intType(8)));
});

it('should convert array types', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/providers/hsds/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('convertHsdsType', () => {
mapping: { FALSE: 0, TRUE: 1 },
};

expect(convertHsdsType(boolEnum)).toStrictEqual(boolType());
expect(convertHsdsType(boolEnum)).toStrictEqual(boolType(intType(8)));
});

it('should convert the complex compound type into Complex type', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/providers/mock/mock-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function makeMockFile(): GroupWithChildren {
string: strType(),
int: intType(),
float: floatType(),
bool: boolType(),
bool: boolType(intType(8)),
complex: cplxType(floatType()),
}),
}),
Expand All @@ -127,7 +127,7 @@ export function makeMockFile(): GroupWithChildren {
string: strType(),
int: intType(),
float: floatType(),
bool: boolType(),
bool: boolType(intType(8)),
complex: cplxType(floatType()),
}),
}),
Expand Down
7 changes: 4 additions & 3 deletions packages/app/src/providers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isEnumType, isNumericType } from '@h5web/shared/guards';
import { isBoolType, isEnumType, isNumericType } from '@h5web/shared/guards';
import type {
ArrayShape,
Dataset,
Expand All @@ -8,13 +8,14 @@ import type {
import { DTypeClass } from '@h5web/shared/hdf5-models';
import type { OnProgress } from '@h5web/shared/react-suspense-fetch';
import type { AxiosProgressEvent } from 'axios';
import { isAxiosError } from 'axios';

import type { DataProviderApi } from './api';

export const CANCELLED_ERROR_MSG = 'Request cancelled';

export function typedArrayFromDType(dtype: DType) {
if (isEnumType(dtype)) {
if (isEnumType(dtype) || isBoolType(dtype)) {
return typedArrayFromDType(dtype.base);
}

Expand Down Expand Up @@ -72,7 +73,7 @@ export async function getValueOrError(
try {
return await api.getValue({ dataset });
} catch (error) {
return error;
return isAxiosError(error) ? error.message : error;
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/vis-packs/core/visualizations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ const scalarInt = dataset('int', intType(), []);
const scalarUint = dataset('uint', uintType(), []);
const scalarFloat = dataset('float', floatType(), []);
const scalarStr = dataset('float', strType(), []);
const scalarBool = dataset('bool', boolType(), []);
const scalarBool = dataset('bool', boolType(intType(8)), []);
const scalarCplx = dataset('cplx', cplxType(floatType()), []);
const scalarCompound = dataset('comp', compoundType({ int: intType() }), []);
const oneDInt = dataset('int_1d', intType(), [5]);
const oneDUint = dataset('uint_1d', uintType(), [5]);
const oneDBool = dataset('bool_1d', boolType(), [3]);
const oneDBool = dataset('bool_1d', boolType(intType(8)), [3]);
const oneDCplx = dataset('cplx_1d', cplxType(floatType()), [10]);
const oneDCompound = dataset('comp_1d', compoundType({ int: intType() }), [5]);
const twoDInt = dataset('int_2d', intType(), [5, 3]);
const twoDUint = dataset('uint_2d', uintType(), [5, 3]);
const twoDBool = dataset('bool_2d', boolType(), [3, 2]);
const twoDBool = dataset('bool_2d', boolType(intType(8)), [3, 2]);
const twoDCplx = dataset('cplx_2d', cplxType(floatType()), [2, 2]);
const twoDStr = dataset('str_2d', strType(), [5, 3]);
const threeDFloat = dataset('float_3d', intType(), [5, 3, 1]);
Expand Down
8 changes: 6 additions & 2 deletions packages/lib/src/vis/matrix/MatrixVis.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type { ArrayValue, Primitive } from '@h5web/shared/hdf5-models';
import type {
ArrayValue,
Primitive,
PrintableType,
} from '@h5web/shared/hdf5-models';
import type { NdArray } from 'ndarray';

import type { ClassStyleAttrs, PrintableType } from '../models';
import type { ClassStyleAttrs } from '../models';
import GridProvider from './context';
import Grid from './Grid';

Expand Down
12 changes: 0 additions & 12 deletions packages/lib/src/vis/models.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import type {
BooleanType,
ComplexType,
NumericType,
StringType,
} from '@h5web/shared/hdf5-models';
import type {
AxisScaleType,
ColorScaleType,
Expand Down Expand Up @@ -87,12 +81,6 @@ export interface AxisParams {

export type Coords = [x: number, y: number];

export type PrintableType =
| BooleanType
| NumericType
| ComplexType
| StringType;

export interface HistogramParams {
values: NumArray;
bins: NumArray;
Expand Down
9 changes: 5 additions & 4 deletions packages/shared/src/hdf5-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ export type DType =
| ReferenceType
| UnknownType;

export interface BooleanType {
class: DTypeClass.Bool;
}

export interface NumericType {
class: DTypeClass.Integer | DTypeClass.Unsigned | DTypeClass.Float;
size: number;
Expand Down Expand Up @@ -172,6 +168,11 @@ export interface ArrayType<T extends DType = DType> {
dims?: number[];
}

export interface BooleanType {
class: DTypeClass.Bool;
base: NumericType; // typically int8 with h5py
}

export interface EnumType {
class: DTypeClass.Enum;
base: NumericType; // technically, only int/uint
Expand Down
10 changes: 5 additions & 5 deletions packages/shared/src/hdf5-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ export function strType(
};
}

export function boolType(): BooleanType {
return { class: DTypeClass.Bool };
}

export function cplxType(
realType: NumericType,
imagType = realType,
Expand Down Expand Up @@ -155,6 +151,10 @@ export function enumType(
};
}

export function boolType(baseType: NumericType): BooleanType {
return { class: DTypeClass.Bool, base: baseType };
}

export function enumOrBoolType(
baseType: NumericType,
hdf5Mapping: Record<string, number>,
Expand All @@ -164,7 +164,7 @@ export function enumOrBoolType(
hdf5Mapping.FALSE === 0 &&
hdf5Mapping.TRUE === 1
) {
return boolType();
return boolType(baseType);
}

return enumType(baseType, hdf5Mapping);
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/src/mock-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
buildEntityPath,
cplxType,
floatType,
intType,
strType,
unknownType,
} from './hdf5-utils';
Expand Down Expand Up @@ -297,7 +298,7 @@ function guessType(value: unknown): DType {
}

if (typeof value === 'boolean') {
return boolType();
return boolType(intType(8));
}

if (
Expand Down

0 comments on commit cd9174e

Please sign in to comment.