示例#1
0
def add_oil(record):
    print 'Estimations for {0}'.format(record.adios_oil_id)
    oil = Oil()
    oil.estimated = Estimated()

    add_demographics(record, oil)
    add_densities(record, oil)
    add_viscosities(record, oil)
    add_oil_water_interfacial_tension(record, oil)
    add_oil_seawater_interfacial_tension(record, oil)

    add_pour_point(record, oil)
    add_flash_point(record, oil)
    add_emulsion_water_fraction_max(record, oil)

    add_resin_fractions(record, oil)
    add_asphaltene_fractions(record, oil)

    add_bullwinkle_fractions(record, oil)
    add_adhesion(record, oil)
    add_sulphur_mass_fraction(record, oil)
    add_soluability(record, oil)
    add_distillation_cut_boiling_point(record, oil)
    add_molecular_weights(record, oil)
    add_component_densities(record, oil)
    add_saturate_aromatic_fractions(record, oil)
    adjust_resin_asphaltene_fractions(record, oil)

    add_k0y(record, oil)

    reject_oil_if_bad(record, oil)

    record.oil = oil
示例#2
0
def get_oil(oil_, max_cuts=None):
    """
    function returns the Oil object given the name of the oil as a string.

    :param oil_: The oil that spilled.
                 - If it is a dictionary of items, then we will assume it is
                   a JSON payload sufficient for creating an Oil object.
                 - If it is one of the names stored in _sample_oil dict,
                   then an Oil object with specified API is returned.
                 - Otherwise, query the database for the oil_name and return
                   the associated Oil object.
    :type oil_: str or dict

    Optional arg:

    :param max_cuts: This is ** only ** used for _sample_oils which dont have
        distillation cut information. For testing, this allows us to model the
        oil with variable number of cuts, with equally divided mass. For a
        real oil pulled from the database, this is ignored.
    :type max_cuts: int

    NOTE I:
    -------
    One issue is that the kwargs in Oil contain spaces, like 'oil_'. This
    can be handled if the user defines a dict as follows:
        kw = {'oil_': 'new oil', 'Field Name': 'field name'}
        get_oil(**kw)
    however, the following will not work:
        get_oil('oil_'='new oil', 'Field Name'='field name')

    This is another reason, we need an interface between the SQL object and the
    end user.
    """
    if isinstance(oil_, dict):
        prune_db_ids(oil_)
        return Oil.from_json(oil_)

    if oil_ in _sample_oils.keys():
        return _sample_oils[oil_]
    else:
        '''
        db_file should exist - if it doesn't then create if first
        should we raise error here?
        '''
        session = _get_db_session()

        try:
            oil = session.query(Oil).filter(Oil.name == oil_).one()
            oil.densities
            oil.kvis
            oil.cuts
            oil.sara_fractions
            oil.sara_densities
            oil.molecular_weights
            return oil
        except NoResultFound, ex:
            ex.message = ("oil with name '{0}', not found in database.  "
                          "{1}".format(oil_, ex.message))
            ex.args = (ex.message, )
            raise ex
示例#3
0
def get_oil(oil_, max_cuts=None):
    """
    function returns the Oil object given the name of the oil as a string.

    :param oil_: The oil that spilled.
                 - If it is a dictionary of items, then we will assume it is
                   a JSON payload sufficient for creating an Oil object.
                 - If it is one of the names stored in _sample_oil dict,
                   then an Oil object with specified API is returned.
                 - Otherwise, query the database for the oil_name and return
                   the associated Oil object.
    :type oil_: str or dict

    Optional arg:

    :param max_cuts: This is ** only ** used for _sample_oils which dont have
        distillation cut information. For testing, this allows us to model the
        oil with variable number of cuts, with equally divided mass. For a
        real oil pulled from the database, this is ignored.
    :type max_cuts: int

    NOTE I:
    -------
    One issue is that the kwargs in Oil contain spaces, like 'oil_'. This
    can be handled if the user defines a dict as follows:
        kw = {'oil_': 'new oil', 'Field Name': 'field name'}
        get_oil(**kw)
    however, the following will not work:
        get_oil('oil_'='new oil', 'Field Name'='field name')

    This is another reason, we need an interface between the SQL object and the
    end user.
    """
    if isinstance(oil_, dict):
        prune_db_ids(oil_)
        return Oil.from_json(oil_)

    if oil_ in _sample_oils.keys():
        return _sample_oils[oil_]
    else:
        '''
        db_file should exist - if it doesn't then create if first
        should we raise error here?
        '''
        session = _get_db_session()

        try:
            oil = session.query(Oil).filter(Oil.name == oil_).one()
            oil.densities
            oil.kvis
            oil.cuts
            oil.sara_fractions
            oil.sara_densities
            oil.molecular_weights
            return oil
        except NoResultFound, ex:
            ex.message = ("oil with name '{0}', not found in database.  "
                          "{1}".format(oil_, ex.message))
            ex.args = (ex.message, )
            raise ex
示例#4
0
def add_oil(record):
    print 'Estimations for {0}'.format(record.adios_oil_id)
    oil = Oil()
    oil.estimated = Estimated()

    add_demographics(record, oil)
    add_densities(record, oil)
    add_viscosities(record, oil)
    add_oil_water_interfacial_tension(record, oil)
    add_oil_seawater_interfacial_tension(record, oil)

    add_pour_point(record, oil)
    add_flash_point(record, oil)
    add_emulsion_water_fraction_max(record, oil)

    add_metals(record, oil)
    add_imported_sara_fractions(record, oil)
    add_misc_fractions(record, oil)

    add_resin_fractions(record, oil)
    add_asphaltene_fractions(record, oil)

    add_bullwinkle_fractions(record, oil)
    add_adhesion(record, oil)
    add_sulphur_mass_fraction(record, oil)
    add_soluability(record, oil)
    add_distillation_cut_boiling_point(record, oil)
    add_molecular_weights(record, oil)
    add_component_densities(record, oil)
    add_saturate_aromatic_fractions(record, oil)
    adjust_resin_asphaltene_fractions(record, oil)

    add_k0y(record, oil)

    reject_oil_if_bad(record, oil)

    record.oil = oil
示例#5
0
def test_get_oil_from_json():
    '''
        Ok, here we will test our ability to construct an oil object from
        a json payload.
    '''
    oil_from_db = get_oil('ALASKA NORTH SLOPE (MIDDLE PIPELINE, 1997)')
    oil_from_json = Oil.from_json(oil_from_db.tojson())

    # Do we want to fill in these properties???
    assert oil_from_json.imported is None
    assert oil_from_json.estimated is None

    for attr in ('adhesion_kg_m_2',
                 'api',
                 'bullwinkle_fraction',
                 'bullwinkle_time',
                 'emulsion_water_fraction_max',
                 'flash_point_max_k',
                 'flash_point_min_k',
                 'id',
                 'name',
                 'oil_seawater_interfacial_tension_n_m',
                 'oil_seawater_interfacial_tension_ref_temp_k',
                 'oil_water_interfacial_tension_n_m',
                 'oil_water_interfacial_tension_ref_temp_k',
                 'pour_point_max_k',
                 'pour_point_min_k',
                 'solubility',
                 'sulphur_fraction',
                 'k0y',):
        assert getattr(oil_from_db, attr) == getattr(oil_from_json, attr)

    for db_obj, json_obj in zip(oil_from_db.cuts, oil_from_json.cuts):
        for attr in ('liquid_temp_k', 'vapor_temp_k', 'fraction'):
            assert getattr(db_obj, attr) == getattr(json_obj, attr)

    for db_obj, json_obj in zip(oil_from_db.densities,
                                oil_from_json.densities):
        for attr in ('kg_m_3', 'ref_temp_k', 'weathering'):
            assert getattr(db_obj, attr) == getattr(json_obj, attr)

    for db_obj, json_obj in zip(oil_from_db.kvis,
                                oil_from_json.kvis):
        for attr in ('m_2_s', 'ref_temp_k', 'weathering'):
            assert getattr(db_obj, attr) == getattr(json_obj, attr)

    for db_obj, json_obj in zip(oil_from_db.molecular_weights,
                                oil_from_json.molecular_weights):
        for attr in ('g_mol', 'ref_temp_k', 'sara_type'):
            assert getattr(db_obj, attr) == getattr(json_obj, attr)

    for db_obj, json_obj in zip(oil_from_db.sara_densities,
                                oil_from_json.sara_densities):
        for attr in ('density', 'ref_temp_k', 'sara_type'):
            assert getattr(db_obj, attr) == getattr(json_obj, attr)

    for db_obj, json_obj in zip(oil_from_db.sara_fractions,
                                oil_from_json.sara_fractions):
        for attr in ('fraction', 'ref_temp_k', 'sara_type'):
            assert getattr(db_obj, attr) == getattr(json_obj, attr)

    for db_obj, json_obj in zip(oil_from_db.categories,
                                oil_from_json.categories):
        assert getattr(db_obj, 'name') == getattr(json_obj, 'name')
        assert (getattr(db_obj.parent, 'name') ==
                getattr(json_obj.parent, 'name'))
示例#6
0
def test_get_oil_from_json():
    '''
        Ok, here we will test our ability to construct an oil object from
        a json payload.
    '''
    oil_from_db = get_oil('ALASKA NORTH SLOPE (MIDDLE PIPELINE, 1997)')
    oil_from_json = Oil.from_json(oil_from_db.tojson())

    # Do we want to fill in these properties???
    assert oil_from_json.imported is None
    assert oil_from_json.estimated is None

    for attr in (
            'adhesion_kg_m_2',
            'api',
            'bullwinkle_fraction',
            'bullwinkle_time',
            'emulsion_water_fraction_max',
            'flash_point_max_k',
            'flash_point_min_k',
            'id',
            'name',
            'oil_seawater_interfacial_tension_n_m',
            'oil_seawater_interfacial_tension_ref_temp_k',
            'oil_water_interfacial_tension_n_m',
            'oil_water_interfacial_tension_ref_temp_k',
            'pour_point_max_k',
            'pour_point_min_k',
            'solubility',
            'sulphur_fraction',
            'k0y',
    ):
        assert getattr(oil_from_db, attr) == getattr(oil_from_json, attr)

    for db_obj, json_obj in zip(oil_from_db.cuts, oil_from_json.cuts):
        for attr in ('liquid_temp_k', 'vapor_temp_k', 'fraction'):
            assert getattr(db_obj, attr) == getattr(json_obj, attr)

    for db_obj, json_obj in zip(oil_from_db.densities,
                                oil_from_json.densities):
        for attr in ('kg_m_3', 'ref_temp_k', 'weathering'):
            assert getattr(db_obj, attr) == getattr(json_obj, attr)

    for db_obj, json_obj in zip(oil_from_db.kvis, oil_from_json.kvis):
        for attr in ('m_2_s', 'ref_temp_k', 'weathering'):
            assert getattr(db_obj, attr) == getattr(json_obj, attr)

    for db_obj, json_obj in zip(oil_from_db.molecular_weights,
                                oil_from_json.molecular_weights):
        for attr in ('g_mol', 'ref_temp_k', 'sara_type'):
            assert getattr(db_obj, attr) == getattr(json_obj, attr)

    for db_obj, json_obj in zip(oil_from_db.sara_densities,
                                oil_from_json.sara_densities):
        for attr in ('density', 'ref_temp_k', 'sara_type'):
            assert getattr(db_obj, attr) == getattr(json_obj, attr)

    for db_obj, json_obj in zip(oil_from_db.sara_fractions,
                                oil_from_json.sara_fractions):
        for attr in ('fraction', 'ref_temp_k', 'sara_type'):
            assert getattr(db_obj, attr) == getattr(json_obj, attr)

    for db_obj, json_obj in zip(oil_from_db.categories,
                                oil_from_json.categories):
        assert getattr(db_obj, 'name') == getattr(json_obj, 'name')
        assert (getattr(db_obj.parent,
                        'name') == getattr(json_obj.parent, 'name'))