Help needed to accelerate the GUI using GEE

What I’m trying to do:
Using Google Earth Engine in the server side as fast as possible.
What I’ve tried and what’s not working:
I am trying to figure out a way to operate GEE in the server side as fast as possible.
Since Anvil server side doesn’t operate in persistence mode, unless you pay the business plan, each time I interact with the GUI it call the server from scratch thus initiate the GEE and all the credentials all over again this takes too much time.
I tried to call it in the client side but since it use secret, client side doesn’t support it.
So I try to bypass it by calling the secret only in the server side, and sending back to client side the credentials.
But… the client side doesn’t know ee module, and it seems you can’t install anything to it…
So I am stuck… any ideas?

Just a friendly tip:

You may have better luck getting an answer if you share a minimal example for people to play around.

Folks around here love to help to solve puzzles but perhaps they don’t know what GEE is or other aspects of the issue.

I’d suggest creating a minimal example that demontrates the issue clearly so others can jump right in to help.

1 Like

I wrote:
GEE = Google Earth Engine.
There isn’t much code to write.

You need to initiate GEE, with one line in the server module:
ee.Initialize(credentials)
And this line is called again and again due to the nature of the Anvil - Server communication.
(As I explained in the post)

You could continue to ignore the advice from @stefano.menci if you wish, but you’re far more likely to get any help if do as he suggests.

I really can’t understand what more information is needed. but here is the code:

Server side

ee.Initialize(credentials)

@anvil.server.callable
def create_HTML_file():
      #some code

Client side

class Form1(Form1Template):
  
  def __init__(self, **properties):
    # THIS CODE WILL RUN UPON APP LUNCH
    # Set Form properties and Data Bindings.
    self.init_components(**properties)
    anvil.server.call("create_HTML_file")
   

Now each call from the Client side operate this line which takes too much time.
That’s all to it, really…

He meant to create a minimal example and post a clone link. The more work people have to do to try to help you, the less likely you are to get help. There’s a reason the prompt that comes up when you post in the Q&A forum asks for a clone link.

I see.
Well as requested I wrote the relevant lines of code.
Thing is that it is not a code design or programming issue but rather a basic function of Anvil-Server communication.
It can be generalized to any operation that takes too much time in the server side due to the fact that anvil server “reboot” each time you call it from the client,
And you can’t put the code in the client as this lib is not recognized.

That’s not what was requested, as I explained.

Can you grab a state string from GEE to be able to recreate the state of it? Can you convert a GEE object to a JSON object to be able to recreate it? Can you pickle it and have it still work after it’s unpickled?

Things are not nearly so general as you seem to think. What works for one situation isn’t going to work for all of them. Without something that actually runs to experiment with, nobody is going to be able to do more than offer general advice.

If you want specifics, provide the minimal example that people can play with.

1 Like

Worth pointing out that it appears your calling initialize inside the module scope.

I assume you’ve timed this and that you’ve noticed that this specific line is the slow line?

There may be a bunch of functions that you want to call server side that don’t actually need the ee instance to be initialised. So instead consider moving this to a function scope and call when necessary. I’d provide specific examples, but I can’t be more specific since I don’t have any example functions in your app I can adjust…


def setup_ee():
    # other setup
    ee.Initialize()

@anvil.server.callable
def some_func():
    setup_ee()
    # do a thing

But maybe that line isn’t actually slow. You’d want time your code. Including import statements.

If you’re using anvil extras there’s a timer logger somewhere in there.

I really think providing a minimal clone is the best idea, as others have said. The question asks about accelerating the gui but we don’t know much beyond what you’ve shown us (which isn’t much). There are other things that we might be able to suggest with a broader picture of your app.

You’ll want to provide information about how to do any specific setup, eg getting credentials so that we can play with the cloned app. Not many of us have played with google earth and we’ll need some hand holding.
(Note secrets will NOT be cloned)

1 Like

Thanks,
I will try to provide a working simple version later.
Btw to your question, the ee is called almost each time a gui press is done, as the code need to use GEE to create HTML files to be presented.

Again as you said since GEE and the connection to Anvil is unique I will try to bring some simple version so the forum can play with it and understand better the problem.

1 Like