Skip to content

Commit

Permalink
gh-362: review the ruff-format recommended rules
Browse files Browse the repository at this point in the history
Closes #362. When you first run `ruff-format` it only warns about
`COM812` and `ISC001`. This PR just reduces the others which technically
also in conflict to just these two. I have used these extensively and
have had no issues.
  • Loading branch information
paddyroddy committed Oct 30, 2024
1 parent 646e823 commit d9ac23d
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 26 deletions.
7 changes: 6 additions & 1 deletion examples/2-advanced/cosmic_shear.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,12 @@
"\n",
" # apply the shear fields to the ellipticities\n",
" gal_she = glass.galaxy_shear(\n",
" gal_lon, gal_lat, gal_eps, kappa_i, gamm1_i, gamm2_i\n",
" gal_lon,\n",
" gal_lat,\n",
" gal_eps,\n",
" kappa_i,\n",
" gamm1_i,\n",
" gamm2_i,\n",
" )\n",
"\n",
" # map the galaxy shears to a HEALPix map; this is opaque but works\n",
Expand Down
12 changes: 10 additions & 2 deletions examples/2-advanced/stage_4_galaxies.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@
"\n",
" # generate galaxy positions from the matter density contrast\n",
" for gal_lon, gal_lat, gal_count in glass.positions_from_delta(\n",
" ngal[i], delta_i, bias, vis\n",
" ngal[i],\n",
" delta_i,\n",
" bias,\n",
" vis,\n",
" ):\n",
" # generate random redshifts over the given shell\n",
" gal_z = glass.redshifts(gal_count, ws[i])\n",
Expand All @@ -297,7 +300,12 @@
"\n",
" # apply the shear fields to the ellipticities\n",
" gal_she = glass.galaxy_shear(\n",
" gal_lon, gal_lat, gal_eps, kappa_i, gamm1_i, gamm2_i\n",
" gal_lon,\n",
" gal_lat,\n",
" gal_eps,\n",
" kappa_i,\n",
" gamm1_i,\n",
" gamm2_i,\n",
" )\n",
"\n",
" # make a mini-catalogue for the new rows\n",
Expand Down
2 changes: 1 addition & 1 deletion glass/ext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _extend_path(path, name) -> list: # type: ignore[no-untyped-def, type-arg]
filter(
os.path.isdir,
(os.path.join(p, _mod) for p in extend_path(path, _pkg)), # noqa: PTH118
)
),
)


Expand Down
17 changes: 13 additions & 4 deletions glass/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
Size = typing.Optional[typing.Union[int, tuple[int, ...]]]
Iternorm = tuple[typing.Optional[int], npt.NDArray[typing.Any], npt.NDArray[typing.Any]]
ClTransform = typing.Union[
str, typing.Callable[[npt.NDArray[typing.Any]], npt.NDArray[typing.Any]]
str,
typing.Callable[[npt.NDArray[typing.Any]], npt.NDArray[typing.Any]],
]
Cls = collections.abc.Sequence[
typing.Union[npt.NDArray[typing.Any], collections.abc.Sequence[float]]
Expand Down Expand Up @@ -110,7 +111,10 @@ def iternorm(


def cls2cov(
cls: Cls, nl: int, nf: int, nc: int
cls: Cls,
nl: int,
nf: int,
nc: int,
) -> collections.abc.Generator[npt.NDArray[typing.Any], None, None]:
"""Return array of cls as a covariance matrix for iterative sampling."""
cov = np.zeros((nl, nc + 1))
Expand Down Expand Up @@ -149,7 +153,8 @@ def transform_cls(cls: Cls, tfm: ClTransform, pars: tuple[typing.Any, ...] = ())
gl, info, _, _ = gaussiancl(cl, tfm, pars, monopole=monopole)
if info == 0:
warnings.warn(
"Gaussian cl did not converge, inexact transform", stacklevel=2
"Gaussian cl did not converge, inexact transform",
stacklevel=2,
)
else:
gl = []
Expand Down Expand Up @@ -352,7 +357,11 @@ def getcl(cls, i, j, lmax=None): # type: ignore[no-untyped-def]


def effective_cls( # type: ignore[no-untyped-def]
cls, weights1, weights2=None, *, lmax=None
cls,
weights1,
weights2=None,
*,
lmax=None,
) -> npt.NDArray[np.float64]:
r"""
Compute effective angular power spectra from weights.
Expand Down
9 changes: 7 additions & 2 deletions glass/lensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,10 @@ def add_window(self, delta: npt.NDArray[typing.Any], w: RadialWindow) -> None:
self.add_plane(delta, zsrc, lens_weight)

def add_plane(
self, delta: npt.NDArray[typing.Any], zsrc: float, wlens: float = 1.0
self,
delta: npt.NDArray[typing.Any],
zsrc: float,
wlens: float = 1.0,
) -> None:
"""Add a mass plane at redshift ``zsrc`` to the convergence."""
if zsrc <= self.z3:
Expand Down Expand Up @@ -417,7 +420,9 @@ def multi_plane_weights(


def deflect(
lon: npt.ArrayLike, lat: npt.ArrayLike, alpha: npt.ArrayLike
lon: npt.ArrayLike,
lat: npt.ArrayLike,
alpha: npt.ArrayLike,
) -> npt.NDArray[typing.Any]:
r"""
Apply deflections to positions.
Expand Down
3 changes: 2 additions & 1 deletion glass/shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ def tophat_windows(
raise ValueError(msg)
if zbins[0] != 0:
warnings.warn(
"first tophat window does not start at redshift zero", stacklevel=2
"first tophat window does not start at redshift zero",
stacklevel=2,
)

wht: WeightFunc
Expand Down
5 changes: 4 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ def examples(session: nox.Session) -> None:
"""Run the example notebooks."""
session.install("-e", ".[examples]")
session.run(
"jupyter", "execute", *Path().glob("examples/**/*.ipynb"), *session.posargs
"jupyter",
"execute",
*Path().glob("examples/**/*.ipynb"),
*session.posargs,
)


Expand Down
12 changes: 0 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,11 @@ lint.ignore = [
"ANN003", # TODO: missing-type-kwargs
"ANN201", # TODO: missing-return-type-undocumented-public-function
"COM812", # missing-trailing-comma (ruff-format recommended)
"COM819", # prohibited-trailing-comma (ruff-format recommended)
"D203", # one-blank-line-before-class
"D206", # indent-with-spaces (ruff-format recommended)
"D212", # blank-line-before-class
"D300", # triple-single-quotes (ruff-format recommended)
"E111", # indentation-with-invalid-multiple (ruff-format recommended)
"E114", # indentation-with-invalid-multiple-comment (ruff-format recommended)
"E117", # over-indented (ruff-format recommended)
"ISC001", # single-line-implicit-string-concatenation (ruff-format recommended)
"ISC002", # multi-line-implicit-string-concatenation (ruff-format recommended)
"NPY201", # TODO: numpy2-deprecation
"Q000", # bad-quotes-inline-string (ruff-format recommended)
"Q001", # bad-quotes-multiline-string (ruff-format recommended)
"Q002", # bad-quotes-docstring (ruff-format recommended)
"Q003", # avoidable-escaped-quote (ruff-format recommended)
"RUF003", # ambiguous-unicode-character-comment
"W191", # tab-indentation (ruff-format recommended)
]
lint.isort = {known-first-party = [
"glass",
Expand Down
14 changes: 12 additions & 2 deletions tests/test_galaxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ def test_redshifts_from_nz(rng: np.random.Generator) -> None:
# test with rng

redshifts = redshifts_from_nz(
10, [0, 1, 2, 3, 4], [0, 0, 1, 1, 1], warn=False, rng=rng
10,
[0, 1, 2, 3, 4],
[0, 0, 1, 1, 1],
warn=False,
rng=rng,
)
assert not np.any(redshifts <= 1)

Expand Down Expand Up @@ -130,7 +134,13 @@ def test_galaxy_shear(rng): # type: ignore[no-untyped-def]
rng.normal(size=(512,)),
)
shear = galaxy_shear(
gal_lon, gal_lat, gal_eps, kappa, gamma1, gamma2, reduced_shear=False
gal_lon,
gal_lat,
gal_eps,
kappa,
gamma1,
gamma2,
reduced_shear=False,
)
assert np.shape(shear) == (512,)

Expand Down

0 comments on commit d9ac23d

Please sign in to comment.