From 160a668b1699c33142eb52a3088addb0701463ad Mon Sep 17 00:00:00 2001 From: Austin Raney Date: Mon, 5 Aug 2024 12:02:52 -0400 Subject: [PATCH] refactor: register default ngen plugins in one place --- python/ngen_cal/src/ngen/cal/ngen.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/python/ngen_cal/src/ngen/cal/ngen.py b/python/ngen_cal/src/ngen/cal/ngen.py index d4f7a4c4..aa8e2593 100644 --- a/python/ngen_cal/src/ngen/cal/ngen.py +++ b/python/ngen_cal/src/ngen/cal/ngen.py @@ -22,7 +22,6 @@ from .parameter import Parameter, Parameters from .calibration_cathment import CalibrationCatchment, AdjustableCatchment from .calibration_set import CalibrationSet, UniformCalibrationSet -from .ngen_hooks.ngen_output import TrouteOutput, NgenSaveOutput #HyFeatures components from hypy.hydrolocation import NWISLocation from hypy.nexus import Nexus @@ -64,6 +63,7 @@ def _map_params_to_realization(params: Mapping[str, Parameters], realization: Re else: return _params_as_df(params, module.model_name) + class NgenBase(ModelExec): """ Data class specific for Ngen @@ -110,10 +110,10 @@ def __init__(self, **kwargs): #Let pydantic work its magic super().__init__(**kwargs) #now we work ours - # Register the default ngen output hook - self._plugin_manager.register(TrouteOutput(self.routing_output)) #Make a copy of the config file, just in case shutil.copy(self.realization, str(self.realization)+'_original') + + self._register_default_ngen_plugins() # Read the catchment hydrofabric data if self.hydrofabric is not None: @@ -129,6 +129,12 @@ def __init__(self, **kwargs): data = json.load(fp) self.ngen_realization = NgenRealization(**data) + def _register_default_ngen_plugins(self): + from .ngen_hooks.ngen_output import TrouteOutput + + # t-route outputs + self._plugin_manager.register(TrouteOutput(self.routing_output)) + @staticmethod def _is_legacy_gpkg_hydrofabric(hydrofabric: Path) -> bool: """Return True if legacy (<=v2.1) gpkg hydrofabric."""