xbitinfo.graphics.add_bitinfo_labels
xbitinfo.graphics.add_bitinfo_labels#
- xbitinfo.graphics.add_bitinfo_labels(da, info_per_bit, inflevels, ax=None, x_dim_name='lon', y_dim_name='lat', lon_coord_name='guess', lat_coord_name='guess', label_latitude='center', label_latitude_offset=8, **kwargs)[source]#
Helper function for visualization of Figure 3 in Klöwer et al. 2021. Adds latitudinal lines and labels with keepbits and information content for each slice.
Klöwer, M., Razinger, M., Dominguez, J. J., Düben, P. D., & Palmer, T. N. (2021). Compressing atmospheric data into its real information content. Nature Computational Science, 1(11), 713–724. doi: 10/gnm4jj
- Parameters
da (
xarray.DataArray()
) – Plotted datainfo_per_bit (dict) – Information content of each bit for each variable in
da
. This is the output fromxbitinfo.xbitinfo.get_bitinformation()
.inflevels (list of floats) – Level of information that shall be preserved.
ax (plt.Axes or None) – Axes. If
None
, get current axis.x_dim_name (str) – Name of the x dimension. Defaults to
"lon"
.y_dim_name (str) – Name of the y dimension. Defaults to
"lat"
.lon_coord_name (str) – Name of the longitude coordinate. Only matters when plotting with multi-dimensional coordinates (i.e. curvilinear grids) with
cartopy
(whentransform=ccrs.Geodetic()
must be also set viakwargs
). Defaults tox_dim_name
.lat_coord_name (str) – Name of the latitude coordinate. Only matters when plotting with multi-dimensional coordinates (i.e. curvilinear grids) with
cartopy
(whentransform=ccrs.Geodetic()
must be also set viakwargs
). Defaults toy_dim_name
.label_latitude (float or str) – Latitude for the label. Defaults to
"center"
, which uses the meanlat_coord_name
.label_latitude_offset (float) – Distance between
keepbits = int
andx%
label. Defaults to8
.kwargs (dict) – Kwargs to be passed to
ax.text
andax.plot
. Usetransform=ccrs.Geodetic()
when usingcartopy
Example
Plotting a single-dimension coordinate dataset: >>> ds = xr.tutorial.load_dataset(“air_temperature”) >>> info_per_bit = xb.get_bitinformation(ds, dim=”lon”) >>> inflevels = [1.0, 0.9999, 0.99, 0.975, 0.95] >>> ds_bitrounded_along_lon = xb.bitround.bitround_along_dim( … ds, info_per_bit, dim=”lon”, inflevels=inflevels … ) >>> diff = (ds - ds_bitrounded_along_lon)[“air”].isel(time=0) >>> diff.plot() # doctest: +ELLIPSIS <matplotlib.collections.QuadMesh object at …> >>> add_bitinfo_labels(diff, info_per_bit, inflevels) # doctest: +ELLIPSIS
Plotting a multi-dimensional coordinate dataset >>> v = “Tair” >>> ds = xr.tutorial.load_dataset(“rasm”) >>> dim = “y” >>> info_per_bit = xb.get_bitinformation(ds, dim=dim) >>> ds_bitrounded_along_lon = xb.bitround.bitround_along_dim( … ds, info_per_bit, dim=dim, inflevels=inflevels … ) >>> import cartopy.crs as ccrs # doctest: +SKIP >>> fig, axis = plt.subplots( # doctest: +SKIP … 1, 1, subplot_kw=dict(projection=ccrs.PlateCarree()) … ) >>> (ds - ds_bitrounded_along_lon)[v].isel(time=-10).plot( … ax=axis, transform=ccrs.PlateCarree() … ) # doctest: +SKIP >>> add_bitinfo_labels( … (ds - ds_bitrounded_along_lon)[v].isel(time=0), … lon_coord_name=”xc”, … lat_coord_name=”yc”, … x_dim_name=”x”, … y_dim_name=”y”, … transform=ccrs.Geodetic(), … ) # doctest: +SKIP