-
Notifications
You must be signed in to change notification settings - Fork 0
Saving and Loading Particles
This page goes through the example found in path/to/GROUPy/examples/io/saving_loading_halos.py. This will give a basic tutorial on how to save and load halo files. The particle saving/loading mechanism is almost identical, but instead of using load_halo, use load_particle.
This is a self-contained example, so you do not need to generate test data beforehand. To run the example script, type the following into your terminal:
cd path/to/GROUPy/examples/io
python saving_loading_halos.py
If everything runs correctly, there should be the following output:
True
Now for what the example actually does...
First import the Halo library, along with the os library, which is used to create the directory we save the halo into:
import os
from Halo import load_halo
This section creates the output directory and specifies what we will call the file
save_dir = "save_output/"
if not os.path.exists(save_dir): os.mkdir(save_dir)
save_name = os.path.join(save_dir, "halo.npy")
Here we instantiate the halo and add some dummy data:
h = Halo()
h.ids = [1, 2, 3, 4]
h.x = [1, 2, 3, 4]
Now we save the halo to the desired file name.
h.save(save_name)
h2 = load_halo(save_name)
For a sanity check, see if the loaded halo and the original halo have the same id list:
print(h2.ids == h.ids)
This should output True