From b5ed95d13367c2e8ba641116c8b65b1a3afd2e44 Mon Sep 17 00:00:00 2001 From: Lionel GUEZ <guez@lmd.ens.fr> Date: Tue, 21 Mar 2023 18:14:58 +0100 Subject: [PATCH] Remove default value of argument orientation On second thought, I find the default value confusing. We are reverting commit b328ab6. --- Common/util_eddies.py | 17 ++++++----------- Inst_eddies/Analysis/eddy_dump.py | 3 ++- Overlap/report_graph.py | 10 +++++----- Trajectories/cost_function.py | 20 +++++++++++--------- Trajectories/plot_traj.py | 16 +++++++++------- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/Common/util_eddies.py b/Common/util_eddies.py index 0acb072d..62248e54 100644 --- a/Common/util_eddies.py +++ b/Common/util_eddies.py @@ -79,7 +79,8 @@ class SHPC_class: = self._ishape_last[i_slice]["Cyclones"].size else: 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: # Try the other orientation: orientation = other_orient(self.def_orient) @@ -88,9 +89,7 @@ class SHPC_class: return self._n_dates[i_slice] - def get_ishape_last(self, i_slice, orientation = None): - if orientation is None: orientation = self.def_orient - + def get_ishape_last(self, i_slice, orientation): if self._ishape_last[i_slice][orientation] is None: fname = path.join(self.dir, f"Slice_{i_slice}", orientation, "ishape_last.txt") @@ -106,9 +105,7 @@ class SHPC_class: return self._ishape_last[i_slice][orientation] - def get_reader(self, i_slice, layer, orientation = None): - if orientation is None: orientation = self.def_orient - + def get_reader(self, i_slice, layer, orientation): if layer not in self._readers[i_slice][orientation]: my_shapefile = path.join(self.dir, f"Slice_{i_slice}", orientation, layer) @@ -123,9 +120,7 @@ class SHPC_class: return self._readers[i_slice][orientation][layer] - def get_n_shapes(self, i_slice, orientation = None): - if orientation is None: orientation = self.def_orient - + def get_n_shapes(self, i_slice, orientation): if self._n_shapes[i_slice][orientation] == 0: reader = self.get_reader(i_slice, layer = "extremum", orientation = orientation) @@ -169,7 +164,7 @@ class SHPC_class: assert i_slice >= 0 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.""" assert date >= self.d_init[i_slice] diff --git a/Inst_eddies/Analysis/eddy_dump.py b/Inst_eddies/Analysis/eddy_dump.py index 1ee28756..709bd1de 100755 --- a/Inst_eddies/Analysis/eddy_dump.py +++ b/Inst_eddies/Analysis/eddy_dump.py @@ -44,7 +44,8 @@ for layer in ["extremum", "outermost_contour", "max_speed_contour", "centroid"]: print() try: - shapeRec = SHPC.get_reader(0, layer).shapeRecord(ishape) + shapeRec = SHPC.get_reader(0, layer, args.orientation)\ + .shapeRecord(ishape) except AttributeError: pass else: diff --git a/Overlap/report_graph.py b/Overlap/report_graph.py index 77af0f11..f501370a 100755 --- a/Overlap/report_graph.py +++ b/Overlap/report_graph.py @@ -38,21 +38,21 @@ def read_eddy_graph(edgelist, shpc_dir = None, orientation = "Cyclones"): if shpc_dir is not None: # Read and set attributes of eddies: SHPC = util_eddies.SHPC_class(shpc_dir, orientation) - set_attribute(G, SHPC) + set_attribute(G, SHPC, orientation) else: print(edgelist, "not readable") G = nx.DiGraph() return G -def set_attribute(G, SHPC): - reader = SHPC.get_reader(0, "extremum") +def set_attribute(G, SHPC, orientation): + 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: date_index, eddy_index = node_to_date_eddy(n, 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) G.add_node(n, coordinates = tuple(shape_rec.shape.points[0]), speed = shape_rec.record.speed, diff --git a/Trajectories/cost_function.py b/Trajectories/cost_function.py index fdd28179..6c4e827a 100755 --- a/Trajectories/cost_function.py +++ b/Trajectories/cost_function.py @@ -52,7 +52,7 @@ def calculate_radii_rossby(properties): if n_valid_Rossby != 0: avg_Rossby /= n_valid_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 instantaneous eddies. This function returns some properties of the eddies, read from shapefiles: position of extremum, radius of @@ -66,14 +66,16 @@ def node_to_prop(node_list, e_overestim, SHPC): for n in node_list: date_index, eddy_index = report_graph.node_to_date_eddy(n, e_overestim) i_slice = SHPC.get_slice(date_index) - ishape = SHPC.comp_ishape(date_index, eddy_index, i_slice) - shapeRec = SHPC.get_reader(i_slice, "extremum").shapeRecord(ishape) + ishape = SHPC.comp_ishape(date_index, eddy_index, i_slice, orientation) + shapeRec = SHPC.get_reader(i_slice, "extremum", orientation)\ + .shapeRecord(ishape) prop = {"pos": shapeRec.shape.points[0], "speed": shapeRec.record.speed} - prop["radius"] = SHPC.get_reader(i_slice, "max_speed_contour")\ - .record(ishape).r_eq_area + prop["radius"] = SHPC.get_reader(i_slice, "max_speed_contour", + orientation).record(ishape).r_eq_area 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 properties.append(prop) @@ -129,7 +131,7 @@ for n in g.vertices(): if n.in_degree() != 0: # Define properties for beginning of the segment: 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] \ = calculate_radii_rossby(properties) g.vp.pos_first[n] = properties[0]["pos"] # in degrees @@ -147,7 +149,7 @@ for n in g.vertices(): # We cannot use part of properties from the beginning # of the segment. properties = node_to_prop(g.vp.inst_eddies[n][- n_days_avg:], - e_overestim, SHPC) + e_overestim, SHPC, args.orientation) else: # assertion: n.in_degree() != 0 and n_days_avg < # len_seg < 2 * n_days_avg @@ -156,7 +158,7 @@ for n in g.vertices(): # of the segment. properties = properties[len_seg - 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] \ = calculate_radii_rossby(properties) diff --git a/Trajectories/plot_traj.py b/Trajectories/plot_traj.py index e0dc3c13..3898e483 100755 --- a/Trajectories/plot_traj.py +++ b/Trajectories/plot_traj.py @@ -3,7 +3,7 @@ import report_graph import random -def get_extr_coord(traj, e_overestim, SHPC): +def get_extr_coord(traj, e_overestim, SHPC, orientation): x = [] y = [] @@ -11,15 +11,17 @@ def get_extr_coord(traj, e_overestim, SHPC): date_index, eddy_index = report_graph.node_to_date_eddy(node, e_overestim) i_slice = SHPC.get_slice(date_index) - ishape = SHPC.comp_ishape(date_index, eddy_index, i_slice) - shape = SHPC.get_reader(i_slice, layer = "extremum").shape(ishape) + ishape = SHPC.comp_ishape(date_index, eddy_index, i_slice, orientation) + shape = SHPC.get_reader(i_slice, layer = "extremum", + orientation = orientation).shape(ishape) x.append(shape.points[0][0]) y.append(shape.points[0][1]) return x, y -def plot_single_traj(traj, e_overestim, SHPC, ax, src_crs, annotate_flag): - x, y = get_extr_coord(traj, e_overestim, SHPC) +def plot_single_traj(traj, e_overestim, SHPC, orientation, ax, src_crs, + 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[0], y[0], marker = "s", markersize = 2, color = "black", transform = src_crs) @@ -75,8 +77,8 @@ if __name__ == "__main__": only_date = True) if args.min_duration == 1 or duration >= args.min_duration: if args.min_duration > 1: n_long_traj += 1 - plot_single_traj(traj, e_overestim, SHPC, ax, src_crs, - args.annotate) + plot_single_traj(traj, e_overestim, SHPC, args.orientation, ax, + src_crs, args.annotate) ax.add_feature(cfeature.LAND, edgecolor = "black") ax.gridlines(draw_labels = True) -- GitLab