@@ -26,12 +26,13 @@ import {
2626} from '@h5web/shared/hdf5-models' ;
2727import { getChildEntity } from '@h5web/shared/hdf5-utils' ;
2828
29- import { type AttrValuesStore } from '../../providers/models' ;
29+ import { type AttrValuesStore , type ValuesStore } from '../../providers/models' ;
3030import { hasAttribute } from '../../utils' ;
3131import {
3232 type AxisDef ,
3333 type DatasetInfo ,
3434 type DefaultSlice ,
35+ type ScalingInfo ,
3536 type SilxStyle ,
3637} from './models' ;
3738
@@ -130,6 +131,38 @@ export function findAuxErrorDataset(
130131 return dataset ;
131132}
132133
134+ export function findScalingFactor (
135+ group : GroupWithChildren ,
136+ datasetName : string ,
137+ ) : Dataset < ScalarShape , NumericType > | undefined {
138+ const dataset = getChildEntity ( group , `${ datasetName } _scaling_factor` ) ;
139+
140+ if ( ! dataset ) {
141+ return undefined ;
142+ }
143+
144+ assertDataset ( dataset ) ;
145+ assertScalarShape ( dataset ) ;
146+ assertNumericType ( dataset ) ;
147+ return dataset ;
148+ }
149+
150+ export function findOffset (
151+ group : GroupWithChildren ,
152+ datasetName : string ,
153+ ) : Dataset < ScalarShape , NumericType > | undefined {
154+ const dataset = getChildEntity ( group , `${ datasetName } _offset` ) ;
155+
156+ if ( ! dataset ) {
157+ return undefined ;
158+ }
159+
160+ assertDataset ( dataset ) ;
161+ assertScalarShape ( dataset ) ;
162+ assertNumericType ( dataset ) ;
163+ return dataset ;
164+ }
165+
133166export function findAssociatedDatasets (
134167 group : GroupWithChildren ,
135168 type : 'axes' | 'auxiliary_signals' ,
@@ -312,6 +345,27 @@ export function getSilxStyle(
312345 }
313346}
314347
348+ export function getScalingInfo (
349+ group : GroupWithChildren ,
350+ datasetName : string ,
351+ valuesStore : ValuesStore ,
352+ ) : ScalingInfo {
353+ const scalingFactorDataset = findScalingFactor ( group , datasetName ) ;
354+ const scalingFactor = scalingFactorDataset
355+ ? Number ( valuesStore . get ( { dataset : scalingFactorDataset } ) )
356+ : undefined ;
357+
358+ const offsetDataset = findOffset ( group , datasetName ) ;
359+ const offset = offsetDataset
360+ ? Number ( valuesStore . get ( { dataset : offsetDataset } ) )
361+ : undefined ;
362+
363+ return {
364+ scalingFactor,
365+ offset,
366+ } ;
367+ }
368+
315369export function getDatasetInfo (
316370 dataset : Dataset ,
317371 attrValuesStore : AttrValuesStore ,
0 commit comments