-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1303 from knutfrode/dev
Added utility method open_mfdataset_overlap to create manual threds a…
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python | ||
""" | ||
Manual aggregate | ||
================== | ||
""" | ||
|
||
from datetime import datetime, timedelta | ||
import pandas as pd | ||
import matplotlib.pyplot as plt | ||
from opendrift.readers import reader_netCDF_CF_generic | ||
from opendrift.readers import open_mfdataset_overlap | ||
from opendrift.models.oceandrift import OceanDrift | ||
|
||
#% | ||
# Create manual aggregate from individual URLs, for NorKyst ocean model initialized at 00 hours every day | ||
ds = open_mfdataset_overlap( | ||
'https://thredds.met.no/thredds/dodsC/fou-hi/norkyst800m-1h/NorKyst-800m_ZDEPTHS_his.an.%Y%m%d%H.nc', | ||
time_series=pd.date_range(datetime.now().date()-timedelta(days=1), datetime.now().date(), freq='1D')) | ||
|
||
#% | ||
# Create reader from Xarray dataset | ||
rm = reader_netCDF_CF_generic.Reader(ds, name='NorKyst manual aggregate') | ||
print(rm) | ||
|
||
om = OceanDrift() | ||
om.add_reader(rm) | ||
om.seed_elements(lon=3.4, lat=60.23, number=1000, radius=100, time=rm.start_time) | ||
om.run(end_time=rm.end_time) | ||
|
||
#% | ||
# Second simulation using ready made aggregate from thredds | ||
ot = OceanDrift() | ||
ot.add_readers_from_list(['https://thredds.met.no/thredds/dodsC/sea/norkyst800m/1h/aggregate_be']) | ||
ot.seed_elements(lon=3.4, lat=60.23, number=1000, radius=100, time=rm.start_time) | ||
ot.run(end_time=rm.end_time) | ||
|
||
#% | ||
# Simulation should be identical, but we see that manual aggregate is significantly slower than using thredds aggregate | ||
om.animation(compare=ot, | ||
legend=[f'NorKyst manual aggregate {om.timing["total time"]}', | ||
f'NorKyst thredds aggregate {ot.timing["total time"]}']) | ||
|
||
#%% | ||
# .. image:: /gallery/animations/example_manual_aggregate_0.gif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters