Skip to content

Commit 3df451e

Browse files
committed
added test
1 parent ecf2b04 commit 3df451e

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ dist
104104
.tern-port
105105

106106
# Data files
107+
*.TIF
108+
*.TIFF
107109
*.tif
108110
*.tiff
109111
*.xml

Diff for: test/data/setup.sh

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ gdal_edit.py -stats stats.tiff
1111

1212
wget "https://landsat-pds.s3.amazonaws.com/L8/012/031/LC80120312013106LGN01/LC80120312013106LGN01_B6.TIF" -O LC80120312013106LGN01_B6.tif
1313

14+
wget "https://landsat-pds.s3.amazonaws.com/c1/L8/024/030/LC08_L1TP_024030_20180723_20180731_01_T1/LC08_L1TP_024030_20180723_20180731_01_T1_B1.TIF" -O LC08_L1TP_024030_20180723_20180731_01_T1_B1.TIF
15+
1416
# download Global Human Settlement Layer
1517
wget wget http://cidportal.jrc.ec.europa.eu/ftp/jrc-opendata/GHSL/GHS_POP_MT_GLOBE_R2019A/GHS_POP_E2015_GLOBE_R2019A_54009_250/V1-0/GHS_POP_E2015_GLOBE_R2019A_54009_250_V1_0.zip
1618
unzip GHS_POP_E2015_GLOBE_R2019A_54009_250_V1_0_8_4.zip

Diff for: test/test.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ const SECONDS_TO_MILLISECONDS = 1000;
77

88
async function getStatsFromFilepath(filepath, debug=false) {
99
const data = readFileSync(filepath);
10+
11+
if (data.byteLength === 0) {
12+
throw new Error("This file has 0 bytes: " + filepath);
13+
}
14+
1015
const arrayBuffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
1116
const geotiff = await fromArrayBuffer(arrayBuffer);
1217
const image = await geotiff.getImage();
@@ -42,12 +47,22 @@ describe("GeoTIFF.js Test Data", function() {
4247
});
4348

4449
describe("Landsat Data", function() {
45-
it('should get stats for downloaded Landsat Scene', async function() {
50+
it('should get stats for old downloaded Landsat Scene', async function() {
4651
this.timeout(20 * SECONDS_TO_MILLISECONDS);
47-
const { bands } = await getStatsFromFilepath('./test/data/LC80120312013106LGN01_B6.tif');
52+
const debug = false;
53+
const { bands } = await getStatsFromFilepath('./test/data/LC80120312013106LGN01_B6.tif', debug);
4854
expect(bands[0].min).to.equal(0);
4955
expect(bands[0].max).to.equal(62196);
5056
});
57+
it('should get stats for newer downloaded Landsat Scene', async function() {
58+
this.timeout(20 * SECONDS_TO_MILLISECONDS);
59+
const debug = false;
60+
const { bands } = await getStatsFromFilepath('./test/data/LC08_L1TP_024030_20180723_20180731_01_T1_B1.TIF', debug);
61+
expect(bands[0].min).to.equal(0);
62+
// this gives different results than GDAL, but is consistent with rasterio
63+
// import rasterio; rasterio.open("./test/data/LC08_L1TP_024030_20180723_20180731_01_T1_B1.TIF").read()[0].max()
64+
expect(bands[0].max).to.equal(54590);
65+
});
5166
it('should get stats for online Landsat Scene with overview file', async function() {
5267
this.timeout(20 * SECONDS_TO_MILLISECONDS);
5368
const debug = false;

0 commit comments

Comments
 (0)