Util

Utils module Configuration table manipulation

Lattice configuration table is abstracted as a dict[str, dict[str, str | int | float | dict]] Where the first-level keys correspond to location names The corresponding values contain the second-level keys and values

table = {…, location -> data, …} = {…, location -> {…, key -> value, …}, …}

Functions

mod : Compute remainder with offset cast : Cast string load : Load configuration table save : Save configuration table rename : Rename keys select : Select key insert : Insert key remove : Remove key mingle : Mingle two configuration tables

model.util.cast(value: str) str | int | float[source]

Casr string

Parameters:

value (str) – input string

Return type:

str|int|float

model.util.insert(table: Table, key: str, locations: dict[str, str | int | float | dict], *, replace: bool = True, apply: Callable | None = None) Table[source]

Insert key

Parameters:
  • table (Table) – input configuration table

  • key (str) – key name

  • locations (dict[str,str|int|float|dict]) – values to insert

  • replace (bool, default=True) – flag to replace existing values

  • apply (Optional[Callable]) – function to apply to shared keys values

Return type:

Table

model.util.load(path: Path) Table[source]

Load configuration table

Parameters:

path (Path) – input path with table to load

Return type:

Table

model.util.mingle(probe: Table, other: Table, replace: bool = True, apply: Callable | None = None) Table[source]

Mingle two configuration tables

Parameters:
  • probe (Table) – probe table (shared keys values appear first)

  • other (Table) – other table

  • replace (bool, default=True) – flag to replace existing values

  • apply (Optional[Callable]) – function to apply to shared keys values

Return type:

Table

model.util.mod(x: float, y: float, z: float = 0.0) float[source]

Compute remainder with offset

Parameters:
  • x (float) – numerator

  • y (Tensfloator) – denomenator

  • z (float, default=0.0) – offset

Return type:

float

model.util.remove(table: Table, key: str, *, locations: list[str] | None = None) Table[source]

Remove key

Parameters:
  • table (Table) – input configuration table

  • key (str) – key name

  • locations (Optiona[list[str]]) – list of locations

Return type:

Table

model.util.rename(table: Table, rule: dict[str, str], *, drop: bool = True) Table[source]

Rename keys

Parameters:
  • table (Table) – input table

  • rule (dict[str, str]) – keys replacement rule

  • drop (bool, default=true) – flag to drop keys not appearing in rule

Return type:

Table

model.util.save(table: Table, path: Path) None[source]

Save configuration table

Parameters:
  • table (Table) – table to save

  • path (Path) – output file path

Return type:

None

model.util.select(table: Table, key: str, *, keep: bool = False) dict[str, str | int | float | dict][source]

Select key

Parameters:
  • table (Table) – input table

  • key (str) – selected key

  • keep (bool) – flag to keep key in the output

Return type:

dict[str,str|int|float|dict]