.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/example_seed_demonstration.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_seed_demonstration.py: Seed demonstration ================== .. GENERATED FROM PYTHON SOURCE LINES 6-16 .. code-block:: Python from datetime import datetime, timedelta import numpy as np from opendrift.models.oceandrift import OceanDrift from opendrift.models.openoil import OpenOil o = OceanDrift(loglevel=50) time=datetime(2016, 1, 20, 12, 30, 0) .. GENERATED FROM PYTHON SOURCE LINES 17-18 Seeding a single element at a point .. GENERATED FROM PYTHON SOURCE LINES 18-27 .. code-block:: Python print('\n' + '='*70) print('Seeding a single element at a point:') print('o.seed_elements(lon=4, lat=60, time=time)') print('='*70) o.seed_elements(lon=4, lat=60, time=time) #o.run(steps=1) o.plot(buffer=.7, fast=True) .. image-sg:: /gallery/images/sphx_glr_example_seed_demonstration_001.png :alt: OpenDrift - OceanDrift 1 elements seeded at 2016-01-20 12:30 UTC :srcset: /gallery/images/sphx_glr_example_seed_demonstration_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ====================================================================== Seeding a single element at a point: o.seed_elements(lon=4, lat=60, time=time) ====================================================================== (,
) .. GENERATED FROM PYTHON SOURCE LINES 28-29 Seeding 100 elements within a radius of 1000 m .. GENERATED FROM PYTHON SOURCE LINES 29-39 .. code-block:: Python o = OceanDrift(loglevel=50) print('\n' + '='*70) print('Seeding 100 elements within a radius of 1000 m:') print('o.seed_elements(lon=4, lat=60, number=100, radius=1000, time=time)') print('='*70) o.seed_elements(lon=4, lat=60, number=100, radius=1000, time=time) #o.run(steps=1) o.plot(buffer=.7, fast=True) .. image-sg:: /gallery/images/sphx_glr_example_seed_demonstration_002.png :alt: OpenDrift - OceanDrift 100 elements seeded at 2016-01-20 12:30 UTC :srcset: /gallery/images/sphx_glr_example_seed_demonstration_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ====================================================================== Seeding 100 elements within a radius of 1000 m: o.seed_elements(lon=4, lat=60, number=100, radius=1000, time=time) ====================================================================== (,
) .. GENERATED FROM PYTHON SOURCE LINES 40-41 Seeding 100 elements within a radius of 1000 m and specifying a property (here z/depth) as an array .. GENERATED FROM PYTHON SOURCE LINES 41-53 .. code-block:: Python print('\n' + '='*70) print('Seeding 100 elements within a radius of 1000 m\n and specifying a property (here z/depth) as an array:') print('o.seed_elements(lon=4, lat=60, number=100, radius=1000, time=time, z=z)') print('='*70) o = OceanDrift(loglevel=50) z = np.linspace(0, -50, 100) # Linearly increasing depth o.set_config('environment:fallback:y_sea_water_velocity', 3) # Adding some current to be able to visualise depth as color of trajectories o.seed_elements(lon=4, lat=60, number=100, radius=1000, time=time, z=z) o.run(steps=1) o.plot(linecolor='z', buffer=.7, fast=True) .. image-sg:: /gallery/images/sphx_glr_example_seed_demonstration_003.png :alt: OpenDrift - OceanDrift 2016-01-20 12:30 to 2016-01-20 13:30 UTC (2 steps) :srcset: /gallery/images/sphx_glr_example_seed_demonstration_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ====================================================================== Seeding 100 elements within a radius of 1000 m and specifying a property (here z/depth) as an array: o.seed_elements(lon=4, lat=60, number=100, radius=1000, time=time, z=z) ====================================================================== (,
) .. GENERATED FROM PYTHON SOURCE LINES 54-55 Seeding 100 elements at user defined locations (here along line between two points) .. GENERATED FROM PYTHON SOURCE LINES 55-69 .. code-block:: Python print('\n' + '='*70) print('Seeding 100 elements at user defined locations\n (here along line between two points):') print('lats = np.linspace(60, 61, 100)\n' \ 'lons = np.linspace(4, 4.8, 100)\n' \ 'o.seed_elements(lon=lons, lat=lats, time=time)') print('='*70) o = OceanDrift(loglevel=50) lats = np.linspace(60, 61, 100) lons = np.linspace(4, 4.8, 100) o.seed_elements(lon=lons, lat=lats, time=time) o.run(steps=1) o.plot(buffer=.2, fast=True) .. image-sg:: /gallery/images/sphx_glr_example_seed_demonstration_004.png :alt: OpenDrift - OceanDrift 2016-01-20 12:30 to 2016-01-20 13:30 UTC (2 steps) :srcset: /gallery/images/sphx_glr_example_seed_demonstration_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ====================================================================== Seeding 100 elements at user defined locations (here along line between two points): lats = np.linspace(60, 61, 100) lons = np.linspace(4, 4.8, 100) o.seed_elements(lon=lons, lat=lats, time=time) ====================================================================== (,
) .. GENERATED FROM PYTHON SOURCE LINES 70-71 Seeding 100 elements between two points with seed_cone() (achieving the same as previous example) .. GENERATED FROM PYTHON SOURCE LINES 71-80 .. code-block:: Python print('\n' + '='*70) print('Seeding 100 elements between two points with seed_cone() (achieving the same as previous example):') print('o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=100, time=time)') print('='*70) o = OceanDrift(loglevel=50) o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=100, time=time) o.run(steps=1) o.plot(buffer=.2, fast=True) .. image-sg:: /gallery/images/sphx_glr_example_seed_demonstration_005.png :alt: OpenDrift - OceanDrift 2016-01-20 12:30 to 2016-01-20 13:30 UTC (2 steps) :srcset: /gallery/images/sphx_glr_example_seed_demonstration_005.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ====================================================================== Seeding 100 elements between two points with seed_cone() (achieving the same as previous example): o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=100, time=time) ====================================================================== (,
) .. GENERATED FROM PYTHON SOURCE LINES 81-82 Seeding 1000 elements along cone with radius/uncertainty increasing linearly from 0 to 5000 m .. GENERATED FROM PYTHON SOURCE LINES 82-91 .. code-block:: Python print('\n' + '='*70) print('Seeding 1000 elements along cone with radius/uncertainty\n increasing linearly from 0 to 5000 m:') print('o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=1000, radius=[0, 5000], time=time)') print('='*70) o = OceanDrift(loglevel=50) o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=1000, radius=[0, 5000], time=time) o.run(steps=1) o.plot(buffer=.2, fast=True) .. image-sg:: /gallery/images/sphx_glr_example_seed_demonstration_006.png :alt: OpenDrift - OceanDrift 2016-01-20 12:30 to 2016-01-20 13:30 UTC (2 steps) :srcset: /gallery/images/sphx_glr_example_seed_demonstration_006.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ====================================================================== Seeding 1000 elements along cone with radius/uncertainty increasing linearly from 0 to 5000 m: o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=1000, radius=[0, 5000], time=time) ====================================================================== (,
) .. GENERATED FROM PYTHON SOURCE LINES 92-93 If specifying time as a two element list (start and end, here +5 hours), elements are seeded linearly in time .. GENERATED FROM PYTHON SOURCE LINES 93-102 .. code-block:: Python print('\n' + '='*70) print('If specifying time as a two element list (start and end,\n here +5 hours), elements are seeded linearly in time:') print('o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=1000, radius=[0, 5000], time=[time, time+timedelta(hours=5)])') print('='*70) o = OceanDrift(loglevel=50) o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=1000, radius=[0, 5000], time=[time, time+timedelta(hours=5)]) o.run(steps=5*4, time_step=900) o.animation(fast=True) .. rst-class:: sphx-glr-script-out .. code-block:: none ====================================================================== If specifying time as a two element list (start and end, here +5 hours), elements are seeded linearly in time: o.seed_cone(lon=[4, 4.8], lat=[60, 61], number=1000, radius=[0, 5000], time=[time, time+timedelta(hours=5)]) ====================================================================== /opt/conda/envs/opendrift/lib/python3.11/site-packages/cartopy/mpl/geoaxes.py:1683: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap' will be ignored result = super().scatter(*args, **kwargs) .. GENERATED FROM PYTHON SOURCE LINES 103-104 .. image:: /gallery/animations/example_seed_demonstration_0.gif .. GENERATED FROM PYTHON SOURCE LINES 104-119 .. code-block:: Python print('\n' + '='*70) print('Any model/module may provide specialised seeding-functions, such as \n seeding oil within contours read from a GML file:') print('o.seed_from_gml(o.test_data_folder() + "radarsat_oil_satellite_observation/RS2_20151116_002619_0127_SCNB_HH_SGF_433012_9730_12182143_Oil.gml", num_elements=2000)') print('='*70) o = OpenOil(loglevel=50) o.set_config('environment:fallback:x_wind', 0) o.set_config('environment:fallback:y_wind', 0) o.set_config('environment:fallback:x_sea_water_velocity', 0) o.set_config('environment:fallback:y_sea_water_velocity', 0) o.seed_from_gml(o.test_data_folder() + 'radarsat_oil_satellite_observation/RS2_20151116_002619_0127_SCNB_HH_SGF_433012_9730_12182143_Oil.gml', num_elements=2000) o.run(steps=1, time_step=1800, time_step_output=1800) o.plot(buffer=.03, fast=True) .. image-sg:: /gallery/images/sphx_glr_example_seed_demonstration_007.png :alt: OpenDrift - OpenOil (GENERIC BUNKER C) 2015-11-16 00:26 to 2015-11-16 00:56 UTC (2 steps) :srcset: /gallery/images/sphx_glr_example_seed_demonstration_007.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ====================================================================== Any model/module may provide specialised seeding-functions, such as seeding oil within contours read from a GML file: o.seed_from_gml(o.test_data_folder() + "radarsat_oil_satellite_observation/RS2_20151116_002619_0127_SCNB_HH_SGF_433012_9730_12182143_Oil.gml", num_elements=2000) ====================================================================== (,
) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 41.405 seconds) .. _sphx_glr_download_gallery_example_seed_demonstration.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_seed_demonstration.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_seed_demonstration.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_