Commit fa9fc2fa authored by Joseph Siddons's avatar Joseph Siddons
Browse files

Merge branch 'typing-3.9' into 'main'

Compatibility with python 3.9

See merge request nocsurfaceprocesses/geospatialtools!11
parents 2818c35d c6b57bfb
...@@ -4,6 +4,7 @@ navigational information to DataFrames. ...@@ -4,6 +4,7 @@ navigational information to DataFrames.
""" """
from math import acos, asin, atan2, cos, sin, degrees, radians, sqrt from math import acos, asin, atan2, cos, sin, degrees, radians, sqrt
from typing import Tuple
def gcd_slc( def gcd_slc(
...@@ -124,7 +125,7 @@ def bearing( ...@@ -124,7 +125,7 @@ def bearing(
def destination( def destination(
lon: float, lat: float, bearing: float, distance: float lon: float, lat: float, bearing: float, distance: float
) -> tuple[float, float]: ) -> Tuple[float, float]:
""" """
Compute destination of a great circle path. Compute destination of a great circle path.
...@@ -173,7 +174,7 @@ def midpoint( ...@@ -173,7 +174,7 @@ def midpoint(
lat0: float, lat0: float,
lon1: float, lon1: float,
lat1: float, lat1: float,
) -> tuple[float, float]: ) -> Tuple[float, float]:
""" """
Compute the midpoint of a great circle track Compute the midpoint of a great circle track
......
...@@ -5,6 +5,7 @@ Useful tool for quickly searching for nearest neighbours. ...@@ -5,6 +5,7 @@ Useful tool for quickly searching for nearest neighbours.
from . import Record from . import Record
from numpy import inf from numpy import inf
from typing import List, Optional, Tuple
class KDTree: class KDTree:
...@@ -33,7 +34,7 @@ class KDTree: ...@@ -33,7 +34,7 @@ class KDTree:
""" """
def __init__( def __init__(
self, points: list[Record], depth: int = 0, max_depth: int = 20 self, points: List[Record], depth: int = 0, max_depth: int = 20
) -> None: ) -> None:
self.depth = depth self.depth = depth
n_points = len(points) n_points = len(points)
...@@ -110,7 +111,7 @@ class KDTree: ...@@ -110,7 +111,7 @@ class KDTree:
return True return True
return False return False
def query(self, point) -> tuple[list[Record], float]: def query(self, point) -> Tuple[List[Record], float]:
"""Find the nearest Record within the KDTree to a query Record""" """Find the nearest Record within the KDTree to a query Record"""
if point.lon < 0: if point.lon < 0:
point2 = Record(point.lon + 360, point.lat, fix_lon=False) point2 = Record(point.lon + 360, point.lat, fix_lon=False)
...@@ -127,9 +128,9 @@ class KDTree: ...@@ -127,9 +128,9 @@ class KDTree:
def _query( def _query(
self, self,
point: Record, point: Record,
current_best: list[Record] | None = None, current_best: Optional[List[Record]] = None,
best_distance: float = inf, best_distance: float = inf,
) -> tuple[list[Record], float]: ) -> Tuple[List[Record], float]:
if current_best is None: if current_best is None:
current_best = list() current_best = list()
if not self.split: if not self.split:
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
from numpy import argmin from numpy import argmin
from bisect import bisect from bisect import bisect
from typing import TypeVar from typing import List, TypeVar, Union
from datetime import date, datetime from datetime import date, datetime
from warnings import warn from warnings import warn
...@@ -22,7 +22,7 @@ class SortedError(Exception): ...@@ -22,7 +22,7 @@ class SortedError(Exception):
pass pass
def _find_nearest(vals: list[Numeric], test: Numeric) -> int: def _find_nearest(vals: List[Numeric], test: Numeric) -> int:
i = bisect(vals, test) # Position that test would be inserted i = bisect(vals, test) # Position that test would be inserted
# Handle edges # Handle edges
...@@ -36,10 +36,10 @@ def _find_nearest(vals: list[Numeric], test: Numeric) -> int: ...@@ -36,10 +36,10 @@ def _find_nearest(vals: list[Numeric], test: Numeric) -> int:
def find_nearest( def find_nearest(
vals: list[Numeric], vals: List[Numeric],
test: list[Numeric] | Numeric, test: Union[List[Numeric], Numeric],
check_sorted: bool = True, check_sorted: bool = True,
) -> list[int] | int: ) -> Union[List[int], int]:
""" """
Find the nearest value in a list of values for each test value. Find the nearest value in a list of values for each test value.
......
from dataclasses import dataclass from dataclasses import dataclass
from typing import List, Optional
import datetime import datetime
from .distance_metrics import haversine, destination from .distance_metrics import haversine, destination
from .utils import LatitudeError, DateWarning from .utils import LatitudeError, DateWarning
...@@ -45,7 +46,7 @@ class SpaceTimeRecord: ...@@ -45,7 +46,7 @@ class SpaceTimeRecord:
lon: float, lon: float,
lat: float, lat: float,
datetime: datetime.datetime, datetime: datetime.datetime,
uid: str | None = None, uid: Optional[str] = None,
fix_lon: bool = True, fix_lon: bool = True,
**data, **data,
) -> None: ) -> None:
...@@ -80,7 +81,7 @@ class SpaceTimeRecord: ...@@ -80,7 +81,7 @@ class SpaceTimeRecord:
) )
class SpaceTimeRecords(list[SpaceTimeRecord]): class SpaceTimeRecords(List[SpaceTimeRecord]):
"""List of SpaceTimeRecords""" """List of SpaceTimeRecords"""
...@@ -402,7 +403,7 @@ class OctTree: ...@@ -402,7 +403,7 @@ class OctTree:
boundary: SpaceTimeRectangle, boundary: SpaceTimeRectangle,
capacity: int = 5, capacity: int = 5,
depth: int = 0, depth: int = 0,
max_depth: int | None = None, max_depth: Optional[int] = None,
) -> None: ) -> None:
self.boundary = boundary self.boundary = boundary
self.capacity = capacity self.capacity = capacity
...@@ -584,7 +585,7 @@ class OctTree: ...@@ -584,7 +585,7 @@ class OctTree:
def query( def query(
self, self,
rect: SpaceTimeRectangle, rect: SpaceTimeRectangle,
points: SpaceTimeRecords | None = None, points: Optional[SpaceTimeRecords] = None,
) -> SpaceTimeRecords: ) -> SpaceTimeRecords:
"""Get points that fall in a SpaceTimeRectangle""" """Get points that fall in a SpaceTimeRectangle"""
if not points: if not points:
...@@ -611,7 +612,7 @@ class OctTree: ...@@ -611,7 +612,7 @@ class OctTree:
def query_ellipse( def query_ellipse(
self, self,
ellipse: SpaceTimeEllipse, ellipse: SpaceTimeEllipse,
points: SpaceTimeRecords | None = None, points: Optional[SpaceTimeRecords] = None,
) -> SpaceTimeRecords: ) -> SpaceTimeRecords:
"""Get points that fall in an ellipse.""" """Get points that fall in an ellipse."""
if not points: if not points:
...@@ -640,7 +641,7 @@ class OctTree: ...@@ -640,7 +641,7 @@ class OctTree:
point: SpaceTimeRecord, point: SpaceTimeRecord,
dist: float, dist: float,
t_dist: datetime.timedelta, t_dist: datetime.timedelta,
points: SpaceTimeRecords | None = None, points: Optional[SpaceTimeRecords] = None,
) -> SpaceTimeRecords: ) -> SpaceTimeRecords:
""" """
Get all points that are nearby another point. Get all points that are nearby another point.
......
...@@ -4,6 +4,7 @@ for detecting nearby records for example ...@@ -4,6 +4,7 @@ for detecting nearby records for example
""" """
from dataclasses import dataclass from dataclasses import dataclass
from typing import List, Optional
from datetime import datetime from datetime import datetime
from .distance_metrics import haversine, destination from .distance_metrics import haversine, destination
from .utils import LatitudeError from .utils import LatitudeError
...@@ -41,8 +42,8 @@ class Record: ...@@ -41,8 +42,8 @@ class Record:
self, self,
lon: float, lon: float,
lat: float, lat: float,
datetime: datetime | None = None, datetime: Optional[datetime] = None,
uid: str | None = None, uid: Optional[str] = None,
fix_lon: bool = True, fix_lon: bool = True,
**data, **data,
) -> None: ) -> None:
...@@ -305,13 +306,13 @@ class QuadTree: ...@@ -305,13 +306,13 @@ class QuadTree:
boundary: Rectangle, boundary: Rectangle,
capacity: int = 5, capacity: int = 5,
depth: int = 0, depth: int = 0,
max_depth: int | None = None, max_depth: Optional[int] = None,
) -> None: ) -> None:
self.boundary = boundary self.boundary = boundary
self.capacity = capacity self.capacity = capacity
self.depth = depth self.depth = depth
self.max_depth = max_depth self.max_depth = max_depth
self.points: list[Record] = list() self.points: List[Record] = list()
self.divided: bool = False self.divided: bool = False
return None return None
...@@ -406,8 +407,8 @@ class QuadTree: ...@@ -406,8 +407,8 @@ class QuadTree:
def query( def query(
self, self,
rect: Rectangle, rect: Rectangle,
points: list[Record] | None = None, points: Optional[List[Record]] = None,
) -> list[Record]: ) -> List[Record]:
"""Get points that fall in a rectangle""" """Get points that fall in a rectangle"""
if not points: if not points:
points = list() points = list()
...@@ -429,8 +430,8 @@ class QuadTree: ...@@ -429,8 +430,8 @@ class QuadTree:
def query_ellipse( def query_ellipse(
self, self,
ellipse: Ellipse, ellipse: Ellipse,
points: list[Record] | None = None, points: Optional[List[Record]] = None,
) -> list[Record]: ) -> List[Record]:
"""Get points that fall in an ellipse.""" """Get points that fall in an ellipse."""
if not points: if not points:
points = list() points = list()
...@@ -453,8 +454,8 @@ class QuadTree: ...@@ -453,8 +454,8 @@ class QuadTree:
self, self,
point: Record, point: Record,
dist: float, dist: float,
points: list[Record] | None = None, points: Optional[List[Record]] = None,
) -> list[Record]: ) -> List[Record]:
"""Get all points that are nearby another point""" """Get all points that are nearby another point"""
if not points: if not points:
points = list() points = list()
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
Python module containing useful functions and classes for Spatial Analysis. Python module containing useful functions and classes for Spatial Analysis.
Tested on Python versions 3.11, 3.12, and 3.13. Not expected to work with Python 3.9 or below due Tested on Python versions 3.9 to 3.13.
to usage of type annotations.
## Installation ## Installation
......
...@@ -12,11 +12,11 @@ packages = ["GeoSpatialTools"] ...@@ -12,11 +12,11 @@ packages = ["GeoSpatialTools"]
[project] [project]
name = "GeoSpatialTools" name = "GeoSpatialTools"
version = "0.6.0" version = "0.7.0"
dependencies = [ dependencies = [
"numpy", "numpy",
] ]
requires-python = ">=3.11" requires-python = ">=3.9"
authors = [ authors = [
{name = "Joseph Siddons", email = "josidd@noc.ac.uk"}, {name = "Joseph Siddons", email = "josidd@noc.ac.uk"},
{name = "Richard Cornes", email = "rcornes@noc.ac.uk"}, {name = "Richard Cornes", email = "rcornes@noc.ac.uk"},
...@@ -45,6 +45,11 @@ notebooks = [ ...@@ -45,6 +45,11 @@ notebooks = [
test = [ test = [
"pytest", "pytest",
] ]
all = [
"ipykernel",
"polars",
"pytest",
]
[tool.ruff] [tool.ruff]
line-length = 80 line-length = 80
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment