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

Add arguments X, Y, ADT to function write

Instead of using values of global variable `matlab_data` inside the
function write. This is clearer. Especially since we already had an
argument of write, cell, which is a value of `matlab_data`.
parent 60650738
No related branches found
No related tags found
No related merge requests found
......@@ -42,14 +42,16 @@ def define_fields(writers):
writers["max_speed"].field("days_1950", "N", 5)
writers["max_speed"].field("eddy_index", "N", 5)
def write(writers, cell, cyclone):
def write(writers, cell, X, Y, ADT, cyclone):
"""Write to shapefiles eddies with a given orientation, at a given
date.
writers is a dictionary. cell is a numpy.ndarray with shape
(number of eddies, 21). cyclone is a boolean. The eddy
identification numbers start at 1 and increment by 1 for each eddy
in cell.
(number of eddies, 21). X and Y are numpy one-dimensional arrays
containing longitudes and latitudes of the SSH grid. ADT is a
numpy two-dimensional array containing SSH. cyclone is a
boolean. The eddy identification numbers start at 1 and increment
by 1 for each eddy in cell.
"""
eddy_index = 0
......@@ -63,17 +65,16 @@ def write(writers, cell, cyclone):
eddy_index += 1
writers["extr"].point(eddy[0], eddy[1])
i = np.argwhere(matlab_data["X"] == eddy[0]).item()
j = np.argwhere(matlab_data["Y"] == eddy[1]).item()
i = np.argwhere(X == eddy[0]).item()
j = np.argwhere(Y == eddy[1]).item()
speed = 1e4 if np.isnan(eddy[12]) else eddy[12]
writers["extr"].record(ssh = matlab_data["ADT"][i, j], valid = 1,
days_1950 = d, eddy_index = eddy_index,
speed = speed)
writers["extr"].record(ssh = ADT[i, j], valid = 1, days_1950 = d,
eddy_index = eddy_index, speed = speed)
if cyclone:
ssh = matlab_data["ADT"][i, j] + eddy[7]
ssh = ADT[i, j] + eddy[7]
else:
ssh = matlab_data["ADT"][i, j] - eddy[7]
ssh = ADT[i, j] - eddy[7]
writers["centroid"].point(eddy[2], eddy[3])
writers["centroid"].record(days_1950 = d, eddy_index = eddy_index)
......@@ -84,9 +85,9 @@ def write(writers, cell, cyclone):
writers["outer"].poly([polyline])
if cyclone:
ssh = matlab_data["ADT"][i, j] + eddy[11]
ssh = ADT[i, j] + eddy[11]
else:
ssh = matlab_data["ADT"][i, j] - eddy[11]
ssh = ADT[i, j] - eddy[11]
writers["max_speed"].record(r_eq_area = eddy[10], ssh = ssh,
days_1950 = d, eddy_index = eddy_index)
......@@ -163,6 +164,7 @@ while True:
for factory in factories:
write(factory["writers"], matlab_data[factory["cell_name"]],
matlab_data["X"], matlab_data["Y"], matlab_data["ADT"],
factory["cyclone"])
os.remove("adt.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