Skip to content

Commit

Permalink
New example to illustrate use of new Copernicus Marine Client
Browse files Browse the repository at this point in the history
  • Loading branch information
knutfrode committed Jan 5, 2024
1 parent 2bca199 commit 35a3a42
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
45 changes: 45 additions & 0 deletions examples/example_long_cmems_new.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python
"""
Copernicus marine client
========================
This example runs an OceanDrift simulation
with current data from CMEMS
To run this example, you need a CMEMS account created at
https://marine.copernicus.eu
and the copernicus_marine_client installed from
https://pypi.org/project/copernicus-marine-client/
"""

from datetime import datetime, timedelta
import copernicus_marine_client as copernicusmarine
from opendrift.readers.reader_netCDF_CF_generic import Reader
from opendrift.models.oceandrift import OceanDrift

lon = 4.8; lat = 60 # Bergen, Norway
lon = -89; lat = 29.8 # New Orleans
lon = 107; lat = 10 # Ho Chi Minh
lon = 123; lat = -16.3 # Australia


o = OceanDrift()

#%%
# First get a Xarray dataset from copernicus_marine_client
ds = copernicusmarine.open_dataset(
dataset_id='cmems_mod_glo_phy_anfc_merged-uv_PT1H-i',
username='<your cmems username>', password='<your cmems password>')

#%%
# Then create an OpenDrift reader from this dataset
r = Reader(ds)
o.add_reader(r)

o.seed_elements(lon=lon, lat=lat, number=5000, radius=1000, time=datetime.utcnow())
o.run(duration=timedelta(days=3))

o.animation(fast=True, clabel='Ocean current [m/s]',
background=['x_sea_water_velocity', 'y_sea_water_velocity'])

#%%
# .. image:: /gallery/animations/example_cmems_new_0.gif
2 changes: 1 addition & 1 deletion examples/example_macondo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

try:
reader_globcurrent = reader_netCDF_CF_generic.Reader(
'http://tds0.ifremer.fr/thredds/dodsC/GLOBCURRENT-L4-CUREUL_HS-ALT_SUM-V03.0',
'https://tds0.ifremer.fr/thredds/dodsC/GLOBCURRENT-L4-CUREUL_HS-ALT_SUM-V03.0',
standard_name_mapping={'eastward_eulerian_current_velocity': 'x_sea_water_velocity',
'northward_eulerian_current_velocity': 'y_sea_water_velocity'})
except:
Expand Down

0 comments on commit 35a3a42

Please sign in to comment.