diff --git a/Convert_Matlab/overlap_v6.py b/Convert_Matlab/overlap_v6.py index 9d0234ec33c7c2182935d7cd8ec342da4007d863..d8cdaaf67d53f297d9327827022062caeced8c2a 100755 --- a/Convert_Matlab/overlap_v6.py +++ b/Convert_Matlab/overlap_v6.py @@ -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]) diff --git a/Tests/short_tests.json b/Tests/short_tests.json index 6ee1e836ca500fa63b7982c6213f96c04b4c6d4d..da1dfcdf36f623a27e1577729525ba3ff321cce1 100644 --- a/Tests/short_tests.json +++ b/Tests/short_tests.json @@ -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" ]