Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import h5py
  2. import os
  3. import fnmatch
  4. from halotools.sim_manager import HaloTableCache
  5.  
  6. # %%
  7.  
  8. cache = HaloTableCache()
  9.  
  10.  
  11. def halo_table_fnames_in_standard_cache():
  12. """ Walk the directory tree of all subdirectories in
  13. $HOME/.astropy/cache/halotools/halo_catalogs and yield the absolute path
  14. to any file with a .hdf5 extension.
  15. """
  16. standard_loc = os.path.join(os.path.dirname(cache.cache_log_fname),
  17. 'halo_catalogs')
  18. if os.path.exists(standard_loc):
  19. for path, dirlist, filelist in os.walk(standard_loc):
  20. for name in fnmatch.filter(filelist, '*.hdf5'):
  21. yield os.path.abspath(os.path.join(path, name))
  22. # %%
  23.  
  24. fnames = list(halo_table_fnames_in_standard_cache())
  25. fnames_to_update = []
  26.  
  27. for fname in fnames:
  28. f = h5py.File(fname, 'r')
  29. if fname != f.attrs['fname']:
  30. print "File %s has invalide filename entry." % fname
  31. fnames_to_update.append(fname)
  32. f.close()
  33.  
  34. for fname in fnames_to_update:
  35. f = h5py.File(fname, 'r+')
  36. print "File %s will be updated." % fname
  37. f.attrs['fname'] = fname
  38. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement