Skip to content

Commit 381af61

Browse files
added get_unit_type function
1 parent 9a68d75 commit 381af61

File tree

4 files changed

+287
-0
lines changed

4 files changed

+287
-0
lines changed

NUCOS_unit_list.txt

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
NUCOS Unit List
2+
3+
The NOAA Unit Converter for Oil Spills (NUCOS) is designed specifically to support
4+
oils spill response and planning. As the Oil industry (and the response community)
5+
use some unusual units, this is NOT a general purpose or full featured unit converter.
6+
However, it does try to include all the units that one might need for oil spill work.
7+
8+
Complete unit type, units, and synonym list:
9+
10+
Note that in NUCOS, unit names and synonyms are case and white space insensitive, so, eg:
11+
12+
"Pounds per Cubic Foot" is the same as "poundspercubicfoot"
13+
14+
All The Units:
15+
16+
Length:
17+
meter: “meter”, “m”, “meters”, “metre”
18+
centimeter: “centimeter”, “cm”, “centimeters”
19+
millimeter: “millimeter”, “mm”, “millimeters”
20+
micron: “micron”, “µm”, “micrometer”, “microns”
21+
kilometer: “kilometer”, “km”, “kilometers”
22+
foot: “foot”, “ft”, “feet”
23+
inch: “inch”, “in”, “inches”
24+
yard: “yard”, “yd”, “yards”
25+
mile: “mile”, “mi”, “miles”
26+
nautical mile: “nautical mile”, “nm”, “nauticalmiles”
27+
fathom: “fathom”, “fthm”, “fathoms”
28+
latitude degree: “latitude degree”, “latitudedegrees”
29+
latitude minute: “latitude minute”, “latitudeminutes”
30+
31+
Oil Concentration:
32+
micron: “micron”, “µm”, “microns”, “micrometer”
33+
cubic meter per square kilometer: “cubic meter per square kilometer”, “m³/km²”, “m^3/km^2”
34+
millimeter: “millimeter”, “mm”, “millimeters”
35+
inch: “inch”, “in”, “inches”
36+
barrel per acre: “barrel per acre”, “bbl/acre”
37+
barrel per square mile: “barrel per square mile”, “bbl/mile²”, “bbl/sq.mile”
38+
gallon per acre: “gallon per acre”, “gal/acre”
39+
liter per hectare: “liter per hectare”, “l/hectare”, “liter/hectare”
40+
liter per square meter: “liter per square meter”, “l/m²”, “l/m^2”
41+
gram per square meter: “gram per square meter”, “g/m²”, “g/m^2”
42+
kilogram per square meter: “kilogram per square meter”, “kg/m²”, “kg/m^2”
43+
kilogram per square kilometer: “kilogram per square kilometer”, “g/km²”, “kg/km^2”
44+
45+
Area:
46+
square meter: “square meter”, “m²”, “m^2”, “sq m”
47+
square centimeter: “square centimeter”, “cm²”, “cm^2”, “sq cm”
48+
square kilometer: “square kilometer”, “km²”, “km^2”, “sq km”
49+
acre: “acre”, “ac”, “acres”
50+
square mile: “square mile”, “sq miles”
51+
square nautical mile: “square nautical mile”, “nm²”, “sq nm”, “nm^2”
52+
square yard: “square yard”, “yd²”, “sq yards”, “square yards”
53+
square foot: “square foot”, “ft²”, “ft^2”, “sq foot”, “square feet”
54+
square inch: “square inch”, “in²”, “in^2”, “sq inch”, “square inches”
55+
hectare: “hectare”, “ha”, “hectares”
56+
57+
Volume:
58+
cubic meter: “cubic meter”, “m³”, “m^3”, “cu m”, “cubic meters”
59+
cubic kilometer: “cubic kilometer”, “km³”, “km^3”, “cu km”, “cubic kilometers”
60+
cubic centimeter: “cubic centimeter”, “cm³”, “cm^3”, “cu cm”, “cc”
61+
milliliter: “milliliter”, “ml”, “milliters”
62+
barrel (petroleum): “barrel (petroleum)”, “bbl”, “barrels”, “barrel”, “bbls”
63+
liter: “liter”, “l”, “liters”
64+
gallon: “gallon”, “gal”, “gallons”, “usgal”
65+
gallon (UK): “gallon (UK)”, “ukgal”, “gallons(uk)”
66+
million US gallon: “million US gallon”, “milgal”, “milliongallons”
67+
cubic foot: “cubic foot”, “ft³”, “ft^3”, “cu feet”, “cubicfeet”
68+
cubic inch: “cubic inch”, “in³”, “in^3”, “cu inch”, “cubicinches”
69+
cubic yard: “cubic yard”, “yd³”, “yd^3”, “cu yard”, “cubicyards”
70+
fluid ounce: “fluid ounce”, “oz”, “ounces(fluid)”, “fluid oz”
71+
fluid ounce (UK): “fluid ounce (UK)”, “ukoz”, “fluid oz(uk)”
72+
73+
Temperature:
74+
Kelvin: “Kelvin”, “K”, “degrees k”, “degree k”, “degrees kelvin”, “degree kelvin”, “deg k”
75+
Celsius: “Celsius”, “°C”, “C”, “degrees c”, “degrees celsius”, “deg c”, “centigrade”
76+
Fahrenheit: “Fahrenheit”, “°F”, “F”, “degrees f”, “degree f”, “degrees fahrenheit”, “deg f”
77+
78+
Delta Temperature:
79+
Kelvin: “Kelvin”, “K”, “degrees k”, “degree k”, “degrees kelvin”, “degree kelvin”, “deg k”
80+
Celsius: “Celsius”, “°C”, “C”, “degrees c”, “degree_c”, “degrees celsius”, “deg c”, “centigrade”
81+
Fahrenheit: “Fahrenheit”, “°F”, “F”, “degrees f”, “degree f”, “degree_f”, “deg f”, “degrees fahrenheit”
82+
83+
Mass:
84+
kilogram: “kilogram”, “kg”, “kilograms”
85+
pound: “pound”, “lb”, “pounds”, “lbs”
86+
gram: “gram”, “g”, “grams”
87+
milligram: “milligram”, “mg”
88+
microgram: “microgram”, “µg”, “ug”
89+
ton (US): “ton (US)”, “ton”, “tons”, “uston”, “short ton”
90+
metric ton (tonne): “metric ton (tonne)”, “mt”, “tonne”, “tonnes”, “metric ton”, “metric tons”
91+
slug: “slug”, “slugs”
92+
ounce: “ounce”, “oz”, “ounces”
93+
ton (UK): “ton (UK)”, “ukton”, “long ton”
94+
95+
Time:
96+
second: “second”, “s”, “sec”, “seconds”
97+
minute: “minute”, “min”, “minutes”
98+
hour: “hour”, “hr”, “hours”, “hrs”
99+
day: “day”, “days”
100+
101+
Velocity:
102+
meter per second: “meter per second”, “m/s”, “meter/sec”, “meter/second”, “meters per second”, “mps”, “meter sec-1”, “meter second-1”, “meter seconds-1”, “meters sec-1”, “meters second-1”, “meters seconds-1”, “m s-1”, “meter s-1”, “meters s-1”
103+
centimeter per second: “centimeter per second”, “cm/s”
104+
meter per minute: “meter per minute”, “m/min”, “meters per minute”
105+
kilometer per hour: “kilometer per hour”, “km/h”, “km/hr”
106+
kilometer per day: “kilometer per day”, “km/day”, “km/d”
107+
knot: “knot”, “kt”, “kn”, “kts”, “knots”
108+
mile per hour: “mile per hour”, “mph”, “miles per hour”
109+
foot per second: “foot per second”, “ft/s”, “ft/sec”, “feet per second”, “feet/s”
110+
foot per minute: “foot per minute”, “ft/min”, “feet per minute”, “feet/min”
111+
foot per hour: “foot per hour”, “ft/hr”, “feet per hour”, “feet/hour”
112+
113+
Discharge:
114+
cubic meter per second: “cubic meter per second”, “m³/s”, “m^3/s”, “cu m/s”, “cms”
115+
cubic meter per min: “cubic meter per min”, “m³/min”, “m^3/min”
116+
cubic meter per hour: “cubic meter per hour”, “m³/hr”, “m^3/hr”
117+
liter per second: “liter per second”, “l/s”, “lps”
118+
liter per minute: “liter per minute”, “l/min”
119+
cubic foot per second: “cubic foot per second”, “ft³/s”, “cfs”, “cu feet/s”, “feet^3/s”
120+
cubic foot per minute: “cubic foot per minute”, “ft³/min”, “ft^3/min”
121+
gallon per day: “gallon per day”, “gal/day”
122+
gallon per hour: “gallon per hour”, “gal/hr”
123+
gallon per minute: “gallon per minute”, “gal/min”, “gpm”
124+
gallon per second: “gallon per second”, “gal/s”, “gal/sec”
125+
barrel per hour: “barrel per hour”, “bbl/hr”
126+
barrel per day: “barrel per day”, “bbl/day”, “bbl/d”
127+
128+
Mass Discharge:
129+
kilogram per second: “kilogram per second”, “kg/s”
130+
gram per second: “gram per second”, “g/s”
131+
132+
Density:
133+
gram per cubic centimeter: “gram per cubic centimeter”, “g/cm³”, “g/cm^3”, “grams per cubic centimeter”
134+
gram per liter: “gram per liter”, “g/L”, “gram per litre”
135+
kilogram per liter: “kilogram per liter”, “kg/L”, “kilogram per litre”
136+
gram per milliliter: “gram per milliliter”, “g/mL”, “gram per millilitre”
137+
specific gravity (15°C): “specific gravity (15°C)”, “S”, “specificgravity”, “Spec grav”, “SG”, “specificgravity(15C)”
138+
kilogram per cubic meter: “kilogram per cubic meter”, “kg/m³”, “kg/m^3”
139+
tonne per cubic meter: “tonne per cubic meter”, “tonne/m³”, “tonne/m^3”, “t/m^3”, “t/m³”
140+
pound per cubic foot: “pound per cubic foot”, “lb/ft³”, “lbs/ft^3”, “lb/ft^3”
141+
pound per gallon: “pound per gallon”, “lb/gal”, “lbs/gal”
142+
API degree: “API degree”, “api”
143+
144+
Kinematic Viscosity:
145+
Stoke: “Stoke”, “St”, “stokes”
146+
centiStoke: “centiStoke”, “cSt”, “centistokes”
147+
square millimeter per second: “square millimeter per second”, “mm²/s”, “mm^2/s”
148+
square centimeter per second: “square centimeter per second”, “cm²/s”, “cm^2/s”
149+
square meter per second: “square meter per second”, “m²/s”, “m^2/s”
150+
square inch per second: “square inch per second”, “in²/s”, “in^2/s”, “squareinchespersecond”
151+
Saybolt Universal Second: “Saybolt Universal Second”, “SSU”, “SUS”
152+
Saybolt Furol Second: “Saybolt Furol Second”, “SSF”, “SFS”
153+
154+
Dynamic Viscosity:
155+
kilogram per meter per second: “kilogram per meter per second”, “kg/(m s)”
156+
Pascal second: “Pascal second”, “Pa s”
157+
milliPascal second: “milliPascal second”, “mPa s”
158+
Newton seconds per square meter: “Newton seconds per square meter”, “N s/m²”, “N s/m^2”
159+
gram per centimeter per second: “gram per centimeter per second”, “g/(cm s)”
160+
poise: “poise”, “p”
161+
dyne seconds per square centimeter: “dyne seconds per square centimeter”, “dyne s/cm²”, “dyne s/cm^2”
162+
centipoise: “centipoise”, “cP”
163+
164+
Interfacial Tension:
165+
Newton per meter: “Newton per meter”, “N/m”
166+
milliNewton per meter: “milliNewton per meter”, “mN/m”
167+
dyne per centimeter: “dyne per centimeter”, “dyne/cm”, “dyn/cm”
168+
Poundal per inch: “Poundal per inch”, “pdl/in”
169+
Pound force per inch: “Pound force per inch”, “lbf/in”
170+
erg per square centimeter: “erg per square centimeter”, “erg/cm²”, “erg/cm^2”
171+
erg per square millimeter: “erg per square millimeter”, “erg/mm²”, “erg/mm^2”
172+
joule per square meter: “joule per square meter”, “j/m²”, “j/m^2”
173+
174+
Pressure:
175+
Pascal: “Pascal”, “Pa”
176+
kiloPascal: “kiloPascal”, “kPa”
177+
megaPascal: “megaPascal”, “MPa”
178+
Newton per square meter: “Newton per square meter”, “N/m²”, “N/m^2”
179+
bar: “bar”,
180+
millibar: “millibar”, “mbar”
181+
dyne per square centimeter: “dyne per square centimeter”, “dyn/cm²”, “dyn/cm^2”
182+
pound per square inch: “pound per square inch”, “lb/in²”, “lb/in^2”, “psi”
183+
184+
Concentration In Water:
185+
kilogram per cubic meter: “kilogram per cubic meter”, “kg/m³”, “kg/m^3”
186+
gram per cubic meter: “gram per cubic meter”, “g/m³”, “g/m^3”
187+
part per million: “part per million”, “ppm”, “parts per million”
188+
part per billion: “part per billion”, “ppb”, “parts per billion”
189+
part per thousand: “part per thousand”, “‰”, “0/00”, “ppt”, “parts per thousand”
190+
part per trillion: “part per trillion”, “pptr”, “parts per trillion”
191+
fraction (decimal): “fraction (decimal)”, “fraction”, “mass per mass”, “1”
192+
percent: “percent”, “%”, “parts per hundred”
193+
pound per cubic foot: “pound per cubic foot”, “lb/ft³”, “lb/ft^3”
194+
milligram per liter: “milligram per liter”, “mg/l”
195+
gram per liter: “gram per liter”, “g/l”
196+
kilogram per liter: “kilogram per liter”, “kg/l”
197+
milligram per gram: “milligram per gram”, “mg/g”
198+
milligram per kilogram: “milligram per kilogram”, “mg/kg”
199+
milligram per milliliter: “milligram per milliliter”, “mg/ml”
200+
microgram per liter: “microgram per liter”, “µg/l”, “ug/l”
201+
microgram per gram: “microgram per gram”, “µg/g”, “ug/g”
202+
nanogram per liter: “nanogram per liter”, “ng/l”
203+
204+
Concentration:
205+
fraction (decimal): “fraction (decimal)”, “fraction”, “mass per mass”, “1”
206+
percent: “percent”, “%”, “parts per hundred”
207+
part per thousand: “part per thousand”, “‰”, “0/00”, “parts per thousand”
208+
part per million: “part per million”, “ppm”, “parts per million”
209+
part per billion: “part per billion”, “ppb”, “parts per billion”
210+
part per trillion: “part per trillion”, “parts per trillion”
211+
212+
Dimensionless:
213+
fraction (decimal): “fraction (decimal)”, “number”, “fraction”, “1”
214+
percent: “percent”, “%”, “parts per hundred”
215+
part per thousand: “part per thousand”, “‰”, “0/00”, “ppt”, “parts per thousand”
216+
part per million: “part per million”, “ppm”, “parts per million”
217+
part per billion: “part per billion”, “ppb”, “parts per billion”
218+
219+
Mass Fraction:
220+
fraction (decimal): “fraction (decimal)”, “fraction”, “1”, “mass per mass”
221+
percent: “percent”, “%”, “parts per hundred”
222+
part per thousand: “part per thousand”, “‰”, “0/00”, “ppt”, “parts per thousand”
223+
part per million: “part per million”, “ppm”, “parts per million”
224+
part per billion: “part per billion”, “ppb”, “parts per billion”
225+
part per trillion: “part per trillion”, “parts per trillion”
226+
gram per kilogram: “gram per kilogram”, “g/kg”
227+
milligram per gram: “milligram per gram”, “mg/g”
228+
milligram per kilogram: “milligram per kilogram”, “mg/kg”
229+
microgram per gram: “microgram per gram”, “µg/g”, “ug/g”
230+
nanogram per gram: “nanogram per gram”, “ng/g”, “nanograms per gram”
231+
232+
Volume Fraction:
233+
fraction (decimal): “fraction (decimal)”, “fraction”, “1”, “mass per mass”
234+
percent: “percent”, “%”, “parts per hundred”
235+
part per thousand: “part per thousand”, “‰”, “0/00”, “ppt”, “parts per thousand”
236+
part per million: “part per million”, “ppm”, “parts per million”
237+
part per billion: “part per billion”, “ppb”, “parts per billion”
238+
part per trillion: “part per trillion”, “pptril”, “parts per trillion”
239+
milliliter per liter: “milliliter per liter”, “ml/l”, “mL/dm^3”
240+
liter per cubic meter: “liter per cubic meter”, “l/m^3”
241+
242+
Angular Measure:
243+
radian: “radian”, “rad”, “radians”
244+
degree: “degree”, “deg”, “degrees”
245+
246+
Angular Velocity:
247+
rad/s: “rad/s”, “1/s”, “radians/sec”
248+
hertz: “hertz”, “hz”, “cycles/sec”
249+
rotations per minute: “rotations per minute”, “rpm”

nucos/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
is_supported,
2424
is_supported_unit,
2525
get_supported_names,
26+
get_unit_type,
2627
get_unit_types,
2728
get_primary_name,
2829
get_primary_names,

nucos/tests/test_unit_conversion.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,3 +709,19 @@ def test_get_primary_names_with_space():
709709
assert set(result) == {'gram per second', 'kilogram per second'}
710710

711711

712+
def test_get_unit_type():
713+
"""
714+
not much, but something
715+
"""
716+
unit_type = unit_conversion.get_unit_type('m/s')
717+
718+
assert unit_type == "velocity"
719+
720+
def test_get_unit_type_bad():
721+
"""
722+
not much, but something
723+
"""
724+
with pytest.raises(unit_conversion.NotSupportedUnitError):
725+
unit_type = unit_conversion.get_unit_type('fred')
726+
727+

nucos/unit_conversion.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,27 @@ def GetUnitTypes():
7676
return list(ConvertDataUnits.keys())
7777

7878

79+
def get_unit_type(unit):
80+
"""
81+
Return the unit type for a given unit name.
82+
83+
Note that this will only work for unambiguous units
84+
85+
:param unit: the unit you want the type of
86+
:type unit: str
87+
88+
In [2]: nucos.get_unit_type('meter')
89+
Out[2]: 'length'
90+
"""
91+
unit = Simplify(unit)
92+
93+
try:
94+
unit_type = UNIT_TYPES[unit]
95+
except KeyError:
96+
raise NotSupportedUnitError(unit)
97+
return unit_type
98+
99+
79100
def get_unit_types():
80101
return list(PRETTY_UNIT_TYPES.values())
81102

0 commit comments

Comments
 (0)