Exemplo n.º 1
0
def builder_class_constructor(loader, node):
    value = loader.construct_scalar(node)
    # seperate the units from the magnitude to build the quantity.
    pattern = re.compile(r'([ ]?[+-]?[0-9]*[.]?[0-9]+)')
    split_list = re.split(pattern, value)
    mag, units = split_list[1], ''.join(split_list[2:])
    return u.Quantity(float(mag), units)
Exemplo n.º 2
0
], False)
def n_cdc_tube(FlowPlant, ConcDoseMax, ConcStock, DiamTubeAvail, HeadlossCDC,
               LenCDCTubeMax, temp, en_chem, KMinor):

    index = i_cdc(FlowPlant, ConcDoseMax, ConcStock, DiamTubeAvail,
                  HeadlossCDC, LenCDCTubeMax, temp, en_chem, KMinor)

    n_cdc_tube = _n_tube_array(FlowPlant, ConcDoseMax, ConcStock,
                               DiamTubeAvail, HeadlossCDC, Ratio_Error,
                               KMinor)[index]

    return n_cdc_tube


# testing
FlowPlant = 100 * u.L / u.s
DiamTubeAvail = np.array(np.arange(1 / 16, 6 / 16, 1 / 16)) * u.inch
temp = u.Quantity(20, u.degC)
HeadlossCDC = 20 * (u.cm)
ConcStock = 51.4 * (u.gram / u.L)
ConcDoseMax = 2 * (u.mg / u.L)
LenCDCTubeMax = 4 * u.m
en_chem = 2
KMinor = 2
Ratio_Error = 0.1
x = len_cdc_tube(FlowPlant, ConcDoseMax, ConcStock, DiamTubeAvail, HeadlossCDC,
                 LenCDCTubeMax, temp, en_chem, KMinor)
#print(x)
#print(diam_cdc_tube(FlowPlant, ConcDoseMax, ConcStock, DiamTubeAvail, HeadlossCDC, LenCDCTubeMax, temp, en_chem, KMinor).to(u.inch))
#print(n_cdc_tube(FlowPlant, ConcDoseMax, ConcStock, DiamTubeAvail, HeadlossCDC, LenCDCTubeMax, temp, en_chem, KMinor))
Exemplo n.º 3
0
def sig(x, n):
    """Return the 1st input reduced to a number of significant digits.
    
    x is a number that may include units. n is the number of significant 
    digits to display.
    """
    # Check to see if the quantity x includes units so we can strip the
    # units and then reattach them at the end.
    if type(x) == type(1 * u.m):
        xunit = x.units
        xmag = float(x.magnitude)
        if n == 1 and xmag >= 1:
            req = round(xmag)
            return '{:~P}'.format(u.Quantity(req, xunit))

    else:
        xmag = x
    if xmag == 0.:
        return "0." + "0" * (n - 1)
    if n == 1 and type(x) != type(1 * u.m):
        return round(xmag)

    out = []
    if xmag < 0:
        out.append("-")
        xmag = -xmag
    e = int(math.log10(xmag))
    tens = math.pow(10, e - n + 1)
    y = math.floor(xmag / tens)
    if y < math.pow(10, n - 1):
        e = e - 1
        tens = math.pow(10, e - n + 1)
        y = math.floor(xmag / tens)
    if abs((y + 1.) * tens - xmag) <= abs(y * tens - xmag):
        y = y + 1
    if y >= math.pow(10, n):
        y = y / 10.
        e = e + 1

    m = "%.*g" % (n, y)
    if e < -2 or e >= n:
        out.append(m[0])
        if n > 1:
            out.append(".")
            out.extend(m[1:n])
        out.append('e')
        if e > 0:
            out.append("+")
        out.append(str(e))
    elif e == (n - 1):
        out.append(m)
    elif e >= 0:
        out.append(m[:e + 1])
        if e + 1 < len(m):
            out.append(".")
            out.extend(m[e + 1:])
    else:
        out.append("0.")
        out.extend(["0"] * -(e + 1))
        out.append(m)

    if type(x) == type(1 * u.m):
        req = "".join(out)
        return '{:~P}'.format(u.Quantity(req, xunit))
    else:
        return "".join(out)
Exemplo n.º 4
0
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from aide_design import physchem as pc
from aide_design.units import unit_registry as u
from aide_design import utility as ut

# h_drive = height of drive pipe
# A_drive = Area of drive pipe
# x_max = maximum spring compression distance, equal to plate ampltitude
# h_eff = Necessary pumping height
# A_eff = Area of effluent flow

# Minimum force balance
# k_min = minimum k value needed to open from closed position
temp = u.Quantity(22, u.degC)
# Assume room temperature.
rho = pc.density_water(temp)
g = pc.gravity
x_max = .045 * u.m
h_drive = .51 * u.m
d_drive = 0.025273 * u.m
A_drive = pc.area_circle(d_drive)
P_hydrostatic = rho * g * h_drive
k_min = P_hydrostatic * A_drive / x_max

# Equation for k value
# k = EA/L
# L_opt = optimal spring length
# A_spring = Area of spring