Skip to content

Provide more general zero up crossing analysis #230

@mbruggs

Description

@mbruggs

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

  • wave height
  • zero crossing period
  • crests (essentially what global_peaks is now)
  • troughs

What does the MHKit team think about this?

Happy to contribute the change when I have a moment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions