From d4d5a7ccc47322bcba22a643dfe9b695d6e0bfc1 Mon Sep 17 00:00:00 2001 From: robjmcgibbon Date: Wed, 20 May 2026 13:27:47 +0100 Subject: [PATCH] Change attribute reading --- .gitignore | 1 + SOAP/catalogue_readers/read_hbtplus.py | 8 ++++---- SOAP/core/halo_tasks.py | 2 +- pyproject.toml | 2 +- requirements.txt | 2 +- tests/dummy_halo_generator.py | 5 +++++ 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 914afcd6..707095ce 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ tests/FLAMINGO/test_parameters.yml tests/COLIBRE/test_parameters.yml tests/test_SO_radius_*.png test_data/* +test_SO_radius*png diff --git a/SOAP/catalogue_readers/read_hbtplus.py b/SOAP/catalogue_readers/read_hbtplus.py index 4dff8d93..b54c2047 100644 --- a/SOAP/catalogue_readers/read_hbtplus.py +++ b/SOAP/catalogue_readers/read_hbtplus.py @@ -33,7 +33,7 @@ def read_hbtplus_groupnr(basename, read_potential_energies=False, registry=None) if comm_rank == 0: if os.path.exists(hbt_filename(basename, 0)): with h5py.File(hbt_filename(basename, 0), "r") as infile: - nr_files = int(infile["NumberOfFiles"][...]) + nr_files = infile["NumberOfFiles"][0] sorted_file = False elif os.path.exists(basename): with h5py.File(basename, "r") as infile: @@ -241,9 +241,9 @@ def read_hbtplus_catalogue( have_units = False with h5py.File(filename, "r") as infile: if "Units" in infile: - LengthInMpch = float(infile["Units/LengthInMpch"][...]) - MassInMsunh = float(infile["Units/MassInMsunh"][...]) - VelInKmS = float(infile["Units/VelInKmS"][...]) + LengthInMpch = infile["Units/LengthInMpch"][0] + MassInMsunh = infile["Units/MassInMsunh"][0] + VelInKmS = infile["Units/VelInKmS"][0] have_units = True # Otherwise, will have to read the Parameters.log file if not (have_units): diff --git a/SOAP/core/halo_tasks.py b/SOAP/core/halo_tasks.py index 0261771c..6cb76e52 100644 --- a/SOAP/core/halo_tasks.py +++ b/SOAP/core/halo_tasks.py @@ -354,7 +354,7 @@ def process_halos( next_task.win.Lock(0) next_task.win.Fetch_and_op(one, task_to_do, 0) next_task.win.Unlock(0) - task_to_do = int(task_to_do) + task_to_do = int(task_to_do.flat[0]) # Execute the task, if there's one left if task_to_do < nr_halos: diff --git a/pyproject.toml b/pyproject.toml index 3704b2a2..9d22b7d8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" [project] name = "SOAP" -version = "0.1.1" +version = "0.1.2" description = "MPI parallel Python code to compute properties of halos in SWIFT n-body simulations" readme = "README.md" requires-python = ">=3.10" diff --git a/requirements.txt b/requirements.txt index 6cf2915d..461cebf0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ mpi4py h5py -numpy>=2,<2.4 +numpy>=2 unyt>=3 astropy>=6 scipy diff --git a/tests/dummy_halo_generator.py b/tests/dummy_halo_generator.py index 73e36aa8..a726da1f 100644 --- a/tests/dummy_halo_generator.py +++ b/tests/dummy_halo_generator.py @@ -213,6 +213,7 @@ def __init__(self): "BirthTemperatures", "SmoothedElementMassFractions", "IronMassFractionsFromSNIa", + "BirthHaloCatalogueIndex", ], "PartType5": [ "Coordinates", @@ -1170,6 +1171,10 @@ def get_random_halo( data["PartType4"]["GroupNr_all"] = groupnr_all[star_mask] data["PartType4"]["GroupNr_bound"] = groupnr_bound[star_mask] data["PartType4"]["FOFGroupIDs"] = fof_group_ids[star_mask] + # Some in-situ stars, some ex-situ + data["PartType4"]["BirthHaloCatalogueIndex"] = groupnr_bound[star_mask] + mask = np.random.random(Nstar) < 0.1 + data["PartType4"]["BirthHaloCatalogueIndex"][mask] = -1 # initial masses are always larger than the actual mass data["PartType4"]["InitialMasses"] = unyt.unyt_array( mass[star_mask].value * (1.0 + np.random.random(Nstar)),