Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions uxarray/grid/arcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def point_within_gca(pt_xyz, gca_a_xyz, gca_b_xyz):
raise ValueError(
"The input Great Circle Arc spans exactly 180 degrees, which can correspond to multiple planes. "
"Consider breaking the Great Circle Arc into two smaller arcs."
f"\npoint_within_gca(pt_xyz, gca_a_xyz, gca_b_xyz) got gca_a_xyz={gca_a_xyz}, gca_b_xyz={gca_b_xyz}, "
f"which are 180 degrees apart. (Was checking pt_xyz={pt_xyz}.)"
)

# 2. Verify if the point lies on the plane of the GCA
Expand Down Expand Up @@ -224,7 +226,8 @@ def extreme_gca_latitude(gca_cart, gca_lonlat, extreme_type):
"""
# Validate extreme_type
if (extreme_type != "max") and (extreme_type != "min"):
raise ValueError("extreme_type must be either 'max' or 'min'")
raise ValueError("Invalid extreme_type. Expected 'max' or 'min'.")
# (numba complains about f-strings, so don't put `extreme_type` value in message.)

# Extract the two points
n1 = gca_cart[0]
Expand Down Expand Up @@ -305,7 +308,8 @@ def extreme_gca_z(gca_cart, extreme_type):

# Validate extreme_type
if (extreme_type != "max") and (extreme_type != "min"):
raise ValueError("extreme_type must be either 'max' or 'min'")
raise ValueError("Invalid extreme_type. Expected 'max' or 'min'.")
# (numba complains about f-strings, so don't put `extreme_type` value in message.)

# Extract the two points
n1 = gca_cart[0]
Expand Down
8 changes: 6 additions & 2 deletions uxarray/grid/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def calculate_face_area(
dG, dW = get_tri_quadrature_dg(order)
is_gaussian = False
else:
raise ValueError("Invalid quadrature rule, specify gaussian or triangular")
raise ValueError(
"Invalid quadrature_rule. Expected 'triangular' or 'gaussian'."
) # (numba complains about f-strings, so don't put actual value in message.)

return _face_area_from_quadrature(
x, y, z, dG, dW, is_gaussian, latitude_adjusted_area
Expand Down Expand Up @@ -253,7 +255,9 @@ def _get_all_face_area_from_coords(
dG, dW = get_tri_quadrature_dg(order)
is_gaussian = False
else:
raise ValueError("Invalid quadrature rule, specify gaussian or triangular")
raise ValueError(
"Invalid quadrature_rule. Expected 'triangular' or 'gaussian'."
) # (numba complains about f-strings, so don't put actual value in message.)

# set initial area of each face to 0
area = np.zeros(n_face)
Expand Down
8 changes: 4 additions & 4 deletions uxarray/grid/bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def insert_pt_in_latlonbox(old_box, new_pt, is_lon_periodic=True):
else:
# Validate longitude point
if not np.isnan(lon_pt) and (lon_pt < 0.0 or lon_pt > 2.0 * np.pi):
raise ValueError("Longitude point out of range")
raise ValueError(f"Longitude point out of range (<0 or >2*pi): {lon_pt}")

# Check for pole points
is_pole_point = False
Expand Down Expand Up @@ -466,7 +466,7 @@ def insert_pt_in_latlonbox(old_box, new_pt, is_lon_periodic=True):
# Ensure widths are non-negative
if (d_width_a < 0.0) or (d_width_b < 0.0):
raise AssertionError(
"Logic error in longitude box width calculation"
"Logic error in longitude box width calculation: computed negative width"
)

# Choose the box with the smaller width
Expand All @@ -490,8 +490,8 @@ def insert_pt_in_latlonbox(old_box, new_pt, is_lon_periodic=True):

# Ensure widths are non-negative
if (d_width_a < 0.0) or (d_width_b < 0.0):
raise Exception(
"Logic error in longitude box width calculation"
raise AssertionError(
"Logic error in longitude box width calculation: computed negative width"
)

# Choose the box with the smaller width
Expand Down
6 changes: 4 additions & 2 deletions uxarray/grid/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,8 @@ def prepare_points(points, normalize):
x, y, z = _normalize_xyz(x, y, z)
else:
raise DimensionError(
"Points must be a sequence of length 2 (longitude, latitude) or 3 (x, y, z coordinates)."
"Expected len(points) == 2 (for longitude, latitude) or 3 (for x, y, z coordinates); "
f"got len(points)={len(points)}, in grid.coordinates.prepare_points"
)

return np.vstack([x, y, z]).T
Expand Down Expand Up @@ -811,7 +812,8 @@ def points_atleast_2d_xyz(points):
points_xyz = points
else:
raise DimensionError(
"Points are neither Cartesian (shape N x 3) nor Spherical (shape N x 2)."
"Expected points.shape == (N,2) or (N,3) for (lon, lat) or (x, y, z), "
f"respectively; got points.shape == {points.shape}."
)

return points_xyz
17 changes: 12 additions & 5 deletions uxarray/grid/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ def _grid_to_matplotlib_polycollection(
# Handle unsupported configuration: splitting periodic elements with projection
if periodic_elements == "split" and projection is not None:
raise ValueError(
"Explicitly projecting lines is not supported. Please pass in your projection "
"using the 'transform' parameter"
'Must provide `projection` when periodic_elements=="split" '
"while attempting to create polycollection, but got projection=None."
)

# Correct the central longitude and build polygon shells
Expand Down Expand Up @@ -717,6 +717,7 @@ def pole_point_inside_polygon(pole, face_edges_xyz, face_edges_lonlat):

if pole != 1 and pole != -1:
raise ValueError("Pole must be 1 (North) or -1 (South)")
# (numba complains about f-strings, so don't put `pole` value in message.)

# Define constants within the function
pole_point_xyz = np.empty(3, dtype=np.float64)
Expand Down Expand Up @@ -838,7 +839,11 @@ def pole_point_inside_polygon(pole, face_edges_xyz, face_edges_lonlat):
return ((north_intersections + south_intersections) % 2) != 0

else:
raise ValueError("Invalid pole point query.")
# (location will always be 1, -1, or 0 from _classify_polygon_location,
# so it should always be handled by cases above.)
raise AssertionError(
"Internal coding/implementation error: invalid `location`."
)


@njit(cache=True)
Expand Down Expand Up @@ -1272,8 +1277,10 @@ def barycentric_coordinates_cartesian(polygon_xyz, point_xyz):

return weights, nodes

# If the point doesn't reside in the polygon, raise an error
raise ValueError("Point does not reside in polygon")
raise ValueError(
"Point does not reside in polygon, during "
"barycentric_coordinates_cartesian(polygon_xyz, point_xyz)"
) # (can't do str(float) in numba --> can't include numbers here.)


@njit(cache=True)
Expand Down
Loading