Commit 72f0b1d9 authored by Laura, Jason R.'s avatar Laura, Jason R.
Browse files

Merge branch 'Place_polar_points' into 'main'

Fix so correctly gets number of points without errors

See merge request astrogeology/autocnet!696
parents 34bafae9 abe89c6d
Loading
Loading
Loading
Loading
+1 −1
Changes for CHANGELOG.md: 1 added line, 1 removed line.
Original line number Original line Diff line number Diff line
@@ -45,7 +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`
- Correctly find the number of points without producing errors in `centroids.py`


## [1.1.0]
## [1.1.0]
### Added
### Added
+10 −20
Changes for autocnet/spatial/centroids.py: 10 added lines, 20 removed lines.
Original line number Original line Diff line number Diff line
@@ -27,36 +27,26 @@ def get_number_of_points(target_distance_km, latitude, radius):
    Parameters
    Parameters
    ___________
    ___________
    target_distance_km : int
    target_distance_km : int
        The target distance to maintin between points
        The target distance to maintin between points in km


    latitude : int
    latitude : int
        the latitude where points are needed
        the latitude where points are needed in degrees
    
    
    radius : int
    radius : int
        radius of the planetary body
        radius of the planetary body in km
    
    
    Returns
    Returns
    _______
    _______
    num_points : int
    num_points : int
        Number of points needed to maintin target distance
        Number of points needed to maintin target distance at specified latitude
    """
    """


    # Convert to radians
    # Convert latitude to radians
    target_distance_rad = target_distance_km / radius
    lat_rad = math.radians(latitude)

    # Find the circumference of the planetary body
    # Calculate longitudal distance between two points
    circumference = 2 * math.pi * radius * math.cos(lat_rad)
    try:
    # Calculate the number of points
        longitudinal_distance = 2 * math.asin(math.sqrt(math.sin(target_distance_rad/2)**2 / (math.cos(math.radians(latitude))**2)))
    num_points = int(circumference/target_distance_km)
    # 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
    body_circumference = 2 * math.pi * radius * math.cos(math.radians(latitude))

    # Calculate points needed
    num_points = int(body_circumference / longitudinal_distance) + 1


    return num_points
    return num_points