Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/complex-reduce'
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Feb 13, 2020
2 parents b34f9ef + 345a5a0 commit ea33427
Show file tree
Hide file tree
Showing 56 changed files with 996 additions and 186 deletions.
201 changes: 201 additions & 0 deletions docs/s2-evi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
{
"1": {
"process_id": "apply",
"arguments": {
"data": {
"from_node": "mintime"
},
"process": {
"callback": {
"2": {
"process_id": "linear_scale_range",
"arguments": {
"x": {
"from_argument": "x"
},
"inputMin": -1,
"inputMax": 1,
"outputMax": 255
},
"result": true
}
}
}
},
"description": "Stretch range from -1 / 1 to 0 / 255 for PNG visualization."
},
"dc": {
"process_id": "load_collection",
"arguments": {
"id": "COPERNICUS/S2",
"spatial_extent": null,
"temporal_extent": [
"2018-01-01T00:00:00Z",
"2018-01-31T23:59:59Z"
],
"bands": [
"B8",
"B4",
"B2"
]
},
"description": "Loading the data; The order of the specified bands is important for the following reduce operation."
},
"evi": {
"process_id": "reduce",
"arguments": {
"data": {
"from_node": "dc"
},
"reducer": {
"callback": {
"nir": {
"process_id": "array_element",
"arguments": {
"data": {
"from_argument": "data"
},
"index": 0
}
},
"sub": {
"process_id": "subtract",
"arguments": {
"data": [
{
"from_node": "nir"
},
{
"from_node": "red"
}
]
}
},
"div": {
"process_id": "divide",
"arguments": {
"data": [
{
"from_node": "sub"
},
{
"from_node": "sum"
}
]
}
},
"p3": {
"process_id": "product",
"arguments": {
"data": [
2.5,
{
"from_node": "div"
}
]
},
"result": true
},
"sum": {
"process_id": "sum",
"arguments": {
"data": [
1,
{
"from_node": "nir"
},
{
"from_node": "p1"
},
{
"from_node": "p2"
}
]
}
},
"red": {
"process_id": "array_element",
"arguments": {
"data": {
"from_argument": "data"
},
"index": 1
}
},
"p1": {
"process_id": "product",
"arguments": {
"data": [
6,
{
"from_node": "red"
}
]
}
},
"blue": {
"process_id": "array_element",
"arguments": {
"data": {
"from_argument": "data"
},
"index": 2
}
},
"p2": {
"process_id": "product",
"arguments": {
"data": [
-7.5,
{
"from_node": "blue"
}
]
}
}
}
},
"dimension": "bands"
},
"description": "Compute the EVI. Formula: 2.5 * (NIR - RED) / (1 + NIR + 6*RED + -7.5*BLUE)"
},
"mintime": {
"process_id": "reduce",
"arguments": {
"data": {
"from_node": "evi"
},
"reducer": {
"callback": {
"min": {
"process_id": "min",
"arguments": {
"data": {
"from_argument": "data"
}
},
"result": true
}
}
},
"dimension": "temporal"
},
"description": "Compute a minimum time composite by reducing the temporal dimension"
},
"save": {
"process_id": "save_result",
"arguments": {
"data": {
"from_node": "1"
},
"format": "PNG",
"options": {
"red": null,
"green": null,
"blue": null,
"gray": null
}
},
"result": true
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dependencies": {
"@google-cloud/storage": "^3.0.2",
"@google/earthengine": "0.1.185",
"@openeo/js-commons": "^0.4.4",
"@openeo/js-commons": "^0.4.7",
"ajv": "^6.10.0",
"axios": "^0.19.0",
"check-disk-space": "^2.1.0",
Expand Down
10 changes: 3 additions & 7 deletions src/api/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ module.exports = class ServicesAPI {
return Promise.resolve();
}

calculateXYZRect(x, y, z) {
return ee.Geometry.Rectangle(this.storage.calculateXYZRect(x, y, z), 'EPSG:4326');
}

getXYZ(req, res, next) {
var query = {
// Tiles are always public!
Expand All @@ -40,12 +36,12 @@ module.exports = class ServicesAPI {
}

try {
var rect = this.calculateXYZRect(req.params.x, req.params.y, req.params.z);
var rect = this.storage.calculateXYZRect(req.params.x, req.params.y, req.params.z);
var context = this.context.processingContext(req);
// Update user id to the user id, which stored the job. See https://github.com/Open-EO/openeo-earthengine-driver/issues/19
context.setUserId(service.user_id);
var pg = new ProcessGraph(service.process_graph, context);
pg.optimizeLoadCollectionRect(this.storage.calculateXYZRect(req.params.x, req.params.y, req.params.z));
pg.optimizeLoadCollectionRect(rect);
pg.execute()
.then(resultNode => context.retrieveResults(resultNode.getResult(), '256x256', rect))
.then(url => {
Expand All @@ -56,7 +52,7 @@ module.exports = class ServicesAPI {
})
.catch(e => next(Errors.wrap(e)));
} catch(e) {
return next(e);
return next(Errors.wrap(e));
}
});
}
Expand Down
3 changes: 3 additions & 0 deletions src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ for(var name in errors) {
else if (CommonUtils.isObject(obj)) {
args = obj;
}
else if (typeof obj === 'string') {
this.message = obj;
}
this.info = args;
this.message = CommonUtils.replacePlaceholders(this.message, this.info);
};
Expand Down
9 changes: 8 additions & 1 deletion src/models/servicestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ module.exports = class ServiceStore {
var xMax = Math.max(nw_lng, se_lng);
var yMin = Math.min(nw_lat, se_lat);
var yMax = Math.max(nw_lat, se_lat);
return [xMin, yMin, xMax, yMax];

return {
west: xMin,
east: xMax,
south: yMin,
north: yMax,
// crs: 'EPSG:3857'
};
}

};
2 changes: 1 addition & 1 deletion src/processes/absolute.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Commons = require('../processgraph/commons');
module.exports = class absolute extends Process {

async execute(node, context) {
return Commons.applyInCallback(node, image => image.abs(), array => array.abs());
return Commons.applyInCallback(node, image => image.abs());
}

};
2 changes: 1 addition & 1 deletion src/processes/arccos.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Commons = require('../processgraph/commons');
module.exports = class arccos extends Process {

async execute(node, context) {
return Commons.applyInCallback(node, image => image.acos(), array => array.acos());
return Commons.applyInCallback(node, image => image.acos());
}

};
2 changes: 1 addition & 1 deletion src/processes/arcsin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Commons = require('../processgraph/commons');
module.exports = class arcsin extends Process {

async execute(node, context) {
return Commons.applyInCallback(node, image => image.asin(), array => array.asin());
return Commons.applyInCallback(node, image => image.asin());
}

};
2 changes: 1 addition & 1 deletion src/processes/arctan.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Commons = require('../processgraph/commons');
module.exports = class arctan extends Process {

async execute(node, context) {
return Commons.applyInCallback(node, image => image.atan(), array => array.atan());
return Commons.applyInCallback(node, image => image.atan());
}

};
22 changes: 22 additions & 0 deletions src/processes/array_element.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const Process = require('../processgraph/process');
const Errors = require('../errors');

module.exports = class array_element extends Process {

async execute(node, context) {
var data = node.getArgument("data");
var index = node.getArgument("index");
var return_nodata = node.getArgument("return_nodata", false);

if (Array.isArray(data) && typeof data[index] !== 'undefined') {
return data[index];
}
else if (return_nodata) {
return null;
}
else {
throw new Errors.IndexOutOfBounds();
}
}

};
Loading

0 comments on commit ea33427

Please sign in to comment.