Пример #1
0
def get_corrected_density_and_viscosity(oil):
    '''
        Get coefficients for calculating resin (and asphaltene) fractions
        based on Merv Fingas' empirical analysis of ESTC oil properties
        database.
        - Bill has clarified that we want to get the coefficients for just
          the 15C Density
        - Mervs calculations depend on a density measured in g/mL and a
          viscosity measured in mPa.s, so we do a conversion here.
    '''
    try:
        temperature = 273.15 + 15
        P0_oil = density_at_temperature(oil, temperature)
        V0_oil = get_viscosity(oil, temperature)
        a = 10 * exp(0.001 * P0_oil)
        b = 10 * log(1000.0 * P0_oil * V0_oil)

    except:
        print 'get_corrected_density_and_viscosity() generated exception:'
        print '\toil = ', oil
        print '\toil.kvis = ', oil.kvis
        print '\tP0_oil = ', density_at_temperature(oil, temperature)
        print '\tV0_oil = ', get_viscosity(oil, temperature)
        raise

    return a, b
Пример #2
0
def test_get_viscosity(temps, exp_value, use_out):
    if use_out:
        out = np.zeros_like(temps)
        get_viscosity(oil_, temps, out)
    else:
        out = get_viscosity(oil_, temps)
    assert np.all(out == exp_value)   # so it works for scalar + arrays
Пример #3
0
def get_corrected_density_and_viscosity(oil):
    '''
        Get coefficients for calculating resin (and asphaltene) fractions
        based on Merv Fingas' empirical analysis of ESTC oil properties
        database.
        - Bill has clarified that we want to get the coefficients for just
          the 15C Density
        - Mervs calculations depend on a density measured in g/mL and a
          viscosity measured in mPa.s, so we do a conversion here.
    '''
    try:
        temperature = 273.15 + 15
        P0_oil = density_at_temperature(oil, temperature)
        V0_oil = get_viscosity(oil, temperature)
        a = 10 * exp(0.001 * P0_oil)
        b = 10 * log(1000.0 * P0_oil * V0_oil)

    except:
        print 'get_corrected_density_and_viscosity() generated exception:'
        print '\toil = ', oil
        print '\toil.kvis = ', oil.kvis
        print '\tP0_oil = ', density_at_temperature(oil, temperature)
        print '\tV0_oil = ', get_viscosity(oil, temperature)
        raise

    return a, b
Пример #4
0
def test_get_viscosity(temps, exp_value, use_out):
    if use_out:
        out = np.zeros_like(temps)
        get_viscosity(oil_, temps, out)
    else:
        out = get_viscosity(oil_, temps)

    assert np.all(out == exp_value)  # so it works for scalar + arrays
Пример #5
0
def show_uncategorized_oils(session):
    oils = (session.query(Oil)
            .filter(Oil.categories == None)
            .all())

    fd = open('temp.txt', 'w')
    fd.write('adios_oil_id\t'
             'product_type\t'
             'api\t'
             'viscosity\t'
             'pour_point\t'
             'name\n')
    print ('{0} oils uncategorized.'
           .format(len(oils)))
    for o in oils:
        if o.api >= 0:
            if o.api < 15:
                category_temp = 273.15 + 50
            else:
                category_temp = 273.15 + 38
            viscosity = uc.convert('Kinematic Viscosity', 'm^2/s', 'cSt',
                                   get_viscosity(o, category_temp))
        else:
            viscosity = None

        fd.write('{0.imported.adios_oil_id}\t'
                 '{0.imported.product_type}\t'
                 '{0.api}\t'
                 '{1}\t'
                 '({0.pour_point_min_k}, {0.pour_point_max_k})\t'
                 '{0.name}\n'
                 .format(o, viscosity))
Пример #6
0
def link_refined_fuel_oil_6(session):
    '''
       Category Name:
       - Fuel Oil #6/Bunker/Heavy Fuel Oil/Group V
       Sample Oils:
       - Bunker C
       - Residual Oil
       Density Criteria:
       - API < 15
       Kinematic Viscosity Criteria:
       - 200.0 <= v cSt @ 50 degrees Celcius
    '''
    top_category = (session.query(Category)
                    .filter(Category.parent == None)
                    .filter(Category.name == 'Refined').one())
    categories = [c for c in top_category.children
                  if c.name in ('Fuel Oil 6',
                                'Bunker',
                                'Heavy Fuel Oil',
                                'Group V')
                  ]

    oils = get_oils_by_api(session, 'Refined',
                           api_min=0.0, api_max=15.0)

    count = 0
    category_temp = 273.15 + 50
    for o in oils:
        viscosity = uc.convert('Kinematic Viscosity', 'm^2/s', 'cSt',
                               get_viscosity(o, category_temp))

        if viscosity >= 200.0:
            for category in categories:
                o.categories.append(category)
            count += 1

    print ('{0} oils added to {1} -> {2}.'
           .format(count, top_category.name,
                   [n.name for n in categories]))
    transaction.commit()
Пример #7
0
def link_refined_fuel_oil_2(session):
    '''
       Category Name:
       - Fuel oil #2/Diesel/Heating Oil
       Sample Oils:
       - Diesel
       - Heating Oil
       - No. 2 Distillate
       Density Criteria:
       - 30 <= API < 35
       Kinematic Viscosity Criteria:
       - 2.5 < v <= 4.0 cSt @ 38 degrees Celcius
    '''
    top_category = (session.query(Category)
                    .filter(Category.parent == None)
                    .filter(Category.name == 'Refined').one())
    categories = [c for c in top_category.children
                  if c.name in ('Fuel Oil 2',
                                'Diesel',
                                'Heating Oil')
                  ]

    oils = get_oils_by_api(session, 'Refined',
                           api_min=30.0, api_max=35.0)

    count = 0
    category_temp = 273.15 + 38
    for o in oils:
        viscosity = uc.convert('Kinematic Viscosity', 'm^2/s', 'cSt',
                               get_viscosity(o, category_temp))

        if viscosity > 2.5 or viscosity <= 4.0:
            for category in categories:
                o.categories.append(category)
            count += 1

    print ('{0} oils added to {1} -> {2}.'
           .format(count, top_category.name,
                   [n.name for n in categories]))
    transaction.commit()
Пример #8
0
def link_refined_fuel_oil_1(session):
    '''
       Category Name:
       - Fuel oil #1/gasoline/kerosene
       Sample Oils:
       - gasoline
       - kerosene
       - JP-4
       - avgas
       Density Criteria:
       - API >= 35
       Kinematic Viscosity Criteria:
       - v <= 2.5 cSt @ 38 degrees Celcius
    '''
    top_category = (session.query(Category)
                    .filter(Category.parent == None)
                    .filter(Category.name == 'Refined').one())
    categories = [c for c in top_category.children
                  if c.name in ('Light Products (Fuel Oil 1)',
                                'Gasoline',
                                'Kerosene')
                  ]

    oils = get_oils_by_api(session, 'Refined', api_min=35.0)

    count = 0
    category_temp = 273.15 + 38
    for o in oils:
        viscosity = uc.convert('Kinematic Viscosity', 'm^2/s', 'cSt',
                               get_viscosity(o, category_temp))

        if viscosity <= 2.5:
            for category in categories:
                o.categories.append(category)
            count += 1

    print ('{0} oils added to {1} -> {2}.'
           .format(count, top_category.name,
                   [n.name for n in categories]))
    transaction.commit()
Пример #9
0
def link_refined_ifo(session):
    '''
       Category Name:
       - Intermediate Fuel Oil
       Sample Oils:
       - IFO 180
       - Fuel Oil #4
       - Marine Diesel
       Density Criteria:
       - 15 <= API < 30
       Kinematic Viscosity Criteria:
       - 4.0 < v < 200.0 cSt @ 38 degrees Celcius
    '''
    top_category = (session.query(Category)
                    .filter(Category.parent == None)
                    .filter(Category.name == 'Refined').one())
    categories = [c for c in top_category.children
                  if c.name in ('Intermediate Fuel Oil',)
                  ]

    oils = get_oils_by_api(session, 'Refined',
                           api_min=15.0, api_max=30.0)

    count = 0
    category_temp = 273.15 + 38
    for o in oils:
        viscosity = uc.convert('Kinematic Viscosity', 'm^2/s', 'cSt',
                               get_viscosity(o, category_temp))

        if viscosity > 4.0 or viscosity < 200.0:
            for category in categories:
                o.categories.append(category)
            count += 1

    print ('{0} oils added to {1} -> {2}.'
           .format(count, top_category.name,
                   [n.name for n in categories]))
    transaction.commit()
Пример #10
0
     (np.asarray(density_tests), np.asarray(density_exp), False),
     (np.asarray(density_tests), np.asarray(density_exp), True)])
def test_get_density(temps, exp_value, use_out):
    if use_out:
        out = np.zeros_like(temps)
        get_density(oil_, temps, out)
    else:
        out = get_density(oil_, temps)
    assert np.all(out == exp_value)  # so it works for scalar + arrays


# Test case - get ref temps from kvis then append ref_temp for
# kvis at 0th index for a few more values:
#    viscosity_tests = [d.ref_temp_k for d in oil_.densities]
#    viscosity_tests.append(oil_.densities[0].ref_temp_k)
v_max = get_viscosity(oil_, get_pour_point(oil_), clip_to_vmax=False)

viscosity_tests = [
    oil_.kvis[ix].ref_temp_k
    if ix < len(oil_.kvis) else oil_.kvis[0].ref_temp_k
    for ix in range(0,
                    len(oil_.kvis) + 3)
]

viscosity_exp = [(d.m_2_s, v_max)[v_max < d.m_2_s] for temp in viscosity_tests
                 for d in oil_.kvis if abs(d.ref_temp_k - temp) == 0]


@pytest.mark.parametrize(
    ("temps", "exp_value", "use_out"),
    [(viscosity_tests[0], viscosity_exp[0], False),
Пример #11
0
from pyramid.paster import get_appsettings, setup_logging

from oil_library import _get_db_session
from oil_library.models import Base, ImportedRecord, Oil, Density, Toxicity, Category
from oil_library.oil_props import OilProps

from oil_library.utilities import get_viscosity, get_boiling_points_from_api
from oil_library.init_oil import density_at_temperature


session = _get_db_session()

oil_obj = session.query(Oil).filter(Oil.name == "ALASKA NORTH SLOPE").one()
props_obj = OilProps(oil_obj)

viscosity = uc.convert("Kinematic Viscosity", "m^2/s", "cSt", get_viscosity(oil_obj, 273.15 + 38))

print oil_obj, "\n\tviscosity at 38C =", viscosity
for v in oil_obj.kvis:
    v_ref, t_ref = v.m_2_s, v.ref_temp_k
    print "\tviscosity: {0} m^2/s at {1}K".format(v.m_2_s, v.ref_temp_k)
print "imported pour points:", (oil_obj.imported.pour_point_min_k, oil_obj.imported.pour_point_max_k)
print "oil pour points:", (oil_obj.pour_point_min_k, oil_obj.pour_point_max_k)


def get_ptry_values(oil_obj, component_type, sub_fraction=None):
    """
        This gives an initial trial estimate for each density component.

        In theory the fractionally weighted average of these densities,
        combined with the fractionally weighted average resin and asphaltene
Пример #12
0
                          (np.asarray(density_tests),
                           np.asarray(density_exp), True)])
def test_get_density(temps, exp_value, use_out):
    if use_out:
        out = np.zeros_like(temps)
        get_density(oil_, temps, out)
    else:
        out = get_density(oil_, temps)
    assert np.all(out == exp_value)   # so it works for scalar + arrays


# Test case - get ref temps from kvis then append ref_temp for
# kvis at 0th index for a few more values:
#    viscosity_tests = [d.ref_temp_k for d in oil_.densities]
#    viscosity_tests.append(oil_.densities[0].ref_temp_k)
v_max = get_viscosity(oil_, get_pour_point(oil_), clip_to_vmax=False)

viscosity_tests = [oil_.kvis[ix].ref_temp_k if ix < len(oil_.kvis)
                   else oil_.kvis[0].ref_temp_k
                   for ix in range(0, len(oil_.kvis) + 3)]

viscosity_exp = [(d.m_2_s, v_max)[v_max < d.m_2_s]
                 for temp in viscosity_tests
                 for d in oil_.kvis
                 if abs(d.ref_temp_k - temp) == 0]


@pytest.mark.parametrize(("temps", "exp_value", "use_out"),
                         [(viscosity_tests[0], viscosity_exp[0], False),
                          (viscosity_tests, viscosity_exp, False),
                          (tuple(viscosity_tests), viscosity_exp, False),