Skip to content

Commit

Permalink
Upgrade Pint version (#284)
Browse files Browse the repository at this point in the history
* upgraded pint, fixed round off errors in tests

* Update Pipfile.lock

* Increment version number

* round outputs of doctests
  • Loading branch information
HannahSi authored Nov 17, 2020
1 parent 0a774df commit 6e2a864
Show file tree
Hide file tree
Showing 10 changed files with 642 additions and 418 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "pypi"
[packages]
matplotlib = "*"
urllib3 = "*"
pint = "==0.8.1"
pint = "*"
pandas = "*"
scipy = "*"

Expand Down
994 changes: 607 additions & 387 deletions Pipfile.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions aguaclara/design/ent_floc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
Example:
>>> from aguaclara.design.ent_floc import *
>>> etf = EntTankFloc(q=20 * u.L / u.s, floc=Flocculator(hl=35 * u.cm))
>>> etf.ent.l
<Quantity(40.56720950298926, 'inch')>
>>> round(etf.ent.l, 5)
<Quantity(40.56721, 'inch')>
"""
from aguaclara.design.ent import *
from aguaclara.design.lfom import *
Expand Down
4 changes: 2 additions & 2 deletions aguaclara/design/floc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
Example:
>>> from aguaclara.design.floc import *
>>> floc = Flocculator(q = 20 * u.L / u.s, hl = 40 * u.cm)
>>> floc.chan_w
<Quantity(34.0, 'centimeter')>
>>> round(floc.chan_w)
<Quantity(34, 'centimeter')>
"""
import aguaclara.core.head_loss as hl
import aguaclara.design.human_access as ha
Expand Down
4 changes: 2 additions & 2 deletions aguaclara/design/sed_chan.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Example:
>>> from aguaclara.design.sed_chan import *
>>> sed_chan = SedimentationChannel(q = 20 * u.L / u.s, temp = 20 * u.degC)
>>> sed_chan.inlet_w
<Quantity(59.52755905511811, 'inch')>
>>> round(sed_chan.inlet_w, 5)
<Quantity(59.52756, 'inch')>
"""
from aguaclara.core.units import u
import aguaclara.core.constants as con
Expand Down
4 changes: 2 additions & 2 deletions aguaclara/design/sed_tank.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Example:
>>> from aguaclara.design.sed_tank import *
>>> sed_tank = SedimentationTank(q = 60 * u.L / u.s)
>>> sed_tank.diffuser_hl
<Quantity(0.009259259259259259, 'centimeter')>
>>> round(sed_tank.diffuser_hl, 5)
<Quantity(0.00926, 'centimeter')>
"""
from aguaclara.core.units import u
import aguaclara.core.constants as con
Expand Down
9 changes: 5 additions & 4 deletions aguaclara/research/stock_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ class Variable_Q_Stock(Stock):
>>> from aguaclara.research.stock_qc import Variable_Q_Stock
>>> from aguaclara.core.units import u
>>> reactor = Variable_Q_Stock(Q_sys = 1*u.mL/u.s, C_sys = 1.4*u.mg/u.L, C_stock = 7.6*u.mg/u.L)
>>> reactor.Q_stock()
<Quantity(0.18421052631578946, 'milliliter / second')>
>>> reactor.rpm(vol_per_rev = .5*u.mL/u.rev).to(u.rev/u.min)
<Quantity(22.105263157894736, 'rev / minute')>
>>> round(reactor.Q_stock(), 6)
<Quantity(0.184211, 'milliliter / second')>
>>> pump_speed = reactor.rpm(vol_per_rev = .5*u.mL/u.rev).to(u.rev/u.min)
>>> round(pump_speed, 6)
<Quantity(22.105263, 'rev / minute')>
"""

def __init__(self, Q_sys, C_sys, C_stock):
Expand Down
17 changes: 8 additions & 9 deletions tests/core/test_physchem.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def test_density_air(self):

def test_density_gas(self):
"""Test the gas density function"""
answer = 1.29320776*u.kg/u.m**3
answer = 1.29320768*u.kg/u.m**3
self.assertAlmostEqualQuantity(pc.density_gas(1*u.atm, 28.97*u.g/u.mol, 273*u.K), answer)
answer = 2.06552493*u.kg/u.m**3
answer = 2.06552481*u.kg/u.m**3
self.assertAlmostEqualQuantity(pc.density_gas(5*u.atm, 10*u.g/u.mol, 295*u.K), answer)
answer = 1.62487961*u.kg/u.m**3
answer = 1.62487951*u.kg/u.m**3
self.assertAlmostEqualQuantity(pc.density_gas(101325*u.Pa, 40*u.g/u.mol, 300*u.K), answer)
answer = 0.20786109*u.kg/u.m**3
answer = 0.20786108*u.kg/u.m**3
self.assertAlmostEqualQuantity(pc.density_gas(700*u.mmHg, 5*u.g/u.mol, 270*u.K), answer)
answer = 0*u.kg/u.m**3
self.assertAlmostEqualQuantity(pc.density_gas(0*u.atm, 28.97*u.g/u.mol, 273*u.K), answer)
Expand Down Expand Up @@ -271,7 +271,7 @@ def test_fric_pipe(self):
self.assertAlmostEqualQuantity(pc.fric_pipe(*i[0]), i[1] * u.dimensionless)

def test_fric_range(self):
"""fric_pipe should raise an error if 0 <= Roughness <= 1 is not true."""
"""fric_pipe should raise an error if 0 <= Roughness is not true."""
checks = ([1 * u.m**3/u.s, 2 * u.m, 0.1 * u.m**2/u.s, -0.1 * u.m],)
for i in checks:
with self.subTest(i=i):
Expand All @@ -290,7 +290,7 @@ def test_fric_rect(self):
self.assertAlmostEqualQuantity(pc.fric_rect(*i[0]), i[1] * u.dimensionless)

def test_fric_rect_range(self):
"""fric_rect should raise an error if 0 <= PipeRough <= 1 is not true."""
"""fric_rect should raise an error if 0 <= Roughness not true."""
checks = ([1 * u.m**3/u.s, 1 * u.m, 1 * u.m, 1 * u.m**2/u.s, -1.1 * u.m, True],)
for i in checks:
with self.subTest(i=i):
Expand Down Expand Up @@ -324,9 +324,8 @@ def test_fric_channel(self):
self.assertAlmostEqualQuantity(pc.fric_channel(*i[0]), i[1] * u.dimensionless)

def test_fric_channel_range(self):
"""fric_channel should raise an error if 0 <= Roughness <= 1 is not true."""
checks = ((1 * u.m**2, 1 * u.m, 1 * u.m**2/u.s, 1 * u.m**2/u.s, -0.0001 * u.m),
(1 * u.m**2, 1 * u.m, 1 * u.m**2/u.s, 1 * u.m**2/u.s, 1.1 * u.m))
"""fric_channel should raise an error if 0 <= Roughness is not true."""
checks = ((1 * u.m**2, 1 * u.m, 1 * u.m/u.s, 1 * u.m**2/u.s, -0.0001 * u.m),)
for i in checks:
with self.subTest(i=i):
self.assertRaises(ValueError, pc.fric_channel, *i)
Expand Down
16 changes: 8 additions & 8 deletions tests/core/test_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@ def density_air(Pressure, MolarMass, Temperature):
"""
return (Pressure * MolarMass / (u.R * Temperature)).to(u.kg/u.m**3)

answer = 1.29320776*u.kg/u.m**3
answer = 1.29320768*u.kg/u.m**3
self.assertAlmostEqualQuantity(density_air(1*u.atm, 28.97*u.g/u.mol, 273*u.K), answer)

answer = 1.29320776*u.kg/u.m**3
answer = 1.29320768*u.kg/u.m**3
self.assertAlmostEqualQuantity(density_air(MolarMass=28.97*u.g/u.mol, Temperature=273*u.K, Pressure=1*u.atm), answer)

answer = np.array([1.29320776, 2.58641552, 3.87962328, 12.93207761])*u.kg/u.m**3
answer = np.array([1.29320768, 2.58641536, 3.87962304, 12.93207681])*u.kg/u.m**3
self.assertAlmostEqualArrayQuantity(density_air([1, 2, 3, 10]*u.atm, 28.97*u.g/u.mol, 273*u.K), answer)

answer = np.array([1.29320776, 2.58641552, 3.87962328, 12.93207761])*u.kg/u.m**3
answer = np.array([1.29320768, 2.58641536, 3.87962304, 12.93207681])*u.kg/u.m**3
self.assertAlmostEqualArrayQuantity(density_air(MolarMass=28.97*u.g/u.mol, Temperature=273*u.K, Pressure=[1, 2, 3, 10]*u.atm), answer)

answer = np.array([[1.29320776, 1.20526784, 1.07134919, 0.89279099],
[2.58641552, 2.41053569, 2.14269839, 1.78558199],
[3.87962328, 3.61580354, 3.21404759, 2.67837299],
[12.93207761, 12.05267848, 10.71349198, 8.92790998]])*u.kg/u.m**3
answer = np.array([[1.29320768, 1.20526777, 1.07134913, 0.89279094],
[2.58641536, 2.41053555, 2.14269826, 1.78558189],
[3.87962304, 3.61580333, 3.21404740, 2.67837283],
[12.93207681, 12.05267773, 10.71349131, 8.92790943]])*u.kg/u.m**3
output = density_air([1, 2, 3, 10]*u.atm, [28.97, 27, 24, 20]*u.g/u.mol, 273*u.K)
self.assertEqual(output.units, answer.units)
for i in range(len(output.magnitude)):
Expand Down
6 changes: 5 additions & 1 deletion tests/design/test_floc.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@
])

def test_floc(actual, expected):
assert actual == expected
if (type(actual) == u.Quantity and type(expected) == u.Quantity):
expected = expected.to(actual.units)
assert actual.magnitude == pytest.approx(expected.magnitude)
else:
assert actual == pytest.approx(expected)

0 comments on commit 6e2a864

Please sign in to comment.