MHKiT-Python
MHKiT-Python copied to clipboard
Speed up wave.resource module
@ssolson This is a follow-up to my other wave PRs and resolves #331. Handling the various edge cases robustly in pure numpy is difficult, so I want to first resolve #331 by using DataArrays throughout the wave resource functions instead of Datasets.
Similar to Ryan's testing mentioned in #331, I found that using DataArrays/Pandas has a 1000x speed up vs Datasets for very large input data. This should restore MHKiT's speed to it's previous state. Using a pure numpy base would have an additional 5-10x speed up from DataArrays, but I think the current work with DataArrays will:
- be sufficient for our users
- be easier to develop with
- be easier to handle edge cases
Before I go forward and apply this change to the rest of the wave.resource module, can you test out energy_period and frequency_moment and try to break them? With the appropriate frequency_dimension input, those functions should handle Pandas Series, Pandas DataFrames, and xarray DataArrays regardless of input shape, dimensions names, dimension order, etc.