Skip to content

Commit

Permalink
Lint with updated black.
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleaoman committed Oct 11, 2023
1 parent eacc9bb commit 929f3e6
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 60 deletions.
8 changes: 4 additions & 4 deletions swiftgalaxy/halo_finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def centre(self) -> cosmo_array:
]
),
comoving=False, # velociraptor gives physical centres!
cosmo_factor=cosmo_factor(a ** 1, self.scale_factor),
cosmo_factor=cosmo_factor(a**1, self.scale_factor),
).to_comoving()

@property
Expand Down Expand Up @@ -323,7 +323,7 @@ def velocity_centre(self) -> cosmo_array:
]
),
comoving=False,
cosmo_factor=cosmo_factor(a ** 0, self.scale_factor),
cosmo_factor=cosmo_factor(a**0, self.scale_factor),
).to_comoving()

def __getattr__(self, attr: str) -> Any:
Expand Down Expand Up @@ -584,7 +584,7 @@ def centre(self) -> cosmo_array:
u.kpc
), # maybe comoving, ensure physical
comoving=False,
cosmo_factor=cosmo_factor(a ** 1, self._caesar.simulation.scale_factor),
cosmo_factor=cosmo_factor(a**1, self._caesar.simulation.scale_factor),
).to_comoving()

@property
Expand All @@ -603,7 +603,7 @@ def velocity_centre(self) -> cosmo_array:
return cosmo_array(
getattr(self._group, vcentre_attr).to(u.km / u.s),
comoving=False,
cosmo_factor=cosmo_factor(a ** 0, self._caesar.simulation.scale_factor),
cosmo_factor=cosmo_factor(a**0, self._caesar.simulation.scale_factor),
).to_comoving()

def __getattr__(self, attr: str) -> Any:
Expand Down
10 changes: 5 additions & 5 deletions swiftgalaxy/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ def spherical_coordinates(self) -> _CoordinateHelper:
units=unyt.rad,
comoving=r.comoving,
cosmo_factor=cosmo_factor(
a ** 0, scale_factor=r.cosmo_factor.scale_factor
a**0, scale_factor=r.cosmo_factor.scale_factor
),
)
if self.cylindrical_coordinates is not None:
Expand All @@ -668,7 +668,7 @@ def spherical_coordinates(self) -> _CoordinateHelper:
units=unyt.rad,
comoving=r.comoving,
cosmo_factor=cosmo_factor(
a ** 0, scale_factor=r.cosmo_factor.scale_factor
a**0, scale_factor=r.cosmo_factor.scale_factor
),
)
phi[phi < 0] = phi[phi < 0] + 2 * np.pi * unyt.rad
Expand Down Expand Up @@ -834,7 +834,7 @@ def cylindrical_coordinates(self) -> _CoordinateHelper:
units=unyt.rad,
comoving=rho.comoving,
cosmo_factor=cosmo_factor(
a ** 0, scale_factor=rho.cosmo_factor.scale_factor
a**0, scale_factor=rho.cosmo_factor.scale_factor
),
)
z = self.cartesian_coordinates.z
Expand Down Expand Up @@ -1427,7 +1427,7 @@ def centre(self) -> cosmo_array:
units=transform_units,
comoving=True,
cosmo_factor=cosmo_factor(
a ** 1, scale_factor=self.metadata.scale_factor
a**1, scale_factor=self.metadata.scale_factor
),
),
transform,
Expand All @@ -1444,7 +1444,7 @@ def velocity_centre(self) -> cosmo_array:
units=transform_units,
comoving=True,
cosmo_factor=cosmo_factor(
a ** 0, scale_factor=self.metadata.scale_factor
a**0, scale_factor=self.metadata.scale_factor
),
),
transform,
Expand Down
54 changes: 27 additions & 27 deletions tests/test_coordinate_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,91 +17,91 @@
reltol * 10,
units=u.kpc,
comoving=True,
cosmo_factor=cosmo_factor(a ** 1, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**1, scale_factor=1.0),
),
"dark_matter": cosmo_array(
reltol * 100,
units=u.kpc,
comoving=True,
cosmo_factor=cosmo_factor(a ** 1, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**1, scale_factor=1.0),
),
"stars": cosmo_array(
reltol * 5,
units=u.kpc,
comoving=True,
cosmo_factor=cosmo_factor(a ** 1, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**1, scale_factor=1.0),
),
"black_holes": cosmo_array(
abstol_c, comoving=True, cosmo_factor=cosmo_factor(a ** 1, scale_factor=1.0)
abstol_c, comoving=True, cosmo_factor=cosmo_factor(a**1, scale_factor=1.0)
),
}
expected_z = {
"gas": cosmo_array(
reltol,
units=u.kpc,
comoving=True,
cosmo_factor=cosmo_factor(a ** 1, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**1, scale_factor=1.0),
),
"dark_matter": cosmo_array(
reltol * 100,
units=u.kpc,
comoving=True,
cosmo_factor=cosmo_factor(a ** 1, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**1, scale_factor=1.0),
),
"stars": cosmo_array(
reltol * 500,
units=u.pc,
comoving=True,
cosmo_factor=cosmo_factor(a ** 1, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**1, scale_factor=1.0),
),
"black_holes": cosmo_array(
abstol_c, comoving=True, cosmo_factor=cosmo_factor(a ** 1, scale_factor=1.0)
abstol_c, comoving=True, cosmo_factor=cosmo_factor(a**1, scale_factor=1.0)
),
}
expected_vxy = {
"gas": cosmo_array(
reltol * 100,
units=u.km / u.s,
comoving=True,
cosmo_factor=cosmo_factor(a ** 0, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**0, scale_factor=1.0),
),
"dark_matter": cosmo_array(
reltol * 100,
units=u.km / u.s,
comoving=True,
cosmo_factor=cosmo_factor(a ** 0, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**0, scale_factor=1.0),
),
"stars": cosmo_array(
reltol * 50,
units=u.km / u.s,
comoving=True,
cosmo_factor=cosmo_factor(a ** 0, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**0, scale_factor=1.0),
),
"black_holes": cosmo_array(
abstol_v, comoving=True, cosmo_factor=cosmo_factor(a ** 0, scale_factor=1.0)
abstol_v, comoving=True, cosmo_factor=cosmo_factor(a**0, scale_factor=1.0)
),
}
expected_vz = {
"gas": cosmo_array(
reltol * 10,
units=u.km / u.s,
comoving=True,
cosmo_factor=cosmo_factor(a ** 0, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**0, scale_factor=1.0),
),
"dark_matter": cosmo_array(
reltol * 100,
units=u.km / u.s,
comoving=True,
cosmo_factor=cosmo_factor(a ** 0, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**0, scale_factor=1.0),
),
"stars": cosmo_array(
reltol * 10,
units=u.km / u.s,
comoving=True,
cosmo_factor=cosmo_factor(a ** 0, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**0, scale_factor=1.0),
),
"black_holes": cosmo_array(
abstol_v, comoving=True, cosmo_factor=cosmo_factor(a ** 0, scale_factor=1.0)
abstol_v, comoving=True, cosmo_factor=cosmo_factor(a**0, scale_factor=1.0)
),
}

Expand Down Expand Up @@ -265,7 +265,7 @@ def test_manual_recentring(self, sg, particle_name, coordinate_name, before_load
[1, 1, 1],
units=u.Mpc,
comoving=True,
cosmo_factor=cosmo_factor(a ** 1, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**1, scale_factor=1.0),
)
sg.recentre(new_centre)
xyz = getattr(getattr(sg, particle_name), f"{coordinate_name}")
Expand All @@ -289,7 +289,7 @@ def test_manual_recentring_velocity(
[100, 100, 100],
units=u.km / u.s,
comoving=True,
cosmo_factor=cosmo_factor(a ** 0, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**0, scale_factor=1.0),
)
sg.recentre_velocity(new_centre)
vxyz = getattr(getattr(sg, particle_name), f"{velocity_name}")
Expand All @@ -315,7 +315,7 @@ def test_translate(self, sg, particle_name, coordinate_name, before_load):
[1, 1, 1],
units=u.Mpc,
comoving=True,
cosmo_factor=cosmo_factor(a ** 1, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**1, scale_factor=1.0),
)
sg.translate(translation)
xyz = getattr(getattr(sg, particle_name), f"{coordinate_name}")
Expand All @@ -337,7 +337,7 @@ def test_boost(self, sg, particle_name, velocity_name, before_load):
[100, 100, 100],
u.km / u.s,
comoving=True,
cosmo_factor=cosmo_factor(a ** 0, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**0, scale_factor=1.0),
)
sg.boost(boost)
vxyz = getattr(getattr(sg, particle_name), f"{velocity_name}")
Expand Down Expand Up @@ -389,7 +389,7 @@ def test_box_wrap(self, sg, particle_name, coordinate_name):
boxsize = cosmo_array(
sg.metadata.boxsize,
comoving=True,
cosmo_factor=cosmo_factor(a ** 1, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**1, scale_factor=1.0),
)
xyz_before = getattr(getattr(sg, particle_name), f"{coordinate_name}")
sg.translate(-2 * boxsize) # -2x box size
Expand All @@ -412,7 +412,7 @@ def test_translate_then_rotate(self, sg, before_load):
[1, 1, 1],
units=u.Mpc,
comoving=True,
cosmo_factor=cosmo_factor(a ** 1, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**1, scale_factor=1.0),
)
sg.translate(translation)
sg.rotate(Rotation.from_matrix(rot))
Expand All @@ -436,7 +436,7 @@ def test_rotate_then_translate(self, sg, before_load):
[1, 1, 1],
units=u.Mpc,
comoving=True,
cosmo_factor=cosmo_factor(a ** 1, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**1, scale_factor=1.0),
)
sg.translate(translation)
xyz = sg.gas.coordinates
Expand All @@ -458,7 +458,7 @@ def test_boost_then_rotate(self, sg, before_load):
[100, 100, 100],
units=u.km / u.s,
comoving=True,
cosmo_factor=cosmo_factor(a ** 0, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**0, scale_factor=1.0),
)
sg.boost(boost)
sg.rotate(Rotation.from_matrix(rot))
Expand All @@ -482,7 +482,7 @@ def test_rotate_then_boost(self, sg, before_load):
[100, 100, 100],
units=u.km / u.s,
comoving=True,
cosmo_factor=cosmo_factor(a ** 0, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**0, scale_factor=1.0),
)
sg.boost(boost)
vxyz = sg.gas.velocities
Expand Down Expand Up @@ -515,7 +515,7 @@ def test_copied_coordinate_transform(self, sg):
[1, 1, 1],
units=u.Mpc,
comoving=True,
cosmo_factor=cosmo_factor(a ** 1, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**1, scale_factor=1.0),
)
sg.translate(translation)
sg2 = SWIFTGalaxy(
Expand All @@ -535,7 +535,7 @@ def test_copied_velocity_transform(self, sg):
[1, 1, 1],
units=u.Mpc,
comoving=True,
cosmo_factor=cosmo_factor(a ** 1, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**1, scale_factor=1.0),
)
sg.translate(translation)
sg2 = SWIFTGalaxy(
Expand Down
16 changes: 8 additions & 8 deletions tests/test_derived_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ class TestInteractionWithCoordinateTransformations:
np.zeros(3),
units=u.Mpc,
comoving=True,
cosmo_factor=cosmo_factor(a ** 1, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**1, scale_factor=1.0),
),
),
(
Expand All @@ -352,7 +352,7 @@ class TestInteractionWithCoordinateTransformations:
np.zeros(3),
units=u.km / u.s,
comoving=True,
cosmo_factor=cosmo_factor(a ** 0, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**0, scale_factor=1.0),
),
),
(
Expand All @@ -361,7 +361,7 @@ class TestInteractionWithCoordinateTransformations:
np.zeros(3),
units=u.Mpc,
comoving=True,
cosmo_factor=cosmo_factor(a ** 1, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**1, scale_factor=1.0),
),
),
(
Expand All @@ -370,7 +370,7 @@ class TestInteractionWithCoordinateTransformations:
np.zeros(3),
units=u.km / u.s,
comoving=True,
cosmo_factor=cosmo_factor(a ** 0, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**0, scale_factor=1.0),
),
),
("rotate", Rotation.from_matrix(np.eye(3))),
Expand Down Expand Up @@ -419,7 +419,7 @@ def test_void_derived_coordinates(
np.ones(3),
units=u.Mpc,
comoving=True,
cosmo_factor=cosmo_factor(a ** 1, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**1, scale_factor=1.0),
),
),
(
Expand All @@ -428,7 +428,7 @@ def test_void_derived_coordinates(
100 * np.ones(3),
units=u.km / u.s,
comoving=True,
cosmo_factor=cosmo_factor(a ** 0, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**0, scale_factor=1.0),
),
),
(
Expand All @@ -437,7 +437,7 @@ def test_void_derived_coordinates(
np.ones(3),
units=u.Mpc,
comoving=True,
cosmo_factor=cosmo_factor(a ** 0, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**0, scale_factor=1.0),
),
),
(
Expand All @@ -446,7 +446,7 @@ def test_void_derived_coordinates(
100 * np.ones(3),
units=u.km / u.s,
comoving=True,
cosmo_factor=cosmo_factor(a ** 0, scale_factor=1.0),
cosmo_factor=cosmo_factor(a**0, scale_factor=1.0),
),
),
("rotate", Rotation.from_rotvec(np.pi / 2 * np.array([1, 1, 1]))),
Expand Down
15 changes: 9 additions & 6 deletions tests/test_halo_finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,15 @@ def test_spatial_mask_applied(self, caesar):
create_toysnap()
sg = SWIFTGalaxy(toysnap_filename, caesar)
for particle_type in present_particle_types.values():
assert getattr(sg, particle_type).masses.size == dict(
gas=n_g_b // 2 + n_g,
dark_matter=n_dm_b // 2 + n_dm,
stars=n_s,
black_holes=n_bh,
)[particle_type]
assert (
getattr(sg, particle_type).masses.size
== dict(
gas=n_g_b // 2 + n_g,
dark_matter=n_dm_b // 2 + n_dm,
stars=n_s,
black_holes=n_bh,
)[particle_type]
)
remove_toysnap()


Expand Down
Loading

0 comments on commit 929f3e6

Please sign in to comment.