Skip to content

hertzforge.core.scan_fit

scan_fit

Accelerometers fitted to points measured on them.

A coordinate measuring arm is touched to the faces of each accelerometer and the points of each surface are exported as one feature, named <sensor>_<label>. The label says which surface it is:

  • 1, 2, 3 and -1, -2, -3: a flat face whose outward normal is the accelerometer's X+, Y+, Z+ or X-, Y-, Z- axis.
  • c: the round side of a uni-axial accelerometer. Its sensor then has one flat face as well, whose label names the axis that points out of it. p, the top, is read as 3: Z+ points out of the face measured. b, the bottom, is read as -3: the face measured is the one it is mounted by, and Z+ points away from it, through the body.

A tri-axial accelerometer is located by the planes fitted to two or three of its faces, a uni-axial one by the cylinder fitted to its side and the plane fitted to its top. Each fit says how good it is, and what is wrong with it when something is.

Lengths are in the unit of the points. The limits on lengths (PLANE_RMS, CYLINDER_RMS) are in meters and are applied only when the caller says how many meters one unit is.

Classes:

Name Description
Flag

Something wrong with a fit: level is 'warn' or 'error'. A sensor

PlaneFit

A plane through points: a point on it (their centroid), its unit

CylinderFit

A cylinder through points on its side: a point on its axis, the

SensorFit

One accelerometer as its measured surfaces locate it.

Functions:

Name Description
fit_plane

The least-squares plane through points.

fit_cylinder

The least-squares cylinder through points on its side.

fit_triax

A tri-axial accelerometer from the points on its faces.

fit_uniaxial

A uni-axial accelerometer from the points on its round side and on

measured_features

The features a geometry of measured points holds

residuals

How far each of a surface's points lies from the surface fitted

parse_feature

A feature's sensor and label from its name, <sensor>_<label>.

written_label

A feature's sensor and its label as written, p and b kept

surface_of

What a feature's surface is called, one of SURFACES' values.

label_of

The label a feature's name is written with for a surface.

fit_sensors

Every accelerometer the features locate.

Classes

Flag dataclass

Flag(level: str, text: str)

Something wrong with a fit: level is 'warn' or 'error'. A sensor with an error cannot be placed.

PlaneFit dataclass

PlaneFit(point: ndarray, normal: ndarray, rms: float, worst: float, count: int)

A plane through points: a point on it (their centroid), its unit normal (either way round), the residuals' RMS and largest size, and how many points.

CylinderFit dataclass

CylinderFit(point: ndarray, axis: ndarray, radius: float, rms: float, worst: float, arc: float, span: tuple[float, float], count: int)

A cylinder through points on its side: a point on its axis, the axis (unit), the radius, the residuals' RMS and largest size, the arc of the circumference the points cover in degrees, where along the axis from point they start and stop, and how many points.

SensorFit dataclass

SensorFit(sensor: str, kind: str, frame: ndarray | None = None, anchor: ndarray | None = None, axes: tuple[int, ...] = (), extent: float | None = None, length: float | None = None, planes: dict[str, PlaneFit] = dict(), cylinder: CylinderFit | None = None, moved: float = 0.0, flags: list[Flag] = list())

One accelerometer as its measured surfaces locate it.

Attributes: sensor: The sensor's name, the part of its features' names before the last underscore. kind: 'triax' or 'uniaxial'. frame: (3, 3), rows the accelerometer's X+, Y+, Z+ in the points' coordinates, right-handed and orthonormal; None when the surfaces do not give one. anchor: The point the body is placed from: the corner where three faces meet, the middle of the edge two faces share, or where a uni-axial accelerometer's axis meets its top face. axes: The body axes of the measured faces, signed: 1 for a face whose outward normal is X+, -2 for Y-. The body lies behind each of them from anchor. One entry for a uni-axial accelerometer, its top face. extent: A tri-axial accelerometer's side is at least this: the furthest a measured point lies behind another face. A uni-axial accelerometer's diameter, as measured. length: A uni-axial accelerometer's length, as measured: twice how far its top lies along the axis from the middle of the points on its side, which is taken as the middle of the body. None when the top is not past that middle. planes: The plane fitted to each flat face, by its label. cylinder: The cylinder fitted to a uni-axial accelerometer's side. moved: The largest angle, in degrees, a measured axis was turned to make the frame square. flags: What is wrong with the fit.

Methods:

Name Description
center

The center of the body, which is where its node goes.

Attributes:

Name Type Description
placed bool

Whether the fit locates the accelerometer: it has a frame and

direction str | None

The channel of a uni-axial accelerometer, 'X+', 'Y+' or 'Z+':

Attributes
placed property
placed: bool

Whether the fit locates the accelerometer: it has a frame and no error.

direction property
direction: str | None

The channel of a uni-axial accelerometer, 'X+', 'Y+' or 'Z+': the axis its top face was labelled with, always positive. None for a tri-axial one, which has all three.

Methods:
center
center(size: float | Sequence[float]) -> ndarray

The center of the body, which is where its node goes.

Parameters:

Name Type Description Default
size float or sequence of 3 floats

The body's size along its X, Y and Z, in the points' unit; one number for a cube. For a uni-axial accelerometer only the size along its sensing axis, its height, is used.

required

Returns:

Type Description
ndarray

anchor moved half the size back from each measured face.

Raises:

Type Description
ValueError

When the fit does not locate the accelerometer.

Functions:

fit_plane

fit_plane(points: ndarray) -> PlaneFit

The least-squares plane through points.

Parameters:

Name Type Description Default
points (array_like, [N, 3])

Three points or more.

required

Returns:

Type Description
PlaneFit

The plane through their centroid whose normal is the direction the points vary least in.

Raises:

Type Description
ValueError

With fewer than three points.

fit_cylinder

fit_cylinder(points: ndarray, axis_hint: ndarray | None = None) -> CylinderFit

The least-squares cylinder through points on its side.

The fit is nonlinear, so it is started several ways and the best is kept: along each direction the points spread in and along axis_hint, each with the axis through the points' middle and to either side of it, since points on one side of a cylinder have their middle a radius off its axis.

Parameters:

Name Type Description Default
points (array_like, [N, 3])

Five points or more, not all at one height on a line.

required
axis_hint array_like

A direction the axis is expected near, such as the normal of the accelerometer's top face.

None

Returns:

Type Description
CylinderFit

The axis, radius and residuals; point is on the axis beside the points' centroid.

Raises:

Type Description
ValueError

With fewer than five points.

fit_triax

fit_triax(sensor: str, faces: Mapping[str, ndarray], meters: float | None = None) -> SensorFit

A tri-axial accelerometer from the points on its faces.

The outward normal of a face is the one pointing away from the points of the other faces, and a face labelled k gives the body axis |k|, reversed for a negative label. The measured axes are turned to the nearest square, right-handed frame. With two faces the third axis is the one that makes them right-handed.

Parameters:

Name Type Description Default
sensor str

The sensor's name.

required
faces mapping of str to array_like [N, 3]

The points of each face by its label, one of FACE_LABELS.

required
meters float

How many meters one unit of the points is. Without it the roughness of a face is not judged.

None

Returns:

Type Description
SensorFit

With a frame when two or three faces of different axes were measured; its flags say what is wrong otherwise.

fit_uniaxial

fit_uniaxial(sensor: str, side: ndarray, top: ndarray, label: str = '3', meters: float | None = None) -> SensorFit

A uni-axial accelerometer from the points on its round side and on its flat top.

The direction comes from the top's plane and the position from the side's cylinder: the side is often measured over a short height, which fixes where the axis is and not well which way it points. The top's outward normal points from the side's points toward the top, and is the body axis the top is labelled with. The other two axes are laid into the top by instrumentation.surface_frame.

Parameters:

Name Type Description Default
sensor str

The sensor's name.

required
side (array_like, [N, 3])

The points on the round side.

required
top (array_like, [N, 3])

The points on the flat top.

required
label str

The top's label, one of FACE_LABELS.

'3'
meters float

How many meters one unit of the points is. Without it the roughness of the surfaces is not judged.

None

Returns:

Type Description
SensorFit

With a frame unless a surface has too few points; anchor is where the cylinder's axis meets the top, extent the diameter and length twice how far the top is from the middle of the side's points.

measured_features

measured_features(geometry: Any) -> dict[str, ndarray]

The features a geometry of measured points holds (io.point_files): its element groups of measured-point elements.

Parameters:

Name Type Description Default
geometry Geometry

The geometry.

required

Returns:

Type Description
dict of str to numpy.ndarray

The node rows of each feature by the group's name, in the order the groups' elements come. Empty when it holds no measured point.

residuals

residuals(fit: SensorFit, label: str, points: ndarray) -> ndarray | None

How far each of a surface's points lies from the surface fitted to it.

Parameters:

Name Type Description Default
fit SensorFit

The sensor's fit.

required
label str

The surface's label, a face's or c.

required
points (array_like, [N, 3])

Its points.

required

Returns:

Type Description
ndarray or None

The signed distances, in the points' unit; None when no surface was fitted for that label.

parse_feature

parse_feature(name: str) -> tuple[str, str] | None

A feature's sensor and label from its name, <sensor>_<label>.

Parameters:

Name Type Description Default
name str

The feature's name, such as '31_1', '3_-1' or '11_C'.

required

Returns:

Type Description
tuple of (str, str) or None

The sensor and the label, lower-cased, with p read as 3 and b as -3; None when the name has no underscore, no sensor, or a label that is neither a face's nor a cylinder's.

written_label

written_label(name: str) -> tuple[str, str] | None

A feature's sensor and its label as written, p and b kept (parse_feature reads them as faces).

Parameters:

Name Type Description Default
name str

The feature's name.

required

Returns:

Type Description
tuple of (str, str) or None

The sensor and the label, lower-cased; None as parse_feature.

surface_of

surface_of(name: str, beside_cylinder: bool = False) -> str

What a feature's surface is called, one of SURFACES' values.

Parameters:

Name Type Description Default
name str

The feature's name.

required
beside_cylinder bool

Whether its sensor has a cylinder: a 3 there is the top and a -3 the bottom, and is called so.

False

Returns:

Type Description
str

'X+', 'Cylinder', 'Uni-axial Top' and so on; '' when the name is no feature's.

label_of

label_of(surface: str) -> str

The label a feature's name is written with for a surface.

Parameters:

Name Type Description Default
surface str

One of SURFACES' values, in any case, or a label itself.

required

Returns:

Type Description
str

The label.

Raises:

Type Description
ValueError

When it is neither.

fit_sensors

fit_sensors(features: Mapping[str, ndarray], meters: float | None = None) -> tuple[list[SensorFit], list[str]]

Every accelerometer the features locate.

Parameters:

Name Type Description Default
features mapping of str to array_like [N, 3]

The points of each feature by its name, <sensor>_<label>.

required
meters float

How many meters one unit of the points is. Without it the roughness of a surface is not judged.

None

Returns:

Name Type Description
fits list of SensorFit

One per sensor, in the order the sensors first appear. A sensor with a c feature is uni-axial, any other tri-axial.

notes list of str

The features left out, and why.