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): 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_normalization(self): p = Particle() dt = datetime(2012, 8, 15, 0, tzinfo=pytz.utc) norms =[dt] last_real_movement = Location4D(latitude=38, longitude=-76, depth=0, time=dt) p.location = Location4D(latitude=100, longitude=-100, depth=0, time=dt) p.location = Location4D(latitude=101, longitude=-101, depth=0, time=dt) p.location = last_real_movement for x in xrange(1,10): norm = (dt + timedelta(hours=x)).replace(tzinfo=pytz.utc) norms.append(norm) p.location = Location4D(latitude=38 + x, longitude=-76 + x, depth=x, time=norm) locs = p.normalized_locations(norms) assert locs[0] == last_real_movement
def test_normalization(self): p = Particle() dt = datetime(2012, 8, 15, 0, tzinfo=pytz.utc) norms = [dt] last_real_movement = Location4D(latitude=38, longitude=-76, depth=0, time=dt) p.location = Location4D(latitude=100, longitude=-100, depth=0, time=dt) p.location = Location4D(latitude=101, longitude=-101, depth=0, time=dt) p.location = last_real_movement for x in range(1, 10): norm = (dt + timedelta(hours=x)).replace(tzinfo=pytz.utc) norms.append(norm) p.location = Location4D(latitude=38 + x, longitude=-76 + x, depth=x, time=norm) locs = p.normalized_locations(norms) assert locs[0] == last_real_movement
def setUp(self): self.p = Particle() self.p.location = Location4D(latitude=38, longitude=-76, depth=0) self.p.location = Location4D(latitude=39, longitude=-75, depth=1) self.p.location = Location4D(latitude=40, longitude=-74, depth=2)
class ParticleTest(unittest.TestCase): def setUp(self): self.p = Particle() self.p.location = Location4D(latitude=38, longitude=-76, depth=0) self.p.location = Location4D(latitude=39, longitude=-75, depth=1) self.p.location = Location4D(latitude=40, longitude=-74, depth=2) def test_particle_linestring(self): result = list(self.p.linestring().coords) assert (-76, 38, 0) == result[0] assert (-75, 39, 1) == result[1] assert (-74, 40, 2) == result[2] def test_particle_linestring_length(self): assert (len(list(self.p.linestring().coords))) == 3 self.p.location = Location4D(latitude=39, longitude=-75, depth=1) assert (len(list(self.p.linestring().coords))) == 4 def test_particle_last_movement(self): result = list(self.p.get_last_movement().coords) assert (-75, 39, 1) == result[0] assert (-74, 40, 2) == result[1] def test_particle_age(self): assert self.p.get_age(units='seconds') == 0 assert self.p.get_age() == 0 self.p.age(days=1) assert self.p.get_age(units='minutes') == 24 * 60 assert self.p.get_age() == 1 self.p.age(days=1) assert self.p.get_age(units='hours') == 48 assert self.p.get_age() == 2 def test_normalization(self): p = Particle() dt = datetime(2012, 8, 15, 0, tzinfo=pytz.utc) norms = [dt] last_real_movement = Location4D(latitude=38, longitude=-76, depth=0, time=dt) p.location = Location4D(latitude=100, longitude=-100, depth=0, time=dt) p.location = Location4D(latitude=101, longitude=-101, depth=0, time=dt) p.location = last_real_movement for x in range(1, 10): norm = (dt + timedelta(hours=x)).replace(tzinfo=pytz.utc) norms.append(norm) p.location = Location4D(latitude=38 + x, longitude=-76 + x, depth=x, time=norm) locs = p.normalized_locations(norms) assert locs[0] == last_real_movement
class ParticleTest(unittest.TestCase): def setUp(self): self.p = Particle() self.p.location = Location4D(latitude=38, longitude=-76, depth=0) self.p.location = Location4D(latitude=39, longitude=-75, depth=1) self.p.location = Location4D(latitude=40, longitude=-74, depth=2) def test_particle_linestring(self): result = list(self.p.linestring().coords) assert (-76, 38, 0) == result[0] assert (-75, 39, 1) == result[1] assert (-74, 40, 2) == result[2] def test_particle_linestring_length(self): assert(len(list(self.p.linestring().coords))) == 3 self.p.location= Location4D(latitude=39, longitude=-75, depth=1) assert(len(list(self.p.linestring().coords))) == 4 def test_particle_last_movement(self): result = list(self.p.get_last_movement().coords) assert (-75, 39, 1) == result[0] assert (-74, 40, 2) == result[1] def test_particle_age(self): assert self.p.get_age(units='seconds') == 0 assert self.p.get_age() == 0 self.p.age(days=1) assert self.p.get_age(units='minutes') == 24 * 60 assert self.p.get_age() == 1 self.p.age(days=1) assert self.p.get_age(units='hours') == 48 assert self.p.get_age() == 2 def test_normalization(self): p = Particle() dt = datetime(2012, 8, 15, 0, tzinfo=pytz.utc) norms =[dt] last_real_movement = Location4D(latitude=38, longitude=-76, depth=0, time=dt) p.location = Location4D(latitude=100, longitude=-100, depth=0, time=dt) p.location = Location4D(latitude=101, longitude=-101, depth=0, time=dt) p.location = last_real_movement for x in xrange(1,10): norm = (dt + timedelta(hours=x)).replace(tzinfo=pytz.utc) norms.append(norm) p.location = Location4D(latitude=38 + x, longitude=-76 + x, depth=x, time=norm) locs = p.normalized_locations(norms) assert locs[0] == last_real_movement