Skip to content

Commit

Permalink
pws step3 notebook update again
Browse files Browse the repository at this point in the history
  • Loading branch information
jmccreight committed Sep 18, 2024
1 parent 167391d commit b26bf75
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 73 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
157 changes: 84 additions & 73 deletions exercises-completed/pywatershed/step3_mf6_api.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"metadata": {},
"source": [
"## MF6 setup\n",
"The MF6 input files need copied to a run directory. One should look at `run_dir/mfsim.nam` (copied from the source `sagehenmodel` directory) to inspect the MF6 model setup up in more detail."
"The MF6 input files need copied to a run directory. One should look at `run_dir/mfsim.nam` (copied from the source `sagehenmodel` directory) to inspect the MF6 model setup up in more detail. Looking at `run_dir/ex-gwf-sagehen-gsf.tdis` we can see that the time units are days. The length units of meters are not explicitly stated, but we know that the grid in the `common/gwf_sagehen-gsf.dis` are in meters. We can also see that output will be sent to a directory `output` within the run directory. If we dont create this, the dylib/dll will die when it cant output to that location. "
]
},
{
Expand Down Expand Up @@ -159,23 +159,13 @@
"source": [
"run_dir = nb_output_dir / \"run_dir\"\n",
"assert run_dir.exists()\n",
"\n",
"mf6_output_dir = run_dir / \"output\"\n",
"# This step is *critical* for MF6 initialization\n",
"if not mf6_output_dir.exists():\n",
" mf6_output_dir.mkdir()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "383f8cf5-f1a8-4792-bcb0-ac8876927508",
"metadata": {},
"outputs": [],
"source": [
"# is the output directory specified in the input files? must be, confirm\n",
"# what are the units of MF6?"
]
},
{
"cell_type": "markdown",
"id": "72122c0c-e68e-4145-8812-fff8f1b63619",
Expand Down Expand Up @@ -225,9 +215,84 @@
"# control.edit_n_time_steps(5844) # the 16 years in the forcing files above\n",
"control.edit_n_time_steps(5 * 365) # the 16 years in the forcing files above\n",
"control.options[\"calc_method\"] = \"numba\"\n",
"control.options[\"budget_type\"] = None\n",
"control.options[\"netcdf_output_dir\"] = nb_output_dir / \"pws_model_output\"\n",
"control.options[\"budget_type\"] = \"warn\"\n",
"control.options[\"netcdf_output_dir\"] = nb_output_dir / \"pws_model_output\""
]
},
{
"cell_type": "markdown",
"id": "b8d3e34d-eb4f-41d0-a70a-2d4f327eb9e9",
"metadata": {},
"source": [
"We discussed the coupling strategy above, but now it's time to get specific with pywatershed. Fortunately, we can ask pywatershed for details about its fluxes and states. For fluxes leaving the model, we can look specifically at the \"output\" mass balance terms. "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "47f28ecd-28e0-480d-8f32-eccb71ab146c",
"metadata": {},
"outputs": [],
"source": [
"pws.meta.get_vars(pws.PRMSRunoffCascadesNoDprst.get_mass_budget_terms()[\"outputs\"])"
]
},
{
"cell_type": "markdown",
"id": "d97ca6e9-700c-4e71-8c0c-c241763d5d02",
"metadata": {},
"source": [
"From the `PRMSRunoffCascadesNoDprst` process, the `hru_horton_cascflow` variable is one component of flux we want to map to SFR in MF6. Looking at `PRMSSoilzoneCascadesNoDprst` next, "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0a508f36-884c-4519-a00d-cfe65ee117a9",
"metadata": {},
"outputs": [],
"source": [
"pws.meta.get_vars(pws.PRMSSoilzoneCascadesNoDprst.get_mass_budget_terms()[\"outputs\"])"
]
},
{
"cell_type": "markdown",
"id": "32f691fe-44b6-41e4-bd89-9709749e5994",
"metadata": {},
"source": [
"To SFR, we'll also want to add `dunnian_flow`, `pref_flow`, and `slow_flow`. Note that all these fluxes to SFR are reported by PRMS in inches on an HRU per day. We'll need to convert these depths into volumes in cubic meters for SFR. This will require the area of the HRUs from which these fluxes come. \n",
"\n",
"Similarly, the vertical fluxes from `PRMSSoilzoneCascadesNoDprst` to UZF, `soil_to_gw` and `ssr_to_gw`, are in inches on an HRU per day and we'll have to make the same unit conversion to volume for MF6 inputs. Finally, let's look at `unused_potet`. We'll verify that it's a varible in `PRMSSoilzoneCascadesNoDprst`, which is the last process in pywatershed to take its toll on potential evapotranspiration."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "79d41315-5fe9-450d-988d-9a330a47fb43",
"metadata": {},
"outputs": [],
"source": [
"assert \"unused_potet\" in pws.PRMSSoilzoneCascadesNoDprst.get_variables()\n",
"pws.meta.get_vars(\"unused_potet\")"
]
},
{
"cell_type": "markdown",
"id": "b5f13526-50ef-4c7c-a1a6-3d53490116d3",
"metadata": {},
"source": [
"Again, the state of this variable is in inches on an HRU and will need the same conversion as the other variables.\n",
"\n",
"We specify the variable names we'd like to be output by the pywatershed model run. We make this output optional with the `pws_write_output` variable. Below, we'll actually write our own custom output routine for pywatershed to see how easy that is."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "28c6d9f5-066b-4380-9169-f470943abf1b",
"metadata": {},
"outputs": [],
"source": [
"pws_write_output = False\n",
"output_var_names = [\n",
" \"hru_ppt\",\n",
Expand All @@ -248,22 +313,6 @@
"control.options[\"netcdf_output_var_names\"] = output_var_names"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "28c6d9f5-066b-4380-9169-f470943abf1b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "ec3f6140-ce35-4baf-a02b-cccac881445d",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "a6c1b085-e8bf-4cf4-a1f4-7fe905b2691e",
Expand Down Expand Up @@ -295,43 +344,13 @@
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "575d71d5-7145-4be3-bdbe-d83f58399470",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "47f28ecd-28e0-480d-8f32-eccb71ab146c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "ebc22a0c-8a9d-4fbd-96b5-08f5adf64bb1",
"metadata": {},
"outputs": [],
"source": [
"pws.meta.get_vars(\n",
" [\n",
" *pws.PRMSRunoffCascadesNoDprst.get_mass_budget_terms()[\"outputs\"],\n",
" *pws.PRMSSoilzoneCascadesNoDprst.get_mass_budget_terms()[\"outputs\"],\n",
" ]\n",
")"
]
},
{
"cell_type": "markdown",
"id": "aa73ab2a-1164-4b84-8b2c-e8a3c54debc3",
"metadata": {},
"source": [
"## Spatial mappings"
"## Spatial mappings\n",
"These mappings from HRUs to the MF6 grid and to the SFR network are magically created. "
]
},
{
Expand Down Expand Up @@ -415,7 +434,8 @@
"id": "121152b8-ef53-4743-8ca2-d57ed9ceb875",
"metadata": {},
"source": [
"## Unit conversion factors"
"## Unit conversion factors\n",
"As noted above, we'll need to comvert from inches on an hru to cubic meters. The HRU areas also happen to be in acres! This is FUN."
]
},
{
Expand All @@ -427,16 +447,7 @@
"source": [
"m2ft = 3.28081\n",
"in2m = 1.0 / (12.0 * m2ft)\n",
"acre2m2 = 43560.0 / (m2ft * m2ft)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7f228dc2-aca2-4861-99e5-39c8b97c1aae",
"metadata": {},
"outputs": [],
"source": [
"acre2m2 = 43560.0 / (m2ft * m2ft)\n",
"hru_area_m2 = params.parameters[\"hru_area\"] * acre2m2"
]
},
Expand Down

0 comments on commit b26bf75

Please sign in to comment.