diff --git a/ripple1d/api/postman_collection.json b/ripple1d/api/postman_collection.json index 0fda7d54..57743627 100644 --- a/ripple1d/api/postman_collection.json +++ b/ripple1d/api/postman_collection.json @@ -1,6 +1,6 @@ { "info": { - "_postman_id": "c9f7dbb7-0b52-42d6-ba15-209b33e020dc", + "_postman_id": "a4de6034-22c7-4a2b-b91c-12494de19040", "name": "ripple1d", "description": "Collection for processing existing HEC-RAS models for use in the production of Flood Inundation Maps (FIMs) and rating curves for use in near-real time flood forecasting on the NOAA National Water Model", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", @@ -307,7 +307,7 @@ "header": [], "body": { "mode": "raw", - "raw": "{\r\n \"submodel_directory\": \"{{submodels_base_directory}}\\\\{{nwm_reach_id}}\",\r\n \"plans\": [\"nd\",\"kwse\"],\r\n \"library_directory\":\"{{submodels_base_directory}}\\\\{{nwm_reach_id}}\\\\fim\",\r\n \"resolution\":3,\r\n \"resolution_units\":\"Meters\"\r\n}", + "raw": "{\r\n \"submodel_directory\": \"{{submodels_base_directory}}\\\\{{nwm_reach_id}}\",\r\n \"plans\": [\"nd\",\"kwse\"],\r\n \"resolution\":3,\r\n \"resolution_units\":\"Meters\"\r\n}", "options": { "raw": { "language": "json" diff --git a/ripple1d/data_model.py b/ripple1d/data_model.py index 1ce8a4ac..2ade8001 100644 --- a/ripple1d/data_model.py +++ b/ripple1d/data_model.py @@ -198,9 +198,8 @@ def nwm_conflation_parameters(self, nwm_id: str): class NwmReachModel(RasModelStructure): """National Water Model reach-based HEC-RAS Model files and directory structure.""" - def __init__(self, model_directory: str, library_directory: str = ""): + def __init__(self, model_directory: str): super().__init__(model_directory) - self.library_directory = library_directory @property def terrain_directory(self): @@ -215,7 +214,7 @@ def ras_terrain_hdf(self): @property def fim_results_directory(self): """FIM results directory.""" - return str(Path(self.library_directory) / self.model_name) + return str(Path(self.model_directory) / "fims") @property def fim_lib_assets(self): diff --git a/ripple1d/ops/fim_lib.py b/ripple1d/ops/fim_lib.py index 66b7f4e9..97bb7a16 100644 --- a/ripple1d/ops/fim_lib.py +++ b/ripple1d/ops/fim_lib.py @@ -127,7 +127,6 @@ def post_process_depth_grids( def create_fim_lib( submodel_directory: str, plans: list, - library_directory: str, ras_version: str = "631", table_name: str = "rating_curves", tiled=False, @@ -136,14 +135,13 @@ def create_fim_lib( resolution_units: str = "Meters", ): """Create a new FIM library for a NWM id.""" - nwm_rm = NwmReachModel(submodel_directory, library_directory) + nwm_rm = NwmReachModel(submodel_directory) + if not nwm_rm.file_exists(nwm_rm.ras_gpkg_file): + raise FileNotFoundError(f"cannot find ras_gpkg_file file {nwm_rm.ras_gpkg_file}, please ensure file exists") - rm = RasManager( - nwm_rm.ras_project_file, - version=ras_version, - terrain_path=nwm_rm.ras_terrain_hdf, - crs=nwm_rm.ripple1d_parameters["crs"], - ) + crs = gpd.read_file(nwm_rm.ras_gpkg_file, layer="XS").crs + + rm = RasManager(nwm_rm.ras_project_file, version=ras_version, terrain_path=nwm_rm.ras_terrain_hdf, crs=crs) ras_plans = [f"{nwm_rm.model_name}_{plan}" for plan in plans] missing_grids_kwse, missing_grids_nd = post_process_depth_grids( diff --git a/ripple1d/ops/ras_run.py b/ripple1d/ops/ras_run.py index 19082393..7532bbd4 100644 --- a/ripple1d/ops/ras_run.py +++ b/ripple1d/ops/ras_run.py @@ -80,6 +80,9 @@ def run_incremental_normal_depth( if not nwm_rm.file_exists(nwm_rm.conflation_file): raise FileNotFoundError(f"cannot find conflation file {nwm_rm.conflation_file}, please ensure file exists") + if not nwm_rm.file_exists(nwm_rm.ras_gpkg_file): + raise FileNotFoundError(f"cannot find ras_gpkg_file file {nwm_rm.ras_gpkg_file}, please ensure file exists") + logging.info(f"Working on normal depth run for nwm_id: {nwm_rm.model_name}") if nwm_rm.ripple1d_parameters["us_xs"]["xs_id"] == "-9999": logging.warning(f"skipping {nwm_rm.model_name}; no cross sections conflated.") @@ -136,18 +139,18 @@ def run_known_wse( if not nwm_rm.file_exists(nwm_rm.conflation_file): raise FileNotFoundError(f"cannot find conflation file {nwm_rm.conflation_file}, please ensure file exists") + if not nwm_rm.file_exists(nwm_rm.ras_gpkg_file): + raise FileNotFoundError(f"cannot find ras_gpkg_file file {nwm_rm.ras_gpkg_file}, please ensure file exists") + logging.info(f"Working on known water surface elevation run for nwm_id: {nwm_rm.model_name}") start_elevation = np.floor(min_elevation * 2) / 2 # round down to nearest .0 or .5 known_water_surface_elevations = np.arange(start_elevation, max_elevation + depth_increment, depth_increment) + crs = gpd.read_file(nwm_rm.ras_gpkg_file, layer="XS").crs + # write and compute flow/plans for known water surface elevation runs - rm = RasManager( - nwm_rm.ras_project_file, - version=ras_version, - terrain_path=nwm_rm.ras_terrain_hdf, - crs=nwm_rm.ripple1d_parameters["crs"], - ) + rm = RasManager(nwm_rm.ras_project_file, version=ras_version, terrain_path=nwm_rm.ras_terrain_hdf, crs=crs) # get resulting depths from the second normal depth runs_nd rm.plan = rm.plans[f"{nwm_rm.model_name}_nd"] diff --git a/tests/api_tests.py b/tests/api_tests.py index 0e7d4cd9..76a5888a 100644 --- a/tests/api_tests.py +++ b/tests/api_tests.py @@ -161,11 +161,7 @@ def test_f_run_known_wse(self): @check_process def test_g_create_fim_lib(self): - payload = { - "submodel_directory": self.SUBMODELS_DIRECTORY, - "plans": ["nd", "kwse"], - "library_directory": self.FIM_LIB_DIRECTORY, - } + payload = {"submodel_directory": self.SUBMODELS_DIRECTORY, "plans": ["nd", "kwse"]} process = "create_fim_lib" files = [self.FIM_LIB_DB, self.DEPTH_GRIDS_ND, self.DEPTH_GRIDS_KWSE] return process, payload, files diff --git a/tests/conftest.py b/tests/conftest.py index dca38812..c203ca71 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -26,7 +26,6 @@ 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) - FIM_LIB_DIRECTORY = os.path.join(SUBMODELS_DIRECTORY, "fim") request.cls.REACH_ID = RAS_MODEL request.cls.REACH_ID = REACH_ID @@ -34,7 +33,6 @@ def setup_data(request): request.cls.SOURCE_RAS_MODEL_DIRECTORY = SOURCE_RAS_MODEL_DIRECTORY request.cls.SUBMODELS_BASE_DIRECTORY = SUBMODELS_BASE_DIRECTORY request.cls.SUBMODELS_DIRECTORY = SUBMODELS_DIRECTORY - request.cls.FIM_LIB_DIRECTORY = FIM_LIB_DIRECTORY request.cls.GPKG_FILE = os.path.join(SUBMODELS_DIRECTORY, f"{REACH_ID}.gpkg") request.cls.SOURCE_GPKG_FILE = os.path.join(SOURCE_RAS_MODEL_DIRECTORY, f"{RAS_MODEL}.gpkg") request.cls.TERRAIN_HDF = os.path.join(SUBMODELS_DIRECTORY, f"Terrain\\{REACH_ID}.hdf") @@ -50,10 +48,10 @@ def setup_data(request): request.cls.PLAN3_FILE = os.path.join(SUBMODELS_DIRECTORY, f"{REACH_ID}.p03") request.cls.FLOW3_FILE = os.path.join(SUBMODELS_DIRECTORY, f"{REACH_ID}.f03") request.cls.RESULT3_FILE = os.path.join(SUBMODELS_DIRECTORY, f"{REACH_ID}.r03") - request.cls.FIM_LIB_DB = os.path.join(FIM_LIB_DIRECTORY, f"{REACH_ID}\\{REACH_ID}.db") - request.cls.DEPTH_GRIDS_ND = os.path.join(FIM_LIB_DIRECTORY, f"{REACH_ID}\\z_nd") + request.cls.FIM_LIB_DB = os.path.join(SUBMODELS_DIRECTORY, f"fims\\{REACH_ID}.db") + request.cls.DEPTH_GRIDS_ND = os.path.join(SUBMODELS_DIRECTORY, f"fims\\z_nd") integer, decimal = str(np.floor((MIN_ELEVATION + 41) * 2) / 2).split(".") - request.cls.DEPTH_GRIDS_KWSE = os.path.join(FIM_LIB_DIRECTORY, f"{REACH_ID}\\z_{integer}_{decimal}") + request.cls.DEPTH_GRIDS_KWSE = os.path.join(SUBMODELS_DIRECTORY, f"fims\\z_{integer}_{decimal}") request.cls.MODEL_STAC_ITEM = os.path.join(SUBMODELS_DIRECTORY, f"{REACH_ID}.model.stac.json") request.cls.FIM_LIB_STAC_ITEM = os.path.join(SUBMODELS_DIRECTORY, f"fims\\{REACH_ID}.fim_lib.stac.json") request.cls.min_elevation = MIN_ELEVATION diff --git a/tests/ras-data/Baxter/Baxter.conflation.json b/tests/ras-data/Baxter/Baxter.conflation.json index b7b9bb49..af8a22f4 100644 --- a/tests/ras-data/Baxter/Baxter.conflation.json +++ b/tests/ras-data/Baxter/Baxter.conflation.json @@ -725,8 +725,8 @@ "type": "nwm_hydrofabric" }, "conflation_png": "Baxter.conflation.png", - "conflation_ripple1d_version": "0.5.0", - "metrics_ripple1d_version": "0.5.0", + "conflation_ripple1d_version": "0.4.2", + "metrics_ripple1d_version": "0.4.2", "source_ras_model": { "stac_api": "https://stac2.dewberryanalytics.com", "stac_collection_id": "ebfe-12090301_LowerColoradoCummins", diff --git a/tests/ras-data/Baxter/Baxter.gpkg b/tests/ras-data/Baxter/Baxter.gpkg index 46d172e7..75542cb5 100644 Binary files a/tests/ras-data/Baxter/Baxter.gpkg and b/tests/ras-data/Baxter/Baxter.gpkg differ diff --git a/tests/ras-data/MissFldwy/MissFldwy.conflation.json b/tests/ras-data/MissFldwy/MissFldwy.conflation.json index df8c125f..f31bcb33 100644 --- a/tests/ras-data/MissFldwy/MissFldwy.conflation.json +++ b/tests/ras-data/MissFldwy/MissFldwy.conflation.json @@ -15285,8 +15285,8 @@ "type": "nwm_hydrofabric" }, "conflation_png": "MissFldwy.conflation.png", - "conflation_ripple1d_version": "0.5.0", - "metrics_ripple1d_version": "0.5.0", + "conflation_ripple1d_version": "0.4.2", + "metrics_ripple1d_version": "0.4.2", "source_ras_model": { "stac_api": "https://stac2.dewberryanalytics.com", "stac_collection_id": "ebfe-12090301_LowerColoradoCummins", diff --git a/tests/ras-data/MissFldwy/MissFldwy.gpkg b/tests/ras-data/MissFldwy/MissFldwy.gpkg index 55c81424..3c6e26ad 100644 Binary files a/tests/ras-data/MissFldwy/MissFldwy.gpkg and b/tests/ras-data/MissFldwy/MissFldwy.gpkg differ diff --git a/tests/ras-data/PatuxentRiver/PatuxentRiver.conflation.json b/tests/ras-data/PatuxentRiver/PatuxentRiver.conflation.json index 8b70397a..b4b57039 100644 --- a/tests/ras-data/PatuxentRiver/PatuxentRiver.conflation.json +++ b/tests/ras-data/PatuxentRiver/PatuxentRiver.conflation.json @@ -3677,8 +3677,8 @@ "type": "nwm_hydrofabric" }, "conflation_png": "PatuxentRiver.conflation.png", - "conflation_ripple1d_version": "0.5.0", - "metrics_ripple1d_version": "0.5.0", + "conflation_ripple1d_version": "0.4.2", + "metrics_ripple1d_version": "0.4.2", "source_ras_model": { "stac_api": "https://stac2.dewberryanalytics.com", "stac_collection_id": "ebfe-12090301_LowerColoradoCummins", diff --git a/tests/ras-data/PatuxentRiver/PatuxentRiver.gpkg b/tests/ras-data/PatuxentRiver/PatuxentRiver.gpkg index da71f2d2..fafc46f3 100644 Binary files a/tests/ras-data/PatuxentRiver/PatuxentRiver.gpkg and b/tests/ras-data/PatuxentRiver/PatuxentRiver.gpkg differ