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: np.datetime64 | None = None, t2: np.datetime64 | None = None) None ¶
Read data of an opened RSK file.
- Parameters:
Retrieves data values from the .rsk file and populates
RSK.data
. IfRSK.data
already contains data, the newly queried data replaces anything inRSK.data
.If you would like to read in only a subsection of the database, the
t1
andt2
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:
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: 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:
- 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 inRSK.regions
.Example:
>>> profileIndices = rsk.getprofilesindices() ... upcastIndices = rsk.getprofilesindices(direction="up") ... firstDowncastIndices = rsk.getprofilesindices(profiles=1, direction="down")
readprocesseddata¶
- RSK.readprocesseddata(t1: np.datetime64 | None = None, t2: np.datetime64 | None = None) None ¶
Read the burst data of an opened RSK file.
- Parameters:
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:
RSK –
RSK
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.3871564099200167,49.5725,21.8453,95.3111564099200333,49.5948,21.8752,95.237where 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.