@@ -770,20 +770,39 @@ def azimuth_to_next(self):
770
770
return azimuth_forward
771
771
772
772
def velocity_components (self ):
773
- """Returns velocity components [m/s] from one position to the next.
773
+ """
774
+ Calculate velocity components [m/s] from one position to the next.
774
775
775
- Last time is repeated for last position (which has no next position)
776
+ The last time step is repeated for the last position (which has no next position).
776
777
777
778
Returns
778
779
-------
779
- (u, v) : array_like
780
- East and north components of velocities at given position along trajectories.
780
+ u : xarray.DataArray
781
+ Eastward velocity component [m/s] at each position along trajectories.
782
+ Dimensions: same as the dataset's trajectory and observation dimensions.
783
+ v : xarray.DataArray
784
+ Northward velocity component [m/s] at each position along trajectories.
785
+ Dimensions: same as the dataset's trajectory and observation dimensions.
786
+
787
+ See Also
788
+ --------
789
+ speed : Calculate the speed along trajectories.
790
+ azimuth_to_next : Calculate the azimuth (direction) to the next position.
781
791
"""
782
792
speed = self .speed ()
783
793
azimuth = self .azimuth_to_next ()
784
794
785
- u = speed * np .cos (azimuth )
786
- v = speed * np .sin (azimuth )
795
+ # Calculate velocity components
796
+ u = speed * np .cos (np .radians (azimuth ))
797
+ v = speed * np .sin (np .radians (azimuth ))
798
+
799
+ # Assign names and attributes
800
+ u .name = "u_velocity"
801
+ v .name = "v_velocity"
802
+ u .attrs ["units" ] = "m/s"
803
+ v .attrs ["units" ] = "m/s"
804
+ u .attrs ["description" ] = "Eastward velocity component"
805
+ v .attrs ["description" ] = "Northward velocity component"
787
806
788
807
return u , v
789
808
0 commit comments