@@ -128,8 +128,38 @@ def constant_lon_intersections_no_extreme(lon, edge_node_x, edge_node_y, n_edge)
128128 return np .unique (intersecting_edges )
129129
130130
131+ # @njit(cache=True)
132+ # def constant_lat_intersections_face_bounds(lat, face_bounds_lat):
133+ # """Identifies the candidate faces on a grid that intersect with a given
134+ # constant latitude.
135+ #
136+ # This function checks whether the specified latitude, `lat`, in degrees lies within
137+ # the latitude bounds of grid faces, defined by `face_min_lat_rad` and `face_max_lat_rad`,
138+ # which are given in radians. The function returns the indices of the faces where the
139+ # latitude is within these bounds.
140+ #
141+ # Parameters
142+ # ----------
143+ # lat : float
144+ # The latitude in degrees for which to find intersecting faces.
145+ # TODO:
146+ #
147+ # Returns
148+ # -------
149+ # candidate_faces : numpy.ndarray
150+ # A 1D array containing the indices of the faces that intersect with the given latitude.
151+ # """
152+ #
153+ # face_bounds_lat_min = face_bounds_lat[:, 0]
154+ # face_bounds_lat_max = face_bounds_lat[:, 1]
155+ #
156+ # within_bounds = (face_bounds_lat_min <= lat) & (face_bounds_lat_max >= lat)
157+ # candidate_faces = np.where(within_bounds)[0]
158+ # return
159+
160+
131161@njit (cache = True )
132- def constant_lat_intersections_face_bounds (lat , face_bounds_lat ):
162+ def constant_lat_intersections_face_bounds (lat , bounds ):
133163 """Identifies the candidate faces on a grid that intersect with a given
134164 constant latitude.
135165
@@ -142,19 +172,33 @@ def constant_lat_intersections_face_bounds(lat, face_bounds_lat):
142172 ----------
143173 lat : float
144174 The latitude in degrees for which to find intersecting faces.
145- TODO:
175+ bounds: todo
176+ todo
146177
147178 Returns
148179 -------
149180 candidate_faces : numpy.ndarray
150181 A 1D array containing the indices of the faces that intersect with the given latitude.
151182 """
152183
153- face_bounds_lat_min = face_bounds_lat [:, 0 ]
154- face_bounds_lat_max = face_bounds_lat [:, 1 ]
184+ lat_rad = np .deg2rad (lat )
185+
186+ # Check if the constant latitude is within the range of [-90, 90]
187+ if lat_rad < - np .pi or lat_rad > np .pi :
188+ raise ValueError (
189+ "The constant latitude must be within the range of [-90, 90] degree."
190+ )
155191
156- within_bounds = (face_bounds_lat_min <= lat ) & (face_bounds_lat_max >= lat )
192+ # Extract the latitude bounds
193+ lat_bounds_min = bounds [:, 0 , 0 ] # Minimum latitude bound
194+ lat_bounds_max = bounds [:, 0 , 1 ] # Maximum latitude bound
195+
196+ # Check if the constant latitude is within the bounds of each face
197+ within_bounds = (lat_bounds_min <= lat_rad ) & (lat_bounds_max >= lat_rad )
198+
199+ # Get the indices of faces where the condition is True
157200 candidate_faces = np .where (within_bounds )[0 ]
201+
158202 return candidate_faces
159203
160204
0 commit comments