Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CSNMF
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TrafficPatterns
CSNMF
Commits
176042d8
Commit
176042d8
authored
7 years ago
by
yager2
Browse files
Options
Downloads
Patches
Plain Diff
Merged visualize.py and added geopandas functions
parent
bfce6ad7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Multiplicative Algorithm/Visualizations.py
+88
-0
88 additions, 0 deletions
Multiplicative Algorithm/Visualizations.py
with
88 additions
and
0 deletions
Multiplicative Algorithm/Visualizations.py
+
88
−
0
View file @
176042d8
...
...
@@ -2,6 +2,8 @@ import numpy as np
import
pandas
as
pd
import
matplotlib.pyplot
as
plt
import
config
import
geopandas
as
gpd
from
shapely.geometry
import
LineString
days_of_week
=
[
'
Saturday
'
,
'
Sunday
'
,
'
Monday
'
,
'
Tuesday
'
,
'
Wednesday
'
,
'
Thursday
'
,
'
Friday
'
]
...
...
@@ -41,4 +43,90 @@ def plot_all_signatures_particular_weekday(W, weekday, mean = False):
imagename
=
'
../Figures/
'
+
str
(
signature
).
zfill
(
2
)
+
days_of_week
[
weekday
][
0
:
3
]
+
'
.png
'
plt
.
savefig
(
imagename
,
dpi
=
300
,
bbox_inches
=
'
tight
'
)
# dpi ideal for viewing on laptop fullscreen
plt
.
clf
()
def
Heatmap
(
W1
,
W2
):
assert
W1
.
shape
==
W2
.
shape
Ro
=
np
.
corrcoef
(
W1
.
T
,
W2
.
T
)[
len
(
W1
.
T
):,:
len
(
W2
.
T
)]
plt
.
imshow
(
Ro
,
cmap
=
'
hot
'
,
interpolation
=
'
nearest
'
)
plt
.
colorbar
()
plt
.
title
(
'
Heatmap for correlation coefficients comparing two runs of W
'
)
plt
.
xlabel
(
'
Columns of W1
'
)
plt
.
ylabel
(
'
Columns of W2
'
)
plt
.
savefig
(
'
Heatmap
'
)
plt
.
show
()
return
None
# Requires full_link_ids.txt, links.csv, and H_trips.txt in running folder
# Requires Signature_Maps folder within running folder
def
map_signature
(
signature
):
filenames
=
config
.
generate_filenames
(
''
)
full_link_ids
=
np
.
loadtxt
(
'
full_link_ids.txt
'
,
dtype
=
int
)
H_loaded
=
gpd
.
pd
.
read_csv
(
filenames
[
'
H_trips
'
],
delimiter
=
'
'
,
names
=
full_link_ids
)
link_df
=
gpd
.
pd
.
read_csv
(
filenames
[
'
links
'
])
crs
=
{
'
init
'
:
'
epsg:4326
'
}
signature_list
=
H_loaded
.
loc
[
signature
,:][
H_loaded
.
loc
[
signature
,:]
>
0
].
keys
().
tolist
()
if
len
(
signature_list
)
>
0
:
df
=
link_df
[
link_df
[
'
link_id
'
].
isin
(
signature_list
)]
df
[
'
geom
'
]
=
df
.
apply
(
lambda
x
:
LineString
([(
x
.
startX
,
x
.
startY
),(
x
.
endX
,
x
.
endY
)]),
axis
=
1
)
geo_df
=
gpd
.
GeoDataFrame
(
df
,
crs
=
crs
,
geometry
=
'
geom
'
)
location
=
'
Signature_Maps\sig
'
+
format
(
signature
,
'
02d
'
)
geo_df
.
to_file
(
location
)
else
:
print
(
'
Signature
'
+
str
(
signature
)
+
'
has no links
'
)
return
None
def
map_all_signatures
():
filenames
=
config
.
generate_filenames
(
''
)
full_link_ids
=
np
.
loadtxt
(
'
full_link_ids.txt
'
,
dtype
=
int
)
H_loaded
=
gpd
.
pd
.
read_csv
(
filenames
[
'
H_trips
'
],
delimiter
=
'
'
,
names
=
full_link_ids
)
link_df
=
gpd
.
pd
.
read_csv
(
filenames
[
'
links
'
])
crs
=
{
'
init
'
:
'
epsg:4326
'
}
signature_link_lists
=
list
()
link_df
=
gpd
.
pd
.
read_csv
(
filenames
[
'
links
'
])
for
signature
in
range
(
config
.
RANK
):
signature_list
=
H_loaded
.
loc
[
signature
,:][
H_loaded
.
loc
[
signature
,:]
>
0
].
keys
().
tolist
()
signature_link_lists
.
append
(
signature_list
)
if
len
(
signature_list
)
>
0
:
df
=
link_df
[
link_df
[
'
link_id
'
].
isin
(
signature_link_lists
[
signature
])]
df
[
'
geom
'
]
=
df
.
apply
(
lambda
x
:
LineString
([(
x
.
startX
,
x
.
startY
),(
x
.
endX
,
x
.
endY
)]),
axis
=
1
)
geo_df
=
gpd
.
GeoDataFrame
(
df
,
crs
=
crs
,
geometry
=
'
geom
'
)
location
=
'
Signature_Maps\sig
'
+
format
(
signature
,
'
02d
'
)
geo_df
.
to_file
(
location
)
else
:
print
(
'
Signature
'
+
str
(
signature
)
+
'
has no links
'
)
return
None
def
map_links_with_many_signatures
(
threshold
=
7
):
# threshold for number of signatures for a link considered high
filenames
=
config
.
generate_filenames
(
''
)
full_link_ids
=
np
.
loadtxt
(
'
full_link_ids.txt
'
,
dtype
=
int
)
H_loaded
=
gpd
.
pd
.
read_csv
(
filenames
[
'
H_trips
'
],
delimiter
=
'
'
,
names
=
full_link_ids
)
link_df
=
gpd
.
pd
.
read_csv
(
filenames
[
'
links
'
])
crs
=
{
'
init
'
:
'
epsg:4326
'
}
ds
=
np
.
sum
(
H_loaded
>
0
,
axis
=
0
)
link_ids_with_high_signature_count
=
ds
[
ds
>=
threshold
].
keys
().
tolist
()
df
=
link_df
[
link_df
[
'
link_id
'
].
isin
(
link_ids_with_high_signature_count
)]
df
[
'
geom
'
]
=
df
.
apply
(
lambda
x
:
LineString
([(
x
.
startX
,
x
.
startY
),(
x
.
endX
,
x
.
endY
)]),
axis
=
1
)
geo_df
=
gpd
.
GeoDataFrame
(
df
,
crs
=
crs
,
geometry
=
'
geom
'
)
geo_df
.
to_file
(
'
High_Signature_Map
'
)
return
None
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment