diff --git a/csiborgtools/read/readsim.py b/csiborgtools/read/readsim.py index d7bc7a7..dcc1b5f 100644 --- a/csiborgtools/read/readsim.py +++ b/csiborgtools/read/readsim.py @@ -16,7 +16,7 @@ Functions to read in the particle and clump files. """ from abc import ABC, abstractmethod -from os.path import isfile, join +from os.path import isfile, join, getsize from warnings import warn import numpy @@ -329,10 +329,15 @@ class CSiBORGReader(BaseReader): fname = join(self.paths.snapshots(nsim, "csiborg", tonew=False), "output_{}".format(nsnap), "clump_{}.dat".format(nsnap)) - if not isfile(fname): - raise FileExistsError("Clump file `{}` does not exist." - .format(fname)) + + if not isfile(fname) or getsize(fname) == 0: + raise FileExistsError(f"Clump file `{fname}` does not exist.") + data = numpy.genfromtxt(fname) + + if data.ndim == 1: + raise FileExistsError(f"Invalid clump file `{fname}`.") + # How the data is stored in the clump file. clump_cols = {"index": (0, numpy.int32), "level": (1, numpy.int32), diff --git a/scripts/sort_initsnap.py b/scripts/sort_initsnap.py index bbc00c7..e035db7 100644 --- a/scripts/sort_initsnap.py +++ b/scripts/sort_initsnap.py @@ -327,8 +327,12 @@ def make_phew_halo_catalogue(nsim, find_ultimate_parent, verbose): f.close() for nsnap in tqdm(snapshots, disable=not verbose, desc="Snapshot"): - data = reader.read_phew_clumps(nsnap, nsim, find_ultimate_parent=False, - verbose=False) + try: + data = reader.read_phew_clumps( + nsnap, nsim, find_ultimate_parent=find_ultimate_parent, + verbose=False) + except FileExistsError: + continue with h5py.File(fname, "r+") as f: grp = f.create_group(str(nsnap)) @@ -364,7 +368,7 @@ def main(nsim, args): calculate_initial(nsim, args.simname, args.halofinder, True) if args.make_phew: - make_phew_halo_catalogue(nsim, True, True) + make_phew_halo_catalogue(nsim, False, True) if __name__ == "__main__":