Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split env #1164

Merged
merged 21 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
502a2d8
environment: set up environment class
gauteh Sep 26, 2023
5c66133
basemodel: move reader logic to env
gauteh Sep 26, 2023
385f14d
Use the env class, add shortcuts for user-facing methods
gauteh Sep 27, 2023
4b0d7e8
phy: move stokes wind drift out of class
gauteh Sep 27, 2023
0a0daac
use phy methods from env
gauteh Sep 27, 2023
18e1bae
wip: get_env
gauteh Sep 27, 2023
72c2bef
testing environment
gauteh Sep 28, 2023
8fa3406
env: test fallback
gauteh Sep 28, 2023
5a37c5f
oceandrift: fallback is in env
gauteh Sep 28, 2023
606fa30
Some updates related to new Environment class so that more tests are …
knutfrode Sep 28, 2023
7307007
Updated two more occurances of <model>.get_eviroment
knutfrode Sep 28, 2023
ab1474b
Re-inserted method get_variables_along_trajectory in environment.py
knutfrode Sep 28, 2023
77077f8
Fixed bug in call to env.finalize. Moved particle position diagnostic…
knutfrode Oct 5, 2023
bdf5af4
Now simulation is in one of five given modes (Config,Ready,Run,Result…
knutfrode Oct 6, 2023
cf0c1e9
env: use require_mode decorator to ensure mode
gauteh Oct 7, 2023
649f984
Making more tests pass, mainly by seeding elements after config and a…
knutfrode Oct 12, 2023
6194639
drift:max_speed is now a config value. fallback_values it not anymore…
knutfrode Oct 19, 2023
28b0f69
Setting config before seeding also in example_double_gyre_LCS_particles
knutfrode Oct 19, 2023
a6bffc4
basemodel: do not allow opendrift to be reset.
gauteh Oct 20, 2023
0b8d615
modes: change modes in basemodel and add more requirements
gauteh Oct 20, 2023
3fb6c31
require_mode should return inner return value
gauteh Oct 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/example_advection_schemes_eddy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
o = OceanDrift(loglevel=50)
o.set_config('environment:fallback:land_binary_mask', 0)
o.set_config('drift:advection_scheme', scheme)
o.set_config('drift:vertical_mixing', False)
o.add_reader(fake_eddy)
o.seed_elements(lon=2.0, lat=63.0, time=datetime.utcnow())
o.set_config('drift:vertical_mixing', False)
o.run(duration=timedelta(days=9), time_step=time_step)
runs.append(o)

Expand Down
4 changes: 2 additions & 2 deletions examples/example_backandforth.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

o.add_reader(reader_norkyst)
o.set_config('environment:fallback:land_binary_mask', 0)
o.disable_vertical_motion()

#%%
# Forward run
# Seeding some particles
lon = 4.2; lat = 60.1;
time = reader_norkyst.start_time
o.seed_elements(lon, lat, radius=1000, number=100, time=time)
o.disable_vertical_motion()

o.run(steps=50*4, time_step=900, time_step_output=3600, outfile=ncfile)

Expand All @@ -43,9 +43,9 @@
del o
o = OceanDrift(loglevel=20) # Set loglevel to 0 for debug information
o.set_config('environment:fallback:land_binary_mask', 0)
o.disable_vertical_motion()
o.add_reader(reader_norkyst)
o.schedule_elements(elements_final, time_final)
o.disable_vertical_motion()

#%%
# Running model backwards from end of forward simulation
Expand Down
Empty file modified examples/example_chemicaldrift.py
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion examples/example_coastline.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from opendrift.models.oceandrift import OceanDrift

o = OceanDrift(loglevel=20) # Set loglevel to 0 for debug information
o.max_speed = 3
o.set_config('drift:max_speed', 3)

# This example works better using hourly input from Thredds than the daily data from test folder
reader_current = reader_netCDF_CF_generic.Reader('https://thredds.met.no/thredds/dodsC/cmems/topaz6/dataset-topaz6-arc-15min-3km-be.ncml')
Expand Down
16 changes: 8 additions & 8 deletions examples/example_codegg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
'https://thredds.met.no/thredds/dodsC/cmems/topaz6/dataset-topaz6-arc-15min-3km-be.ncml',
'https://thredds.met.no/thredds/dodsC/mepslatest/meps_lagged_6_h_latest_2_5km_latest.nc'])

#%%
# Adjusting some configuration
o.set_config('drift:vertical_mixing', True)
o.set_config('vertical_mixing:diffusivitymodel', 'windspeed_Sundby1983') # windspeed parameterization for eddy diffusivity
#%%
# Vertical mixing requires fast time step
o.set_config('vertical_mixing:timestep', 60.) # seconds

#%%
# spawn NEA cod eggs at defined position and time
time = datetime.utcnow()
Expand All @@ -27,14 +35,6 @@
o.seed_elements(13., 67.8, z=-40, radius=2000, number=500,
time=time, diameter=0.0014, neutral_buoyancy_salinity=31.25)

#%%
# Adjusting some configuration
o.set_config('drift:vertical_mixing', True)
o.set_config('vertical_mixing:diffusivitymodel', 'windspeed_Sundby1983') # windspeed parameterization for eddy diffusivity
#%%
# Vertical mixing requires fast time step
o.set_config('vertical_mixing:timestep', 60.) # seconds

#%%
# Running model
o.run(duration=timedelta(hours=48), time_step=3600)
Expand Down
19 changes: 9 additions & 10 deletions examples/example_cone.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
o.add_readers_from_list([
'https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be'])

#%%
# Adjusting some configuration
o.set_config('processes:dispersion', True)
o.set_config('processes:evaporation', False)
o.set_config('processes:emulsification', True)
o.disable_vertical_motion()
#o.set_config('drift:vertical_mixing', False)
#o.set_config('drift:vertical_mixing', False)

#%%
# Seed elements along cone, e.g. ship track with
# increasing uncertainty in position
Expand All @@ -23,21 +32,11 @@
latend = 69.991446
lonend = 17.760061
time = [datetime.utcnow(), datetime.utcnow() + timedelta(hours=12)]

o.seed_cone(lon=[lonstart, lonend], lat=[latstart, latend],
oil_type='EKOFISK', radius=[100, 800], number=10000, time=[time])

print(o)

#%%
# Adjusting some configuration
o.set_config('processes:dispersion', True)
o.set_config('processes:evaporation', False)
o.set_config('processes:emulsification', True)
o.disable_vertical_motion()
#o.set_config('drift:vertical_mixing', False)
#o.set_config('drift:vertical_mixing', False)

#%%
# Running model for 24 hours
o.run(steps=24*2, time_step=1800, time_step_output=3600)
Expand Down
8 changes: 4 additions & 4 deletions examples/example_depth.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
o.add_readers_from_list([
'https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be'])

#%%
# Adding some diffusion
o.set_config('drift:horizontal_diffusivity', 10) # m2/s

#%%
# Seed 1000 elements at random depths
z = -np.random.rand(2000)*50
Expand All @@ -23,10 +27,6 @@

print(o)

#%%
# Adding some diffusion
o.set_config('drift:horizontal_diffusivity', 10) # m2/s

#%%
# Running model
o.run(duration=timedelta(hours=24), time_step=1800)
Expand Down
2 changes: 1 addition & 1 deletion examples/example_dominating.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
t = datetime.now()

o = OceanDrift(loglevel=20)
o.set_config('environment:constant:y_sea_water_velocity', .1)

for i, lon in enumerate(lons):
o.seed_elements(lon=lon, lat=60, radius=3000, number=2000, time=t, origin_marker_name='Lon %f' % lon)
o.set_config('environment:constant:y_sea_water_velocity', .1)
o.run(steps=15, outfile=of)

#%%
Expand Down
2 changes: 1 addition & 1 deletion examples/example_double_gyre_LCS_particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
#%%
# Make run with particles for the same period
o.reset()
o.disable_vertical_motion()
x = [.9]
y = [.5]
lon, lat = double_gyre.xy2lonlat(x, y)

o.seed_elements(lon, lat, radius=.15, number=2000,
time=double_gyre.initial_time)
o.disable_vertical_motion()
o.run(duration=duration, time_step=time_step,
time_step_output=time_step_output)
o.animation(buffer=0, lcs=lcs, hide_landmask=True)
Expand Down
6 changes: 3 additions & 3 deletions examples/example_drifter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

o.add_reader([reader_current, reader_wind])

# Prevent mixing elements downwards
o.set_config('drift:vertical_mixing', False)

#%%
# Seeding elements
#
Expand All @@ -41,9 +44,6 @@
time=reader_current.start_time,
wind_drift_factor=wind_drift_factor)

# Prevent mixing elements downwards
o.set_config('drift:vertical_mixing', False)

#%%
# Running model
o.run(time_step=timedelta(minutes=15),
Expand Down
Empty file modified examples/example_eulerdrift_gauss_blob.py
100644 → 100755
Empty file.
Empty file modified examples/example_eulerdrift_norkyst.py
100644 → 100755
Empty file.
8 changes: 4 additions & 4 deletions examples/example_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
reader_arome.start_time + timedelta(hours=30)]
#time = reader_arome.start_time

# Seed oil elements at defined position and time
o.seed_elements(lon=4.6, lat=60.0, radius=50, number=3000, time=time,
wind_drift_factor=.02)

#%%
# Adjusting some configuration
o.set_config('drift:vertical_mixing', False)
Expand All @@ -41,6 +37,10 @@
o.set_config('drift:current_uncertainty', .1)
o.set_config('drift:wind_uncertainty', 1)

# Seed oil elements at defined position and time
o.seed_elements(lon=4.6, lat=60.0, radius=50, number=3000, time=time,
wind_drift_factor=.02)

#%%
# Running model
o.run(end_time=reader_norkyst.end_time, time_step=1800,
Expand Down
8 changes: 4 additions & 4 deletions examples/example_horizontal_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,33 @@
#reader_norkyst = reader_netCDF_CF_generic.Reader('https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be')

o.add_reader([reader_norkyst, reader_arome])
time = reader_arome.start_time
o.seed_elements(lon, lat, radius=500, number=2000, time=time)

#%%
# First run, with no horizontal diffusion
o.set_config('drift:current_uncertainty', 0)
o.set_config('drift:wind_uncertainty', 0)
time = reader_arome.start_time
o.seed_elements(lon, lat, radius=500, number=2000, time=time)
o.run(duration=timedelta(hours=24))

#%%
# Second run, identical, except for added diffusion
o2 = OceanDrift(loglevel=20) # Set loglevel to 0 for debug information
o2.add_reader([reader_norkyst, reader_arome])
o2.seed_elements(lon, lat, radius=500, number=2000, time=time)
#o2.set_config('drift:current_uncertainty', .2) # Difference from first run
#o2.set_config('drift:wind_uncertainty', 1) # Difference from first run
o2.set_config('drift:horizontal_diffusivity', 10) # Difference from first run
o2.seed_elements(lon, lat, radius=500, number=2000, time=time)
o2.run(duration=timedelta(hours=24))

#%%
# Third run, identical, except for diffusion and shorter timestep
o3 = OceanDrift(loglevel=20) # Set loglevel to 0 for debug information
o3.add_reader([reader_norkyst, reader_arome])
o3.seed_elements(lon, lat, radius=500, number=2000, time=time)
#o3.set_config('drift:current_uncertainty', .2) # Difference from first run
#o3.set_config('drift:wind_uncertainty', 1) # Difference from first run
o3.set_config('drift:horizontal_diffusivity', 10) # Difference from first run
o3.seed_elements(lon, lat, radius=500, number=2000, time=time)
o3.run(duration=timedelta(hours=24), time_step=300, time_step_output=3600)

#%%
Expand Down
12 changes: 6 additions & 6 deletions examples/example_huge_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
#%%
# First make a simulation with two seedings, marked by *origin_marker*
o = OceanDrift(loglevel=50)
o.set_config('drift:horizontal_diffusivity', 10)
t1 = datetime.now()
t2 = t1 + timedelta(hours=6)
number = 10000
outfile = 'simulation.nc' # Raw simulation output
o.seed_elements(time=t1, lon=4, lat=60, number=number,
origin_marker=0)
o.seed_elements(time=[t1, t2], lon=4.2, lat=60.4, number=number,
origin_marker=1)

reader_x = reader_oscillating.Reader('x_sea_water_velocity',
amplitude=1, zero_time=t1)
reader_y = reader_oscillating.Reader('y_sea_water_velocity',
amplitude=1, zero_time=t2)
o.add_reader([reader_x, reader_y])
o.set_config('drift:horizontal_diffusivity', 10)
o.seed_elements(time=t1, lon=4, lat=60, number=number,
origin_marker=0)
o.seed_elements(time=[t1, t2], lon=4.2, lat=60.4, number=number,
origin_marker=1)

o.run(duration=timedelta(hours=24),
time_step=900, time_step_output=1800, outfile=outfile)

Expand Down
12 changes: 6 additions & 6 deletions examples/example_larvae.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@

o = LarvalFish(loglevel=50)

#%%
# Seeding 20 fish eggs, which will hatch as larvae after some time, depending om temperature
time = datetime(2020, 7, 1, 12)
o.seed_elements(lon=4, lat=60, time=[time, time+timedelta(hours=24)], number=20)

#%%
# No horizontal movement, here only investigating vertical mixing and swimming
r = ConstantReader(
{'x_sea_water_velocity': 0, 'y_sea_water_velocity': 0, 'x_wind': 0, 'y_wind': 0,
'sea_water_temperature': 10,
'land_binary_mask': 0, 'ocean_vertical_diffusivity': .02})
o.add_reader(r)

o.set_config('general:use_auto_landmask', False)

#%%
# Seeding 20 fish eggs, which will hatch as larvae after some time, depending om temperature
time = datetime(2020, 7, 1, 12)
o.seed_elements(lon=4, lat=60, time=[time, time+timedelta(hours=24)], number=20)

o.run(duration=timedelta(days=40))

#%%
Expand Down
6 changes: 3 additions & 3 deletions examples/example_mixed_layer_depth.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
#%%
# First with Sundby1983 parameterization of diffusivity, based on wind and MLD
o = OceanDrift(loglevel=50)
o.seed_cone(lon=[2, 4], lat=[60, 60], time=datetime.now(), number=5000)
o.add_reader([r1, r2])
o.set_config('environment:constant:y_wind', 8) # Some wind for mixing
o.set_config('drift:vertical_mixing', True)
o.set_config('vertical_mixing:diffusivitymodel', 'windspeed_Sundby1983')
# Increasing background diffusivity beyond default (1.2e-5) to avoid artefact due to sharp gradient at MLD
o.set_config('vertical_mixing:background_diffusivity', 0.001)
o.seed_cone(lon=[2, 4], lat=[60, 60], time=datetime.now(), number=5000)
o.run(duration=timedelta(hours=48))
o.animation_profile()

Expand All @@ -34,12 +34,12 @@
#%%
# Same, but with Large1994 parameterization of diffusivity
o = OceanDrift(loglevel=50)
o.seed_cone(lon=[2, 4], lat=[60, 60], time=datetime.now(), number=5000)
o.add_reader([r1, r2])
o.set_config('environment:constant:y_wind', 8) # Some wind for mixing
o.set_config('drift:vertical_mixing', True)
o.set_config('vertical_mixing:diffusivitymodel', 'windspeed_Large1994')
o.set_config('vertical_mixing:background_diffusivity', 0.001)
o.seed_cone(lon=[2, 4], lat=[60, 60], time=datetime.now(), number=5000)
o.run(duration=timedelta(hours=48))
o.animation_profile()

Expand All @@ -49,12 +49,12 @@
#%%
# Using Large1994, but with 0 diffusivity below MLD
o = OceanDrift(loglevel=50)
o.seed_cone(lon=[2, 4], lat=[60, 60], time=datetime.now(), number=5000)
o.add_reader([r1, r2])
o.set_config('environment:constant:y_wind', 8) # Some wind for mixing
o.set_config('drift:vertical_mixing', True)
o.set_config('vertical_mixing:diffusivitymodel', 'windspeed_Large1994')
o.set_config('vertical_mixing:background_diffusivity', 0)
o.seed_cone(lon=[2, 4], lat=[60, 60], time=datetime.now(), number=5000)
o.run(duration=timedelta(hours=48))
o.animation_profile()

Expand Down
9 changes: 4 additions & 5 deletions examples/example_model_landmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,24 @@
# First run, with default GSHHG vector landmask
o.add_reader([reader_nordic])
time = reader_nordic.start_time
o.seed_elements(lon, lat, radius=3000, number=1000, time=time)
o.set_config('general:use_auto_landmask', True)
o.seed_elements(lon, lat, radius=3000, number=1000, time=time)
o.run(end_time=reader_nordic.end_time, time_step=1800, time_step_output=3*3600)

#%%
# Second run, with landmask from ocean model
o2 = OceanDrift(loglevel=20)
o2.add_reader([reader_nordic])
lon = 14.75; lat = 68.1
o2.seed_elements(lon, lat, radius=3000, number=1000, time=time)
o2.set_config('general:use_auto_landmask', False)
o2.seed_elements(lon, lat, radius=3000, number=1000, time=time)
o2.run(end_time=reader_nordic.end_time, time_step=1800, time_step_output=3*3600)

#%% Prepare cusom colormap/colors for land and ocean
from matplotlib.colors import ListedColormap
import cartopy.feature as cfeature
#cmap = ListedColormap(('blue', 'red'))
cmap = ListedColormap((cfeature.COLORS['water'],
cfeature.COLORS['land']))
cmap = ListedColormap([cfeature.COLORS['water'],
cfeature.COLORS['land']])

#%%
# .. _model_landmask_only_model:
Expand Down
Loading