Skip to content

Commit

Permalink
wet
Browse files Browse the repository at this point in the history
  • Loading branch information
iacopoff committed Nov 1, 2023
1 parent 26396ce commit 0600175
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
4 changes: 2 additions & 2 deletions _site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ <h5 class="quarto-listing-category-title">Categories</h5><div class="quarto-list

<div class="quarto-listing quarto-listing-container-default" id="listing-listing">
<div class="list quarto-listing-default">
<div class="quarto-post image-right" data-index="0" data-listing-file-modified-sort="1698859129624" data-listing-reading-time-sort="1">
<div class="quarto-post image-right" data-index="0" data-listing-file-modified-sort="1698866688397" data-listing-reading-time-sort="1">
<div class="thumbnail">
<p><a href="./posts/2023-10-31_nb/extwet_priority_habitats.html"> <p class="card-img-top"><img src="posts/2023-10-31_nb/data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz
AAAB+wAAAfsBxc2miwAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAA6zSURB
Expand Down Expand Up @@ -252,7 +252,7 @@ <h3 class="no-anchor listing-title">

</div>
<div class="listing-description">
Wetlands
<strong>?(caption)</strong>
</div>
</a>
</div>
Expand Down
29 changes: 17 additions & 12 deletions _site/posts/2023-10-31_nb/extwet_priority_habitats.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _site/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"href": "posts/2023-10-31_nb/extwet_priority_habitats.html",
"title": "Extended wetlands priority habitats",
"section": "",
"text": "from pathlib import Path\nimport pandas as pd\n\nimport os\nos.environ['USE_PYGEOS'] = '0'\nimport geopandas as gpd\n\nimport requests\nimport io\n\nimport sys\nif not sys.warnoptions:\n import warnings\n warnings.simplefilter(\"ignore\")\n# import colorcet as cc\nimport datashader as ds\n# import datashader.transfer_functions as tf\n\nimport holoviews as hv\nfrom holoviews.operation.datashader import rasterize\nfrom holoviews import opts\n\nimport geoviews as gv\nimport cartopy.crs as ccrs\n\nfrom spatialpandas import GeoDataFrame\n\nfrom dask import dataframe as dd\n\ngv.extension('bokeh')\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n \n\n\n\n\n\n\n\n\nPrepared plots showing extended wetland priority habitats.\nTried Holoviews/Geoviews/Datashader for interactive plots, they works very well.\nTried jupyterlite and pyodide but there are no wheels available for datashader and co. so micropip was not able to run with them\n\n\nurl = 'https://github.com/iacopoff/iacopoff.github.io/raw/main/data/n2k_extwet_priority_poly_onehot_s.fgb'\n\n\ndn = requests.get(url).content\n\n\ndf = gpd.read_file(io.BytesIO(dn))\n\n\nurl2 = 'https://github.com/iacopoff/iacopoff.github.io/raw/main/data/annex_I_extended_wetlands.csv'\ndn2 = requests.get(url2).content\nlookup = pd.read_csv(io.StringIO(dn2.decode('utf-8'))).set_index('habitatcode')\n\n\nhcodes = df.filter(regex='\\d',axis=1).columns.tolist()\n\n\ndf['n_pr_hb'] = df.filter(regex='\\d',axis=1).sum(axis=1)\n\n\ndf = df.to_crs(3857)\n\n\ndf_sp = GeoDataFrame(df)\n\n\nddf = dd.from_pandas(df_sp, npartitions=10)\n\n\n# cvs = ds.Canvas()\n# tf.shade(cvs.polygons(ddf[ddf['3170'] == 1], geometry='geometry', agg=ds.mean('n_pr_hb')), cmap=cc.kg);\n\n\nbm = hv.element.tiles.EsriUSATopo()\n\n\ndef get_canvas(hcodes, bm):\n out = []\n for h in hcodes:\n out.append(bm * rasterize(hv.Polygons(ddf[ddf[h] == 1], vdims=['sitename','n_pr_hb']), aggregator=ds.mean('n_pr_hb')).opts(\n colorbar=True, cmap='bgy',fontsize={'title':8}))\n return out\n\n\nouts = get_canvas(hcodes, bm)\n\n\n# def compute_partitions(el):\n# n = ddf[ddf['3170'] == 1].cx_partitions[slice(*el.range('x')), slice(*el.range('y'))].npartitions\n# return el.opts(title=f'Population by country (npartitions: {n})')\n\n# bm * out1.apply(compute_partitions).opts(width=700, height=500, tools=[\"hover\"])\n\n\n# opts.Polygons(logz=True, tools=['hover'], xaxis=None, yaxis=None,\n# show_grid=False, show_frame=False, width=500, height=500,\n# color_index='das', colorbar=True, toolbar='above', line_color='white')\n\n\nhv.Layout([ts.opts(width=400, height=300).relabel(name + \": \" + lookup.loc[name][0]) for name, ts in zip(hcodes,outs)]).opts(\n opts.Tiles(xaxis=None, yaxis=None, width=100, height=100)).cols(3)\n\n\n\n\n\n \n\n\nWetlands\n\n\n\n# import matplotlib.pyplot as plt\n# import cartopy.crs as ccrs\n\n# from cartopy.io.img_tiles import Stamen\n\n\n# tiler = Stamen('terrain-background')\n# mercator = tiler.crs\n\n# # df = df.set_index('sitecode')\n\n# def plot_fig(hcodes):\n# for h in hcodes:\n# fig = plt.figure(figsize=(10,8))\n# ax = fig.add_subplot(1, 1, 1, projection=mercator)\n# ax.set_extent([-15, 37, 34, 71], crs=ccrs.PlateCarree())\n\n# ax.add_image(tiler, 6, alpha=0.8)\n# ax.coastlines('10m',color='grey', )\n# df[df[h] ==1].plot(ax=ax, color='red', linewidth=0.5) # column='n_pr_hb', ax=ax, categorical=True, legend=True, cmap='red')\n\n \n# plt.title(h + ': ' + lookup.loc[h][0])\n# fig.savefig(dpath / f'../habitats/habitat_{h}.png', dpi=300)\n\n\n#plot_fig(hcodes)\n\n\n# fig = plt.figure(figsize=(15,13))\n# ax = fig.add_subplot(1, 1, 1, projection=mercator)\n# ax.set_extent([-15, 38, 34, 72], crs=ccrs.PlateCarree())\n\n# ax.add_image(tiler, 6, alpha=0.8)\n\n# df.plot(column='n_pr_hb', ax=ax, categorical=True, legend=True, cmap='jet')\n\n# #ax.coastlines('10m',color='grey')\n# plt.title(\"Count of 'wet' priority habitats in N2K sites\")\n# fig.savefig(dpath / f'../habitats/priority_habitats_count.png', dpi=300)\n\n\n\n\nReusehttps://creativecommons.org/licenses/by/4.0/CitationBibTeX citation:@online{ferrario,\n author = {Ferrario, Iacopo and Ferrario, Iacopo},\n title = {Extended Wetlands Priority Habitats},\n langid = {en}\n}\nFor attribution, please cite this work as:\nFerrario, Iacopo, and Iacopo Ferrario. n.d. “Extended Wetlands\nPriority Habitats.”"
"text": "from pathlib import Path\nimport pandas as pd\n\nimport os\nos.environ['USE_PYGEOS'] = '0'\nimport geopandas as gpd\n\nimport requests\nimport io\n\nimport sys\nif not sys.warnoptions:\n import warnings\n warnings.simplefilter(\"ignore\")\n# import colorcet as cc\nimport datashader as ds\n# import datashader.transfer_functions as tf\n\nimport holoviews as hv\nfrom holoviews.operation.datashader import rasterize\nfrom holoviews import opts\n\nimport geoviews as gv\nimport cartopy.crs as ccrs\n\nfrom spatialpandas import GeoDataFrame\n\nfrom dask import dataframe as dd\n\ngv.extension('bokeh')\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n \n\n\n\n\n\n\n\n\nPrepared plots showing extended wetland priority habitats.\nTried Holoviews/Geoviews/Datashader for interactive plots, they works very well.\nTried jupyterlite and pyodide but there are no wheels available for datashader and co. so micropip was not able to run with them\n\n\nurl = 'https://github.com/iacopoff/iacopoff.github.io/raw/main/data/n2k_extwet_priority_poly_onehot_s.fgb'\n\n\ndn = requests.get(url).content\n\n\ndf = gpd.read_file(io.BytesIO(dn))\n\n\nurl2 = 'https://github.com/iacopoff/iacopoff.github.io/raw/main/data/annex_I_extended_wetlands.csv'\ndn2 = requests.get(url2).content\nlookup = pd.read_csv(io.StringIO(dn2.decode('utf-8'))).set_index('habitatcode')\n\n\nhcodes = df.filter(regex='\\d',axis=1).columns.tolist()\n\n\ndf['n_pr_hb'] = df.filter(regex='\\d',axis=1).sum(axis=1)\n\n\ndf = df.to_crs(3857)\n\n\ndf_sp = GeoDataFrame(df)\n\n\nddf = dd.from_pandas(df_sp, npartitions=10)\n\n\n# cvs = ds.Canvas()\n# tf.shade(cvs.polygons(ddf[ddf['3170'] == 1], geometry='geometry', agg=ds.mean('n_pr_hb')), cmap=cc.kg);\n\n\nbm = hv.element.tiles.EsriUSATopo()\n\n\ndef get_canvas(hcodes, bm):\n out = []\n for h in hcodes:\n out.append(bm * rasterize(hv.Polygons(ddf[ddf[h] == 1], vdims=['sitename','n_pr_hb']), aggregator=ds.mean('n_pr_hb')).opts(\n colorbar=True, cmap='bgy',fontsize={'title':8}))\n return out\n\n\nouts = get_canvas(hcodes, bm)\n\n\n# def compute_partitions(el):\n# n = ddf[ddf['3170'] == 1].cx_partitions[slice(*el.range('x')), slice(*el.range('y'))].npartitions\n# return el.opts(title=f'Population by country (npartitions: {n})')\n\n# bm * out1.apply(compute_partitions).opts(width=700, height=500, tools=[\"hover\"])\n\n\n# opts.Polygons(logz=True, tools=['hover'], xaxis=None, yaxis=None,\n# show_grid=False, show_frame=False, width=500, height=500,\n# color_index='das', colorbar=True, toolbar='above', line_color='white')\n\n\n\nhv.Layout([ts.opts(width=400, height=300).relabel(name + \": \" + lookup.loc[name][0]) for name, ts in zip(hcodes,outs)]).opts(\n opts.Tiles(xaxis=None, yaxis=None, width=100, height=100)).cols(3)\n\n?(caption)\n\n\n\n\n \n\n\n(a) Wetlands\n\n\nFigure 1: ?(caption)\n\n\n\n# import matplotlib.pyplot as plt\n# import cartopy.crs as ccrs\n\n# from cartopy.io.img_tiles import Stamen\n\n\n# tiler = Stamen('terrain-background')\n# mercator = tiler.crs\n\n# # df = df.set_index('sitecode')\n\n# def plot_fig(hcodes):\n# for h in hcodes:\n# fig = plt.figure(figsize=(10,8))\n# ax = fig.add_subplot(1, 1, 1, projection=mercator)\n# ax.set_extent([-15, 37, 34, 71], crs=ccrs.PlateCarree())\n\n# ax.add_image(tiler, 6, alpha=0.8)\n# ax.coastlines('10m',color='grey', )\n# df[df[h] ==1].plot(ax=ax, color='red', linewidth=0.5) # column='n_pr_hb', ax=ax, categorical=True, legend=True, cmap='red')\n\n \n# plt.title(h + ': ' + lookup.loc[h][0])\n# fig.savefig(dpath / f'../habitats/habitat_{h}.png', dpi=300)\n\n\n#plot_fig(hcodes)\n\n\n# fig = plt.figure(figsize=(15,13))\n# ax = fig.add_subplot(1, 1, 1, projection=mercator)\n# ax.set_extent([-15, 38, 34, 72], crs=ccrs.PlateCarree())\n\n# ax.add_image(tiler, 6, alpha=0.8)\n\n# df.plot(column='n_pr_hb', ax=ax, categorical=True, legend=True, cmap='jet')\n\n# #ax.coastlines('10m',color='grey')\n# plt.title(\"Count of 'wet' priority habitats in N2K sites\")\n# fig.savefig(dpath / f'../habitats/priority_habitats_count.png', dpi=300)\n\n\n\n\nReusehttps://creativecommons.org/licenses/by/4.0/CitationBibTeX citation:@online{ferrario,\n author = {Ferrario, Iacopo and Ferrario, Iacopo},\n title = {Extended Wetlands Priority Habitats},\n langid = {en}\n}\nFor attribution, please cite this work as:\nFerrario, Iacopo, and Iacopo Ferrario. n.d. “Extended Wetlands\nPriority Habitats.”"
}
]
24 changes: 13 additions & 11 deletions posts/2023-10-31_nb/extwet_priority_habitats.ipynb

Large diffs are not rendered by default.

0 comments on commit 0600175

Please sign in to comment.