NOAA-PMEL / iot-data-landing

IoT Data Landing Project
The Unlicense
0 stars 0 forks source link

Discussion: Metadata JSON format #6

Open kwilcox opened 2 years ago

kwilcox commented 2 years ago

I suggest using the NCO-JSON[1][2][3] format for passing any JSON-based metadata around in the MQTT topics. It is very close to what the Payload: Data with metadata already defines and will allow us to standardize on the tools used to interpret and apply the metadata elsewhere.

[1] https://www.essoar.org/doi/abs/10.1002/essoar.10500689.1 [2] http://nco.sourceforge.net/nco.html#json [3] https://github.com/cf-json/cf-json.github.io/issues/10

For example:

"metadata": {
    "make": "MockCo",
    "model": "Sensor_1",
    "variables": {
        "time": {
            "long_name": "Time",
            "dimension": [
                "time"
            ]
        },
        "latitude": {
            "long_name": "Latitude",
            "data_type": "double",
            "units": "degrees_north",
            "dimension": [
                "time"
            ]
        }
    }
}

in NCO-JSON would be

"metadata": {
  "attributes": {
    "make": "MockCo",
    "model": "Sensor_1"
  },
  "variables": {
    "time": {
      "shape": ["time"],
      "attributes": {
        "long_name": "Time"
      }
    },
    "latitude": {
      "type": "double",
      "shape": ["time"]
      "attributes": {
        "long_name": "Latitude",
        "units": "degrees_north"
      }
    }
  }
}

NCO-JSON can also serialize the "type" of the attributes so they can be represented in JSON and then decoded back to the correct type. This is useful for "type aware" attributes like _FillValue, missing_value, scale_factor add_offset, etc.

"metadata": {
  "variables": {
    "time": {
      "shape": ["time"],
      "attributes": {
         "missing_value": { "type": "float", "data": 75.0 },
         "short_attribute": { "type": "short", "data": 75 },
      }
    }
  }
}
derekcoffman commented 2 years ago

Perfect...I will look into that and make the changes. I knew there was a more standard way to do it, I just didn't know what that standard was which leads to me just making things up as I go along. Heh.

derekcoffman commented 2 years ago

I made the changes to the metadata. For now, I've left out the extra type information for the attributes. If you see a need for it, let me know and I can add

kwilcox commented 2 years ago

I started using this metadata format in the register-thing app and updated mock_sensor to output a data field (the data) and metadata field in NCO-JSON.