Skip to content

Commit

Permalink
update notebook 06
Browse files Browse the repository at this point in the history
  • Loading branch information
jmccreight committed Oct 1, 2024
1 parent 2b6c260 commit a5ddbf3
Showing 1 changed file with 71 additions and 38 deletions.
109 changes: 71 additions & 38 deletions examples/06_flow_graph_starfit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@
"metadata": {},
"outputs": [],
"source": [
"# add GRanD shp file? or add to the object afterwards? option to get polygons\n",
"# for sf_params above? but how to show connectivity?\n",
"DomainPlot(\n",
" hru_shp_file=shp_file_hru,\n",
" segment_shp_file=shp_file_seg,\n",
Expand Down Expand Up @@ -207,29 +205,6 @@
"params = pws.parameters.PrmsParameters.load(parameter_file)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "82ba984f-3402-416d-8800-0bee97158219",
"metadata": {},
"outputs": [],
"source": [
"# domain_dir = pl.Path(\"/Users/jmccreight/usgs/data/pynhm/fgr_2yr\")\n",
"# # run just once to convert CBH/day forcing files to pywatershed, NetCDF format\n",
"# cbh_nc_dir = domain_dir\n",
"# cbh_files = [\n",
"# domain_dir / \"prcp_2yr.cbh\",\n",
"# domain_dir / \"tmax_2yr.cbh\",\n",
"# domain_dir / \"tmin_2yr.cbh\",\n",
"# ]\n",
"\n",
"# params = pws.parameters.PrmsParameters.load(domain_dir / \"myparam.param\")\n",
"\n",
"# for cbh_file in cbh_files:\n",
"# out_file = cbh_nc_dir / cbh_file.with_suffix(\".nc\").name\n",
"# pws.utils.cbh_file_to_netcdf(cbh_file, params, out_file)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -488,17 +463,9 @@
" run_dir.mkdir()\n",
" model = pws.Model(model_dict)\n",
" model.run()\n",
" model.finalize()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0b8e0ec9-340c-4668-b483-9df90f8f5936",
"metadata": {},
"outputs": [],
"source": [
"model.processes[\"prms_channel_flow_graph\"].budget"
" model.finalize()\n",
"\n",
" model.processes[\"prms_channel_flow_graph\"].budget"
]
},
{
Expand Down Expand Up @@ -557,9 +524,74 @@
" \"node_storages\": \"Big Sandy Storage\",\n",
" }\n",
").hvplot(\n",
" width=int(plot_width / 1.25),\n",
" height=int(plot_height / 1.3 / 1.2),\n",
" ylabel=\"streamflow (cfs)\\nstorage (million cubic feet)\",\n",
").opts(\n",
" legend_position=\"top_left\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1c20b0dc-0402-45e2-88e5-5aa22c994726",
"metadata": {},
"outputs": [],
"source": [
"import inspect\n",
"\n",
"max_nor = pws.hydrology.starfit.max_nor\n",
"min_nor = pws.hydrology.starfit.min_nor\n",
"\n",
"\n",
"def get_param_names(func):\n",
" return list(inspect.signature(func).parameters.keys())\n",
"\n",
"\n",
"max_nor_names = get_param_names(max_nor)\n",
"min_nor_names = get_param_names(min_nor)\n",
"\n",
"max_nor_params = {\n",
" kk: vv for kk, vv in sf_params.parameters.items() if kk in max_nor_names\n",
"}\n",
"min_nor_params = {\n",
" kk: vv for kk, vv in sf_params.parameters.items() if kk in min_nor_names\n",
"}\n",
"\n",
"omega = 1.0 / 52.0\n",
"max_nor_params[\"omega\"] = omega\n",
"min_nor_params[\"omega\"] = omega\n",
"\n",
"datetime_epiweek = pws.utils.time_utils.datetime_epiweek\n",
"epiweeks = [datetime_epiweek(tt) for tt in outflow.time.values]\n",
"\n",
"max_nor_ts = np.zeros_like(epiweeks, dtype=np.float64) * np.nan\n",
"min_nor_ts = np.zeros_like(epiweeks, dtype=np.float64) * np.nan\n",
"\n",
"for ii, ee in enumerate(epiweeks):\n",
" max_nor_ts[ii] = max_nor(**max_nor_params, epiweek=ee)[0]\n",
" min_nor_ts[ii] = min_nor(**min_nor_params, epiweek=ee)[0]\n",
"\n",
"capacity = sf_params.parameters[\"GRanD_CAP_MCM\"] * pws.constants.cm_to_cf\n",
"max_nor = outflow.copy().rename(\"max_nor\")\n",
"min_nor = outflow.copy().rename(\"min_nor\")\n",
"\n",
"max_nor[:] = max_nor_ts * capacity / 100.0\n",
"min_nor[:] = min_nor_ts * capacity / 100.0\n",
"\n",
"capacity = outflow.copy().rename(\"capacity\") * 0 + capacity\n",
"\n",
"xr.merge([storage_nodes, max_nor, min_nor, capacity]).rename(\n",
" {\n",
" \"node_storages\": \"Big Sandy Storage\",\n",
" \"max_nor\": \"Max NOR\",\n",
" \"min_nor\": \"Min NOR\",\n",
" }\n",
").hvplot(\n",
" width=plot_width,\n",
" height=plot_height,\n",
" ylabel=\"streamflow (cfs)\\nstorage (million cubic feet)\",\n",
" ylabel=\"storage (million cubic feet)\",\n",
")"
]
},
Expand Down Expand Up @@ -670,7 +702,8 @@
" flow_graph.calculate(1.0)\n",
" flow_graph.output()\n",
"\n",
" flow_graph.finalize()"
" flow_graph.finalize()\n",
" flow_graph.budget"
]
},
{
Expand Down

0 comments on commit a5ddbf3

Please sign in to comment.