Skip to content

Commit

Permalink
Merge branch 'masking_in_9.0' of https://github.com/swiftsim/swiftsimio
Browse files Browse the repository at this point in the history
… into masking_in_9.0
  • Loading branch information
JBorrow committed Sep 19, 2024
2 parents 19e069f + 79d098e commit bcc86b9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
14 changes: 8 additions & 6 deletions swiftsimio/masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def __init__(self, metadata: SWIFTMetadata, spatial_only=True):
if not spatial_only:
self._generate_empty_masks()


def _generate_mapping_dictionary(self) -> dict[str, str]:
"""
Creates cross-links between 'group names' and their underlying cell metadata
Expand Down Expand Up @@ -154,7 +153,9 @@ def _generate_empty_masks(self):
mapping = self._generate_mapping_dictionary()

if self.metadata.shared_cell_counts is not None:
size = getattr(self.metadata, f"n_{self.metadata.shared_cell_counts.lower()}")
size = getattr(
self.metadata, f"n_{self.metadata.shared_cell_counts.lower()}"
)
self._shared = np.ones(size, dtype=bool)
self._shared_size = size

Expand Down Expand Up @@ -190,7 +191,6 @@ def _unpack_cell_metadata(self):
# file i/o implemented
offset_handle = cell_handle["Offsets"]


if self.metadata.shared_cell_counts is not None:
# Single - called _shared.
self.offsets["shared"] = offset_handle[self.metadata.shared_cell_counts][:]
Expand All @@ -210,7 +210,7 @@ def _unpack_cell_metadata(self):
# contain at least one of each type of particle).
sort = None

# Now perform sort:
# Now perform sort:
for key in self.offsets.keys():
offsets = self.offsets[key]
counts = self.counts[key]
Expand Down Expand Up @@ -276,7 +276,7 @@ def constrain_mask(
print("You cannot constrain a mask if spatial_only=True")
print("Please re-initialise the SWIFTMask object with spatial_only=False")
return

mapping = self._generate_mapping_dictionary()
data_name = mapping[group_name]

Expand Down Expand Up @@ -522,7 +522,9 @@ def constrain_index(self, index: int):
setattr(self, f"{group_name}_size", 1)
return

def get_masked_counts_offsets(self) -> tuple[dict[str, np.array], dict[str, np.array]]:
def get_masked_counts_offsets(
self
) -> tuple[dict[str, np.array], dict[str, np.array]]:
"""
Returns the particle counts and offsets in cells selected by the mask
Expand Down
2 changes: 1 addition & 1 deletion swiftsimio/metadata/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ def __init__(self, filename: str, units: SWIFTUnits):
self.handle.close()

return

def unpack_subhalo_number(self):
self.n_subhalos = int(self.num_subhalo[0])

Expand Down
10 changes: 3 additions & 7 deletions tests/test_soap.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def test_soap_can_mask_spatial(filename):
this_mask = mask(filename, spatial_only=True)

bs = this_mask.metadata.boxsize
this_mask.constrain_spatial(
[[0 * b, 0.5 * b] for b in bs]
)
this_mask.constrain_spatial([[0 * b, 0.5 * b] for b in bs])

data = load(filename, mask=this_mask)

Expand All @@ -33,10 +31,8 @@ def test_soap_can_mask_non_spatial(filename):
this_mask = mask(filename, spatial_only=False)

bs = this_mask.metadata.boxsize
this_mask.constrain_spatial(
[[0 * b, 0.5 * b] for b in bs]
)
this_mask.constrain_spatial([[0 * b, 0.5 * b] for b in bs])

data = load(filename, mask=this_mask)

data.spherical_overdensity_200_mean.total_mass[0]
data.spherical_overdensity_200_mean.total_mass[0]

0 comments on commit bcc86b9

Please sign in to comment.