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

Do not define `self._ishape_last`

Do not define `self._ishape_last[i_slice][orientation]` in
`_create_ishape_last`. Return a numpy array instead. Clearer.
parent 85cc824f
No related branches found
No related tags found
No related merge requests found
...@@ -160,7 +160,9 @@ class SHPC_class: ...@@ -160,7 +160,9 @@ class SHPC_class:
except OSError: except OSError:
print("Could not read", fname) print("Could not read", fname)
print("Creating it...") 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: if self._ishape_last[i_slice][orientation] is not None:
assert self._ishape_last[i_slice][orientation].size != 0 assert self._ishape_last[i_slice][orientation].size != 0
...@@ -195,9 +197,8 @@ class SHPC_class: ...@@ -195,9 +197,8 @@ class SHPC_class:
return self._n_shapes[i_slice][orientation] return self._n_shapes[i_slice][orientation]
def _create_ishape_last(self, i_slice, orientation): def _create_ishape_last(self, i_slice, orientation):
"""Defines self._ishape_last[i_slice][orientation], which is a numpy """Creates the file ishape_last.txt and returns the corresponding
array, and creates the file ishape_last.txt. Can fail if it numpy array. Returns None if it cannot get a reader.
cannot get a reader.
""" """
...@@ -207,6 +208,7 @@ class SHPC_class: ...@@ -207,6 +208,7 @@ class SHPC_class:
if reader is None: if reader is None:
print('Could not create "ishape_last.txt".') print('Could not create "ishape_last.txt".')
ishape_last = None
else: else:
for ishape, rec in enumerate(reader.iterRecords(fields=["date"])): for ishape, rec in enumerate(reader.iterRecords(fields=["date"])):
if rec.date != last_date: if rec.date != last_date:
...@@ -225,13 +227,13 @@ class SHPC_class: ...@@ -225,13 +227,13 @@ class SHPC_class:
for repet_factor, ishape in date_ishape: for repet_factor, ishape in date_ishape:
ishape_last.extend(repet_factor * [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( fname = path.join(
self.dir, f"Slice_{i_slice}", orientation, "ishape_last.txt" self.dir, f"Slice_{i_slice}", orientation, "ishape_last.txt"
) )
np.savetxt( np.savetxt(fname, ishape_last, fmt="%.0d")
fname, self._ishape_last[i_slice][orientation], fmt="%.0d"
) return ishape_last
def get_slice(self, date_index): def get_slice(self, date_index):
i_slice = bisect.bisect(self.d_init, date_index) - 1 i_slice = bisect.bisect(self.d_init, date_index) - 1
......
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