Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 141 #142

Merged
merged 11 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ New features and enhancements
* Logo plotting now supports both PNG and SVG file types (via `cairosvg`). (:pull:`119`).
* Use small geojson in the notebook. (:pull:`124`).
* Add the Colours of Figanos page (:issue:`126`, :pull:`127`).
* `figanos` now adheres to PEPs 517/518/621 using the `flit` backend for building and packaging. (:pull:`135`).
* New function ``fg.matplotlib.partition``. (:pull:`134`).
* Figanos now adheres to PEPs 517/518/621 using the `flit` backend for building and packaging. (:pull:`135`).
* New function ``fg.partition`` (:pull:`134`).
* Add wrapper around ``xarray.plot.facetgrid`` for map functions (``fg.gridmap``, ``fg.scattermap``, ``fg.hatchmap``). (:issue:`51`, :pull:`136`).
* `figanos` now uses `Semantic Versioning v2.0 <https://semver.org/spec/v2.0.0.html>`_. (:pull:`143`).

Bug fixes
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Need help?
usage
notebooks/figanos_docs
notebooks/figanos_colours
notebooks/figanos_multiplots
api
contributing
authors
Expand Down
79 changes: 43 additions & 36 deletions docs/notebooks/figanos_docs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@
"\n",
"# Plotting with a custom logo, resized with pixels\n",
"fg.utils.plot_logo(\n",
" ax, \n",
" ax,\n",
" logo=\"my_custom_logo\",\n",
" loc='lower right',\n",
" width=100,\n",
Expand Down Expand Up @@ -631,14 +631,17 @@
"attrs = {'units': 'degC', 'standard_name': 'air_temperature', 'long_name': 'Near-Surface Daily Maximum Air Temperature'}\n",
"\n",
"tas = xr.DataArray(data=tas,\n",
" coords={'station': names, 'lat':('station', lat), 'lon': ('station', lon)},\n",
" coords={\n",
" 'station': names,\n",
" 'lat':('station', lat),\n",
" 'lon': ('station', lon),\n",
" 'years': ('station', yrs),\n",
" },\n",
" dims=['station'],\n",
" attrs=attrs)\n",
"years = tas.copy().assign_attrs({'long_name': \"Number of years of observations\", 'units': 'years'})\n",
"\n",
"years.data = yrs\n",
"\n",
"obs = xr.Dataset({'tas': tas, 'years': years})\n",
"tas.name = 'tas'\n",
"tas = tas.to_dataset()\n",
"tas.attrs[\"description\"] = \"Observations\"\n",
"\n",
"#set nice features\n",
"features = {\"land\": {\"color\": \"#f0f0f0\"},\n",
Expand All @@ -648,17 +651,19 @@
"}\n",
"\n",
"# plot\n",
"ax =fg.scattermap(obs,\n",
"ax =fg.scattermap(tas,\n",
" transform=ccrs.PlateCarree(),\n",
" sizes='years',\n",
" sizes ='years',\n",
" size_range=(15, 100),\n",
" divergent=23.5,\n",
" features=features,\n",
" plot_kw={\n",
" \"xlim\": (-78,-68),\n",
" \"ylim\": (43,50)},\n",
" fig_kw={'figsize': (9,6)},\n",
" legend_kw={'loc': 'lower left'},\n",
" )\n",
"ax.set_xlim(-78,-68)\n",
"ax.set_ylim(43,50)\n"
" legend_kw={'loc': 'lower left',\n",
" 'title': 'Number of years of data'},\n",
" )"
]
},
{
Expand Down Expand Up @@ -689,10 +694,12 @@
"ax.set_extent([-76.5, -69, 44.5, 52], crs=ccrs.PlateCarree()) # equivalent to set_xlim and set_ylim for projections\n",
"\n",
"# plotting the observations\n",
"fg.scattermap(obs,\n",
"fg.scattermap(tas,\n",
" ax=ax,\n",
" transform=ccrs.PlateCarree(),\n",
" plot_kw={'vmin': vmin, 'vmax': vmax, 'edgecolors':'grey'}\n",
" plot_kw={'vmin': vmin,\n",
" 'vmax': vmax,\n",
" 'edgecolor':'grey'}\n",
" )"
]
},
Expand Down Expand Up @@ -723,14 +730,13 @@
" 'https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/dodsC/birdhouse/ouranos/portraits-clim-1.1/IPSL-CM5B-LR_rcp85_prcptot_monthly.nc',\n",
" ]\n",
"ens = ensembles.create_ensemble(urls)\n",
"fut = ens.sel(time=slice(\"2020\", \"2050\"))\n",
"ref = ens.sel(time=slice(\"1990\", \"2020\"))\n",
"delta = fut.mean(\"time\") - ref.mean(\"time\")\n",
"chng_f, pos_f = ensembles.change_significance(\n",
" delta, test=\"threshold\", abs_thresh=2\n",
")\n",
"sup_8 = chng_f.where(chng_f.prcptot>0.8)\n",
"inf_5 = chng_f.where(chng_f.prcptot<0.5)\n",
"fut = ens.sel(time=slice(\"2020\", \"2050\")).prcptot\n",
"ref = ens.sel(time=slice(\"1990\", \"2020\")).prcptot\n",
"chng_f= ensembles.robustness_fractions(\n",
" fut, ref, test=\"threshold\", abs_thresh=2\n",
").changed\n",
"sup_8 = chng_f.where(chng_f>0.8)\n",
"inf_5 = chng_f.where(chng_f<0.5)\n",
"\n",
"ens_stats = ensembles.ensemble_mean_std_max_min(ens)\n",
"\n",
Expand All @@ -743,12 +749,6 @@
"ax.set_title('Ensemble plot - hatchmap and gridmap')"
]
},
{
"cell_type": "markdown",
"id": "71cfc95e",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"id": "8936d047",
Expand Down Expand Up @@ -1025,14 +1025,14 @@
"## Partition plots\n",
"\n",
"Partition plots show the fraction of uncertainty associated with different components.\n",
"Xclim has a few different [partition functions](https://xclim.readthedocs.io/en/stable/api.html#uncertainty-partitioning). \n",
"Xclim has a few different [partition functions](https://xclim.readthedocs.io/en/stable/api.html#uncertainty-partitioning).\n",
"\n",
"This tutorial is a reproduction of [xclim's documentation](https://xclim.readthedocs.io/en/stable/notebooks/partitioning.html).\n",
"\n",
"<div class=\"alert alert-info\">\n",
" \n",
"\n",
"Note that you could also use the [xscen library](https://xscen.readthedocs.io/en/latest/index.html) to build and ensemble from a catalog with `xscen.ensembles.build_partition_data`.\n",
" \n",
"\n",
"</div>"
]
},
Expand Down Expand Up @@ -1079,7 +1079,7 @@
" .rename(date=\"time\")\n",
" )\n",
" data.append(da)\n",
" \n",
"\n",
"# Combine DataArrays from the different models and scenarios into one.\n",
"ens_mon = xr.combine_by_coords(data)[\"world\"]\n",
"\n",
Expand Down Expand Up @@ -1128,8 +1128,7 @@
" return uncertainty\n",
"\n",
"frac= fractional_uncertainty(uncertainties)\n",
"\n",
" "
"\n"
]
},
{
Expand All @@ -1149,8 +1148,16 @@
" \"model\": {'color':\"#2B2B8B\"},\n",
" \"scenario\": {'color':\"#275620\"},},\n",
" line_kw={'lw':2}\n",
")"
")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "75349096",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading