ts_ids_core.schema.datacube module

Model DataCube[source]

Bases: IdsElement

TetraScience designed model for multi-dimensional data.

Show JSON schema
{
   "description": "TetraScience designed model for multi-dimensional data.",
   "type": "object",
   "properties": {
      "name": {
         "type": [
            "string",
            "null"
         ]
      },
      "measures": {
         "items": {
            "$ref": "#/definitions/Measure"
         },
         "maxItems": 1,
         "minItems": 1,
         "type": "array"
      },
      "dimensions": {
         "items": {
            "$ref": "#/definitions/Dimension"
         },
         "maxItems": 2,
         "minItems": 2,
         "type": "array"
      }
   },
   "additionalProperties": false,
   "required": [
      "name",
      "measures",
      "dimensions"
   ],
   "definitions": {
      "Dimension": {
         "additionalProperties": false,
         "description": "A dimension of a DataCube",
         "properties": {
            "name": {
               "type": [
                  "string",
                  "null"
               ]
            },
            "unit": {
               "type": [
                  "string",
                  "null"
               ]
            },
            "scale": {
               "items": {
                  "type": [
                     "number",
                     "null"
                  ]
               },
               "type": "array"
            }
         },
         "required": [
            "name",
            "unit",
            "scale"
         ],
         "type": "object"
      },
      "Measure": {
         "additionalProperties": false,
         "description": "A measure of a DataCube",
         "properties": {
            "name": {
               "type": [
                  "string",
                  "null"
               ]
            },
            "unit": {
               "type": [
                  "string",
                  "null"
               ]
            },
            "value": {
               "items": {
                  "items": {
                     "type": [
                        "number",
                        "null"
                     ]
                  },
                  "type": "array"
               },
               "type": "array"
            }
         },
         "required": [
            "name",
            "unit",
            "value"
         ],
         "type": "object"
      }
   }
}

Validators:
field dimensions: Required[Annotated[List[Dimension], fixed_length(2)]]
Constraints:
  • min_length = 2

  • max_length = 2

field measures: Required[Annotated[List[Measure], fixed_length(1)]]
Constraints:
  • min_length = 1

  • max_length = 1

field name: Required[Nullable[str]]
validator consistent_number_of_dimensions  »  all fields[source]

Assert that the dimensionality of all DataCube.measures[*].value is consistent with DataCube.dimensions[*].scale.

For example, consider the following DataCube class that describes one-dimensional data:

from typing import List

from pydantic import conlist

from ts_ids_core.annotations import Required
from ts_ids_core.schema import DataCube, Dimension, Measure

class ExampleMeasure(Measure):
    # note that `value` is one-dimensional to be consistent with the
    # `fixed_length` in the definition of `ExampleDataCube.dimensions`.
    value: List[float]

class ExampleDataCube(DataCube):
    measures: Required[Annotated[List[Measure], fixed_length(1)]]
    dimensions: Required[Annotated[List[Dimension], fixed_length(1)]]

The following would be a valid ExampleDataCube instance:

example = DataCube(
    dimensions=[
        Dimension(
            name="time",
            unit="second",
            scale=[0, 1, 2, 3, 4, 5],
        ),
    ],
    measures=[
        ExampleMeasure(
            name="electrical_current",
            unit="MilliAmp",
            value=[0, 10, 20, 30, 40, 50],
        ),
    ]
)

It’s valid because len(example.measures[0].value) == len(example.dimensions[0].scale).

Validates:
  • all fields

Model DataCubeMetadata[source]

Bases: IdsElement

DataCube metadata, with a file ID referencing a file in the data lake which contains DataCube dimension and measure values.

Show JSON schema
{
   "description": "DataCube metadata, with a file ID referencing a file in the data lake which contains\nDataCube dimension and measure values.",
   "type": "object",
   "properties": {
      "index": {
         "description": "Index which relates dimension and measure values in the external data file with the metadata stored in this model.",
         "type": "integer"
      },
      "name": {
         "type": [
            "string",
            "null"
         ]
      },
      "measures": {
         "items": {
            "$ref": "#/definitions/MeasureMetadata"
         },
         "maxItems": 1,
         "minItems": 1,
         "type": "array"
      },
      "dimensions": {
         "items": {
            "$ref": "#/definitions/DimensionMetadata"
         },
         "maxItems": 2,
         "minItems": 2,
         "type": "array"
      },
      "file_id": {
         "description": "The `fileId` of the file in the data lake containing DataCube data",
         "type": "string"
      }
   },
   "additionalProperties": false,
   "required": [
      "index",
      "name",
      "measures",
      "dimensions",
      "file_id"
   ],
   "definitions": {
      "DimensionMetadata": {
         "additionalProperties": false,
         "description": "Metadata for a dimension of a DataCube",
         "properties": {
            "name": {
               "type": [
                  "string",
                  "null"
               ]
            },
            "unit": {
               "type": [
                  "string",
                  "null"
               ]
            }
         },
         "required": [
            "name",
            "unit"
         ],
         "type": "object"
      },
      "MeasureMetadata": {
         "additionalProperties": false,
         "description": "Metadata for a measure of a DataCube",
         "properties": {
            "name": {
               "type": [
                  "string",
                  "null"
               ]
            },
            "unit": {
               "type": [
                  "string",
                  "null"
               ]
            }
         },
         "required": [
            "name",
            "unit"
         ],
         "type": "object"
      }
   }
}

Validators:
  • all_abstract_fields_implemented » all fields

field dimensions: Required[Annotated[List[DimensionMetadata], fixed_length(2)]]
Constraints:
  • min_length = 2

  • max_length = 2

field file_id: Required[str]

The fileId of the file in the data lake containing DataCube data

field index: Required[int]

Index which relates dimension and measure values in the external data file with the metadata stored in this model.

field measures: Required[Annotated[List[MeasureMetadata], fixed_length(1)]]
Constraints:
  • min_length = 1

  • max_length = 1

field name: Required[Nullable[str]]