-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from lopezvoliver/run
Run GEE scripts in vscode! and performance improvement
- Loading branch information
Showing
24 changed files
with
869 additions
and
315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
0
eetasks-default.png → docs/assets/eetasks-default.png
100755 → 100644
File renamed without changes
0
eetasks-multi.png → docs/assets/eetasks-multi.png
100755 → 100644
File renamed without changes
0
eetasks-readme.gif → docs/assets/eetasks-readme.gif
100755 → 100644
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# Run GEE scripts from vscode! | ||
|
||
## Hello world | ||
|
||
Use the `EE Tasks: run GEE script` command to run the GEE script open in the Editor using a user account/project. For example: | ||
|
||
![hellogee](https://raw.githubusercontent.com/gee-community/eetasks/main/docs/assets/helloGEE.PNG) | ||
|
||
|
||
> The `EE Tasks: run GEE script (service account)` is also available to run scripts using a valid private key (JSON file). | ||
upon picking an available account (and project, if required), the script is started. If successful, the output will open in a channel called "EE Tasks: GEE script runs": | ||
|
||
![hellogee-log](https://raw.githubusercontent.com/gee-community/eetasks/main/docs/assets/helloGEE-log.png) | ||
|
||
## GEE script definition | ||
|
||
For the purpose of this document, a "GEE script" is a `.js` file that is able to run in the [Earth Engine Code Editor](https://developers.google.com/earth-engine/guides/playground). | ||
|
||
> ❗ Not all GEE scripts can be run here. More details will be given below. | ||
How does the [hello-world](#hello-world) example above work? Evidently, running the same script directly in [node](https://nodejs.org/en/) will not work: | ||
|
||
```bash | ||
$ node helloGEE.js | ||
C:\Users\lopezom\helloGEE.js:1 | ||
ee.String("Hello world!") | ||
^ | ||
|
||
ReferenceError: ee is not defined | ||
``` | ||
|
||
Internally, the EE Tasks extension wraps your code in a function that handles the initialization of ee, as well as providing *some* of the extra features in the [Earth Engine Code Editor](https://developers.google.com/earth-engine/guides/playground), including [print](https://developers.google.com/earth-engine/apidocs/print) and `Export` (e.g. [Export.table.toDrive](https://developers.google.com/earth-engine/apidocs/export-table-todrive)). See more details of what features are [included](#features) and which ones are [excluded](#excluded-features). | ||
|
||
|
||
## Use cases | ||
|
||
Why would I want to run a GEE script in vscode? Short answer: [just because I can](https://i.kym-cdn.com/entries/icons/original/000/040/653/goldblum-quote.jpeg). Kidding aside, the goal here is to provide a quick way for developers to test short, simple code, and to submit Export tasks without leaving vscode. | ||
|
||
> ❗ Use of `EE Tasks: run GEE script` is experimental and recommended for experienced GEE developers only. Not following [GEE coding best practices](https://developers.google.com/earth-engine/guides/best_practices) might lead to the extension crashing (e.g. the equivalent of [browser lock](https://developers.google.com/earth-engine/guides/debugging#browser-lock)). However, it's not the end of world, as a simple "Reload window" should get the extension running back to normal. | ||
However, simple client-side errors will be catched: | ||
|
||
![hellogee-log](https://raw.githubusercontent.com/gee-community/eetasks/main/docs/assets/helloGEE-syntaxError.png) | ||
|
||
> ❗ See another [caveat for Windows users here](#caveat-for-windows-users). | ||
## Not recommended use cases | ||
|
||
Outside of the specific use-cases defined above, **it is not recommended to run GEE scripts using the EE Tasks extension**. The [Code Editor](https://code.earthengine.google.com) or [geemap](https://geemap.org) are definitely the right tools for exploratory analyses, debugging, etc. | ||
|
||
## Features | ||
|
||
### `print` | ||
|
||
`print` somewhat mirrors the functionality of [print](https://developers.google.com/earth-engine/apidocs/print) in the Code Editor: | ||
|
||
> ⚠️ An important difference is that when objects that have a `getInfo` get printed, the operation is performed asynchronously, so the order is not guaranteed ❗ | ||
![ExportTableSuccessFail](https://raw.githubusercontent.com/gee-community/eetasks/main/docs/assets/print.png) | ||
|
||
> ⚠️ In windows, do not use the `.getInfo` methods directly. [Here's why](#caveat-for-windows-users). In linux, this shouldn't be an issue. | ||
### `Export` | ||
|
||
All `Export` features mirror the functionality from the [Code Editor](https://developers.google.com/earth-engine/guides/debugging#browser-lock) (in fact, they [wrap](https://github.com/gee-community/eetasks/blob/main/src/utilities/codeEditorUtils.js) the `ee.batch.Export*` methods). However, | ||
|
||
> ⚠️ In contrast to the Code Editor, tasks will be automatically submitted. | ||
For example: | ||
|
||
![ExportTableSuccessFail](https://raw.githubusercontent.com/gee-community/eetasks/main/docs/assets/ExportTableSuccessAndFail.png) | ||
|
||
> ⚠️ Another contrast to the Code Editor can be seen in the example above. Some parameters such as `description`, `fileNamePrefix`, `assetId`, etc. are either given default values (e.g. "myExportTableTask") in the Code Editor, or are prompted from the user after clicking "Run". Here, the task fails to start if they are not provided explicitly. | ||
We can then use the `EE Tasks: view` command to monitor the task: | ||
|
||
![ExportTableTaskCompleted](https://raw.githubusercontent.com/gee-community/eetasks/main/docs/assets/ExportTableTaskCompleted.png) | ||
|
||
We can see that the task completed, demonstrating task submission *and* monitoring from vscode! | ||
|
||
## Excluded features | ||
|
||
### `Map`, `Chart`, and `ui` | ||
|
||
These are not supported here. However, lines of code using these features are silently ignored, so there is no need to exclude them: | ||
|
||
![silentlyIgnored](https://raw.githubusercontent.com/gee-community/eetasks/main/docs/assets/silentlyIgnored.png) | ||
|
||
Support for `Chart` and `Map` *may* be developed in the future. | ||
|
||
### [require](https://developers.google.com/earth-engine/apicods/require) | ||
|
||
Importing a module directly from GEE (e.g. `require("users/homeFolder/repo:path/to/file)`) is not currently supported, and is unlikely to be developed soon. However, in some very *limited and specific* cases, one workaround is to (1) clone the git repository ([see how to here](https://gis.stackexchange.com/a/315134/67301)), and (2) change the line of code to use the absolute path to the local file instead. For example: | ||
|
||
![require](https://raw.githubusercontent.com/gee-community/eetasks/main/docs/assets/require.png) | ||
|
||
This silly example demonstrates the use of require with a local file. However, note that the `clonedGEErepo/test.js` file does not have access to `ee`, `print`, `Export`, etc.. so the script will fail if it attempts to access them. | ||
|
||
The example above works because the function `addOne` does not use any of these, but it does allow using the methods within the objects passed as arguments (e.g. the `.add` method from the passed argument `ee.Number(1)`). A workaround would be to modify the functions to use within the module to require so that they allow passing `ee` (or other features to use) as arguments. | ||
|
||
However.. if you are using `require` you are probably already doing something more complicated than the [recommended use cases](#use-cases) for `EE Tasks: run GEE script`. | ||
|
||
## Caveat for windows users | ||
|
||
For some unknown reason, synchronous calls to some `ee` methods (e.g., most notably `getInfo`) do not work when running from vscode. Even stranger, this issue only occurs in windows. This is unlikely to be a bug with `ee` itself, as running the same code directly in `node` does work in Windows, so the issue is isolated to within vscode. | ||
|
||
See more details in the [question](https://stackoverflow.com/questions/77436205/synchronous-function-call-to-external-library-within-vscode-freezes-only-in-wind) posted to StackOverflow, and if you have some insight please share it. | ||
|
||
What happens when I use `getInfo` (or other method that accepts a callback function) synchronously through a GEE script in `EE Tasks: run GEE script` in windows? | ||
|
||
Nothing really.. the error is not catched properly (there will be no message showing that the script run failed), but any other call to a `EE Tasks` extension will not work. A simple `Developer: Reload Window` will get the extension working back to normal. |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.