NOAA-ORR-ERD / PyGnome

The General NOAA Operational Modeling Environment
https://gnome.orr.noaa.gov/doc/pygnome/index.html
Other
59 stars 44 forks source link

Weathering simulation #162

Closed tottorikenn closed 2 weeks ago

tottorikenn commented 2 weeks ago

Dear all, I want to see weathering, but I can't to do that. I use wrong way or I made abnormal environment? I made my environment with conda. 'https://gnome.orr.noaa.gov/doc/pygnome/installing.html'

""" Script to show how to run py_gnome with weathering

This is a very simple script with "just weathering"

It has no land, no currents, and no transport. """

start_x=45 start_y=80 x_min=start_x -1 x_max=start_x +1 y_min=start_y -0.1 y_max=start_y +0.1

import os from pathlib import Path

from gnome import scripting as gs

import gnome.scripting as gs from gnome.model import Model from gnome.weatherers import Evaporation, NaturalDispersion,Emulsification from gnome.environment import Water, Wind, Waves from datetime import datetime, timedelta

define base directory -- so we can find the data files

base_dir = Path(file).parent

example_files = base_dir / 'example_files'

save_dir = base_dir / 'output'

print('initializing the model') mapfile = gs.get_datafile('ne_110m_coastline.bna') mymap = gs.MapFromBNA(mapfile) # no refloat

mymap = gs.MapFromBNA(mapfile, refloat_halflife=-1) # no refloat

start_time = gs.asdatetime("2020-03-01T00:00") model = gs.Model(start_time=start_time, duration=gs.days(3), time_step=60 * 15, # 15 minutes in seconds ) model.map = mymap

print('adding outputters')

This will write the total oil budget to a CSV file

model.outputters += gs.OilBudgetOutput

We need a spill at the very least

oil = gs.GnomeOil(filename="troll_EC00721.json") spill = gs.surface_point_line_spill(num_elements=1000, start_position=(start_x, start_y), release_time=start_time, end_position=(start_x, start_y), end_release_time= start_time + gs.days(3), amount=50, windage_range=(0.025, 0.025), windage_persist=-1, name='My spill') model.spills += spill

print('adding a RandomMover:')

model.movers += gs.RandomMover()

print('adding a wind mover:')

use wind mover rather than environment or save file won't work in WebGnome

model.movers += gs.constant_point_wind_mover(speed=10, direction=0, units="m/s")

w_mover = gs.GridWind.from_netCDF('era5_2020_03_1_03_5_44_46_79_81.nc',uncertain_speed_scale=2.0, uncertain_angle_scale=0.4,wind_scale=1) wind_mover= gs.WindMover(w_mover) model.movers += wind_mover

fn = 'topaz4_2020_3_01_3_05_44_46_79_81_with_ice_renamed.nc' current_mover = gs.CurrentMover.from_netCDF(filename=fn) model.movers += current_mover

wind = gs.constant_wind(speed=10,

direction=0,

units='knots')

model.environment += wind

Water properties are needed for the weathering algorithms

model.environment += gs.Water(25, units={"temperature": "C"})

Waves are needed for dispersion -- it will use the wind defined above.

waves = gs.Waves(w_mover) model.environment += waves

print('adding the standard weatherers') model.add_weathering()

model.add_weathering(which=('evaporation', 'dispersion'))

'''

model = Model()

wind = Wind(filename="path_2_file/mywind.txt")

waves = Waves(w_mover) water = Water(temperature=300.0, salinity=35.0) #temperature in Kelvin, salinity in psu model.weatherers += Evaporation(wind=w_mover,water=water) model.weatherers += NaturalDispersion(waves=waves,water=water) model.weatherers += Emulsification(waves) '''

Saving the model as a "GNOME Save file"

model.save(saveloc=save_dir / 'WeatheringRun.gnome')

(save_dir / 'GNOME_oil_budget.csv')

This writes the detailed output to a netcdf file

that is, all the properties of the elements

model.outputters += gs.NetCDFOutput(filename= 'weathering_run.nc', which_data='standard', surface_conc=None ) shape =gs.ShapeOutput('pygnome_shape_test_weathering_2', zip_output=True, include_certain_boundary=False, certain_boundary_separate_by_spill=True, certain_boundary_hull_ratio=0.5, certain_boundary_hull_allow_holes=False, include_uncertain_boundary=True, uncertain_boundary_separate_by_spill=True, uncertain_boundary_hull_ratio=0.5, uncertain_boundary_hull_allow_holes=False, surface_conc='kde') model.outputters += shape model.outputters += gs.WeatheringOutput('MyOutputDir_test_weathering_2_simple')

model.outputters += gs.OilBudgetOutput('adios_results',output_timestep=timedelta(hours=6))

print('adding a spill')

print("running the model") model.full_run()

I use this script. No error cord occur, but there are no weathering in json files. In addition to this question, I want to see weathering result in shape file. Can I see weathering result in shape file?

coconnor8 commented 2 weeks ago

The issue is that you have not attached your oil to the spill. You just need to include the line substance = oil, or just substance = gs.GnomeOil(filename="troll_EC00721.json"), without defining oil.

oil = gs.GnomeOil(filename="troll_EC00721.json") spill = gs.surface_point_line_spill(num_elements=1000, start_position=(start_x, start_y), release_time=start_time, end_position=(start_x, start_y), end_release_time= start_time + gs.days(3), amount=50, substance = oil, windage_range=(0.025, 0.025), windage_persist=-1, name='My spill')

tottorikenn commented 2 weeks ago

Dear coconnor8, Thanks for your helping, I add 'substance = oil' in spill object and it solved my problem. Thanks