def setUp(self): start_lat = 38 start_lon = -76 start_depth = -5 temp_time = datetime.utcnow() self.start_time = datetime(temp_time.year, temp_time.month, temp_time.day, temp_time.hour) self.loc = Location4D(latitude=start_lat, longitude=start_lon, depth=start_depth, time=self.start_time) # Generate time,u,v,z as randoms # 48 timesteps at an hour each = 2 days of running self.times = range(0, 172800, 3600) # in seconds self.u = [] self.v = [] self.z = [] for w in xrange(0, 48): self.z.append(random.gauss(0, 0.0001)) # gaussian in m/s self.u.append(abs(AsaRandom.random())) # random function in m/s self.v.append(abs(AsaRandom.random())) # random function in m/s self.particles = [] # Create particles for i in xrange(0, 3): p = Particle() p.location = self.loc self.particles.append(p) # Create a transport instance with horiz and vert dispersions self.transport_model = Transport(horizDisp=0.05, vertDisp=0.00003)
def run(self, hydrodatasets, **kwargs): _wind_path = kwargs.get("winddataset", None) num_particles = 1 models = [Transport(horizDisp=0., vertDisp=0.)] if self._wind_model != None: models.append(WindForcing()) for drifter in self.drifters: start_location4d = drifter.locations[0] start_time = start_location4d.time start_lat = start_location4d.latitude start_lon = start_location4d.longitude start_depth = start_location4d.depth time_step = self.time_step num_steps = self.num_steps model = ModelController(latitude=start_lat, longitude=start_lon, depth=start_depth, start=start_time, step=time_step, nstep=num_steps, npart=num_particles, models=models, use_bathymetry=False, use_shoreline=True, time_chunk=10, horiz_chunk=10) for hydromodel in hydrodatasets: model.run(hydromodel, wind=_wind_path) drifter.add_virtual_drifter(model.particles[0])
class TransportTest(unittest.TestCase): def setUp(self): start_lat = 38 start_lon = -76 start_depth = -5 temp_time = datetime.utcnow() self.start_time = datetime(temp_time.year, temp_time.month, temp_time.day, temp_time.hour) self.loc = Location4D(latitude=start_lat, longitude=start_lon, depth=start_depth, time=self.start_time) # Generate time,u,v,z as randoms # 48 timesteps at an hour each = 2 days of running self.times = list(range(0, 172800, 3600)) # in seconds self.u = [] self.v = [] self.z = [] for w in range(0, 48): self.z.append(random.gauss(0, 0.0001)) # gaussian in m/s self.u.append(abs(AsaRandom.random())) # random function in m/s self.v.append(abs(AsaRandom.random())) # random function in m/s self.particles = [] # Create particles for i in range(0, 3): p = Particle() p.location = self.loc self.particles.append(p) # Create a transport instance with horiz and vert dispersions self.transport_model = Transport(horizDisp=0.05, vertDisp=0.00003) def test_moving_particle(self): for p in self.particles: for i in range(0, len(self.times)): try: modelTimestep = self.times[i+1] - self.times[i] calculatedTime = self.times[i+1] except Exception: modelTimestep = self.times[i] - self.times[i-1] calculatedTime = self.times[i] + modelTimestep newtime = self.start_time + timedelta(seconds=calculatedTime) p.age(seconds=modelTimestep) movement = self.transport_model.move(p, self.u[i], self.v[i], self.z[i], modelTimestep) newloc = Location4D(latitude=movement['latitude'], longitude=movement['longitude'], depth=movement['depth'], time=newtime) p.location = newloc for p in self.particles: # Particle should move every timestep assert len(p.locations) == len(self.times) + 1 # A particle should always move in this test assert len(set(p.locations)) == len(self.times) + 1 # A particle should always age assert p.get_age(units='days') == (self.times[-1] + 3600) / 60. / 60. / 24. # First point of each particle should be the starting location assert p.linestring().coords[0][0] == self.loc.longitude assert p.linestring().coords[0][1] == self.loc.latitude assert p.linestring().coords[0][2] == self.loc.depth
def setUp(self): start_lat = 38 start_lon = -76 start_depth = -5 temp_time = datetime.utcnow() self.start_time = datetime(temp_time.year, temp_time.month, temp_time.day, temp_time.hour) self.loc = Location4D(latitude=start_lat, longitude=start_lon, depth=start_depth, time=self.start_time) # Generate time,u,v,z as randoms # 48 timesteps at an hour each = 2 days of running self.times = list(range(0, 172800, 3600)) # in seconds self.u = [] self.v = [] self.z = [] for w in range(0, 48): self.z.append(random.gauss(0, 0.0001)) # gaussian in m/s self.u.append(abs(AsaRandom.random())) # random function in m/s self.v.append(abs(AsaRandom.random())) # random function in m/s self.particles = [] # Create particles for i in range(0, 3): p = Particle() p.location = self.loc self.particles.append(p) # Create a transport instance with horiz and vert dispersions self.transport_model = Transport(horizDisp=0.05, vertDisp=0.00003)
def setUp(self): self.log = EasyLogger('testlog.txt', level=logging.PROGRESS) self.log.logger.handlers.append(logging.StreamHandler()) self.log.logger.info(self.id()) self.start_lat = 60.75 self.start_lon = -147 self.start_depth = 0 self.num_particles = 4 self.time_step = 3600 self.num_steps = 10 self.start_time = datetime(2014, 1, 2, 00) self.transport = Transport(horizDisp=0.05, vertDisp=0.0003) output_dir = "/data/lm/tests/output" test_dir = self.id().split('.')[-1] self.output_path = os.path.join(output_dir, test_dir) if not os.path.isdir(self.output_path): os.makedirs(self.output_path) self.output_formats = [ex.H5Trackline] cache_dir = "/data/lm/tests/cache" self.cache_path = os.path.join(cache_dir, test_dir, 'cache.nc') self.bathy_file = "/data/lm/bathy/global/ETOPO1_Bed_g_gmt4.grd" self.shoreline_path = "/data/lm/shore"
def setUp(self): self.start_lat = 60.75 self.start_lon = -147 self.start_depth = 0 self.num_particles = 4 self.time_step = 3600 self.num_steps = 10 self.start_time = datetime(2012, 8, 1, 00) self.transport = Transport(horizDisp=0.05, vertDisp=0.0003) self.log = EasyLogger('testlog.txt', level=logging.PROGRESS) self.output_path = "/data/lm/output" self.cache_path = "/data/lm/cache" self.bathy_file = "/data/lm/bathy/ETOPO1_Bed_g_gmt4.grd" self.shoreline_path = "/data/lm/shore"
class TransportTest(unittest.TestCase): def setUp(self): start_lat = 38 start_lon = -76 start_depth = -5 temp_time = datetime.utcnow() self.start_time = datetime(temp_time.year, temp_time.month, temp_time.day, temp_time.hour) self.loc = Location4D(latitude=start_lat, longitude=start_lon, depth=start_depth, time=self.start_time) # Generate time,u,v,z as randoms # 48 timesteps at an hour each = 2 days of running self.times = range(0, 172800, 3600) # in seconds self.u = [] self.v = [] self.z = [] for w in xrange(0, 48): self.z.append(random.gauss(0, 0.0001)) # gaussian in m/s self.u.append(abs(AsaRandom.random())) # random function in m/s self.v.append(abs(AsaRandom.random())) # random function in m/s self.particles = [] # Create particles for i in xrange(0, 3): p = Particle() p.location = self.loc self.particles.append(p) # Create a transport instance with horiz and vert dispersions self.transport_model = Transport(horizDisp=0.05, vertDisp=0.00003) def test_moving_particle(self): for p in self.particles: for i in xrange(0, len(self.times)): try: modelTimestep = self.times[i + 1] - self.times[i] calculatedTime = self.times[i + 1] except StandardError: modelTimestep = self.times[i] - self.times[i - 1] calculatedTime = self.times[i] + modelTimestep newtime = self.start_time + timedelta(seconds=calculatedTime) p.age(seconds=modelTimestep) movement = self.transport_model.move(p, self.u[i], self.v[i], self.z[i], modelTimestep) newloc = Location4D(latitude=movement['latitude'], longitude=movement['longitude'], depth=movement['depth'], time=newtime) p.location = newloc for p in self.particles: # Particle should move every timestep assert len(p.locations) == len(self.times) + 1 # A particle should always move in this test assert len(set(p.locations)) == len(self.times) + 1 # A particle should always age assert p.get_age( units='days') == (self.times[-1] + 3600) / 60. / 60. / 24. # First point of each particle should be the starting location assert p.linestring().coords[0][0] == self.loc.longitude assert p.linestring().coords[0][1] == self.loc.latitude assert p.linestring().coords[0][2] == self.loc.depth