Skip to content

Commit ebafcd0

Browse files
committed
Use copernicus marine reader
1 parent edddd78 commit ebafcd0

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

opendrift_leeway_webgui/leeway/tasks.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def run_leeway_simulation(request_id):
3131
f"COPERNICUSMARINE_SERVICE_USERNAME={settings.COPERNICUSMARINE_SERVICE_USERNAME}",
3232
"-e",
3333
f"COPERNICUSMARINE_SERVICE_PASSWORD={settings.COPERNICUSMARINE_SERVICE_PASSWORD}",
34+
"-e",
35+
f"COPERNICUSMARINE_USERNAME={settings.COPERNICUSMARINE_SERVICE_USERNAME}",
36+
"-e",
37+
f"COPERNICUSMARINE_PASSWORD={settings.COPERNICUSMARINE_SERVICE_PASSWORD}",
3438
"--volume",
3539
f"{settings.SIMULATION_ROOT}:/code/leeway",
3640
"--volume",

opendrift_leeway_webgui/simulation.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import argparse
1212
import os
13+
import sys
1314
import uuid
1415
from datetime import datetime, timedelta
1516

@@ -25,8 +26,10 @@
2526
from matplotlib.colors import ListedColormap
2627

2728
# pylint: disable=import-error, disable=no-name-in-module
29+
import copernicusmarine
2830
from opendrift.models.leeway import Leeway
2931
from opendrift.readers import reader_global_landmask
32+
from opendrift.readers.reader_netCDF_CF_generic import Reader
3033

3134
INPUTDIR = "/code/leeway/input"
3235

@@ -96,20 +99,30 @@ def main():
9699
elif not args.no_web:
97100
if "COPERNICUSMARINE_SERVICE_USERNAME" in os.environ:
98101
print("Using CMEMS")
99-
sources = [
102+
cmems_dataset_ids = [
100103
"cmems_mod_med_phy-cur_anfc_4.2km_PT15M-i",
101104
"cmems_mod_glo_phy_anfc_merged-uv_PT1H-i",
102105
"cmems_obs-wind_glo_phy_nrt_l4_0.125deg_PT1H-i",
103106
]
107+
print("Using sources:\n - {}".format("\n - ".join(cmems_dataset_ids)))
108+
readers = []
109+
for dataset_id in cmems_dataset_ids:
110+
try:
111+
ds = copernicusmarine.open_dataset(dataset_id=dataset_id, chunk_size_limit=0)
112+
print(f"Opened {dataset_id}:")
113+
print(ds)
114+
except Exception as exc:
115+
print(f"ERROR opening {dataset_id}: {exc}", file=sys.stderr)
116+
raise
117+
readers.append(Reader(ds, name=dataset_id))
118+
simulation.add_reader(readers)
104119
else:
105120
sources = [
106121
"https://tds.hycom.org/thredds/dodsC/GLBy0.08/latest",
107122
"https://pae-paha.pacioos.hawaii.edu/thredds/dodsC/ncep_global/NCEP_Global_Atmospheric_Model_best.ncd",
108123
]
109-
110-
print("Using sources:\n - {}".format("\n - ".join(sources)))
111-
112-
simulation.add_readers_from_list(sources, lazy=True)
124+
print("Using sources:\n - {}".format("\n - ".join(sources)))
125+
simulation.add_readers_from_list(sources, lazy=False)
113126

114127
reader_landmask = reader_global_landmask.Reader()
115128
simulation.add_reader([reader_landmask])

0 commit comments

Comments
 (0)