Skip to content
Merged
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
24 changes: 18 additions & 6 deletions src/e3sm_siteview/analysis/cell_timechart.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json

import numpy as np
import plotly.colors
import plotly.graph_objects as go
from trame.app import TrameComponent
from trame.ui.html import DivLayout
Expand All @@ -13,6 +14,7 @@
from e3sm_siteview.io import EAMColumnSource

NAME = "cellTimeChart"
COLORS = plotly.colors.qualitative.Plotly


def min_max(array, min_value, max_value):
Expand All @@ -39,6 +41,9 @@ def __init__(self, server, column_reader):
def name(self):
return self._id

def refresh_data(self):
self._compute_line_plots()

def _subscribe(self, obj, watch, callback, eager=False, sync=False):
self._subscriptions.append(obj.watch(watch, callback, eager=eager, sync=sync))

Expand Down Expand Up @@ -71,7 +76,7 @@ def _compute_line_plots(self, *_):
select_arrays.EnableArray(field)

data = {}
for t in range(self.ctx.setup.time_index_max):
for t in range(self.ctx.setup.time_index_max + 1):
col.SetSlicing(json.dumps({"time": t}))
col.Update()
table = col.GetOutputDataObject(0)
Expand All @@ -83,16 +88,23 @@ def _compute_line_plots(self, *_):
n_array[idx][altitude_idx]
)

t_array = np.array(range(self.ctx.setup.time_index_max))
labels = {item["value"]: item["title"] for item in self.ctx.setup.col_items}
t_array = np.array(range(self.ctx.setup.time_index_max + 1))
figs = []
for field, cols in data.items():
fig = go.Figure()
y1 = None
y0 = None
for col, values in cols.items():
for idx, (col, values) in enumerate(cols.items()):
array = np.array(values)
fig.add_trace(
go.Scatter(x=t_array, y=array, name=str(col), mode="lines")
go.Scatter(
x=t_array,
y=array,
name=labels.get(col, str(col)),
mode="lines",
line={"color": COLORS[idx % len(COLORS)]},
)
)
y0, y1 = min_max(array, y0, y1)

Expand Down Expand Up @@ -156,7 +168,7 @@ def _build_ui(self):
with v3.VSelect(
prepend_inner_icon="mdi-map-marker-outline",
v_model="global.line_chart.columns",
items=("JSON.parse(global.col_ids_str)",),
items=("global.col_items",),
density="compact",
hide_details=True,
variant="flat",
Expand All @@ -170,7 +182,7 @@ def _build_ui(self):
)
v3.VSlider(
prepend_icon="mdi-altimeter",
v_model="global.slice.altitude",
v_model="global.hslice.altitude",
step="1",
min=("global.column.altitude_range[0]",),
max=("global.column.altitude_range[1]",),
Expand Down
Loading
Loading