Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import h5py
- import os
- import fnmatch
- from halotools.sim_manager import HaloTableCache
- # %%
- cache = HaloTableCache()
- def halo_table_fnames_in_standard_cache():
- """ Walk the directory tree of all subdirectories in
- $HOME/.astropy/cache/halotools/halo_catalogs and yield the absolute path
- to any file with a .hdf5 extension.
- """
- standard_loc = os.path.join(os.path.dirname(cache.cache_log_fname),
- 'halo_catalogs')
- if os.path.exists(standard_loc):
- for path, dirlist, filelist in os.walk(standard_loc):
- for name in fnmatch.filter(filelist, '*.hdf5'):
- yield os.path.abspath(os.path.join(path, name))
- # %%
- fnames = list(halo_table_fnames_in_standard_cache())
- fnames_to_update = []
- for fname in fnames:
- f = h5py.File(fname, 'r')
- if fname != f.attrs['fname']:
- print "File %s has invalide filename entry." % fname
- fnames_to_update.append(fname)
- f.close()
- for fname in fnames_to_update:
- f = h5py.File(fname, 'r+')
- print "File %s will be updated." % fname
- f.attrs['fname'] = fname
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement