Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
measprocess
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Lukas Eller
measprocess
Commits
acf279e2
Commit
acf279e2
authored
Apr 13, 2021
by
Lukas Eller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added type hints for all existing functions. Plus included a plotting_osm function.
parent
231f1851
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
9706 additions
and
12 deletions
+9706
-12
__init__.py
measprocess/__init__.py
+3
-0
geospatial.py
measprocess/geospatial.py
+9
-9
plotting.py
measprocess/plotting.py
+40
-0
requirements.txt
requirements.txt
+2
-1
setup.py
setup.py
+2
-2
gps.csv
tests/example_files/gps_test/gps.csv
+9615
-0
overpy_series_test.py
tests/overpy_series_test.py
+3
-0
plotting_test.py
tests/plotting_test.py
+29
-0
projection_test.py
tests/projection_test.py
+3
-0
No files found.
measprocess/__init__.py
View file @
acf279e2
from
.preprocess
import
link_dataframes
from
.geospatial
import
get_geoseries_streets
,
get_geoseries_blockages
from
.geospatial
import
project_onto_streets
from
.plotting
import
plot_series_osm
measprocess/geospatial.py
View file @
acf279e2
...
...
@@ -6,7 +6,7 @@ import numpy as np
import
warnings
import
time
def
make_overpy_request
(
request_body
,
retries
):
def
make_overpy_request
(
request_body
:
str
,
retries
:
int
):
for
_
in
range
(
retries
):
try
:
api
=
overpy
.
Overpass
()
...
...
@@ -19,7 +19,7 @@ def make_overpy_request(request_body, retries):
else
:
return
result
def
get_geoseries_streets
(
measurement_coords
,
retries
=
5
)
:
def
get_geoseries_streets
(
measurement_coords
:
gpd
.
GeoSeries
,
retries
:
int
=
5
)
->
gpd
.
GeoSeries
:
'''
Obtain the street shapes in the area spanned by the measurement_coords.
...
...
@@ -31,8 +31,8 @@ def get_geoseries_streets(measurement_coords, retries=5):
if
measurement_coords
.
crs
!=
"EPSG:4326"
:
raise
ValueError
(
"Make sure to pass data with EPSG:4326 projection"
)
long
,
lat
=
measurement_coords
.
x
,
measurement_coords
.
y
bounds
=
(
lat
.
min
(),
long
.
min
(),
lat
.
max
(),
long
.
max
()
)
#Find total bounds: (lat_min, long_min, lat_max, long_max)
bounds
=
tuple
(
measurement_coords
.
total_bounds
[[
1
,
0
,
3
,
2
]]
)
result
=
make_overpy_request
(
f
"""
...
...
@@ -55,7 +55,7 @@ def get_geoseries_streets(measurement_coords, retries=5):
return
street_series
def
get_geoseries_blockages
(
measurement_coords
,
retries
=
5
)
:
def
get_geoseries_blockages
(
measurement_coords
:
gpd
.
GeoSeries
,
retries
:
int
=
5
)
->
gpd
.
GeoSeries
:
'''
Obtain the blockage shapes in the area spanned by the measurement_coords.
...
...
@@ -67,8 +67,8 @@ def get_geoseries_blockages(measurement_coords, retries=5):
if
measurement_coords
.
crs
!=
"EPSG:4326"
:
raise
ValueError
(
"Make sure to pass data with EPSG:4326 projection"
)
long
,
lat
=
measurement_coords
.
x
,
measurement_coords
.
y
bounds
=
(
lat
.
min
(),
long
.
min
(),
lat
.
max
(),
long
.
max
()
)
#Find total bounds: (lat_min, long_min, lat_max, long_max)
bounds
=
tuple
(
measurement_coords
.
total_bounds
[[
1
,
0
,
3
,
2
]]
)
result
=
make_overpy_request
(
f
"""
...
...
@@ -92,9 +92,9 @@ def get_geoseries_blockages(measurement_coords, retries=5):
return
blockages
def
project_onto_streets
(
point_series
,
street_series
,
epsg
=
"EPSG:31287"
,
plot
=
False
):
def
project_onto_streets
(
point_series
:
gpd
.
GeoSeries
,
street_series
:
gpd
.
GeoSeries
,
epsg
:
str
=
"EPSG:31287"
,
plot
:
bool
=
False
)
->
(
gpd
.
GeoSeries
,
gpd
.
GeoSeries
):
'''
Todo:
Muss noch angepasst werden!
Todo:
Not completed
'''
if
point_series
.
crs
!=
epsg
or
street_series
.
crs
!=
epsg
:
...
...
measprocess/plotting.py
View file @
acf279e2
import
geopandas
as
gpd
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
cartopy.crs
as
ccrs
import
cartopy.io.img_tiles
as
cimgt
def
plot_series_osm
(
gps_series
:
gpd
.
GeoSeries
,
c_series
:
np
.
ndarray
=
None
,
zoom_level
:
int
=
10
,
scatter_size
:
int
=
10
,
fig_size
:
(
int
,
int
)
=
(
12
,
10
),
save_path
=
None
,
show
=
True
):
'''
Plot a series of gps locations onto a OSM map
:param gps_series: geopandas series of the gps value in EPSG:4326 to plot
:param c_series: series of values to be interpreted as colors in the scatterplot
:param zoom_level: zoom level for resolution of OSM tiles
:param fig_size: the figure size of the generated plot
:param save_path: if not none then the plot will be saved under this path
'''
if
gps_series
.
crs
!=
"EPSG:4326"
:
raise
ValueError
(
"Make sure to pass data with EPSG:4326 projection"
)
'''
Make a very simple test
'''
request
=
cimgt
.
OSM
()
extent
=
gps_series
.
total_bounds
[[
0
,
2
,
1
,
3
]]
plt
.
figure
(
figsize
=
fig_size
)
ax
=
plt
.
axes
(
projection
=
request
.
crs
)
ax
.
set_xlabel
(
"Longitude"
)
ax
.
set_ylabel
(
"Latitude"
)
ax
.
set_extent
(
extent
)
ax
.
add_image
(
request
,
zoom_level
)
if
c_series
is
not
None
:
ax
.
scatter
(
gps_series
.
x
,
gps_series
.
y
,
c
=
c_series
,
transform
=
ccrs
.
PlateCarree
(),
s
=
scatter_size
)
else
:
ax
.
scatter
(
gps_series
.
x
,
gps_series
.
y
,
transform
=
ccrs
.
PlateCarree
(),
s
=
scatter_size
)
if
save_path
is
not
None
:
plt
.
savefig
(
save_path
,
bbox_inches
=
"tight"
)
if
show
:
plt
.
show
()
requirements.txt
View file @
acf279e2
pandas
>=1.2.1
pytest
>=6.2.2
overpy
>=0.4
geopandas
>=0.8.1
geopandas
>=0.8.1
cartopy
>=0.18.0
setup.py
View file @
acf279e2
...
...
@@ -10,7 +10,7 @@ README = (HERE / "README.md").read_text()
# This call to setup() does all the work
setup
(
name
=
"measprocess"
,
version
=
"0.5.1
1
"
,
version
=
"0.5.1
2
"
,
description
=
"Collection of measurement processing tools"
,
long_description
=
README
,
long_description_content_type
=
"text/markdown"
,
...
...
@@ -23,5 +23,5 @@ setup(
],
packages
=
[
"measprocess"
],
include_package_data
=
True
,
install_requires
=
[
"pandas"
,
"matplotlib"
,
"geopandas"
,
"overpy"
,
"shapely"
,
"numpy"
,
"tqdm"
],
install_requires
=
[
"pandas"
,
"matplotlib"
,
"geopandas"
,
"overpy"
,
"shapely"
,
"numpy"
,
"tqdm"
,
"cartopy"
],
)
tests/example_files/gps_test/gps.csv
0 → 100644
View file @
acf279e2
This diff is collapsed.
Click to expand it.
tests/overpy_series_test.py
View file @
acf279e2
...
...
@@ -71,3 +71,6 @@ class TestOSMAPI(unittest.TestCase):
self
.
assertTrue
(
blockage_series
.
distance
(
projected
[
0
])
.
mean
()
<
1000
)
if
__name__
==
'__main__'
:
unittest
.
main
()
tests/plotting_test.py
0 → 100644
View file @
acf279e2
import
unittest
import
pandas
as
pd
import
geopandas
as
gpd
from
shapely.geometry
import
Point
from
context
import
measprocess
as
mpc
class
TestPlottingOSM
(
unittest
.
TestCase
):
def
setUp
(
self
):
complete_dataset
=
pd
.
read_csv
(
"tests/example_files/gps_test/gps.csv"
,
index_col
=
0
)
gps_series
=
complete_dataset
[[
'Lon.'
,
'Lat.'
]]
.
values
self
.
_gps_series
=
gpd
.
GeoSeries
(
(
Point
(
lon
,
lat
)
for
lon
,
lat
in
gps_series
)
)
def
test_basic
(
self
):
#Check if no exception comes up
series
=
self
.
_gps_series
.
set_crs
(
"EPSG:4326"
)
mpc
.
plotting
.
plot_series_osm
(
series
,
show
=
False
)
def
test_exception_epsg
(
self
):
with
self
.
assertRaises
(
ValueError
):
series
=
self
.
_gps_series
#.set_crs("EPSG:4326")
mpc
.
plotting
.
plot_series_osm
(
series
,
show
=
False
)
if
__name__
==
'__main__'
:
unittest
.
main
()
tests/projection_test.py
View file @
acf279e2
...
...
@@ -70,3 +70,6 @@ class TestProjections(unittest.TestCase):
deviation
.
values
-
np
.
array
([
10
,
1
,
np
.
sqrt
(
10
**
2
+
10
**
2
)])
)
<
1e-1
)
if
__name__
==
'__main__'
:
unittest
.
main
()
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