HdsNameShrinker#

class lsst.images.ndf.HdsNameShrinker(max_length=15)#

Bases: object

Shrink HDS component names to fit the HDS object-name length limit.

Names are uppercased; names at or under the limit pass through unchanged. Each distinct over-long name is assigned a readable prefix followed by an underscore-separated hexadecimal counter that increments per assignment, so distinct names written through the same shrinker never collide. Assignments are remembered, so repeated requests for the same name return the same result.

A shrinker is scoped to a single output file: shrunk names are not stable across files, so readers must use the paths recorded in the file’s JSON tree rather than recomputing them.

Parameters:

max_length (int, default: 15) – Maximum component length, by default the HDS limit (DAT__SZNAM).

Methods Summary

shrink(name[, reserve])

Shrink a component name to fit in max_length - reserve.

shrink_versioned(base, version)

Shrink a component while preserving a visible version suffix.

Methods Documentation

shrink(name, reserve=0)#

Shrink a component name to fit in max_length - reserve.

Parameters:
  • name (str) – The component name to shrink.

  • reserve (int, default: 0) – Number of characters to leave available for a suffix the caller will append (e.g. a version suffix).

Returns:

The uppercased name, unchanged if it fits, otherwise truncated and suffixed with _ and an uppercase hexadecimal counter (at least three digits) so the result is exactly max_length - reserve characters.

Return type:

str

shrink_versioned(base, version)#

Shrink a component while preserving a visible version suffix.

When version is greater than one a _{version} suffix is reserved at the tail and the base is shrunk into the remaining characters, so the version number stays readable in Starlink tools. Version one (the first occurrence) is shrunk exactly like an unversioned component.

Parameters:
  • base (str) – Component name to shrink.

  • version (int) – Version number whose suffix is preserved when greater than one.

Return type:

str

This page was last modified on .