Skip to content

Commit

Permalink
Merge pull request #310 from Dewberry/feature/unsteady
Browse files Browse the repository at this point in the history
Fix handling of unsteady flows simulations in source model
  • Loading branch information
mdeshotel authored Jan 30, 2025
2 parents 0406ff7 + f6d7c75 commit afa2fd7
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions ripple1d/ras_to_gpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def find_a_valid_file(
return path


def gather_metdata(metadata: dict, ras_project: RasProject, rp: RasPlanText, rf: RasFlowText, rg: RasGeomText) -> dict:
def gather_metadata(
metadata: dict, ras_project: RasProject, rp: RasPlanText, rg: RasGeomText, rf: RasFlowText = None
) -> dict:
"""Gather metadata from the ras project and its components."""
metadata["plans_files"] = "\n".join(
[get_path(i).replace(f"{ras_project._ras_dir}\\", "") for i in ras_project.plans if get_path(i)]
Expand Down Expand Up @@ -123,8 +125,11 @@ def gather_metdata(metadata: dict, ras_project: RasProject, rp: RasPlanText, rf:
else:
metadata["ras_version"] = None
metadata["ripple1d_version"] = ripple1d.__version__
fcls = pd.DataFrame(rf.flow_change_locations)
metadata["profile_names"] = "\n".join(fcls["profile_names"].iloc[0])
if "f" in Path(metadata["primary_flow_file"]).suffix:
fcls = pd.DataFrame(rf.flow_change_locations)
metadata["profile_names"] = "\n".join(fcls["profile_names"].iloc[0])
else:
metadata["profile_names"] = None
metadata["units"] = ras_project.units
return metadata

Expand All @@ -141,7 +146,6 @@ def geom_flow_to_gdfs(
except NoFlowFileSpecifiedError as e:
logging.warning(e)
plan_steady_file = find_a_valid_file(ras_project._ras_dir, VALID_STEADY_FLOWS, client, bucket)

# get geometry file
try:
plan_geom_file = get_path(rp.plan_geom_file, client, bucket)
Expand All @@ -154,16 +158,13 @@ def geom_flow_to_gdfs(

string = str_from_s3(plan_geom_file, client, bucket)
rg = RasGeomText.from_str(string, crs, " .g01")

else:
rp = detemine_primary_plan(ras_project, crs, ras_project._ras_text_file_path)

try:
plan_steady_file = get_path(rp.plan_steady_file)
except NoFlowFileSpecifiedError as e:
logging.warning(e)
plan_steady_file = find_a_valid_file(ras_project._ras_dir, VALID_STEADY_FLOWS)

try:
plan_geom_file = get_path(rp.plan_geom_file)
except NoFlowFileSpecifiedError as e:
Expand All @@ -189,17 +190,14 @@ def geom_flow_to_gdfs(
xs_gdf["units"] = ras_project.units
xs_gdf["project_title"] = ras_project.title
layers["XS"] = xs_gdf

if rg.reaches:
layers["River"] = rg.reach_gdf

if rg.junctions:
layers["Junction"] = rg.junction_gdf

if rg.structures:
layers["Structure"] = rg.structures_gdf

return layers, gather_metdata(metadata, ras_project, rp, rf, rg)
return layers, gather_metadata(metadata, ras_project, rp, rg, rf)


def geom_flow_xs_gdf(rg: RasGeomText, rf: RasFlowText, xs_gdf: gpd.GeoDataFrame) -> gpd.GeoDataFrame:
Expand Down

0 comments on commit afa2fd7

Please sign in to comment.