format_spectrum_id
- emmet.core.xas.format_spectrum_id(spectrum_id, legacy, prefix='mp', padlen=ID_PADLEN)
Render an XAS spectrum id in either legacy or new alpha form.
Spectrum ids are composite identifiers built at runtime from a task id plus three typed suffix components (spectrum type, absorbing element, edge), all joined with
-. Their shape convention follows the same prefix-dropping rule as task ids — the leading id portion is prefixed in legacy form and bare in alpha form:Legacy form:
mp-<int>-<XasType>-<Element>-<XasEdge>(e.g.mp-779827-XANES-O-K).New alpha form:
<padded-alpha>-<XasType>-<Element>-<XasEdge>(e.g.aaabsjpj-XANES-O-K) with nomp-prefix.
Parsing delegates to
validate_xas_spectrum_id()(and through it tovalidate_compound_identifier()), so the suffix shape stays in lockstep with the canonical XAS spectrum_id schema.- Args:
- spectrum_id: A spectrum id in either form. May be the bare composite
string, or anything
validate_xas_spectrum_id()accepts.- legacy: If True, returns the legacy
mp-<int>-...form. If False, returns the bare-alpha-prefixed
<padded-alpha>-...form.
prefix: The id prefix used in the legacy form. Defaults to
"mp". padlen: The minimum identifier length on the alpha-form output.Defaults to 8.
- Returns:
The formatted string. If
spectrum_idis None or empty, it is returned unchanged. If parsing fails, the input is coerced to a string and returned unchanged (defensive: this helper never raises from a display path).- Examples:
>>> format_spectrum_id("mp-779827-XANES-O-K", legacy=False) 'aaabsjpj-XANES-O-K' >>> format_spectrum_id("aaabsjpj-XANES-O-K", legacy=True) 'mp-779827-XANES-O-K'
- Return type:
str|None- Parameters:
spectrum_id (Any)
legacy (bool)
prefix (str)
padlen (int)