Skip to content

Commit

Permalink
Merge pull request #181 from Dewberry/revert-177-feature/fim-directory
Browse files Browse the repository at this point in the history
Revert "Feature/fim directory"
  • Loading branch information
mdeshotel authored Sep 13, 2024
2 parents ba1d015 + feaf9c1 commit 21744f2
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 35 deletions.
4 changes: 2 additions & 2 deletions ripple1d/api/postman_collection.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 2 additions & 3 deletions ripple1d/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
14 changes: 6 additions & 8 deletions ripple1d/ops/fim_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down
15 changes: 9 additions & 6 deletions ripple1d/ops/ras_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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"]
Expand Down
6 changes: 1 addition & 5 deletions tests/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ 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

request.cls.SOURCE_NETWORK = SOURCE_NETWORK
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")
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/ras-data/Baxter/Baxter.conflation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Binary file modified tests/ras-data/Baxter/Baxter.gpkg
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/ras-data/MissFldwy/MissFldwy.conflation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Binary file modified tests/ras-data/MissFldwy/MissFldwy.gpkg
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/ras-data/PatuxentRiver/PatuxentRiver.conflation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Binary file modified tests/ras-data/PatuxentRiver/PatuxentRiver.gpkg
Binary file not shown.

0 comments on commit 21744f2

Please sign in to comment.