Skip to content

Commit

Permalink
Merge pull request #197 from roxyboy/twopi
Browse files Browse the repository at this point in the history
Multiplying 2pi factor when isotropizing
  • Loading branch information
roxyboy authored Apr 11, 2024
2 parents f259414 + a04cbfd commit 92fd1df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
3 changes: 1 addition & 2 deletions xrft/tests/test_xrft.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,6 @@ def synthetic_field(N, dL, amp, s):
def synthetic_field_xr(
N, dL, amp, s, other_dim_sizes=None, dim_order=True, chunks=None
):

theta = xr.DataArray(
synthetic_field(N, dL, amp, s),
dims=["y", "x"],
Expand Down Expand Up @@ -950,7 +949,7 @@ def _test_iso(theta):
ps_iso = xrft.isotropize(ps, fftdim, nfactor=nfactor, truncate=truncate)
assert len(ps_iso.dims) == 1
assert ps_iso.dims[0] == "freq_r"
npt.assert_allclose(ps_iso, ps_iso.freq_r**2, atol=0.02)
npt.assert_allclose(ps_iso, ps_iso.freq_r**2 * 2 * np.pi, atol=0.02)

# np data
theta = synthetic_field_xr(N, dL, amp, s)
Expand Down
22 changes: 16 additions & 6 deletions xrft/xrft.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,15 +993,25 @@ def isotropize(ps, fftdim, nfactor=4, truncate=True, complx=False):

if complx:
iso_ps = (
_groupby_bins_agg(ps, freq_r, bins=nbins, func="mean", dtype=np.complex128)
.rename({"freq_r_bins": "freq_r"})
.drop_vars("freq_r")
(
_groupby_bins_agg(
ps, freq_r, bins=nbins, func="mean", dtype=np.complex128
)
.rename({"freq_r_bins": "freq_r"})
.drop_vars("freq_r")
)
* 2
* np.pi
)
else:
iso_ps = (
_groupby_bins_agg(ps, freq_r, bins=nbins, func="mean")
.rename({"freq_r_bins": "freq_r"})
.drop_vars("freq_r")
(
_groupby_bins_agg(ps, freq_r, bins=nbins, func="mean")
.rename({"freq_r_bins": "freq_r"})
.drop_vars("freq_r")
)
* 2
* np.pi
)
iso_ps.coords["freq_r"] = kr.data
if truncate:
Expand Down

0 comments on commit 92fd1df

Please sign in to comment.