Plot datasets against their HDF5 dimension scales - #2035
Open
NAThompson wants to merge 1 commit into
Open
Conversation
H5Web derives plot axes only from NeXus `NXdata` metadata. A file that labels its axes the native HDF5 way -- `make_scale()` plus `attach_scale()`, which writes `DIMENSION_LIST` on the dataset and `REFERENCE_LIST` on the scale -- gets no axis at all, and is plotted against the integer sample index instead. That is a real loss of information rather than a cosmetic one. A non-uniformly sampled abscissa cannot be recovered from indices, so the plot is not merely unlabelled but wrong in shape: `support/sample/create_dimension_scales_sample.py` generates `t*sin(1/t)` on a time axis whose spacing spans four orders of magnitude, which the index axis renders as a completely different function. Dimension scales are also how NetCDF4 and h5py users label axes by default, so the affected set is large. Today the only workaround is to duplicate the data into hand-written `NXdata` groups, which is the redundancy silx-kit#1313 exists to remove. That fixture is a separate file rather than a group in `sample.h5` for two reasons: `sample.h5` is snapshotted by both the h5wasm and h5grove provider tests, which inline every root dataset's value and assert that every root child is a dataset; and shrinking the data enough to keep those snapshots readable would leave nothing to demonstrate, since the point is the spacing ratio. Scale resolution sits behind a new optional `getDimensionScales` on `DataProviderApi`, implemented here for h5wasm, which can lean on libhdf5 to dereference `DIMENSION_LIST`. h5grove and HSDS are untouched and keep plotting against indices; both would need server-side support first. Labels need none of this, since `DIMENSION_LABELS` is a plain attribute: a dimension can be named even when no scale is attached. Where HDF5 permits more than H5Web can show: the first *usable* of several scales on a dimension wins, so a dimension carrying N+1 bin boundaries next to N centres still gets an axis; a scale that is not 1D, or whose length differs from its dimension, falls back to the index axis rather than erroring, which the spec leaves to the application; the dimension label beats the scale's own name, as silx-kit#1435 did for NeXus `long_name`; and NeXus is untouched, so it still takes precedence. Failing to resolve the scales at all degrades the same way, so a dataset that used to plot against indices never becomes unviewable over an axis it did not have before. Scales are resolved in the vis container and their values fetched under `VisBoundary`, mirroring how the NeXus pack splits metadata from values. That split is load-bearing rather than stylistic: prefetching under a boundary that has already suspended would set the values store's progress state while the mounted loader is subscribed to it, which React reports as updating one component while rendering another. `usePrefetchValue` runs ahead of the resolution so the dataset's own values load alongside the scales, and each dimension's scale metadata and attributes are prefetched as a batch rather than one round trip per dimension. Towards silx-kit#1313.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
H5Web derives plot axes only from NeXus
NXdatametadata. A file that labels its axes the native HDF5 way --make_scale()plusattach_scale(), which writesDIMENSION_LISTon the dataset andREFERENCE_LISTon the scale -- gets no axis at all, and is plotted against the integer sample index instead.That is a real loss of information rather than a cosmetic one. A non-uniformly sampled abscissa cannot be recovered from indices, so the plot is not merely unlabelled but wrong in shape:
support/sample/create_dimension_scales_sample.pygeneratest*sin(1/t)on a time axis whose spacing spans four orders of magnitude, which the index axis renders as a completely different function. Dimension scales are also how NetCDF4 and h5py users label axes by default, so the affected set is large. Today the only workaround is to duplicate the data into hand-writtenNXdatagroups, which is the redundancy #1313 exists to remove.That fixture is a separate file rather than a group in
sample.h5for two reasons:sample.h5is snapshotted by both the h5wasm and h5grove provider tests, which inline every root dataset's value and assert that every root child is a dataset; and shrinking the data enough to keep those snapshots readable would leave nothing to demonstrate, since the point is the spacing ratio.Scale resolution sits behind a new optional
getDimensionScalesonDataProviderApi, implemented here for h5wasm, which can lean on libhdf5 to dereferenceDIMENSION_LIST. h5grove and HSDS are untouched and keep plotting against indices; both would need server-side support first. Labels need none of this, sinceDIMENSION_LABELSis a plain attribute: a dimension can be named even when no scale is attached.Where HDF5 permits more than H5Web can show: the first usable of several scales on a dimension wins, so a dimension carrying N+1 bin boundaries next to N centres still gets an axis; a scale that is not 1D, or whose length differs from its dimension, falls back to the index axis rather than erroring, which the spec leaves to the application; the dimension label beats the scale's own name, as #1435 did for NeXus
long_name; and NeXus is untouched, so it still takes precedence. Failing to resolve the scales at all degrades the same way, so a dataset that used to plot against indices never becomes unviewable over an axis it did not have before.Scales are resolved in the vis container and their values fetched under
VisBoundary, mirroring how the NeXus pack splits metadata from values. That split is load-bearing rather than stylistic: prefetching under a boundary that has already suspended would set the values store's progress state while the mounted loader is subscribed to it, which React reports as updating one component while rendering another.usePrefetchValueruns ahead of the resolution so the dataset's own values load alongside the scales, and each dimension's scale metadata and attributes are prefetched as a batch rather than one round trip per dimension.