# Utils Module

The utils module includes helper functions. The module currently contains a single function to help users convert numeric indexes to datetime indexes. Additional helper functions could be added at a later date.

Note

The names of the functions below are of the convention `path.path.function`. Only the function name is used when calling the function in MATLAB. For example, to call on `mhkit.wave.io.read_NDBC_file` simply use `read_NDBC_file`.

Functions

Description

`get_statistics`

Calculate mean, max, min and stdev statistics of continuous data for a given statistical window.

`excel_to_datetime`

Convert Excel datenum format to Python datetime.

`magnitude_phase`

Calculates magnitude and phase in two or three dimensions of the supplied vector.

mhkit.utils.excel_to_datetime(excel_num)

Convert excel datenum format to datetime

Parameters

excel_num (`vector`) – vector of excel datenums to be converted

Returns

time (DateTimeIndex) – vector of corresponding python datetime values

mhkit.utils.magnitude_phase(vector)

Calculates magnitude and phase in two or three dimensions call -> [mag, theta] = magnitude_phase({x; y}) call -> [mag, theta, phi] = magnitude_phase({x; y; z})

Parameters

vector (`cell array`) –

cell array consisting of x, y, and optionally the z component

of vector

x: array_like x component y: array like y component z: array like z component defined positive up (Optional)

Returns

varargout (array) – depending on number of inputs it will either output an array for magnitude and theta or one for magnitude, theta, and phi

magnitude: array - magnitude of vector theta: array - radians from the x axis phi: array - radians from the z-axis defined as positive up

mhkit.utils.toggleToolbox(varargin)

## Initialize

mhkit.utils.bplot(x, varargin)

save the initial hold state of the figure.

mhkit.utils.get_statistics(data, freq, options)

Calculate mean, max, min and stdev statistics of continuous data for a given statistical window. Default length of statistical window (period) is based on IEC TS 62600-3:2020 ED1. Also allows calculation of statistics for multiple statistical windows of continuous data.

Parameters
• data (`strucutre`) – structure of variables to get statistics for with field called time.

• freq (`double or int`) – Sample rate of data [Hz]

• period (`double/int (optional)`) – Statistical window of interest [sec], default = 600 to call: get_statistics(data,freq,”period”,period)

• vector_channels (`cell array of strings (optional)`) – List of channel names that are to be vector averaged to call: get_statistics(data,freq,”vector_channels”,vector_channels)

Returns

stats (structure) – Structure with mean, max, min, and stdev of each variable

mhkit.utils.uninstall_all_toolboxes()

Uninstall all currently installed toolboxes

Parameters

none

Returns

result (boolean) – 0 = success, 1 = failure, not all toolboxes uninstalled