Read methods

open

RSK.open() None

Open an RBR RSK file and read any available metadata.

Makes a connection to an RSK (SQLite format) database as obtained from an RBR data logger and reads in the instrument’s metadata. It populates the current instance with the metadata.

Example:

>>> rsk = RSK("example.rsk", readHiddenChannels=True)
... rsk.open()

This method is automatically invoked when using the RSK class context manager:

>>> with RSK("example.rsk") as rsk:
...    # RSK is open here

readdata

RSK.readdata(t1: Optional[np.datetime64] = None, t2: Optional[np.datetime64] = None) None

Read data of an opened RSK file.

Parameters:
  • t1 (np.datetime64, optional) – start time for the range of data to be read. Defaults to None.

  • t2 (np.datetime64, optional) – end time for the range of data to be read. Defaults to None.

Retrieves data values from the .rsk file and populates RSK.data. If RSK.data already contains data, the newly queried data replaces anything in RSK.data.

If you would like to read in only a subsection of the database, the t1 and t2 arguments can be used to enter start and end times in the form of a NumPY datetime64 object.

Example:

>>> rsk.readdata()
... # Optional arguments
... tstart = np.datetime64("2022-05-03")
... tend = np.datetime64("2022-05-04")
... rsk.readdata(tstart, tend)

computeprofiles

RSK.computeprofiles(pressureThreshold: float = 3.0, conductivityThreshold: float = 0.05) None

Compute profiles in a time series using pressure and conductivity data (if it exists).

Parameters:
  • pressureThreshold (float, optional) – pressure threshold. Defaults to 3.0.

  • conductivityThreshold (float, optional) – conductivity threshold. Defaults to 0.05.

Detects profiles using the pressure channel in the RSK and populates RSK.regions with the produced metadata.

The algorithm runs through the pressure data of the RSK and finds instances of a pressure reversal that is greater than pressureThreshold or 5% of the pressure differential of the last profile (whichever is greater). If it detects a pressure reversal it goes back to find the minimum or maximum pressure since the last event and records it as the beginning of the upcast or downcast, depending on the direction of the reversal.

When a conductivity channel is available, the algorithm records the samples where the conductivity is less than conductivityThreshold as out of the water and excludes them from the cast.

The default pressureThreshold of 3 dbar may be too large for short profiles. Consider using one-quarter of the pressure range as a guideline, (max(Pressure) - min(Pressure)) * 1/4.

Example:

>>> rsk.computeprofiles()
... # Optional arguments
... rsk.computeprofiles(pressureThreshold=5.0, conductivityThreshold=0.06)

This next example illustrates how to use this method in combination with RSK.getprofilesindices() to parse a time series of data into individual upcasts and downcasts.

>>> with RSK("example.rsk") as rsk:
...     rsk.readdata()
...     print(rsk)
...     # RSK
...     # ...
...     #   .regions is unpopulated
...     # ...
...     rsk.computeprofiles()
...     print(rsk)
...     # RSK
...     # ...
...     #   .regions is populated with 45 elements
...     # ...
...     upcastIndices = rsk.getprofilesindices(direction="up")
...     downcastIndices = rsk.getprofilesindices(direction="down")

getprofilesindices

RSK.getprofilesindices(profiles: Union[int, Collection[int]] = [], direction: str = 'both') List[List[int]]

Get a list of indices for each profile or cast direction used to index into RSK.data.

Parameters:
  • profiles (Union[int, Collection[int]], optional) – profile number(s) to select. Defaults to [] (all profiles).

  • direction (str, optional) – cast direction of either “up”, “down”, or “both”. Defaults to “both”.

Returns:

List[List[int]] – a list of profile/cast indices; each element in the returned list is a list itself which may be used to index into RSK.data.

This method quickly computes a list (of lists) of indices into RSK.data for each profile/cast using the metadata in RSK.regions.

Example:

>>> profileIndices = rsk.getprofilesindices()
... upcastIndices = rsk.getprofilesindices(direction="up")
... firstDowncastIndices = rsk.getprofilesindices(profiles=1, direction="down")

readprocesseddata

RSK.readprocesseddata(t1: Optional[np.datetime64] = None, t2: Optional[np.datetime64] = None) None

Read the burst data of an opened RSK file.

Parameters:
  • t1 (np.datetime64, optional) – start time for a range of burst data to be read. Defaults to None.

  • t2 (np.datetime64, optional) – end time for a range of burst data to be read. Defaults to None.

This function reads all or a subset (determined by t1 and t2) of the burst data and writes it to the RSK.processedData variable of this instance.

When a dataset has burst data, the raw high-frequency values reside in the RSK.processedData field. This field is composed of one sample for each burst with a timestamp set to be the first value of each burst period; the sample is the average of the values during the corresponding burst.

Example:

>>> rsk.readprocesseddata()
... # Optional arguments
... tstart = np.datetime64("2022-05-03")
... tend = np.datetime64("2022-05-04")
... rsk.readprocesseddata(tstart, tend)

csv2rsk

classmethod RSK.csv2rsk(fname: str, model: str = 'unknown', serialID: int = 0, firmwareVersion: str = 'NA', firmwareType: int = 103, partNumber: str = 'unknown') RSK

Convert a CSV file into an RSK class instance.

Parameters:
  • fname (str) – name of the CSV file

  • model (str, optional) – instrument model from which data was collected. Defaults to “unknown”.

  • serialID (int, optional) – serial ID of the instrument. Defaults to 0.

  • firmwareVersion (str, optional) – firmware version of the instrument, e.g., 1.135. Defaults to “NA”.

  • firmwareType (int, optional) – firmware type of the instrument, e.g., 103. Defaults to 103.

  • partNumber (str, optional) – instrument part number. Defaults to “unknown”.

Returns:

RSKRSK class instance populated with the given CSV data.

The function reads in a CSV file and creates an RSK class instance. The header of the CSV file must follow exactly the format below to make the function work:

“timestamp (ms)”,”conductivity (mS/cm)”,”temperature (°C)”,”pressure (dbar)”
1564099200000,49.5392,21.8148,95.387
1564099200167,49.5725,21.8453,95.311
1564099200333,49.5948,21.8752,95.237

where the first column represents the timestamp, which is milliseconds elapsed since Jan 1 1970 (i.e. UNIX time or POSIX time). The header for each column is comprised with channel name followed by space and unit (with parentheses) with double quotes.

Example:

>>> rsk = RSK.csv2rsk("example.csv")
... # Optional arguments
... rsk = RSK.csv2rsk("example.csv", model="RBRconcerto", serialID=200004)

close

RSK.close() None

Closes the connection made to the RSK (SQLite format) database.

Example:

>>> rsk.close()

NOTE: This method is automatically invoked when using the context manager approach.