-# Copyright (C) 2010 Massimo Sandal <devicerandom@gmail.com>
-# Rolf Schmidt <rschmidt@alcor.concordia.ca>
-# W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2010-2012 W. Trevor King <wking@drexel.edu>
#
# This file is part of Hooke.
#
-# Hooke is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
+# Hooke is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
#
-# Hooke is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
-# Public License for more details.
+# Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
#
-# You should have received a copy of the GNU Lesser General Public
-# License along with Hooke. If not, see
-# <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Lesser General Public License
+# along with Hooke. If not, see <http://www.gnu.org/licenses/>.
"""Define functions for handling numbers in SI notation.
"""
if value == 0:
return '0'
- if isnan(value):
+ if value == None or isnan(value):
return 'NaN'
if power == None: # auto-detect power
# 1 for ' ', 1 for '-', 3 for number, 1 for '.', and decimals.
pad = 6 + decimals
format = lambda n: '%*.*f' % (pad, decimals, n)
- return '%s %s%s' % (format(value / pow(10,power)), PREFIX[power], unit)
+ try:
+ prefix = ' '+PREFIX[power]
+ except KeyError:
+ prefix = 'e%d ' % power
+ return '%s%s%s' % (format(value / pow(10,power)), prefix, unit)
def get_power(value):
>>> join_data_label('z piezo', 'm')
'z piezo (m)'
>>> join_data_label('deflection', 'N')
- 'deflection N'
+ 'deflection (N)'
"""
return '%s (%s)' % (name, unit)