-
Notifications
You must be signed in to change notification settings - Fork 28
Improve support for NetCDF fill value and valid range attributes #1956
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.31 KB
(99%)
cypress/snapshots/app.cy.ts/heatmap_2D_inverted_cmap.snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+621 Bytes
(100%)
cypress/snapshots/app.cy.ts/line_complex_constant.snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-241 Bytes
(100%)
cypress/snapshots/app.cy.ts/nxheatmap_complex_2d.snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-173 Bytes
(100%)
cypress/snapshots/app.cy.ts/nxheatmap_complex_2d_float_aux.snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { screen, within } from '@testing-library/react'; | ||
| import { expect, test } from 'vitest'; | ||
|
|
||
| import { renderApp } from '../test-utils'; | ||
|
|
||
| test('visualize dataset with `valid_min` and/or `valid_max` attributes', async () => { | ||
| const { selectExplorerNode } = await renderApp('/netcdf/valid_min'); | ||
|
|
||
| const fig1 = screen.getByRole('figure', { name: 'valid_min' }); | ||
| expect(within(fig1).getByText('4e+2')).toBeVisible(); // data max | ||
| expect(within(fig1).getByText('5e+0')).toBeVisible(); // valid_min | ||
|
|
||
| await selectExplorerNode('valid_max'); | ||
| const fig2 = screen.getByRole('figure', { name: 'valid_max' }); | ||
| expect(within(fig2).getByText('2e+2')).toBeVisible(); // valid_max | ||
| expect(within(fig2).getByText('−9.5e+1')).toBeVisible(); // data min | ||
|
|
||
| await selectExplorerNode('valid_min_max'); | ||
| const fig3 = screen.getByRole('figure', { name: 'valid_min_max' }); | ||
| expect(within(fig3).getByText('2e+2')).toBeVisible(); // valid_max | ||
| expect(within(fig3).getByText('5e+0')).toBeVisible(); // valid_min | ||
| }); | ||
|
|
||
| test('visualize dataset with `valid_range` attribute', async () => { | ||
| await renderApp('/netcdf/valid_range'); | ||
|
|
||
| const fig = screen.getByRole('figure', { name: 'valid_range' }); | ||
| expect(within(fig).getByText('2e+2')).toBeVisible(); // valid_range[1] | ||
| expect(within(fig).getByText('5e+0')).toBeVisible(); // valid_range[0] | ||
| }); | ||
|
|
||
| test('visualize dataset with `_FillValue` attribute', async () => { | ||
| const { selectExplorerNode } = await renderApp('/netcdf/_FillValue'); | ||
|
|
||
| const fig1 = screen.getByRole('figure', { name: '_FillValue' }); | ||
| expect(within(fig1).getByText('9.9e+1')).toBeVisible(); // closest data value lower than _FillValue | ||
| expect(within(fig1).getByText('−9.5e+1')).toBeVisible(); // data min | ||
|
|
||
| await selectExplorerNode('_FillValue (negative)', true); | ||
| const fig2 = screen.getByRole('figure', { name: '_FillValue (negative)' }); | ||
| expect(within(fig2).getByText('4e+2')).toBeVisible(); // data max | ||
| expect(within(fig2).getByText('−6e+0')).toBeVisible(); // closest data value greater than _FillValue | ||
| }); |
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { type IgnoreValue } from '@h5web/lib'; | ||
| import { hasNumericType } from '@h5web/shared/guards'; | ||
| import { type ArrayShape, type Dataset } from '@h5web/shared/hdf5-models'; | ||
| import { useMemo } from 'react'; | ||
|
|
||
| import { useDataContext } from '../../providers/DataProvider'; | ||
| import { createIgnoreFillValue, getFillValue, getValidRange } from './utils'; | ||
|
|
||
| /* Priority order: `valid_min` and/or `valid_max`, then `valid_range`, then `_FillValue`. | ||
| * Note that `_FillValue` acts as an invalid upper or lower bound (if positive or negative respectively). | ||
| * See NetCDF `valid_range` convention: https://docs.unidata.ucar.edu/netcdf-c/current/attribute_conventions.html */ | ||
| export function useNcIgnoreValue( | ||
| dataset: Dataset<ArrayShape>, | ||
| ): IgnoreValue | undefined { | ||
| const { attrValuesStore } = useDataContext(); | ||
|
|
||
| return useMemo(() => { | ||
| if (!hasNumericType(dataset)) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const validRange = getValidRange(dataset, attrValuesStore); | ||
| if (validRange) { | ||
| const [validMin, validMax] = validRange; | ||
| return (val) => val < validMin || val > validMax; | ||
| } | ||
|
|
||
| const fillValue = getFillValue(dataset, attrValuesStore); | ||
| if (fillValue !== undefined) { | ||
| return createIgnoreFillValue(fillValue, dataset.type); | ||
| } | ||
|
|
||
| return undefined; | ||
| }, [dataset, attrValuesStore]); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { floatType, intType } from '@h5web/shared/hdf5-utils'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { createIgnoreFillValue } from './utils'; | ||
|
|
||
| describe('createIgnoreFillValue', () => { | ||
| describe('with integers', () => { | ||
| it('should ignore values greater or equal to positive fill value', () => { | ||
| const ignoreValue = createIgnoreFillValue(10, intType()); | ||
| expect(ignoreValue(9)).toBe(false); | ||
| expect(ignoreValue(10)).toBe(true); | ||
| expect(ignoreValue(11)).toBe(true); | ||
| }); | ||
|
|
||
| it('should ignore values lower or equal to negative fill value', () => { | ||
| const ignoreValue = createIgnoreFillValue(-10, intType()); | ||
| expect(ignoreValue(-9)).toBe(false); | ||
| expect(ignoreValue(-10)).toBe(true); | ||
| expect(ignoreValue(-11)).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with floats', () => { | ||
| it('should ignore values greater than positive fill value', () => { | ||
| const ignoreValue = createIgnoreFillValue(0.3, floatType(64)); | ||
| expect(ignoreValue(0.2)).toBe(false); | ||
| expect(ignoreValue(0.3005)).toBe(true); | ||
| }); | ||
|
|
||
| it('should ignore values close-enough to positive fill value', () => { | ||
| const ignoreValue = createIgnoreFillValue(0.3, floatType(64)); | ||
| expect(ignoreValue(0.3 - 2 * Number.EPSILON)).toBe(false); | ||
| expect(ignoreValue(0.3 - Number.EPSILON)).toBe(true); | ||
| expect(ignoreValue(0.3)).toBe(true); | ||
| expect(ignoreValue(0.3 + Number.EPSILON)).toBe(true); | ||
| expect(ignoreValue(0.3 + 2 * Number.EPSILON)).toBe(true); | ||
| }); | ||
|
|
||
| it('should ignore values lower than negative fill value', () => { | ||
| const ignoreValue = createIgnoreFillValue(-0.3, floatType(64)); | ||
| expect(ignoreValue(-0.2)).toBe(false); | ||
| expect(ignoreValue(-0.3005)).toBe(true); | ||
| }); | ||
|
|
||
| it('should ignore values close-enough to negative fill value', () => { | ||
| const ignoreValue = createIgnoreFillValue(-0.3, floatType(64)); | ||
| expect(ignoreValue(-0.3 + 2 * Number.EPSILON)).toBe(false); | ||
| expect(ignoreValue(-0.3 + Number.EPSILON)).toBe(true); | ||
| expect(ignoreValue(-0.3)).toBe(true); | ||
| expect(ignoreValue(-0.3 - Number.EPSILON)).toBe(true); | ||
| expect(ignoreValue(-0.3 - 2 * Number.EPSILON)).toBe(true); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.