From 18fc2bc752146ee55a793e989e35dd72388c50dc Mon Sep 17 00:00:00 2001 From: Kyle Oman Date: Wed, 21 Aug 2024 17:13:31 +0100 Subject: [PATCH 1/7] Updates after changes in swiftsimio/metadata/particle/particle_types.py --- velociraptor/swift/swift.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/velociraptor/swift/swift.py b/velociraptor/swift/swift.py index 126b69a..1bb0ac1 100644 --- a/velociraptor/swift/swift.py +++ b/velociraptor/swift/swift.py @@ -5,7 +5,6 @@ datasets in a computationally efficient way. """ - import swiftsimio import numpy as np @@ -98,7 +97,7 @@ def generate_bound_mask( particle_name_masks = {} - for particle_name in data.metadata.present_particle_names: + for particle_name in data.metadata.present_group_names: # This will change if we ever take advantage of the # parttypes available through velociraptor. particle_name_masks[particle_name] = np.in1d( @@ -107,7 +106,7 @@ def generate_bound_mask( # Finally we generate a named tuple with the correct fields and # fill it with the contents of our dictionary - MaskTuple = namedtuple("MaskCollection", data.metadata.present_particle_names) + MaskTuple = namedtuple("MaskCollection", data.metadata.present_group_names) mask = MaskTuple(**particle_name_masks) return mask From 8d9169e2bc39f1f3b8c573c8e714509b08eaf2a4 Mon Sep 17 00:00:00 2001 From: Kyle Oman Date: Wed, 21 Aug 2024 17:22:31 +0100 Subject: [PATCH 2/7] Installation breaks with setup.py present, pyproject.toml alone succeeds. --- setup.py | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 setup.py diff --git a/setup.py b/setup.py deleted file mode 100644 index 8c28f45..0000000 --- a/setup.py +++ /dev/null @@ -1,27 +0,0 @@ -import setuptools -from velociraptor import __version__ - -with open("README.md", "r") as fh: - long_description = fh.read() - -setuptools.setup( - name="velociraptor", - version=__version__, - description="Velociraptor catalogue reading routines.", - url="https://github.com/swiftsim/velociraptor-python", - author="Josh Borrow", - author_email="joshua.borrow@durham.ac.uk", - packages=setuptools.find_packages(), - scripts=["velociraptor-plot"], - long_description=long_description, - long_description_content_type="text/markdown", - zip_safe=False, - classifiers=[ - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)", - "Operating System :: OS Independent", - ], - install_requires=["numpy", "unyt>=2.6.0", "h5py", "astropy"], -) From 7e9acc31852ca11bdedd4e71b38af111ec050f74 Mon Sep 17 00:00:00 2001 From: Kyle Oman Date: Wed, 21 Aug 2024 17:46:03 +0100 Subject: [PATCH 3/7] Add missing submodules to pyproject.toml. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 149b108..a3864ea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["setuptools>=61.0"] build-backend = "setuptools.build_meta" [tool.setuptools] -packages = ["velociraptor"] +packages = ["velociraptor", "velociraptor.catalogue", "velociraptor.fitting_formulae", "velociraptor.observations", "velociraptor.autoplotter", "velociraptor.particles", "velociraptor.swift", "velociraptor.tools"] [project] name = "velociraptor-python" From 10cd24027bd915c3b2ae1d7b5f41f6e37f119347 Mon Sep 17 00:00:00 2001 From: Kyle Oman Date: Tue, 8 Oct 2024 10:30:49 +0100 Subject: [PATCH 4/7] Handle the case of an unsorted integer mask array. --- .../catalogue/velociraptor_catalogue.py | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/velociraptor/catalogue/velociraptor_catalogue.py b/velociraptor/catalogue/velociraptor_catalogue.py index d4c4f2d..09b8c19 100644 --- a/velociraptor/catalogue/velociraptor_catalogue.py +++ b/velociraptor/catalogue/velociraptor_catalogue.py @@ -117,9 +117,25 @@ def getter(self): with h5py.File(filename, "r") as handle: try: mask = getattr(self, "mask") - setattr( - self, f"_{name}", unyt.unyt_array(handle[field][mask], unit) - ) + if mask is Ellipsis: + setattr( + self, + f"_{name}", + unyt.unyt_array(handle[field][mask], unit), + ) + else: + # The mask might not be sorted, but hdf5 demands that + # it be. We sort, read and then reverse the sort. + sort_mask = np.argsort(mask) + unsort_mask = np.argsort(sort_mask) + setattr( + self, + f"_{name}", + unyt.unyt_array( + handle[field][mask[sort_mask]][unsort_mask], + unit, + ), + ) getattr(self, f"_{name}").name = full_name getattr(self, f"_{name}").file = filename except KeyError: From b1dfde95e87d02e262ec24c0e6fac79863c52bc2 Mon Sep 17 00:00:00 2001 From: Kyle Oman Date: Tue, 8 Oct 2024 10:43:17 +0100 Subject: [PATCH 5/7] Handle unsorted integer mask array separately from any other mask type. --- .../catalogue/velociraptor_catalogue.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/velociraptor/catalogue/velociraptor_catalogue.py b/velociraptor/catalogue/velociraptor_catalogue.py index 09b8c19..7c4f86a 100644 --- a/velociraptor/catalogue/velociraptor_catalogue.py +++ b/velociraptor/catalogue/velociraptor_catalogue.py @@ -117,13 +117,10 @@ def getter(self): with h5py.File(filename, "r") as handle: try: mask = getattr(self, "mask") - if mask is Ellipsis: - setattr( - self, - f"_{name}", - unyt.unyt_array(handle[field][mask], unit), - ) - else: + if np.ndim(mask) != 0 and np.issubdtype( + np.array(mask).dtype, np.integer + ): + # We have a mask picking out items by index. # The mask might not be sorted, but hdf5 demands that # it be. We sort, read and then reverse the sort. sort_mask = np.argsort(mask) @@ -136,6 +133,12 @@ def getter(self): unit, ), ) + else: + setattr( + self, + f"_{name}", + unyt.unyt_array(handle[field][mask], unit), + ) getattr(self, f"_{name}").name = full_name getattr(self, f"_{name}").file = filename except KeyError: From 53c96f89ed16de31023d8230770d799eb26efac3 Mon Sep 17 00:00:00 2001 From: Kyle Oman Date: Tue, 8 Oct 2024 10:47:05 +0100 Subject: [PATCH 6/7] Only handle sorting mask if it needs to be. --- velociraptor/catalogue/velociraptor_catalogue.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/velociraptor/catalogue/velociraptor_catalogue.py b/velociraptor/catalogue/velociraptor_catalogue.py index 7c4f86a..1d5a9e7 100644 --- a/velociraptor/catalogue/velociraptor_catalogue.py +++ b/velociraptor/catalogue/velociraptor_catalogue.py @@ -117,12 +117,14 @@ def getter(self): with h5py.File(filename, "r") as handle: try: mask = getattr(self, "mask") - if np.ndim(mask) != 0 and np.issubdtype( - np.array(mask).dtype, np.integer + if ( + np.ndim(mask) != 0 + and np.issubdtype(np.array(mask).dtype, np.integer) + and np.all(mask[:-1] < mask[1:]) ): - # We have a mask picking out items by index. - # The mask might not be sorted, but hdf5 demands that - # it be. We sort, read and then reverse the sort. + # We have a mask picking out items by index, and it's + # not sorted. hdf5 demands that it be sorted. + # We sort, read and then reverse the sort. sort_mask = np.argsort(mask) unsort_mask = np.argsort(sort_mask) setattr( From a12c933bec734ccb09065127b84be5a20586b809 Mon Sep 17 00:00:00 2001 From: Kyle Oman Date: Tue, 8 Oct 2024 10:48:17 +0100 Subject: [PATCH 7/7] Missing a logical not... --- velociraptor/catalogue/velociraptor_catalogue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/velociraptor/catalogue/velociraptor_catalogue.py b/velociraptor/catalogue/velociraptor_catalogue.py index 1d5a9e7..60200b8 100644 --- a/velociraptor/catalogue/velociraptor_catalogue.py +++ b/velociraptor/catalogue/velociraptor_catalogue.py @@ -120,7 +120,7 @@ def getter(self): if ( np.ndim(mask) != 0 and np.issubdtype(np.array(mask).dtype, np.integer) - and np.all(mask[:-1] < mask[1:]) + and not np.all(mask[:-1] < mask[1:]) ): # We have a mask picking out items by index, and it's # not sorted. hdf5 demands that it be sorted.