Пример #1
0
def model(sample_model, output_dir):
    model = sample_model['model']
    rel_start_pos = sample_model['release_start_pos']
    rel_end_pos = sample_model['release_end_pos']

    model.start_time = datetime(2015, 5, 14, 0)
    model.cache_enabled = True
    model.uncertain = True

    N = 10  # a line of ten points
    line_pos = np.zeros((N, 3), dtype=np.float64)
    line_pos[:, 0] = np.linspace(rel_start_pos[0], rel_end_pos[0], N)
    line_pos[:, 1] = np.linspace(rel_start_pos[1], rel_end_pos[1], N)

    start_pos = (-164.01696, 72.921024, 0)
    model.spills += point_line_release_spill(1,
                                             start_position=start_pos,
                                             release_time=model.start_time,
                                             end_position=start_pos)

    release = SpatialRelease(start_position=line_pos,
                             release_time=model.start_time)

    model.spills += Spill(release)

    model.movers += c_ice_mover

    model.outputters += IceGeoJsonOutput([c_ice_mover])

    model.rewind()

    return model
Пример #2
0
def model(sample_model, output_dir):
    model = sample_model['model']
    rel_start_pos = sample_model['release_start_pos']
    rel_end_pos = sample_model['release_end_pos']

    model.cache_enabled = True
    model.uncertain = True

    N = 10  # a line of ten points
    line_pos = np.zeros((N, 3), dtype=np.float64)
    line_pos[:, 0] = np.linspace(rel_start_pos[0], rel_end_pos[0], N)
    line_pos[:, 1] = np.linspace(rel_start_pos[1], rel_end_pos[1], N)

    # print start_points
    model.environment += td

    model.spills += point_line_release_spill(1,
                                             start_position=rel_start_pos,
                                             release_time=model.start_time,
                                             end_position=rel_end_pos)

    release = SpatialRelease(start_position=line_pos,
                             release_time=model.start_time)

    model.spills += Spill(release)

    model.movers += c_cats

    model.outputters += CurrentJsonOutput([c_cats])

    model.rewind()

    return model
Пример #3
0
def test_simple_run_with_image_output_uncertainty(tmpdir):
    '''
    Pretty much all this tests is that the model will run and output images
    '''
    images_dir = tmpdir.mkdir('Test_images2').strpath

    if os.path.isdir(images_dir):
        shutil.rmtree(images_dir)
    os.mkdir(images_dir)

    start_time = datetime(2012, 9, 15, 12, 0)

    # the land-water map
    gmap = gnome.map.MapFromBNA(testdata['MapFromBNA']['testmap'],
                                refloat_halflife=6)  # hours
    renderer = gnome.outputters.Renderer(testdata['MapFromBNA']['testmap'],
                                         images_dir, size=(400, 300))

    model = Model(start_time=start_time,
                  time_step=timedelta(minutes=15), duration=timedelta(hours=1),
                  map=gmap,
                  uncertain=True, cache_enabled=False,
                  )

    model.outputters += renderer
    a_mover = SimpleMover(velocity=(1., -1., 0.))
    model.movers += a_mover

    N = 10  # a line of ten points
    start_points = np.zeros((N, 3), dtype=np.float64)
    start_points[:, 0] = np.linspace(-127.1, -126.5, N)
    start_points[:, 1] = np.linspace(47.93, 48.1, N)
    # print start_points

    release = SpatialRelease(start_position=start_points,
                             release_time=start_time)

    model.spills += Spill(release)

    # model.add_spill(spill)

    model.start_time = release.release_time

    # image_info = model.next_image()

    model.uncertain = True
    num_steps_output = 0
    while True:
        try:
            image_info = model.step()
            num_steps_output += 1
            print image_info
        except StopIteration:
            print 'Done with the model run'
            break

    # there is the zeroth step, too.
    calculated_steps = (model.duration.total_seconds() / model.time_step) + 1
    assert num_steps_output == calculated_steps
Пример #4
0
def sample_spatial_release_spill():
    """
    creates an example SpatialRelease object with
    start_positions: ((0., 0., 0.), (28.0, -75.0, 0.), (-15, 12, 4.0),
                   (80, -80, 100.0))
    release_time: datetime(2012, 1, 1, 1)
    :returns: a tuple containing (spill, start_positions). start_positions
        should be equal to spill.start_positions
    """
    from gnome.spill import SpatialRelease
    start_positions = ((0., 0., 0.), (28.0, -75.0, 0.), (-15, 12, 4.0),
                       (80, -80, 100.0))

    rel = SpatialRelease(datetime(2012, 1, 1, 1), start_positions)
    sp = gnome.spill.Spill(release=rel)

    return (sp, start_positions)
Пример #5
0
    def test_set_newparticle_positions(self):
        'define two spatial releases and check positions are set correctly'
        sp2 = Spill(
            SpatialRelease(self.sp.release.release_time,
                           ((0, 0, 0), (0, 0, 0))))
        (data_arrays, num) = release_elements(self.sp,
                                              self.sp.release.release_time,
                                              600)
        # fixme -- should we be checking for the release inside the Spill?
        assert (self.sp.num_released == self.sp.release.num_elements
                and self.sp.release.num_elements == num)

        (data_arrays, num2) = release_elements(sp2, sp2.release.release_time,
                                               600, data_arrays)
        assert (sp2.num_released == sp2.release.num_elements
                and len(data_arrays['positions']) == num2 + num)
        assert (np.all(
            data_arrays['positions'][:num, :] == self.sp.start_position))
        assert (np.all(
            data_arrays['positions'][num:, :] == sp2.start_position))
Пример #6
0
    def test_set_newparticle_positions(self):
        'define two spatial releases and check positions are set correctly'
        sp2 = Spill(
            SpatialRelease(self.sp.release.release_time,
                           ((0, 0, 0), (0, 0, 0))))
        (data_arrays, num) = release_elements(self.sp,
                                              self.sp.release.release_time,
                                              600)
        assert (self.sp.get('num_released') == self.sp.release.num_elements
                and self.sp.release.num_elements == num)

        (data_arrays, num2) = release_elements(sp2, sp2.release.release_time,
                                               600, data_arrays)
        assert (sp2.get('num_released') == sp2.release.num_elements
                and len(data_arrays['positions']) == num2 + num)
        assert (np.all(
            data_arrays['positions'][:num, :] == self.sp.get('start_position'))
                )
        assert (np.all(
            data_arrays['positions'][num:, :] == sp2.get('start_position')))
Пример #7
0
def model(sample_model_fcn, tmpdir):
    '''
    Utility to setup up a simple, but complete model for tests
    '''
    images_dir = tmpdir.mkdir('Test_images').strpath

    if os.path.isdir(images_dir):
        shutil.rmtree(images_dir)
    os.mkdir(images_dir)

    model = sample_model_fcn['model']
    rel_start_pos = sample_model_fcn['release_start_pos']
    rel_end_pos = sample_model_fcn['release_end_pos']

    model.cache_enabled = True
    model.uncertain = False

    model.outputters += Renderer(model.map.filename,
                                 images_dir,
                                 size=(400, 300))

    N = 10  # a line of ten points
    line_pos = np.zeros((N, 3), dtype=np.float64)
    line_pos[:, 0] = np.linspace(rel_start_pos[0], rel_end_pos[0], N)
    line_pos[:, 1] = np.linspace(rel_start_pos[1], rel_end_pos[1], N)

    # print start_points

    release = SpatialRelease(start_position=line_pos,
                             release_time=model.start_time)

    model.spills += Spill(release, substance=test_oil)

    # for weatherers and environment objects, make referenced to default
    # wind/water/waves
    model.set_make_default_refs(True)

    return model