diff --git a/notebooks/wp3/bias_assessment.ipynb b/notebooks/wp3/bias_assessment.ipynb index c611b2e..21b9bb3 100644 --- a/notebooks/wp3/bias_assessment.ipynb +++ b/notebooks/wp3/bias_assessment.ipynb @@ -87,6 +87,7 @@ "}\n", "\n", "# Regions\n", + "defined_regions_module_name = \"ar6.land\"\n", "regions = [\n", " \"CAR\",\n", " \"ENA\",\n", @@ -97,8 +98,6 @@ " \"SEA\",\n", " \"WNA\",\n", "]\n", - "defined_regions = regionmask.defined_regions.ar6.land\n", - "assert set(regions) <= set(defined_regions.abbrevs)\n", "\n", "# Ploting settings\n", "plot_kwargs = {\n", @@ -121,6 +120,16 @@ "metadata": {}, "outputs": [], "source": [ + "def get_defined_regions(defined_regions_module_name):\n", + " defined_regions = regionmask.defined_regions\n", + " for module in defined_regions_module_name.split(\".\"):\n", + " defined_regions = getattr(defined_regions, module)\n", + " return defined_regions\n", + "\n", + "\n", + "defined_regions = get_defined_regions(defined_regions_module_name)\n", + "assert set(regions) <= set(defined_regions.abbrevs)\n", + "\n", "ax = defined_regions[regions].plot(\n", " projection=ccrs.Robinson(),\n", " label=\"abbrev\",\n", @@ -183,8 +192,9 @@ "outputs": [], "source": [ "def regionalised_spatial_weighted_mean(\n", - " ds, region, defined_regions, weights, mean_dims=None\n", + " ds, region, defined_regions_module_name, weights, mean_dims=None\n", "):\n", + " defined_regions = get_defined_regions(defined_regions_module_name)\n", " mask = defined_regions.mask(ds)\n", " index = defined_regions.map_keys(region)\n", " ds = ds.where((mask == index).compute(), drop=True)\n", @@ -363,7 +373,7 @@ " transform_func=regionalised_spatial_weighted_mean,\n", " transform_func_kwargs={\n", " \"region\": region,\n", - " \"defined_regions\": defined_regions,\n", + " \"defined_regions_module_name\": defined_regions_module_name,\n", " \"weights\": True,\n", " },\n", " )\n", @@ -410,7 +420,7 @@ " transform_func=regionalised_spatial_weighted_mean,\n", " transform_func_kwargs={\n", " \"region\": region,\n", - " \"defined_regions\": defined_regions,\n", + " \"defined_regions_module_name\": defined_regions_module_name,\n", " \"weights\": True,\n", " \"mean_dims\": (\"realization\",),\n", " },\n",