Code Monkey home page Code Monkey logo

Comments (21)

giswqs avatar giswqs commented on June 7, 2024 2

Since earthengine-api v0.1.383, users need to specify the project id for ee.Initialize(), which is an extra barrier for ee Python users. Most Python users only have one cloud project (the default cloud project). It would be great if ee.Initialize() can use the default cloud project under the user' account so that users don't have to specify the project id explicitly. It makes more sense to specify a project id only when a user has multiple cloud projects. Otherwise, the breaks most exsiting ee Python code.

ee.Initialize(project='my-project-id')

from geemap.

giswqs avatar giswqs commented on June 7, 2024 1

This bug has been fixed. Run pip install -U geemap and restart the kernel to take effect.

from geemap.

giswqs avatar giswqs commented on June 7, 2024 1

@jdbcode I was thinking about having about a environment variable (e.g., EE_PROJECT_ID) that can be accessed in Colab secrets. We can implement it in geemap before Colab officially supports it.

from geemap.

giswqs avatar giswqs commented on June 7, 2024

I can confirm that ee.Authenticate() is broken for local Jupyter. It takes about 10 seconds to open the login page in the browser, which is significantly slower than previous versions. After that, it throws the invalid request error. Authentication can't proceed. The same procesure works fine on Colab.

@jdbcode @naschmitz @schwehr

image
image

from geemap.

2320sharon avatar 2320sharon commented on June 7, 2024

Hi @giswqs
Thank you for fixing this issue. We encountered the same issue in our project and used your solution, ee.Authenticate(auth_mode='localhost') to fix it. It seems that specifying the project id to initialize with the code ee.Initialize(project='my-project-id') only needs to be used for remote environments like google colab, but not local environments. For our project the code snippet below worked without having to specify a project id. I'm not sure exactly why this is the case.

ee.Authenticate(auth_mode='localhost')
ee.Initialize()

from geemap.

giswqs avatar giswqs commented on June 7, 2024

Running the following code should authenticate and initialize ee automatically. No need to run ee.Authenticate() and ee.Initialize() explictly.

import geemap
m = geemap.Map()
m

from geemap.

giswqs avatar giswqs commented on June 7, 2024

@jdbcode @naschmitz @schwehr Note that ee.Authenticate(auth_mode='notebook') does not work any more. It needs to be fixed in the earthengine-api package.

from geemap.

tofunori avatar tofunori commented on June 7, 2024

Thank you so much!

from geemap.

jdbcode avatar jdbcode commented on June 7, 2024

@giswqs

@jdbcode @naschmitz @schwehr Note that ee.Authenticate(auth_mode='notebook') does not work any more. It needs to be fixed in the earthengine-api package.

Noted, we're looking, thanks for notifying!

from geemap.

jdbcode avatar jdbcode commented on June 7, 2024

For those that are trying to ee.Authenticate() directly in a local Jupyter notebook (as opposed to allowing geemap to attempt it indirectly: m = geemap.Map()), use ee.Authenticate(auth_mode='localhost') for now, despite the auth docs currently saying that auth_mode='notebook' should work.

from geemap.

giswqs avatar giswqs commented on June 7, 2024

@jdbcode geemap v0.30.2 already uses ee.Authenticate(auth_mode='localhost) as a temporary fix. see here.

from geemap.

giswqs avatar giswqs commented on June 7, 2024

Also note that ee.Authenticate() now takes about 10 seconds before openning up the browser. It used to be very fast, less than one second.

from geemap.

jdbcode avatar jdbcode commented on June 7, 2024

Nice! Thanks also for adding the if for Colab!

However, I think the need for a project in initialization is also causing problems.

Testing from Colab:

(I made sure that it is not accessing stored credentials - deleted them temporarily)

!pip install -U geemap
import geemap

m = geemap.Map()
m
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[<ipython-input-11-ef5c07d70876>](https://localhost:8080/#) in <cell line: 1>()
----> 1 m = geemap.Map()
      2 m

[/usr/local/lib/python3.10/dist-packages/geemap/geemap.py](https://localhost:8080/#) in __init__(self, **kwargs)
    155         # Default reducer to use
    156         if kwargs["ee_initialize"]:
--> 157             self.roi_reducer = ee.Reducer.mean()
    158         self.roi_reducer_scale = None
    159 

AttributeError: module 'ee' has no attribute 'Reducer'

I don't think it's initializing successfully and not showing the init error in stack trace.

from geemap.

jdbcode avatar jdbcode commented on June 7, 2024

Issue tracker for auth_mode='notebook' not working: https://issuetracker.google.com/319451094

from geemap.

giswqs avatar giswqs commented on June 7, 2024

I can confirm that the colab auth is broken for geemap. Looking into it now.

from geemap.

giswqs avatar giswqs commented on June 7, 2024

Here is the workaround right now. I think the requirement for specifying a cloud project explicitly is a barrier for Python users. Most ee Python users probably only has one cloud project under their account, with default name like ee-<user-id>. It would be easier if ee.Initialize() user the default project for initialization. In this way, users don't have to login the Code Editor or Google Cloud to check the project id. If there are multiple projects or if ee API is not enabled for the default project, it then makes sense to throw the error message.

import geemap
geemap.ee_initialize(project='<your-project-id>')
m = geemap.Map()
m

from geemap.

giswqs avatar giswqs commented on June 7, 2024

The requirement for specifying a project-id will break all python examples in the documentation. Colab users will have to do one of the following to authenticate and initialize a session. It would be much easier if ee.Initialize() just uses the user's default project rather than having to specify it explictly. In this way, it will not break existing code.

import ee
import geemap

ee.Authenticate(auto_mode='colab')
ee.Iinitialize(project='<your-project-id>')
m = geemap.Map()
m
import geemap
geemap.ee_initialize(project='<your-project-id>')
m = geemap.Map()
m

https://developers.google.com/earth-engine/guides/image_visualization#colab-python
image

from geemap.

giswqs avatar giswqs commented on June 7, 2024

@jdbcode Do you know what is the Python eqivalent to !gcloud projects list? If the user only has one cloud project, it can be used as the default project for ee initialize. Otherwise, print out the list of project ids and alert users to choose a proper project id from the list to initialize. This is only need for Colab.

image

from geemap.

giswqs avatar giswqs commented on June 7, 2024

The auth_mode='notebook' stills works for Colab, but not for local jupyter.

image

However, auth_mode='colab' fails if the project id is not specified. Personally, I would prefer auth_mode='notebook' because users don't have to leave Colab to go to the Code Editor or Google Cloud to find out the project id.

image

from geemap.

jdbcode avatar jdbcode commented on June 7, 2024

ee.Authenticate(auth_mode='notebook') is working again for local Jupyter. It will allow you to select a project, which means you don't need to specify one in call to ee.Initialize().
https://issuetracker.google.com/319451094

If you are running locally though you might do auth and project setting through the command line once to save the credentials and then you only need to call ee.Initialize() (without specifying project) or create a map in geemap for each new EE session. Read more here: https://developers.google.com/earth-engine/guides/auth#python_and_command_line

earthengine authenticate
earthengine set_project YOUR-EE-PROJECT

from geemap.

jdbcode avatar jdbcode commented on June 7, 2024

The requirement for specifying a project-id will break all python examples in the documentation. Colab users will have to do one of the following to authenticate and initialize a session. It would be much easier if ee.Initialize() just uses the user's default project rather than having to specify it explictly. In this way, it will not break existing code.

@giswqs - I agree, for a large group of users, having to specify a project in ee.Initialize(project='YOUR-EE-PROJECT') is serious friction to getting going. With ee.Authenticate(auth_mode='notebook') that should not be a problem because they can select the project in the Auth UI and not need it when calling ee.Initialize(). Cloud platform and projects are confusing, but they are here to stay, so I'm a little reluctant to hide them too much.

What I'd really like are for people to be able to access the Colab secrets through an API that allows a person to write for example earth engine credentials with the default project as an attribute. (so people don't have to run it in the command line locally and then copy/paste into colab) - then they should only have to ee.Initialize() I think. We've heard from the Colab team that something like this might be possible, but need them to make changes, which could take some time.

from geemap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.