Skip to content

Commit 5428aea

Browse files
committed
Update port options in UI managers to allow random available ports
1 parent f0ea12e commit 5428aea

3 files changed

Lines changed: 27 additions & 17 deletions

File tree

schismviz/out2dui.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def _merge(cfg, **cli_overrides):
405405
@click.option("--title", default=None, help="Dashboard title shown in the browser.")
406406
@click.option(
407407
"--port", default=None, type=int,
408-
help="Port for the Panel server (default: 5006).",
408+
help="Port for the Panel server (0 or unset = random available port).",
409409
)
410410
@click.option(
411411
"--show/--no-show", default=True,
@@ -439,7 +439,7 @@ def show_out2d_ui(
439439
nodes_csv: nodes.csv
440440
variables: "elevation,depthAverageVelX"
441441
title: "SCHISM out2d"
442-
port: 5006
442+
port: 0
443443
"""
444444
import glob as _glob
445445
import pandas as pd
@@ -488,7 +488,7 @@ def show_out2d_ui(
488488

489489
# ---- build manager and launch UI ---------------------------------------
490490
dashboard_title = cfg.get("title", "SCHISM out2d")
491-
server_port = int(cfg.get("port", 5006))
491+
server_port = int(cfg.get("port", 0) or 0)
492492

493493
def build_manager():
494494
return SchismOut2DUIManager(

schismviz/schismcalibplotui.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,8 @@ def get_name_to_color(self):
577577
default=False,
578578
help="Validate config and print resolved settings without launching the UI",
579579
)
580-
@click.option("--port", default=5006, help="Port to serve the UI on")
581-
def schism_calib_plot_ui(config_file, base_dir=None, dry_run=False, port=5006, **kwargs):
580+
@click.option("--port", default=0, help="Port to serve the UI on (0 = random available port).")
581+
def schism_calib_plot_ui(config_file, base_dir=None, dry_run=False, port=0, **kwargs):
582582
"""
583583
config_file: str
584584
yaml file containing configuration

schismviz/schismui.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ class SchismDataReferenceReader(DataReferenceReader):
2222
2323
``source == "datastore"`` rows are fetched via the observation datastore;
2424
all other rows are fetched from the matching :class:`SchismStudy` output
25-
files. ``convert_units`` is checked on the owning manager at every
26-
:meth:`load` call. Caching is intentionally disabled on all
27-
:class:`~dvue.catalog.DataReference` objects using this reader so that
28-
toggling ``convert_units`` is always reflected immediately.
25+
files. This reader always returns **raw** data (no unit conversion);
26+
unit conversion is applied by :meth:`SchismOutputUIDataManager.get_data`
27+
so that caching of the raw series remains valid across ``convert_units``
28+
toggle events.
2929
3030
Parameters
3131
----------
@@ -34,7 +34,7 @@ class SchismDataReferenceReader(DataReferenceReader):
3434
obs_datastore : StationDatastore or None
3535
Observation datastore for ``source == "datastore"`` entries.
3636
manager : SchismOutputUIDataManager
37-
Owning manager; provides the reactive ``convert_units`` flag.
37+
Owning manager (kept for compatibility; no longer used here).
3838
"""
3939

4040
def __init__(self, study_dir_map, obs_datastore, manager):
@@ -47,8 +47,6 @@ def load(self, **attributes) -> pd.DataFrame:
4747
unit = attributes.get("unit", "")
4848
if source == "datastore":
4949
df = self._datastore.get_data(attributes)
50-
if self._manager.convert_units:
51-
df, unit = schismstudy.convert_to_SI(df, unit)
5250
else:
5351
base_dir = str(pathlib.Path(attributes["filename"]).parent)
5452
study = self._study_dir_map[base_dir]
@@ -57,8 +55,6 @@ def load(self, **attributes) -> pd.DataFrame:
5755
except KeyError as e:
5856
logger.warning(str(e).strip("'\""))
5957
raise
60-
if self._manager.convert_units:
61-
df, unit = schismstudy.convert_to_SI(df, unit)
6258
df = df[slice(df.first_valid_index(), df.last_valid_index())]
6359
df.attrs["unit"] = unit
6460
df.attrs["ptype"] = "INST-VAL"
@@ -241,13 +237,27 @@ def _build_dvue_catalog(self, crs=None) -> DataCatalog:
241237
catalog.add(DataReference(
242238
reader=self._schism_reader,
243239
name=ref_name,
244-
cache=False, # convert_units is reactive; always re-run
245240
**attrs,
246241
))
247242
except ValueError:
248243
pass # duplicate name; skip
249244
return catalog
250245

246+
def get_data(self, df):
247+
"""Yield data frames for each selected row, applying unit conversion.
248+
249+
Raw data is cached by :class:`~dvue.catalog.DataReference`; unit
250+
conversion is applied here (post-cache) so that toggling
251+
``convert_units`` is reflected immediately without invalidating the
252+
cache.
253+
"""
254+
for data in super().get_data(df):
255+
if self.convert_units:
256+
unit = data.attrs.get("unit", "")
257+
data, unit = schismstudy.convert_to_SI(data, unit)
258+
data.attrs["unit"] = unit
259+
yield data
260+
251261
def get_time_range(self, dfcat):
252262
return self.time_range
253263

@@ -349,7 +359,7 @@ def get_map_marker_columns(self):
349359
@click.option("--flux_out", default="flux.out", help="Path to the flux.out file")
350360
@click.option("--reftime", default=None, help="Reference time")
351361
@click.option("--yaml-file", default=None, help="Path to the yaml file")
352-
@click.option("--port", default=5006, help="Port to serve the UI on")
362+
@click.option("--port", default=0, help="Port to serve the UI on (0 = random available port).")
353363
def show_schism_output_ui(
354364
schism_dir=".",
355365
flux_xsect_file="flow_station_xsects.yaml",
@@ -359,7 +369,7 @@ def show_schism_output_ui(
359369
repo_dir="screened",
360370
inventory_file="inventory_datasets.csv",
361371
yaml_file=None,
362-
port=5006,
372+
port=0,
363373
):
364374
"""
365375
Shows Data UI for SCHISM output files.

0 commit comments

Comments
 (0)