Skip to content

Commit

Permalink
fix glacier
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 committed Apr 19, 2024
1 parent caeab2c commit 352762e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions notebooks/wp5/glacier_mass_balance_maps.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
"source": [
"import fsspec\n",
"import geopandas as gpd\n",
"import matplotlib.colors as mcolors\n",
"import matplotlib.pyplot as plt\n",
"import xarray as xr\n",
"from c3s_eqc_automatic_quality_control import download\n",
"\n",
"plt.style.use(\"seaborn-v0_8-notebook\")"
Expand Down Expand Up @@ -95,9 +97,10 @@
"metadata": {},
"outputs": [],
"source": [
"def sum_and_add_trends(ds):\n",
" da = ds[\"Glacier\"]\n",
" cumsum = da.cumsum(\"time\", keep_attrs=True).drop(\"time\")\n",
"def compute_sum_uncertainty_slope_and_acceleration(ds):\n",
" with xr.set_options(keep_attrs=True):\n",
" cumsum = ds[\"Glacier\"].cumsum(\"time\").drop_vars(\"time\")\n",
" ds[\"Uncertainty\"] = (ds[\"Uncertainty\"] ** 2).sum(\"time\") ** 1 / 2\n",
"\n",
" # Sum\n",
" ds = ds.sum(\"time\", keep_attrs=True)\n",
Expand Down Expand Up @@ -142,7 +145,7 @@
" collection_id,\n",
" request,\n",
" chunks={\"hydrological_year\": 1},\n",
" transform_func=sum_and_add_trends,\n",
" transform_func=compute_sum_uncertainty_slope_and_acceleration,\n",
" transform_chunks=False,\n",
")\n",
"# Customize some attributes\n",
Expand Down Expand Up @@ -231,8 +234,7 @@
"column_kwargs = {\n",
" \"Glacier\": {\n",
" \"cmap\": \"coolwarm_r\",\n",
" \"vmin\": -5,\n",
" \"vmax\": 5,\n",
" \"norm\": mcolors.TwoSlopeNorm(vmin=-5, vcenter=0, vmax=2),\n",
" \"label\": \"Cumulative mass change (Gt)\",\n",
" \"title\": \"Cumulative glacier mass change\",\n",
" },\n",
Expand Down Expand Up @@ -281,7 +283,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"version": "3.11.8"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 352762e

Please sign in to comment.