From 3cb6d13bdcb69f06b4c4ab3f9bcf2566469a2a05 Mon Sep 17 00:00:00 2001 From: Matt Deshotel Date: Mon, 3 Mar 2025 11:25:58 -0600 Subject: [PATCH] add model_name to extract_submodel endpoint closes #325 --- ripple1d/api/postman_collection.json | 6 +++--- ripple1d/data_model.py | 8 ++------ ripple1d/ops/subset_gpkg.py | 6 ++++-- tests/api_tests.py | 1 + tests/conftest.py | 1 + 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ripple1d/api/postman_collection.json b/ripple1d/api/postman_collection.json index f07a98d..247cb02 100644 --- a/ripple1d/api/postman_collection.json +++ b/ripple1d/api/postman_collection.json @@ -75,7 +75,7 @@ "header": [], "body": { "mode": "raw", - "raw": "{\r\n \"source_model_directory\": \"{{source_model_directory}}\",\r\n \"model_name\":\"{{source_model_name}}\",\r\n \"source_network\": {\"file_name\":\"{{nwm_data_directory}}\\\\flows.parquet\",\r\n \"version\":\"2.1\", // optional\r\n \"type\":\"nwm_hydrofabric\"}\r\n \r\n}", + "raw": "{\r\n \"source_model_directory\": \"{{source_model_directory}}\",\r\n \"model_name\":\"{{source_model_name}}\",\r\n \"source_network\": {\"file_name\":\"{{nwm_data_directory}}\\\\nwm_bbox.parquet\",\r\n \"version\":\"2.1\", // optional\r\n \"type\":\"nwm_hydrofabric\"}\r\n \r\n}", "options": { "raw": { "language": "json" @@ -104,7 +104,7 @@ "header": [], "body": { "mode": "raw", - "raw": "{\r\n \"source_model_directory\": \"{{source_model_directory}}\",\r\n \"submodel_directory\": \"{{submodels_base_directory}}\\\\{{nwm_reach_id}}\",\r\n \"nwm_id\": \"{{nwm_reach_id}}\"\r\n}", + "raw": "{\r\n \"source_model_directory\": \"{{source_model_directory}}\",\r\n \"submodel_directory\": \"{{submodels_base_directory}}\\\\{{nwm_reach_id}}\",\r\n \"nwm_id\": \"{{nwm_reach_id}}\",\r\n \"model_name\":\"{{source_model_name}}\"\r\n}", "options": { "raw": { "language": "json" @@ -133,7 +133,7 @@ "header": [], "body": { "mode": "raw", - "raw": "{\r\n \"source_model_directory\": \"{{source_model_directory}}\",\r\n \"crs\": 2227,\r\n \"metadata\": {\"stac_api\":\"https://stac2.dewberryanalytics.com\", // optional\r\n \"stac_collection_id\":\"ebfe-12090301_LowerColoradoCummins\", // optional\r\n \"stac_item_id\":\"137a9667-e5cf-4cea-b6ec-2e882a42fdc8\"} // optional\r\n}\r\n", + "raw": "{\r\n \"source_model_directory\": \"{{source_model_directory}}\",\r\n \"crs\": 3452,\r\n \"metadata\": {\"stac_api\":\"https://stac2.dewberryanalytics.com\", // optional\r\n \"stac_collection_id\":\"ebfe-12090301_LowerColoradoCummins\", // optional\r\n \"stac_item_id\":\"137a9667-e5cf-4cea-b6ec-2e882a42fdc8\"} // optional\r\n}\r\n", "options": { "raw": { "language": "json" diff --git a/ripple1d/data_model.py b/ripple1d/data_model.py index e24aa6a..99dbe52 100644 --- a/ripple1d/data_model.py +++ b/ripple1d/data_model.py @@ -187,15 +187,11 @@ def nwm_conflation_parameters(self, nwm_id: str): class RippleSourceDirectory: """Source Directory for Ripple to create NwmReachModel's. Should contain the conflation.json file and gpkg file for the source model.""" - def __init__(self, source_directory: str): + def __init__(self, source_directory: str, model_name: str): self.source_directory = source_directory self.model_basename = os.path.basename(self.source_directory) - - @property - def model_name(self): - """Model name.""" - return self.model_basename + self.model_name = model_name def derive_path(self, extension: str): """Derive path.""" diff --git a/ripple1d/ops/subset_gpkg.py b/ripple1d/ops/subset_gpkg.py index d5f982c..1c771e1 100644 --- a/ripple1d/ops/subset_gpkg.py +++ b/ripple1d/ops/subset_gpkg.py @@ -495,7 +495,7 @@ def write_ripple1d_parameters(self, ripple1d_parameters: dict): json.dump(ripple1d_parameters, f, indent=4) -def extract_submodel(source_model_directory: str, submodel_directory: str, nwm_id: int): +def extract_submodel(source_model_directory: str, submodel_directory: str, nwm_id: int, model_name: str): """Use ripple conflation data to create a new GPKG from an existing ras geopackage. Create a new geopackage with information for a specific NWM reach. The new geopackage contains layer for the river centerline, cross-sections, and structures. @@ -508,6 +508,8 @@ def extract_submodel(source_model_directory: str, submodel_directory: str, nwm_i The path to export submodel HEC-RAS files to. nwm_id : int The id of the NWM reach to create a submodel for + model_name : str + The name of the HEC-RAS model. task_id : str, optional Task ID to use for logging, by default "" @@ -527,7 +529,7 @@ def extract_submodel(source_model_directory: str, submodel_directory: str, nwm_i raise FileNotFoundError( f"cannot find directory for source model {source_model_directory}, please ensure dir exists" ) - rsd = RippleSourceDirectory(source_model_directory) + rsd = RippleSourceDirectory(source_model_directory, model_name) logging.info(f"extract_submodel starting for nwm_id {nwm_id}") diff --git a/tests/api_tests.py b/tests/api_tests.py index 1a2001b..d036ecb 100644 --- a/tests/api_tests.py +++ b/tests/api_tests.py @@ -102,6 +102,7 @@ def test_b_extract_submodel(self): "source_model_directory": self.SOURCE_RAS_MODEL_DIRECTORY, "submodel_directory": self.SUBMODELS_DIRECTORY, "nwm_id": self.REACH_ID, + "model_name": self.MODEL_NAME, } process = "extract_submodel" files = [self.GPKG_FILE] diff --git a/tests/conftest.py b/tests/conftest.py index 56dfdbd..61ba1c0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -26,6 +26,7 @@ def setup_data(request): SOURCE_RAS_MODEL_DIRECTORY = os.path.join(TEST_DIR, f"ras-data\\{RAS_MODEL}") SUBMODELS_BASE_DIRECTORY = os.path.join(SOURCE_RAS_MODEL_DIRECTORY, "submodels") SUBMODELS_DIRECTORY = os.path.join(SUBMODELS_BASE_DIRECTORY, REACH_ID) + SUBMODEL_NAME = REACH_ID FIM_LIB_DIRECTORY = os.path.join(SUBMODELS_DIRECTORY, f"fims") request.cls.FIM_LIB_DIRECTORY = FIM_LIB_DIRECTORY request.cls.REACH_ID = RAS_MODEL