|
10 | 10 |
|
11 | 11 | import argparse |
12 | 12 | import os |
| 13 | +import sys |
13 | 14 | import uuid |
14 | 15 | from datetime import datetime, timedelta |
15 | 16 |
|
|
25 | 26 | from matplotlib.colors import ListedColormap |
26 | 27 |
|
27 | 28 | # pylint: disable=import-error, disable=no-name-in-module |
| 29 | +import copernicusmarine |
28 | 30 | from opendrift.models.leeway import Leeway |
29 | 31 | from opendrift.readers import reader_global_landmask |
| 32 | +from opendrift.readers.reader_netCDF_CF_generic import Reader |
30 | 33 |
|
31 | 34 | INPUTDIR = "/code/leeway/input" |
32 | 35 |
|
@@ -85,23 +88,46 @@ def main(): |
85 | 88 | args = parser.parse_args() |
86 | 89 |
|
87 | 90 | simulation = Leeway(loglevel=50) |
88 | | - sources = [ |
| 91 | + |
| 92 | + local_sources = [ |
89 | 93 | os.path.join(INPUTDIR, data_file) |
90 | 94 | for data_file in os.listdir(INPUTDIR) |
91 | 95 | if data_file.endswith(".nc") |
92 | 96 | ] |
93 | | - |
94 | | - if not args.no_web: |
95 | | - sources.extend( |
96 | | - ( |
97 | | - "https://tds.hycom.org/thredds/dodsC/GLBy0.08/latest", |
| 97 | + if local_sources: |
| 98 | + sources = local_sources |
| 99 | + elif not args.no_web: |
| 100 | + if "COPERNICUSMARINE_SERVICE_USERNAME" in os.environ: |
| 101 | + print("Using CMEMS") |
| 102 | + cmems_dataset_ids = [ |
| 103 | + "cmems_mod_med_phy-cur_anfc_4.2km_PT15M-i", |
| 104 | + "cmems_mod_glo_phy_anfc_merged-uv_PT1H-i", |
| 105 | + "cmems_obs-wind_glo_phy_nrt_l4_0.125deg_PT1H", |
| 106 | + ] |
| 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) |
| 119 | + sources = [ |
98 | 120 | "https://pae-paha.pacioos.hawaii.edu/thredds/dodsC/ncep_global/NCEP_Global_Atmospheric_Model_best.ncd", |
99 | | - ) |
100 | | - ) |
101 | | - |
102 | | - print("Using sources:\n - {}".format("\n - ".join(sources))) |
103 | | - |
104 | | - simulation.add_readers_from_list(sources, lazy=True) |
| 121 | + ] |
| 122 | + simulation.add_readers_from_list(sources, lazy=False) |
| 123 | + |
| 124 | + else: |
| 125 | + sources = [ |
| 126 | + "https://tds.hycom.org/thredds/dodsC/GLBy0.08/latest", |
| 127 | + "https://pae-paha.pacioos.hawaii.edu/thredds/dodsC/ncep_global/NCEP_Global_Atmospheric_Model_best.ncd", |
| 128 | + ] |
| 129 | + print("Using sources:\n - {}".format("\n - ".join(sources))) |
| 130 | + simulation.add_readers_from_list(sources, lazy=False) |
105 | 131 |
|
106 | 132 | reader_landmask = reader_global_landmask.Reader() |
107 | 133 | simulation.add_reader([reader_landmask]) |
|
0 commit comments