Grid#
- class waveresponse.Grid(freq, dirs, vals, freq_hz=False, degrees=False, clockwise=False, waves_coming_from=True)[source]#
Two-dimentional frequency/(wave)direction grid.
- Parameters:
freq (array-like) – 1-D array of grid frequency coordinates. Positive and monotonically increasing.
dirs (array-like) – 1-D array of grid direction coordinates. Positive and monotonically increasing. Must cover the directional range [0, 360) degrees (or [0, 2 * numpy.pi) radians).
vals (array-like (N, M)) – Values associated with the grid. Should be a 2-D array of shape (N, M), such that
N=len(freq)andM=len(dirs).freq_hz (bool) – If frequency is given in ‘Hz’. If
False, ‘rad/s’ is assumed.degrees (bool) – If direction is given in ‘degrees’. If
False, ‘radians’ is assumed.clockwise (bool) – If positive directions are defined to be ‘clockwise’ (
True) or ‘counterclockwise’ (False). Clockwise means that the directions follow the right-hand rule with an axis pointing downwards.waves_coming_from (bool) – If waves are ‘coming from’ the given directions. If
False, ‘going towards’ convention is assumed.
- dirs(degrees=None)[source]#
Direction coordinates.
- Parameters:
degrees (bool) – If directions should be returned in ‘degrees’. If
False, ‘radians’ is used. Defaults to original units used during initialization.
- freq(freq_hz=None)[source]#
Frequency coordinates.
- Parameters:
freq_hz (bool) – If frequencies should be returned in ‘Hz’. If
False, ‘rad/s’ is used. Defaults to original units used during initialization.
- classmethod from_grid(grid)[source]#
Construct from a Grid-like object.
- Parameters:
grid (obj) – Grid object.
- Returns:
Initialized object.
- Return type:
cls
- grid(freq_hz=None, degrees=None)[source]#
Return a copy of the object’s frequency/direction coordinates and corresponding grid values.
- Parameters:
- Returns:
freq (array) – 1-D array of grid frequency coordinates.
dirs (array) – 1-D array of grid direction coordinates.
vals (array (N, M)) – Grid values as 2-D array of shape (N, M), such that
N=len(freq)andM=len(dirs).
- property imag#
Return a new Grid object where all values are converted to their imaginary part.
- interpolate(freq, dirs, freq_hz=False, degrees=False, complex_convert='rectangular', fill_value=0.0)[source]#
Interpolate (linear) the grid values to match the given frequency and direction coordinates.
A ‘fill value’ is used for extrapolation (i.e. freq outside the bounds of the provided 2-D grid). Directions are treated as periodic.
- Parameters:
freq (array-like) – 1-D array of grid frequency coordinates. Positive and monotonically increasing.
dirs (array-like) – 1-D array of grid direction coordinates. Positive and monotonically increasing.
freq_hz (bool) – If frequency is given in ‘Hz’. If
False, ‘rad/s’ is assumed.degrees (bool) – If direction is given in ‘degrees’. If
False, ‘radians’ is assumed.complex_convert (str, optional) – How to convert complex number grid values before interpolating. Should be ‘rectangular’ or ‘polar’. If ‘rectangular’ (default), complex values are converted to rectangular form (i.e., real and imaginary part) before interpolating. If ‘polar’, the values are instead converted to polar form (i.e., amplitude and phase) before interpolating. The values are converted back to complex form after interpolation.
fill_value (float or None) – The value used for extrapolation (i.e., freq outside the bounds of the provided grid). If
None, values outside the frequency domain are extrapolated via nearest-neighbor extrapolation. Note that directions are treated as periodic (and will not need extrapolation).
- Returns:
Interpolated grid values.
- Return type:
array
- property real#
Return a new Grid object where all values are converted to their real part.
- reshape(freq, dirs, freq_hz=False, degrees=False, complex_convert='rectangular', fill_value=0.0)[source]#
Reshape the grid to match the given frequency/direction coordinates. Grid values will be interpolated (linear).
- Parameters:
freq (array-like) – 1-D array of new grid frequency coordinates. Positive and monotonically increasing.
dirs (array-like) – 1-D array of new grid direction coordinates. Positive and monotonically increasing. Must cover the directional range [0, 360) degrees (or [0, 2 * numpy.pi) radians).
freq_hz (bool) – If frequency is given in ‘Hz’. If
False, ‘rad/s’ is assumed.degrees (bool) – If direction is given in ‘degrees’. If
False, ‘radians’ are assumed.complex_convert (str, optional) – How to convert complex number grid values before interpolating. Should be ‘rectangular’ or ‘polar’. If ‘rectangular’ (default), complex values are converted to rectangular form (i.e., real and imaginary part) before interpolating. If ‘polar’, the values are instead converted to polar form (i.e., amplitude and phase) before interpolating. The values are converted back to complex form after interpolation.
fill_value (float or None) – The value used for extrapolation (i.e., freq outside the bounds of the provided grid). If
None, values outside the frequency domain are extrapolated via nearest-neighbor extrapolation. Note that directions are treated as periodic (and will not need extrapolation).
- Returns:
A copy of the object where the underlying coordinate system is reshaped.
- Return type:
obj
- rotate(angle, degrees=False)[source]#
Rotate the underlying grid coordinate system a given angle.
All directions are converted so that:
dirs_new = dirs_old - angle
Note that the direction of positive rotation follows the set ‘wave convention’.
- set_wave_convention(clockwise=True, waves_coming_from=True)[source]#
Set wave direction convention.
Directions and values will be converted (in-place) to the given convention.
- Parameters:
clockwise (bool) – If positive directions are defined to be ‘clockwise’ (
True) or ‘counterclockwise’ (False). Clockwise means that the directions follow the right-hand rule with an axis pointing downwards.waves_coming_from (bool) – If waves are ‘coming from’ the given directions. If
False, ‘going towards’ convention is assumed.
- property wave_convention#
Wave direction convention.