Skip to content

Commit 42d3f20

Browse files
authored
Merge pull request #53 from carbonplan/katamartin/equally-spaced-validation
Add validation check that proxied datasets have equally spaced spatial coordinates
2 parents 78c3ad7 + 912bed5 commit 42d3f20

3 files changed

Lines changed: 49 additions & 5 deletions

File tree

components/utils/data.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
// LZ4,
99
// Zstd,
1010
} from 'numcodecs'
11-
11+
import { deviation } from 'd3-array'
1212
import { PROJECTIONS, ASPECTS } from '../constants'
1313

1414
const COMPRESSORS = {
@@ -270,6 +270,21 @@ export const getVariableLevelInfo = async (
270270
const axes = ['X', 'Y'].reduce((accum, key, i) => {
271271
const index = dimensions.indexOf(cfAxes[name][key])
272272
const array = coordinates[i]
273+
if (!pyramid) {
274+
const stepValues = array.data.reduce((a, d, i) => {
275+
if (i === 0) return a
276+
const delta = d - array.data[i - 1]
277+
a.add(delta)
278+
return a
279+
}, new Set())
280+
const stepDeviation = deviation(stepValues)
281+
if (stepDeviation && stepDeviation > 1e-3) {
282+
throw new Error(
283+
`Cannot handle coordinate: ${cfAxes[name][key]}. Spatial coordinates must be equally spaced.`
284+
)
285+
}
286+
}
287+
273288
const step = Math.abs(Number(array.data[0]) - Number(array.data[1]))
274289
const reversed = array.data[0] > array.data[array.data.length - 1]
275290

package-lock.json

Lines changed: 32 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@mdx-js/react": "^2.1.5",
3636
"@next/mdx": "^12.3.1",
3737
"@theme-ui/color": "^0.15.3",
38+
"d3-array": "^3.1.0",
3839
"d3-format": "^3.1.0",
3940
"d3-geo": "^3.1.0",
4041
"d3-scale": "^3.1.0",

0 commit comments

Comments
 (0)