Find total number of halos from an existing halo catalog

I am loading an existing halo catalog to create a DataSet object: import yt ds = yt.load("test_halo_catalog.h5") I then wish to use the all_data() method: ad = ds.all_data() But if the halo catalog contains zero halos, I get this error message: yt : [INFO ] 2024-04-26 14:06:04,162 Allocating for 0.000e+00 particles Traceback (most recent call last): File "~/hc_analysis.py", line 130, in <module> ad = ds.all_data() File "/home/hannah/anaconda3/envs/yt-rockstar/lib/python3.10/site-packages/yt/data_objects/static_output.py", line 1122, in all_data self.index File "/home/hannah/anaconda3/envs/yt-rockstar/lib/python3.10/site-packages/yt/data_objects/static_output.py", line 559, in index self._instantiated_index = self._index_class( File "/home/hannah/anaconda3/envs/yt-rockstar/lib/python3.10/site-packages/yt/geometry/particle_geometry_handler.py", line 27, in __init__ self._initialize_index() File "/home/hannah/anaconda3/envs/yt-rockstar/lib/python3.10/site-packages/yt/geometry/particle_geometry_handler.py", line 164, in _initialize_index self.regions = ParticleBitmap( File "yt/geometry/particle_oct_container.pyx", line 476, in yt.geometry.particle_oct_container.ParticleBitmap.__init__ TypeError: an integer is required It seems that all_data() only works if the halo catalog contains a nonzero integer number of halos. Is there a method for a DataSet object to determine the total number of halos found? I wish to implement something like this: if ds.total_halos != 0: ad = ds.all_data() else: print("No halos found in this halo catalog") Any help would be much appreciated, thank you! Kind regards, Hannah O'Brennan

Hi Hannah, I think this is possible! What I'm not sure of is the right place to implement it. Your line numbers don't agree with mine so I can't figure out specifically what is throwing the type error, *but*, I think it might be the number of files. Can you try looking at the contents of ds.file_count and see if that is 0? On Fri, Apr 26, 2024 at 8:10 AM hannah.obrennan.2021--- via yt-users < yt-users@python.org> wrote:
I am loading an existing halo catalog to create a DataSet object:
import yt ds = yt.load("test_halo_catalog.h5")
I then wish to use the all_data() method:
ad = ds.all_data()
But if the halo catalog contains zero halos, I get this error message:
yt : [INFO ] 2024-04-26 14:06:04,162 Allocating for 0.000e+00 particles Traceback (most recent call last): File "~/hc_analysis.py", line 130, in <module> ad = ds.all_data() File "/home/hannah/anaconda3/envs/yt-rockstar/lib/python3.10/site-packages/yt/data_objects/static_output.py", line 1122, in all_data self.index File "/home/hannah/anaconda3/envs/yt-rockstar/lib/python3.10/site-packages/yt/data_objects/static_output.py", line 559, in index self._instantiated_index = self._index_class( File "/home/hannah/anaconda3/envs/yt-rockstar/lib/python3.10/site-packages/yt/geometry/particle_geometry_handler.py", line 27, in __init__ self._initialize_index() File "/home/hannah/anaconda3/envs/yt-rockstar/lib/python3.10/site-packages/yt/geometry/particle_geometry_handler.py", line 164, in _initialize_index self.regions = ParticleBitmap( File "yt/geometry/particle_oct_container.pyx", line 476, in yt.geometry.particle_oct_container.ParticleBitmap.__init__ TypeError: an integer is required
It seems that all_data() only works if the halo catalog contains a nonzero integer number of halos. Is there a method for a DataSet object to determine the total number of halos found? I wish to implement something like this:
if ds.total_halos != 0: ad = ds.all_data()
else: print("No halos found in this halo catalog")
Any help would be much appreciated, thank you! Kind regards, Hannah O'Brennan _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org https://mail.python.org/mailman3/lists/yt-users.python.org/ Member address: matthewturk@gmail.com

Hi Matthew, Thank you for getting back to me so quickly. For me, ds.file_count returns 1 and this is the case if the corresponding halo catalog contains 0 halos or more halos. I also tried ds.particle_type_count. For a halo catalog with 20 halos, ds.particle_type_count returns {'halos', 20}. But for a halo catalog with no halos, I encounter the same error I had before with all_data(). Would you be aware of any other methods that could determine if a halo catalog contains zero halos? Thank you again. Kind regards, Hannah
participants (2)
-
hannah.obrennan.2021@mumail.ie
-
Matthew Turk