From 7444f85f9139a6ad5f16221e68b34533b95aead7 Mon Sep 17 00:00:00 2001 From: manishvenu Date: Thu, 28 May 2026 16:05:31 -0600 Subject: [PATCH 1/2] Write function default args to config and pass through to OBC/IC at runtime --- CrocoDash/case.py | 3 +++ CrocoDash/extract_forcings/case_setup/driver.py | 1 + CrocoDash/extract_forcings/initial_condition.py | 7 ++----- CrocoDash/extract_forcings/obc.py | 6 +----- CrocoDash/raw_data_access/registry.py | 15 +++++++++++++++ 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/CrocoDash/case.py b/CrocoDash/case.py index 3a00fcff..1728af5c 100644 --- a/CrocoDash/case.py +++ b/CrocoDash/case.py @@ -548,6 +548,9 @@ def configure_initial_and_boundary_conditions( config["forcing"]["information"] = ProductRegistry.get_product( self.forcing_product_name.lower() ).write_metadata(include_marbl_tracers=self.bgc_in_compset) + config["forcing"]["function_default_args"] = ProductRegistry.get_function_default_args( + self.forcing_product_name.lower(), function_name + ) # General config["general"]["boundary_number_conversion"] = { diff --git a/CrocoDash/extract_forcings/case_setup/driver.py b/CrocoDash/extract_forcings/case_setup/driver.py index 337568c6..ead1d03e 100644 --- a/CrocoDash/extract_forcings/case_setup/driver.py +++ b/CrocoDash/extract_forcings/case_setup/driver.py @@ -383,6 +383,7 @@ def run_workflow( output_data_dir=cfg["basic"]["paths"]["output_path"], bathymetry_path=cfg["basic"]["paths"]["bathymetry_path"], preview=preview, + function_default_args=cfg["basic"]["forcing"].get("function_default_args", {}), ) if bgcic: diff --git a/CrocoDash/extract_forcings/initial_condition.py b/CrocoDash/extract_forcings/initial_condition.py index bcf4e2a1..6f837a7e 100644 --- a/CrocoDash/extract_forcings/initial_condition.py +++ b/CrocoDash/extract_forcings/initial_condition.py @@ -26,6 +26,7 @@ def process_initial_condition( output_data_dir: str | Path, bathymetry_path: str | Path, preview: bool = False, + function_default_args: dict = None, ): """ Process the initial condition (t=0) through the data retrieval pipeline. @@ -75,11 +76,7 @@ def process_initial_condition( for k, v in product_information["tracer_var_names"].items() if k not in ("temp", "salt") ] - extra_args = { - key: product_information[key] - for key in ["dataset_path", "date_format", "regex", "delimiter"] - if key in product_information - } + extra_args = function_default_args or {} if not preview: _download_initial_condition( data_access_function=data_access_function, diff --git a/CrocoDash/extract_forcings/obc.py b/CrocoDash/extract_forcings/obc.py index 268755f0..59efef34 100644 --- a/CrocoDash/extract_forcings/obc.py +++ b/CrocoDash/extract_forcings/obc.py @@ -385,11 +385,7 @@ def process_obc_conditions( if k not in ("temp", "salt") ] variables = phys_vars + extra_tracers - extra_args = { - k: product_info[k] - for k in ("dataset_path", "date_format", "regex", "delimiter") - if k in product_info - } + extra_args = config["basic"]["forcing"].get("function_default_args", {}) fill_method = rm6.regridding.fill_missing_data if product_info.get("boundary_fill_method", "regional_mom6") != "regional_mom6": diff --git a/CrocoDash/raw_data_access/registry.py b/CrocoDash/raw_data_access/registry.py index d9cd54a3..3cb794db 100644 --- a/CrocoDash/raw_data_access/registry.py +++ b/CrocoDash/raw_data_access/registry.py @@ -1,3 +1,5 @@ +import inspect + from CrocoDash.raw_data_access.datasets import load_all_datasets @@ -53,6 +55,19 @@ def call(cls, product_name, method_name, **kwargs): method = product._access_methods[method_name] return method(**kwargs) + @classmethod + def get_function_default_args(cls, product_name, function_name): + """Return a dict of {param: default} for all non-required parameters of an access method.""" + product = cls.get_product(product_name) + func = product._access_methods[function_name].__func__ + sig = inspect.signature(func) + required = set(product.required_args) + return { + name: param.default + for name, param in sig.parameters.items() + if name not in required and param.default is not inspect.Parameter.empty + } + @classmethod def load(cls): loaded = True From df27a880a3abda1d7a93320fcee48f72ae6bbbac Mon Sep 17 00:00:00 2001 From: manishvenu Date: Fri, 29 May 2026 16:13:18 -0600 Subject: [PATCH 2/2] black --- CrocoDash/case.py | 6 ++++-- CrocoDash/extract_forcings/case_setup/driver.py | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CrocoDash/case.py b/CrocoDash/case.py index 10a32a47..ac577392 100644 --- a/CrocoDash/case.py +++ b/CrocoDash/case.py @@ -548,8 +548,10 @@ def configure_initial_and_boundary_conditions( config["forcing"]["information"] = ProductRegistry.get_product( self.forcing_product_name.lower() ).write_metadata(include_marbl_tracers=self.bgc_in_compset) - config["forcing"]["function_default_args"] = ProductRegistry.get_function_default_args( - self.forcing_product_name.lower(), function_name + config["forcing"]["function_default_args"] = ( + ProductRegistry.get_function_default_args( + self.forcing_product_name.lower(), function_name + ) ) # General diff --git a/CrocoDash/extract_forcings/case_setup/driver.py b/CrocoDash/extract_forcings/case_setup/driver.py index 6f6418c7..70be53b6 100644 --- a/CrocoDash/extract_forcings/case_setup/driver.py +++ b/CrocoDash/extract_forcings/case_setup/driver.py @@ -435,7 +435,9 @@ def run_workflow( output_data_dir=cfg["basic"]["paths"]["output_path"], bathymetry_path=cfg["basic"]["paths"]["bathymetry_path"], preview=preview, - function_default_args=cfg["basic"]["forcing"].get("function_default_args", {}), + function_default_args=cfg["basic"]["forcing"].get( + "function_default_args", {} + ), ) if bgcic: