diff --git a/Common/util_eddies.py b/Common/util_eddies.py index f070b3a89b825882afffc0f06b6254bd8bde1af9..bb575604c74193e662144d73fc09d4d7746391fa 100644 --- a/Common/util_eddies.py +++ b/Common/util_eddies.py @@ -89,7 +89,6 @@ class SHPC_class: self.d_init.append(d_init_slice) - self._n_dates = np.zeros(self.n_slices, dtype=int) self._ishape_last = [ {"Anticyclones": None, "Cyclones": None} for i in range(self.n_slices) @@ -103,43 +102,14 @@ class SHPC_class: # We only need ishape_last for the last slice, for one # orientation, in order to define n_dates: - self.get_ishape_last(self.n_slices - 1, self.def_orient) + ishape_last = self.get_ishape_last(self.n_slices - 1, self.def_orient) + + self.n_dates = np.ediff1d(self.d_init, to_end=ishape_last.size) self._n_shapes = [ {"Anticyclones": 0, "Cyclones": 0} for i in range(self.n_slices) ] - def get_n_dates(self, i_slice): - """Return the number of dates in a given slice, including missing - dates. That is last date in the slice minus first date in the - slice plus one. - - """ - - if self._n_dates[i_slice] == 0: - # Find out the number of dates in the slice: - if self._ishape_last[i_slice]["Anticyclones"] is not None: - self._n_dates[i_slice] = self._ishape_last[i_slice][ - "Anticyclones" - ].size - elif self._ishape_last[i_slice]["Cyclones"] is not None: - self._n_dates[i_slice] = self._ishape_last[i_slice][ - "Cyclones" - ].size - else: - try: - 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) - self._n_dates[i_slice] = self.get_ishape_last( - i_slice, orientation - ).size - - return self._n_dates[i_slice] - def get_ishape_last(self, i_slice, orientation): """Defines and returns self._ishape_last[i_slice][orientation], which is a numpy array. Can return None if ishape_last.txt does not diff --git a/Inst_eddies/Analysis/anim_eddy_contours.py b/Inst_eddies/Analysis/anim_eddy_contours.py index a3688d03c4a2f2d2edd32440f9570c1525732298..f28b106bd6d661cfa000b5112a676eefc6cbaaa9 100755 --- a/Inst_eddies/Analysis/anim_eddy_contours.py +++ b/Inst_eddies/Analysis/anim_eddy_contours.py @@ -144,12 +144,12 @@ if __name__ == "__main__": not SHPC.d_init[0] <= d_min < d_max - <= SHPC.d_init[-1] + SHPC.get_n_dates(SHPC.n_slices - 1) - 1 + <= SHPC.d_init[-1] + SHPC.n_dates[SHPC.n_slices - 1] - 1 ): sys.exit("Bad dates specified") else: d_min = SHPC.d_init[0] - d_max = SHPC.d_init[0] + SHPC.get_n_dates(0) - 1 + d_max = SHPC.d_init[0] + SHPC.n_dates[0] - 1 # -- fig = plt.figure()