Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
NOCSurfaceProcesses
GeoSpatialTools
Commits
fa9fc2fa
Commit
fa9fc2fa
authored
4 months ago
by
Joseph Siddons
Browse files
Options
Download
Plain Diff
Merge branch 'typing-3.9' into 'main'
Compatibility with python 3.9 See merge request
!11
parents
2818c35d
c6b57bfb
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
39 additions
and
31 deletions
+39
-31
GeoSpatialTools/distance_metrics.py
GeoSpatialTools/distance_metrics.py
+3
-2
GeoSpatialTools/kdtree.py
GeoSpatialTools/kdtree.py
+5
-4
GeoSpatialTools/neighbours.py
GeoSpatialTools/neighbours.py
+5
-5
GeoSpatialTools/octtree.py
GeoSpatialTools/octtree.py
+7
-6
GeoSpatialTools/quadtree.py
GeoSpatialTools/quadtree.py
+11
-10
README.md
README.md
+1
-2
pyproject.toml
pyproject.toml
+7
-2
No files found.
GeoSpatialTools/distance_metrics.py
View file @
fa9fc2fa
...
...
@@ -4,6 +4,7 @@ navigational information to DataFrames.
"""
from
math
import
acos
,
asin
,
atan2
,
cos
,
sin
,
degrees
,
radians
,
sqrt
from
typing
import
Tuple
def
gcd_slc
(
...
...
@@ -124,7 +125,7 @@ def bearing(
def
destination
(
lon
:
float
,
lat
:
float
,
bearing
:
float
,
distance
:
float
)
->
t
uple
[
float
,
float
]:
)
->
T
uple
[
float
,
float
]:
"""
Compute destination of a great circle path.
...
...
@@ -173,7 +174,7 @@ def midpoint(
lat0
:
float
,
lon1
:
float
,
lat1
:
float
,
)
->
t
uple
[
float
,
float
]:
)
->
T
uple
[
float
,
float
]:
"""
Compute the midpoint of a great circle track
...
...
This diff is collapsed.
Click to expand it.
GeoSpatialTools/kdtree.py
View file @
fa9fc2fa
...
...
@@ -5,6 +5,7 @@ Useful tool for quickly searching for nearest neighbours.
from
.
import
Record
from
numpy
import
inf
from
typing
import
List
,
Optional
,
Tuple
class
KDTree
:
...
...
@@ -33,7 +34,7 @@ class KDTree:
"""
def
__init__
(
self
,
points
:
l
ist
[
Record
],
depth
:
int
=
0
,
max_depth
:
int
=
20
self
,
points
:
L
ist
[
Record
],
depth
:
int
=
0
,
max_depth
:
int
=
20
)
->
None
:
self
.
depth
=
depth
n_points
=
len
(
points
)
...
...
@@ -110,7 +111,7 @@ class KDTree:
return
True
return
False
def
query
(
self
,
point
)
->
t
uple
[
l
ist
[
Record
],
float
]:
def
query
(
self
,
point
)
->
T
uple
[
L
ist
[
Record
],
float
]:
"""Find the nearest Record within the KDTree to a query Record"""
if
point
.
lon
<
0
:
point2
=
Record
(
point
.
lon
+
360
,
point
.
lat
,
fix_lon
=
False
)
...
...
@@ -127,9 +128,9 @@ class KDTree:
def
_query
(
self
,
point
:
Record
,
current_best
:
l
ist
[
Record
]
|
None
=
None
,
current_best
:
Optional
[
L
ist
[
Record
]
]
=
None
,
best_distance
:
float
=
inf
,
)
->
t
uple
[
l
ist
[
Record
],
float
]:
)
->
T
uple
[
L
ist
[
Record
],
float
]:
if
current_best
is
None
:
current_best
=
list
()
if
not
self
.
split
:
...
...
This diff is collapsed.
Click to expand it.
GeoSpatialTools/neighbours.py
View file @
fa9fc2fa
...
...
@@ -2,7 +2,7 @@
from
numpy
import
argmin
from
bisect
import
bisect
from
typing
import
TypeVar
from
typing
import
List
,
TypeVar
,
Union
from
datetime
import
date
,
datetime
from
warnings
import
warn
...
...
@@ -22,7 +22,7 @@ class SortedError(Exception):
pass
def
_find_nearest
(
vals
:
l
ist
[
Numeric
],
test
:
Numeric
)
->
int
:
def
_find_nearest
(
vals
:
L
ist
[
Numeric
],
test
:
Numeric
)
->
int
:
i
=
bisect
(
vals
,
test
)
# Position that test would be inserted
# Handle edges
...
...
@@ -36,10 +36,10 @@ def _find_nearest(vals: list[Numeric], test: Numeric) -> int:
def
find_nearest
(
vals
:
l
ist
[
Numeric
],
test
:
l
ist
[
Numeric
]
|
Numeric
,
vals
:
L
ist
[
Numeric
],
test
:
Union
[
L
ist
[
Numeric
]
,
Numeric
]
,
check_sorted
:
bool
=
True
,
)
->
l
ist
[
int
]
|
int
:
)
->
Union
[
L
ist
[
int
]
,
int
]
:
"""
Find the nearest value in a list of values for each test value.
...
...
This diff is collapsed.
Click to expand it.
GeoSpatialTools/octtree.py
View file @
fa9fc2fa
from
dataclasses
import
dataclass
from
typing
import
List
,
Optional
import
datetime
from
.distance_metrics
import
haversine
,
destination
from
.utils
import
LatitudeError
,
DateWarning
...
...
@@ -45,7 +46,7 @@ class SpaceTimeRecord:
lon
:
float
,
lat
:
float
,
datetime
:
datetime
.
datetime
,
uid
:
str
|
None
=
None
,
uid
:
Optional
[
str
]
=
None
,
fix_lon
:
bool
=
True
,
**
data
,
)
->
None
:
...
...
@@ -80,7 +81,7 @@ class SpaceTimeRecord:
)
class
SpaceTimeRecords
(
l
ist
[
SpaceTimeRecord
]):
class
SpaceTimeRecords
(
L
ist
[
SpaceTimeRecord
]):
"""List of SpaceTimeRecords"""
...
...
@@ -402,7 +403,7 @@ class OctTree:
boundary
:
SpaceTimeRectangle
,
capacity
:
int
=
5
,
depth
:
int
=
0
,
max_depth
:
int
|
None
=
None
,
max_depth
:
Optional
[
int
]
=
None
,
)
->
None
:
self
.
boundary
=
boundary
self
.
capacity
=
capacity
...
...
@@ -584,7 +585,7 @@ class OctTree:
def
query
(
self
,
rect
:
SpaceTimeRectangle
,
points
:
SpaceTimeRecords
|
None
=
None
,
points
:
Optional
[
SpaceTimeRecords
]
=
None
,
)
->
SpaceTimeRecords
:
"""Get points that fall in a SpaceTimeRectangle"""
if
not
points
:
...
...
@@ -611,7 +612,7 @@ class OctTree:
def
query_ellipse
(
self
,
ellipse
:
SpaceTimeEllipse
,
points
:
SpaceTimeRecords
|
None
=
None
,
points
:
Optional
[
SpaceTimeRecords
]
=
None
,
)
->
SpaceTimeRecords
:
"""Get points that fall in an ellipse."""
if
not
points
:
...
...
@@ -640,7 +641,7 @@ class OctTree:
point
:
SpaceTimeRecord
,
dist
:
float
,
t_dist
:
datetime
.
timedelta
,
points
:
SpaceTimeRecords
|
None
=
None
,
points
:
Optional
[
SpaceTimeRecords
]
=
None
,
)
->
SpaceTimeRecords
:
"""
Get all points that are nearby another point.
...
...
This diff is collapsed.
Click to expand it.
GeoSpatialTools/quadtree.py
View file @
fa9fc2fa
...
...
@@ -4,6 +4,7 @@ for detecting nearby records for example
"""
from
dataclasses
import
dataclass
from
typing
import
List
,
Optional
from
datetime
import
datetime
from
.distance_metrics
import
haversine
,
destination
from
.utils
import
LatitudeError
...
...
@@ -41,8 +42,8 @@ class Record:
self
,
lon
:
float
,
lat
:
float
,
datetime
:
datetime
|
None
=
None
,
uid
:
str
|
None
=
None
,
datetime
:
Optional
[
datetime
]
=
None
,
uid
:
Optional
[
str
]
=
None
,
fix_lon
:
bool
=
True
,
**
data
,
)
->
None
:
...
...
@@ -305,13 +306,13 @@ class QuadTree:
boundary
:
Rectangle
,
capacity
:
int
=
5
,
depth
:
int
=
0
,
max_depth
:
int
|
None
=
None
,
max_depth
:
Optional
[
int
]
=
None
,
)
->
None
:
self
.
boundary
=
boundary
self
.
capacity
=
capacity
self
.
depth
=
depth
self
.
max_depth
=
max_depth
self
.
points
:
l
ist
[
Record
]
=
list
()
self
.
points
:
L
ist
[
Record
]
=
list
()
self
.
divided
:
bool
=
False
return
None
...
...
@@ -406,8 +407,8 @@ class QuadTree:
def
query
(
self
,
rect
:
Rectangle
,
points
:
l
ist
[
Record
]
|
None
=
None
,
)
->
l
ist
[
Record
]:
points
:
Optional
[
L
ist
[
Record
]
]
=
None
,
)
->
L
ist
[
Record
]:
"""Get points that fall in a rectangle"""
if
not
points
:
points
=
list
()
...
...
@@ -429,8 +430,8 @@ class QuadTree:
def
query_ellipse
(
self
,
ellipse
:
Ellipse
,
points
:
l
ist
[
Record
]
|
None
=
None
,
)
->
l
ist
[
Record
]:
points
:
Optional
[
L
ist
[
Record
]
]
=
None
,
)
->
L
ist
[
Record
]:
"""Get points that fall in an ellipse."""
if
not
points
:
points
=
list
()
...
...
@@ -453,8 +454,8 @@ class QuadTree:
self
,
point
:
Record
,
dist
:
float
,
points
:
l
ist
[
Record
]
|
None
=
None
,
)
->
l
ist
[
Record
]:
points
:
Optional
[
L
ist
[
Record
]
]
=
None
,
)
->
L
ist
[
Record
]:
"""Get all points that are nearby another point"""
if
not
points
:
points
=
list
()
...
...
This diff is collapsed.
Click to expand it.
README.md
View file @
fa9fc2fa
...
...
@@ -2,8 +2,7 @@
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
to usage of type annotations.
Tested on Python versions 3.9 to 3.13.
## Installation
...
...
This diff is collapsed.
Click to expand it.
pyproject.toml
View file @
fa9fc2fa
...
...
@@ -12,11 +12,11 @@ packages = ["GeoSpatialTools"]
[project]
name
=
"GeoSpatialTools"
version
=
"0.
6
.0"
version
=
"0.
7
.0"
dependencies
=
[
"numpy"
,
]
requires-python
=
">=3.
11
"
requires-python
=
">=3.
9
"
authors
=
[
{name
=
"Joseph Siddons"
,
email
=
"josidd@noc.ac.uk"
}
,
{name
=
"Richard Cornes"
,
email
=
"rcornes@noc.ac.uk"
}
,
...
...
@@ -45,6 +45,11 @@ notebooks = [
test
=
[
"pytest"
,
]
all
=
[
"ipykernel"
,
"polars"
,
"pytest"
,
]
[tool.ruff]
line-length
=
80
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment