Skip to content

Commit

Permalink
Run formatter.
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleaoman committed Sep 19, 2024
1 parent a0923e1 commit 79d098e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
31 changes: 12 additions & 19 deletions swiftsimio/masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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):
"""
Expand All @@ -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

Expand Down Expand Up @@ -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][:]
Expand All @@ -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]
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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
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 79d098e

Please sign in to comment.