Skip to content

Commit

Permalink
Simplify inner for loop and use urllib
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonbb committed Apr 23, 2024
1 parent 48b4dee commit 3d676d6
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/kbmod/region_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

from astropy.table import Table

from urllib.parse import urlparse


def _chunked_data_ids(dataIds, chunk_size=200):
"""Helper function to yield successive chunk_size chunks from dataIds."""
Expand All @@ -18,8 +20,8 @@ def _chunked_data_ids(dataIds, chunk_size=200):


def _trim_uri(uri):
"""Trim the URI to remove the file:// prefix."""
return uri[7:]
"""Trim the URI to a more standardized output."""
return urlparse(uri).path


class RegionSearch:
Expand Down Expand Up @@ -405,16 +407,17 @@ def find_overlapping_coords(self, data=None, uncertainty_radius=30):
# with an index less than 'i'. So we only have to compute the separation
# distances for the coordinates that come after 'i'.
distances = coord.separation(all_ra_dec[i + 1 :]).to(u.arcsec).value
within_radius = (distances <= uncertainty_radius_as.value) & (distances > 0)
if any(within_radius):
# Choose the current index
overlapping_data_ids = [i]
# Add the indices of the other coordinates within the radius
for j in range(len(within_radius)):
if within_radius[j]:
# We add the indices of other coordinates within the radius,
# offset by our starting 'all_ra_dec' index of i + 1
overlapping_data_ids.append(i + 1 + j)

# Consider choosing the the current index.
overlapping_data_ids = [i]

for j in range(len(distances)):
if distances[j] <= uncertainty_radius_as.value:
# We add the indices of other coordinates within the radius,
# offset by our starting 'all_ra_dec' index of i + 1
overlapping_data_ids.append(i + 1 + j)
if len(overlapping_data_ids) > 1:
# Add our choice of overlapping set to our results.
processed_data_ids.update(overlapping_data_ids)
overlapping_sets.append(overlapping_data_ids)

Expand Down

0 comments on commit 3d676d6

Please sign in to comment.