open-geocomputing / OpenEarthEngineLibrary

https://www.open-geocomputing.org/OpenEarthEngineLibrary/
125 stars 38 forks source link

oeel.requireJS(url) or geemap.requireJS() require 10min can't back a result #9

Closed kenansun closed 1 year ago

kenansun commented 2 years ago

i hava install node js package and success down google earth package , then i can success import oeel ,when i excute url = 'https://github.com/giswqs/geemap/blob/master/examples/javascripts/grid.js' lib = oeel.requireJS(url) it need a lot time ,can't back a result

mgravey commented 2 years ago

Weird

do you have all 3 package installed: npm install @google/earthengine npm install zeromq@6.0.0-beta.6 npm install request

and node and git were in the system PATH before you run python? if you have a doubt reboot the computer :)

can we have more detail on your setup? Python version, do you use in Jupyter, on Windows/linux ... ?

kenansun commented 2 years ago

thanks for your help run this in windows system Python 3.9.12 npm and git already in the system PATH npm vesion 8.11.0 npm package version +-- @google/earthengine@0.1.317 +-- request@2.88.2 `-- zeromq@6.0.0-beta.6 i found when send a socket requirst it can't receive sucess self.nodeSocket.send_string(json.dumps({'type':'load','lib':'users/OEEL/lib:loadAll'})) if(not json.loads(self.nodeSocket.recv())['sucess']): image

mgravey commented 2 years ago

This is typical when nodejs can not be executed or crash immediately.

This is really surprising

can you try something like

import subprocess
import time
process =subprocess.Popen(["node","./EE_node_server.js","8001","8002","fcrewfcrewsd"]);
time.sleep(10)
print(process.wait())

you can download EE_node_server.js here https://github.com/open-geocomputing/OpenEarthEngineLibrary/blob/oeel-python/oeel/EE_node_server.js

kenansun commented 2 years ago

node can load this script 1658469393401(1)

kenansun commented 2 years ago

lib = geemap.requireJS(); ic = ee.ImageCollection("COPERNICUS/S2_SR"); icSize = ( lib.Algorithms.Sentinel2.cloudfree(maxCloud=20, S2Collection=ic) .filterDate('2020-01-01', '2020-01-02') .size() ) run this code, i can ge the lib object and detail properties in this object. but when call lib.Algorithms.Sentinel2.cloudfree(maxCloud=20, S2Collection=ic) this function it can't back result

kenansun commented 2 years ago

url = 'https://github.com/giswqs/geemap/blob/master/examples/javascripts/grid.js' lib = geemap.requireJS(url) lib.availability grid = lib.generateGrid(-180, -50, 180, 50, 10, 10, 0, 0) run this code ,it excute till this code , can't back Is there a problem with the version of the installation package? self.nodeSocket.send_string(json.dumps({'type':'load','lib':'users/OEEL/lib:loadAll'})) image image

mgravey commented 1 year ago

After numerous investigation, I think I finally figure out !! (At least I hope :) )

Did you Authenticate before loading OEEL ? I think this is the issue, you need to do it before calling oeel, because the authentication key is needed in JS

try this before any require

ee.Authenticate()
ee.Initialize()
kenansun commented 1 year ago

yesterday, build a new environment in linux base on wsl2 in win11,there still hava this question。 then i direct found document in gee develop manual, then run the guid, run code in this page ,it need a authentication process https://developers.google.com/earth-engine/guides/npm_install i found a question, is the js client sent a quest to google cloud api , it hava some permession configure in google cloud platform? the follow link i found ,i am tring to follow this guid to configure https://developers.google.com/identity/protocols/oauth2/javascript-implicit-flow#creatingclient https://developers.google.com/identity/protocols/oauth2/javascript-implicit-flow#creatingcred

kenansun commented 1 year ago

when this problem accurs ,i already run ee.Initialize() code in python

mgravey commented 1 year ago

so the JS need to authentificate, but to this it share the python authentification. the ee.Authenticate() need to be done before from oeel import oeel like

import ee
ee.Authenticate()
ee.Initialize()
from oeel import oeel

I tested this morning on win10 (I don't have a 11 available) and it work well

mgravey commented 1 year ago

I assume this solved, if not reopen it.