Beispiel #1
0
def test_two_substance_different(sample_model_fcn,
                                 s0=test_oil,
                                 s1="ARABIAN MEDIUM, EXXON"):
    '''
    The model (SpillContainer) does not allow two different substances.

    Keeping this test in case we do want to extend it some day.

    only tests data arrays are correct and we don't end up with stale data
    in substance_data structure of spill container. It models each substance
    independently

    We don't accurately model two oils at present. This is a basic test,
    maybe a useful example when extending code to multiple oils. It is also
    useful for catching bugs when doing a refactor so leave it in.
    '''
    model = sample_model_weathering(sample_model_fcn, s0)
    model.map = gnome.map.GnomeMap()  # make it all water
    model.uncertain = False
    rel_time = model.spills[0].release_time
    model.duration = timedelta(days=1)

    et = floating(substance=s1)
    cs = point_line_release_spill(500, (0, 0, 0),
                                  rel_time,
                                  end_release_time=(rel_time +
                                                    timedelta(hours=1)),
                                  element_type=et,
                                  amount=1,
                                  units='tonnes')

    with pytest.raises(ValueError):
        model.spills += cs
Beispiel #2
0
def test_contains_object(sample_model_fcn):
    '''
    Test that we can find all contained object types with a model.
    '''
    model = sample_model_weathering(sample_model_fcn, test_oil)

    gnome_map = model.map = gnome.map.GnomeMap()    # make it all water

    rel_time = model.spills[0].get('release_time')
    model.start_time = rel_time - timedelta(hours=1)
    model.duration = timedelta(days=1)

    water, wind = Water(), constant_wind(1., 0)
    model.environment += [water, wind]

    et = floating(substance=model.spills[0].get('substance').name)
    sp = point_line_release_spill(500, (0, 0, 0),
                                  rel_time + timedelta(hours=1),
                                  element_type=et,
                                  amount=100,
                                  units='tons')
    rel = sp.release
    initializers = et.initializers
    model.spills += sp

    movers = [m for m in model.movers]

    evaporation = Evaporation()
    skim_start = sp.get('release_time') + timedelta(hours=1)
    skimmer = Skimmer(.5*sp.amount, units=sp.units, efficiency=0.3,
                      active_start=skim_start,
                      active_stop=skim_start + timedelta(hours=1))
    burn = burn_obj(sp)
    disp_start = skim_start + timedelta(hours=1)
    dispersion = ChemicalDispersion(0.1,
                                    active_start=disp_start,
                                    active_stop=disp_start + timedelta(hours=1)
                                    )

    model.weatherers += [evaporation, dispersion, burn, skimmer]

    renderer = Renderer(images_dir='junk', size=(400, 300))
    model.outputters += renderer

    for o in (gnome_map, sp, rel, et,
              water, wind,
              evaporation, dispersion, burn, skimmer,
              renderer):
        assert model.contains_object(o.id)

    for o in initializers:
        assert model.contains_object(o.id)

    for o in movers:
        assert model.contains_object(o.id)
Beispiel #3
0
def test_contains_object(sample_model_fcn):
    '''
    Test that we can find all contained object types with a model.
    '''
    model = sample_model_weathering(sample_model_fcn, test_oil)

    gnome_map = model.map = gnome.map.GnomeMap()  # make it all water

    rel_time = model.spills[0].get('release_time')
    model.start_time = rel_time - timedelta(hours=1)
    model.duration = timedelta(days=1)

    water, wind = Water(), constant_wind(1., 0)
    model.environment += [water, wind]

    et = floating(substance=model.spills[0].get('substance').name)
    sp = point_line_release_spill(500, (0, 0, 0),
                                  rel_time + timedelta(hours=1),
                                  element_type=et,
                                  amount=100,
                                  units='tons')
    rel = sp.release
    initializers = et.initializers
    model.spills += sp

    movers = [m for m in model.movers]

    evaporation = Evaporation()
    skim_start = sp.get('release_time') + timedelta(hours=1)
    skimmer = Skimmer(.5 * sp.amount,
                      units=sp.units,
                      efficiency=0.3,
                      active_start=skim_start,
                      active_stop=skim_start + timedelta(hours=1))
    burn = burn_obj(sp)
    disp_start = skim_start + timedelta(hours=1)
    dispersion = ChemicalDispersion(0.1,
                                    active_start=disp_start,
                                    active_stop=disp_start +
                                    timedelta(hours=1))

    model.weatherers += [evaporation, dispersion, burn, skimmer]

    renderer = Renderer(images_dir='junk', size=(400, 300))
    model.outputters += renderer

    for o in (gnome_map, sp, rel, et, water, wind, evaporation, dispersion,
              burn, skimmer, renderer):
        assert model.contains_object(o.id)

    for o in initializers:
        assert model.contains_object(o.id)

    for o in movers:
        assert model.contains_object(o.id)
Beispiel #4
0
def test_staggered_spills_weathering(sample_model_fcn, delay):
    '''
    Test that a model with weathering and spills staggered in time runs
    without errors. Also test that a continuous + instant release works
    correctly where the total amount_released is the sum of oil removed by
    weathering processes

    test exposed a bug, which is now fixed
    '''
    model = sample_model_weathering(sample_model_fcn, test_oil)
    model.map = gnome.map.GnomeMap()    # make it all water
    model.uncertain = False
    rel_time = model.spills[0].get('release_time')
    model.start_time = rel_time - timedelta(hours=1)
    model.duration = timedelta(days=1)

    # test with outputter + w/ cache enabled
    model.cache = True
    model.outputters += gnome.outputters.WeatheringOutput()

    et = floating(substance=model.spills[0].get('substance').name)
    cs = point_line_release_spill(500, (0, 0, 0),
                                  rel_time + delay,
                                  end_release_time=(rel_time + delay +
                                                    timedelta(hours=1)),
                                  element_type=et,
                                  amount=1,
                                  units='tonnes')
    model.spills += cs

    # ensure amount released is equal to exp_total_mass
    exp_total_mass = 0.0
    for spill in model.spills:
        exp_total_mass += spill.get_mass()

    skimmer = make_skimmer(model.spills[0])
    burn = burn_obj(model.spills[0])
    c_disp = chemical_disperson_obj(model.spills[0], 4)

    model.environment += [Water(), constant_wind(1., 0)]
    model.weatherers += [Evaporation(),
                         c_disp,
                         burn,
                         skimmer]
    model.set_make_default_refs(True)

    # model.full_run()
    for step in model:
        if not step['valid']:
            print step['messages']
            raise RuntimeError("Model has error in setup_model_run")

        for sc in model.spills.items():
            print "completed step {0}".format(step)
            # sum up all the weathered mass + mass of LEs marked for weathering
            # and ensure this equals the total amount released
            print (sc.mass_balance['beached'],
                   sc.mass_balance['burned'],
                   sc.mass_balance['chem_dispersed'],
                   sc.mass_balance['evaporated'],
                   sc.mass_balance['floating'],
                   sc.mass_balance['skimmed'],
                   )
            sum_ = (sc.mass_balance['beached'] +
                    sc.mass_balance['burned'] +
                    sc.mass_balance['chem_dispersed'] +
                    sc.mass_balance['evaporated'] +
                    sc.mass_balance['floating'] +
                    sc.mass_balance['skimmed']
                    )

            assert abs(sum_ - sc.mass_balance['amount_released']) < 1.e-6

    assert sc.mass_balance['burned'] > 0
    assert sc.mass_balance['skimmed'] > 0

    assert np.isclose(exp_total_mass, sc.mass_balance['amount_released'])
Beispiel #5
0
def test_two_substance_spills_weathering(sample_model_fcn, s0, s1):
    '''
    only tests data arrays are correct and we don't end up with stale data
    in substance_data structure of spill container. It models each substance
    independently

    We don't accurately model two oils at present. This is a basic test,
    maybe a useful example when extending code to multiple oils. It is also
    useful for catching bugs when doing a refactor so leave it in.
    '''
    model = sample_model_weathering(sample_model_fcn, s0)
    model.map = gnome.map.GnomeMap()    # make it all water
    model.uncertain = False
    rel_time = model.spills[0].get('release_time')
    model.duration = timedelta(days=1)

    et = floating(substance=s1)
    cs = point_line_release_spill(500, (0, 0, 0),
                                  rel_time,
                                  end_release_time=(rel_time +
                                                    timedelta(hours=1)),
                                  element_type=et,
                                  amount=1,
                                  units='tonnes')
    model.spills += cs

    # ensure amount released is equal to exp_total_mass
    exp_total_mass = 0.0
    for spill in model.spills:
        exp_total_mass += spill.get_mass()

    model.environment += [Water(), constant_wind(1., 0)]
    # model will automatically setup default references
    model.weatherers += Evaporation()
    if s0 == s1:
        '''
        multiple substances will not work with Skimmer or Burn
        '''
        c_disp = chemical_disperson_obj(model.spills[0], 3)
        burn = burn_obj(model.spills[0], 2.5)
        skimmer = make_skimmer(model.spills[0], 2)

        model.weatherers += [c_disp, burn, skimmer]

    model.set_make_default_refs(True)

    # model.full_run()
    for step in model:
        for sc in model.spills.items():
            # sum up all the weathered mass + mass of LEs marked for weathering
            # and ensure this equals the total amount released
            sum_ = 0.0

            if s0 == s1:
                # mass marked for skimming/burning/dispersion that is not yet
                # removed - cleanup operations only work on single substance
                sum_ += (sc.mass_balance['burned'] +
                         sc.mass_balance['chem_dispersed'] +
                         sc.mass_balance['skimmed'])

            sum_ += (sc.mass_balance['beached'] +
                     sc.mass_balance['evaporated'] +
                     sc.mass_balance['floating'])

            assert abs(sum_ - sc.mass_balance['amount_released']) < 1.e-6

        print "completed step {0}".format(step)

    assert np.isclose(exp_total_mass, sc.mass_balance['amount_released'])
Beispiel #6
0
def test_staggered_spills_weathering(sample_model_fcn, delay):
    '''
    Test that a model with weathering and spills staggered in time runs
    without errors. Also test that a continuous + instant release works
    correctly where the total amount_released is the sum of oil removed by
    weathering processes

    test exposed a bug, which is now fixed
    '''
    model = sample_model_weathering(sample_model_fcn, test_oil)
    model.map = gnome.map.GnomeMap()  # make it all water
    model.uncertain = False
    rel_time = model.spills[0].get('release_time')
    model.start_time = rel_time - timedelta(hours=1)
    model.duration = timedelta(days=1)

    # test with outputter + w/ cache enabled
    model.cache = True
    model.outputters += gnome.outputters.WeatheringOutput()

    et = floating(substance=model.spills[0].get('substance').name)
    cs = point_line_release_spill(500, (0, 0, 0),
                                  rel_time + delay,
                                  end_release_time=(rel_time + delay +
                                                    timedelta(hours=1)),
                                  element_type=et,
                                  amount=1,
                                  units='tonnes')
    model.spills += cs

    # ensure amount released is equal to exp_total_mass
    exp_total_mass = 0.0
    for spill in model.spills:
        exp_total_mass += spill.get_mass()

    skimmer = make_skimmer(model.spills[0])
    burn = burn_obj(model.spills[0])
    c_disp = chemical_disperson_obj(model.spills[0], 4)

    model.environment += [Water(), constant_wind(1., 0)]
    model.weatherers += [Evaporation(), c_disp, burn, skimmer]
    model.set_make_default_refs(True)

    # model.full_run()
    for step in model:
        if not step['valid']:
            print step['messages']
            raise RuntimeError("Model has error in setup_model_run")

        for sc in model.spills.items():
            print "completed step {0}".format(step)
            # sum up all the weathered mass + mass of LEs marked for weathering
            # and ensure this equals the total amount released
            print(
                sc.mass_balance['beached'],
                sc.mass_balance['burned'],
                sc.mass_balance['chem_dispersed'],
                sc.mass_balance['evaporated'],
                sc.mass_balance['floating'],
                sc.mass_balance['skimmed'],
            )
            sum_ = (sc.mass_balance['beached'] + sc.mass_balance['burned'] +
                    sc.mass_balance['chem_dispersed'] +
                    sc.mass_balance['evaporated'] +
                    sc.mass_balance['floating'] + sc.mass_balance['skimmed'])

            assert abs(sum_ - sc.mass_balance['amount_released']) < 1.e-6

    assert sc.mass_balance['burned'] > 0
    assert sc.mass_balance['skimmed'] > 0

    assert np.isclose(exp_total_mass, sc.mass_balance['amount_released'])
Beispiel #7
0
def test_two_substance_spills_weathering(sample_model_fcn, s0, s1):
    '''
    only tests data arrays are correct and we don't end up with stale data
    in substance_data structure of spill container. It models each substance
    independently

    We don't accurately model two oils at present. This is a basic test,
    maybe a useful example when extending code to multiple oils. It is also
    useful for catching bugs when doing a refactor so leave it in.
    '''
    model = sample_model_weathering(sample_model_fcn, s0)
    model.map = gnome.map.GnomeMap()  # make it all water
    model.uncertain = False
    rel_time = model.spills[0].get('release_time')
    model.duration = timedelta(days=1)

    et = floating(substance=s1)
    cs = point_line_release_spill(500, (0, 0, 0),
                                  rel_time,
                                  end_release_time=(rel_time +
                                                    timedelta(hours=1)),
                                  element_type=et,
                                  amount=1,
                                  units='tonnes')
    model.spills += cs

    # ensure amount released is equal to exp_total_mass
    exp_total_mass = 0.0
    for spill in model.spills:
        exp_total_mass += spill.get_mass()

    model.environment += [Water(), constant_wind(1., 0)]
    # model will automatically setup default references
    model.weatherers += Evaporation()
    if s0 == s1:
        '''
        multiple substances will not work with Skimmer or Burn
        '''
        c_disp = chemical_disperson_obj(model.spills[0], 3)
        burn = burn_obj(model.spills[0], 2.5)
        skimmer = make_skimmer(model.spills[0], 2)

        model.weatherers += [c_disp, burn, skimmer]

    model.set_make_default_refs(True)

    # model.full_run()
    for step in model:
        for sc in model.spills.items():
            # sum up all the weathered mass + mass of LEs marked for weathering
            # and ensure this equals the total amount released
            sum_ = 0.0

            if s0 == s1:
                # mass marked for skimming/burning/dispersion that is not yet
                # removed - cleanup operations only work on single substance
                sum_ += (sc.mass_balance['burned'] +
                         sc.mass_balance['chem_dispersed'] +
                         sc.mass_balance['skimmed'])

            sum_ += (sc.mass_balance['beached'] +
                     sc.mass_balance['evaporated'] +
                     sc.mass_balance['floating'])

            assert abs(sum_ - sc.mass_balance['amount_released']) < 1.e-6

        print "completed step {0}".format(step)

    assert np.isclose(exp_total_mass, sc.mass_balance['amount_released'])