-
Notifications
You must be signed in to change notification settings - Fork 121
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 #1435 from knutfrode/dev
Made new example illustrating mapping of variables for CMEMS currents…
- Loading branch information
Showing
5 changed files
with
82 additions
and
65 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 |
---|---|---|
|
@@ -13,6 +13,7 @@ dependencies: | |
- xarray | ||
- dask | ||
- cfgrib | ||
- cf_xarray | ||
- pygrib | ||
- xhistogram | ||
- requests | ||
|
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
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,64 @@ | ||
#!/usr/bin/env python | ||
""" | ||
CMEMS current components | ||
======================== | ||
The global CMEMS/copernicus ocean model contains several different surface current fields. | ||
OpenDrift will by default use the variables with "standard_name" attribute equal to what is requested from a module, typically "x_sea_water_velocity"/"y_sea_water_velocity" for currents. | ||
Note that "east/north" counterparts will also be detected, and eventual rotation will be performed automatically. | ||
This example illustrates how a "standard_name_mapping" can be added to the generic netCDF reader to chose alternative variables. | ||
The example also illustrates the alternative (experimental) mechanism of summing two readers. | ||
""" | ||
|
||
from datetime import datetime, timedelta | ||
import cf_xarray | ||
import copernicusmarine | ||
from opendrift.models.oceandrift import OceanDrift | ||
from opendrift.readers.reader_netCDF_CF_generic import Reader | ||
|
||
#%% | ||
# Get an Xarray dataset from copernicusmarine client | ||
ds = copernicusmarine.open_dataset(dataset_id='cmems_mod_glo_phy_anfc_merged-uv_PT1H-i') | ||
print(ds) # Default Xarray output | ||
print(ds.cf) # Output from cf-xarray | ||
|
||
#%% | ||
# Create an OpenDrift reader from this dataset | ||
reader_default = Reader(ds, name='CMEMS default') | ||
|
||
#%% | ||
# Mapping other variables to required standard_name's | ||
reader_tides_only = Reader(ds, standard_name_mapping={ | ||
'utide': 'x_sea_water_velocity', | ||
'vtide': 'y_sea_water_velocity', | ||
}, name='Tides only') | ||
reader_stokes = Reader(ds, standard_name_mapping={ | ||
'vsdx': 'x_sea_water_velocity', | ||
'vsdy': 'y_sea_water_velocity', | ||
}, name='Stokes only') | ||
reader_total = Reader(ds, standard_name_mapping={ | ||
'utotal': 'x_sea_water_velocity', | ||
'vtotal': 'y_sea_water_velocity', | ||
}, name='Total current') | ||
|
||
#%% | ||
# Run and compare simulations using the different current components | ||
cases = {'Eulerian current': reader_default, | ||
'Tides only': reader_tides_only, | ||
'Stokes drift only': reader_stokes, | ||
'Total current': reader_total, | ||
'SUM: Eulerian + Tides': reader_default + reader_tides_only, # Experimental feature | ||
'SUM: Eulerian + Stokes': reader_default + reader_stokes, # Experimental feature | ||
} | ||
|
||
simulations = [] | ||
for cname, reader in cases.items(): | ||
o = OceanDrift() | ||
o.add_reader(reader, variables=['x_sea_water_velocity', 'y_sea_water_velocity']) | ||
o.seed_elements(lon=4.8, lat=60, time=datetime(2024, 10, 31, 6)) | ||
o.run(duration=timedelta(hours=12)) | ||
simulations.append(o) | ||
|
||
simulations[0].plot(filename='cmems_comparison.png', buffer=.05, | ||
compare=simulations[1:], legend=list(cases)) |
This file was deleted.
Oops, something went wrong.
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