tlc.core.schema
#
Defines Schema, which is a class for describing atomic or (possibly nested) composite structures
Module Contents#
Classes#
Class |
Description |
---|---|
Defines a single item in a value map. |
|
Describes a scalar value in a schema |
|
Describes a scalar boolean value |
|
Describes a scalar numeric value |
|
A numeric value with type ‘float32’ |
|
A numeric value with type ‘float64’ |
|
A numeric value with type ‘uint8’ |
|
A numeric value with type ‘int8’ |
|
A numeric value with type ‘uint16’ |
|
A numeric value with type ‘int16’ |
|
A numeric value with type ‘uint32’ |
|
A numeric value with type ‘int32’ |
|
A numeric value with type ‘uint64’ |
|
A numeric value with type ‘int64’ |
|
A timestamp value counting the number of ‘unit’s since epoch |
|
Describes a scalar numeric value which is a dimension size within a property |
|
Describes a string value |
|
Describes a generic URL string value |
|
Describes a Image URL string value |
|
Describes a Segmentation URL string value |
|
Describes a Segmentation Mask URL string value |
|
Describes a date-time string value |
|
A string containing an object type |
|
Describes a generic URL string value |
|
Describes a URL string value pointing to a tensor |
|
Describes a value which consists of an anonymous, free-form dictionary |
|
A schema is a recursive structure which defines the layout of an object. It defines what elements the object consists of, which must be either |
|
A schema that encodes a None value |
API#
- class tlc.core.schema.MapElement(internal_name: str = '', display_name: str = '', description: str = '', display_color: str = '', url: str = '')#
Bases:
dict
Defines a single item in a value map.
Initialize self. See help(type(self)) for accurate signature.
- to_minimal_dict(include_all: bool) dict[str, Any] #
Add a minimal representation of this object to a dictionary for subsequent serialization to JSON
- static from_any(any_map_element: Any) tlc.core.schema.MapElement #
Creates a MapElement object and populates it from an anonymous, possibly sparse object
- class tlc.core.schema.ScalarValue(value_type: str = _DEFAULT_SCALAR_VALUE_TYPE, default_value: Any = None)#
Describes a scalar value in a schema
- to_minimal_dict(include_all: bool) dict[str, Any] #
Add a minimal representation of this object to a dictionary for subsequent serialization to JSON
- static from_any(any_value: Any) tlc.core.schema.ScalarValue #
Create and populate a ScalarValue (or one of the derived classes) given an anonymous, potentially sparse object
- static from_value(value: Any) tlc.core.schema.ScalarValue #
Create a scalar value from a Python value.
- Parameters:
value – The value to create a ScalarValue from
- Returns:
A ScalarValue (or one it the derived classes) representing the value
- class tlc.core.schema.BoolValue(default_value: bool | None = None)#
Bases:
tlc.core.schema.ScalarValue
Describes a scalar boolean value
- static from_any(any_value: Any) tlc.core.schema.BoolValue #
Create and populate a BoolValue object given an anonymous, potentially sparse object
- class tlc.core.schema.NumericValue(value_type: str = _DEFAULT_SCALAR_VALUE_TYPE, value_min: float | int | None = None, value_max: float | int | None = None, enforce_min: bool = False, enforce_max: bool = False, value_step: float = 0, number_role: str = '', unit: str = '', value_map: dict[float, tlc.core.schema.MapElement] | None = None, default_value: int | float | None = None)#
Bases:
tlc.core.schema.ScalarValue
Describes a scalar numeric value
- to_minimal_dict(include_all: bool) dict[str, Any] #
Add a minimal representation of this object to a dictionary for subsequent serialization to JSON
- static from_any(any_value: Any) tlc.core.schema.NumericValue #
Create and populate a NumericValue object given an anonymous, potentially sparse object
- static from_value(value: Any) tlc.core.schema.NumericValue #
Create a numeric value from a Python value.
- Parameters:
value – The value to create a NumericValue from
- Returns:
A NumericValue (or one it the derived classes) representing the value
- class tlc.core.schema.Float32Value(value_min: float | None = None, value_max: float | None = None, enforce_min: bool = False, enforce_max: bool = False, value_step: float = 0, number_role: str = '', unit: str = '', value_map: dict[float, tlc.core.schema.MapElement] | None = None, default_value: float | None = None)#
Bases:
tlc.core.schema.NumericValue
A numeric value with type ‘float32’
- class tlc.core.schema.Float64Value(value_min: float | None = None, value_max: float | None = None, enforce_min: bool = False, enforce_max: bool = False, value_step: float = 0, number_role: str = '', unit: str = '', value_map: dict[float, tlc.core.schema.MapElement] | None = None, default_value: float | None = None)#
Bases:
tlc.core.schema.NumericValue
A numeric value with type ‘float64’
- class tlc.core.schema.Uint8Value(value_min: float | None = None, value_max: float | None = None, enforce_min: bool = False, enforce_max: bool = False, value_step: float = 0, number_role: str = '', unit: str = '', value_map: dict[float, tlc.core.schema.MapElement] | None = None, default_value: int | None = None)#
Bases:
tlc.core.schema.NumericValue
A numeric value with type ‘uint8’
- class tlc.core.schema.Int8Value(value_min: float | None = None, value_max: float | None = None, enforce_min: bool = False, enforce_max: bool = False, value_step: float = 0, number_role: str = '', unit: str = '', value_map: dict[float, tlc.core.schema.MapElement] | None = None, default_value: int | None = None)#
Bases:
tlc.core.schema.NumericValue
A numeric value with type ‘int8’
- class tlc.core.schema.Uint16Value(value_min: float | None = None, value_max: float | None = None, enforce_min: bool = False, enforce_max: bool = False, value_step: float = 0, number_role: str = '', unit: str = '', value_map: dict[float, tlc.core.schema.MapElement] | None = None, default_value: int | None = None)#
Bases:
tlc.core.schema.NumericValue
A numeric value with type ‘uint16’
- class tlc.core.schema.Int16Value(value_min: float | None = None, value_max: float | None = None, enforce_min: bool = False, enforce_max: bool = False, value_step: float = 0, number_role: str = '', unit: str = '', value_map: dict[float, tlc.core.schema.MapElement] | None = None, default_value: int | None = None)#
Bases:
tlc.core.schema.NumericValue
A numeric value with type ‘int16’
- class tlc.core.schema.Uint32Value(value_min: float | None = None, value_max: float | None = None, enforce_min: bool = False, enforce_max: bool = False, value_step: float = 0, number_role: str = '', unit: str = '', value_map: dict[float, tlc.core.schema.MapElement] | None = None, default_value: int | None = None)#
Bases:
tlc.core.schema.NumericValue
A numeric value with type ‘uint32’
- class tlc.core.schema.Int32Value(value_min: int | None = None, value_max: int | None = None, enforce_min: bool = False, enforce_max: bool = False, value_step: float = 0, number_role: str = '', unit: str = '', value_map: dict[float, tlc.core.schema.MapElement] | None = None, default_value: int | None = None)#
Bases:
tlc.core.schema.NumericValue
A numeric value with type ‘int32’
- class tlc.core.schema.Uint64Value(value_min: float | None = None, value_max: float | None = None, enforce_min: bool = False, enforce_max: bool = False, value_step: float = 0, number_role: str = '', unit: str = '', value_map: dict[float, tlc.core.schema.MapElement] | None = None, default_value: int | None = None)#
Bases:
tlc.core.schema.NumericValue
A numeric value with type ‘uint64’
- class tlc.core.schema.Int64Value(value_min: float | None = None, value_max: float | None = None, enforce_min: bool = False, enforce_max: bool = False, value_step: float = 0, number_role: str = '', unit: str = '', value_map: dict[float, tlc.core.schema.MapElement] | None = None, default_value: int | None = None)#
Bases:
tlc.core.schema.NumericValue
A numeric value with type ‘int64’
- class tlc.core.schema.TimestampValue(value_min: float | None = None, value_max: float | None = None, enforce_min: bool = False, enforce_max: bool = False, value_step: float = 0, number_role: str = NUMBER_ROLE_TIMESTAMP, unit: str = 'ms', value_map: dict[float, tlc.core.schema.MapElement] | None = None, default_value: int | None = None)#
Bases:
tlc.core.schema.Int64Value
A timestamp value counting the number of ‘unit’s since epoch
Stores the value as an ‘int64’
Defaults to milliseconds resolution
- class tlc.core.schema.DimensionNumericValue(value_min: int = 0, value_max: int | None = None, enforce_min: bool = True, enforce_max: bool = False, display_name: str = '', description: str = '', number_role: str = '', unit: str = '', value_map: dict[float, tlc.core.schema.MapElement] | None = None, sample_type: str = '', default_value: int | None = None)#
Bases:
tlc.core.schema.Int32Value
Describes a scalar numeric value which is a dimension size within a property
- classmethod fixed_size(size: int) tlc.core.schema.DimensionNumericValue #
Create a fixed size dimension value
- to_minimal_dict(include_all: bool) dict[str, Any] #
Add a minimal representation of this object to a dictionary for subsequent serialization to JSON
- static dimension_numeric_value_from_any(this_property: Any) tlc.core.schema.DimensionNumericValue | None #
Creates a DimensionNumericValue object and populates it from an anonymous, possibly sparse object
- class tlc.core.schema.StringValue(string_role: str = '', default_value: str | None = None)#
Bases:
tlc.core.schema.ScalarValue
Describes a string value
- to_minimal_dict(include_all: bool) dict[str, Any] #
Add a minimal representation of this object to a dictionary for subsequent serialization to JSON
- static from_any(any_value: Any) tlc.core.schema.StringValue #
Create and populate a StringValue object given an anonymous, potentially sparse object
- class tlc.core.schema.UrlStringValue(url_string_icon: str = '', default_value: str | None = None)#
Bases:
tlc.core.schema.StringValue
Describes a generic URL string value
- class tlc.core.schema.ImageUrlStringValue(default_value: str | None = None)#
Bases:
tlc.core.schema.UrlStringValue
Describes a Image URL string value
- class tlc.core.schema.SegmentationUrlStringValue(default_value: str | None = None, map: dict[float, tlc.core.schema.MapElement] | None = None)#
Bases:
tlc.core.schema.UrlStringValue
Describes a Segmentation URL string value
- static from_any(any_value: Any) tlc.core.schema.SegmentationUrlStringValue #
Create and populate a SegmentationUrlStringValue object given an anonymous, potentially sparse object
- class tlc.core.schema.SegmentationMaskUrlStringValue(default_value: str | None = None, map: dict[float, tlc.core.schema.MapElement] | None = None)#
Bases:
tlc.core.schema.SegmentationUrlStringValue
Describes a Segmentation Mask URL string value
- static from_any(any_value: Any) tlc.core.schema.SegmentationMaskUrlStringValue #
Create and populate a SegmentationMaskUrlStringValue object given an anonymous, potentially sparse object
- class tlc.core.schema.DatetimeStringValue(default_value: str | None = None)#
Bases:
tlc.core.schema.StringValue
Describes a date-time string value
- class tlc.core.schema.ObjectTypeStringValue(default_value: str | None = None)#
Bases:
tlc.core.schema.StringValue
A string containing an object type
- class tlc.core.schema.FolderUrlStringValue(default_value: str | None = None)#
Bases:
tlc.core.schema.StringValue
Describes a generic URL string value
- class tlc.core.schema.TensorUrlStringValue(default_value: str | None = None)#
Bases:
tlc.core.schema.UrlStringValue
Describes a URL string value pointing to a tensor
- class tlc.core.schema.DictValue(default_value: dict = {})#
Bases:
tlc.core.schema.ScalarValue
Describes a value which consists of an anonymous, free-form dictionary
- static from_any(_: Any) tlc.core.schema.DictValue #
- class tlc.core.schema.Schema(display_name: str = '', description: str = '', writable: bool = True, display_importance: float = 0, value: tlc.core.schema.ScalarValue | None = None, values: dict[str, tlc.core.schema.Schema] | None = None, composite_role: str = '', display_color: str = '', swap_group: str = '', computable: bool = True, sample_type: str = '', transient: bool = False, default_visible: bool = True, size0: tlc.core.schema.DimensionNumericValue | None = None, size1: tlc.core.schema.DimensionNumericValue | None = None, size2: tlc.core.schema.DimensionNumericValue | None = None, size3: tlc.core.schema.DimensionNumericValue | None = None, size4: tlc.core.schema.DimensionNumericValue | None = None, size5: tlc.core.schema.DimensionNumericValue | None = None)#
A schema is a recursive structure which defines the layout of an object. It defines what elements the object consists of, which must be either
Atomic type (with optional metadata, e.g. value range, unit, etc.) OR
Composite contents (a list of schemas describing the sub-object)
In addition, it defines HOW MANY of these scalar or composite elements exist, in the form of up to six-dimensions which can each be described separately and be of fixed or variable lengths. The default size of dimensions is 1, describing a scalar value.
Schemas are used for
Defining the layout of Objects (as reported by e.g. “MyObject.schema”)
In the case of Tables: defining the common layout of all table rows (as reported by e.g “MyTableObject.schema.values[“rows”])
In the case where a schema defines a “top-level” object, it will always have a ‘values’ attribute (since it is always a composite object, and does not comprise only a single atomic value).
- last_dimension() tlc.core.schema.DimensionNumericValue | None #
Return the last (outermost) dimension of the Schema
- to_minimal_dict(include_all: bool) dict[str, Any] #
Add a minimal representation of this object to a dictionary for subsequent serialization to JSON
- add_sub_schema(name: str, schema: tlc.core.schema.Schema) None #
Adds a Schema as a sub-property within this Schema (i.e. into the ‘values’ collection)
- add_sub_value(name: str, value: tlc.core.schema.ScalarValue, writable: bool = True, computable: bool = True) None #
Adds a scalar value as a sub-property within this Schema (i.e. into the ‘values’ collection)
- to_json() str #
Writes the contents of this schema to a JSON string. Note that
Defaults values are omitted for brevity
Schemas might be recursive
- static from_any(any_object: Any) tlc.core.schema.Schema #
Returns a Schema object which has been populated from a serialized (possibly sparse) object
- static from_json(json_string: str) tlc.core.schema.Schema #
Returns a Schema object which has been populated from a JSON string
- consider_override_from(override_schema: tlc.core.schema.Schema | Mapping[str, object] | None) tlc.core.schema.Schema #
Selectively overwrites columns within this Schema according to the columns defined in another Schema.
- does_object_match(_object: Any) bool #
Checks whether a schema matches an example object.
This requires exact 1:1 mapping between attributes in the object and the schema (including recursively). This means no attributes can be missing, nor can there be any additional attributes only present in the object.
- is_fixed_size() bool #
Return whether the schema has fixed size.
This requires all dimensions to be fixed size.
- is_scalar() bool #
Return whether the schema is a scalar value
Sizes are required to be set in increasing dimensions without gaps and no size is treated like a scalar.
- is_atomic() bool #
Return whether the schema is atomic, i.e. has a single value.
The opposite of
is_composite
.- Returns:
Whether the schema is atomic
- is_composite() bool #
Return whether the schema is composite, i.e. has multiple values.
The opposite of
is_atomic
.- Returns:
Whether the schema is composite
- property sample_type_object: tlc.client.sample_type.SampleType#
- classmethod from_structure(structure: tlc.client.sample_type._SampleTypeStructure) tlc.core.schema.Schema #
Creates a schema from a structure.
- Parameters:
structure – The structure to create a schema from
- Returns:
The schema
- classmethod from_sample(sample: Any) tlc.core.schema.Schema #
Creates a schema describing the provided sample.
- Parameters:
sample – The sample to create a schema from
- Returns:
The schema
- push_dim(dim: tlc.core.schema.DimensionNumericValue | None = None) tlc.core.schema.DimensionNumericValue | None #
Inserts dim as size0 and shifts all other dimensions right. (size1 becomes size0, size2 becomes size1).
- Parameters:
dim – The dimension to insert as size0
- Returns:
The old size5
- pop_dim() tlc.core.schema.DimensionNumericValue | None #
Sets size5 to None and shifts all other dimensions left. (size5 becomes size4, size4 becomes size3, etc.).
- Returns:
The old size0
- class tlc.core.schema.NoneSchema#
Bases:
tlc.core.schema.Schema
A schema that encodes a None value
It is not a valid Schema as it has neither value nor values. It is used to encode override schemas that remove sub schemas.
- Example:
override_schema = { "values": { "column_to_remove": None }} # or equivalently override_schema = { "values": { "column_to_remove": NoneSchema()}}