Skip to content

Commit

Permalink
Merge pull request #112 from aleaf/main
Browse files Browse the repository at this point in the history
fix(part1_flopy/solutions/04_Modelgrid_and_intersection.ipynb): updat…
  • Loading branch information
mnfienen authored Feb 3, 2024
2 parents 4ea5da8 + ac8a89c commit 104e37c
Show file tree
Hide file tree
Showing 5 changed files with 42,869 additions and 337 deletions.
2,008 changes: 1,910 additions & 98 deletions notebooks/part1_flopy/04_Modelgrid_and_intersection.ipynb

Large diffs are not rendered by default.

60 changes: 41 additions & 19 deletions notebooks/part1_flopy/solutions/04_Modelgrid_and_intersection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,37 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "72833c87",
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'pygeohydro'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[1], line 12\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mgeopandas\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mgpd\u001b[39;00m\n\u001b[1;32m 10\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mshapely\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mgeometry\u001b[39;00m\n\u001b[0;32m---> 12\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpygeohydro\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mgh\u001b[39;00m\n\u001b[1;32m 13\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpynhd\u001b[39;00m\n\u001b[1;32m 14\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpydaymet\u001b[39;00m\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'pygeohydro'"
]
}
],
"source": [
"import os\n",
"from pathlib import Path\n",
"import flopy\n",
"from flopy.utils.gridgen import Gridgen\n",
"from flopy.utils import GridIntersect, Raster\n",
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import pandas as pdy\n",
"import geopandas as gpd\n",
"import shapely.geometry\n",
"\n",
"import pygeohydro as gh\n",
"import pynhd\n",
"import pydaymet\n",
"import utm\n",
"\n",
"# pd.options.mode.chained_assignment = None\n",
"data_path = os.path.join(\"..\", \"data\", \"modelgrid_intersection\")"
"data_path = Path(\"..\", \"data\", \"modelgrid_intersection\")"
]
},
{
Expand Down Expand Up @@ -356,8 +364,8 @@
"metadata": {},
"outputs": [],
"source": [
"active_shp = os.path.join(data_path, \"active_area.shp\")\n",
"refine_shp = os.path.join(data_path, \"refined_area.shp\")\n",
"active_shp = data_path / \"active_area.shp\"\n",
"refine_shp = data_path / \"refined_area.shp\"\n",
"\n",
"active = gpd.read_file(active_shp)\n",
"refined = gpd.read_file(refine_shp)"
Expand Down Expand Up @@ -570,7 +578,7 @@
"outputs": [],
"source": [
"# if pynhd is acting up load shapefile from disk\n",
"# basin = gpd.read_file(os.path.join(data_path, \"sagehen_basin.shp\"))\n",
"# basin = gpd.read_file(data_path / \"sagehen_basin.shp\")\n",
"epsg = 26911 # NAD83 utm zone 11 N, epsg: 26911\n",
"basin = basin.to_crs(epsg=epsg)\n",
"basin"
Expand Down Expand Up @@ -757,7 +765,7 @@
"metadata": {},
"outputs": [],
"source": [
"dem_file = os.path.join(data_path, \"dem_30m.img\")\n",
"dem_file = data_path / \"dem_30m.img\"\n",
"\n",
"raster = Raster.load(dem_file)"
]
Expand Down Expand Up @@ -1025,8 +1033,8 @@
"metadata": {},
"outputs": [],
"source": [
"pet_raster = os.path.join(data_path, \"pet.tif\")\n",
"prcp_raster = os.path.join(data_path, \"prcp.tif\")\n",
"pet_raster = data_path / \"pet.tif\"\n",
"prcp_raster = data_path / \"prcp.tif\"\n",
"mm_clim.pet.rio.to_raster(pet_raster)\n",
"mm_clim.prcp.rio.to_raster(prcp_raster)"
]
Expand Down Expand Up @@ -1092,7 +1100,7 @@
"metadata": {},
"outputs": [],
"source": [
"arr = np.genfromtxt(os.path.join(data_path, \"pet.txt\"))\n",
"arr = np.genfromtxt(data_path / \"pet.txt\")\n",
"arr.shape = (12, modelgrid.nrow, modelgrid.ncol)\n",
"pet_monthly = {i: a for i, a in enumerate(arr)}\n",
"pet_monthly"
Expand Down Expand Up @@ -1161,7 +1169,7 @@
"metadata": {},
"outputs": [],
"source": [
"ksat_raster = os.path.join(data_path, \"ksat.img\")\n",
"ksat_raster = data_path / \"ksat.img\"\n",
"rstr = flopy.utils.Raster.load(ksat_raster)\n",
"vks = rstr.resample_to_grid(\n",
" modelgrid,\n",
Expand Down Expand Up @@ -1359,7 +1367,7 @@
" tributaries.append(res)\n",
" \n",
"tributaries[0:5]\n",
"with open(os.path.join(data_path, \"trib_cells.txt\"), 'w') as foo:\n",
"with open(data_path / \"trib_cells.txt\", 'w') as foo:\n",
" for line in tributaries:\n",
" foo.write(f\"{line[0]},{line[1]}\\n\")"
]
Expand All @@ -1380,7 +1388,7 @@
"outputs": [],
"source": [
"tributaries = []\n",
"with open(os.path.join(data_path, \"trib_cells.txt\")) as foo:\n",
"with open(data_path / \"trib_cells.txt\") as foo:\n",
" for line in foo:\n",
" t = line.strip().split(\",\")\n",
" tributaries.append((int(t[0]), int(t[1])))"
Expand Down Expand Up @@ -1556,8 +1564,22 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "pyclass",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 104e37c

Please sign in to comment.