Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ on:
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install ruff
run: python -m pip install ruff
- name: Lint
run: ruff check .
- name: Format check
run: ruff format --check .

test:
runs-on: ubuntu-latest
strategy:
Expand Down
12 changes: 6 additions & 6 deletions examples/sparse_transcranial_shear_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@
import numpy as np

matplotlib.use("Agg", force=True)
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection

import fullwave
import matplotlib.pyplot as plt
from fullwave.medium_builder import MediumBuilder
from fullwave.medium_builder.presets import BackgroundDomain, MicroCTSkullDomain
from fullwave.utils import plot_utils
from fullwave.utils.nrrd_reader import download_halle_skull
from fullwave.utils.slab_extraction import Placement
from mpl_toolkits.mplot3d.art3d import Poly3DCollection

from shearwave import (
compute_radiation_force,
compute_radiation_force_velocity,
shear_fdtd,
)
from fullwave.utils import plot_utils
from fullwave.utils.nrrd_reader import download_halle_skull
from fullwave.utils.slab_extraction import Placement

logger = logging.getLogger(__name__)

Expand Down
14 changes: 7 additions & 7 deletions examples/tips_transcranial_shear_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@
import numpy as np

matplotlib.use("Agg", force=True)
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection

import fullwave
import matplotlib.pyplot as plt
from fullwave.medium_builder import MediumBuilder
from fullwave.medium_builder.presets import BackgroundDomain, MicroCTSkullDomain
from fullwave.transducers import create_tips_transducer
from fullwave.utils import plot_utils
from fullwave.utils.nrrd_reader import download_halle_skull
from fullwave.utils.slab_extraction import Placement
from mpl_toolkits.mplot3d.art3d import Poly3DCollection

from shearwave import (
compute_acoustic_strain_gradient_peak,
compute_acoustic_strain_peak,
compute_radiation_force,
compute_radiation_force_velocity,
shear_fdtd,
)
from fullwave.transducers import create_tips_transducer
from fullwave.utils import plot_utils
from fullwave.utils.nrrd_reader import download_halle_skull
from fullwave.utils.slab_extraction import Placement

logger = logging.getLogger(__name__)

Expand Down
37 changes: 8 additions & 29 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
"B905", # zip() without strict=
"F841", # unused intermediate variables (colorbars, etc.)
"FBT003", # boolean positional values in matplotlib calls
"D401", # non-imperative docstrings in figure helpers
"N803", # physics variable naming
"N806", # physics variable naming
"PLC0415", # conditional imports (e.g. skimage)
Expand All @@ -137,46 +138,23 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
"src/shearwave/solver.py" = ["N803"]

# Acoustic strain: allow uppercase dX/dY/dZ and K (physics convention)
"fullwave/shear_wave/acoustic_strain.py" = ["N803", "N806"]
"src/shearwave/acoustic_strain.py" = ["N803", "N806"]

# Strain: allow uppercase dX/dY/dZ (physics convention)
"fullwave/shear_wave/strain.py" = ["N803"]
"src/shearwave/strain.py" = ["N803"]

# Bioheat: physics variable naming (T for temperature, Tp for padded)
"fullwave/bioheat/**" = ["N803", "N806"]

# Bioheat docs/scripts: matplotlib.use() requires import ordering, path setup
"fullwave/bioheat/docs/**" = [
"ANN001", "ANN002", "ANN003", "ANN201", "ANN202", "ANN204",
"D100", "D103", "D104",
"E402", "I001",
"N803", "N806",
]

# Neuromodulation: physics variable naming (V, T, I_Na, K_A, E_rev, etc.)
"fullwave/neuromodulation/**" = ["N803", "N806", "N815", "B905", "PLC0415"]

# Neuromodulation docs/scripts: path setup requires late imports, plot helpers
"fullwave/neuromodulation/docs/**" = [
"ANN001", "ANN002", "ANN003", "ANN201", "ANN202", "ANN204",
"D100", "D103", "D104",
"E402", "I001",
"E741",
"F841",
"FBT003",
"N803", "N806",
"PLR0912",
"PLW3301",
]
# Radiation force: allow uppercase physics variable naming
"src/shearwave/radiation_force.py" = ["N803", "N806"]

# Validation scripts: relax annotations, naming, and complexity rules
"fullwave/shear_wave/validation/**" = [
"validation/**" = [
"ANN001",
"ANN002",
"ANN003",
"ANN201",
"ANN202",
"ANN204",
"ARG001", # unused args in helper/plot functions
"B905",
"C901",
"COM812",
Expand All @@ -193,6 +171,7 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
"PLW2901",
"PTH123",
"RUF046",
"SIM108", # if/else over ternary is fine in scripts
]

[lint.pydocstyle]
Expand Down
2 changes: 1 addition & 1 deletion src/shearwave/radiation_force.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def compute_radiation_force_velocity(
velocity_w_4d: NDArray[np.floating],
velocity_v_4d: NDArray[np.floating],
c_map: NDArray[np.floating],
rho_map: NDArray[np.floating],
rho_map: NDArray[np.floating], # noqa: ARG001 kept for interface parity with compute_radiation_force
alpha_coeff_map: NDArray[np.floating],
f0: float,
gate: slice | NDArray[np.integer] | None = None,
Expand Down
11 changes: 4 additions & 7 deletions src/shearwave/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Supports both NumPy (CPU) and JAX (GPU/TPU) backends.
"""

# ruff: noqa: ANN001, ANN201, ANN202, BLE001, C901, FBT002, FBT003, RUF059, SIM108
# ruff: noqa: ANN001, ANN201, ANN202, FBT002, FBT003, SIM108

import numpy as np

Expand All @@ -24,7 +24,7 @@
_HAS_JAX = False


def shear_fdtd( # noqa: PLR0912, PLR0915
def shear_fdtd( # noqa: PLR0912
bx,
by,
bz,
Expand Down Expand Up @@ -227,7 +227,7 @@ def project_force(fx, fy, fz):
return u_center, v_center


def shear_fdtd_jax( # noqa: PLR0912, PLR0915
def shear_fdtd_jax( # noqa: PLR0912
bx,
by,
bz,
Expand Down Expand Up @@ -280,10 +280,7 @@ def shear_fdtd_jax( # noqa: PLR0912, PLR0915
raise ValueError(msg)
snapshot_stride = int(snapshot_stride)
if n_steps % snapshot_stride != 0:
msg = (
f"n_steps ({n_steps}) must be a multiple of snapshot_stride "
f"({snapshot_stride})."
)
msg = f"n_steps ({n_steps}) must be a multiple of snapshot_stride ({snapshot_stride})."
raise ValueError(msg)
if return_traces:
msg = "return_traces and snapshot_stride are not both supported in v1."
Expand Down
6 changes: 3 additions & 3 deletions tests/test_projection_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ def test_projection_numpy_jax_parity_is_divergence_free(seed):
rng = np.random.default_rng(seed)
# smooth, boundary-tapered random field
taper = (np.sin(np.pi * x) * np.sin(np.pi * y) * np.sin(np.pi * z)).astype(np.float32)
fx = (rng.standard_normal((n, n, n)).astype(np.float32) * taper) * np.ones((n, n, n), np.float32)
fy = (rng.standard_normal((n, n, n)).astype(np.float32) * taper) * np.ones((n, n, n), np.float32)
fz = (rng.standard_normal((n, n, n)).astype(np.float32) * taper) * np.ones((n, n, n), np.float32)
fx = rng.standard_normal((n, n, n)).astype(np.float32) * taper
fy = rng.standard_normal((n, n, n)).astype(np.float32) * taper
fz = rng.standard_normal((n, n, n)).astype(np.float32) * taper
nx, ny, nz = project_vector_field(fx.copy(), fy.copy(), fz.copy(), d, d, d, 1e-8, 5000)
jx, jy, jz = (np.asarray(a) for a in project_vector_field_jax(fx, fy, fz, d, d, d, 1e-8, 5000))
# backend agreement
Expand Down
1 change: 0 additions & 1 deletion validation/validate_convergence.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

matplotlib.use("Agg", force=True)
import matplotlib.pyplot as plt

from validate_wavespeed import run_validation


Expand Down
4 changes: 1 addition & 3 deletions validation/validate_qiba.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,7 @@ def callback(it, u):
"progress_every": max(1, n_steps // 6),
}

shear_fdtd(
bx, None, None, rho, mu, dx, dx, dx, dT, n_steps, opts=opts, callback=callback
)
shear_fdtd(bx, None, None, rho, mu, dx, dx, dx, dT, n_steps, opts=opts, callback=callback)

# Group velocity (measured from velocity traces = dU/dt)
c_group, peak_times, vel_traces = _measure_group_velocity(traces, distances, t_vec, cs)
Expand Down
1 change: 0 additions & 1 deletion validation/validate_viscosity.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

matplotlib.use("Agg", force=True)
import matplotlib.pyplot as plt

from validate_wavespeed import run_validation


Expand Down
3 changes: 2 additions & 1 deletion validation/validate_wavespeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def run_validation(
movie_every: Frame save interval for movie.
movie_dir: Directory for movie frames.

Returns:
Returns
-------
Dictionary with wavespeed results including sensor traces,
arrival times, and recovered speeds.

Expand Down
Loading