This converts the contents of an object's metadata slot
into JSON format, using the toJSON() function from the
jsonlite library. Some conversion is required, and this
is also handled if the results are reconstituted using
json2metadata(). See “Details”.
metadata2json(m, digits = 15)contents of the metadata slot of an oce object.
integer, the number of digits to store in the JSON representation.
metadata2json returns a character value holding
the metadata slot in JSON, transformed as indicated in
the “Details” section.
Some metadata items cannot be handled by jsonlite::toJSON(), so
these are transformed as follows before storage in the return value
NOTE: the reverse function, json2metadata(), reverses all of these
transformations, so that the original metadata can be recovered.
Oce uses expression objects to store units, and these are converted
to character values using as.character() before converting to JSON.
Oce stores a raw matrix called codes for adp objects created from
RDI/Teledyne files, and so this is converted to an integer matrix
before converting to JSON.
The following items are converted from POSIXct values to character
values: date, endTime, startTime, and systemUploadTime.
Other things relating to serialization:
json2metadata()
# Example 1: CTD data
data("ctd")
metadata2json(ctd@metadata)
#> {
#> "units": {
#> "scan": {
#> "unit": [],
#> "scale": [""]
#> },
#> "timeS": {
#> "unit": ["s"],
#> "scale": [""]
#> },
#> "pressure": {
#> "unit": ["dbar"],
#> "scale": [""]
#> },
#> "depth": {
#> "unit": ["m"],
#> "scale": [""]
#> },
#> "temperature": {
#> "unit": ["degree * C"],
#> "scale": ["IPTS-68"]
#> },
#> "salinity": {
#> "unit": [],
#> "scale": ["PSS-78"]
#> },
#> "flag": {
#> "unit": [],
#> "scale": [""]
#> }
#> },
#> "flags": [],
#> "pressureType": ["sea"],
#> "deploymentType": ["unknown"],
#> "waterDepth": [null],
#> "dataNamesOriginal": {
#> "scan": ["scan"],
#> "timeS": ["timeS"],
#> "pressure": ["pr"],
#> "depth": ["depS"],
#> "temperature": ["t068"],
#> "salinity": ["sal00"],
#> "flag": ["flag"]
#> },
#> "model": ["25"],
#> "header": ["* Sea-Bird SBE 25 Data File:", "* FileName = C:\\SEASOFT3\\BASIN\\BED0302.HEX", "* Software Version 4.230a", "* Temperature SN = 1140", "* Conductivity SN = 832", "* System UpLoad Time = Oct 15 2003 11:38:38", "* Command Line = seasave ", "** Ship: Divcom3", "** Cruise: Halifax Harbour", "** Station: Stn 2", "** Latitude: N44 41.056", "** Longitude: w63 38.633", "* Real-Time Sample Interval = 1.000 seconds", "# nquan = 7", "# nvalues = 773 ", "# units = metric", "# name 0 = scan: scan number", "# name 1 = timeS: time [s]", "# name 2 = pr: pressure [db]", "# name 3 = depS: depth, salt water [m]", "# name 4 = t068: temperature, IPTS-68 [deg C]", "# name 5 = sal00: salinity, PSS-78 [PSU]", "# name 6 = flag: 0.000e+00", "# span 0 = 1, 773 ", "# span 1 = 0.000, 772.000 ", "# span 2 = -0.378, 163.899 ", "# span 3 = -0.375, 162.504 ", "# span 4 = 2.3237, 99.0000 ", "# span 5 = 0.3276, 99.0000 ", "# span 6 = 0.000e+00, 0.000e+00 ", "# interval = seconds: 1 ", "# start_time = Oct 15 1903 11:38:38", "# bad_flag = -9.990e-29", "# sensor 0 = Frequency 0 temperature, 1140, 13 Mar 03", "# sensor 1 = Frequency 1 conductivity, 832, 13 Mar 03, cpcor = -9.5700e-08", "# sensor 2 = Pressure Voltage, 145033, 17 Mar 03, cpcor = -9.5700e-08", "# sensor 3 = Stored Volt 0 transmissometer", "# datcnv_date = Oct 15 2003 13:46:47, 4.230a", "# datcnv_in = BED0302.HEX BED0301.CON", "# datcnv_skipover = 0", "# file_type = ascii", "*END*"],
#> "type": ["SBE"],
#> "hexfilename": ["c:\\seasoft3\\basin\\bed0302.hex"],
#> "serialNumber": [""],
#> "serialNumberTemperature": ["1140"],
#> "serialNumberConductivity": ["832"],
#> "systemUploadTime": ["2003-10-15 11:38:38"],
#> "ship": ["Divcom3"],
#> "scientist": [""],
#> "institute": [""],
#> "address": [""],
#> "cruise": ["Halifax Harbour"],
#> "station": ["Stn 2"],
#> "date": ["2003-10-15 11:38:38"],
#> "startTime": ["2003-10-15 15:38:38"],
#> "recoveryTime": [null],
#> "latitude": [44.684266666666666],
#> "longitude": [-63.643883333333335],
#> "sampleInterval": [1],
#> "sampleIntervalUnits": ["s"],
#> "filename": ["/Users/kelley/git/oce/create_data/ctd/ctd.cnv"]
#> }
# Example 2: ADP data
data("adp")
metadata2json(adp@metadata)
#> {
#> "units": {
#> "v": {
#> "unit": ["m/s"],
#> "scale": [""]
#> },
#> "distance": {
#> "unit": ["m"],
#> "scale": [""]
#> },
#> "pressure": {
#> "unit": ["dbar"],
#> "scale": [""]
#> },
#> "salinity": {
#> "unit": [],
#> "scale": ["PSS-78"]
#> },
#> "temperature": {
#> "unit": ["degree * C"],
#> "scale": ["ITS-90"]
#> },
#> "soundSpeed": {
#> "unit": ["m/s"],
#> "scale": [""]
#> },
#> "heading": {
#> "unit": ["degree"],
#> "scale": [""]
#> },
#> "pitch": {
#> "unit": ["degree"],
#> "scale": [""]
#> },
#> "roll": {
#> "unit": ["degree"],
#> "scale": [""]
#> },
#> "headingStd": {
#> "unit": ["degree"],
#> "scale": [""]
#> },
#> "pitchStd": {
#> "unit": ["degree"],
#> "scale": [""]
#> },
#> "rollStd": {
#> "unit": ["degree"],
#> "scale": [""]
#> },
#> "attitude": {
#> "unit": ["degree"],
#> "scale": [""]
#> },
#> "depth": {
#> "unit": ["m"],
#> "scale": [""]
#> }
#> },
#> "flags": [],
#> "oceCoordinate": ["enu"],
#> "orientation": ["upward", "upward", "upward", "upward", "upward", "upward", "upward", "upward", "upward", "upward", "upward", "upward", "upward", "upward", "upward", "upward", "upward", "upward", "upward", "upward", "upward", "upward", "upward", "upward", "upward"],
#> "instrumentType": ["adcp"],
#> "instrumentSubtype": ["workhorse"],
#> "firmwareVersionMajor": [16],
#> "firmwareVersionMinor": [28],
#> "firmwareVersion": ["16.28"],
#> "bytesPerEnsemble": [1832],
#> "systemConfiguration": ["11001011-01000001"],
#> "frequency": [600],
#> "beamAngle": [20],
#> "beamPattern": ["convex"],
#> "beamConfig": ["janus"],
#> "numberOfDataTypes": [6],
#> "dataOffset": [18, 77, 142, 816, 1154, 1492],
#> "codes": [
#> [127, 127],
#> [0, 0],
#> [128, 0],
#> [0, 1],
#> [0, 2],
#> [0, 3],
#> [0, 4]
#> ],
#> "numberOfBeams": [4],
#> "numberOfCells": [84],
#> "pingsPerEnsemble": [20],
#> "cellSize": [0.5],
#> "transducerDepth": [0],
#> "profilingMode": [1],
#> "lowCorrThresh": [0],
#> "numberOfCodeReps": [2],
#> "percentGdMinimum": [0],
#> "errorVelocityMaximum": [5000],
#> "coordTransform": ["00000111"],
#> "originalCoordinate": ["beam"],
#> "tiltUsed": [true],
#> "threeBeamUsed": [true],
#> "binMappingUsed": [true],
#> "headingAlignment": [0],
#> "headingBias": [0],
#> "sensorSource": ["01111111"],
#> "sensorsAvailable": ["00111101"],
#> "bin1Distance": [2.23],
#> "xmitPulseLength": [1.35],
#> "wpRefLayerAverage": [1281],
#> "falseTargetThresh": [50],
#> "transmitLagDistance": [86],
#> "cpuBoardSerialNumber": [158, 0, 0, 3, 1, 160, 95, 9],
#> "systemBandwidth": [0],
#> "serialNumber": ["(redacted)"],
#> "haveActualData": [true],
#> "ensembleNumber": [5041, 5401, 5761, 6121, 6481, 6841, 7201, 7561, 7921, 8281, 8641, 9001, 9361, 9721, 10081, 10441, 10801, 11161, 11521, 11881, 12241, 12601, 12961, 13321, 13681],
#> "manufacturer": ["teledyne rdi"],
#> "filename": ["(redacted)"],
#> "longitude": [-69.73433],
#> "latitude": [47.881259999999997],
#> "ensembleInFile": [9243361, 9903601, 10563841, 11224081, 11884321, 12544561, 13204801, 13865041, 14525281, 15185521, 15845761, 16506001, 17166241, 17826481, 18486721, 19146961, 19807201, 20467441, 21127681, 21787921, 22448161, 23108401, 23768641, 24428881, 25089121],
#> "velocityResolution": [0.001],
#> "velocityMaximum": [32.768000000000001],
#> "numberOfSamples": [25],
#> "oceBeamUnspreaded": [false],
#> "depthMean": [38.792000000000002],
#> "transformationMatrix": [
#> [1.461902200081544, -1.461902200081544, 0, 0],
#> [0, 0, -1.461902200081544, 1.461902200081544],
#> [0.266044443118978, 0.266044443118978, 0.266044443118978, 0.266044443118978],
#> [1.033720959109192, 1.033720959109192, -1.033720959109192, -1.033720959109192]
#> ],
#> "headSerialNumber": ["(redacted)"],
#> "deploymentName": ["(redacted)"],
#> "comments": ["sample ADP file"]
#> }