Beispiel #1
0
def plot_elevation_timeseries(eta, ax=None):
    """
    Plot wave surface elevation time-series
    
    Parameters
    ------------
    eta: pandas DataFrame
        Wave surface elevation [m] indexed by time [datetime or s]
    ax : matplotlib axes object
        Axes for plotting.  If None, then a new figure is created.
        
    Returns
    ---------
    ax : matplotlib pyplot axes
            
    """

    assert isinstance(eta, pd.DataFrame), 'eta must be of type pd.DataFrame'

    ax = _xy_plot(eta.index,
                  eta,
                  fmt='-',
                  xlabel='Time',
                  ylabel='$\eta$ [m]',
                  ax=ax)

    return ax
Beispiel #2
0
def plot_spectrum(S, ax=None):
    """
    Plots wave amplitude spectrum versus omega

    Parameters
    ------------
    S: pandas DataFrame
        Spectral density [m^2/Hz] indexed frequency [Hz]
    ax : matplotlib axes object
        Axes for plotting.  If None, then a new figure is created.
    Returns
    ---------
    ax : matplotlib pyplot axes

    """
    assert isinstance(S, pd.DataFrame), 'S must be of type pd.DataFrame'

    f = S.index

    ax = _xy_plot(f * 2 * np.pi,
                  S / (2 * np.pi),
                  fmt='-',
                  xlabel='omega [rad/s]',
                  ylabel='Spectral density [m$^2$s/rad]',
                  ax=ax)

    return ax
Beispiel #3
0
def plot_current_timeseries(directions,
                            velocities,
                            principal_direction,
                            label=None,
                            ax=None):
    '''
    Returns a plot of velocity from an array of direction and speed
    data in the direction of the supplied principal_direction.

    Parameters
    ----------
    directions: array-like
        Time-series of directions [degrees]
    velocities: array-like
        Time-series of speeds [m/s]
    principal_direction: float
        Direction to compute the velocity in [degrees]
    label: string
        Label to use in the legend
    ax : matplotlib axes object
        Axes for plotting.  If None, then a new figure with a single 
        axes is used.  

    Returns
    -------
    ax: figure
        Time-series plot of current-speed velocity
    '''
    assert isinstance(velocities,(np.ndarray, pd.Series)), \
        'velocities  must be of type np.ndarry or pd.Series'
    assert isinstance(directions,(np.ndarray, pd.Series)), \
        'directions  must be of type np.ndarry or pd.Series'
    assert len(velocities) == len(directions),  \
        'velocities and directions  must have the same length'
    assert all(velocities.values >= 0),\
        'All velocities must be positive'
    assert all(directions.values >= 0) and all(directions.values <= 360),\
        'directions must be between 0 and 360 degrees'
    assert isinstance(principal_direction, (int, float)), \
        'principal_direction must be of type int or float'
    assert principal_direction >=0 and principal_direction <=360,\
        'principal_direction must be between 0 and 360 degrees'

    # Rotate coordinate system by supplied principal_direction
    principal_directions = directions - principal_direction
    # Calculate the velocity
    velocity = velocities * np.cos(np.pi / 180 * principal_directions)
    # Call on standard xy plotting
    ax = _xy_plot(velocities.index,
                  velocity,
                  fmt='-',
                  label=label,
                  xlabel='Time',
                  ylabel='Velocity [$m/s$]',
                  ax=ax)
    return ax
Beispiel #4
0
def plot_current_timeseries(directions,
                            speeds,
                            principal_direction,
                            label=None,
                            ax=None):
    '''
    Returns a plot of velocity from an array of direction and speed
    data in the direction of the supplied principal_direction.

    Parameters
    ----------
    direction: array-like
        Time-series of directions [degrees]
    speed: array-like
        Time-series of speeds [m/s]
    principal_direction: float
        Direction to compute the velocity in [degrees]
    label: string
        Label to use in the legend
    ax : matplotlib axes object
        Axes for plotting.  If None, then a new figure with a single 
        axes is used.  

    Returns
    -------
    ax: figure
        Time-series plot of current-speed velocity
    '''
    # Rotate coordinate system by supplied principal_direction
    principal_directions = directions - principal_direction
    # Calculate the velocity
    velocities = speeds * np.cos(np.pi / 180 * principal_directions)
    # Call on standard xy plotting
    ax = _xy_plot(velocities.index,
                  velocities,
                  fmt='-',
                  label=label,
                  xlabel='Time',
                  ylabel='Velocity [$m/s$]',
                  ax=ax)
    return ax
Beispiel #5
0
def plot_spectrum(S, ax=None):
    """
    Plots wave amplitude spectrum versus omega
    
    Parameters
    ------------
    S: pandas DataFrame
        Spectral density [m^2/Hz] indexed frequency [Hz]
    ax : matplotlib axes object
        Axes for plotting.  If None, then a new figure is created.
    Returns
    ---------
    ax : matplotlib pyplot axes
    
    """
    assert isinstance(S, pd.DataFrame), 'S must be of type pd.DataFrame'

    f = S.index

    ax = _xy_plot(f * 2 * np.pi,
                  S / (2 * np.pi),
                  fmt='-',
                  xlabel='omega [rad/s]',
                  ylabel='Spectral density [m$^2$s/rad]',
                  ax=ax)
    """
    spectrum_type = S.columns
    if S.shape[1] == 1:
        Hm0 = _sig_wave_height(S).iloc[0,0]
        Tp0 = _peak_period(S).iloc[0,0]
        title = 'Spectrum: ' + spectrum_type[0] + ' \n Tp = {:0.2f}, Hs = {:0.2f}'.format(Tp0,Hm0)
        ax.set_title(title)
    else:
        ax.legend(spectrum_type)
    """
    return ax
Beispiel #6
0
def plot_environmental_contour(x1, x2, x1_contour, x2_contour, **kwargs):
    '''
    Plots an overlay of the x1 and x2 variables to the calculate
    environmental contours.
    Parameters
    ----------
    x1: numpy array  
        x-axis data
    x2: numpy array 
        x-axis data
    x1_contour: numpy array 
        Calculated x1 contour values
    x2_contour: numpy array 
        Calculated x2 contour values 
    **kwargs : optional         
        x_label: string (optional)
            x-axis label. Default None. 
        y_label: string (optional)
            y-axis label. Default None.
        data_label: string (optional)
            Legend label for x1, x2 data (e.g. 'Buoy 46022'). 
            Default None.
        contour_label: string or list of strings (optional)
            Legend label for x1_contour, x2_contour countor data 
            (e.g. '100-year contour'). Default None.
        ax : matplotlib axes object (optional)
            Axes for plotting.  If None, then a new figure is created.
            Default None.
    Returns
    -------
    ax : matplotlib pyplot axes
    '''
    
    assert isinstance(x1, np.ndarray), 'x1 must be of type np.ndarray'
    assert isinstance(x2, np.ndarray), 'x2 must be of type np.ndarray'
    assert isinstance(x1_contour, np.ndarray), ('x1_contour must be of '
                                                'type np.ndarray')
    assert isinstance(x2_contour, np.ndarray), ('x2_contour must be of '
                                               'type np.ndarray')
    x_label = kwargs.get("x_label", None)
    y_label = kwargs.get("y_label", None)
    data_label=kwargs.get("data_label", None)
    contour_label=kwargs.get("contour_label", None)
    ax=kwargs.get("ax", None)
    assert isinstance(data_label, str), 'data_label must be of type str'
    assert isinstance(contour_label, (str,list)), ('contour_label be of '
                                                  'type str')
    assert x2_contour.ndim == x1_contour.ndim,  ('contour must be of' 
            f'equal dimesion got {x2_contour.ndim} and {x1_contour.ndim}')                                                  
    
        
    if x2_contour.ndim == 1:
        x2_contour  = x2_contour.reshape(-1,1) 
        x1_contour = x1_contour.reshape(-1,1) 
    
    N_contours = x2_contour.shape[1]
    
    if contour_label != None:
        if isinstance(contour_label, str):
            contour_label = [contour_label] 
        N_c_labels = len(contour_label)
        assert  N_c_labels == N_contours, ('If specified, the '
             'number of contour lables must be equal to number the '
            f'number of contour years. Got {N_c_labels} and {N_contours}')   
    else:
        contour_label = [None] * N_contours
    
    for i in range(N_contours):       
        ax = _xy_plot(x1_contour[:,i], x2_contour[:,i],'-', 
                      label=contour_label[i], ax=ax)
            
    ax = plt.plot(x1, x2, 'bo', alpha=0.1, 
                  label=data_label) 
    plt.legend(loc='lower right')
    plt.xlabel(x_label)
    plt.ylabel(y_label)
    plt.tight_layout()
    return ax