Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
favyen2 committed Dec 20, 2024
1 parent 9c825c1 commit 3c0fb7f
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions rslp/utils/filter.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Filters for vessel detection projects."""

import functools
import json

import numpy as np
import requests
from upath import UPath


class Filter:
Expand All @@ -30,22 +31,17 @@ def should_filter(self, lat: float, lon: float) -> bool:


@functools.cache
def get_infra_latlons(infra_url: str) -> tuple[np.ndarray, np.ndarray]:
def get_infra_latlons(infra_path: UPath) -> tuple[np.ndarray, np.ndarray]:
"""Fetch and cache the infrastructure latitudes and longitudes.
Args:
infra_url: URL to the marine infrastructure GeoJSON file.
infra_path: path to the marine infrastructure GeoJSON file.
Returns:
A tuple of arrays: (latitudes, longitudes).
"""
try:
# Read the geojson data from the URL.
response = requests.get(infra_url, timeout=10)
response.raise_for_status() # Raise an error for bad responses
geojson_data = response.json()
except requests.RequestException as e:
raise RuntimeError(f"Failed to fetch infrastructure data: {e}")
with infra_path.open("r") as f:
geojson_data = json.load(f)

lats = np.array(
[feature["geometry"]["coordinates"][1] for feature in geojson_data["features"]]
Expand All @@ -72,7 +68,7 @@ def __init__(
infra_distance_threshold: distance threshold for marine infrastructure.
"""
self.infra_url = infra_url
self.infra_latlons = get_infra_latlons(self.infra_url)
self.infra_latlons = get_infra_latlons(UPath(self.infra_url))
self.infra_distance_threshold = infra_distance_threshold

def _get_haversine_distances(
Expand Down

0 comments on commit 3c0fb7f

Please sign in to comment.