Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ requires-python = ">=3.10"
dependencies = [
"trame>=3.12",
"trame-vuetify>=3.1",
"trame-rca[turbo]>=2.3.1",
"trame-rca[turbo]>=2.4",
"pyproj>=3.6.1",
"netCDF4>=1.6.5",
"trame-dataclass >=2.0.2",
Expand Down
51 changes: 44 additions & 7 deletions src/e3sm_quickview/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import json
import math
import os
import time
from functools import partial
from pathlib import Path

from trame.app import TrameApp, asynchronous, file_upload
from trame.decorators import change, controller, life_cycle, trigger
from trame.ui.vuetify3 import VAppLayout
from trame.widgets import client, dataclass, html, tauri
from trame.widgets import client, dataclass, html, rca, tauri
from trame.widgets import trame as tw
from trame.widgets import vuetify3 as v3

Expand All @@ -18,11 +19,21 @@
from e3sm_quickview.components import css, dialogs, doc, drawers, file_browser, toolbars
from e3sm_quickview.pipeline import EAMVisSource
from e3sm_quickview.utils import cli, compute
from e3sm_quickview.view_manager import ViewManager

v3.enable_lab()


def create_view_manager(single_view, server, source):
if single_view:
from e3sm_quickview.view_manager2 import ViewManager

return ViewManager(server, source)

from e3sm_quickview.view_manager import ViewManager

return ViewManager(server, source)


class EAMApp(TrameApp):
def __init__(self, server=None):
super().__init__(server)
Expand Down Expand Up @@ -62,7 +73,7 @@ def __init__(self, server=None):
self.source = EAMVisSource()

# Helpers
self.view_manager = ViewManager(self.server, self.source)
self.view_manager = create_view_manager(args.fast, self.server, self.source)
self.file_browser = file_browser.ParaViewFileBrowser(
self.server,
prefix="pv_files",
Expand Down Expand Up @@ -209,10 +220,23 @@ def _build_ui(self, **_):
toolbars.Animation()

# View of all the variables
client.ServerTemplate(
name=("active_layout", "auto_layout"),
v_if="variables_selected.length",
)
if self.view_manager.use_image_stream:
with rca.ImageStream(
self.view_manager._render_window,
encoder="turbo-jpeg",
ctx_name="view",
):
# To debug vtkRenderWindow content
# html.Img(src=["image?.src"], height="300px")
client.ServerTemplate(
name=("active_layout", "auto_layout"),
v_if="variables_selected.length",
)
else:
client.ServerTemplate(
name=("active_layout", "auto_layout"),
v_if="variables_selected.length",
)

# Show documentation when no variable selected
with html.Div(v_if="!variables_selected.length"):
Expand Down Expand Up @@ -450,10 +474,15 @@ def data_loading_hide(self):
]

def data_load_variables(self):
self.state.loading = True
asynchronous.create_task(self._data_load_variables())

async def _data_load_variables(self):
"""Called at 'Load Variables' button click"""
t0 = time.perf_counter()
# Give some room
await asyncio.sleep(0.1)

vars_to_show = self.selected_variables

# Flatten the list of lists
Expand All @@ -477,17 +506,25 @@ async def _data_load_variables(self):
# Trigger source update + compute avg
with self.state:
self.state.variables_loaded = True

await self.server.network_completion

# Update views in layout
with self.state:
self.view_manager.build_auto_layout(vars_to_show)

await self.server.network_completion

# Reset camera after yield
await asyncio.sleep(0.1)
self.view_manager.reset_camera()

# Done with the loading
t1 = time.perf_counter()
with self.state:
self.state.loading = False
self.state.loading_time = t1 - t0

@change("layout_grouped")
def _on_layout_change(self, **_):
vars_to_show = self.selected_variables
Expand Down
7 changes: 5 additions & 2 deletions src/e3sm_quickview/components/drawers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def __init__(self, load_variables=None):
style=(f"{js.is_active('select-fields')} ? 'transform: none;' : ''",),
)

self.state.setdefault("loading_time", 0)

with self:
with html.Div(
style="position:fixed;top:0;width: 500px;height:100vh;",
Expand All @@ -85,12 +87,13 @@ def __init__(self, load_variables=None):
color="primary",
prepend_icon="mdi-database",
text=(
"`Load ${variables_selected.length} variable${variables_selected.length > 1 ? 's' :''}`",
"`Load ${variables_selected.length} variable${variables_selected.length > 1 ? 's' :''} ${ loading_time ? ('(' + loading_time.toFixed(1) + ' s)') : ''}`",
),
variant="flat",
disabled=(
"variables_selected.length === 0 || variables_loaded",
"variables_selected.length === 0 || variables_loaded || loading",
),
loading=("loading", False),
click=load_variables,
block=True,
)
Expand Down
6 changes: 6 additions & 0 deletions src/e3sm_quickview/utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,11 @@ def configure_and_parse(parser):
action="store_true",
help="Use user home as home for file browsing",
)
parser.add_argument(
"--fast",
dest="fast",
action="store_true",
help="Use a single vtkRenderWindow to share GPU memory",
)

return parser.parse_known_args()[0]
4 changes: 2 additions & 2 deletions src/e3sm_quickview/view_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ def _build_ui(self):
class ViewManager(TrameComponent):
def __init__(self, server, source):
super().__init__(server)
self.use_image_stream = False
self.source = source
self._var2view = {}
self._camera_sync_in_progress = False
Expand Down Expand Up @@ -507,8 +508,7 @@ def build_auto_layout(self, variables=None):
existed_order = set()
order_max = 0
orders_to_update = []
for var_type in variables.keys():
var_names = variables[var_type]
for var_type, var_names in variables.items():
for name in var_names:
config = self.get_view(name, var_type).config
self._active_configs[name] = config
Expand Down
Loading
Loading