@@ -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). " )
353363def 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