Skip to content

Commit

Permalink
Merge pull request #36 from Open-EO/development
Browse files Browse the repository at this point in the history
Release v1.0.0-rc.5
  • Loading branch information
m-mohr authored Oct 30, 2020
2 parents 38d7e5b + fb68b90 commit f2d7779
Show file tree
Hide file tree
Showing 34 changed files with 2,914 additions and 233 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ node_modules/
/openeo.min.js
/openeo.node.js
/openeo.node.min.js
types/

# Reports
coverage/
Expand Down
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ cache:
script:
# Run code checks
- npm run lint
# Build once to check it's all working
- npm run build
# Run tests
- npm run test
- npm run test_node
Expand Down
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

JavaScript/TypeScript client for the openEO API.

* [Documentation](https://open-eo.github.io/openeo-js-client/1.0.0-rc.4/).
* [Documentation](https://open-eo.github.io/openeo-js-client/1.0.0-rc.5/).

The version of this client is **1.0.0-rc.4** and supports **openEO API versions 1.0.x**. Legacy versions are available as releases.
The version of this client is **1.0.0-rc.5** and supports **openEO API versions 1.0.x**. Legacy versions are available as releases.

## Usage

Expand Down Expand Up @@ -41,16 +41,26 @@ Afterwards, you can import the package:

### Examples

* [Basic Discovery (promises)](examples/discovery.html)
* [Run sync. job (async/await)](examples/workflow.html)
In the browser:
* [Basic Discovery (promises)](examples/web/discovery.html)
* [Run sync. job (async/await)](examples/web/workflow.html)

More information can be found in the [documentation](https://open-eo.github.io/openeo-js-client/1.0.0-rc.4/).
In Node.js:
* [Basic Discovery (promises)](examples/node/discovery.js)

In Typescript:
* [Basic Discovery (promises)](examples/typescript/discovery.ts)

More information can be found in the [documentation](https://open-eo.github.io/openeo-js-client/1.0.0-rc.5/).

## Development

[![Build Status](https://travis-ci.org/Open-EO/openeo-js-client.svg?branch=master)](https://travis-ci.org/Open-EO/openeo-js-client)

Generate a build: `npm run build` (generates `openeo.js`, `openeo.min.js` and `openeo.d.ts`)
Always make sure to adapt changes in the *.js files to the openeo.d.ts file.
If changes are larger you may want to run `npm run tsd` and regenerate the declaration file and cherry-pick your changes from there.

Generate a build: `npm run build` (generates `openeo.js` and `openeo.min.js`)

Generate the documentation to the `docs/` folder: `npm run docs`

Expand Down
27 changes: 27 additions & 0 deletions examples/node/discovery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Import the JS client
const { OpenEO } = require('@openeo/js-client');

var url = "https://earthengine.openeo.org"; // Insert the openEO server URL here
var connection = null;

console.log('URL: ' + url);
console.log('Client Version: ' + OpenEO.clientVersion());

OpenEO.connect(url)
.then(c => {
connection = c;
return connection.capabilities();
})
.then(capabilities => {
console.log('Server Version: ' + capabilities.apiVersion());
return connection.listCollections();
})
.then(collections => {
console.log('Number of supported collections: ' + collections.collections.length);
return connection.listProcesses();
})
.then(processes => {
console.log('Number of supported processes: ' + processes.processes.length);
return;
})
.catch(err => console.error(err.message));
30 changes: 30 additions & 0 deletions examples/node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@openeo/js-client-example-node",
"version": "0.1.0",
"author": "openEO Consortium",
"contributors": [
{
"name": "Christoph Friedrich"
},
{
"name": "Matthias Mohr"
}
],
"description": "Example showcasing the usage of the openEO JavaScript client in Node.js",
"license": "Apache-2.0",
"homepage": "http://openeo.org",
"bugs": {
"url": "https://github.com/Open-EO/openeo-js-client/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/Open-EO/openeo-js-client.git"
},
"main": "discovery.js",
"dependencies": {
"@openeo/js-client": "1.0.0-rc.5"
},
"scripts": {
"start": "node discovery.js"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/axios@0.19/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/oidc-client@1/dist/oidc-client.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@openeo/js-client@1.0.0-rc.4/openeo.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@openeo/js-client@1.0.0-rc.5/openeo.min.js"></script>
<script type="text/javascript">
const BACKEND = "https://example.openeo.org"; // TODO: Set the back-end to authenticate against
const CLIENT_ID = ""; // TODO: Set the client id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/axios@0.19/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/oidc-client@1/dist/oidc-client.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@openeo/js-client@1.0.0-rc.4/openeo.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@openeo/js-client@1.0.0-rc.5/openeo.min.js"></script>
<script type="text/javascript">
const BACKEND = "https://example.openeo.org"; // TODO: Set the back-end to authenticate against
const CLIENT_ID = ""; // TODO: Set the client id
Expand Down
2 changes: 2 additions & 0 deletions examples/typescript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
discovery.js
package-lock.json
28 changes: 28 additions & 0 deletions examples/typescript/discovery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// import the JS client main part (OpenEO) for the actual functionality
// and some classes (Connection, Capabilities) and types (Collections, Processes) for TypeScript stuff
import { OpenEO, Connection, Capabilities, Collections, Processes } from '@openeo/js-client';

let url: string = "https://earthengine.openeo.org"; // Insert the openEO server URL here
let connection: Connection = null; // Reserve a variable for the connection and specify its type

console.log('URL: ' + url);
console.log('Client Version: ' + OpenEO.clientVersion());

OpenEO.connect(url)
.then((c: Connection): Capabilities => { // specify parameter type and return type
connection = c;
return connection.capabilities();
})
.then((capabilities: Capabilities): Promise<Collections> => { // as before, note the `Promise<>` generic
console.log('Server Version: ' + capabilities.apiVersion());
return connection.listCollections();
})
.then((collections: Collections): Promise<Processes> => { // note that `Promise<Collections>` has become `Collections`
console.log('Number of supported collections: ' + collections.collections.length);
return connection.listProcesses();
})
.then((processes: Processes): void => { // final callback in chain doesn't return anything
console.log('Number of supported processes: ' + processes.processes.length);
return;
})
.catch((err: Error) => console.error(err.message));
32 changes: 32 additions & 0 deletions examples/typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@openeo/js-client-example-typescript",
"version": "0.1.0",
"author": "openEO Consortium",
"contributors": [
{
"name": "Christoph Friedrich"
},
{
"name": "Matthias Mohr"
}
],
"description": "Example showcasing the usage of the openEO JavaScript client in Typescript",
"license": "Apache-2.0",
"homepage": "http://openeo.org",
"bugs": {
"url": "https://github.com/Open-EO/openeo-js-client/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/Open-EO/openeo-js-client.git"
},
"main": "discovery.ts",
"dependencies": {
"@openeo/js-client": "1.0.0-rc.5",
"typescript": "^4.0.5"
},
"scripts": {
"build": "tsc discovery.ts",
"start": "node discovery.js"
}
}
2 changes: 1 addition & 1 deletion examples/discovery.html → examples/web/discovery.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/axios@0.19/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@openeo/js-client@1.0.0-rc.4/openeo.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@openeo/js-client@1.0.0-rc.5/openeo.min.js"></script>
<script type="text/javascript">
var url = "https://earthengine.openeo.org"; // Insert the openEO server URL here
var connection = null;
Expand Down
33 changes: 17 additions & 16 deletions examples/workflow.html → examples/web/workflow.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/axios@0.19/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@openeo/js-client@1.0.0-rc.4/openeo.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@openeo/js-client@1.0.0-rc.5/openeo.min.js"></script>
<script type="text/javascript">
async function run() {
// Show the client version
Expand Down Expand Up @@ -47,16 +47,19 @@
// Write an algorithm / process to run
var builder = await con.buildProcess();

// Simplified geometry of central Münster (Germany)
var msGeometry = {"type":"Polygon","coordinates":[[[7.637799974419459,52.01332193589061],[7.62398169352488,52.00969307661495],[7.619823829597119,52.00158245346181],[7.590738404820496,52.00730662092496],[7.563811834154673,52.001308616165645],[7.573636346303766,51.992180777860874],[7.569855884060181,51.98545643508868],[7.543540879611669,51.96991821995572],[7.577623151858387,51.93997003636344],[7.559435909709811,51.931123434089656],[7.556625867211423,51.92504156203243],[7.564681636267283,51.9188162156423],[7.577387619476905,51.9233317429785],[7.588347839936553,51.918646814268996],[7.595284932021921,51.92479589461621],[7.621031519108772,51.917243800385535],[7.656038175955233,51.91943727698611],[7.67194795756578,51.92238830466648],[7.686556925502693,51.9290516727655],[7.690291911499357,51.93671875429201],[7.699225443980613,51.936707107569255],[7.687961904959071,51.94731673700126],[7.675211564663383,51.94964649247447],[7.678202838213879,51.976670456099136],[7.667564910410129,51.97853371878003],[7.660981470643656,51.98621447362924],[7.660952980726099,52.00839143191412],[7.652037968822863,52.01317315906101],[7.637799974419459,52.01332193589061]]]};

var datacube = builder.load_collection(
"COPERNICUS/S2",
{ "west": 16.1, "east": 16.6, "north": 48.6, "south": 47.2 },
["2018-01-01", "2018-02-01"],
"COPERNICUS/S2_SR",
msGeometry,
["2019-06-23", "2019-06-30"],
["B2", "B4", "B8"]
);

// Alternatively you can also use the shorter variant:
// var eviAlgorithm = new Formula('2.5 * (($1 - $2) / (1 + $1 + 6 * $2 + -7.5 * $3))');
var eviAlgorithm = function(data) {
var eviAlgorithm = new Formula('2.5 * (($B2 - $B4) / (1 + $B2 + 6 * $B4 + -7.5 * $B8))');
// The formula is the equivalent to this code:
/* var eviAlgorithm = function(data) {
var nir = data[2];
var red = data[1];
var blue = data[0];
Expand All @@ -72,27 +75,26 @@
])
)
);
};
}; */
datacube = builder.reduce_dimension(datacube, eviAlgorithm, "bands")
.description("Compute the EVI. Formula: 2.5 * (NIR - RED) / (1 + NIR + 6*RED + -7.5*BLUE)");

var min = function(data) { return this.min(data); };
datacube = builder.reduce_dimension(datacube, min, "t");
var reducer = function(data) { return this.max(data); };
datacube = builder.reduce_dimension(datacube, reducer, "t");

var scale = function(x) { return this.linear_scale_range(x, -1, 1, 0, 255); };
var scale = function(x) { return this.linear_scale_range(x, -1, 1, 0, 255); }; // Use -0.5 instead of -1 for more contrast
datacube = builder.apply(datacube, scale);

datacube = builder.save_result(datacube, "PNG");

// Request a preview synchronously for the process
if (syncSupport) {
log("Running process...");
// This returns an object containing a binary PNG file in the data property you could further process or show.
var preview = await con.computeResult(datacube);

// Show image in browser
var objectURL = URL.createObjectURL(preview.data);
document.getElementById('image').src = objectURL;
// This returns an object containing a binary PNG file in the data property you could further process or show.
// Show image in the browser
log('<img src="' + URL.createObjectURL(preview.data) + '" />');
}
} catch (e) {
log("Error: " + e.message);
Expand All @@ -106,7 +108,6 @@

<body onload="run()">
<code id="console"></code>
<img id="image" />
</body>

</html>
Loading

0 comments on commit f2d7779

Please sign in to comment.