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

Process either anticyclones or cyclones

The choice is made with a command line argument. As in commit 1e4d2ee1.
parent b5630c4e
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
"""This script reads the eddy graph from Matlab v7.3 mat files and
writes it in edgelist format. All the anticyclones are processed
before all the cyclones. It is about 10 times slower than the
writes it in edgelist format. It is about 10 times slower than the
corresponding script reading the same data from a Matlab v6 file.
"""
......@@ -10,6 +9,7 @@
import h5py
import datetime
import csv
import sys
def convert_id(cyclone, eddy_index_Matlab):
"""Convert from Matlab eddy identification to eddy
......@@ -23,7 +23,7 @@ def convert_id(cyclone, eddy_index_Matlab):
"""
k = (eddy_index_Matlab - 1) // n_max
date_num = Assoc_eddies_Anti_max["date_num"][k].item()
date_num = Assoc_eddies["date_num"][k].item()
date_num = int(date_num)
date = datetime.date.fromordinal(date_num - 366) - datetime.date(1950,1,1)
date = date.days
......@@ -47,30 +47,30 @@ def print_edgelist(file, id_child, cyclone):
writer.writerow(convert_id(*predecessor)
+ convert_id(cyclone, eddy_index_Matlab))
Assoc_eddies_Anti_max = h5py.File("Association_eddies_Anti_max.mat", "r")
Assoc_eddies_Cyclo_max = h5py.File("Association_eddies_Cyclo_max.mat", "r")
orientation = sys.argv[1]
cyclone = orientation == "Cyclo"
Assoc_eddies = h5py.File(f"Association_eddies_{orientation}_max.mat", "r")
with h5py.File("Parameters_Anticyclonic_Eddies.mat", "r") as f:
Nanti = f["Nanti"][:].squeeze().astype(int)
with h5py.File("Parameters_Cyclonic_Eddies.mat", "r") as f:
Ncyclo = f["Ncyclo"][:].squeeze().astype(int)
if cyclone:
with h5py.File("Parameters_Cyclonic_Eddies.mat", "r") as f:
n_eddies = f["Ncyclo"][:].squeeze().astype(int)
else:
n_eddies = Nanti
n_dates = Nanti.size
print("n_dates =", n_dates)
n_max = Assoc_eddies_Anti_max["id_child"].shape[1]
n_max = Assoc_eddies["id_child"].shape[1]
print("n_max =", n_max)
with open("edgelist.csv", "w", newline = '') as edgelist:
with open(f"edgelist_{orientation}.csv", "w", newline = '') as edgelist:
writer = csv.writer(edgelist, delimiter = ' ', lineterminator = "\n")
writer.writerow(["predecessor date subscript", "predecessor eddy subscript",
"successor date subscript", "successor eddy subscript"])
writer.writerow(["k1", "i1", "k2", "i2"])
for k1 in range(n_dates):
print_edgelist(Assoc_eddies_Anti_max,
Assoc_eddies_Anti_max["id_child"][k1, :Nanti[k1]],
cyclone = False)
print_edgelist(Assoc_eddies_Cyclo_max,
Assoc_eddies_Cyclo_max["id_child"][k1, :Ncyclo[k1]],
cyclone = True)
print_edgelist(Assoc_eddies,
Assoc_eddies["id_child"][k1, :n_eddies[k1]], cyclone)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment