Exemplo n.º 1
0
 def test_num_per_timestep(self):
     'test PointLineRelease when a fixed rate per timestep is given'
     r = PointLineRelease(self.rel_time, self.pos, num_per_timestep=100)
     assert r.num_elements is None
     for ts in (100, 400):
         num = r.num_elements_to_release(self.rel_time, ts)
         assert num == 100
Exemplo n.º 2
0
 def test_num_per_timestep(self):
     'test PointLineRelease when a fixed rate per timestep is given'
     r = PointLineRelease(self.rel_time,
                          self.pos,
                          num_per_timestep=100)
     assert r.num_elements is None
     for ts in (100, 400):
         num = r.num_elements_to_release(self.rel_time, ts)
         assert num == 100
Exemplo n.º 3
0
    def test_serialization(self, r1):
        ser = r1.serialize()
        deser = PointLineRelease.deserialize(ser)
        assert deser == r1

        r1.prepare_for_model_run(900)
        ser = r1.serialize()
        deser = PointLineRelease.deserialize(ser)
        assert deser == r1
Exemplo n.º 4
0
 def test__eq__(self):
     r = PointLineRelease(self.rel_time,
                          self.pos,
                          end_position=(1, 2, 3),
                          num_per_timestep=100,
                          end_release_time=self.rel_time+timedelta(hours=2))
     r1 = PointLineRelease(self.rel_time,
                           (0, 0, 0),
                           end_position=(1, 2, 3),
                           num_per_timestep=100,
                           end_release_time=self.rel_time+timedelta(hours=2))
     assert r != r1
Exemplo n.º 5
0
    def test_property_num_per_timestep_elements(self):
        '''
        test either num_elements or num_per_timestep is set but not both
        also test the num_elements_to_release references correct method
        '''
        r = PointLineRelease(self.rel_time,
                             self.pos,
                             num_per_timestep=100)
        r.num_elements = 10
        assert r.num_per_timestep is None
        assert r.num_elements_to_release(self.rel_time, 900) == 10

        r.num_per_timestep = 100
        assert r.num_elements is None
        assert r.num_elements_to_release(self.rel_time, 900) == 100
Exemplo n.º 6
0
def r3():
    return PointLineRelease(release_time=rel_time,
                            start_position=pos,
                            end_position=(10, 20, 30),
                            end_release_time=rel_time +
                            timedelta(seconds=900) * 10,
                            num_per_timestep=100,
                            release_mass=5000)
Exemplo n.º 7
0
    def test_rewind(self):
        '''
        test rewind resets all parameters of interest
        '''
        r = PointLineRelease(self.rel_time,
                             self.pos,
                             end_position=(1, 2, 3),
                             num_per_timestep=100,
                             end_release_time=self.rel_time +
                             timedelta(hours=2))
        num = r.num_elements_to_release(self.rel_time, 900)
        assert not r.start_time_invalid

        # updated only after set_newparticle_positions is called
        assert r.num_released == 0
        pos = {'positions': positions.initialize(num)}
        r.set_newparticle_positions(num, self.rel_time, 900, pos)
        assert r.num_released == num
        assert r._delta_pos is not None
        assert np.any(r._next_release_pos != r.start_position)

        r.rewind()
        assert r.start_time_invalid is None
        assert r._delta_pos is None
        assert np.all(r._next_release_pos == r.start_position)
Exemplo n.º 8
0
def r1():
    #150 minute continuous release
    return PointLineRelease(release_time=rel_time,
                            start_position=pos,
                            end_position=(10, 20, 30),
                            end_release_time=rel_time +
                            timedelta(seconds=900) * 10,
                            num_elements=1000,
                            release_mass=5000)
Exemplo n.º 9
0
def test_release_no_attr():
    """
    a lot of attribute access is to get attributes of the initilizers

    that is tested in other tests, but this tests that it fails when it should
    """
    rel = PointLineRelease(release_time=rel_time,
                           num_elements=5,
                           start_position=(0, 0, 0)),

    with pytest.raises(AttributeError):
        rel.something_weird
Exemplo n.º 10
0
    def test_rewind(self):
        '''
        test rewind resets all parameters of interest
        '''
        r = PointLineRelease(self.rel_time,
                             self.pos,
                             end_position=(1, 2, 3),
                             num_per_timestep=100,
                             end_release_time=self.rel_time + timedelta(hours=2))
        num = r.num_elements_to_release(self.rel_time, 900)
        assert not r.start_time_invalid

        # updated only after set_newparticle_positions is called
        assert r.num_released == 0
        pos = {'positions': positions.initialize(num)}
        r.set_newparticle_positions(num,
                                    self.rel_time,
                                    900,
                                    pos)
        assert r.num_released == num
        assert r._delta_pos is not None
        assert np.any(r._next_release_pos != r.start_position)

        r.rewind()
        assert r.start_time_invalid is None
        assert r._delta_pos is None
        assert np.all(r._next_release_pos == r.start_position)
Exemplo n.º 11
0
    def test_property_num_per_timestep_elements(self):
        '''
        test either num_elements or num_per_timestep is set but not both
        also test the num_elements_to_release references correct method
        '''
        r = PointLineRelease(self.rel_time, self.pos, num_per_timestep=100)
        r.num_elements = 10
        assert r.num_per_timestep is None
        assert r.num_elements_to_release(self.rel_time, 900) == 10

        r.num_per_timestep = 100
        assert r.num_elements is None
        assert r.num_elements_to_release(self.rel_time, 900) == 100
Exemplo n.º 12
0
 def test_num_per_timestep_release_elements(self):
     'release elements in the context of a spill container'
     # todo: need a test for a line release where rate is given - to check
     # positions are being initialized correctly
     end_time = self.rel_time + timedelta(hours=1)
     release = PointLineRelease(self.rel_time,
                                self.pos,
                                num_per_timestep=100,
                                end_release_time=end_time)
     s = Spill(release)
     sc = SpillContainer()
     sc.spills += s
     sc.prepare_for_model_run()
     for ix in range(5):
         time = self.rel_time + timedelta(seconds=900 * ix)
         num_les = sc.release_elements(900, time)
         if time <= s.get('end_release_time'):
             assert num_les == 100
             assert sc.num_released == 100 + ix * 100
         else:
             assert num_les == 0
Exemplo n.º 13
0
    that is tested in other tests, but this tests that it fails when it should
    """
    rel = PointLineRelease(release_time=rel_time,
                           num_elements=5,
                           start_position=(0, 0, 0)),

    with pytest.raises(AttributeError):
        rel.something_weird


# todo: add other release to this test - need schemas for all

rel_time = datetime(2012, 8, 20, 13)
rel_type = [
    PointLineRelease(release_time=rel_time,
                     num_elements=5,
                     start_position=(0, 0, 0)),
    PointLineRelease(release_time=rel_time,
                     num_per_timestep=5,
                     start_position=(0, 0, 0)),
    ContinuousRelease(initial_elements=5,
                      release_time=rel_time,
                      num_per_timestep=5,
                      start_position=(0, 0, 0))
]
# SpatialRelease(rel_time, np.zeros((4, 3), dtype=np.float64))]


@pytest.mark.parametrize("rel_type", rel_type)
def test_release_serialization_deserialization(rel_type):
    '''
Exemplo n.º 14
0
def r2():
    return PointLineRelease(release_time=rel_time,
                            start_position=pos,
                            end_position=(10, 20, 30),
                            num_elements=1000)