Export functions

RSK2CSV

RSK2CSV(RSK)

RSK2CSV - Write one or more CSV files of logger data and metadata.

Syntax:

RSK2CSV(RSK, [OPTIONS])

RSK2CSV outputs the RSK structure format into one or more CSV file. The CSV file contains important logger metadata and a row of variable names and units above each column of channel data. If the data has been parsed into profiles, then one file will be written for each profile. Furthermore, an extra column called ‘cast_direction’ will be included. The column will contain ‘d’ or ‘u’ to indicate whether the sample is part of the downcast or upcast, respectively.

Note: The header also includes entries for station metadata, although as of RSKtools v2.2.0 these must be populated by the user. In future versions of RSKtools some of these fields may be filled automatically using, for example, Ruskin annotations.

Below is an example of a CSV file created with RSK2CSV:

//Creator: RBR Ltd
//Create Time: 23-Jan-2018 09:49:17
//Instrument model firmware and serialID: RBRmaestro 12.03 80217
//Sample period: 0.167 second
//Processing history:
///Users/RZhang/code/rsk_files/080217_20150919_1417.rsk opened using RSKtools v2.1.0.
//Sea pressure calculated using an atmospheric pressure of 10.1325 dbar.
//Cruise:
//Station:
//Vessel:
//Latitude:
//Longitude:
//Depth:
//Date:
//Weather:
//Crew:
//Comment: Hey Jude

//Time(yyyy-mm-dd HH:MM:ss.FFF),  Conductivity(mS/cm),   Pressure(dbar),   Dissolved_O2(%)
2015-09-19 08:32:16.000,           34.6058,           12.6400,          694.7396
2015-09-19 08:32:16.167,           34.6085,           12.4154,          682.4502
2015-09-19 08:32:16.333,           34.6130,           12.4157,          666.1949

Inputs:

Required:

  • RSK – Structure containing the logger metadata, along with the added ‘data’ field.

Optional:

  • channel – Longname of channel(s) to include in CSV file (e.g., temperature, salinity, etc), default is all channels.

  • profile – Profile number for output CSV files, default is all profiles.

  • direction – Direction for output CSV files, default is both.

  • outputdir – directory for output CSV files, default is current directory.

  • comment – Extra comments to attach to the end of the header.

  • schedules – which schedule(s) this function should export. Default is ‘all’, which exports all schedules with each schedule in a separate CSV. Can be ‘all’, ‘default’, a label string, or cell array of label strings. Here ‘default’ is the reserved generic default selector, not a literal label: it resolves to the schedule with the most non-NaN Conductivity samples, then Temperature, then schedule 1.

Outputs:

CSV file - Output CSV file contains logger metadata, processing log entries, user-defined comments, and column data of selected channels.

Example:

rsk = RSKopen(fname);
rsk = RSKreadprofiles(rsk);
RSK2CSV(rsk,'channel',{'Temperature','Pressure'},'outputdir','/Users/decide/where','comment','Hey Jude');

RSK2ODV

RSK2ODV(RSK)

RSK2ODV - Creates one or multiple Ocean Data View (ODV) output from a RSK structure.

Syntax:

RSK2ODV(RSK, [OPTIONS])

RSK2ODV outputs the RSK structure format into ODV (txt) file(s). The ODV file contains some logger metadata and a row of variable names and units above each column of channel data. If the data has been parsed into profiles, then one file will be written for each profile. Furthermore, an extra column called ‘cast_direction’ will be included, where ‘d’ indicates downcast while ‘u’ indicates upcast.

Notes: Cruise, station, longitude, latitude and bottom depth are set to C1, S1, 0.0, 0.0 and 0.0 respectively as default. They will be filled automatically with Ruskin annotations if they were added by the user. Alternatively, they can be populated with RSKaddstationdata.m.

Output samples as below:

//<Creator>RBR</Creator>
//<CreateTime>30-Nov-2017 17:20:01</CreateTime>
//<Software>RSKtools</Software>
//<Source></Source>
//<SourceLast-Modified></SourceLast-Modified>
//<Version>ODV Spreadsheet V4.0</Version>
//<DataField>Ocean</DataField>
//<DataType>Profile</DataType>
//<DataVariable>label="Cast_direction" value_type="TEXT" is_primary_variable="F" comment="d-downcast u-upcast"</DataVariable>
//<MissingDataValues>NaN</MissingDataValues>
// Model=RBRmaestro
// Firmware=12.03
// Serial=80217
//Processing history:
///Users/RZhang/code/rsk_files/080217_20150919_1417.rsk opened using RSKtools v2.3.0.
//Sea pressure calculated using an atmospheric pressure of 10.1325 dbar.
//Comment: Hey Jude

Cruise Station Type    yyyy-mm-ddTHH:MM:ss.FFF Longitude[degrees_east] Latitude [degrees_north]        Bot. Depth [m]  Conductivity[mS/cm]     Pressure[dbar]  Dissolved_O2[%] Cast_direction
C1     S1      C       2015-09-19T08:59:05.000 0.0     0.0     0.0     34.2349 79.0907 472.6810        d
C1     S1      C       2015-09-19T08:59:05.167 0.0     0.0     0.0     34.2363 78.8998 472.5748        d
C1     S1      C       2015-09-19T08:59:05.333 0.0     0.0     0.0     34.2414 78.7738 472.5124        d

Inputs:

Required:

  • RSK – Structure containing the logger metadata, along with the added ‘data’ field.

Optional:

  • channel – Longname of channel for output in ODV file (e.g., temperature, salinity, etc), default is all channels.

  • profile – Profile number for output ODV files, default is all profiles.

  • direction – Direction for output ODV files, default is both.

  • outputdir – Directory for output ODV files, default is current directory.

  • comment – Extra comments to attach to the end of the header.

  • schedules – which schedule(s) this function should export. Default is ‘all’, which exports all schedules with each schedule in a separate ODV. Can be ‘all’, ‘default’, a label string, or cell array of label strings. Here ‘default’ is the reserved generic default selector, not a literal label: it resolves to the schedule with the most non-NaN Conductivity samples, then Temperature, then schedule 1.

Outputs:

ODV file - Output ODV file contains logger metadata, processing log entries, user-defined comments, and column data of selected channels.

Example:

rsk = RSKopen(fname);
rsk = RSKreadprofiles(rsk);
RSK2ODV(rsk,'channel',{'Temperature','Pressure'},'outputdir','/Users/decide/where','comment','Hey Jude');

RSK2RSK

RSK2RSK(RSK)

RSK2RSK - Write current rsk structure into a new rsk file.

Syntax:

newfile = RSK2RSK(RSK, [OPTIONS])

RSK2RSK writes a new RSK file containing the data and various metadata from the Matlab rsk structure. It is designed to store post-processed data in a sqlite file that is readable by Ruskin. The new rsk file is in “EPdesktop” format, which is the simplest Ruskin table schema. RSK2RSK effectively provides a convenient method for Matlab users to easily share post-processed RBR logger data with others without recourse to CSV, MAT, or ODV files.

RSK2RSK only supports the v2 schema. A 3.0.0+ RSK (which includes all multi-schedule files) raises an error; use RSK2RSKFULL for those, which preserves the original schema.

Inputs:

Required:

  • RSK – rsk structure

Optional:

  • outputdir – directory for output rsk file, default is current directory.

  • suffix – string to append to output rsk file name, default is current time in format of YYYYMMDDTHHMM.

Outputs:

  • newfile – file name of output rsk file

Example:

rsk = RSKopen('rsk_file.rsk');
rsk = RSKreadprofiles(rsk);
rsk = RSKaddstationdata(rsk,'profile',1:3,'latitude',[45,44,46],'longitude',[-25,-24,-23]);
outputdir = '/Users/Tom/Jerry';
newfile = RSK2RSK(rsk,'outputdir',outputdir,'suffix','processed');

RSK2RSKFULL

RSK2RSKFULL(RSK)

RSK2RSKFULL - Write current rsk structure into a new rsk file with 3.0.0+ schema.

Syntax:

newfile = RSK2RSKFULL(RSK, inputpath, [OPTIONS])

RSK2RSKFULL writes a new RSK file containing the data and various metadata from the Matlab rsk structure. It is designed to store post-processed data in a sqlite file that is readable by Ruskin. The difference between this and RSK2RSK is that this function will retain all the information contained in the original RSK file, while adding changes such as post-processing made during the current session to the new RSK file. This function requires the original RSK file to exist when the function is called, and only supports RSK schema version 3.0.0 or higher.

The function handles both v3.0.0 and v3.2.0 schemas:
  • Channel table: writes original DB names via dbLongName (not renamed in-memory names), with NULL safety for derived channel fields.

  • instrumentChannel: inserts rows for new derived channels.

  • Data table: uses channelOrder for column naming (channelXX where XX matches instrumentChannel.channelOrder), DOUBLE type for v3.2.0.

  • Downsample caches: dropped and regenerated by Ruskin on open.

  • Row IDs: globally unique across schedules (v3.0.0 only).

Inputs:

Required:

  • RSK – rsk structure

  • inputpath – filepath for the original RSK file the current instance read from.

Optional:

  • outputdir – directory for output rsk file, default is current directory.

  • suffix – string to append to output rsk file name, default is current time in format of YYYYMMDDTHHMM.

Outputs:

  • newfile – file name of output rsk file

RSK2MAT

RSK2MAT(RSK)

RSK2MAT - Creates a structure array from a RSK structure.

Syntax:

[RBR] = RSK2MAT(RSK)

RSK2MAT converts the regular RSK structure format to the legacy .mat RBR structure array. The output structure (RBR) is similar to the .mat file generated by Ruskin but is missing some fields: comments, serialstarttime/serialendtime, derived channels, events, parameters and sample code.

NOTE: Only use this function if you previously have been using the .mat export from Ruskin and already have scripts set up to work with this layout. If possible use the .rsk files directly.

NOTE: In addition to returning the RBR structure, RSK2MAT also writes a <serialID>_<model>.mat file (containing the RBR structure) to the current working directory.

Inputs:

Required:

  • RSK – Structure containing the logger metadata, along with the added ‘data’ field.

Outputs:

  • RBR – Structure containing the logger data and some metadata in the same format as the .mat files exported by Ruskin.

Example:

rsk = RSKopen(fname);
rsk = RSKreaddata(rsk);
RBR = RSK2MAT(rsk);