def test_initialize_InitRiseVelFromDropletDist_weibull():
    'Test initialize data_arrays with Weibull dist'
    num_elems = 10
    data_arrays = mock_append_data_arrays(rise_vel_diameter_array, num_elems)
    substance = get_oil_props(oil)
    spill = Spill(Release(datetime.now()))

    # (.001*.2) / (.693 ** (1 / 1.8)) - smaller droplet test case, in mm
    #                                   so multiply by .001
    dist = WeibullDistribution(alpha=1.8, lambda_=.000248)
    fcn = InitRiseVelFromDropletSizeFromDist(dist)
    fcn.initialize(num_elems, spill, data_arrays, substance)

    assert_dataarray_shape_size(rise_vel_array, data_arrays, num_elems)

    assert np.all(0 != data_arrays['rise_vel'])
    assert np.all(0 != data_arrays['droplet_diameter'])
Example #2
0
def test_initialize_InitRiseVelFromDropletDist_weibull():
    'Test initialize data_arrays with Weibull dist'
    num_elems = 10
    data_arrays = mock_append_data_arrays(rise_vel_diameter_array, num_elems)
    substance = get_oil_props(oil)
    spill = Spill(Release(datetime.now()), water=Water())

    # (.001*.2) / (.693 ** (1 / 1.8)) - smaller droplet test case, in mm
    #                                   so multiply by .001
    dist = WeibullDistribution(alpha=1.8, lambda_=.000248)
    fcn = InitRiseVelFromDropletSizeFromDist(dist)
    fcn.initialize(num_elems, spill, data_arrays, substance)

    assert_dataarray_shape_size(rise_vel_array, data_arrays, num_elems)

    assert np.all(0 != data_arrays['rise_vel'])
    assert np.all(0 != data_arrays['droplet_diameter'])
def test_initialize_InitRiseVelFromDropletDist_weibull_with_min_max():
    "Test initialize data_arrays with Weibull dist"
    num_elems = 1000
    data_arrays = mock_append_data_arrays(rise_vel_diameter_array, num_elems)
    substance = OilProps("oil_conservative")
    spill = Spill(Release(datetime.now()))

    # (.001*3.8) / (.693 ** (1 / 1.8)) - larger droplet test case, in mm
    #                                    so multiply by .001
    dist = WeibullDistribution(min_=0.002, max_=0.004, alpha=1.8, lambda_=0.00456)
    fcn = InitRiseVelFromDropletSizeFromDist(dist)
    fcn.initialize(num_elems, spill, data_arrays, substance)

    # test for the larger droplet case above
    assert np.all(data_arrays["droplet_diameter"] >= 0.002)

    # test for the larger droplet case above
    assert np.all(data_arrays["droplet_diameter"] <= 0.004)
Example #4
0
def test_initialize_InitRiseVelFromDropletDist_weibull_with_min_max():
    'Test initialize data_arrays with Weibull dist'
    num_elems = 1000
    data_arrays = mock_append_data_arrays(rise_vel_diameter_array, num_elems)
    substance = get_oil_props(oil)
    spill = Spill(Release(datetime.now()), water=Water())

    # (.001*3.8) / (.693 ** (1 / 1.8)) - larger droplet test case, in mm
    #                                    so multiply by .001
    dist = WeibullDistribution(min_=0.002, max_=0.004,
                               alpha=1.8, lambda_=.00456)
    fcn = InitRiseVelFromDropletSizeFromDist(dist)
    fcn.initialize(num_elems, spill, data_arrays, substance)

    # test for the larger droplet case above
    assert np.all(data_arrays['droplet_diameter'] >= .002)

    # test for the larger droplet case above
    assert np.all(data_arrays['droplet_diameter'] <= .004)
def test_SpillContainer_add_array_types():
    '''
    Test an array_type is dynamically added/subtracted from SpillContainer if
    it is contained in Initailizer's array_types property.

    For example:

        Add 'rise_vel' initializer, InitRiseVelFromDropletSizeFromDist()) is
        added to Spill's element_type object. Now, the array_types for this
        initailizer are 'rise_vel' and 'droplet_diameter'. Only if a
        RiseVelocityMover is added to the model in which case the Model
        provides 'rise_vel' as an array_type to the SpillContainer to append
        it to its own list, then the SpillContainer will also add the
        'droplet_diameter' array_type that is additionally set by the
        Initializer but is not explicitly required by the Mover.
    '''
    sc = SpillContainer()
    s = Spill(Release(datetime(2014, 1, 1, 12, 0), 0))
    s.set_initializer(
        InitRiseVelFromDropletSizeFromDist(distribution=UniformDistribution()))
    sc.spills += s
    assert 'rise_vel' not in sc.array_types
    assert 'droplet_diameter' not in sc.array_types

    # Now say you added RiseVelocityMover and the Model collects ArrayTypes
    # from all movers and passes it into SpillContainer's prepare_for_model_run
    #
    sc.prepare_for_model_run(array_types={'rise_vel'})
    assert 'rise_vel' in sc.array_types
    assert 'droplet_diameter' in sc.array_types

    # calling prepare_for_model_run without different array_types keeps the
    # previously added 'rise_vel' array_types - always rewind if you want to
    # clear out the state and reset array_types to original data
    sc.prepare_for_model_run()
    assert 'rise_vel' in sc.array_types
    assert 'droplet_diameter' in sc.array_types

    # Now let's rewind array_types and these extra properties should disappear
    # they are only added after the prepare_for_model_run step
    sc.rewind()
    sc.prepare_for_model_run()
    assert 'rise_vel' not in sc.array_types
    assert 'droplet_diameter' not in sc.array_types
Example #6
0
    for key, val in arr_types.iteritems():
        assert data_arrays[key].dtype == val.dtype
        assert data_arrays[key].shape == (num_released,) + val.shape


""" Initializers - following are used for parameterizing tests """
fcn_list = (InitWindages(),
            InitRiseVelFromDist(distribution=UniformDistribution()),
            InitRiseVelFromDist(distribution=NormalDistribution(mean=0,
                                                                sigma=0.1)),
            InitRiseVelFromDist(distribution=LogNormalDistribution(mean=0,
                                                                   sigma=0.1)),
            InitRiseVelFromDist(distribution=WeibullDistribution(alpha=1.8,
                                                                 lambda_=(1 / (.693 ** (1 / 1.8)))
                                                                 )),
            InitRiseVelFromDropletSizeFromDist(NormalDistribution(mean=0,
                                                                  sigma=0.1))
            )

arrays_ = (windages,
           rise_vel_array, rise_vel_array, rise_vel_array, rise_vel_array,
           rise_vel_diameter_array)

spill_list = (None, None, None, None, None,
              Spill(Release(datetime.now()), water=Water()))


@pytest.mark.parametrize(("fcn", "arr_types", "spill"),
                         zip(fcn_list, arrays_, spill_list))
def test_correct_particles_set_by_initializers(fcn, arr_types, spill):
    '''
    Tests that the correct elements (ones that