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

Remove default value of argument orientation

On second thought, I find the default value confusing. We are
reverting commit b328ab6f.
parent 64e09be8
No related branches found
No related tags found
No related merge requests found
...@@ -79,7 +79,8 @@ class SHPC_class: ...@@ -79,7 +79,8 @@ class SHPC_class:
= self._ishape_last[i_slice]["Cyclones"].size = self._ishape_last[i_slice]["Cyclones"].size
else: else:
try: try:
self._n_dates[i_slice] = self.get_ishape_last(i_slice).size self._n_dates[i_slice] \
= self.get_ishape_last(i_slice, self.def_orient).size
except AttributeError: except AttributeError:
# Try the other orientation: # Try the other orientation:
orientation = other_orient(self.def_orient) orientation = other_orient(self.def_orient)
...@@ -88,9 +89,7 @@ class SHPC_class: ...@@ -88,9 +89,7 @@ class SHPC_class:
return self._n_dates[i_slice] return self._n_dates[i_slice]
def get_ishape_last(self, i_slice, orientation = None): def get_ishape_last(self, i_slice, orientation):
if orientation is None: orientation = self.def_orient
if self._ishape_last[i_slice][orientation] is None: if self._ishape_last[i_slice][orientation] is None:
fname = path.join(self.dir, f"Slice_{i_slice}", orientation, fname = path.join(self.dir, f"Slice_{i_slice}", orientation,
"ishape_last.txt") "ishape_last.txt")
...@@ -106,9 +105,7 @@ class SHPC_class: ...@@ -106,9 +105,7 @@ class SHPC_class:
return self._ishape_last[i_slice][orientation] return self._ishape_last[i_slice][orientation]
def get_reader(self, i_slice, layer, orientation = None): def get_reader(self, i_slice, layer, orientation):
if orientation is None: orientation = self.def_orient
if layer not in self._readers[i_slice][orientation]: if layer not in self._readers[i_slice][orientation]:
my_shapefile = path.join(self.dir, f"Slice_{i_slice}", orientation, my_shapefile = path.join(self.dir, f"Slice_{i_slice}", orientation,
layer) layer)
...@@ -123,9 +120,7 @@ class SHPC_class: ...@@ -123,9 +120,7 @@ class SHPC_class:
return self._readers[i_slice][orientation][layer] return self._readers[i_slice][orientation][layer]
def get_n_shapes(self, i_slice, orientation = None): def get_n_shapes(self, i_slice, orientation):
if orientation is None: orientation = self.def_orient
if self._n_shapes[i_slice][orientation] == 0: if self._n_shapes[i_slice][orientation] == 0:
reader = self.get_reader(i_slice, layer = "extremum", reader = self.get_reader(i_slice, layer = "extremum",
orientation = orientation) orientation = orientation)
...@@ -169,7 +164,7 @@ class SHPC_class: ...@@ -169,7 +164,7 @@ class SHPC_class:
assert i_slice >= 0 assert i_slice >= 0
return i_slice return i_slice
def comp_ishape(self, date, eddy_index, i_slice, orientation = None): def comp_ishape(self, date, eddy_index, i_slice, orientation):
"""Compute the location in the shapefiles.""" """Compute the location in the shapefiles."""
assert date >= self.d_init[i_slice] assert date >= self.d_init[i_slice]
......
...@@ -44,7 +44,8 @@ for layer in ["extremum", "outermost_contour", "max_speed_contour", "centroid"]: ...@@ -44,7 +44,8 @@ for layer in ["extremum", "outermost_contour", "max_speed_contour", "centroid"]:
print() print()
try: try:
shapeRec = SHPC.get_reader(0, layer).shapeRecord(ishape) shapeRec = SHPC.get_reader(0, layer, args.orientation)\
.shapeRecord(ishape)
except AttributeError: except AttributeError:
pass pass
else: else:
......
...@@ -38,21 +38,21 @@ def read_eddy_graph(edgelist, shpc_dir = None, orientation = "Cyclones"): ...@@ -38,21 +38,21 @@ def read_eddy_graph(edgelist, shpc_dir = None, orientation = "Cyclones"):
if shpc_dir is not None: if shpc_dir is not None:
# Read and set attributes of eddies: # Read and set attributes of eddies:
SHPC = util_eddies.SHPC_class(shpc_dir, orientation) SHPC = util_eddies.SHPC_class(shpc_dir, orientation)
set_attribute(G, SHPC) set_attribute(G, SHPC, orientation)
else: else:
print(edgelist, "not readable") print(edgelist, "not readable")
G = nx.DiGraph() G = nx.DiGraph()
return G return G
def set_attribute(G, SHPC): def set_attribute(G, SHPC, orientation):
reader = SHPC.get_reader(0, "extremum") reader = SHPC.get_reader(0, "extremum", orientation)
if G.number_of_nodes() <= SHPC.get_n_shapes(0) / 100: if G.number_of_nodes() <= SHPC.get_n_shapes(0, orientation) / 100:
for n in G: for n in G:
date_index, eddy_index = node_to_date_eddy(n, date_index, eddy_index = node_to_date_eddy(n,
G.graph["e_overestim"]) G.graph["e_overestim"])
ishape = SHPC.comp_ishape(date_index, eddy_index, 0) ishape = SHPC.comp_ishape(date_index, eddy_index, 0, orientation)
shape_rec = reader.shapeRecord(ishape) shape_rec = reader.shapeRecord(ishape)
G.add_node(n, coordinates = tuple(shape_rec.shape.points[0]), G.add_node(n, coordinates = tuple(shape_rec.shape.points[0]),
speed = shape_rec.record.speed, speed = shape_rec.record.speed,
......
...@@ -52,7 +52,7 @@ def calculate_radii_rossby(properties): ...@@ -52,7 +52,7 @@ def calculate_radii_rossby(properties):
if n_valid_Rossby != 0: avg_Rossby /= n_valid_Rossby if n_valid_Rossby != 0: avg_Rossby /= n_valid_Rossby
return avg_rad, avg_Rossby return avg_rad, avg_Rossby
def node_to_prop(node_list, e_overestim, SHPC): def node_to_prop(node_list, e_overestim, SHPC, orientation):
"""node_list is a list of node identification numbers for """node_list is a list of node identification numbers for
instantaneous eddies. This function returns some properties of the instantaneous eddies. This function returns some properties of the
eddies, read from shapefiles: position of extremum, radius of eddies, read from shapefiles: position of extremum, radius of
...@@ -66,14 +66,16 @@ def node_to_prop(node_list, e_overestim, SHPC): ...@@ -66,14 +66,16 @@ def node_to_prop(node_list, e_overestim, SHPC):
for n in node_list: for n in node_list:
date_index, eddy_index = report_graph.node_to_date_eddy(n, e_overestim) date_index, eddy_index = report_graph.node_to_date_eddy(n, e_overestim)
i_slice = SHPC.get_slice(date_index) i_slice = SHPC.get_slice(date_index)
ishape = SHPC.comp_ishape(date_index, eddy_index, i_slice) ishape = SHPC.comp_ishape(date_index, eddy_index, i_slice, orientation)
shapeRec = SHPC.get_reader(i_slice, "extremum").shapeRecord(ishape) shapeRec = SHPC.get_reader(i_slice, "extremum", orientation)\
.shapeRecord(ishape)
prop = {"pos": shapeRec.shape.points[0], "speed": shapeRec.record.speed} prop = {"pos": shapeRec.shape.points[0], "speed": shapeRec.record.speed}
prop["radius"] = SHPC.get_reader(i_slice, "max_speed_contour")\ prop["radius"] = SHPC.get_reader(i_slice, "max_speed_contour",
.record(ishape).r_eq_area orientation).record(ishape).r_eq_area
if prop["radius"] < 0: if prop["radius"] < 0:
prop["radius"] = SHPC.get_reader(i_slice, "outermost_contour")\ prop["radius"] = SHPC.get_reader(i_slice, "outermost_contour",
orientation)\
.record(ishape).r_eq_area .record(ishape).r_eq_area
properties.append(prop) properties.append(prop)
...@@ -129,7 +131,7 @@ for n in g.vertices(): ...@@ -129,7 +131,7 @@ for n in g.vertices():
if n.in_degree() != 0: if n.in_degree() != 0:
# Define properties for beginning of the segment: # Define properties for beginning of the segment:
properties = node_to_prop(g.vp.inst_eddies[n][:n_days_avg], e_overestim, properties = node_to_prop(g.vp.inst_eddies[n][:n_days_avg], e_overestim,
SHPC) SHPC, args.orientation)
g.vp.first_av_rad[n], g.vp.first_av_ros[n] \ g.vp.first_av_rad[n], g.vp.first_av_ros[n] \
= calculate_radii_rossby(properties) = calculate_radii_rossby(properties)
g.vp.pos_first[n] = properties[0]["pos"] # in degrees g.vp.pos_first[n] = properties[0]["pos"] # in degrees
...@@ -147,7 +149,7 @@ for n in g.vertices(): ...@@ -147,7 +149,7 @@ for n in g.vertices():
# We cannot use part of properties from the beginning # We cannot use part of properties from the beginning
# of the segment. # of the segment.
properties = node_to_prop(g.vp.inst_eddies[n][- n_days_avg:], properties = node_to_prop(g.vp.inst_eddies[n][- n_days_avg:],
e_overestim, SHPC) e_overestim, SHPC, args.orientation)
else: else:
# assertion: n.in_degree() != 0 and n_days_avg < # assertion: n.in_degree() != 0 and n_days_avg <
# len_seg < 2 * n_days_avg # len_seg < 2 * n_days_avg
...@@ -156,7 +158,7 @@ for n in g.vertices(): ...@@ -156,7 +158,7 @@ for n in g.vertices():
# of the segment. # of the segment.
properties = properties[len_seg - n_days_avg:] \ properties = properties[len_seg - n_days_avg:] \
+ node_to_prop(g.vp.inst_eddies[n][n_days_avg:], + node_to_prop(g.vp.inst_eddies[n][n_days_avg:],
e_overestim, SHPC) e_overestim, SHPC, args.orientation)
g.vp.last_av_rad[n], g.vp.last_av_ros[n] \ g.vp.last_av_rad[n], g.vp.last_av_ros[n] \
= calculate_radii_rossby(properties) = calculate_radii_rossby(properties)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
import report_graph import report_graph
import random import random
def get_extr_coord(traj, e_overestim, SHPC): def get_extr_coord(traj, e_overestim, SHPC, orientation):
x = [] x = []
y = [] y = []
...@@ -11,15 +11,17 @@ def get_extr_coord(traj, e_overestim, SHPC): ...@@ -11,15 +11,17 @@ def get_extr_coord(traj, e_overestim, SHPC):
date_index, eddy_index = report_graph.node_to_date_eddy(node, date_index, eddy_index = report_graph.node_to_date_eddy(node,
e_overestim) e_overestim)
i_slice = SHPC.get_slice(date_index) i_slice = SHPC.get_slice(date_index)
ishape = SHPC.comp_ishape(date_index, eddy_index, i_slice) ishape = SHPC.comp_ishape(date_index, eddy_index, i_slice, orientation)
shape = SHPC.get_reader(i_slice, layer = "extremum").shape(ishape) shape = SHPC.get_reader(i_slice, layer = "extremum",
orientation = orientation).shape(ishape)
x.append(shape.points[0][0]) x.append(shape.points[0][0])
y.append(shape.points[0][1]) y.append(shape.points[0][1])
return x, y return x, y
def plot_single_traj(traj, e_overestim, SHPC, ax, src_crs, annotate_flag): def plot_single_traj(traj, e_overestim, SHPC, orientation, ax, src_crs,
x, y = get_extr_coord(traj, e_overestim, SHPC) annotate_flag):
x, y = get_extr_coord(traj, e_overestim, SHPC, orientation)
ax.plot(x, y, color = "red", linewidth = 0.5, transform = src_crs) ax.plot(x, y, color = "red", linewidth = 0.5, transform = src_crs)
ax.plot(x[0], y[0], marker = "s", markersize = 2, color = "black", ax.plot(x[0], y[0], marker = "s", markersize = 2, color = "black",
transform = src_crs) transform = src_crs)
...@@ -75,8 +77,8 @@ if __name__ == "__main__": ...@@ -75,8 +77,8 @@ if __name__ == "__main__":
only_date = True) only_date = True)
if args.min_duration == 1 or duration >= args.min_duration: if args.min_duration == 1 or duration >= args.min_duration:
if args.min_duration > 1: n_long_traj += 1 if args.min_duration > 1: n_long_traj += 1
plot_single_traj(traj, e_overestim, SHPC, ax, src_crs, plot_single_traj(traj, e_overestim, SHPC, args.orientation, ax,
args.annotate) src_crs, args.annotate)
ax.add_feature(cfeature.LAND, edgecolor = "black") ax.add_feature(cfeature.LAND, edgecolor = "black")
ax.gridlines(draw_labels = True) ax.gridlines(draw_labels = 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