diff --git a/swiftsimio/masks.py b/swiftsimio/masks.py index 7b2cda63..d197250b 100644 --- a/swiftsimio/masks.py +++ b/swiftsimio/masks.py @@ -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 @@ -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 @@ -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][:] @@ -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] @@ -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] @@ -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 diff --git a/swiftsimio/metadata/objects.py b/swiftsimio/metadata/objects.py index 34b7f471..206a05ad 100644 --- a/swiftsimio/metadata/objects.py +++ b/swiftsimio/metadata/objects.py @@ -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]) diff --git a/tests/test_soap.py b/tests/test_soap.py index 6f96843b..b27defa6 100644 --- a/tests/test_soap.py +++ b/tests/test_soap.py @@ -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) @@ -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] \ No newline at end of file + data.spherical_overdensity_200_mean.total_mass[0]