@@ -215,19 +215,20 @@ def _get_zonal_face_interval(
215215 face_lon_bound_left , face_lon_bound_right = face_latlon_bound [1 ]
216216
217217 try :
218- unique_intersections , pt_lon_min , pt_lon_max = (
218+
219+ unique_intersections_cart ,unique_intersection_lonlat , pt_lon_min , pt_lon_max = (
219220 _get_faces_constLat_intersection_info (
220221 face_edges_cart , latitude_cart , is_GCA_list , is_latlonface
221222 )
222223 )
223224
224225 # If there's exactly one intersection, the face is only "touched"
225- if len (unique_intersections ) == 1 :
226+ if len (unique_intersections_cart ) == 1 :
226227 return pl .DataFrame ({"start" : [0.0 ], "end" : [0.0 ]})
227228
228- # Convert intersection points to (lon, lat) in radians
229+ # Extract unique longitudes from intersection points
229230 longitudes = np .array (
230- [_xyz_to_lonlat_rad ( * pt . tolist ()) [0 ] for pt in unique_intersections ]
231+ [pt [0 ] for pt in unique_intersection_lonlat ]
231232 )
232233
233234 # Handle special wrap-around cases (crossing anti-meridian, etc.)
@@ -378,7 +379,8 @@ def _get_faces_constLat_intersection_info(
378379 -------
379380 tuple
380381 A tuple containing:
381- - intersections_pts_list_cart (list): A list of intersection points where each point is where an edge intersects with the latitude.
382+ - intersections_pts_list_cart (list): A list of intersection points in cartesian where each point is where an edge intersects with the latitude.
383+ - intersections_pts_list_lon (list): A list of intersection points in lonlat where each point is where an edge intersects with the latitude.
382384 - pt_lon_min (float): The min longnitude of the interseted intercal in radian if any; otherwise, None..
383385 - pt_lon_max (float): The max longnitude of the interseted intercal in radian, if any; otherwise, None.
384386 """
@@ -418,28 +420,30 @@ def _get_faces_constLat_intersection_info(
418420 intersections_pts_list_cart .append (intersections [0 ])
419421
420422 # Find the unique intersection points
421- unique_intersections = np .unique (intersections_pts_list_cart , axis = 0 )
423+ unique_intersections_cart = np .unique (intersections_pts_list_cart , axis = 0 )
422424
423- if len (unique_intersections ) == 2 :
425+ if len (unique_intersections_cart ) == 2 :
424426 unique_intersection_lonlat = np .array (
425- [_xyz_to_lonlat_rad (pt [0 ], pt [1 ], pt [2 ]) for pt in unique_intersections ]
427+ [_xyz_to_lonlat_rad (pt [0 ], pt [1 ], pt [2 ]) for pt in unique_intersections_cart ]
426428 )
427429
428430 sorted_lonlat = np .sort (unique_intersection_lonlat , axis = 0 )
429431 pt_lon_min , pt_lon_max = sorted_lonlat [:, 0 ]
430- return unique_intersections , pt_lon_min , pt_lon_max
431- elif len (unique_intersections ) == 1 :
432- return unique_intersections , None , None
433- elif len (unique_intersections ) != 0 and len (unique_intersections ) != 1 :
432+ return unique_intersections_cart ,unique_intersection_lonlat , pt_lon_min , pt_lon_max
433+ elif len (unique_intersections_cart ) == 1 :
434+ return unique_intersections_cart , np .array (_xyz_to_lonlat_rad (unique_intersections_cart [0 ][0 ],
435+ unique_intersections_cart [0 ][1 ],
436+ unique_intersections_cart [0 ][2 ])), None , None
437+ elif len (unique_intersections_cart ) != 0 and len (unique_intersections_cart ) != 1 :
434438 # If the unique intersections numbers is larger than n_edges * 2, then it means the face is concave
435- if len (unique_intersections ) > len (valid_edges ) * 2 :
439+ if len (unique_intersections_cart ) > len (valid_edges ) * 2 :
436440 raise ValueError (
437441 "UXarray doesn't support concave face with intersections points as currently, please modify your grids accordingly"
438442 )
439443 else :
440444 # Now return all the intersections points and the pt_lon_min, pt_lon_max
441445 unique_intersection_lonlat = np .array (
442- [_xyz_to_lonlat_rad (pt [0 ], pt [1 ], pt [2 ]) for pt in unique_intersections ]
446+ [_xyz_to_lonlat_rad (pt [0 ], pt [1 ], pt [2 ]) for pt in unique_intersections_cart ]
443447 )
444448
445449 sorted_lonlat = np .sort (unique_intersection_lonlat , axis = 0 )
@@ -449,8 +453,8 @@ def _get_faces_constLat_intersection_info(
449453 np .max (sorted_lonlat [:, 0 ]),
450454 )
451455
452- return unique_intersections , pt_lon_min , pt_lon_max
453- elif len (unique_intersections ) == 0 :
456+ return unique_intersections_cart , unique_intersection_lonlat , pt_lon_min , pt_lon_max
457+ elif len (unique_intersections_cart ) == 0 :
454458 raise ValueError (
455459 "No intersections are found for the face, please make sure the build_latlon_box generates the correct results"
456460 )
0 commit comments