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

Keep the Matlab indexing of eddies

Which is separate for cyclones and anticyclones. For now. Then we do
not need the argument cyclone of functions `convert_id` and
`print_edgelist`, and we do not need to read `Nanti.mat` for
processing cyclones.
parent 78ca0b37
No related branches found
No related tags found
No related merge requests found
......@@ -10,12 +10,7 @@ import datetime
import csv
import sys
def convert_id(cyclone, node_index):
We assume that the shapefiles are created by the script
"mat_to_shapefiles.py", that is: at each date, all the
anticyclones are before all the cyclones. We use global variable
Nanti.
def convert_id(node_index):
"""Convert from node identification in graph to eddy identification in
shapefiles.
......@@ -24,17 +19,12 @@ def convert_id(cyclone, node_index):
date = datetime.date.fromordinal(date_num[k] - 366) - datetime.date(1950,
1, 1)
date = date.days
if cyclone:
eddy_index_F = Nanti[k] + node_index - k * n_max
else:
eddy_index_F = node_index - k * n_max
return date, eddy_index_F
eddy_index = node_index - k * n_max
return date, eddy_index
def print_edgelist(id_child, cyclone):
def print_edgelist(id_child):
for i1, id_child_1 in enumerate(id_child):
predecessor = (cyclone, k1 * n_max + 1 + i1)
predecessor = k1 * n_max + 1 + i1
# 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.
......@@ -42,26 +32,23 @@ def print_edgelist(id_child, cyclone):
try:
# Try processing id_child_1 as an array:
for node_index in id_child_1:
writer.writerow(convert_id(*predecessor)
+ convert_id(cyclone, node_index))
writer.writerow(convert_id(predecessor)
+ convert_id(node_index))
except TypeError:
# id_child_1 is a scalar int.
writer.writerow(convert_id(*predecessor)
+ convert_id(cyclone, id_child_1))
writer.writerow(convert_id(predecessor) + convert_id(id_child_1))
orientation = sys.argv[1]
id_child = sio.loadmat(f"id_child_{orientation}.mat", squeeze_me=True)\
["id_child"]
Nanti = sio.loadmat("Nanti.mat", squeeze_me = True)["Nanti"]\
.astype(int, casting = "safe", copy = False)
cyclone = orientation == "cyclo"
if cyclone:
n_eddies = sio.loadmat("Ncyclo.mat", squeeze_me = True)["Ncyclo"]\
.astype(int, casting = "safe", copy = False)
if orientation == "cyclo":
var_name = "Ncyclo"
else:
n_eddies = Nanti
var_name = "Nanti"
n_eddies = sio.loadmat(f"{var_name}.mat", squeeze_me = True)[var_name]\
.astype(int, casting = "safe", copy = False)
date_num = sio.loadmat("date_num.mat", squeeze_me = True)["date_num"]
n_dates = n_eddies.size
print("n_dates =", n_dates)
......@@ -75,4 +62,4 @@ with open(f"edgelist_{orientation}.csv", "w", newline = '') as edgelist:
writer.writerow(["k1", "i1", "k2", "i2"])
for k1 in range(n_dates):
print_edgelist(id_child[:n_eddies[k1], k1], cyclone)
print_edgelist(id_child[:n_eddies[k1], k1])
......@@ -1038,7 +1038,6 @@
"required":
[
"$src_dir/Tests/Input/Eurec4A_OA/id_child_cyclo.mat",
"$src_dir/Tests/Input/Eurec4A_OA/Nanti.mat",
"$src_dir/Tests/Input/Eurec4A_OA/Ncyclo.mat",
"$src_dir/Tests/Input/Eurec4A_OA/date_num.mat"
]
......
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