Skip to content

scene_pipelines.ingestion.normalization

Normalization helpers for ingestion.

normalize_code

normalize_code(value: str, *, field: str, max_length: int) -> str

Strip value and check it is a pseudonymous code.

Codes are shared with the consortium, so they must never contain a real name, initials, a birth date or other identifying information. The format check (ASCII letters, digits, ., _, -; no spaces) rejects free-text names such as "Jan de Vries"; it cannot catch every identifying code, so choosing a pseudonym remains the lab's duty.

Parameters:

Name Type Description Default
value str

Raw code, e.g. " P012 ".

required
field str

Field name used in error messages, e.g. "subject_code".

required
max_length int

Maximum length (the column width).

required

Returns:

Type Description
str

The stripped code.

Raises:

Type Description
ValueError

If the code is empty, too long, or not in the allowed format.