def test_prepare_for_model_step_boat(self, sample_model_fcn2): timeseries = np.array([(rel_time, rel_time + timedelta(hours=12.))]) disp = Disperse( name='boat_disperse', transit=20, pass_length=4, # dosage=1, cascade_on=False, cascade_distance=None, timeseries=timeseries, loading_type='simultaneous', pass_type='bidirectional', disp_oil_ratio=None, disp_eff=None, platform='Typical Large Vessel', units=None, onsite_reload_refuel=True) self.sc, self.model = ROCTests.mk_objs(sample_model_fcn2) self.model.weatherers += disp self.model.spills[0].amount = 20000 self.model.spills[0].units = 'gal' self.model.spills[0].end_release_time = (self.model.start_time + timedelta(hours=3)) self.reset_and_release() disp.prepare_for_model_run(self.sc) print self.model.start_time print self.disp.timeseries assert disp.cur_state == 'retired' self.model.step() print self.model.current_time_step self.model.step() print self.model.spills.items()[0]['viscosity'] assert disp.cur_state == 'en_route' print disp._next_state_time self.model.step() assert disp.cur_state == 'en_route' print disp.transit print disp.platform.transit_speed print disp.platform.one_way_transit_time(disp.transit) / 60 while disp.cur_state == 'en_route': self.model.step() off = self.model.current_time_step * self.model.time_step print self.model.start_time + timedelta(seconds=off) print 'pump_rate ', disp.platform.eff_pump_rate(disp.dosage) try: for _step in self.model: off = self.model.current_time_step * self.model.time_step print self.model.start_time + timedelta(seconds=off) except StopIteration: pass
def test_prepare_for_model_step_boat(self, sample_model_fcn2): timeseries = np.array([(rel_time, rel_time + timedelta(hours=12.))]) disp = Disperse(name='boat_disperse', transit=20, pass_length=4, # dosage=1, cascade_on=False, cascade_distance=None, timeseries=timeseries, loading_type='simultaneous', pass_type='bidirectional', disp_oil_ratio=None, disp_eff=None, platform='Typical Large Vessel', units=None, onsite_reload_refuel=True) self.sc, self.model = ROCTests.mk_objs(sample_model_fcn2) self.model.weatherers += disp self.model.spills[0].amount = 20000 self.model.spills[0].units = 'gal' self.model.spills[0].end_release_time = (self.model.start_time + timedelta(hours=3)) self.reset_and_release() disp.prepare_for_model_run(self.sc) print self.model.start_time print self.disp.timeseries assert disp.cur_state == 'retired' self.model.step() print self.model.current_time_step self.model.step() print self.model.spills.items()[0]['viscosity'] assert disp.cur_state == 'en_route' print disp._next_state_time self.model.step() assert disp.cur_state == 'en_route' print disp.transit print disp.platform.transit_speed print disp.platform.one_way_transit_time(disp.transit) / 60 while disp.cur_state == 'en_route': self.model.step() off = self.model.current_time_step * self.model.time_step print self.model.start_time + timedelta(seconds=off) print 'pump_rate ', disp.platform.eff_pump_rate(disp.dosage) try: for _step in self.model: off = self.model.current_time_step * self.model.time_step print self.model.start_time + timedelta(seconds=off) except StopIteration: pass
def test_serialization(self): timeseries = np.array([(rel_time, rel_time + timedelta(hours=12.))]) p = Disperse(name='test_disperse', transit=100, pass_length=4, # dosage=1, cascade_on=False, cascade_distance=None, timeseries=timeseries, loading_type='simultaneous', pass_type='bidirectional', disp_oil_ratio=None, disp_eff=None, platform='Test Platform', units=None,) ser = p.serialize() pp.pprint(ser) p2 = Disperse.deserialize(ser) assert p == p2
def test_serialization(self): import pprint as pp p = Disperse( name='test_disperse', transit=100, pass_length=4, # dosage=1, cascade_on=False, cascade_distance=None, timeseries=np.array([(rel_time, rel_time + timedelta(hours=12.))]), loading_type='simultaneous', pass_type='bidirectional', disp_oil_ratio=None, disp_eff=None, platform='Test Platform', units=None, ) ser = p.serialize() print 'Ser' pp.pprint(ser) deser = Disperse.deserialize(ser) print '' print 'deser' pp.pprint(deser) p2 = Disperse.new_from_dict(deser) ser2 = p2.serialize() print pp.pprint(ser2) ser.pop('id') ser2.pop('id') ser['platform'].pop('id') ser2['platform'].pop('id') assert ser['platform']['swath_width'] == 100.0 assert ser2['platform']['swath_width'] == 100.0 assert ser == ser2
def test_prepare_for_model_step_cont(self, sample_model_fcn2): timeseries = np.array([(rel_time, rel_time + timedelta(hours=12.))]) disp = Disperse(name='test_disperse', transit=100, pass_length=4, # dosage=1, cascade_on=False, cascade_distance=None, timeseries=timeseries, loading_type='simultaneous', pass_type='bidirectional', disp_oil_ratio=None, disp_eff=None, platform='Test Platform', units=None,) self.sc, self.model = ROCTests.mk_objs(sample_model_fcn2) self.model.weatherers += disp self.model.spills[0].amount = 20000 self.model.spills[0].units = 'gal' self.model.spills[0].end_release_time = (self.model.start_time + timedelta(hours=3)) self.reset_and_release() disp.prepare_for_model_run(self.sc) try: for _step in self.model: off = self.model.current_time_step * self.model.time_step print self.model.start_time + timedelta(seconds=off) except StopIteration: pass # print self.model.start_time # print self.disp.timeseries # assert self.disp.cur_state == 'retired' # self.model.step() # print self.model.current_time_step # self.model.step() # print self.model.spills.items()[0]['viscosity'] # assert self.disp.cur_state == 'en_route' # print self.disp._next_state_time # self.model.step() # assert self.disp.cur_state == 'en_route' # print self.disp.transit # print self.disp.platform.transit_speed # print self.disp.platform.one_way_transit_time(self.disp.transit)/60 # while self.disp.cur_state == 'en_route': # self.model.step() # off = self.model.current_time_step * self.model.time_step # print self.model.start_time + timedelta(seconds=off) # print ('pump_rate {}' # .format(self.disp.platform.eff_pump_rate(self.disp.dosage))) # assert 'disperse' in self.disp.cur_state try: for _step in self.model: off = self.model.current_time_step * self.model.time_step assert all(self.sc['mass'] >= 0) assert np.all(self.sc['mass_components'] >= 0) assert ((self.sc.mass_balance['chem_dispersed'] + self.sc.mass_balance['evaporated']) < sum(self.sc['init_mass'])) except StopIteration: pass
def test_construction(self): _d = Disperse(name='testname', transit=100, platform='Test Platform')
class TestRocChemDispersion(ROCTests): timeseries = np.array([(rel_time, rel_time + timedelta(hours=12.))]) disp = Disperse(name='test_disperse', transit=100, pass_length=4, # dosage=1, cascade_on=False, cascade_distance=None, timeseries=timeseries, loading_type='simultaneous', pass_type='bidirectional', disp_oil_ratio=None, disp_eff=None, platform='Test Platform', units=None,) def test_construction(self): _d = Disperse(name='testname', transit=100, platform='Test Platform') # payload in gallons, computation in gallons, so no conversion def test_serialization(self): timeseries = np.array([(rel_time, rel_time + timedelta(hours=12.))]) p = Disperse(name='test_disperse', transit=100, pass_length=4, # dosage=1, cascade_on=False, cascade_distance=None, timeseries=timeseries, loading_type='simultaneous', pass_type='bidirectional', disp_oil_ratio=None, disp_eff=None, platform='Test Platform', units=None,) ser = p.serialize() pp.pprint(ser) p2 = Disperse.deserialize(ser) assert p == p2 def test_prepare_for_model_run(self, sample_model_fcn2): self.sc, self.model = ROCTests.mk_objs(sample_model_fcn2) self.reset_and_release() self.disp.prepare_for_model_run(self.sc) # assert self.sc.mass_balance[self.disp.id] == 0.0 assert self.disp.cur_state == 'retired' assert len(self.sc.report[self.disp.id]) == 0 assert len(self.disp.timeseries) == 1 def test_prepare_for_model_step(self, sample_model_fcn2): timeseries = np.array([(rel_time, rel_time + timedelta(hours=12.))]) disp = Disperse(name='test_disperse', transit=100, pass_length=4, dosage=1, cascade_on=False, cascade_distance=None, timeseries=timeseries, loading_type='simultaneous', pass_type='bidirectional', disp_oil_ratio=None, disp_eff=None, platform='Test Platform', units=None,) self.sc, self.model = ROCTests.mk_objs(sample_model_fcn2) self.model.weatherers += disp self.model.spills[0].amount = 1000 self.model.spills[0].units = 'gal' self.reset_and_release() disp.prepare_for_model_run(self.sc) print self.model.start_time print self.disp.timeseries assert disp.cur_state == 'retired' self.model.step() print self.model.current_time_step self.model.step() print self.model.spills.items()[0]['viscosity'] assert disp.cur_state == 'en_route' print disp._next_state_time self.model.step() assert disp.cur_state == 'en_route' print disp.transit print disp.platform.transit_speed print disp.platform.one_way_transit_time(disp.transit)/60 while disp.cur_state == 'en_route': self.model.step() off = self.model.current_time_step * self.model.time_step print self.model.start_time + timedelta(seconds=off) print 'pump_rate ', disp.platform.eff_pump_rate(disp.dosage) try: for _step in self.model: off = self.model.current_time_step * self.model.time_step print self.model.start_time + timedelta(seconds=off) except StopIteration: pass def test_prepare_for_model_step_cont(self, sample_model_fcn2): timeseries = np.array([(rel_time, rel_time + timedelta(hours=12.))]) disp = Disperse(name='test_disperse', transit=100, pass_length=4, # dosage=1, cascade_on=False, cascade_distance=None, timeseries=timeseries, loading_type='simultaneous', pass_type='bidirectional', disp_oil_ratio=None, disp_eff=None, platform='Test Platform', units=None,) self.sc, self.model = ROCTests.mk_objs(sample_model_fcn2) self.model.weatherers += disp self.model.spills[0].amount = 20000 self.model.spills[0].units = 'gal' self.model.spills[0].end_release_time = (self.model.start_time + timedelta(hours=3)) self.reset_and_release() disp.prepare_for_model_run(self.sc) try: for _step in self.model: off = self.model.current_time_step * self.model.time_step print self.model.start_time + timedelta(seconds=off) except StopIteration: pass # print self.model.start_time # print self.disp.timeseries # assert self.disp.cur_state == 'retired' # self.model.step() # print self.model.current_time_step # self.model.step() # print self.model.spills.items()[0]['viscosity'] # assert self.disp.cur_state == 'en_route' # print self.disp._next_state_time # self.model.step() # assert self.disp.cur_state == 'en_route' # print self.disp.transit # print self.disp.platform.transit_speed # print self.disp.platform.one_way_transit_time(self.disp.transit)/60 # while self.disp.cur_state == 'en_route': # self.model.step() # off = self.model.current_time_step * self.model.time_step # print self.model.start_time + timedelta(seconds=off) # print ('pump_rate {}' # .format(self.disp.platform.eff_pump_rate(self.disp.dosage))) # assert 'disperse' in self.disp.cur_state try: for _step in self.model: off = self.model.current_time_step * self.model.time_step assert all(self.sc['mass'] >= 0) assert np.all(self.sc['mass_components'] >= 0) assert ((self.sc.mass_balance['chem_dispersed'] + self.sc.mass_balance['evaporated']) < sum(self.sc['init_mass'])) except StopIteration: pass def test_prepare_for_model_step_boat(self, sample_model_fcn2): timeseries = np.array([(rel_time, rel_time + timedelta(hours=12.))]) disp = Disperse(name='boat_disperse', transit=20, pass_length=4, # dosage=1, cascade_on=False, cascade_distance=None, timeseries=timeseries, loading_type='simultaneous', pass_type='bidirectional', disp_oil_ratio=None, disp_eff=None, platform='Typical Large Vessel', units=None, onsite_reload_refuel=True) self.sc, self.model = ROCTests.mk_objs(sample_model_fcn2) self.model.weatherers += disp self.model.spills[0].amount = 20000 self.model.spills[0].units = 'gal' self.model.spills[0].end_release_time = (self.model.start_time + timedelta(hours=3)) self.reset_and_release() disp.prepare_for_model_run(self.sc) print self.model.start_time print self.disp.timeseries assert disp.cur_state == 'retired' self.model.step() print self.model.current_time_step self.model.step() print self.model.spills.items()[0]['viscosity'] assert disp.cur_state == 'en_route' print disp._next_state_time self.model.step() assert disp.cur_state == 'en_route' print disp.transit print disp.platform.transit_speed print disp.platform.one_way_transit_time(disp.transit) / 60 while disp.cur_state == 'en_route': self.model.step() off = self.model.current_time_step * self.model.time_step print self.model.start_time + timedelta(seconds=off) print 'pump_rate ', disp.platform.eff_pump_rate(disp.dosage) try: for _step in self.model: off = self.model.current_time_step * self.model.time_step print self.model.start_time + timedelta(seconds=off) except StopIteration: pass