@@ -54,7 +54,7 @@ def _xyz_to_lonlat_rad_no_norm(
5454 lon = np .arctan2 (y , x )
5555 lat = np .asin (z )
5656
57- # set longitude range to [0, pi]
57+ # set longitude range to [0, 2* pi]
5858 lon = np .mod (lon , 2 * np .pi )
5959
6060 z_mask = np .abs (z ) > 1.0 - ERROR_TOLERANCE
@@ -130,7 +130,7 @@ def _xyz_to_lonlat_rad(
130130 lon = np .arctan2 (y , x )
131131 lat = np .arcsin (z )
132132
133- # set longitude range to [0, pi]
133+ # set longitude range to [0, 2* pi]
134134 lon = np .mod (lon , 2 * np .pi )
135135
136136 z_mask = np .abs (z ) > 1.0 - ERROR_TOLERANCE
@@ -182,7 +182,7 @@ def _normalize_xyz(
182182 y : Union [np .ndarray , float ],
183183 z : Union [np .ndarray , float ],
184184) -> tuple [np .ndarray , np .ndarray , np .ndarray ]:
185- """Normalizes a set of Cartesiain coordinates."""
185+ """Normalizes a set of Cartesian coordinates."""
186186 denom = np .linalg .norm (
187187 np .asarray (np .array ([x , y , z ]), dtype = np .float64 ), ord = 2 , axis = 0
188188 )
@@ -699,155 +699,6 @@ def _set_desired_longitude_range(uxgrid):
699699 uxgrid ._ds [lon_name ] = (uxgrid ._ds [lon_name ] + 180 ) % 360 - 180
700700
701701
702- def _xyz_to_lonlat_rad (
703- x : Union [np .ndarray , float ],
704- y : Union [np .ndarray , float ],
705- z : Union [np .ndarray , float ],
706- normalize : bool = True ,
707- ) -> tuple [np .ndarray , np .ndarray , np .ndarray ]:
708- """Converts Cartesian x, y, z coordinates in Spherical latitude and
709- longitude coordinates in degrees.
710-
711- Parameters
712- ----------
713- x : Union[np.ndarray, float]
714- Cartesian x coordinates
715- y: Union[np.ndarray, float]
716- Cartesiain y coordinates
717- z: Union[np.ndarray, float]
718- Cartesian z coordinates
719- normalize: bool
720- Flag to select whether to normalize the coordinates
721-
722- Returns
723- -------
724- lon : Union[np.ndarray, float]
725- Longitude in radians
726- lat: Union[np.ndarray, float]
727- Latitude in radians
728- """
729-
730- if normalize :
731- x , y , z = _normalize_xyz (x , y , z )
732- denom = np .abs (x * x + y * y + z * z )
733- x /= denom
734- y /= denom
735- z /= denom
736-
737- lon = np .arctan2 (y , x , dtype = np .float64 )
738- lat = np .arcsin (z , dtype = np .float64 )
739-
740- # set longitude range to [0, pi]
741- lon = np .mod (lon , 2 * np .pi )
742-
743- z_mask = np .abs (z ) > 1.0 - ERROR_TOLERANCE
744-
745- lat = np .where (z_mask , np .sign (z ) * np .pi / 2 , lat )
746- lon = np .where (z_mask , 0.0 , lon )
747-
748- return lon , lat
749-
750-
751- @njit (cache = True )
752- def _xyz_to_lonlat_rad_no_norm (
753- x : Union [np .ndarray , float ],
754- y : Union [np .ndarray , float ],
755- z : Union [np .ndarray , float ],
756- ):
757- """Converts a Cartesian x,y,z coordinates into Spherical latitude and
758- longitude without normalization, decorated with Numba.
759-
760- Parameters
761- ----------
762- x : float
763- Cartesian x coordinate
764- y: float
765- Cartesiain y coordinate
766- z: float
767- Cartesian z coordinate
768-
769-
770- Returns
771- -------
772- lon : float
773- Longitude in radians
774- lat: float
775- Latitude in radians
776- """
777-
778- lon = np .arctan2 (y , x )
779- lat = np .asin (z )
780-
781- # set longitude range to [0, pi]
782- lon = np .mod (lon , 2 * np .pi )
783-
784- z_mask = np .abs (z ) > 1.0 - ERROR_TOLERANCE
785-
786- lat = np .where (z_mask , np .sign (z ) * np .pi / 2 , lat )
787- lon = np .where (z_mask , 0.0 , lon )
788-
789- return lon , lat
790-
791-
792- @njit (cache = True )
793- def _lonlat_rad_to_xyz (
794- lon : Union [np .ndarray , float ],
795- lat : Union [np .ndarray , float ],
796- ) -> tuple [np .ndarray , np .ndarray , np .ndarray ]:
797- """Converts Spherical lon and lat coordinates into Cartesian x, y, z
798- coordinates."""
799- x = np .cos (lon ) * np .cos (lat )
800- y = np .sin (lon ) * np .cos (lat )
801- z = np .sin (lat )
802-
803- return x , y , z
804-
805-
806- def _xyz_to_lonlat_deg (
807- x : Union [np .ndarray , float ],
808- y : Union [np .ndarray , float ],
809- z : Union [np .ndarray , float ],
810- normalize : bool = True ,
811- ) -> tuple [np .ndarray , np .ndarray , np .ndarray ]:
812- """Converts Cartesian x, y, z coordinates in Spherical latitude and
813- longitude coordinates in degrees.
814-
815- Parameters
816- ----------
817- x : Union[np.ndarray, float]
818- Cartesian x coordinates
819- y: Union[np.ndarray, float]
820- Cartesiain y coordinates
821- z: Union[np.ndarray, float]
822- Cartesian z coordinates
823- normalize: bool
824- Flag to select whether to normalize the coordinates
825-
826- Returns
827- -------
828- lon : Union[np.ndarray, float]
829- Longitude in degrees
830- lat: Union[np.ndarray, float]
831- Latitude in degrees
832- """
833- lon_rad , lat_rad = _xyz_to_lonlat_rad (x , y , z , normalize = normalize )
834-
835- lon = np .rad2deg (lon_rad )
836- lat = np .rad2deg (lat_rad )
837-
838- lon = (lon + 180 ) % 360 - 180
839- return lon , lat
840-
841-
842- @njit (cache = True )
843- def _normalize_xyz_scalar (x : float , y : float , z : float ):
844- denom = np .linalg .norm (np .asarray (np .array ([x , y , z ]), dtype = np .float64 ), ord = 2 )
845- x_norm = x / denom
846- y_norm = y / denom
847- z_norm = z / denom
848- return x_norm , y_norm , z_norm
849-
850-
851702def prepare_points (points , normalize ):
852703 """Prepares points for use with ``Grid.from_points()``"""
853704 if len (points ) == 2 :
0 commit comments