diff --git a/Common/util_eddies.py b/Common/util_eddies.py index e98d5baf70bac586099c5d51ef3ef9782e382bce..cd39e6f4ab1e528631ffe571b6ee68a796295203 100644 --- a/Common/util_eddies.py +++ b/Common/util_eddies.py @@ -160,7 +160,9 @@ class SHPC_class: except OSError: print("Could not read", fname) print("Creating it...") - self._create_ishape_last(i_slice, orientation) + self._ishape_last[i_slice][ + orientation + ] = self._create_ishape_last(i_slice, orientation) if self._ishape_last[i_slice][orientation] is not None: assert self._ishape_last[i_slice][orientation].size != 0 @@ -195,9 +197,8 @@ class SHPC_class: return self._n_shapes[i_slice][orientation] def _create_ishape_last(self, i_slice, orientation): - """Defines self._ishape_last[i_slice][orientation], which is a numpy - array, and creates the file ishape_last.txt. Can fail if it - cannot get a reader. + """Creates the file ishape_last.txt and returns the corresponding + numpy array. Returns None if it cannot get a reader. """ @@ -207,6 +208,7 @@ class SHPC_class: if reader is None: print('Could not create "ishape_last.txt".') + ishape_last = None else: for ishape, rec in enumerate(reader.iterRecords(fields=["date"])): if rec.date != last_date: @@ -225,13 +227,13 @@ class SHPC_class: for repet_factor, ishape in date_ishape: ishape_last.extend(repet_factor * [ishape]) - self._ishape_last[i_slice][orientation] = np.array(ishape_last) + ishape_last = np.array(ishape_last) fname = path.join( self.dir, f"Slice_{i_slice}", orientation, "ishape_last.txt" ) - np.savetxt( - fname, self._ishape_last[i_slice][orientation], fmt="%.0d" - ) + np.savetxt(fname, ishape_last, fmt="%.0d") + + return ishape_last def get_slice(self, date_index): i_slice = bisect.bisect(self.d_init, date_index) - 1