otaf.schema package
Module contents
Input schema of the assembly dictionary (pydantic models).
See docs/guide/input_format.md for the keys and their meaning. JSON schema:
otaf.schema.SystemData.model_json_schema().
- class otaf.schema.ExtentLocal(*, x_min, x_max)[source]
Bases:
BaseModelAxial extent of a cylinder along its local x axis, measured from
ORIGIN.- Parameters:
x_min (Annotated[float, PlainValidator(func=~otaf.schema._models._real, json_schema_input_type=~typing.Any), WithJsonSchema(json_schema={'type': 'number'}, mode=None)])
x_max (Annotated[float, PlainValidator(func=~otaf.schema._models._real, json_schema_input_type=~typing.Any), WithJsonSchema(json_schema={'type': 'number'}, mode=None)])
- x_min, x_max
Ends of the extent,
x_max >= x_min.- Type:
float
- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- x_max: Number
- x_min: Number
- class otaf.schema.Loops(*, COMPATIBILITY, **extra_data)[source]
Bases:
BaseModelCompatibility loops:
LOOPS.- Parameters:
COMPATIBILITY (Dict[str, str])
extra_data (Any)
- COMPATIBILITY
Loop name to loop string, elements
P<part><surface><point>joined by" -> ".- Type:
dict of str to str
- COMPATIBILITY: Dict[str, str]
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class otaf.schema.Part(root=PydanticUndefined)[source]
Bases:
RootModel[Dict[str, Surface]]The surfaces of one part:
PARTS[part], keyed by lowercase surface labels.- Parameters:
root (RootModelRootType)
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class otaf.schema.Surface(*, TYPE, FRAME=None, ORIGIN=None, POINTS=None, CONTOUR_GLOBAL=None, RADIUS=None, EXTENT_LOCAL=None, INTERACTIONS=None, CONSTRAINTS_D=None, CONSTRAINTS_G=None, BLOCK_TRANSLATIONS_G=None, BLOCK_ROTATIONS_G=None, SURFACE_DIRECTION=None, DIAMETER_DEVIATION=None, **extra_data)[source]
Bases:
BaseModelOne feature (plane or cylinder) of a part:
PARTS[part][surface].The keys are those of the dictionary (see
docs/guide/input_format.md). Keys that are not listed (e.g.META,CAD_ID) are kept and ignored. Which keys are required depends on the other keys and on the interactions; those checks need the part and surface labels and are made by SystemData.- Parameters:
TYPE (str)
FRAME (Annotated[ndarray, PlainValidator(func=~otaf.schema._models._frame, json_schema_input_type=~typing.Any), PlainSerializer(func=~otaf.schema._models._to_list, return_type=PydanticUndefined, when_used=json), WithJsonSchema(json_schema={'type': 'array', 'items': {'type': 'array', 'items': {'type': 'number'}, 'minItems': 3, 'maxItems': 3}, 'minItems': 3, 'maxItems': 3, 'description': 'Rotation matrix; columns are the local axes.'}, mode=None)] | None)
ORIGIN (Annotated[ndarray, PlainValidator(func=~otaf.schema._models._vector3, json_schema_input_type=~typing.Any), PlainSerializer(func=~otaf.schema._models._to_list, return_type=PydanticUndefined, when_used=json), WithJsonSchema(json_schema={'type': 'array', 'items': {'type': 'number'}, 'minItems': 3, 'maxItems': 3}, mode=None)] | None)
POINTS (Dict[str, Annotated[ndarray, PlainValidator(func=~otaf.schema._models._vector3, json_schema_input_type=~typing.Any), PlainSerializer(func=~otaf.schema._models._to_list, return_type=PydanticUndefined, when_used=json), WithJsonSchema(json_schema={'type': 'array', 'items': {'type': 'number'}, 'minItems': 3, 'maxItems': 3}, mode=None)]] | None)
CONTOUR_GLOBAL (Annotated[ndarray, PlainValidator(func=~otaf.schema._models._contour, json_schema_input_type=~typing.Any), PlainSerializer(func=~otaf.schema._models._to_list, return_type=PydanticUndefined, when_used=json), WithJsonSchema(json_schema={'type': 'array', 'items': {'type': 'array', 'items': {'type': 'number'}, 'minItems': 3, 'maxItems': 3}}, mode=None)] | None)
RADIUS (Annotated[float, PlainValidator(func=~otaf.schema._models._positive_real, json_schema_input_type=~typing.Any), WithJsonSchema(json_schema={'type': 'number', 'exclusiveMinimum': 0}, mode=None)] | None)
EXTENT_LOCAL (ExtentLocal | None)
INTERACTIONS (List[str] | None)
CONSTRAINTS_D (List[str] | None)
CONSTRAINTS_G (List[str] | None)
BLOCK_TRANSLATIONS_G (str | None)
BLOCK_ROTATIONS_G (str | None)
SURFACE_DIRECTION (str | None)
DIAMETER_DEVIATION (Annotated[bool, PlainValidator(func=~otaf.schema._models._strict_bool, json_schema_input_type=~typing.Any), WithJsonSchema(json_schema={'type': 'boolean'}, mode=None)] | None)
extra_data (Any)
- TYPE
One of
otaf.constants.SUPPORTED_SURFACE_TYPES.- Type:
str
- FRAME
Rotation matrix whose columns are the local axes (x: plane normal or cylinder axis).
- Type:
ndarray of shape (3, 3)
- ORIGIN
Origin of the surface frame. Taken from the origin point when
POINTSis given.- Type:
ndarray of shape (3,)
- POINTS
Points of the feature, labelled
<PREFIX><int>; must contain the origin (suffix all zeros).- Type:
dict of str to ndarray of shape (3,)
- CONTOUR_GLOBAL
Contour points in global coordinates, used when
POINTSis absent.- Type:
ndarray of shape (n, 3)
- RADIUS
Nominal radius of a cylinder, > 0.
- Type:
float
- EXTENT_LOCAL
Axial extent of a cylinder.
- Type:
- INTERACTIONS
Surfaces this one can touch, as
P<part><surface>.- Type:
list of str
- CONSTRAINTS_D
Deviations of the feature:
NONE,PERFECT,TRANSLATIONorROTATION(case-insensitive).- Type:
list of one str
- CONSTRAINTS_G
Relative motion at the contact:
FLOATING,SLIDINGorFIXED(case-insensitive). Must be the same on both surfaces of a contact.- Type:
list of one str
- BLOCK_TRANSLATIONS_G, BLOCK_ROTATIONS_G
Extra blocked gap axes, letters among
xyz.- Type:
str
- SURFACE_DIRECTION
centripetal(hole) orcentrifugal(pin); cylinders only.- Type:
str
- DIAMETER_DEVIATION
Diameter as a deviation variable; cylinders only.
- Type:
bool
- BLOCK_ROTATIONS_G: str | None
- BLOCK_TRANSLATIONS_G: str | None
- CONSTRAINTS_D: List[str] | None
- CONSTRAINTS_G: List[str] | None
- CONTOUR_GLOBAL: Contour | None
- DIAMETER_DEVIATION: StrictBool | None
- EXTENT_LOCAL: ExtentLocal | None
- FRAME: Frame | None
- INTERACTIONS: List[str] | None
- ORIGIN: Vector3 | None
- POINTS: Dict[str, Vector3] | None
- RADIUS: PositiveNumber | None
- SURFACE_DIRECTION: str | None
- TYPE: str
- contact_constraint()[source]
Return the
CONSTRAINTS_Gentry, upper case,FLOATINGby default.- Returns:
The entry used for the contact type.
- Return type:
str
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class otaf.schema.SystemData(*, PARTS, LOOPS, GLOBAL_CONSTRAINTS, **extra_data)[source]
Bases:
BaseModelThe whole assembly dictionary.
Validate a plain dictionary with
SystemData.model_validate(data)or validate_system_data (which raises the otaf.exceptions errors). A SystemData can be passed to otaf.AssemblyDataProcessor in place of the dictionary.- Parameters:
- PARTS
Parts keyed by the string of an integer.
- Type:
dict of str to Part
- GLOBAL_CONSTRAINTS
3D,2D_NX,2D_NYor2D_NZ.- Type:
str
Examples
>>> import numpy as np >>> data = { ... "PARTS": {"1": {"a": {"TYPE": "plane", "FRAME": np.eye(3), ... "POINTS": {"A0": (0, 0, 0), "A1": (0, 1, 0)}}}}, ... "LOOPS": {"COMPATIBILITY": {}}, ... "GLOBAL_CONSTRAINTS": "2D_NZ", ... } >>> SystemData.model_validate(data).PARTS["1"].root["a"].TYPE 'plane'
- GLOBAL_CONSTRAINTS: Literal['3D', '2D_NX', '2D_NY', '2D_NZ']
- contact_pairs()[source]
Return the contacts listed in
INTERACTIONS, each pair once.- Returns:
Sorted
((part1, surf1), (part2, surf2))pairs.- Return type:
list of tuple
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- surface(part_id, surf_id)[source]
Return a surface by its labels.
- Parameters:
part_id (str) – Labels of the part and of the surface.
surf_id (str) – Labels of the part and of the surface.
- Returns:
The surface.
- Return type:
- Raises:
otaf.exceptions.PartNotFoundError, otaf.exceptions.SurfaceNotFoundError – If the part or the surface does not exist.
- otaf.schema.validate_point_dict(point_dict)[source]
Check the labels and coordinates of a
POINTSdictionary.- Parameters:
point_dict (dict) –
{label: (x, y, z)}.- Raises:
otaf.exceptions.LabelPatternError – If a label does not match
otaf.constants.SURF_POINT_PATTERN.otaf.exceptions.LabelPrefixError – If the labels do not all have the same upper-case prefix.
otaf.exceptions.UniqueLabelSuffixError – If two labels have the same integer suffix (
A0andA00).otaf.exceptions.NonUniqueCoordinatesError – If two points have the same coordinates.
- Return type:
None
Examples
>>> validate_point_dict({"A0": (0, 0, 0), "A1": (1, 0, 0)}) >>> validate_point_dict({"A0": (0, 0, 0), "B1": (1, 0, 0)}) Traceback (most recent call last): ... otaf.exceptions._exceptions.LabelPrefixError: Some labels in the point dict do not comply to the expected pattern, all prefixes should be identical.
- otaf.schema.validate_system_data(system_data)[source]
Validate an assembly dictionary against the input schema.
- Parameters:
system_data (dict or SystemData) – The assembly dictionary (see
docs/guide/input_format.md).- Returns:
The validated model. The dictionary itself is not modified.
- Return type:
- Raises:
otaf.exceptions.MissingKeyError – If a required key is missing (
MissingSurfaceTypeKeyErrorforTYPE).otaf.exceptions.InvalidPartLabelError, otaf.exceptions.InvalidSurfaceLabelError – For malformed part or surface labels.
otaf.exceptions.UnsupportedSurfaceTypeError – If
TYPEis notplaneorcylinder.otaf.exceptions.InconsistentContactConstraintsError – If the two surfaces of a contact have different
CONSTRAINTS_G.NotImplementedError – For a contact between a plane and a cylinder.
otaf.exceptions.SystemDataValidationError – For any other problem; lists all of them.
Other otaf.exceptions errors (point labels, interaction format, missing –
origin point, unknown part or surface, ...) are raised as they are, with the –
location of the problem in front of their message. When several problems –
are found, the first one is raised, chained to a –