astropy / halotools

Python package for studying large scale structure, cosmology, and galaxy evolution using N-body simulations and halo models
http://halotools.rtfd.org
BSD 3-Clause "New" or "Revised" License
104 stars 65 forks source link

How to add attribute 'cosmology' to halo catalog built by 'halotools.sim_manager.RockstarHlistReader()'? #1103

Closed Sherlockids closed 1 month ago

Sherlockids commented 1 month ago

SMDPL is not provided in the halotools.empirical_models.PrebuiltHodModelFactory(), so I build a SMDPL halo catalog via halotools.sim_manager.RockstarHlistReader():

from astropy.cosmology import Planck13
reader = RockstarHlistReader(input_fname, columns_to_keep_dict, output_fname, simname, halo_finder, redshift,\
                              version_name, Lbox, particle_mass, overwrite=True, cosmology = Planck13) 
reader.read_halocat(columns_to_convert_from_kpc_to_mpc = ['halo_rvir', 'halo_rs'] ,write_to_disk = True,\
                             update_cache_log = True) 

But there is no attribute 'cosmology' in the output:

halocat = CachedHaloCatalog(simname = 'SMDPL', halo_finder='rockstar', version_name='rockstar', redshift = 0.)
halocat.cosmology

>>> AttributeError: 'CachedHaloCatalog' object has no attribute 'cosmology'

image

I want to ask how can I add attribute 'cosmology' into the output, since halotools.sim_manager.RockstarHlistReader() do not accept such a parameter.

image

### Tasks
aphearin commented 1 month ago

The attributes bound to the reader were really only intended to disambiguate one simulation from the next, to avoid collisions between multiple halo catalogs, and so cosmology is not an attribute of the CachedHaloCatalog class. If you'd like to have cosmology attached to a CachedHaloCatalog instance, probably the simplest thing is to just write a wrapper that inherits from CachedHaloCatalog and adds this attribute.

Sherlockids commented 1 month ago

Thanks a lot.