Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add model_name to extract_submodel endpoint #334

Merged
merged 1 commit into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ripple1d/api/postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
8 changes: 2 additions & 6 deletions ripple1d/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
6 changes: 4 additions & 2 deletions ripple1d/ops/subset_gpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 ""

Expand All @@ -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}")

Expand Down
1 change: 1 addition & 0 deletions tests/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down