Skip to content

Commit

Permalink
Merge pull request #227 from GeoTIFF/refactor-stats
Browse files Browse the repository at this point in the history
Refactored stats
  • Loading branch information
DanielJDufour committed Dec 17, 2023
2 parents 1338a3e + 6c35a01 commit bfd42ae
Show file tree
Hide file tree
Showing 53 changed files with 194 additions and 139 deletions.
2 changes: 1 addition & 1 deletion lite/band-arithmetic.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from "../src/band-arithmetic";
export { default } from "../src/band-arithmetic";
2 changes: 1 addition & 1 deletion lite/cache.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from "../src/cache";
export { default } from "../src/cache";
2 changes: 1 addition & 1 deletion lite/get.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from "../src/get";
export { default } from "../src/get";
2 changes: 1 addition & 1 deletion lite/histogram.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from "../src/histogram/histogram.core";
export { default } from "../src/histogram/histogram.core";
2 changes: 1 addition & 1 deletion lite/identify.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from "../src/identify/identify.core";
export { default } from "../src/identify/identify.core";
2 changes: 1 addition & 1 deletion lite/load.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from "../src/load";
export { default } from "../src/load";
6 changes: 5 additions & 1 deletion lite/max.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export { default } from "../src/max/max.core";
import stat from "./stat";

export default function max(georaster, geometry, test) {
return stat(georaster, geometry, "max", test);
}
6 changes: 5 additions & 1 deletion lite/mean.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export { default } from "../src/mean/mean.core";
import stat from "./stat";

export default function mean(georaster, geometry, test) {
return stat(georaster, geometry, "mean", test);
}
6 changes: 5 additions & 1 deletion lite/median.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export { default } from "../src/median/median.core";
import stat from "./stat";

export default function median(georaster, geometry, test) {
return stat(georaster, geometry, "median", test);
}
6 changes: 5 additions & 1 deletion lite/min.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export { default } from "../src/min/min.core";
import stat from "./stat";

export default function min(georaster, geometry, test) {
return stat(georaster, geometry, "min", test);
}
6 changes: 5 additions & 1 deletion lite/mode.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export { default } from "../src/mode/mode.core";
import stat from "./stat";

export default function mode(georaster, geometry, test) {
return stat(georaster, geometry, "mode", test);
}
6 changes: 5 additions & 1 deletion lite/modes.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export { default } from "../src/modes/modes.core";
import stat from "./stat";

export default function modes(georaster, geometry, test) {
return stat(georaster, geometry, "modes", test);
}
2 changes: 1 addition & 1 deletion lite/parse.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from "../src/parse";
export { default } from "../src/parse";
2 changes: 1 addition & 1 deletion lite/raster-calculator.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from "../src/raster-calculator";
export { default } from "../src/raster-calculator";
6 changes: 6 additions & 0 deletions lite/stat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import QuickPromise from "quick-promise";
import stats from "./stats";

export default function stat(georaster, geometry, stat, test) {
return QuickPromise.resolve(stats(georaster, geometry, { stats: [stat] }, test)).then(stats => stats.map(it => it[stat]));
}
2 changes: 1 addition & 1 deletion lite/stats.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from "../src/stats/stats.core";
export { default } from "../src/stats/stats.core";
6 changes: 5 additions & 1 deletion lite/sum.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export { default } from "../src/sum/sum.core";
import stat from "./stat";

export default function sum(georaster, geometry, test) {
return stat(georaster, geometry, "sum", test);
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"dev": "webpack --mode development --target node --watch",
"document": "npx documentation build src/** --config documentation.yml -f html -o docs && echo 'docs.geoblaze.io' > docs/CNAME",
"fix": "eslint lite --fix && eslint src --fix",
"format": "npx prettier --arrow-parens=avoid --print-width=160 --trailing-comma=none --write src/*.js src/*/*.js",
"format": "npx prettier --arrow-parens=avoid --print-width=160 --trailing-comma=none --write lite/*.js src/*.js src/*/*.js ",
"lint": "eslint lite && eslint src",
"serve": "npx srvd --debug --port=3000 --wait=120",
"test": "set -e; for f in src/*/*test*.js; do echo \"\nrunning $f\" && sleep 5 && node -r esm $f; done",
Expand Down Expand Up @@ -77,7 +77,6 @@
"proj4": "^2.9.0",
"proj4-fully-loaded": "^0.2.0",
"quick-promise": "^0.1.0",
"quick-resolve": "^0.0.1",
"reproject-bbox": "^0.12.0",
"reproject-geojson": "^0.5.0",
"snap-bbox": "^0.5.0",
Expand Down
9 changes: 4 additions & 5 deletions src/histogram/histogram.core.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import _ from "underscore";
import fastMin from "fast-min";
import fastMax from "fast-max";
import QuickPromise from "quick-promise";

import get from "../get";
import utils from "../utils";
import wrap from "../wrap-parse";
import { convertBbox, convertMultiPolygon } from "../convert-geometry";
import intersectPolygon from "../intersect-polygon";

const { resolve } = utils;

const getEqualIntervalBins = (values, numClasses) => {
// get min and max values
const minValue = fastMin(values);
Expand Down Expand Up @@ -152,14 +151,14 @@ const getHistogramsForRaster = (georaster, geom, options) => {
if (geom === null || geom === undefined) {
const flat = true;
const values = get(georaster, null, flat);
return resolve(values).then(calc);
return QuickPromise.resolve(values).then(calc);
} else if (utils.isBbox(geom)) {
geom = convertBbox(geom);

// grab array of values by band
const flat = true;
const values = get(georaster, geom, flat);
return resolve(values).then(calc);
return QuickPromise.resolve(values).then(calc);
} else if (utils.isPolygonal(geom)) {
geom = convertMultiPolygon(geom);
const { noDataValue } = georaster;
Expand All @@ -174,7 +173,7 @@ const getHistogramsForRaster = (georaster, geom, options) => {
}
});

return resolve(done).then(() => values.map(band => band.filter(value => value !== noDataValue)).map(band => getHistogram(band, options)));
return QuickPromise.resolve(done).then(() => values.map(band => band.filter(value => value !== noDataValue)).map(band => getHistogram(band, options)));
} else {
throw "Only Bounding Box and Polygon geometries are currently supported.";
}
Expand Down
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import median from "./median";
import min from "./min";
import mode from "./mode";
import parse from "./parse";
import range from "./range";
import rasterCalculator from "./raster-calculator";
import sum from "./sum";
import stat from "./stat";
import stats from "./stats";

const geoblaze = {
Expand All @@ -27,9 +29,11 @@ const geoblaze = {
min,
mode,
parse,
range,
rasterCalculator,
sum,
stats
stat,
stats,
sum
};

export default geoblaze;
Expand Down
7 changes: 6 additions & 1 deletion src/max/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import stat from "../stat";

/**
* The max function takes a georaster and an optional geometry.
* If a geometry is included, the function returns the max of all the pixels
Expand All @@ -15,4 +17,7 @@
* // maxs is [red, green, blue, nir]
* [231, 242, 254, 255]
*/
export { default } from "./max.module";

export default function max(georaster, geometry, test) {
return stat(georaster, geometry, "max", test);
}
6 changes: 0 additions & 6 deletions src/max/max.core.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/max/max.module.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/max/max.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import test from "flug";
import reprojectBoundingBox from "reproject-bbox";
import { serve } from "srvd";
import load from "../load";
import max from "./max.core";
import max from ".";

serve({ debug: true, max: 1, port: 3000 });

Expand Down
7 changes: 6 additions & 1 deletion src/mean/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import stat from "../stat";

/**
* The mean function takes a georaster and an optional geometry.
* If a geometry is included, the function returns the mean of all the pixels
Expand All @@ -15,4 +17,7 @@
* // means is [red, green, blue, nir]
* [42, 84, 92, 94]
*/
export { default } from "./mean.module";

export default function mean(georaster, geometry, test) {
return stat(georaster, geometry, "mean", test);
}
6 changes: 0 additions & 6 deletions src/mean/mean.core.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/mean/mean.module.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/mean/mean.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readFileSync } from "fs";
import test from "flug";
import { serve } from "srvd";
import load from "../load";
import mean from "./mean.module";
import mean from ".";
import utils from "../utils";

serve({ debug: true, max: 2, port: 3000 });
Expand Down
7 changes: 6 additions & 1 deletion src/median/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import stat from "../stat";

/**
* The median function takes a raster and an optional geometry.
* If a geometry is included, the function returns the median of all the pixels
Expand All @@ -15,4 +17,7 @@
* // medians is [red, green, blue, nir]
* [42, 84, 92, 94]
*/
export { default } from "./median.module";

export default function median(georaster, geometry, test) {
return stat(georaster, geometry, "median", test);
}
6 changes: 0 additions & 6 deletions src/median/median.core.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/median/median.module.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/median/median.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readFileSync } from "fs";
import test from "flug";
import { serve } from "srvd";
import load from "../load";
import median from "./median.module";
import median from ".";

serve({ debug: true, max: 1, port: 3000 });

Expand Down
7 changes: 6 additions & 1 deletion src/min/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import stat from "../stat";

/**
* The min function takes a georaster as an input and an optional geometry.
* If a geometry is included, the function returns the min of all the pixels
Expand All @@ -15,4 +17,7 @@
* // mins is [red, green, blue, nir]
* [1, 4, 9, 4]
*/
export { default } from "./min.module";

export default function min(georaster, geometry, test) {
return stat(georaster, geometry, "min", test);
}
6 changes: 0 additions & 6 deletions src/min/min.core.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/min/min.module.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/min/min.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from "flug";
import { serve } from "srvd";
import load from "../load";
import min from "./min.module";
import min from ".";

serve({ debug: true, max: 1, port: 3000 });

Expand Down
7 changes: 6 additions & 1 deletion src/mode/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import stat from "../stat";

/**
* The mode function takes a georaster and an optional geometry.
* If a geometry is included, the function returns the mode of all the pixels
Expand All @@ -16,4 +18,7 @@
* // results is [red, green, blue, nir]
* [42, 84, 92, 94]
*/
export { default } from "./mode.module";

export default function mode(georaster, geometry, test) {
return stat(georaster, geometry, "mode", test);
}
6 changes: 0 additions & 6 deletions src/mode/mode.core.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/mode/mode.module.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/mode/mode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readFileSync } from "fs";
import test from "flug";
import { serve } from "srvd";
import load from "../load";
import mode from "./mode.module";
import mode from ".";

serve({ debug: true, max: 1, port: 3000 });

Expand Down
6 changes: 5 additions & 1 deletion src/modes/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import stat from "../stat";

/**
* The modes function takes a georaster and an optional geometry.
* If a geometry is included, the function returns the modes of all the pixels
Expand All @@ -17,4 +19,6 @@
* [[ 42, 43] , [83, 82, 84], [92], [94]]
*/

export { default } from "./modes.module";
export default function modes(georaster, geometry, test) {
return stat(georaster, geometry, "modes", test);
}
6 changes: 0 additions & 6 deletions src/modes/modes.core.js

This file was deleted.

Loading

0 comments on commit bfd42ae

Please sign in to comment.