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"is0); - 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_LENGTHcharacters that repeats one character, case-insensitive ("XXXXXXXX","99999999"); an integer id such as1111is not filler; - truncated read (
truncations=True; text only, in order) -- a value held at most :data:TRUNCATION_MAX_SAMPLESconsecutive 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_SHAREof 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).
| Name | Description |
|---|---|
is_misread_value | Whether one value is a misread (context-free rules only). |
is_misread | Flag misread id readings. |
id_strings | Object ids as text (string dtype, missing values stay <NA>). |
is_misread_value
is_misread_value(value: object) -> bool
Whether one value is a misread (context-free rules only).
| Name | Type | Description | Default |
|---|---|---|---|
value | object | A raw id reading (text or number). | required |
| Type | Description |
|---|---|
bool | True for a blank, letterless/digitless, PLC default, placeholder |
bool | or filler value; False for a missing value, a boolean and every |
bool | other id. |
is_misread
is_misread(values: Iterable[object], *, truncations: bool = True) -> _BOOL
Flag misread id readings.
| Name | Type | Description | Default |
|---|---|---|---|
values | Iterable[object] | The readings of one id signal, in time order when truncations is on (a Series, array or list). | required |
truncations | bool | Also flag truncated reads, which needs the neighbouring readings (see the module docstring). | True |
| Type | Description |
|---|---|
_BOOL | A 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
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.