Closed jonathom closed 3 years ago
JavaScript doesn't have named parameters, you just provide parameters by order.
So for example your code var cube_s2_b348_red_lin = builder.apply(data = cube_s2_b348_red, process = scale_);
must be var cube_s2_b348_red_lin = builder.apply(cube_s2_b348_red, scale_);
instead.
It seems you are doing too much R and Python. :-D
alright :), I will change this in the cookbook as well.
@m-mohr One question though: If I can't name parameters, how can I skip a parameter that I don't need to pass. E.g. in array_element
, where I can choose to pass either an index or a label?
(I am aware that there are easier ways to accomplish the overall task here)
You can pass undefined
, i.e. b8 = this.array_element(data, undefined, "B08")
. Not very nice though and therefore array_element has a nice simplification for that, you can basically do the following instead:
b4 = data[0]
b8 = data["B08"]
It detects the data type (integer = index, string = label) and converts it correctly into array_element calls.
See also: https://open-eo.github.io/openeo-js-client/1.3.1/Parameter.html
So your code could be shortened to:
var _ndvi = (data, _, child) => child.normalized_difference(data[0], data["B08"]);
or
var _ndvi = function(data) {
return this.normalized_difference(data[0], data["B08"]);
}
great, thanks! VITO backend throws an error (when doing the above) cause it expects a number for some reason, but that's their thing.
Anyway, how's this for a bandmath definition? Or is it generally done differently?
Maybe this is the place for using Formula
? Is there a way that should be preferred over the other?
Yes, that's a good place for using "Formula". For everything where you compute on a single number (i.e. not an array of numbers), Formula is probably the best choice.
I noticed some behaviour that I can't quite explain when executing a .js script. See this gist with the code I'm referring to.
,process = scale_
as such. If I only put, scale_
, not mentioning the name, the script runs without error.reducer = ...
anddimension = 't'
in line 32, the script fails to execute.Can't make any sense of it. EDIT: using authenticateBasic, deleted login for upload