def setup_test(self, end_time_delay, num_les, ts=900.): stime = datetime(2015, 1, 1, 12, 0) etime = stime + end_time_delay st_pos = (0, 0, 0) oil = test_oil m1 = Model(start_time=stime, time_step=ts) m1.environment += [constant_wind(0, 0), Water()] m1.weatherers += Evaporation() m1.spills += point_line_release_spill(num_les[0], st_pos, stime, end_release_time=etime, substance=oil, amount=36000, units='kg') m1.outputters += WeatheringOutput() m2 = Model(start_time=stime, time_step=ts) m2.environment += [constant_wind(0, 0), Water()] m2.weatherers += Evaporation() m2.spills += point_line_release_spill(num_les[1], st_pos, stime, end_release_time=etime, substance=oil, amount=36000, units='kg') m2.outputters += WeatheringOutput() return (m1, m2)
def model(sample_model): model = sample_model['model'] model.make_default_refs = True rel_start_pos = sample_model['release_start_pos'] rel_end_pos = sample_model['release_end_pos'] model.cache_enabled = True model.uncertain = False model.environment += Water(311.15) print 'adding a Weatherer' model.environment += constant_wind(1.0, 0.0) N = 10 # a line of ten points line_pos = np.zeros((N, 3), dtype=np.float64) line_pos[:, 0] = np.linspace(rel_start_pos[0], rel_end_pos[0], N) line_pos[:, 1] = np.linspace(rel_start_pos[1], rel_end_pos[1], N) # print start_points model.duration = timedelta(hours=6) end_time = model.start_time + timedelta(hours=1) spill = point_line_release_spill(1000, start_position=rel_start_pos, release_time=model.start_time, end_release_time=end_time, end_position=rel_end_pos, substance=test_oil, amount=1000, units='kg') model.spills += spill # figure out mid-run save for weathering_data attribute, then add this in rel_time = model.spills[0].get('release_time') skim_start = rel_time + timedelta(hours=1) amount = model.spills[0].amount units = model.spills[0].units skimmer = Skimmer(.3 * amount, units=units, efficiency=0.3, active_start=skim_start, active_stop=skim_start + timedelta(hours=1)) # thickness = 1m so area is just 20% of volume volume = spill.get_mass() / spill.get('substance').get_density() burn = Burn(0.2 * volume, 1.0, active_start=skim_start, efficiency=0.9) c_disp = ChemicalDispersion(.1, efficiency=0.5, active_start=skim_start, active_stop=skim_start + timedelta(hours=1)) model.weatherers += [Evaporation(), c_disp, burn, skimmer] model.outputters += WeatheringOutput() model.rewind() return model
def test_full_run_disp_not_active(sample_model_fcn): 'no water/wind/waves object and no evaporation' model = sample_model_weathering(sample_model_fcn, 'oil_6') model.weatherers += NaturalDispersion(on=False) model.outputters += WeatheringOutput() for step in model: ''' if no weatherers, then no weathering output - need to add on/off switch to WeatheringOutput ''' assert 'natural_dispersion' not in step['WeatheringOutput'] assert 'sedimentation' not in step['WeatheringOutput'] assert ('time_stamp' in step['WeatheringOutput'])
def test_full_run_evap_not_active(sample_model_fcn): 'no water/wind object' model = sample_model_weathering(sample_model_fcn, 'oil_6') model.weatherers += Evaporation(on=False) model.outputters += WeatheringOutput() for step in model: ''' if no weatherers, then no weathering output - need to add on/off switch to WeatheringOutput ''' assert 'evaporated' not in step['WeatheringOutput'] assert ('time_stamp' in step['WeatheringOutput']) print("Completed step: {0}".format(step['step_num']))
def test_full_run_emul_not_active(sample_model_fcn): 'no water/wind/waves object and no evaporation' model = sample_model_weathering(sample_model_fcn, 'oil_crude') model.weatherers += Emulsification(on=False) model.outputters += WeatheringOutput() for step in model: ''' if no weatherers, then no weathering output - need to add on/off switch to WeatheringOutput ''' assert 'water_content' not in step['WeatheringOutput'] assert ('time_stamp' in step['WeatheringOutput']) print("Completed step: {0}".format(step['step_num']))
def test_full_run_dissolution_not_active(sample_model_fcn): 'no water/wind/waves object and no evaporation' model = sample_model_weathering(sample_model_fcn, 'oil_4') model.environment += [Water(288.7), wind, waves] model.weatherers += Evaporation() model.weatherers += NaturalDispersion() model.weatherers += Dissolution(waves=waves, wind=wind, on=False) model.outputters += WeatheringOutput() for step in model: ''' if no weatherers, then no weathering output - need to add on/off switch to WeatheringOutput ''' assert 'dissolution' not in step['WeatheringOutput'] assert ('time_stamp' in step['WeatheringOutput']) print ("Completed step: {0}".format(step['step_num']))
def make_model(images_dir=os.path.join(base_dir, 'images')): print 'initializing the model' start_time = datetime(2012, 9, 15, 12, 0) mapfile = get_datafile(os.path.join(base_dir, './LongIslandSoundMap.BNA')) gnome_map = MapFromBNA(mapfile, refloat_halflife=6) # hours # # the image output renderer # global renderer # one hour timestep model = Model(start_time=start_time, duration=timedelta(hours=48), time_step=3600, map=gnome_map, uncertain=False, cache_enabled=False) print 'adding a spill' et = floating_weathering(substance='FUEL OIL NO.6') spill = point_line_release_spill(num_elements=1000, start_position=(-72.419992, 41.202120, 0.0), release_time=start_time, amount=1000, units='kg', element_type=et) spill.amount_uncertainty_scale = 1.0 model.spills += spill print 'adding a RandomMover:' model.movers += RandomMover(diffusion_coef=500000, uncertain_factor=2) print 'adding a wind mover:' series = np.zeros((5, ), dtype=datetime_value_2d) series[0] = (start_time, (10, 45)) series[1] = (start_time + timedelta(hours=18), (10, 90)) series[2] = (start_time + timedelta(hours=30), (10, 135)) series[3] = (start_time + timedelta(hours=42), (10, 180)) series[4] = (start_time + timedelta(hours=54), (10, 225)) wind = Wind(timeseries=series, units='m/s', speed_uncertainty_scale=0.5) model.movers += WindMover(wind) print 'adding a cats mover:' curr_file = get_datafile(os.path.join(base_dir, r"./LI_tidesWAC.CUR")) tide_file = get_datafile(os.path.join(base_dir, r"./CLISShio.txt")) c_mover = CatsMover(curr_file, tide=Tide(tide_file)) model.movers += c_mover model.environment += c_mover.tide print 'adding Weatherers' water_env = Water(311.15) model.environment += water_env model.weatherers += [Evaporation(water_env, wind), Dispersion(), Burn(), Skimmer()] print 'adding outputters' model.outputters += WeatheringOutput() return model
Wind(timeseries=(sec_to_date(24 * 60 * 60), (0, 0)), units='mps'), Water(temperature=273), RandomMover(), CatsMover(testdata['CatsMover']['curr']), CatsMover(testdata['CatsMover']['curr'], tide=Tide(testdata['CatsMover']['tide'])), ComponentMover(testdata['ComponentMover']['curr']), ComponentMover(testdata['ComponentMover']['curr'], wind=Wind(filename=testdata['ComponentMover']['wind'])), RandomMover3D(), SimpleMover(velocity=(10.0, 10.0, 0.0)), map.MapFromBNA(testdata['MapFromBNA']['testmap'], 6), NetCDFOutput(os.path.join(base_dir, u'xtemp.nc')), Renderer(testdata['Renderer']['bna_sample'], os.path.join(base_dir, 'output_dir')), WeatheringOutput(), spill.PointLineRelease(release_time=datetime.now(), num_elements=10, start_position=(0, 0, 0)), spill.point_line_release_spill(10, (0, 0, 0), datetime.now()), spill.substance.Substance(windage_range=(0.05, 0.07)), spill.substance.GnomeOil(test_oil, windage_range=(0.05, 0.07)), spill.substance.NonWeatheringSubstance(windage_range=(0.05, 0.07)), Skimmer(amount=100, efficiency=0.3, active_range=(datetime(2014, 1, 1, 0, 0), datetime(2014, 1, 1, 4, 0)), units='kg'), Burn(area=100, thickness=1, active_range=(datetime(2014, 1, 1, 0, 0), datetime(2014, 1, 1, 4, 0)),
def make_model(uncertain=False, geojson_output=False): print 'initializing the model' start_time = datetime(2012, 9, 15, 12, 0) mapfile = testdata["lis"]["map"] gnome_map = MapFromBNA(mapfile, refloat_halflife=6) # hours # # the image output renderer # global renderer # one hour timestep model = Model(start_time=start_time, duration=timedelta(hours=48), time_step=3600, map=gnome_map, uncertain=uncertain, cache_enabled=False) print 'adding a spill' spill = point_line_release_spill(num_elements=1000, start_position=(-72.419992, 41.202120, 0.0), release_time=start_time, amount=1000, substance=test_oil, units='kg') spill.amount_uncertainty_scale = 1.0 model.spills += spill print 'adding a RandomMover:' model.movers += RandomMover(diffusion_coef=500000, uncertain_factor=2) print 'adding a wind mover:' series = np.zeros((5, ), dtype=datetime_value_2d) series[0] = (start_time, (20, 45)) series[1] = (start_time + timedelta(hours=18), (20, 90)) series[2] = (start_time + timedelta(hours=30), (20, 135)) series[3] = (start_time + timedelta(hours=42), (20, 180)) series[4] = (start_time + timedelta(hours=54), (20, 225)) wind = Wind(timeseries=series, units='m/s', speed_uncertainty_scale=0.05) model.movers += WindMover(wind) print 'adding a cats mover:' c_mover = CatsMover(testdata["lis"]["cats_curr"], tide=Tide(testdata["lis"]["cats_tide"])) model.movers += c_mover model.environment += c_mover.tide print 'adding Weatherers' rel_time = model.spills[0].get('release_time') skim_start = rel_time + timedelta(hours=4) amount = spill.amount units = spill.units # define skimmer/burn cleanup options skimmer = Skimmer(0.3 * amount, units=units, efficiency=0.3, active_start=skim_start, active_stop=skim_start + timedelta(hours=4)) # thickness = 1m so area is just 20% of volume volume = spill.get_mass() / spill.get('substance').get_density() burn = Burn(0.2 * volume, 1.0, active_start=skim_start, efficiency=.9) c_disp = ChemicalDispersion(0.1, efficiency=0.5, active_start=skim_start, active_stop=skim_start + timedelta(hours=1)) water_env = Water(311.15) model.environment += water_env model.weatherers += [Evaporation(water_env, wind), c_disp, burn, skimmer] print 'adding outputters' model.outputters += WeatheringOutput() if geojson_output: model.outputters += TrajectoryGeoJsonOutput() return model
def make_model(images_dir=os.path.join(base_dir, 'images')): print 'initializing the model' start_time = datetime(2015, 5, 14, 0, 0) # 1 day of data in file # 1/2 hr in seconds model = Model(start_time=start_time, duration=timedelta(days=1.75), time_step=60 * 60, uncertain=True) # mapfile = get_datafile(os.path.join(base_dir, './ak_arctic.bna')) # # print 'adding the map' # model.map = MapFromBNA(mapfile, refloat_halflife=1) # seconds # # # draw_ontop can be 'uncertain' or 'forecast' # # 'forecast' LEs are in black, and 'uncertain' are in red # # default is 'forecast' LEs draw on top # renderer = Renderer(mapfile, images_dir, size=(800, 600), # output_timestep=timedelta(hours=2), # draw_ontop='forecast') # # print 'adding outputters' # model.outputters += renderer model.outputters += WeatheringOutput() netcdf_file = os.path.join(base_dir, 'script_weatherers.nc') scripting.remove_netcdf(netcdf_file) model.outputters += NetCDFOutput(netcdf_file, which_data='all', output_timestep=timedelta(hours=1)) print 'adding a spill' # for now subsurface spill stays on initial layer # - will need diffusion and rise velocity # - wind doesn't act # - start_position = (-76.126872, 37.680952, 5.0), end_time = start_time + timedelta(hours=24) spill = point_line_release_spill( num_elements=100, start_position=(-164.791878561, 69.6252597267, 0.0), release_time=start_time, end_release_time=end_time, amount=1000, substance='ALASKA NORTH SLOPE (MIDDLE PIPELINE)', units='bbl') # set bullwinkle to .303 to cause mass goes to zero bug at 24 hours (when continuous release ends) spill.element_type._substance._bullwinkle = .303 model.spills += spill print 'adding a RandomMover:' #model.movers += RandomMover(diffusion_coef=50000) print 'adding a wind mover:' series = np.zeros((2, ), dtype=datetime_value_2d) series[0] = (start_time, (20, 0)) series[1] = (start_time + timedelta(hours=23), (20, 0)) wind2 = Wind(timeseries=series, units='knot') w_mover = WindMover(wind) model.movers += w_mover print 'adding weatherers and cleanup options:' # define skimmer/burn cleanup options skim1_start = start_time + timedelta(hours=15.58333) skim2_start = start_time + timedelta(hours=16) units = spill.units skimmer1 = Skimmer(80, units=units, efficiency=0.36, active_start=skim1_start, active_stop=skim1_start + timedelta(hours=8)) skimmer2 = Skimmer(120, units=units, efficiency=0.2, active_start=skim2_start, active_stop=skim2_start + timedelta(hours=12)) burn_start = start_time + timedelta(hours=36) burn = Burn(1000., .1, active_start=burn_start, efficiency=.2) chem_start = start_time + timedelta(hours=24) c_disp = ChemicalDispersion(0.5, efficiency=0.4, active_start=chem_start, active_stop=chem_start + timedelta(hours=8)) model.environment += [Water(280.928), wind, waves] model.weatherers += Evaporation(water, wind) model.weatherers += Emulsification(waves) model.weatherers += NaturalDispersion(waves, water) model.weatherers += skimmer1 model.weatherers += skimmer2 model.weatherers += burn model.weatherers += c_disp return model
def test_init(): 'simple initialization passes' g = WeatheringOutput() assert g.output_dir is None
import gnome.scripting as gs from gnome.outputters import WeatheringOutput, OilBudgetOutput try: savefile = sys.argv[1] except IndexError: print "You must provide a savefile to load" sys.exit(1) print "Loading:", savefile model = gs.Model.load_savefile(savefile) model.outputters += WeatheringOutput(output_dir="NewModel", output_timestep=gs.hours(1), ) print "running model" model.full_run() # note: this outputs a bunch of JSON -- one for each timestep. # maybe a MassBalanceOutputter that ouputs a CSV file would be in order?
def model(sample_model): model = sample_model['model'] model.make_default_refs = True rel_start_pos = sample_model['release_start_pos'] rel_end_pos = sample_model['release_end_pos'] # model.cache_enabled = True # why use the cache -- it'll just slow things down!!! model.uncertain = False wind = constant_wind(1.0, 0.0) water = Water(311.15) model.environment += water waves = Waves(wind, water) model.environment += waves print "the environment:", model.environment start_time = model.start_time model.duration = timedelta(hours=12) end_time = start_time + timedelta(hours=1) spill = point_line_release_spill(100, start_position=rel_start_pos, release_time=start_time, end_release_time=start_time + hours(1), end_position=rel_end_pos, substance=test_oil, amount=1000, units='kg') model.spills += spill # figure out mid-run save for weathering_data attribute, then add this in # rel_time = model.spills[0].release_time skim_start = start_time + timedelta(hours=1) amount = model.spills[0].amount units = model.spills[0].units skimmer = Skimmer(.3 * amount, units=units, efficiency=0.3, active_range=(skim_start, skim_start + hours(1))) # thickness = 1m so area is just 20% of volume volume = spill.get_mass() / spill.substance.density_at_temp() burn = Burn(0.2 * volume, 1.0, active_range=(skim_start, InfDateTime('inf')), efficiency=0.9) c_disp = ChemicalDispersion(.1, efficiency=0.5, active_range=(skim_start, skim_start + timedelta(hours=1)), waves=waves) model.weatherers += [Evaporation(), c_disp, burn, skimmer] model.outputters += WeatheringOutput() model.rewind() return model