Beispiel #1
0
    def test_spills_different_substance_release(self):
        '''
        Test data structure gets correctly set/updated after release_elements
        is invoked
        '''
        sc = SpillContainer()
        rel_time = datetime(2014, 1, 1, 12, 0, 0)
        end_time = rel_time + timedelta(hours=1)
        time_step = 900
        splls0 = [
            point_line_release_spill(100, (1, 1, 1),
                                     rel_time,
                                     end_release_time=end_time,
                                     element_type=floating(substance=test_oil),
                                     amount=100,
                                     units='kg'),
            point_line_release_spill(50, (2, 2, 2),
                                     rel_time + timedelta(seconds=900),
                                     element_type=floating(substance=test_oil),
                                     amount=150,
                                     units='kg'),
        ]
        sc.spills += splls0
        splls1 = point_line_release_spill(
            10, (0, 0, 0), rel_time, element_type=floating(substance=None))
        sc.spills += splls1

        at = {'density', 'mass_components'}
        sc.prepare_for_model_run(at)
        assert len(sc.get_substances()) == 2

        print '\nElements released:'
        for ix in range(-1, 8):
            time = rel_time + timedelta(seconds=time_step) * ix
            num_rel = sc.release_elements(time_step, time)
            print num_rel
            for substance, data in sc.itersubstancedata(at):
                assert substance.name == test_oil
                idx = sc._substances_spills.substances.index(substance)
                mask = sc['substance'] == idx
                for array in at:
                    assert array in data
                    assert np.all(data[array] == sc[array][mask])
    def test_no_substance(self):
        '''
        no substance means run trajectory without an OilProps object/without
        weathering is one reason to do this
        '''
        sc = SpillContainer()
        sc.spills += [Spill(Release(datetime.now(), 10),
                            element_type=floating(substance=None),
                            name='spill0'),
                      Spill(Release(datetime.now(), 10),
                            element_type=floating(substance=None),
                            name='spill1')]
        assert len(sc.itersubstancedata('mass')) == 0
        assert len(sc.get_substances()) == 1
        assert len(sc.get_substances(complete=False)) == 0

        # iterspillsbysubstance() iterates through all the spills associated
        # with each substance including the spills where substance is None
        assert len(sc.iterspillsbysubstance()) == 2
    def test_spills_different_substance_release(self):
        '''
        Test data structure gets correctly set/updated after release_elements
        is invoked
        '''
        sc = SpillContainer()
        rel_time = datetime(2014, 1, 1, 12, 0, 0)
        end_time = rel_time + timedelta(hours=1)
        time_step = 900
        splls0 = [point_line_release_spill(100, (1, 1, 1),
                                           rel_time,
                                           end_release_time=end_time,
                                           element_type=floating(substance=test_oil),
                                           amount=100,
                                           units='kg'),
                  point_line_release_spill(50, (2, 2, 2),
                                           rel_time + timedelta(seconds=900),
                                           element_type=floating(substance=test_oil),
                                           amount=150,
                                           units='kg'),
                  ]
        sc.spills += splls0
        splls1 = point_line_release_spill(10, (0, 0, 0),
                                          rel_time,
                                          element_type=floating(substance=None))
        sc.spills += splls1

        at = {'density', 'mass_components'}
        sc.prepare_for_model_run(at)
        assert len(sc.get_substances()) == 2

        print '\nElements released:'
        for ix in range(-1, 8):
            time = rel_time + timedelta(seconds=time_step) * ix
            num_rel = sc.release_elements(time_step, time)
            print num_rel
            for substance, data in sc.itersubstancedata(at):
                assert substance.name == test_oil
                idx = sc._substances_spills.substances.index(substance)
                mask = sc['substance'] == idx
                for array in at:
                    assert array in data
                    assert np.all(data[array] == sc[array][mask])
Beispiel #4
0
    def test_no_substance(self):
        '''
        no substance means run trajectory without an OilProps object/without
        weathering is one reason to do this
        '''
        sc = SpillContainer()
        sc.spills += [
            Spill(Release(datetime.now(), 10),
                  element_type=floating(substance=None),
                  name='spill0'),
            Spill(Release(datetime.now(), 10),
                  element_type=floating(substance=None),
                  name='spill1')
        ]
        assert len(sc.itersubstancedata('mass')) == 0
        assert len(sc.get_substances()) == 1

        # iterspillsbysubstance() iterates through all the spills associated
        # with each substance including the spills where substance is None
        assert len(sc.iterspillsbysubstance()) == 1
        assert len(sc.iterspillsbysubstance()) == 1