Skip to content

Commit

Permalink
clean up docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc2 committed Jan 17, 2025
1 parent ef14dad commit ea145ad
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
25 changes: 23 additions & 2 deletions uxarray/grid/arcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,28 @@ def extreme_gca_latitude(gca_cart, gca_lonlat, extreme_type):

@njit(cache=True)
def extreme_gca_z(gca_cart, extreme_type):
"""
Calculate the maximum or minimum latitude of a great circle arc defined
by two 3D points.
Parameters
----------
gca_cart : numpy.ndarray
An array containing two 3D vectors that define a great circle arc.
extreme_type : str
The type of extreme latitude to calculate. Must be either 'max' or 'min'.
Returns
-------
float
The maximum or minimum latitude of the great circle arc in radians.
Raises
------
ValueError
If `extreme_type` is not 'max' or 'min'.
"""
# Validate extreme_type
if (extreme_type != "max") and (extreme_type != "min"):
raise ValueError("extreme_type must be either 'max' or 'min'")
Expand Down Expand Up @@ -313,7 +335,7 @@ def extreme_gca_z(gca_cart, extreme_type):
# Compute the intermediate point on the GCA
node3 = (1.0 - d_a_max) * n1 + d_a_max * n2

# Normalize the intermediate point TODO:
# Normalize the intermediate point
x, y, z = _normalize_xyz_scalar(node3[0], node3[1], node3[2])
node3_normalized = np.empty(3)
node3_normalized[0] = x
Expand All @@ -322,7 +344,6 @@ def extreme_gca_z(gca_cart, extreme_type):

d_z = clip_scalar(node3_normalized[2], -1.0, 1.0)

# TODO: # Return the extreme latitude
if extreme_type == "max":
return max3(d_z, z_n1, z_n2)
else:
Expand Down
4 changes: 3 additions & 1 deletion uxarray/grid/integrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@ def _get_faces_constLat_intersection_info(
)


# Only handles overlaps near the equator
def get_non_conservative_zonal_face_weights_at_const_lat(
face_edges_xyz: np.ndarray,
face_bounds,
n_edges_per_face: np.ndarray,
z: float,
):
# TODO: edge case near the equator.
"""Computes the weight of each face at a constant latitude."""
# 0) Use accurate method at th equator
if np.isclose(z, 0.0):
return get_non_conservative_zonal_face_weights_at_const_lat_overlap(
face_edges_xyz, z, face_bounds
Expand Down
16 changes: 15 additions & 1 deletion uxarray/grid/intersections.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,19 @@ def gca_gca_intersection(gca_a_xyz, gca_b_xyz):

@njit(cache=True)
def gca_const_lat_intersection(gca_cart, const_z):
"""Calculate the intersection point(s) of a Great Circle Arc (GCA) and a
constant latitude line in a Cartesian coordinate system.
Parameters
----------
gca_cart : [2, 3] np.ndarray Cartesian coordinates of the two end points GCA.
const_z : float
The constant latitude represented in cartesian of the latitude line.
Returns
-------
np.ndarray
Cartesian coordinates of the intersection point(s) the shape is [2, 3].
"""
res = np.empty((2, 3))
res.fill(np.nan)

Expand Down Expand Up @@ -395,7 +408,6 @@ def gca_const_lat_intersection(gca_cart, const_z):

const_lat_rad = np.arcsin(const_z)

# TODO:
# Check if the constant latitude is within the GCA range
# Because the constant latitude is calculated from np.sin, which may have some floating-point error,
if not in_between(lat_min, const_lat_rad, lat_max):
Expand Down Expand Up @@ -430,6 +442,8 @@ def gca_const_lat_intersection(gca_cart, const_z):

@njit(cache=True)
def get_number_of_intersections(arr):
"""Helper that detrmines the number of intersections
for the output of gca_const_lat_intersection."""
row1_is_nan = np.all(np.isnan(arr[0]))
row2_is_nan = np.all(np.isnan(arr[1]))

Expand Down
5 changes: 0 additions & 5 deletions uxarray/grid/neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,11 +915,6 @@ def _construct_edge_face_distances(node_lon, node_lat, edge_faces):
return edge_face_distances


def euclidean_distance(p1, p2):
"""Calculate Euclidean distance between two points represented as NumPy arrays."""
return np.sqrt(np.sum((p1 - p2) ** 2))


class PointsAlongGCA:
def __init__(self):
# List of all unique points as NumPy arrays
Expand Down

0 comments on commit ea145ad

Please sign in to comment.