forked from yocontra/node-gdal-next
-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathopen_hdf5.test.ts
62 lines (51 loc) · 1.67 KB
/
open_hdf5.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import * as gdal from 'gdal-async'
import * as path from 'path'
import { assert } from 'chai'
describe('Open', () => {
afterEach(() => void global.gc!())
describe('HDF5', () => {
let filename, ds: gdal.Dataset
it('should not throw', () => {
filename = path.join(__dirname, 'data/h5ex_t_array.h5')
ds = gdal.open(filename)
})
it('should be able to read raster size', () => {
assert.equal(ds.rasterSize.x, 512)
assert.equal(ds.rasterSize.y, 512)
assert.equal(ds.bands.count(), 0)
})
it('should not have projection', () => {
assert.isNull(ds.srs)
})
})
describe('HDF5/gzip', () => {
let filename, ds: gdal.Dataset
it('should not throw', () => {
filename = path.join(__dirname, 'data/h5ex_d_gzip.h5')
ds = gdal.open(filename)
})
it('should be able to read raster size', () => {
assert.equal(ds.rasterSize.x, 64)
assert.equal(ds.rasterSize.y, 32)
assert.equal(ds.bands.count(), 1)
})
it('should not have projection', () => {
assert.isNull(ds.srs)
})
it('should be able to read statistics', () => {
const band = ds.bands.get(1)
const expected_stats = {
min: -63,
max: 1890,
mean: 456.75,
std_dev: 430.61431409093
}
const actual_stats = band.getStatistics(false, true) as typeof expected_stats
const delta = 0.00001
assert.closeTo(expected_stats.min, actual_stats.min, delta)
assert.closeTo(expected_stats.max, actual_stats.max, delta)
assert.closeTo(expected_stats.mean, actual_stats.mean, delta)
assert.closeTo(expected_stats.std_dev, actual_stats.std_dev, delta)
})
})
})