Skip to content

Commit ce58643

Browse files
committed
style: fix ruff lint and format findings in polarized-sky code
1 parent 98e3e5a commit ce58643

6 files changed

Lines changed: 26 additions & 18 deletions

File tree

src/matvis/core/coherency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ def partition_and_negate(stokes, skycoords, I_sky=None):
483483
if len(idx_M) > 0:
484484
raise ValueError(
485485
"partition_and_negate is only valid when no sources have "
486-
"mixed-sign eigenvalues; got {} mixed sources.".format(len(idx_M))
486+
f"mixed-sign eigenvalues; got {len(idx_M)} mixed sources."
487487
)
488488
perm = np.concatenate([idx_P, idx_N])
489489
n_P = int(len(idx_P))

src/matvis/wrapper.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,7 @@ def simulate_vis(
168168
fnc = gpu.simulate if use_gpu else cpu.simulate
169169

170170
if (fluxes is None) == (stokes is None):
171-
raise ValueError(
172-
"Provide exactly one of `fluxes` or `stokes` to simulate_vis."
173-
)
171+
raise ValueError("Provide exactly one of `fluxes` or `stokes` to simulate_vis.")
174172

175173
if polarized is None:
176174
polarized = stokes is not None

tests/test_coherency.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""Unit tests for coherency matrix and M matrix computation."""
22

3-
import pytest
4-
53
import numpy as np
4+
import pytest
65

76
from matvis.core.coherency import (
87
coherency_to_stokes,

tests/test_compare_pyuvsim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_compare_pyuvsim(polarized, use_analytic_beam):
8989
ids=["analytic_beam", "uvbeam"],
9090
)
9191
def test_compare_pyuvsim_polarized_sky(use_analytic_beam, xfail):
92-
"""matvis stokes path vs pyuvsim for a fully polarized sky (Q,U,V≠0).
92+
"""Compare the matvis stokes path with pyuvsim for a fully polarized sky (Q,U,V≠0).
9393
9494
The existing ``test_compare_pyuvsim`` only exercises Stokes I; this one
9595
drives non-trivial coherency rotation and XY/YX off-diagonals through

tests/test_polarized_benchmark.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
Not run in CI — use: pytest tests/test_polarized_benchmark.py -v -s
44
"""
55

6-
import pytest
7-
86
import os
97

8+
import pytest
9+
1010
pytestmark = pytest.mark.skipif(
1111
not os.getenv("RUN_BENCHMARKS"),
1212
reason="Set RUN_BENCHMARKS=1 to run benchmarks",
1313
)
1414

15-
import numpy as np
1615
import time
16+
17+
import numpy as np
1718
from astropy import units as un
1819
from astropy.coordinates import EarthLocation
1920
from astropy.time import Time

tests/test_polarized_sky.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
- New path: simulate_vis(stokes=...) with full Stokes params
66
"""
77

8-
import pytest
9-
108
import numpy as np
9+
import pytest
1110
from astropy import units as un
1211
from astropy.coordinates import EarthLocation, SkyCoord
1312
from astropy.time import Time
@@ -54,8 +53,11 @@ def _make_sim_params(nsrc=10, nant=3, ntime=2, nfreq=1, precision=2):
5453

5554

5655
class TestBackwardCompatibility:
57-
"""``stokes=[I,0,0,0]`` routed through the eigen path must reproduce
58-
the legacy ``fluxes``-only path that uses ``sqrt(0.5*I)`` directly."""
56+
"""Check that the eigen path reproduces the legacy unpolarized path.
57+
58+
``stokes=[I,0,0,0]`` routed through the eigen path must reproduce
59+
the legacy ``fluxes``-only path that uses ``sqrt(0.5*I)`` directly.
60+
"""
5961

6062
@pytest.mark.parametrize("precision,atol", [(2, 1e-12), (1, 1e-4)])
6163
def test_unpolarized_stokes_matches_existing(self, precision, atol):
@@ -138,8 +140,11 @@ class TestNegativeFluxHandling:
138140
["positive_sky", "mixed_negative_sky"],
139141
)
140142
def test_negative_flux_path(self, case):
141-
"""Sign-split route must match eigen when sky is positive, and
142-
produce finite nonzero visibilities when some Stokes I are negative."""
143+
"""Check the sign-split route against the eigen route.
144+
145+
Sign-split must match eigen when the sky is positive, and
146+
produce finite nonzero visibilities when some Stokes I are negative.
147+
"""
143148
params = _make_sim_params(nsrc=10, nant=3, ntime=2, nfreq=1)
144149

145150
if case == "positive_sky":
@@ -246,10 +251,14 @@ def test_negate_source_symmetry(self):
246251

247252

248253
class TestPolarizedInference:
249-
"""Passing ``stokes`` must auto-enable ``polarized``; explicit
250-
``polarized=False`` alongside ``stokes`` must raise."""
254+
"""Check that ``polarized`` is correctly inferred from ``stokes``.
255+
256+
Passing ``stokes`` must auto-enable ``polarized``; explicit
257+
``polarized=False`` alongside ``stokes`` must raise.
258+
"""
251259

252260
def test_stokes_alone_enables_polarized(self):
261+
"""Omitting ``polarized`` while passing ``stokes`` must auto-enable it."""
253262
params = _make_sim_params(nsrc=5, nant=2, ntime=1, nfreq=1)
254263
nsrc = len(params["ra"])
255264
nfreq = len(params["freqs"])
@@ -264,6 +273,7 @@ def test_stokes_alone_enables_polarized(self):
264273
assert not np.any(np.isnan(vis))
265274

266275
def test_polarized_false_with_stokes_raises(self):
276+
"""Explicit ``polarized=False`` alongside ``stokes`` must raise."""
267277
params = _make_sim_params(nsrc=5, nant=2, ntime=1, nfreq=1)
268278
nsrc = len(params["ra"])
269279
nfreq = len(params["freqs"])

0 commit comments

Comments
 (0)