Skip to main content
Version: 0.0.98

ts_shape.utils.id_codes

Recognise misread object-id values (PLC no-reads, placeholders, fillers).

A scanner or PLC that fails to read an id still writes something into the id tag: "NOREAD", "#N/A", "????????", the integer default 0 or 65535, a run of X or 0, or the first few characters of the id. Taken at face value each of these becomes an object of its own and splits the presence of the real id around it. :func:is_misread flags such readings so id consumers (object detection, object identification) can treat them as "no reading".

The rules (any one makes a value a misread):

  • blank -- empty or whitespace only ("", " ", "\x00");
  • no letter or digit -- "????????", "--------", "#";
  • PLC default number -- 0, -1, 32767, -32768, 65535, 2147483647, 4294967295, as a number or as text, leading zeros ignored ("00000000" is 0);
  • placeholder token, case-insensitive and ignoring blanks and punctuation -- NOREAD ("NO READ", "no_read"), ERR, ERROR, #N/A / N/A / NA, NULL, NONE, NAN;
  • filler -- text (not a number column) of at least :data:FILLER_MIN_LENGTH characters that repeats one character, case-insensitive ("XXXXXXXX", "99999999"); an integer id such as 1111 is not filler;
  • truncated read (truncations=True; text only, in order) -- a value held at most :data:TRUNCATION_MAX_SAMPLES consecutive samples that is a strict prefix (case-insensitive) of the id read just before it and just after it (SN-0042, SN-0, SN-0042), or of one neighbour when it is also shorter than the length shared by at least :data:MODAL_LENGTH_SHARE of the signal's distinct values (fixed-format ids).

Missing values (NaN / None / <NA>) are not flagged -- they are already "no reading". This module is a superset of the context-free rules of :mod:ts_shape.signals.identify (no letter or digit, PLC default numbers).

Functions
NameDescription
is_misread_valueWhether one value is a misread (context-free rules only).
is_misreadFlag misread id readings.
id_stringsObject ids as text (string dtype, missing values stay <NA>).

is_misread_value​

functionsource
is_misread_value(value: object) -> bool

Whether one value is a misread (context-free rules only).

Parameters
NameTypeDescriptionDefault
valueobjectA raw id reading (text or number).required
Returns
TypeDescription
boolTrue for a blank, letterless/digitless, PLC default, placeholder
boolor filler value; False for a missing value, a boolean and every
boolother id.

is_misread​

functionsource
is_misread(values: Iterable[object], *, truncations: bool = True) -> _BOOL

Flag misread id readings.

Parameters
NameTypeDescriptionDefault
valuesIterable[object]The readings of one id signal, in time order when truncations is on (a Series, array or list).required
truncationsboolAlso flag truncated reads, which needs the neighbouring readings (see the module docstring).True
Returns
TypeDescription
_BOOLA boolean array, one entry per value; True marks a misread.
Example
>>> is_misread(["B1", "NOREAD", "", "????", 0, "B2", None]).tolist()
[False, True, True, True, True, False, False]

id_strings​

functionsource
id_strings(values: pd.Series) -> pd.Series

Object ids as text (string dtype, missing values stay <NA>).

Like values.astype("string"), except that an integral float renders without .0 (1001.0 -> "1001"), as the oids of :func:ts_shape.eventlog.object_intervals do. Keeps the index.