Read methods

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.


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

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

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


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

Read data of an opened RSK file.

  • 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 If already contains data, the newly queried data replaces anything in

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.


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


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).

  • 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.


>>> 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")


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

  • 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”.


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

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


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


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

Read the burst data of an opened RSK file.

  • 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.


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


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.

  • 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”.


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)”

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.


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


RSK.close() None

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


>>> rsk.close()

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