From 2d5ff37272f83b7b4d55db7163d281a860060276 Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Fri, 5 Apr 2013 22:53:11 -0400 Subject: [PATCH 1/2] Added log-intensity and log-power units. --- quantities/unitquantity.py | 8 ++++++++ quantities/units/__init__.py | 3 +++ quantities/units/logunits.py | 27 +++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 quantities/units/logunits.py diff --git a/quantities/unitquantity.py b/quantities/unitquantity.py index 9ecc0eb..fc4d3e8 100644 --- a/quantities/unitquantity.py +++ b/quantities/unitquantity.py @@ -382,6 +382,14 @@ class UnitInformation(IrreducibleUnit): class UnitCurrency(IrreducibleUnit): _primary_order = 9 + +class UnitLogIntensity(IrreducibleUnit): + + _primary_order = 10 + +class UnitLogPower(IrreducibleUnit): + + _primary_order = 11 class CompoundUnit(UnitQuantity): diff --git a/quantities/units/__init__.py b/quantities/units/__init__.py index 48a34fe..ed74fae 100644 --- a/quantities/units/__init__.py +++ b/quantities/units/__init__.py @@ -42,6 +42,9 @@ from . import length from .length import * +from . import logunits +from .logunits import * + from . import mass from .mass import * diff --git a/quantities/units/logunits.py b/quantities/units/logunits.py new file mode 100644 index 0000000..11a3448 --- /dev/null +++ b/quantities/units/logunits.py @@ -0,0 +1,27 @@ +""" +""" +from __future__ import absolute_import + +from ..unitquantity import UnitLogIntensity, UnitLogPower, UnitQuantity + +bel = UnitLogIntensity( + 'bel', + symbol='bel' +) +decibel = dB = UnitQuantity( + 'decibel', + bel / 10, + 'dB' +) + +bel_milliwatt = UnitLogPower( + 'bel-milliwatt', + symbol='Bm' +) +decibel_milliwatt = dBm = UnitQuantity( + 'decibel-milliwatt', + bel_milliwatt / 10, + symbol='dBm' +) + +del UnitLogIntensity, UnitLogPower, UnitQuantity From 96b67a3a1cca461ac664656aae855d2ec61b22cc Mon Sep 17 00:00:00 2001 From: Christopher Granade Date: Sat, 13 Apr 2013 15:14:44 -0400 Subject: [PATCH 2/2] Fixed problem with string representation. --- quantities/units/logunits.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quantities/units/logunits.py b/quantities/units/logunits.py index 11a3448..4594515 100644 --- a/quantities/units/logunits.py +++ b/quantities/units/logunits.py @@ -15,11 +15,11 @@ ) bel_milliwatt = UnitLogPower( - 'bel-milliwatt', + 'bel_milliwatt', symbol='Bm' ) decibel_milliwatt = dBm = UnitQuantity( - 'decibel-milliwatt', + 'decibel_milliwatt', bel_milliwatt / 10, symbol='dBm' )