def test_stage_via_depth_topo_broken(self): params = particle_track.modelParams() params.dx = 1 params.topography = 'badstring' params.depth = np.ones((3,3)) params.u = np.ones((3,3)) params.v = np.ones((3,3)) with pytest.raises(ValueError): particle = particle_track.Particles(params)
def test_rcm_model_uv_broken(self): params = particle_track.modelParams() params.dx = 1 params.depth = np.ones((3, 3)) params.topography = np.zeros((3, 3)) params.u = np.ones((3, 3)) params.model = 'DeltaRCM' with pytest.raises(ValueError): particle = particle_track.Particles(params)
def test_depth_via_stage_topo(self): params = particle_track.modelParams() params.dx = 1 params.stage = np.ones((3,3)) params.topography = np.zeros((3,3)) params.u = np.ones((3,3)) params.v = np.ones((3,3)) particle = particle_track.Particles(params) # should work so make assertion assert np.all(particle.depth == params.stage-params.topography)
def test_init_params(): # test initialization of params class params = particle_track.modelParams() # make assertions assert params.dx is None assert params.depth is None assert params.stage is None assert params.qx is None assert params.qy is None assert params.u is None assert params.v is None
def test_stage_via_depth_topo(self): params = particle_track.modelParams() params.dx = 1 params.topography = np.zeros((3,3)) params.depth = np.ones((3,3)) params.depth[0,0] = 0 params.u = np.ones((3,3)) params.v = np.ones((3,3)) particle = particle_track.Particles(params) # should work so make assertion assert np.isnan(particle.stage[0,0]) == True assert particle.stage[1,1] == 1.
def test_model_q(self): params = particle_track.modelParams() params.dx = 1 params.depth = np.ones((3,3)) params.topography = np.zeros((3,3)) params.qx = np.ones((3,3)) params.qy = np.ones((3,3)) particle = particle_track.Particles(params) # should work so make assertion assert np.all(particle.v == particle.qy*particle.depth/(particle.depth**2+1e-8)) assert np.all(particle.u == particle.qx*particle.depth/(particle.depth**2+1e-8)) assert np.all(particle.qx == -1*params.qy) assert np.all(particle.qy == params.qx)
def test_rcm_model_uv(self): params = particle_track.modelParams() params.dx = 1 params.depth = np.ones((3,3)) params.topography = np.zeros((3,3)) params.u = np.ones((3,3)) params.v = np.ones((3,3)) params.model = 'DeltaRCM' particle = particle_track.Particles(params) # should work so make assertion assert np.all(particle.v == params.v) assert np.all(particle.u == params.u) assert np.all(particle.qx == params.u*params.depth) assert np.all(particle.qy == params.v*params.depth)
def init_particles(init_x, init_y, Np_tracer, grid_spacing, gridded_vals): """Initialize the particles. Inputs : init_x : `list` List of starting x locations for the particles init_y : `list` List of starting y locations for the particles Np_tracer : `int` Number of particles to route grid_spacing : `int` Size of the raster grid cells gridded_vals : `obj` gridded_vals object from map_fun.py Outputs : params : `obj` an initialized params class """ # create class params = pt.modelParams() # populate with required parameters params.seed_xloc = init_y params.seed_yloc = init_x params.u = gridded_vals.ex params.v = gridded_vals.ey params.depth = gridded_vals.depth params.topography = gridded_vals.elev params.Np_tracer = Np_tracer params.dx = grid_spacing # hold ebb and flood velocity components in the class too params.ex = gridded_vals.ex params.ey = gridded_vals.ey params.fx = gridded_vals.fx params.fy = gridded_vals.fy return params
def test_missing_depth(self): params = particle_track.modelParams() params.dx = 1 with pytest.raises(ValueError): particle = particle_track.Particles(params)
def test_broken_depth(self): params = particle_track.modelParams() params.dx = 1 params.depth = 'badstring' with pytest.raises(ValueError): particle = particle_track.Particles(params)
def test_dx(self): params = particle_track.modelParams() with pytest.raises(ValueError): particle = particle_track.Particles(params)
class TestRCM: """Class to test particles on RCM field.""" # set up DeltaRCM test case rcm_data = np.load('tests/data/ex_deltarcm_data.npz') params = pt.modelParams() params.stage = rcm_data['stage'] params.depth = rcm_data['depth'] params.dx = 50. # just do one particle in a set location for this test seed_xloc = [16] seed_yloc = [140] Np_tracer = 1 # no discharge data so use 0s as substitute params.qx = np.zeros_like(params.depth) params.qy = np.zeros_like(params.depth) params.model = 'DeltaRCM' 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] 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] def test_set_time_RCM(self): ''' Test setting a time target ''' # defining / initializing particle = Particles(self.params) # define the particle np.random.seed(0) # fix the random seed # generate 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]
class TestANUGA: """Class to test particles on ANUGA flow field.""" # set up anuga test case - going to use subset of domain an_data = np.load('tests/data/ex_anuga_data.npz') an_params = pt.modelParams() an_params.stage = an_data['depth'][40:61, 40:61] # just using depth here an_params.depth = an_data['depth'][40:61, 40:61] # just do one particle in a set location for this test seed_xloc = [5] seed_yloc = [10] Np_tracer = 1 an_params.dx = 50. # no discharge data so use 0s as substitute an_params.qx = an_data['qx'][40:61, 40:61] an_params.qy = an_data['qy'][40:61, 40:61] an_params.model = 'Anuga' 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] 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 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
import numpy as np import os.path from dorado.routines import steady_plots import dorado.particle_track as pt # load some variables from a deltarcm output so stage is varied f_path = os.path.abspath(os.path.dirname(__file__)) data_path = os.path.join(f_path, 'ex_deltarcm_data.npz') data = np.load(data_path) # pull depth and stage from that data stage = data['stage'] depth = data['depth'] # create params and then assign the parameters params = pt.modelParams() # define the params variables params.stage = stage params.depth = depth params.dx = 50. # don't have any discharge data so we use zeros in place of it # weighting scheme uses both discharge and depth so can still weight # based on the water depths params.qx = np.zeros(np.shape(params.depth)) params.qy = np.zeros(np.shape(params.depth)) params.theta = 1.0 params.steepest_descent = True params.model = 'DeltaRCM' # say that our inputs are from DeltaRCM # define particle information
# The particle_track module is loaded to help define the particle parameters. # The routines module is used to access the high-level API functions for # particle movement on a steady flow field, and plotting particle locations. import numpy as np from dorado import particle_track from dorado import routines # Here we define the parameters for the particle routing. Since we are # simulating the generic random walk here, we set our water depth and stage to # all 1s, and the flow discharge components to all 0s. In this case we are # seeding 50 particles in the center of our domain. The weighting parameters # theta and gamma are set to 0. # create params and then assign the parameters params = particle_track.modelParams() # define the params variables params.depth = np.ones((100, 100)) params.stage = np.ones((100, 100)) params.qx = np.zeros_like(params.depth) params.qy = np.zeros_like(params.depth) params.dx = 50. params.theta = 0.0 params.gamma = 0.0 params.model = 'None' # particle info seed_xloc = list(range(45, 56)) seed_yloc = list(range(45, 56)) Np_tracer = 50
from __future__ import division, print_function, absolute_import from builtins import range, map from math import floor, sqrt, pi import pytest import sys, os sys.path.append(os.path.realpath(os.path.dirname(__file__) + "/..")) import numpy as np import dorado.particle_track as pt from dorado.particle_track import Particles # set up DeltaRCM test case rcm_data = np.load('tests/data/ex_deltarcm_data.npz') params = pt.modelParams() params.stage = rcm_data['stage'] params.depth = rcm_data['depth'] params.dx = 50. # just do one particle in a set location for this test seed_xloc = [16] seed_yloc = [140] Np_tracer = 1 # no discharge data so use 0s as substitute params.qx = np.zeros_like(params.depth) params.qy = np.zeros_like(params.depth) params.model = 'DeltaRCM' def test_few_steps_RCM(): ''' Test running a few steps '''