Skip to content

Commit 37b2c4b

Browse files
authored
More unit definitions from xclim (#284)
1 parent 04ebf64 commit 37b2c4b

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

cf_xarray/units.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def repl(m):
6060
except ImportError:
6161
pass
6262

63-
63+
# ------
6464
# Reused with modification from MetPy under the terms of the BSD 3-Clause License.
6565
# Copyright (c) 2015,2017,2019 MetPy Developers.
6666
# Create registry, with preprocessors for UDUNITS-style powers (m2 s-2) and percent signs
@@ -83,13 +83,29 @@ def repl(m):
8383
)
8484

8585
# Define commonly encountered units (both CF and non-CF) not defined by pint
86+
units.define("@alias meter = gpm")
87+
# ----- end block copied from metpy
88+
89+
# -----
90+
# The following redefinitions were copied from xclim under the terms of their Apache-2 license
91+
# In pint, the default symbol for year is "a" which is not CF-compliant (stands for "are")
92+
units.define("year = 365.25 * day = yr")
93+
94+
# Define commonly encountered units not defined by pint
95+
units.define("@alias degC = C = deg_C")
96+
units.define("@alias degK = deg_K")
97+
units.define("@alias day = d")
98+
units.define("@alias hour = h") # Not the Planck constant...
8699
units.define(
87-
"degrees_north = degree = degrees_N = degreesN = degree_north = degree_N = degreeN"
100+
"degrees_north = degree = degrees_north = degrees_N = degreesN = degree_north = degree_N = degreeN"
88101
)
89102
units.define(
90-
"degrees_east = degree = degrees_E = degreesE = degree_east = degree_E = degreeE"
103+
"degrees_east = degree = degrees_east = degrees_E = degreesE = degree_east = degree_E = degreeE"
91104
)
92-
units.define("@alias meter = gpm")
105+
units.define("[speed] = [length] / [time]")
106+
# ----- end block copied from xclim
107+
108+
# Add other specific aliases (by cf_xarray developers)
93109
units.define("practical_salinity_unit = [] = psu = PSU")
94110

95111
# Enable pint's built-in matplotlib support

0 commit comments

Comments
 (0)