Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 committed Apr 2, 2024
1 parent 96f89cd commit 27cdf4e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 301 deletions.
33 changes: 27 additions & 6 deletions notebooks/wp5/glacier_distribution.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,18 @@
" ds.to_pandas(),\n",
" geometry=gpd.points_from_xy(ds[\"CENLON\"], ds[\"CENLAT\"]),\n",
" crs=\"EPSG:4326\",\n",
")"
")\n",
"\n",
"# Convert dates from string to datetime, and add digitalization year\n",
"columns = []\n",
"for column in (\"BGNDATE\", \"ENDDATE\"):\n",
" years = gdf[column].str[:4]\n",
" months = gdf[column].str[4:6].replace(\"99\", \"01\")\n",
" days = gdf[column].str[6:8].replace(\"99\", \"01\")\n",
" series = years + months + days\n",
" series = series.where(~series.str.startswith(\"-\"))\n",
" columns.append(pd.to_datetime(series))\n",
"gdf[\"year\"] = pd.DataFrame(columns).mean().dt.year.astype(\"Int64\")"
]
},
{
Expand Down Expand Up @@ -180,12 +191,22 @@
"metadata": {},
"outputs": [],
"source": [
"year = pd.DataFrame(\n",
" [gdf[\"BGNDATE\"].str[:4].astype(int), gdf[\"ENDDATE\"].str[:4].astype(int)]\n",
")\n",
"gdf[\"year\"] = year.where(year > 0).mean().round().astype(\"Int64\")\n",
"size = gdf.set_index(\"year\").groupby(\"year\").size()\n",
"ax = size.plot.bar(figsize=(15, 5), grid=True, ylabel=\"Number of glaciers\")"
"size = size.reindex(range(gdf[\"year\"].min(), gdf[\"year\"].max()), fill_value=0)\n",
"missing = gdf[\"year\"].isnull().sum()\n",
"missing_perc = 100 * (missing / len(gdf[\"year\"]))\n",
"ax = size.plot.bar(\n",
" figsize=(15, 5),\n",
" grid=True,\n",
" ylabel=\"Number of glaciers\",\n",
")\n",
"_ = ax.text(\n",
" 0,\n",
" 1,\n",
" f\"Date of digitization data are missing for {missing} glaciers or {missing_perc:.2f}% of the dataset.\",\n",
" transform=ax.transAxes,\n",
" bbox={\"facecolor\": \"white\", \"edgecolor\": \"black\"},\n",
")"
]
},
{
Expand Down
295 changes: 0 additions & 295 deletions notebooks/wp5/glacier_distribution_template.ipynb

This file was deleted.

0 comments on commit 27cdf4e

Please sign in to comment.