Skip to content

Commit 3e304ef

Browse files
committed
Improve used sources listing
1 parent 7921337 commit 3e304ef

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

opendrift_leeway_webgui/simulation.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def main():
8686
action="store_true",
8787
default=False,
8888
)
89+
8990
args = parser.parse_args()
9091

9192
simulation = Leeway(loglevel=50)
@@ -95,8 +96,9 @@ def main():
9596
for data_file in os.listdir(INPUTDIR)
9697
if data_file.endswith(".nc")
9798
]
99+
sources = []
98100
if local_sources:
99-
sources = local_sources
101+
sources += local_sources
100102
elif not args.no_web:
101103
if os.environ.get("COPERNICUSMARINE_SERVICE_USERNAME") not in (
102104
None,
@@ -109,7 +111,9 @@ def main():
109111
"cmems_mod_glo_phy_anfc_merged-uv_PT1H-i",
110112
"cmems_obs-wind_glo_phy_nrt_l4_0.125deg_PT1H",
111113
]
112-
print("Using sources:\n - {}".format("\n - ".join(cmems_dataset_ids)))
114+
print(
115+
"Using CMEMS datasets:\n - {}".format("\n - ".join(cmems_dataset_ids))
116+
)
113117
readers = []
114118
for dataset_id in cmems_dataset_ids:
115119
try:
@@ -123,18 +127,16 @@ def main():
123127
raise
124128
readers.append(Reader(ds, name=dataset_id))
125129
simulation.add_reader(readers)
126-
sources = [
130+
sources += [
127131
"https://pae-paha.pacioos.hawaii.edu/thredds/dodsC/ncep_global/NCEP_Global_Atmospheric_Model_best.ncd"
128132
]
129-
simulation.add_readers_from_list(sources, lazy=False)
130-
131-
else:
132-
sources = [
133-
"https://tds.hycom.org/thredds/dodsC/GLBy0.08/latest",
134-
"https://pae-paha.pacioos.hawaii.edu/thredds/dodsC/ncep_global/NCEP_Global_Atmospheric_Model_best.ncd",
135-
]
136-
print("Using sources:\n - {}".format("\n - ".join(sources)))
137-
simulation.add_readers_from_list(sources, lazy=False)
133+
else:
134+
sources += [
135+
"https://tds.hycom.org/thredds/dodsC/GLBy0.08/latest",
136+
"https://pae-paha.pacioos.hawaii.edu/thredds/dodsC/ncep_global/NCEP_Global_Atmospheric_Model_best.ncd",
137+
]
138+
print("Using sources:\n - {}".format("\n - ".join(sources)))
139+
simulation.add_readers_from_list(sources, lazy=False)
138140

139141
reader_landmask = reader_global_landmask.Reader()
140142
simulation.add_reader([reader_landmask])

tests/leeway/test_simulation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import re
2-
from datetime import datetime
2+
from datetime import datetime, timedelta
33

44
import pytest
55
from django.core import mail
@@ -24,7 +24,9 @@ def test_simulation(admin_client, settings, celery_worker, uuid_store):
2424
"latitude": "33°58'44.3\"",
2525
"longitude": "11°21'13.4\"",
2626
"object_type": 27,
27-
"start_time": datetime.now().strftime("%Y-%m-%d %H:%M"),
27+
"start_time": (datetime.now() - timedelta(hours=4)).strftime(
28+
"%Y-%m-%d %H:%M"
29+
),
2830
"duration": 2,
2931
"radius": 1000,
3032
},

0 commit comments

Comments
 (0)