示例#1
0
    def test_boundary_travel_time_anuga(self):
        '''
        Test running into the boundary and not reaching travel time target
        '''
        # defining / initializing
        an_particle = Particles(self.an_params)  # define the particle
        np.random.seed(0)  # fix the random seed

        # generate particles
        an_particle.generate_particles(self.Np_tracer, self.seed_xloc,
                                       self.seed_yloc)  # init walk data

        # set target time for iterations
        all_walk_data = an_particle.run_iteration(target_time=1000.0)

        # make assertions
        # check initial position and travel time
        assert all_walk_data['xinds'][0][0] == self.seed_xloc[0]
        assert all_walk_data['yinds'][0][0] == self.seed_yloc[0]
        assert all_walk_data['travel_times'][0][0] == 0.0
        # particle reaches boundary after 18 iterations
        # data shouldn't be recorded after boundary is reached
        assert len(all_walk_data['xinds'][0]) == 9
        assert len(all_walk_data['yinds'][0]) == 9
        assert len(all_walk_data['travel_times'][0]) == 9
示例#2
0
    def test_few_steps_RCM(self):
        '''
        Test running a few steps
        '''
        # defining / initializing
        particle = Particles(self.params)  # define the particle
        np.random.seed(0)  # fix the random seed
        # init the walk data
        particle.generate_particles(self.Np_tracer, self.seed_xloc,
                                    self.seed_yloc)

        # 3 iterations
        for i in list(range(0, 3)):
            all_walk_data = particle.run_iteration()

        # make assertions
        # check initial position and travel time
        assert all_walk_data['xinds'][0][0] == self.seed_xloc[0]
        assert all_walk_data['yinds'][0][0] == self.seed_yloc[0]
        assert all_walk_data['travel_times'][0][0] == 0.0
        # check all positions and times
        assert all_walk_data['xinds'][0] == [16, 17, 18, 19]
        assert all_walk_data['yinds'][0] == [140, 141, 141, 141]
        assert all_walk_data['travel_times'][0] == \
            [0, 7007593448.337235, 10439964733.462337, 13698473384.876724]
示例#3
0
def test_set_time_RCM():
    '''
    Test setting a time target
    '''
    # defining / initializing
    particle = Particles(params)  # define the particle
    np.random.seed(0)  # fix the random seed

    # generate particles
    particle.generate_particles(Np_tracer, seed_xloc,
                                seed_yloc)  # init the walk data

    # set time
    all_walk_data = particle.run_iteration(target_time=5e6)

    # make assertions
    # check initial position and travel time
    assert all_walk_data['xinds'][0][0] == seed_xloc[0]
    assert all_walk_data['yinds'][0][0] == seed_yloc[0]
    assert all_walk_data['travel_times'][0][0] == 0.0
    # check all positions and times
    assert pytest.approx(all_walk_data['xinds'][0] == [16, 17, 18, 19, 20])
    assert pytest.approx(
        all_walk_data['yinds'][0] == [140, 141, 141, 141, 142])
    assert pytest.approx(
        all_walk_data['travel_times'][0] ==
        [0.0, 1414213.56594, 2414213.56846, 3414213.57099, 4828427.13693])
示例#4
0
    def test_set_time_RCM_previousdata(self):
        '''
        Test setting a time target when using old walk data
        '''
        # defining / initializing
        particle = Particles(self.params)  # define the particle
        np.random.seed(0)  # fix the random seed

        # generate the particles
        particle.generate_particles(self.Np_tracer, self.seed_xloc,
                                    self.seed_yloc)  # init walk data

        # set time
        all_walk_data = particle.run_iteration(target_time=5e6)
        # make assertions
        # check initial position and travel time
        assert all_walk_data['xinds'][0][0] == self.seed_xloc[0]
        assert all_walk_data['yinds'][0][0] == self.seed_yloc[0]
        assert all_walk_data['travel_times'][0][0] == 0.0
        # check all positions and times
        assert all_walk_data['xinds'][0] == [16, 17]
        assert all_walk_data['yinds'][0] == [140, 141]
        assert all_walk_data['travel_times'][0] == [0, 7007593448.337235]
示例#5
0
    def test_boundary_anuga(self):
        '''
        Test running into the boundary
        '''
        # defining / initializing
        an_particle = Particles(self.an_params)  # define the particle
        np.random.seed(0)  # fix the random seed
        an_particle.generate_particles(self.Np_tracer, self.seed_xloc,
                                       self.seed_yloc)  # init walk data

        # 20 iterations
        for i in list(range(0, 20)):
            all_walk_data = an_particle.run_iteration()

        # make assertions
        # check initial position and travel time
        assert all_walk_data['xinds'][0][0] == self.seed_xloc[0]
        assert all_walk_data['yinds'][0][0] == self.seed_yloc[0]
        assert all_walk_data['travel_times'][0][0] == 0.0
        # particle reaches boundary after 18 iterations
        # data shouldn't be recorded after boundary is reached
        assert len(all_walk_data['xinds'][0]) == 15
        assert len(all_walk_data['yinds'][0]) == 15
        assert len(all_walk_data['travel_times'][0]) == 15
示例#6
0
    def test_few_steps_anuga(self):
        '''
        Test running a few steps
        '''
        # defining / initializing
        an_particle = Particles(self.an_params)  # define the particle
        np.random.seed(0)  # fix the random seed
        an_particle.generate_particles(self.Np_tracer, self.seed_xloc,
                                       self.seed_yloc)  # init walk data

        # 3 iterations
        for i in list(range(0, 3)):
            all_walk_data = an_particle.run_iteration()

        # make assertions
        # check initial position and travel time
        assert all_walk_data['xinds'][0][0] == self.seed_xloc[0]
        assert all_walk_data['yinds'][0][0] == self.seed_yloc[0]
        assert all_walk_data['travel_times'][0][0] == 0.0
        # check all positions and times
        assert all_walk_data['xinds'][0] == [5, 6, 7, 8]
        assert all_walk_data['yinds'][0] == [10, 10, 10, 10]
        assert all_walk_data['travel_times'][0] == \
            [0, 132.8105258698104, 258.1975289086354, 375.18128832888203]
示例#7
0
def test_few_steps_RCM():
    '''
    Test running a few steps
    '''
    # defining / initializing
    particle = Particles(params)  # define the particle
    np.random.seed(0)  # fix the random seed
    particle.generate_particles(Np_tracer, seed_xloc,
                                seed_yloc)  # init the walk data

    # 3 iterations
    for i in list(range(0, 3)):
        all_walk_data = particle.run_iteration()

    # make assertions
    # check initial position and travel time
    assert all_walk_data['xinds'][0][0] == seed_xloc[0]
    assert all_walk_data['yinds'][0][0] == seed_yloc[0]
    assert all_walk_data['travel_times'][0][0] == 0.0
    # check all positions and times
    assert pytest.approx(all_walk_data['xinds'][0] == [16, 17, 18, 19])
    assert pytest.approx(all_walk_data['yinds'][0] == [140, 141, 141, 141])
    assert pytest.approx(all_walk_data['travel_times'][0] ==
                         [0.0, 1414213.56594, 2414213.56846, 3414213.57099])
示例#8
0
def test_few_steps_anuga():
    '''
    Test running a few steps
    '''
    # defining / initializing
    an_particle = Particles(an_params)  # define the particle
    np.random.seed(0)  # fix the random seed
    an_particle.generate_particles(Np_tracer, seed_xloc,
                                   seed_yloc)  # init the walk data

    # 3 iterations
    for i in list(range(0, 3)):
        all_walk_data = an_particle.run_iteration()

    # make assertions
    # check initial position and travel time
    assert all_walk_data['xinds'][0][0] == seed_xloc[0]
    assert all_walk_data['yinds'][0][0] == seed_yloc[0]
    assert all_walk_data['travel_times'][0][0] == 0.0
    # check all positions and times
    assert pytest.approx(all_walk_data['xinds'][0] == [5, 6, 7, 8])
    assert pytest.approx(all_walk_data['yinds'][0] == [10, 10, 10, 10])
    assert pytest.approx(
        all_walk_data['travel_times'][0] == [0.0, 2.68302, 5.27901, 7.83891])
示例#9
0
"""Plot for quickstart demo 2 particle locations."""
import matplotlib.pyplot as plt
from dorado.example_data.define_params import make_anuga_params
from dorado.particle_track import Particles
import dorado as pr
import numpy as np

np.random.seed(1)  # make result consistent for docs
params = make_anuga_params()
particles = Particles(params)
seed_xloc = list(range(20, 30))
seed_yloc = list(range(48, 53))
Np_tracer = 50
particles.generate_particles(Np_tracer, seed_xloc, seed_yloc)
walk_data = particles.run_iteration(target_time=2100)
plt.figure(figsize=(8, 5))
pr.routines.plot_state(particles.depth, walk_data, iteration=0, c='b')
pr.routines.plot_state(particles.depth, walk_data, iteration=-1, c='r')
plt.title('Initial and Final Particle Locations')
plt.tight_layout()
plt.show()
示例#10
0
params.qy = qy
params.dx = 50.
params.theta = 1.0
params.model = 'Anuga'

# for parallel routing we define the particle information
seed_xloc = list(range(20, 30))
seed_yloc = list(range(48, 53))
Np_tracer = 200

# Apply the parameters to run the particle routing model

# use 2 cores to route in parallel
print('start parallel')
start_par_time = time.time()
particles = Particles(params)
par_result = parallel_routing(particles, 50, Np_tracer, seed_xloc, seed_yloc,
                              2)
par_time = time.time() - start_par_time
print('end parallel')

# compare to a serial run
print('start serial')
start_serial_time = time.time()
# do twice to match number of particles parallel is doing
for z in list(range(0, 2)):
    particle = Particles(params)
    particle.generate_particles(Np_tracer, seed_xloc, seed_yloc)
    # do 50 iterations to match parallel
    for i in list(range(0, 50)):
        all_walk = particle.run_iteration()