MHKiT-Software / MHKiT-Python

MHKiT-Python provides the marine renewable energy (MRE) community tools for data processing, visualization, quality control, resource assessment, and device performance.
https://mhkit-software.github.io/MHKiT/
BSD 3-Clause "New" or "Revised" License
47 stars 45 forks source link

Provide more general zero up crossing analysis #230

Closed mbruggs closed 8 months ago

mbruggs commented 1 year ago

Describe the bug:

At present an upcrossing analysis is performed in the loads.extreme.global_peaks function. In that case the maximum value between up crossings is returned.

I had a case today where I wanted to find the heights of the individual waves in a time series. To do this, I pulled the zero crossing code from global_peaks and modified it to the below

def wave_heights(t, data):
    assert isinstance(t, np.ndarray), 't must be of type np.ndarray'
    assert isinstance(data, np.ndarray), 'data must be of type np.ndarray'

    # eliminate zeros
    zeroMask = (data == 0)
    data[zeroMask] = 0.5 * np.min(np.abs(data))
    # zero up-crossings
    diff = np.diff(np.sign(data))
    zeroUpCrossings_mask = (diff == 2) | (diff == 1)
    zeroUpCrossings_index = np.where(zeroUpCrossings_mask)[0]
    zeroUpCrossings_index = np.append(zeroUpCrossings_index, len(data) - 1)

    nwaves = len(zeroUpCrossings_index)

    H = np.empty(nwaves-1)
    for i in range(nwaves - 1):
        use = data[zeroUpCrossings_index[i]:zeroUpCrossings_index[i + 1]]
        H[i] = np.max(use) - np.min(use)

    return H

It would be nice to pull out the zero crossing part to a helper function and provide some new functions in the wave module for

What does the MHKit team think about this?

Happy to contribute the change when I have a moment.

ssolson commented 1 year ago

@mbruggs this looks like a perfect fit for MHKiT. I would recommend this for inclusion in MHKiT and could work with you to help develop examples and tests but could not lead the design. I think an example of the functions in a new example or as an expansion of the previous would help me understand better how this fits into MHKiT.

akeeste commented 8 months ago

Resolved by #252