Add FFT-free spatial sweep alternative for wind shear perturbation (ustars/ustarn)#288
Draft
Add FFT-free spatial sweep alternative for wind shear perturbation (ustars/ustarn)#288
Conversation
- shear.py: add compute_shear_spatial + _cauchy_hilbert_sweep (numba JIT)
- shear.py: add method parameter to WindShear.__init__ ('fft'|'spatial')
- wind.py: pass method_shear='spatial' to WindShear when selected
- constants.py: document 'spatial' as valid method_shear option
- tests/test_shear.py: 12 new tests for helper and WindShear
Co-authored-by: Sierd <14054272+Sierd@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor ustarn and ustars calculation to avoid FFT
Add FFT-free spatial sweep alternative for wind shear perturbation (ustars/ustarn)
Mar 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
WindShear.compute_shearmethod computeddtaux/dtauy(Weng et al. perturbation theory, drivingustars/ustarn) exclusively via 2-D FFT. This adds a loop-and-sweep alternative that avoids FFT entirely, structured analogously to the directionalCtsweep inutils.py.Core algorithm (
shear.py)compute_shear_spatialmethod: applies a Gaussian spatial filter (replaces FFT-based high-frequency filter), computes central-difference bed slopes, then delegates to a row-by-row Cauchy sweep.@njit(cache=True)helper_cauchy_hilbert_sweep: for each y-row sweeps the antisymmetric kernel1/(k·π)over all nx cells — the discrete Hilbert transform of the slope in the wind direction. Numerically ~88–90 % correlated with the FFT result.alpha_s = 2·log(l/z₀)/ul²,alpha_n = 2/ul²), consistent withcompute_shear.Method selection
WindShear.__init__gains amethodparameter ('fft'|'spatial', default'fft'). Existing behaviour is unchanged.wind.initializeandconstants.pyupdated to recognise'spatial'as a validmethod_shearvalue alongside'fft','quasi2d', and'duna2d'.Tests (
tests/test_shear.py)12 new tests covering
_cauchy_hilbert_sweep(flat bed → zero, antisymmetric hill response, amplitude linearity, row independence) andWindShearwithmethod='spatial'(zero-wind, non-trivial output, ≥ 0.7 correlation with FFT, shape, backward compatibility of FFT path).✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.