From 79d098e693abfabd188f28c4bb34e2c3cba65a2a Mon Sep 17 00:00:00 2001 From: Kyle Oman Date: Thu, 19 Sep 2024 15:45:36 +0100 Subject: [PATCH] Run formatter. --- swiftsimio/masks.py | 31 ++++++++++++------------------- swiftsimio/metadata/objects.py | 2 +- tests/test_soap.py | 10 +++------- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/swiftsimio/masks.py b/swiftsimio/masks.py index a19ba417..65d96b31 100644 --- a/swiftsimio/masks.py +++ b/swiftsimio/masks.py @@ -66,7 +66,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 @@ -86,7 +85,7 @@ def _generate_mapping_dictionary(self) -> dict[str, str]: } return self.group_mapping - + def _generate_update_list(self) -> list[str]: """ Gets a list of internal mask variables that need to be updated when @@ -100,22 +99,13 @@ def _generate_update_list(self) -> list[str]: else: # We actually only have _one_ mask! return ["_shared"] - + def _create_pointers(self): # Create pointers for every single particle type. for group_name, data_name in self._generate_mapping_dictionary().items(): - setattr( - self, - group_name, - getattr(self, data_name) - ) - - setattr( - self, - f"{group_name}_size", - getattr(self, f"{data_name}_size") - ) + setattr(self, group_name, getattr(self, data_name)) + setattr(self, f"{group_name}_size", getattr(self, f"{data_name}_size")) def _generate_empty_masks(self): """ @@ -126,7 +116,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 @@ -164,7 +156,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][:] @@ -184,7 +175,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] @@ -250,7 +241,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] @@ -500,7 +491,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]