xbitinfo.graphics.add_bitinfo_labels

xbitinfo.graphics.add_bitinfo_labels#

xbitinfo.graphics.add_bitinfo_labels(da, info_per_bit, inflevels=None, keepbits=None, 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 data

  • info_per_bit (dict) – Information content of each bit for each variable in da. This is the output from xbitinfo.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 (when transform=ccrs.Geodetic() must be also set via kwargs). Defaults to x_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 (when transform=ccrs.Geodetic() must be also set via kwargs). Defaults to y_dim_name.

  • label_latitude (float or str) – Latitude for the label. Defaults to "center", which uses the mean lat_coord_name.

  • label_latitude_offset (float) – Distance between keepbits = int and x% label. Defaults to 8.

  • kwargs (dict) – Kwargs to be passed to ax.text and ax.plot. Use transform=ccrs.Geodetic() when using cartopy

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]
>>> keepbits = None
>>> 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()  
<matplotlib.collections.QuadMesh object at ...>
>>> add_bitinfo_labels(
...     diff, info_per_bit, inflevels, keepbits
... )  

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  
>>> fig, axis = plt.subplots(  
...     1, 1, subplot_kw=dict(projection=ccrs.PlateCarree())
... )
>>> (ds - ds_bitrounded_along_lon)[v].isel(time=-10).plot(
...     ax=axis, transform=ccrs.PlateCarree()
... )  
>>> 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(),
... )