Paste #24

Welcome To LodgeIt

Welcome to the LodgeIt pastebin. In order to use the notification feature a 31 day cookie with an unique ID was created for you. The lodgeit database does not store any information about you, it's just used for an advanced pastebin experience :-). Read more on the about lodgeit page. Have fun :-)

hide this notification

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import yt

from yt.analysis_modules.halo_analysis.api import \
    HaloCatalog, add_callback

def append_profiles(halo):
    hc = halo.halo_catalog
    if not hasattr(hc, "profile_storage"):
        hc.profile_storage = dict((field, []) for field in halo.profiles)
    for field, profile in halo.profiles.items():
        hc.profile_storage[field].append(profile)

add_callback("append_profiles", append_profiles)

if __name__ == "__main__":
    dds = yt.load("DD0046/DD0046")
    hds = yt.load("rockstar_halos/halos_0.0.bin")
    hc = HaloCatalog(halos_ds=hds, data_ds=dds)
    hc.add_filter("quantity_value", "particle_mass", ">", 1e13, "Msun")
    hc.add_callback("sphere")
    hc.add_callback("profile", ["radius"], ["density"], n_bins=16)
    hc.add_callback("append_profiles")
    hc.create()

    # recombine profiles into arrays
    for field in hc.profile_storage:
        hc.profile_storage[field] = dds.arr(hc.profile_storage[field])

    yt.save_as_dataset(dds, "profiles.h5", hc.profile_storage)

    # ...later
    profds = yt.load("profiles.h5")
    print (profds.data["radius"])
    print (profds.data["density"])