-
Notifications
You must be signed in to change notification settings - Fork 29
Support scaling_factor and offset for axis #1944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,13 +19,14 @@ import { | |
| findTitleDataset, | ||
| getDatasetInfo, | ||
| getDefaultSlice, | ||
| getScalingInfo, | ||
| getSilxStyle, | ||
| } from './utils'; | ||
|
|
||
| export const useDefaultSlice = createMemo(getDefaultSlice); | ||
|
|
||
| export function useNxData(group: GroupWithChildren): NxData { | ||
| const { attrValuesStore } = useDataContext(); | ||
| const { attrValuesStore, valuesStore } = useDataContext(); | ||
|
|
||
| assertNxDataGroup(group, attrValuesStore); | ||
| const signalDataset = findSignalDataset(group, attrValuesStore); | ||
|
|
@@ -46,7 +47,11 @@ export function useNxData(group: GroupWithChildren): NxData { | |
| })), | ||
| axisDefs: axisDatasets.map( | ||
| (dataset) => | ||
| dataset && { dataset, ...getDatasetInfo(dataset, attrValuesStore) }, | ||
| dataset && { | ||
| dataset, | ||
| ...getDatasetInfo(dataset, attrValuesStore), | ||
| ...getScalingInfo(group, dataset.name, valuesStore), | ||
| }, | ||
|
Comment on lines
+50
to
+53
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe time to make a |
||
| ), | ||
| defaultSlice: useDefaultSlice(group, signalDataset.shape, attrValuesStore), | ||
| silxStyle: getSilxStyle(group, attrValuesStore), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,11 @@ export interface DatasetInfo { | |
| unit: string | undefined; | ||
| } | ||
|
|
||
| export interface ScalingInfo { | ||
| scalingFactor: number | undefined; | ||
| offset: number | undefined; | ||
| } | ||
|
|
||
| export interface DatasetDef< | ||
| T extends NumericLikeType | ComplexType = NumericLikeType | ComplexType, | ||
| > extends DatasetInfo { | ||
|
|
@@ -38,7 +43,7 @@ type WithError<T extends DatasetDef> = T & { | |
| errorDataset?: Dataset<ArrayShape, NumericType>; | ||
| }; | ||
|
|
||
| export type AxisDef = DatasetDef<NumericType>; | ||
| export type AxisDef = DatasetDef<NumericType> & ScalingInfo; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about: interface AxisDef extends DatasetDef<NumericType> {
scalingFactor: number | undefined;
offset: number | undefined;
}
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, makes sense if we replace |
||
|
|
||
| export type DefaultSlice = (number | '.')[]; | ||
| export interface SilxStyle { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,12 +26,13 @@ import { | |
| } from '@h5web/shared/hdf5-models'; | ||
| import { getChildEntity } from '@h5web/shared/hdf5-utils'; | ||
|
|
||
| import { type AttrValuesStore } from '../../providers/models'; | ||
| import { type AttrValuesStore, type ValuesStore } from '../../providers/models'; | ||
| import { hasAttribute } from '../../utils'; | ||
| import { | ||
| type AxisDef, | ||
| type DatasetInfo, | ||
| type DefaultSlice, | ||
| type ScalingInfo, | ||
| type SilxStyle, | ||
| } from './models'; | ||
|
|
||
|
|
@@ -130,6 +131,38 @@ export function findAuxErrorDataset( | |
| return dataset; | ||
| } | ||
|
|
||
| export function findScalingFactor( | ||
|
||
| group: GroupWithChildren, | ||
| datasetName: string, | ||
| ): Dataset<ScalarShape, NumericType> | undefined { | ||
| const dataset = getChildEntity(group, `${datasetName}_scaling_factor`); | ||
|
|
||
| if (!dataset) { | ||
| return undefined; | ||
| } | ||
|
|
||
| assertDataset(dataset); | ||
| assertScalarShape(dataset); | ||
| assertNumericType(dataset); | ||
| return dataset; | ||
| } | ||
|
|
||
| export function findOffset( | ||
| group: GroupWithChildren, | ||
| datasetName: string, | ||
| ): Dataset<ScalarShape, NumericType> | undefined { | ||
| const dataset = getChildEntity(group, `${datasetName}_offset`); | ||
|
|
||
| if (!dataset) { | ||
| return undefined; | ||
| } | ||
|
|
||
| assertDataset(dataset); | ||
| assertScalarShape(dataset); | ||
| assertNumericType(dataset); | ||
| return dataset; | ||
| } | ||
|
|
||
| export function findAssociatedDatasets( | ||
| group: GroupWithChildren, | ||
| type: 'axes' | 'auxiliary_signals', | ||
|
|
@@ -312,6 +345,27 @@ export function getSilxStyle( | |
| } | ||
| } | ||
|
|
||
| export function getScalingInfo( | ||
| group: GroupWithChildren, | ||
| datasetName: string, | ||
| valuesStore: ValuesStore, | ||
| ): ScalingInfo { | ||
| const scalingFactorDataset = findScalingFactor(group, datasetName); | ||
| const scalingFactor = scalingFactorDataset | ||
| ? Number(valuesStore.get({ dataset: scalingFactorDataset })) | ||
| : undefined; | ||
|
|
||
| const offsetDataset = findOffset(group, datasetName); | ||
| const offset = offsetDataset | ||
| ? Number(valuesStore.get({ dataset: offsetDataset })) | ||
|
||
| : undefined; | ||
|
|
||
| return { | ||
| scalingFactor, | ||
| offset, | ||
| }; | ||
| } | ||
|
|
||
| export function getDatasetInfo( | ||
| dataset: Dataset, | ||
| attrValuesStore: AttrValuesStore, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to use
value.mapbut to no avail: I got errors saying thatBigIntcould not be converted to number.I think it has to do with the savage conversions I am doing in this part but I am not versed in TS enough to do better 😓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be best to skip bigint arrays, since it will not work anyway? I'll push something.