polaris.analysis.units.units_to_mathtext

polaris.analysis.units.units_to_mathtext(units)[source]

Render a CF units string as matplotlib text

Parameters:

units (str) – The units attribute of a field, e.g. kg m-2 s-1, m/s or degree_C. A string that is already mathtext, with $ in it, is returned as it is.

Returns:

text (str) – The units with each exponent as a superscript, e.g. kg m$^{-2}$ s$^{-1}$, and a dimensionless quantity as an empty string. A factor that is not recognized is left as it was.