.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/example_model_along_trajectory.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_model_along_trajectory.py: Read variables from a model along the trajectories of drifters. ============================================================================= .. GENERATED FROM PYTHON SOURCE LINES 5-13 .. code-block:: Python import xarray as xr import numpy as np import cf_xarray as _ import pyproj import trajan as ta import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 14-15 Open drifter dataset from a CSV file .. GENERATED FROM PYTHON SOURCE LINES 15-22 .. code-block:: Python ds = ta.read_csv('bug05_pos.csv.xz', lon='Longitude', lat='Latitude', time='Time', name='Device') print(ds) .. rst-class:: sphx-glr-script-out .. code-block:: none 2024-10-31 20:48:49 fv-az1024-670 trajan.accessor[2149] DEBUG Detecting time-dimension for "obs".. 2024-10-31 20:48:49 fv-az1024-670 trajan.accessor[2149] DEBUG Detected obs-dim: obs, detected time-dim: time. 2024-10-31 20:48:49 fv-az1024-670 trajan.accessor[2149] DEBUG Detected un-structured (2D) trajectory dataset 2024-10-31 20:48:49 fv-az1024-670 trajan.traj2d[2149] DEBUG Condensing 844 observations. 2024-10-31 20:48:49 fv-az1024-670 trajan.traj2d[2149] DEBUG Condensed observations from: 844 to 844 2024-10-31 20:48:49 fv-az1024-670 trajan.accessor[2149] DEBUG Detecting time-dimension for "obs".. 2024-10-31 20:48:49 fv-az1024-670 trajan.accessor[2149] DEBUG Detected obs-dim: obs, detected time-dim: time. 2024-10-31 20:48:49 fv-az1024-670 trajan.accessor[2149] DEBUG Detected un-structured (2D) trajectory dataset 2024-10-31 20:48:49 fv-az1024-670 trajan.traj[2149] DEBUG No grid-mapping specified, checking if coordinates are lon/lat.. 2024-10-31 20:48:49 fv-az1024-670 trajan.traj[2149] DEBUG No grid-mapping specified, checking if coordinates are lon/lat.. 2024-10-31 20:48:49 fv-az1024-670 trajan.traj[2149] DEBUG No grid-mapping specified, checking if coordinates are lon/lat.. 2024-10-31 20:48:49 fv-az1024-670 trajan.traj[2149] DEBUG No grid-mapping specified, checking if coordinates are lon/lat.. Size: 27kB Dimensions: (trajectory: 1, obs: 844) Coordinates: * trajectory (trajectory) Size: 6kB Dimensions: (trajectory: 1, time: 239) Coordinates: * time (time) datetime64[ns] 2kB 2022-05-10T13:00:00 ... 2022-05-20T... * trajectory (trajectory) `_ for more details. .. GENERATED FROM PYTHON SOURCE LINES 47-50 .. code-block:: Python tx = xr.DataArray(tx, dims=['trajectory', 'time']) ty = xr.DataArray(ty, dims=['trajectory', 'time']) .. GENERATED FROM PYTHON SOURCE LINES 51-52 Extract the values of a variable for the trajectory .. GENERATED FROM PYTHON SOURCE LINES 52-58 .. code-block:: Python temp = nk.isel(depth=0).sel(time=ds.time, X=tx, Y=ty, method='nearest').temperature print(temp) .. rst-class:: sphx-glr-script-out .. code-block:: none Size: 956B [239 values with dtype=float32] Coordinates: X (trajectory, time) float64 2kB 3.416e+05 3.416e+05 ... 3.464e+05 Y (trajectory, time) float64 2kB 4.344e+05 4.344e+05 ... 4.416e+05 depth float64 8B 0.0 * time (time) datetime64[ns] 2kB 2022-05-10T13:00:00 ... 2022-05-20T11:... lat (trajectory, time) float64 2kB 60.38 60.38 60.38 ... 60.44 60.45 lon (trajectory, time) float64 2kB 5.33 5.33 5.33 ... 5.243 5.243 5.249 Dimensions without coordinates: trajectory Attributes: units: Celsius time: ocean_time grid: grid location: face field: temperature, scalar, series grid_mapping: projection_stere long_name: Sea water potential temperature standard_name: sea_water_potential_temperature _ChunkSizes: [ 1 1 17 2602] .. GENERATED FROM PYTHON SOURCE LINES 59-60 Notice that the `lat` and `lon` variables from Norkyst match the original `lat` and `lon` from the dataset. .. GENERATED FROM PYTHON SOURCE LINES 60-64 .. code-block:: Python plt.figure() temp.plot() plt.show() .. image-sg:: /gallery/images/sphx_glr_example_model_along_trajectory_001.png :alt: depth = 0.0 [m] :srcset: /gallery/images/sphx_glr_example_model_along_trajectory_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 22.442 seconds) .. _sphx_glr_download_gallery_example_model_along_trajectory.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_model_along_trajectory.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_model_along_trajectory.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_model_along_trajectory.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_