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 |
|
Describes a binary value utf-8 encoded as a string |
|
Describes a binary value encoded as a run-length encoding |
|
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 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,
Add a minimal representation of this object to a dictionary for subsequent serialization to JSON
- static from_any(
- any_map_element: Any,
Creates a MapElement object and populates it from an anonymous, possibly sparse object
- class ScalarValue( )¶
Describes a scalar value in a schema
- to_minimal_dict(
- include_all: bool,
Add a minimal representation of this object to a dictionary for subsequent serialization to JSON
- static from_any(
- any_value: Any,
Create and populate a ScalarValue (or one of the derived classes) given an anonymous, potentially sparse object
- static from_value(
- value: Any,
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 BoolValue( )¶
Bases:
tlc.core.schema.ScalarValue
Describes a scalar boolean value
- class 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, 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,
Add a minimal representation of this object to a dictionary for subsequent serialization to JSON
- static from_any(
- any_value: Any,
Create and populate a NumericValue object given an anonymous, potentially sparse object
- static from_value(
- value: Any,
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 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, MapElement] | None = None,
- default_value: float | None = None,
Bases:
tlc.core.schema.NumericValue
A numeric value with type ‘float32’
- class 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, MapElement] | None = None,
- default_value: float | None = None,
Bases:
tlc.core.schema.NumericValue
A numeric value with type ‘float64’
- class 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, MapElement] | None = None,
- default_value: int | None = None,
Bases:
tlc.core.schema.NumericValue
A numeric value with type ‘uint8’
- class 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, MapElement] | None = None,
- default_value: int | None = None,
Bases:
tlc.core.schema.NumericValue
A numeric value with type ‘int8’
- class 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, MapElement] | None = None,
- default_value: int | None = None,
Bases:
tlc.core.schema.NumericValue
A numeric value with type ‘uint16’
- class 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, MapElement] | None = None,
- default_value: int | None = None,
Bases:
tlc.core.schema.NumericValue
A numeric value with type ‘int16’
- class 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, MapElement] | None = None,
- default_value: int | None = None,
Bases:
tlc.core.schema.NumericValue
A numeric value with type ‘uint32’
- class 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, MapElement] | None = None,
- default_value: int | None = None,
Bases:
tlc.core.schema.NumericValue
A numeric value with type ‘int32’
- class 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, MapElement] | None = None,
- default_value: int | None = None,
Bases:
tlc.core.schema.NumericValue
A numeric value with type ‘uint64’
- class 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, MapElement] | None = None,
- default_value: int | None = None,
Bases:
tlc.core.schema.NumericValue
A numeric value with type ‘int64’
- class 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, 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 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, 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,
Create a fixed size dimension value
- to_minimal_dict(
- include_all: bool,
Add a minimal representation of this object to a dictionary for subsequent serialization to JSON
- static dimension_numeric_value_from_any(
- this_property: Any,
Creates a DimensionNumericValue object and populates it from an anonymous, possibly sparse object
- class StringValue( )¶
Bases:
tlc.core.schema.ScalarValue
Describes a string value
- to_minimal_dict(
- include_all: bool,
Add a minimal representation of this object to a dictionary for subsequent serialization to JSON
- static from_any(
- any_value: Any,
Create and populate a StringValue object given an anonymous, potentially sparse object
- class UrlStringValue( )¶
Bases:
tlc.core.schema.StringValue
Describes a generic URL string value
- class ImageUrlStringValue( )¶
Bases:
tlc.core.schema.UrlStringValue
Describes a Image URL string value
- class SegmentationUrlStringValue( )¶
Bases:
tlc.core.schema.UrlStringValue
Describes a Segmentation URL string value
- static from_any(
- any_value: Any,
Create and populate a SegmentationUrlStringValue object given an anonymous, potentially sparse object
- class SegmentationMaskUrlStringValue( )¶
Bases:
tlc.core.schema.SegmentationUrlStringValue
Describes a Segmentation Mask URL string value
- static from_any(
- any_value: Any,
Create and populate a SegmentationMaskUrlStringValue object given an anonymous, potentially sparse object
- class DatetimeStringValue( )¶
Bases:
tlc.core.schema.StringValue
Describes a date-time string value
- class ObjectTypeStringValue( )¶
Bases:
tlc.core.schema.StringValue
A string containing an object type
- class FolderUrlStringValue( )¶
Bases:
tlc.core.schema.StringValue
Describes a generic URL string value
- class TensorUrlStringValue( )¶
Bases:
tlc.core.schema.UrlStringValue
Describes a URL string value pointing to a tensor
- class DictValue(
- default_value: dict = {},
Bases:
tlc.core.schema.ScalarValue
Describes a value which consists of an anonymous, free-form dictionary
- class BytesStringValue( )¶
Bases:
tlc.core.schema.StringValue
Describes a binary value utf-8 encoded as a string
- class InstanceSegmentationRLEBytesStringValue( )¶
Bases:
tlc.core.schema.BytesStringValue
Describes a binary value encoded as a run-length encoding
- static from_any(
- any_value: Any,
- class Schema(
- display_name: str = '',
- description: str = '',
- writable: bool = True,
- display_importance: float = 0,
- value: ScalarValue | None = None,
- values: dict[str, Schema] | None = None,
- composite_role: str = '',
- display_color: str = '',
- swap_group: str = '',
- computable: bool = True,
- sample_type: str | None = None,
- transient: bool = False,
- default_visible: bool = True,
- size0: DimensionNumericValue | None = None,
- size1: DimensionNumericValue | None = None,
- size2: DimensionNumericValue | None = None,
- size3: DimensionNumericValue | None = None,
- size4: DimensionNumericValue | None = None,
- size5: 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() DimensionNumericValue | None ¶
Return the last (outermost) dimension of the Schema
- to_minimal_dict(
- include_all: bool,
Add a minimal representation of this object to a dictionary for subsequent serialization to JSON
- add_sub_schema( ) None ¶
Adds a Schema as a sub-property within this Schema (i.e. into the ‘values’ collection)
- add_sub_value(
- name: str,
- value: ScalarValue,
- writable: bool = True,
- computable: bool = True,
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,
Returns a Schema object which has been populated from a serialized (possibly sparse) object
- static from_json(
- json_string: str,
Returns a Schema object which has been populated from a JSON string
- consider_override_from( ) Schema ¶
Selectively overwrites columns within this Schema according to the columns defined in another Schema.
- does_object_match(
- _object: Any,
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: SampleType¶
- classmethod from_structure(
- structure: tlc.client.sample_type._SampleTypeStructure,
Creates a schema from a structure.
- Parameters:
structure – The structure to create a schema from
- Returns:
The schema
- classmethod from_sample(
- sample: Any,
Creates a schema describing the provided sample.
- Parameters:
sample – The sample to create a schema from
- Returns:
The schema
- push_dim(
- dim: DimensionNumericValue | None = 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() DimensionNumericValue | None ¶
Sets size5 to None and shifts all other dimensions left. (size5 becomes size4, size4 becomes size3, etc.).
- Returns:
The old size0
- class 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()}}