Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to Solara #16

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

Convert to Solara #16

wants to merge 10 commits into from

Conversation

Carifio24
Copy link
Member

This PR moves the story into Solara, using #9 as a starting point but putting the content in the main app page. This also converts the subset control widget to a Solara component.

I'm running into issues just like we saw on #9 - in particular, the interaction between the controls and the image layer on the map viewer seems problematic. I've also noticed that the image layer doesn't update when the map zooms, and I get some errors in the console. Still working on investigating these.

@jfoster17
Copy link
Contributor

What is the right way to run this for testing?

I tried:solara run tempods

But this gives me some slightly odd error message (below). Before I try to solve that, is that the right way to try and invoke this?

❯ solara run tempods
Solara server is starting at http://localhost:8765
Database updates enabled.
Traceback (most recent call last):
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/bin/solara", line 8, in <module>
    sys.exit(main())
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/site-packages/solara/__main__.py", line 750, in main
    cli(args[1:])
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/site-packages/rich_click/rich_command.py", line 367, in __call__
    return super().__call__(*args, **kwargs)
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/site-packages/rich_click/rich_command.py", line 152, in main
    rv = self.invoke(ctx)
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/site-packages/solara/__main__.py", line 474, in run
    start_server()
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/site-packages/solara/__main__.py", line 440, in start_server
    server.run()
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/site-packages/uvicorn/server.py", line 65, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/site-packages/uvicorn/server.py", line 69, in serve
    await self._serve(sockets)
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/site-packages/uvicorn/server.py", line 76, in _serve
    config.load()
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/site-packages/uvicorn/config.py", line 434, in load
    self.loaded_app = import_from_string(self.app)
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/site-packages/uvicorn/importer.py", line 19, in import_from_string
    module = importlib.import_module(module_str)
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/site-packages/solara/server/starlette.py", line 56, in <module>
    from . import app as appmod
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/site-packages/solara/server/app.py", line 491, in <module>
    apps["__default__"] = AppScript(os.environ.get("SOLARA_APP", "solara.website.pages:Page"))
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/site-packages/solara/server/app.py", line 73, in __init__
    app = self._execute()
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/site-packages/solara/server/app.py", line 153, in _execute
    routes = solara.generate_routes(mod)
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/site-packages/solara/autorouting.py", line 434, in generate_routes
    children = generate_routes(submod)
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/site-packages/solara/autorouting.py", line 423, in generate_routes
    submod = importlib.import_module(module.__name__ + f".{info.name}")
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/Users/jfoster/Developer/tempo-cosmic-ds/tempods/src/tempods/pages/01-first-stage/__init__.py", line 5, in <module>
    from .component_state import COMPONENT_STATE
  File "/Users/jfoster/Developer/tempo-cosmic-ds/tempods/src/tempods/pages/01-first-stage/component_state.py", line 14, in <module>
    class Marker(enum.Enum, BaseMarker):
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/enum.py", line 173, in __prepare__
    member_type, first_enum = metacls._get_mixins_(cls, bases)
  File "/Users/jfoster/mambaforge/envs/tempo-cosmic-ds/lib/python3.10/enum.py", line 619, in _get_mixins_
    raise TypeError("new enumerations should be created as "
TypeError: new enumerations should be created as `EnumName([mixin_type, ...] [data_type,] enum_type)`

@Carifio24
Copy link
Member Author

@jfoster17 I've generally been using

SOLARA_SESSION_SECRET_KEY="SECRETTESTKEY" SOLARA_OAUTH_CLIENT_ID="ohpOLLdBibfGp2YUVwkmokTw18CXiD0B" SOLARA_OAUTH_CLIENT_SECRET="DRmKDfn4ikzkdkSHXvCQPg6p0vQe46aCqmUND4YVQ9yzxZPrjdqp9qdMkGBl23MC" SOLARA_OAUTH_API_BASE_URL="dev-tbr72rd5whnwlyrg.us.auth0.com" SOLARA_OAUTH_SCOPE="openid profile email" SOLARA_SESSION_HTTPS_ONLY=false CDS_API_KEY="ILyJO2xo5wk2aKClDDaF6zwJ48UNzI" solara run tempods.pages --theme-variant dark --port=8865

powerplant_data.add_component(big*9 + med*4 + small*1, label='Size_binned')

map = cast(IPyLeafletMapViewer, app.new_data_viewer(IPyLeafletMapViewer, data=tempo_data, state=map_state, show=False))
map.map.add(TileLayer(url=stadia_labels_url, pane='labels'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You accidentally removed the definition of the custom "pane" for the label layer. Restoring this here:

map.map.panes = {"labels": {"zIndex": 650}}

Will fix the crash that causes zooming and panning to break.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not solve the problem that the time slider only updates once and then stops working...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That fixed the zooming/panning for me as well.

def update_image(index):
print(f"update_image: {index}")
set_time_index(index)
timestep = time_values[index]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be:

timestep = time_values[index].item()

to cast the solara-returned np.int64 down to an int (otherwise ipyleaflet casts the np.int64 to a string, which breaks things)

# Our remote dataset does not have real components representing latitude and longitude. We link to the only components
# it does have so that we can display this on the same viewer without trigger and IncompatibleAttribute error
app.add_link(app.data_collection["Power_Plants"], 'Longitude', app.data_collection["TEMPO"], 'Pixel Axis 0')
app.add_link(app.data_collection["Power_Plants"], 'Latitude', app.data_collection["TEMPO"], 'TEMPO_NO2_L3_V03_HOURLY_TROPOSPHERIC_VERTICAL_COLUMN_BETA')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the variable name on the server changed, so this needs to be:

TEMPO_NO2_L3_V03_HOURLY_TROPOSPHERIC_VERTICAL_COLUMN

(i.e. just remove the _BETA)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll also need the latest glue_map because I hacked the component name there instead of doing it properly. I've now hacked it to the current correct version and next time I'll certainly fix it properly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants