Skip to content

Commit

Permalink
change default behaviour of from_file and read methods
Browse files Browse the repository at this point in the history
  • Loading branch information
daviesje committed Sep 19, 2024
1 parent f6e727b commit 0dc75a2
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/py21cmfast/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ def read(
self,
direc: Union[str, Path, None] = None,
fname: Union[str, Path, None, h5py.File, h5py.Group] = None,
keys: Optional[Sequence[str]] = None,
keys: Optional[Sequence[str]] = [],
):
"""
Try find and read existing boxes from cache, which match the parameters of this instance.
Expand All @@ -1149,15 +1149,17 @@ def read(
The filename to read. By default, use the filename associated with this
object. Can be an open h5py File or Group, which will be directly written to.
keys
The names of boxes to read in (can be a subset). By default, read everything.
The names of boxes to read in (can be a subset). By default, read nothing.
If `None` is explicitly passed, read everything
"""
if not isinstance(fname, (h5py.File, h5py.Group)):
pth = self._get_path(direc, fname)
fl = h5py.File(pth, "r")
else:
fl = fname

keys = keys or []
if keys is None:
keys = self._array_structure
try:
try:
boxes = fl[self._name]
Expand Down Expand Up @@ -1214,9 +1216,8 @@ def from_file(
cls,
fname,
direc=None,
load_data=True,
h5_group: Union[str, None] = None,
arrays_to_load=None,
arrays_to_load=[],
):
"""Create an instance from a file on disk.
Expand All @@ -1227,12 +1228,13 @@ def from_file(
direc : str, optional
The directory from which fname is relative to (if it is relative). By
default, will be the cache directory in config.
load_data : bool, optional
Whether to read in the data when creating the instance. If False, a bare
instance is created with input parameters -- the instance can read data
with the :func:`read` method.
h5_group
The path to the group within the file in which the object is stored.
arrays_to_load : list of str, optional
A list of array names to load into memory
If the list is empty (default), a bare instance is created with input parameters
-- the instance can read data with the :func:`read` method.
If `None` is explicitly passed, all arrays are loaded into memory
"""
direc = path.expanduser(direc or config["direc"])

Expand All @@ -1245,9 +1247,6 @@ def from_file(
else:
self = cls(**cls._read_inputs(fl))

if not load_data:
arrays_to_load = []

if h5_group is not None:
with h5py.File(fname, "r") as fl:
self.read(fname=fl[h5_group], keys=arrays_to_load)
Expand Down

0 comments on commit 0dc75a2

Please sign in to comment.