Commit d03a02bd authored by Bauck, Kirsten (Contractor) Hailey's avatar Bauck, Kirsten (Contractor) Hailey Committed by Laura, Jason R.
Browse files

small update for math domain error

parent 5de8577f
Loading
Loading
Loading
Loading
+1 −0
Changes for CHANGELOG.md: 1 added line, 0 removed lines.
Original line number Original line Diff line number Diff line
@@ -45,6 +45,7 @@ release.
- Finding points in polar areas that avoids dividing by zero errors
- Finding points in polar areas that avoids dividing by zero errors
- Small errors in `overlap.py` to get overlap function working.
- Small errors in `overlap.py` to get overlap function working.
- Raise an exception if the shear is too high when trying to find the baseline affine
- Raise an exception if the shear is too high when trying to find the baseline affine
- Catch divide by 0 errors when getting the number of points to place in `centroids.py`


## [1.1.0]
## [1.1.0]
### Added
### Added
+7 −3
Changes for autocnet/spatial/centroids.py: 7 added lines, 3 removed lines.
Original line number Original line Diff line number Diff line
@@ -45,7 +45,12 @@ def get_number_of_points(target_distance_km, latitude, radius):
    target_distance_rad = target_distance_km / radius
    target_distance_rad = target_distance_km / radius


    # Calculate longitudal distance between two points
    # Calculate longitudal distance between two points
    try:
        longitudinal_distance = 2 * math.asin(math.sqrt(math.sin(target_distance_rad/2)**2 / (math.cos(math.radians(latitude))**2)))
        longitudinal_distance = 2 * math.asin(math.sqrt(math.sin(target_distance_rad/2)**2 / (math.cos(math.radians(latitude))**2)))
    # If given latitude is too close to 90 or 270, taking the cosine of it will give 0, so will then have a divide by 0 error.
    except:
        log.info(f"Math domain error at {latitude}, skipping")
        return None


    # Calculate the circumference of the planetary body at the given latitude
    # Calculate the circumference of the planetary body at the given latitude
    body_circumference = 2 * math.pi * radius * math.cos(math.radians(latitude))
    body_circumference = 2 * math.pi * radius * math.cos(math.radians(latitude))
@@ -126,15 +131,14 @@ def find_points_in_centroids(radius,
    if polygon:
    if polygon:
        _, min_lat, _, max_lat = polygon.bounds
        _, min_lat, _, max_lat = polygon.bounds
    latitude_intervals = np.arange(max_lat, min_lat, latitude_decriment)
    latitude_intervals = np.arange(max_lat, min_lat, latitude_decriment)
    # Remove intervals that cause divide by 0 errors
    latitude_intervals = latitude_intervals[latitude_intervals != 270.0]
    latitude_intervals = latitude_intervals[latitude_intervals != 90.0]
    points=[]
    points=[]


    # Itterate through each latitude
    # Itterate through each latitude
    for lat in latitude_intervals:
    for lat in latitude_intervals:
        # Calculate the number of points needed to space points along a latitude line every __km
        # Calculate the number of points needed to space points along a latitude line every __km
        num_points = get_number_of_points(target_distance_in_km, lat, radius)
        num_points = get_number_of_points(target_distance_in_km, lat, radius)
        if not num_points:
            continue
        p1 = (longitude_min, lat)
        p1 = (longitude_min, lat)
        p2 = (longitude_max, lat)
        p2 = (longitude_max, lat)
        # Create a list of points for latitude lines
        # Create a list of points for latitude lines