Closed mbruggs closed 10 months ago
That is an incredible time improvement and we should use this assuming there are no other tradeoffs. @cmichelenstrofer could you comment on @mbruggs proposed approach?
@ssolson The IFFT is the better approach for this. The only limitation is that the frequencies have to be evenly spaced (but I believe the current function enforces this anyways). In some applications (rare in practice tbh) you might want uneven spacing, such as the "equal energy binning". So maybe there is still an advantage to keeping a separate function that uses the sum of sines? @ryancoe thoughts?
I'd say it'd be relatively easy to check that frequency spacing and then select either the ifft
or summation of sinusoids depending on whether the spacing is equal.
This is primarily placeholder, I'm happy to contribute this improvement when I get a moment. The code below needs generalising to properly use the Dataframe that is passed in.
Describe the bug:
The computation of the surface elevation from a spectrum uses a 'sum of sines' approach which is prohibitively slow. During some experiments, trying calculate a 3hr sea state at 20Hz resolution crashed the python process on my machine, a 1hr sea state took 11s.
Alternative approach
Alternatively, we can use an approach using an
ifft
. For the same calculation that previously took 11s, theifft
version took 0.007s.The code below (loosely adapted to match current MHKit structure) gave the same results as the previous surface_elevation method using the sum of sines.