Skip to content

Commit

Permalink
Add homogeneous attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
robjmcgibbon committed Sep 19, 2024
1 parent 19dc97e commit 790c97e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions swiftsimio/masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,17 @@ def constrain_index(self, index: int):
"""
Constrain the mask to a single row.
Intended for use with SOAP catalogues, mask to read only a single row.
Intended for use with halo catalogues, mask to read only a single row.
Parameters
----------
index : int
The index of the row to select.
"""
if not self.metadata.filetype == "SOAP":
warnings.warn("Not masking a SOAP catalogue, nothing constrained.")
if not self.metadata.homogeneous_arrays:
warnings.warn(
"Different datasets correspond to different objects, nothing constrained."
)
return
for group_name in self.metadata.present_group_names:
setattr(self, group_name, np.array([[index, index + 1]]))
Expand Down
7 changes: 7 additions & 0 deletions swiftsimio/metadata/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class SWIFTMetadata(ABC):
# (as is the case in SOAP) or whether each type (e.g. Gas, Dark Matter, etc.)
# has its own top-level cell grid counts.
shared_cell_counts: str | None = None
# Whether all the arrays in this files have the same length and order (as is
# the case for SOAP, all arrays correspond to subhalos) or whether there are
# multiple types (e.g. Gas, Dark Matter, etc.)
homogeneous_arrays: bool = False

@abstractmethod
def __init__(self, filename, units: "SWIFTUnits"):
Expand Down Expand Up @@ -1223,6 +1227,8 @@ class SWIFTFOFMetadata(SWIFTMetadata):
class.
"""

homogeneous_arrays: bool = True

def __init__(self, filename: str, units: SWIFTUnits):
self.filename = filename
self.units = units
Expand Down Expand Up @@ -1265,6 +1271,7 @@ class SWIFTSOAPMetadata(SWIFTMetadata):

masking_valid: bool = True
shared_cell_counts: str = "Subhalos"
homogeneous_arrays: bool = True

def __init__(self, filename: str, units: SWIFTUnits):
self.filename = filename
Expand Down

0 comments on commit 790c97e

Please sign in to comment.