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

Do not compute predecessor and re-decompose it

e1 is directly i1 + 1 and we just need the new function `date_index`
to process k1. Additional benefit: we process k1 out of the loop on
`id_child_1`.
parent 2c21aab0
No related branches found
No related tags found
No related merge requests found
......@@ -10,21 +10,29 @@ import datetime
import csv
import sys
def date_index(k):
"""Compute the number of days since Jan 1st 1950, given the subscript
index in date_num.
"""
date = datetime.date.fromordinal(date_num[k] - 366) - datetime.date(1950,
1, 1)
return date.days
def convert_id(node_index):
"""Convert from node identification in graph to eddy identification in
shapefiles.
"""
k = (node_index - 1) // n_max
date = datetime.date.fromordinal(date_num[k] - 366) - datetime.date(1950,
1, 1)
date = date.days
eddy_index = node_index - k * n_max
return date, eddy_index
return date_index(k), eddy_index
def print_edgelist(id_child):
d1 = date_index(k1)
for i1, id_child_1 in enumerate(id_child):
predecessor = k1 * n_max + 1 + i1
e1 = i1 + 1
# id_child_1 may be an int, which means there is a single
# successor, or id_child_1 may be a numpy array, which means
# there are several successors.
......@@ -32,11 +40,10 @@ def print_edgelist(id_child):
try:
# Try processing id_child_1 as an array:
for node_index in id_child_1:
writer.writerow(convert_id(predecessor)
+ convert_id(node_index))
writer.writerow((d1, e1) + convert_id(node_index))
except TypeError:
# id_child_1 is a scalar int.
writer.writerow(convert_id(predecessor) + convert_id(id_child_1))
writer.writerow((d1, e1) + convert_id(id_child_1))
orientation = sys.argv[1] # "cyclo" or "anti"
id_child = sio.loadmat(f"id_child_{orientation}.mat", squeeze_me=True)\
......
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