Utilities

rsktime2datetime

utils.rsktime2datetime() datetime64

Converts milliseconds (e.g., a timestamp from a .rsk file) into a NumPY datetime64 object with millisecond precision.

Parameters:

rsktime (int) – RSK time/milliseconds to convert.

Returns:

np.datetime64 – the resultant datetime64 object.

datetime2rsktime

utils.datetime2rsktime() int

Converts a NumPY datetime64 object (of any precision) into milliseconds (integer value).

Parameters:

datetime (np.datetime64) – the datetime64 object to convert.

Returns:

int – the resultant milliseconds integer.

formatchannelname

utils.formatchannelname() str

Take a given channel name and return a formatted version adhering to the standard used by pyRSKtools.

Parameters:

unformattedChannelName (str) – the unformatted channel.

Returns:

str – the input channel formatted.

Example:

>>> formatchannelname("Conductivity") # = "conductivity"
... formatchannelname("Dissolved O₂ saturation") # = "dissolved_o2_saturation"
... formatchannelname("1/10 wave height") # = "one_tenth_wave_height"

createuniquechannelname

utils.createuniquechannelname(existingChannelNames: Collection[str]) str

Format the given channel name using formatchannelname() and, if needed, alter it further to make sure it is unique against the list of existing channel names.

This method is most useful when you already have an established list of channel names (e.g., RSK.channelNames) and want to append an additional channel.

Parameters:
  • unformattedChannelName (str) – the channel to format.

  • existingChannelNames (Collection[str]) – a list of already existing channels.

Returns:

str – the original channel name but properly formatted/unique.

The example below outputs "conductivity1" if the channel exists in rsk.channelNames, or "conductivity" if the channel does not exist in the list.

Example:

>>> createuniquechannelname("Conductivity", rsk.channelNames)

intoarray

utils.intoarray(dtype: str = 'float64') ndarray[Any, dtype[ScalarType]]

Tries to transform any given value into a 1-D NumPY array with the specified data type.

Parameters:
  • data (Any) – the data to try and convert (e.g., the value of type int, list, iterable, etc)

  • dtype (str) – the data type of the created NumPY array (any valid NumPY type). Defaults to “float64”.

Raises:

ValueError – if the given value could not be transformed into a NumPY array.

Returns:

npt.NDArray – the 1-D NumPY array containing the passed-in values.

Example:

>>> intoarray(1)
... intoarray([1, 2, 3])
... intoarray(range(3))