Skip to content

Commit

Permalink
fix aggregate nearest for different modelgrids. further deprecating g…
Browse files Browse the repository at this point in the history
…df_to_data_array_struc
  • Loading branch information
OnnoEbbens committed Jun 26, 2023
1 parent 18db5c5 commit e1da378
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 43 deletions.
53 changes: 38 additions & 15 deletions docs/examples/06_gridding_vector_data.ipynb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -19,27 +20,20 @@
"outputs": [],
"source": [
"import nlmod\n",
"from nlmod import resample\n",
"import numpy as np\n",
"import xarray as xr\n",
"import flopy\n",
"import warnings\n",
"\n",
"\n",
"from matplotlib.colors import Normalize\n",
"from matplotlib.patches import Polygon\n",
"from matplotlib.collections import PatchCollection\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import geopandas as gpd\n",
"from shapely.geometry import LineString, Point\n",
"from shapely.geometry import Polygon as shp_polygon\n",
"from scipy.interpolate import RectBivariateSpline\n",
"\n",
"from IPython.display import display"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -63,6 +57,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -121,13 +116,15 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Points"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -168,6 +165,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -185,12 +183,12 @@
"sim = nlmod.sim.sim(ds)\n",
"gwf = nlmod.gwf.gwf(ds, sim)\n",
"dis = nlmod.gwf.dis(ds, gwf)\n",
"da1 = nlmod.grid.gdf_to_data_array_struc(\n",
" point_gdf, gwf, field=\"values\", interp_method=\"nearest\"\n",
")\n",
"da2 = nlmod.grid.gdf_to_data_array_struc(\n",
" point_gdf, gwf, field=\"values\", interp_method=\"linear\"\n",
"da1 = nlmod.grid.gdf_to_da(\n",
" point_gdf, ds, column=\"values\", agg_method=\"nearest\"\n",
")\n",
"da2 = xr.DataArray(np.nan, dims=(\"y\", \"x\"), coords={\"y\": ds.y, \"x\": ds.x})\n",
"da2.values = nlmod.grid.interpolate_gdf_to_array(point_gdf, gwf, field='values', \n",
"method='linear')\n",
"\n",
"vmin = min(da1.min(), da2.min())\n",
"vmax = max(da1.max(), da2.max())\n",
Expand All @@ -211,6 +209,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -251,6 +250,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -267,7 +267,7 @@
"\n",
"da1 = nlmod.grid.gdf_to_da(pol_gdf, ds, \"values\", agg_method=\"max_area\")\n",
"da2 = nlmod.grid.gdf_to_da(pol_gdf, ds, \"values\", agg_method=\"area_weighted\")\n",
"da3 = nlmod.grid.gdf_to_data_array_struc(pol_gdf, gwf, \"values\", agg_method=\"nearest\")\n",
"da3 = nlmod.grid.gdf_to_da(pol_gdf, ds, \"values\", agg_method=\"nearest\")\n",
"\n",
"vmin = min(da1.min(), da2.min(), da3.min())\n",
"vmax = max(da1.max(), da2.max(), da3.max())\n",
Expand All @@ -291,6 +291,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -328,6 +329,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -373,6 +375,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -416,6 +419,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -438,6 +442,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -461,6 +466,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -496,6 +502,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -517,6 +524,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -540,6 +548,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -566,8 +575,22 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "nlmod",
"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.9.4"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit e1da378

Please sign in to comment.