Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit conversion fix #173

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions scimath/units/acceleration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
# Thanks for using Enthought open source!

""" Define units of acceleration

Symbols defined: feet_per_second_squared, meters_per_second_squared [and aliases]

"""

#####################################################################
Expand Down
4 changes: 4 additions & 0 deletions scimath/units/angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
# Thanks for using Enthought open source!

""" Define units of angle (dimensionless with meaning)

Symbols defined: circle, degree, grad, quadrant, mil, right_angle, radian, revolution, sextant, sign, turn
minute, second, [and aliases]

"""

#############################################################################
Expand Down
7 changes: 7 additions & 0 deletions scimath/units/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@

from .length import meter, centimeter, inch, foot, mile

""" Define units of area

Symbols defined: acre, hectare,
barn,
square_centimeter, square_foot, square_inch, square_meter, square_mile [and aliases]

"""

#
# Definitions of common area units
Expand Down
4 changes: 4 additions & 0 deletions scimath/units/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
# Thanks for using Enthought open source!

""" Defines units of density

Derived from: units/density.py [pyre system]
Michael A.G. Aivazis
California Institute of Technology
(c) 1998-2003

Symbols defined: grams_per_cubic_centimeter, kilograms_per_cubic_meter, lb_per_gal [and aliases]

"""

#############################################################################
Expand Down
6 changes: 6 additions & 0 deletions scimath/units/dimensionless.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
#
# Thanks for using Enthought open source!

""" Defines units of dimensionless

Symbols defined: fractional, parts_per_million, parts_per_one, percent [and aliases]

"""

from copy import copy
from scimath.units.SI import dimensionless
from scimath.units.unit import one, dim
Expand Down
13 changes: 13 additions & 0 deletions scimath/units/electromagnetism.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@
#
# Thanks for using Enthought open source!

""" Defines units of electromagnetism

Symbols defined: ampere, milli_ampere,
farad, micro_farad, pico_farad,
henry,
ohm, ohm_meter, ohmm,
siemen, mSiemen, siemens_per_meter,
tesla,
volt, milivolt,
weber [and aliases]

"""

from copy import copy

from scimath.units.SI import ampere, coulomb, farad, henry, joule, ohm, \
Expand Down
7 changes: 7 additions & 0 deletions scimath/units/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
# The NIST Reference on Constants, Units and Uncertainty,
# http://physics.nist.gov/cuu
#
# Symbols defined: Btu,
# Calorie, calorie,
# electron_volt,
# erg,
# foot_pound,
# horse_power_hour, kilowatt_hour [and aliases]
#


Btu = 1055 * joule
Expand Down
6 changes: 6 additions & 0 deletions scimath/units/force.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
#
# Thanks for using Enthought open source!

""" Defines units of force

Symbols defined: lbf, lbs, N [and aliases]

"""

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Michael A.G. Aivazis
Expand Down
2 changes: 2 additions & 0 deletions scimath/units/frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# Thanks for using Enthought open source!

""" Defines units of frequency

Symbols defined: hertz, kilohertz, rpm [and aliases]
"""

#############################################################################
Expand Down
7 changes: 7 additions & 0 deletions scimath/units/length.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
Michael A.G. Aivazis
California Institute of Technology
(c) 1998-2003

Symbols defined: kilo-, centi-, milli-, micro-, nano-, pico-, meter,
inch, foot, yard, mile,
fathom, nautical_mile,
angstrom, fermi, survey_foot, us_foot, us_feet,
astronomical_unit, light_year, parsec [and aliases]

"""

#############################################################################
Expand Down
6 changes: 6 additions & 0 deletions scimath/units/mass.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
# Thanks for using Enthought open source!

""" Defines units of mass

Derived from: units/mass.py [pyre system]
Michael A.G. Aivazis
California Institute of Technology
(c) 1998-2003

Symbols defined: centigram, gram, kilogram, milligram,
metric_ton, ton,
ounce, pound [and aliases]

"""

#############################################################################
Expand Down
1 change: 1 addition & 0 deletions scimath/units/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# Definitions of common power units
# Data taken from Appendix F of Halliday, Resnick, Walker, "Fundamentals of Physics",
# fourth edition, John Willey and Sons, 1993
# Symbols defined: kilowatt, horsepower [and aliases]

kilowatt = kilo * watt
kw = kilowatt
Expand Down
5 changes: 4 additions & 1 deletion scimath/units/pressure.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@
#
# The NIST Reference on Constants, Units and Uncertainty,
# http://physics.nist.gov/cuu
#
# Symbols defined: pascal, kPa, MPa, GPa, inHg,
# bar, kilobar, millibar, torr, atmosphere,
# pounds_per_square_inch [and aliases]
#


# aliases

Pa = pascal
Expand Down
3 changes: 1 addition & 2 deletions scimath/units/quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ def propagate_data_changes(self):
return

# Replace the predecessor's data with converted data.
new_quantity = self.change_unit_system(predecessor.units)
predecessor.data = new_quantity.data
predecessor.data = units_convert(self.data, self.units, predecessor.units)

# Recursively continue propagating.
predecessor.propagate_data_changes()
Expand Down
5 changes: 5 additions & 0 deletions scimath/units/speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
# Thanks for using Enthought open source!

""" Defines units of density.

Derived from: units/density.py [pyre system]
Michael A.G. Aivazis
California Institute of Technology
(c) 1998-2003

Symbols defined: feet_per_second, meters_per_second, kilometers_per_second, miles_per_hour,
knot [and aliases]

"""

#############################################################################
Expand Down
5 changes: 5 additions & 0 deletions scimath/units/substance.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

""" Defines units of substance

Symbols defined: mole, kmole [and aliases]
"""

from .SI import mole, kilo


Expand Down
6 changes: 6 additions & 0 deletions scimath/units/temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

""" Defines units of temperature

Symbols defined: celsius, fahrenheit, kelvin, rankine [and aliases]

"""

from scimath.units.unit import unit

# Tk = Tk
Expand Down
9 changes: 9 additions & 0 deletions scimath/units/tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ def test_propagation(self):
self.assertAlmostEqual(30., q1.data, 1,
"Propagation test expected data 30, got %s" % str(q1.data))

def test_propagation2(self):
""" Tests data propagation for a single converted quantity. """

q1 = Quantity(10.0, units='ft', family_name='depth')
q2 = q1.change_unit_system('METRIC')
q2.data = 2 * q2.data
q2.propagate_data_changes()
self.assertAlmostEqual(q1.data, 20.0)

def test_get_original(self):

q1 = Quantity(10, units='m', family_name='depth')
Expand Down
4 changes: 4 additions & 0 deletions scimath/units/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
Michael A.G. Aivazis
California Institute of Technology
(c) 1998-2003

Symbols defined: milli-, micro-, nano-, pico-, second,
minute, hour, day, week, year [and aliases]

"""

#############################################################################
Expand Down
6 changes: 6 additions & 0 deletions scimath/units/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
Michael A.G. Aivazis
California Institute of Technology
(c) 1998-2003

Symbols defined: cubic_centimeter, cubic_foot, cubic_meter,
liter, barrel,
us_pint,
us_fluid_ounce, us_fluid_quart, us_fluid_gallon [and aliases]

"""
#############################################################################
# Imports:
Expand Down