Repository navigation
change isotropize to satisfy Parseval's thereom - #222
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
|
Hi @roxyboy, following your suggestions, I've reformatted the modified codes using Lines 953 to 959 in 9ac46f9 cannot be passed. The slopes of the two arrays are the same but differ by a constant that may depend on the number of points within each radial band, as |
Apologies for my slow reply, I was away for the past week. Thanks for the Black formatting! I understand that the assertion isn't passing because the radial wavenumber is taken using a |
|
I've changed the assertion to I also changed Line 1012 in 9ac46f9 Not sure if it is fine. It cannot get passed when |
| npt.assert_almost_equal(np.ma.masked_invalid(iso_ps).mask.sum(), 0.0) | ||
| y_fit, a, b = xrft.fit_loglog(iso_ps.freq_r.values[4:], iso_ps.values[4:]) | ||
| npt.assert_allclose(a, s, atol=0.1) | ||
| npt.assert_allclose(a, s, atol=1) |
There was a problem hiding this comment.
Does this mean that this PR results in the slopes differing by a factor of one...? If so, this is not good.
Yes, this is what I was personally worried that could happen when switching the isotropization from |
|
Hi @roxyboy, I just looked into the test, and found that the frequency range to be fitted is crucial. Line 1011 in 9ac46f9 Previously, indices from 4 to end are used, which include the highest frequencies that are steeper than expected. Now I switch the indices from 0 to -35, which overlap with the expected range, and this test passed even with a smaller `atol=0.06. The red curve is the fitted line over indices from 0 to -35. You may want to check if this is OK. |
|
@miniufo Ok, this is great! Can you run the Black formatting once more and I can merge this :) |
|
Oops, I forgot to do this after any changes. Can you check it again? |
|
@miniufo Sorry, it seems that some files are still missing the Black formatting... |
|
That's strange. I format all .py files. Possibly missing the .ipynb files. Please try again and see if it is fine now. |
|
@miniufo I agree that this is kind of unexpected behavior but the GitHub log is saying that |
|
Thanks for your work @miniufo ! The checks are all passing now so I will merge this. |
|
That's great~ |
|
Hi @roxyboy, I've recently found that in a 2D homogeneous turbulence, the zonal/meridional spectra are not the same as isotropic spectra. The following codes passed the test of Parseval's thereom: import xrft
import numpy.testing as npt
import xarray as xr
import numpy as np
ds = xr.open_dataset('/mnt/Data3/2DTurbulence/8192/non/sim_bih_ray_flow_part09.nc', chunks={'time':1})
psi = ds.psi[0].load() # 8192 * 8192 streamfunction
psihx = xrft.power_spectrum(psi, dim=['x'], scaling='density').mean('y') # x-component
psihy = xrft.power_spectrum(psi, dim=['y'], scaling='density').mean('x') # y-component
psihi = xrft.isotropic_power_spectrum(psi, dim=['x', 'y'], scaling='density',
truncate=True) # r-component
npt.assert_almost_equal((psi**2 * dx).sum('x').mean('y'), # variance in grid space
psihx.sum('freq_x'), decimal=5) # variance in spectral space
npt.assert_almost_equal((psi**2 * dy).sum('y').mean('x'), # variance in grid space
psihy.sum('freq_y'), decimal=5) # variance in spectral space
npt.assert_almost_equal((psi**2 * dx * dy).sum(['x', 'y']), # total variance in grid space
psihi.sum('freq_r'), decimal=5) # total variance in spectral spacewhich is a bit surprising to me that the radial spectra differs from x-/y-components by a constant. The constant could be Also, I find the docstring for |
Yes, they are not the same due to the Jacobian that is needed for coordinate transformation from Cartesian to polar coordinates.
Regarding the |
|
Thank you for sharing these. @roxyboy. I was trying to evaluate the spectra from a model simulation agaist SWOT observation. The calculation based on the model outputs uses 2D isotropic spectrum while the one based on SWOT uses along-track 1D power spectrum. Then how to reconcile these if they are not at the same energy level? |
|
I'm going to add back the option of taking the azimuthal mean in isotropizing the 2D spectra #225 . |


This PR tries to solve #219.
Also, we add 3D detrending codes, which may be useful when calculating 3D (2D space and 1D time) frequency-wavenumber spectrum.