Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ celerybeat-schedule
.env

# virtualenv
.venv/
venv/
ENV/

Expand All @@ -96,3 +97,6 @@ ENV/

# Rope project settings
.ropeproject

# Pycharm
.idea/
89 changes: 58 additions & 31 deletions examples/crs_conversion.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
},
"outputs": [],
"source": [
"grid = Grid.from_raster('../data/n30w100_con', data_name='dem')\n",
"grid = Grid.from_raster(\"../data/n30w100_con\", data_name=\"dem\")\n",
"\n",
"grid.read_raster('../data/n30w100_dir', data_name='dir')"
"grid.read_raster(\"../data/n30w100_dir\", data_name=\"dir\")"
]
},
{
Expand All @@ -48,8 +48,8 @@
},
"outputs": [],
"source": [
" #N NE E SE S SW W NW\n",
"dirmap = (64, 128, 1, 2, 4, 8, 16, 32)"
"# N NE E SE S SW W NW\n",
"dirmap = (64, 128, 1, 2, 4, 8, 16, 32)"
]
},
{
Expand All @@ -64,8 +64,15 @@
"x, y = -97.294167, 32.73750\n",
"\n",
"# Delineate the catchment\n",
"grid.catchment(data='dir', x=x, y=y, dirmap=dirmap, out_name='catch',\n",
" recursionlimit=15000, xytype='label')"
"grid.catchment(\n",
" data=\"dir\",\n",
" x=x,\n",
" y=y,\n",
" dirmap=dirmap,\n",
" out_name=\"catch\",\n",
" recursionlimit=15000,\n",
" xytype=\"label\",\n",
")"
]
},
{
Expand All @@ -74,7 +81,7 @@
"metadata": {},
"outputs": [],
"source": [
"grid.clip_to('catch')"
"grid.clip_to(\"catch\")"
]
},
{
Expand All @@ -85,7 +92,7 @@
},
"outputs": [],
"source": [
"catch = grid.view('catch')"
"catch = grid.view(\"catch\")"
]
},
{
Expand All @@ -101,8 +108,12 @@
"metadata": {},
"outputs": [],
"source": [
"grid.read_raster('../../../Data/GIS/nlcd_2011_impervious_2011_edition_2014_10_10/nlcd_2011_impervious_2011_edition_2014_10_10.img',\n",
" data_name='terrain', window=grid.bbox, window_crs=grid.crs)"
"grid.read_raster(\n",
" \"../../../Data/GIS/nlcd_2011_impervious_2011_edition_2014_10_10/nlcd_2011_impervious_2011_edition_2014_10_10.img\",\n",
" data_name=\"terrain\",\n",
" window=grid.bbox,\n",
" window_crs=grid.crs,\n",
")"
]
},
{
Expand Down Expand Up @@ -174,16 +185,32 @@
}
],
"source": [
"fig, ax = plt.subplots(1, 3, figsize=(18,6))\n",
"ax[0].imshow(grid.view('terrain', dtype=np.float32), cmap='bone',\n",
" extent=grid.extent, zorder=1, vmin=0, vmax=100)\n",
"ax[0].set_title('Impervious area (nearest neighbor)')\n",
"ax[1].imshow(grid.view('terrain', interpolation='linear', dtype=np.float32), cmap='bone',\n",
" extent=grid.extent, zorder=1)\n",
"ax[1].set_title('Impervious area (linear interpolation)')\n",
"ax[2].imshow(grid.view('terrain', interpolation='cubic', dtype=np.float32), cmap='bone',\n",
" extent=grid.extent, zorder=1, vmin=0, vmax=100)\n",
"ax[2].set_title('Impervious area (cubic interpolation)')"
"fig, ax = plt.subplots(1, 3, figsize=(18, 6))\n",
"ax[0].imshow(\n",
" grid.view(\"terrain\", dtype=np.float32),\n",
" cmap=\"bone\",\n",
" extent=grid.extent,\n",
" zorder=1,\n",
" vmin=0,\n",
" vmax=100,\n",
")\n",
"ax[0].set_title(\"Impervious area (nearest neighbor)\")\n",
"ax[1].imshow(\n",
" grid.view(\"terrain\", interpolation=\"linear\", dtype=np.float32),\n",
" cmap=\"bone\",\n",
" extent=grid.extent,\n",
" zorder=1,\n",
")\n",
"ax[1].set_title(\"Impervious area (linear interpolation)\")\n",
"ax[2].imshow(\n",
" grid.view(\"terrain\", interpolation=\"cubic\", dtype=np.float32),\n",
" cmap=\"bone\",\n",
" extent=grid.extent,\n",
" zorder=1,\n",
" vmin=0,\n",
" vmax=100,\n",
")\n",
"ax[2].set_title(\"Impervious area (cubic interpolation)\")"
]
},
{
Expand All @@ -202,10 +229,10 @@
"outputs": [],
"source": [
"# WGS 84: Geographic\n",
"old_crs = pyproj.Proj('+init=epsg:4326')\n",
"old_crs = pyproj.Proj(\"+init=epsg:4326\")\n",
"\n",
"# NAD83 / Texas Centric Albers Equal Area: Projected\n",
"new_crs = pyproj.Proj('+init=epsg:3083')"
"new_crs = pyproj.Proj(\"+init=epsg:3083\")"
]
},
{
Expand All @@ -216,7 +243,7 @@
},
"outputs": [],
"source": [
"projected_catch, projected_coords = grid.view('catch', as_crs=new_crs, return_coords=True)"
"projected_catch, projected_coords = grid.view(\"catch\", as_crs=new_crs, return_coords=True)"
]
},
{
Expand Down Expand Up @@ -270,18 +297,18 @@
"y = projected_coords[:, 0][(projected_catch != 0).ravel()]\n",
"x = projected_coords[:, 1][(projected_catch != 0).ravel()]\n",
"\n",
"fig, ax = plt.subplots(1, 2, figsize=(14,6))\n",
"fig, ax = plt.subplots(1, 2, figsize=(14, 6))\n",
"\n",
"plt.grid('on', zorder=0)\n",
"plt.grid(\"on\", zorder=0)\n",
"bbox = grid.catch.bbox\n",
"extent = (bbox[0], bbox[2], bbox[1], bbox[3])\n",
"im = ax[0].imshow(image_arr, extent=extent, zorder=1, cmap='viridis')\n",
"ax[0].set_title('Geographic coordinates')\n",
"ax[0].set_aspect('equal')\n",
"im = ax[0].imshow(image_arr, extent=extent, zorder=1, cmap=\"viridis\")\n",
"ax[0].set_title(\"Geographic coordinates\")\n",
"ax[0].set_aspect(\"equal\")\n",
"\n",
"ax[1].set_aspect('equal')\n",
"sc = ax[1].scatter(x, y, c=image_arr2.ravel(), s=6, cmap='viridis')\n",
"ax[1].set_title('Projected coordinates')\n",
"ax[1].set_aspect(\"equal\")\n",
"sc = ax[1].scatter(x, y, c=image_arr2.ravel(), s=6, cmap=\"viridis\")\n",
"ax[1].set_title(\"Projected coordinates\")\n",
"\n",
"plt.tight_layout()"
]
Expand Down
79 changes: 43 additions & 36 deletions examples/extract_river_network.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"outputs": [],
"source": [
"sns.set()\n",
"sns.set_palette('husl', 8)"
"sns.set_palette(\"husl\", 8)"
]
},
{
Expand All @@ -58,7 +58,7 @@
},
"outputs": [],
"source": [
"grid = Grid.from_raster('../data/n30w100_dir', data_name='dir')"
"grid = Grid.from_raster(\"../data/n30w100_dir\", data_name=\"dir\")"
]
},
{
Expand All @@ -76,8 +76,8 @@
},
"outputs": [],
"source": [
" #N NE E SE S SW W NW\n",
"dirmap = (64, 128, 1, 2, 4, 8, 16, 32)"
"# N NE E SE S SW W NW\n",
"dirmap = (64, 128, 1, 2, 4, 8, 16, 32)"
]
},
{
Expand All @@ -99,8 +99,15 @@
"x, y = -97.294167, 32.73750\n",
"\n",
"# Delineate the catchment\n",
"grid.catchment(data='dir', x=x, y=y, dirmap=dirmap, out_name='catch',\n",
" recursionlimit=15000, xytype='label')"
"grid.catchment(\n",
" data=\"dir\",\n",
" x=x,\n",
" y=y,\n",
" dirmap=dirmap,\n",
" out_name=\"catch\",\n",
" recursionlimit=15000,\n",
" xytype=\"label\",\n",
")"
]
},
{
Expand All @@ -110,7 +117,7 @@
"outputs": [],
"source": [
"# Clip the bounding box to the catchment\n",
"grid.clip_to('catch')"
"grid.clip_to(\"catch\")"
]
},
{
Expand All @@ -128,7 +135,7 @@
},
"outputs": [],
"source": [
"grid.accumulation(data='catch', dirmap=dirmap, pad_inplace=False, out_name='acc')"
"grid.accumulation(data=\"catch\", dirmap=dirmap, pad_inplace=False, out_name=\"acc\")"
]
},
{
Expand All @@ -146,7 +153,7 @@
},
"outputs": [],
"source": [
"branches = grid.extract_river_network('catch', 'acc', threshold=200, dirmap=dirmap)"
"branches = grid.extract_river_network(\"catch\", \"acc\", threshold=200, dirmap=dirmap)"
]
},
{
Expand All @@ -166,18 +173,18 @@
}
],
"source": [
"fig, ax = plt.subplots(figsize=(6.5,6.5))\n",
"fig, ax = plt.subplots(figsize=(6.5, 6.5))\n",
"\n",
"plt.grid('on', zorder=0)\n",
"plt.xlabel('Longitude')\n",
"plt.ylabel('Latitude')\n",
"plt.title('River network (>200 accumulation)')\n",
"plt.grid(\"on\", zorder=0)\n",
"plt.xlabel(\"Longitude\")\n",
"plt.ylabel(\"Latitude\")\n",
"plt.title(\"River network (>200 accumulation)\")\n",
"plt.xlim(grid.bbox[0], grid.bbox[2])\n",
"plt.ylim(grid.bbox[1], grid.bbox[3])\n",
"ax.set_aspect('equal')\n",
"ax.set_aspect(\"equal\")\n",
"\n",
"for branch in branches['features']:\n",
" line = np.asarray(branch['geometry']['coordinates'])\n",
"for branch in branches[\"features\"]:\n",
" line = np.asarray(branch[\"geometry\"][\"coordinates\"])\n",
" plt.plot(line[:, 0], line[:, 1])"
]
},
Expand All @@ -189,7 +196,7 @@
},
"outputs": [],
"source": [
"branches = grid.extract_river_network('catch', 'acc', threshold=50, dirmap=dirmap)"
"branches = grid.extract_river_network(\"catch\", \"acc\", threshold=50, dirmap=dirmap)"
]
},
{
Expand All @@ -209,21 +216,21 @@
}
],
"source": [
"fig, ax = plt.subplots(figsize=(6.5,6.5))\n",
"fig, ax = plt.subplots(figsize=(6.5, 6.5))\n",
"\n",
"plt.grid('on', zorder=0)\n",
"plt.xlabel('Longitude')\n",
"plt.ylabel('Latitude')\n",
"plt.title('River network (>50 accumulation)')\n",
"plt.grid(\"on\", zorder=0)\n",
"plt.xlabel(\"Longitude\")\n",
"plt.ylabel(\"Latitude\")\n",
"plt.title(\"River network (>50 accumulation)\")\n",
"plt.xlim(grid.bbox[0], grid.bbox[2])\n",
"plt.ylim(grid.bbox[1], grid.bbox[3])\n",
"ax.set_aspect('equal')\n",
"ax.set_aspect(\"equal\")\n",
"\n",
"for branch in branches['features']:\n",
" line = np.asarray(branch['geometry']['coordinates'])\n",
"for branch in branches[\"features\"]:\n",
" line = np.asarray(branch[\"geometry\"][\"coordinates\"])\n",
" plt.plot(line[:, 0], line[:, 1])\n",
"\n",
"plt.savefig('img/river_network.png', bbox_inches='tight')"
"plt.savefig(\"img/river_network.png\", bbox_inches=\"tight\")"
]
},
{
Expand All @@ -234,7 +241,7 @@
},
"outputs": [],
"source": [
"branches = grid.extract_river_network('catch', 'acc', threshold=2, dirmap=dirmap)"
"branches = grid.extract_river_network(\"catch\", \"acc\", threshold=2, dirmap=dirmap)"
]
},
{
Expand All @@ -254,18 +261,18 @@
}
],
"source": [
"fig, ax = plt.subplots(figsize=(6.5,6.5))\n",
"fig, ax = plt.subplots(figsize=(6.5, 6.5))\n",
"\n",
"plt.grid('on', zorder=0)\n",
"plt.xlabel('Longitude')\n",
"plt.ylabel('Latitude')\n",
"plt.title('River network (>2 accumulation)')\n",
"plt.grid(\"on\", zorder=0)\n",
"plt.xlabel(\"Longitude\")\n",
"plt.ylabel(\"Latitude\")\n",
"plt.title(\"River network (>2 accumulation)\")\n",
"plt.xlim(grid.bbox[0], grid.bbox[2])\n",
"plt.ylim(grid.bbox[1], grid.bbox[3])\n",
"ax.set_aspect('equal')\n",
"ax.set_aspect(\"equal\")\n",
"\n",
"for branch in branches['features']:\n",
" line = np.asarray(branch['geometry']['coordinates'])\n",
"for branch in branches[\"features\"]:\n",
" line = np.asarray(branch[\"geometry\"][\"coordinates\"])\n",
" plt.plot(line[:, 0], line[:, 1])"
]
},
Expand Down
Loading