Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Feb 25, 2023
1 parent 345f1e2 commit 4beb87a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 23 deletions.
12 changes: 7 additions & 5 deletions geowarp.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ const mode = (nums, no_data) => {
};

// returns [functionCached, clearCache]
const cacheFunction = (f, str = it => it.toString()) => {
let cache = {};
return [xy => (cache[str(xy)] ??= f(xy)), () => (cache = {})];
};
// const cacheFunction = (f, str = it => it.toString()) => {
// let cache = {};
// return [xy => (cache[str(xy)] ??= f(xy)), () => (cache = {})];
// };

const geowarp = function geowarp({
debug_level = 0,
Expand All @@ -113,6 +113,7 @@ const geowarp = function geowarp({
out_width = 256,
out_height = 256,
out_no_data = null,
// out_no_data_strategy = "keep",
method = "median",
read_bands = undefined, // which bands to read, used in conjunction with expr
row_start = 0, // which sample row to start writing with
Expand Down Expand Up @@ -206,6 +207,7 @@ const geowarp = function geowarp({
out_bands ??= read_bands;

if (round && typeof out_no_data === "number") out_no_data = Math.round(out_no_data);
// if (out_no_data === null && out_no_data_strategy === "keep") out_no_data = in_no_data;

// processing step after we have read the raw pixel values
let process;
Expand Down Expand Up @@ -441,7 +443,7 @@ const geowarp = function geowarp({
if (inverse_turbocharged) console.log("[geowarp] turbocharged inverse");
}
const fwd = forward_turbocharged?.reproject || forward;
let inv = inverse_turbocharged?.reproject || inverse;
const inv = inverse_turbocharged?.reproject || inverse;
// const [invCached, clearInvCache] = cacheFunction(inv);

const select = xdim.prepareSelect({ data: in_data, layout: in_layout, sizes: in_sizes });
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"scripts": {
"clean": "rm -fr ./test-data/*.png && rm -fr ./test-output/*.png",
"format": "npx prettier --arrow-parens=avoid --print-width=160 --trailing-comma=none --write *.js *.ts",
"format": "npm run lint -- --fix && npx prettier --arrow-parens=avoid --print-width=160 --trailing-comma=none --write *.js *.ts",
"lint": "npx eslint *.js",
"perf": "TEST_NAME=*perf* LOG_SKIP=false TIME=true node test.js",
"prepublish": "npm run lint",
Expand Down
37 changes: 23 additions & 14 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ const runTileTests = async ({
turbo
});

if (process.env.WRITE) {
writePNGSync({ h: size, w: size, data: result.data, filepath: `./test-output/${testName}` });
}

eq(result.read_bands, out_bands || range(info.depth));

let counts;
Expand All @@ -253,11 +257,14 @@ const runTileTests = async ({
eq(result.data[0].length, size);
eq(result.data[0][0].length, out_bands?.length ?? 3);
counts = count(result.data, { depth: 2 });
const top = Object.entries(counts).sort((a, b) => Math.sign(b - a))[0][0];
const sortedCounts = Object.entries(counts).sort((a, b) => Math.sign(b[1] - a[1]));
const top = sortedCounts[0][0];
if (method !== "first" && !out_bands) {
try {
eq(most_common_pixels.includes(top), true);
} catch (error) {
console.dir(result.data, { depth: 5, maxArrayLength: 5 });
console.log("sortedCounts:", sortedCounts.slice(0, 5), "...");
console.error(top);
throw error;
}
Expand All @@ -280,10 +287,6 @@ const runTileTests = async ({
true
);
}

if (process.env.WRITE) {
writePNGSync({ h: size, w: size, data: result.data, filepath: `./test-data/${testName}` });
}
});
});
});
Expand All @@ -305,7 +308,20 @@ const runTileTests = async ({
filename: "wildfires.tiff",
methods: ["first", "bilinear", "near", "max", "mean", "median", "min", "mode", "mode-mean", "mode-max", "mode-min"],
out_bands_array: [undefined, [0], [2, 1, 0]],
most_common_pixels: ["0,0,0", "11,16,7", "11,16,8", "18,26,11", "18,26,12", "19,27,12", "20,28,13", "21,29,14", "13,18,9", "22,30,17"]
most_common_pixels: [
"0,0,0",
"11,16,7",
"11,16,8",
"17,25,12",
"18,26,11",
"18,26,12",
"19,27,12",
"20,28,13",
"21,29,14",
"13,18,9",
"19,25,13",
"22,30,17"
]
},
{
x: 3853,
Expand Down Expand Up @@ -351,14 +367,7 @@ const runTileTests = async ({
}
].forEach(runTileTests);

[
"bilinear",
"near",
"min",
"max",
"median",
"vectorize"
].forEach(method => {
["bilinear", "near", "min", "max", "median", "vectorize"].forEach(method => {
test(method + " performance", async ({ eq }) => {
const info = await readTile({ x: 3853, y: 6815, z: 14, filename: "SkySat_Freeport_s03_20170831T162740Z3.tif" });

Expand Down
11 changes: 8 additions & 3 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,14 @@ const runTileTests = async ({
eq(result_data[0].length, size);
eq(result_data[0][0].length, out_bands?.length ?? 3);
counts = count(result.data, { depth: 2 });
const top = Object.entries(counts).sort((a, b) => Math.sign(b[1] - a[1]))[0][0];
const sortedCounts = Object.entries(counts).sort((a, b) => Math.sign(b[1] - a[1]));
const top = sortedCounts[0][0];
if (method !== "first" && !out_bands) {
try {
eq(most_common_pixels.includes(top), true);
} catch (error) {
console.error("top:", top);
console.log("sortedCounts:", sortedCounts.slice(0, 5));
console.error("top:", `rgb(${top})`);
throw error;
}
}
Expand Down Expand Up @@ -351,14 +353,17 @@ const runTileTests = async ({
"14,22,9",
"15,23,10",
"16,24,11",
"16,24,13",
"17,25,12",
"17,25,14",
"18,26,11",
"18,26,12",
"18,26,13",
"19,25,13",
"20,23,12",
"22,30,17"
"22,30,17",
"22,30,19",
"42,51,48"
],
turbos: [false, true],
out_resolutions: [
Expand Down

0 comments on commit 4beb87a

Please sign in to comment.