Skip to content

Commit

Permalink
A little more refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadair committed Oct 28, 2024
1 parent 9f2baa3 commit 516f7a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions dkist/io/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,13 @@ def __init__(
self.dtype = dtype
self.target = target
self._loader = loader
self._basepath = None
self.basepath = basepath # Use the setter to convert to a Path
self._basepath = self._sanitize_basepath(basepath)
self.chunksize = chunksize
self._fileuri_array = np.atleast_1d(np.array(fileuris))

loader_array = np.empty_like(self._fileuri_array, dtype=object)
for i, fileuri in enumerate(self._fileuri_array.flat):
loader_array.flat[i] = loader(fileuri, shape, dtype, target, self)
loader_array.flat[i] = loader(fileuri, shape, dtype, target, self.basepath)

self._loader_array = loader_array

Expand All @@ -125,13 +124,15 @@ def basepath(self) -> os.PathLike:
"""
return self._basepath

@staticmethod
def _sanitize_basepath(value):
return Path(value).expanduser() if value is not None else None

@basepath.setter
def basepath(self, value: os.PathLike | str | None):
self._basepath = Path(value).expanduser() if value is not None else None
if hasattr(self, '_loader_array'):
# We get called during __init__ before _loader_array is created
for loader in self._loader_array.flat:
loader.basepath = self._basepath
self._basepath = self._sanitize_basepath(value)
for loader in self._loader_array.flat:
loader.basepath = self._basepath

@property
def fileuri_array(self) -> NDArray[str]:
Expand Down
4 changes: 2 additions & 2 deletions dkist/io/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ class BaseFITSLoader(metaclass=abc.ABCMeta):
time.
"""

def __init__(self, fileuri, shape, dtype, target, array_container):
def __init__(self, fileuri, shape, dtype, target, basepath):
self.fileuri = fileuri
self.shape = shape
self.dtype = dtype
self.target = target
self.basepath = array_container.basepath
self.basepath = basepath
self.ndim = len(self.shape)
self.size = np.prod(self.shape)

Expand Down

0 comments on commit 516f7a8

Please sign in to comment.