.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/example_long_cmems_currents.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_example_long_cmems_currents.py: 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. .. GENERATED FROM PYTHON SOURCE LINES 13-20 .. code-block:: Python 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 .. GENERATED FROM PYTHON SOURCE LINES 21-22 Get an Xarray dataset from copernicusmarine client .. GENERATED FROM PYTHON SOURCE LINES 22-26 .. code-block:: Python ds = copernicusmarine.open_dataset(dataset_id='cmems_mod_glo_phy_anfc_merged-uv_PT1H-i', chunk_size_limit=0) print(ds) # Default Xarray output print(ds.cf) # Output from cf-xarray .. GENERATED FROM PYTHON SOURCE LINES 27-28 Create an OpenDrift reader from this dataset .. GENERATED FROM PYTHON SOURCE LINES 28-30 .. code-block:: Python reader_default = Reader(ds, name='CMEMS default') .. GENERATED FROM PYTHON SOURCE LINES 31-32 Mapping other variables to required standard_name's .. GENERATED FROM PYTHON SOURCE LINES 32-45 .. code-block:: Python reader_tides = 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') .. GENERATED FROM PYTHON SOURCE LINES 46-47 Run and compare simulations using the different current components .. GENERATED FROM PYTHON SOURCE LINES 47-66 .. code-block:: Python cases = {'Eulerian current': reader_default, 'Tides only': reader_tides, 'Stokes drift only': reader_stokes, 'Total current': reader_total, 'SUM: Eulerian + Tides': reader_default + reader_tides, # Experimental feature 'SUM: Eulerian + Stokes': reader_default + reader_stokes, # Experimental feature 'SUM: Eulerian + Tides + Stokes': reader_default + reader_tides + 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)) .. _sphx_glr_download_gallery_example_long_cmems_currents.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_long_cmems_currents.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_long_cmems_currents.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_long_cmems_currents.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_