Skip to content

Commit

Permalink
implement decimal year
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 committed Apr 4, 2024
1 parent 1532818 commit 476d108
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions notebooks/wp5/glacier_distribution.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@
" date = years + months + days\n",
" date = date.where(~date.str.startswith(\"-\"))\n",
" columns.append(pd.to_datetime(date))\n",
"gdf[\"year\"] = pd.DataFrame(columns).mean().dt.year.astype(\"Int64\")"
"dates = pd.DataFrame(columns).mean()\n",
"gdf[\"decimal_year\"] = dates.year + (dates.dayofyear - 1) / (364 + dates.is_leap_year)\n",
"gdf[\"year\"] = dates.dt.year.astype(\"Int64\")"
]
},
{
Expand Down Expand Up @@ -345,7 +347,9 @@
"grouped = gdf[[\"year\", \"AREA\", \"region\"]].groupby(\"region\")\n",
"means = {\n",
" \"arithmetic\": grouped[\"year\"].mean(),\n",
" \"weighted\": grouped.apply(weighted_average, \"year\", \"AREA\", include_groups=False),\n",
" \"weighted\": grouped.apply(\n",
" weighted_average, \"decimal_year\", \"AREA\", include_groups=False\n",
" ),\n",
"}\n",
"text = []\n",
"for label, mean in means.items():\n",
Expand Down

0 comments on commit 476d108

Please sign in to comment.