Featured paper: Graphical Abstract ¶
Alexander Dunkel, Leibniz Institute of Ecological Urban and Regional Development,
Transformative Capacities & Research Data Centre (IÖR-FDZ)
Publication:
Dunkel, A., Burghardt, D. (2024). Assessing perceived landscape change from opportunistic spatio-temporal occurrence data. Land 2024
This notebook creates the graphical abstract for use as featured paper in LAND (13/7)
Preparations¶
We first want to get a globe view of all coordinates under investigation in the paper. For this, we use geoplot.
We can update our base worker_env
with this package.
!../py/modules/base/pkginstall.sh "geoplot alphashape"
import sys
import warnings
import alphashape
from pathlib import Path
import matplotlib.pyplot as plt
import pandas as pd
import geopandas as gp
import cartopy
import seaborn as sns
import geoplot
import geoplot.crs as gcrs
from matplotlib.patches import Patch
from matplotlib.lines import Line2D
import matplotlib.patches as mpatches
module_path = str(Path.cwd().parents[0] / "py")
if module_path not in sys.path:
sys.path.append(module_path)
from modules.base import tools, hll
from modules.base.hll import union_hll, cardinality_hll
%load_ext autoreload
%autoreload 2
OUTPUT = Path.cwd().parents[0] / "out" # output directory for figures (etc.)
WORK_DIR = Path.cwd().parents[0] / "tmp" # Working directory
(OUTPUT / "figures").mkdir(exist_ok=True)
(OUTPUT / "svg").mkdir(exist_ok=True)
WORK_DIR.mkdir(exist_ok=True)
DATA_FOLDER = Path.cwd().parents[0] / "00_data"
CRS_WGS = "epsg:4326" # WGS1984
plt.rcParams['font.family'] = 'serif'
plt.rcParams['font.serif'] = ['Times New Roman'] + plt.rcParams['font.serif']
Create globe¶
world = tools.get_shapes("world", shape_dir=OUTPUT / "shapes")
world.crs
Create a globe that covers USA and Europe, where most case studies are located
with warnings.catch_warnings():
# catch extent warning, which will always be trigged with Orthographic/worldwide data
warnings.simplefilter("ignore")
ax = geoplot.polyplot(world, projection=gcrs.Orthographic(central_latitude=50, central_longitude=-35), figsize=(10, 5), edgecolor='black', linewidth=0.2)
ax.set_global()
ax.add_feature(cartopy.feature.LAND, edgecolor='gray', facecolor='lightblue', alpha=0.2)
ax.spines['geo'].set_visible(True)
# ax.outline_patch.set_visible(True)
Load locations for Case Studies¶
df = pd.read_csv(DATA_FOLDER / "list.csv")
df.head()
df.columns
cs = gp.GeoDataFrame(
df, geometry=gp.points_from_xy(df.longitude, df.latitude), crs=CRS_WGS)
cs.head()
df_hotspots = gp.read_file(
Path.cwd().parents[0] / "00_data" / "hotspots" / "hotspots2021.shp")
df_4 = df_hotspots.geometry.centroid.to_crs(CRS_WGS)
gdf_4 = gp.GeoDataFrame(df_4)
gdf_4.set_geometry(0, inplace=True)
gdf_4.rename_geometry("geometry", inplace=True)
gdf_4["latitude"] = gdf_4.geometry.y
gdf_4["longitude"] = gdf_4.geometry.x
gdf_4["casestudy"] = "Case Study 4"
cs = pd.concat([cs, gdf_4])
cs.tail()
Get alphashapes¶
cs_1_a = alphashape.alphashape(cs[cs["casestudy"]=="Case Study 1"], 0.)
cs_2_a = alphashape.alphashape(cs[cs["casestudy"]=="Case Study 2"], 0.)
cs_4_a = alphashape.alphashape(cs[cs["casestudy"]=="Case Study 4"], 0.)
cs_5_a = gp.read_file(
OUTPUT/ 'Milvusmilvus_range.gpkg', layer='Milvus milvus')
Chose any of the great color palettes from seaborn: https://seaborn.pydata.org/generated/seaborn.color_palette.html
colors=sns.color_palette("Spectral", as_cmap=True)
colors
legend_kwds = {
"bbox_to_anchor": (1.0, 1),
"loc":'upper left',
"fontsize":10, "frameon":False,
"title":"Location of Case Studies", "title_fontsize":12,
"alignment":"left"}
plt_kwds = {
"projection":gcrs.Orthographic(central_latitude=50, central_longitude=-35), # projection and center focus
}
def add_patch(legend):
ax = legend.axes
handles, labels = ax.get_legend_handles_labels()
handles.append(Patch(facecolor='orange', edgecolor='r'))
labels.append("Color Patch")
legend._legend_box = None
legend._init_legend_box(handles, labels)
legend._set_loc(legend._loc)
legend.set_title(legend.get_title().get_text())
Create plot¶
with warnings.catch_warnings():
# catch extent warning, which will always be trigged with Orthographic/worldwide data
warnings.simplefilter("ignore")
ax = geoplot.polyplot(
world, figsize=(10, 5), edgecolor='black',
linewidth=0.2, **plt_kwds)
pt_kwds = {
"marker":'.',
"s":5,
}
alpha_shapes_kwds = {
"edgecolor":'None',
"alpha":0.2
}
ax = geoplot.polyplot(
cs_5_a, ax=ax, facecolor=colors(0.2), edgecolor='None', alpha=0.4,
**plt_kwds)
ax = geoplot.polyplot(
cs_1_a, ax=ax, facecolor=colors(0.0),
**plt_kwds, **alpha_shapes_kwds)
ax = geoplot.polyplot(
cs_2_a, ax=ax, facecolor=colors(1.0),
**plt_kwds, **alpha_shapes_kwds)
ax = geoplot.polyplot(
cs_4_a, ax=ax, facecolor=colors(0.5), edgecolor='None', alpha=1.0,
**plt_kwds)
ax = geoplot.pointplot(
cs[cs["casestudy"]=="Case Study 2"],
ax=ax, color=colors(1.0), **pt_kwds, **plt_kwds)
ax = geoplot.pointplot(
cs[cs["casestudy"]=="Case Study 4"],
ax=ax, color=colors(0.5), alpha=0.5, **pt_kwds, **plt_kwds)
ax = geoplot.pointplot(
cs[cs["casestudy"]=="Case Study 1"],
ax=ax, color=colors(0.0), **pt_kwds, **plt_kwds)
# manually create legend
cs1_patch = plt.scatter([], [], label='Case Study 1', color=colors(0.0), s=12)
cs2_patch = plt.scatter([], [], label='Case Study 2', color=colors(1.0), s=12)
cs3_patch = Line2D([0], [0], label='Case Study 3', color=colors(0.8), linewidth=2)
cs4_patch = plt.scatter([], [], label='Case Study 4', color=colors(0.5), edgecolor="grey", linewidth=0.25, s=25)
cs5_patch = mpatches.Patch(color=colors(0.2), label='Case Study 5', alpha=0.4)
plt.legend(handles=[cs1_patch, cs2_patch, cs3_patch, cs4_patch, cs5_patch], **legend_kwds)
# Add l1 as a separate artist to the axes
ax.set_global()
ax.add_feature(
cartopy.feature.LAND, edgecolor='gray',
facecolor='lightblue', alpha=0.2)
ax.gridlines(alpha=0.4)
ax.spines['geo'].set_visible(True)
ax.spines['geo'].set_edgecolor(colors(0.8))
ax.spines['geo'].set_linewidth(2)
fig = ax.get_figure()
tools.save_fig(fig, output=OUTPUT, name="overview")
Create notebook HTML¶
!jupyter nbconvert --to html_toc \
--output-dir=../resources/html/ ./11_graphical_abstract.ipynb \
--template=../nbconvert.tpl \
--ExtractOutputPreprocessor.enabled=False >&- 2>&-