Skip to content
Snippets Groups Projects
Commit cdeb688e authored by Lionel GUEZ's avatar Lionel GUEZ
Browse files

Change name of output file "graph_1.txt" to "edgelist_1.csv". Add

title lines in "edgelist_1.csv". Add python script reading
"edgelist_1.csv" into a NetworkX graph.
parent a33ecf3e
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
import networkx as nx
import csv
import matplotlib.pyplot as plt
G = nx.DiGraph()
with open("edgelist_1.csv") as f:
reader = csv.reader(f, delimiter = " ", skipinitialspace = True)
# Skip title lines:
next(reader)
next(reader)
for row in reader:
k1, i1, k2, i2, weight = int(row[0]), int(row[1]), int(row[2]), \
int(row[3]), float(row[4])
G.add_edge((k1, i1), (k2, i2), weight = weight)
plt.figure()
nx.draw(G, with_labels=True)
plt.show()
...@@ -12,7 +12,7 @@ program test_successive_overlap ...@@ -12,7 +12,7 @@ program test_successive_overlap
implicit none implicit none
integer unit_graph, i integer unit_edgelist, i
type(snapshot) flow(2) type(snapshot) flow(2)
TYPE(shpfileobject) hshp_extremum ! shapefile extremum_1 TYPE(shpfileobject) hshp_extremum ! shapefile extremum_1
TYPE(shpfileobject) hshp_outermost ! shapefile outermost_contour_1 TYPE(shpfileobject) hshp_outermost ! shapefile outermost_contour_1
...@@ -43,11 +43,19 @@ program test_successive_overlap ...@@ -43,11 +43,19 @@ program test_successive_overlap
CALL shpclose(hshp_max_speed) CALL shpclose(hshp_max_speed)
flow(2) = flow(1) flow(2) = flow(1)
call new_unit(unit_graph) call new_unit(unit_edgelist)
open(unit_graph, file = "graph_1.txt", status = "replace", action = "write") open(unit_edgelist, file = "edgelist_1.csv", status = "replace", &
call successive_overlap(unit_graph, nlon, nlat, flow, j = 2, k = 2) action = "write")
close(unit_graph)
print *, 'Created file "graph_1.txt".' ! Title lines:
write(unit_edgelist, fmt = "(1x, a)") '"predecessor date index" ' &
// '"predecessor eddy index" "successor date index" ' &
// '"successor eddy index"'
write(unit_edgelist, fmt = *) "k1 i1 k2 i2 weight"
call successive_overlap(unit_edgelist, nlon, nlat, flow, j = 2, k = 2)
close(unit_edgelist)
print *, 'Created file "edgelist_1.csv".'
do i = 1, 2 do i = 1, 2
print *, "flow(", i, ")%list_vis%delta_in:", flow(i)%list_vis%delta_in print *, "flow(", i, ")%list_vis%delta_in:", flow(i)%list_vis%delta_in
......
...@@ -4,10 +4,10 @@ module successive_overlap_m ...@@ -4,10 +4,10 @@ module successive_overlap_m
contains contains
subroutine successive_overlap(unit_graph, nlon, nlat, flow, j, k) subroutine successive_overlap(unit_edgelist, nlon, nlat, flow, j, k)
! Finds edges between flow(j - 1) and flow(j), corresponding to ! Finds edges between flow(j - 1) and flow(j), corresponding to
! dates k - 1 and k. Writes these edges to graph.txt. Updates ! dates k - 1 and k. Writes these edges to unit_edgelist. Updates
! flow(j - 1)%list_vis%delta_out and flow(j)%list_vis%delta_in. ! flow(j - 1)%list_vis%delta_out and flow(j)%list_vis%delta_in.
use contour_531, only: polyline use contour_531, only: polyline
...@@ -17,7 +17,7 @@ contains ...@@ -17,7 +17,7 @@ contains
use spherical_polyline_area_m, only: spherical_polyline_area use spherical_polyline_area_m, only: spherical_polyline_area
use weight_m, only: weight use weight_m, only: weight
integer, intent(in):: unit_graph ! logical unit for graph file integer, intent(in):: unit_edgelist ! logical unit for edgelist file
integer, intent(in):: nlon, nlat integer, intent(in):: nlon, nlat
type(snapshot), intent(inout):: flow(:) ! (max_delta + 1) type(snapshot), intent(inout):: flow(:) ! (max_delta + 1)
integer, intent(in):: j, k integer, intent(in):: j, k
...@@ -62,7 +62,7 @@ contains ...@@ -62,7 +62,7 @@ contains
if (spherical_polygon_area(res_pol) >= 0.25 & if (spherical_polygon_area(res_pol) >= 0.25 &
* min(spherical_polyline_area(polyline_1), & * min(spherical_polyline_area(polyline_1), &
spherical_polyline_area(polyline_2))) then spherical_polyline_area(polyline_2))) then
write(unit_graph, fmt = *) k - 1, i1, k, i2, & write(unit_edgelist, fmt = *) k - 1, i1, k, i2, &
weight(flow(j - 1)%list_vis(i1), & weight(flow(j - 1)%list_vis(i1), &
flow(j)%list_vis(i2)) flow(j)%list_vis(i2))
flow(j - 1)%list_vis(i1)%delta_out = 1 flow(j - 1)%list_vis(i1)%delta_out = 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment