gruvoc.surfconfig: Surface name, ID, and property management

This module provides an interface to surface grid configuration control. Perhaps the primary goal is simply to associate a name with each ID number in a surface grid.

class cape.gruvoc.surfconfig.JSONOpts(*args, **kw)
class cape.gruvoc.surfconfig.SurfConfig(fname: str | None = None, **kw)

Surface properties and configurations

Call:
>>> cfg = SurfConfig(fname=None, **kw)
Outputs:
cfg: SurfConfig

Surface configuration

Attributes:
add_face(comp: str, comp_id: int)

Add a new face with specified ID number

Call:
>>> cfg.add_face(comp, comp_id)
Inputs:
cfg: SurfConfig

Surface configuration

comp: str

Name of component (face/family)

comp_id: int

ID number for comp

add_parent(parent: str, child: str)

Add a parent-child relationship for two named components

Call:
>>> cfg.add_parent(parent, child)
Inputs:
cfg: SurfConfig

Surface component configuration instance

parent: str

Name of parent component

child: str

Name of child component

Attributes:

parents: parent added to cfg.parents[child]

apply_comp_dict(configdict: dict)

Renumber components to match dict and remove unused comps

Call:
>>> cfg.apply_comp_dict(configdict)
Inputs:
cfg: SurfConfig

Surface component configuration instance

configdict: dict[int]

Dictionary of components to keep and their final IDs

assert_comp(comp: str)

Test of comp is in the configuration

Call:
>>> cfg.assert_comp(comp)
Inputs:
cfg: SurfConfig

Surface configuration

comp: str

Name of component (face/family)

Raises:

GruvocValueError if comp is not present

clear_parent_comp_ids()

Remove CompID setting from any comp that is a parent

This means that only the base-level components are numbered.

Call:
>>> cfg.clear_parent_comp_ids()
Inputs:
cfg: SurfConfig

Surface component configuration instance

faces

list[str] Ordered list of faces

fdir

str | None Absolute path to folder containing source file

fname

str | None Base name of file from which configuration was read

get_comp_ids(comp: str) list

Get list of component IDs within a component, expanding tree

Call:
>>> comp_ids = cfg.get_comp_ids(comp)
Inputs:
cfg: SurfConfig

Surface component configuration instance

comp: str

Name of component

Outputs:
comp_ids: list[int]

List of component IDs in comp and its children

get_complist() list

Get full list components from tree and props

Call:
>>> complist = cfg.get_complist()
Inputs:
cfg: SurfConfig

Surface component configuration instance

Outputs:
complist: list[str]

List of components mentioned in configuration

get_name(surf_id: int) str

Find face name from a single component ID

Call:
>>> face = cfg.get_name(surf_id)
Inputs:
cfg: SurfConfig

Surface component configuration instance

surf_id: int

Surface index

get_prop(comp: str, opt: str) Any

Get any property for one component, including from parents

Call:
>>> val = cfg.get_prop(comp, opt)
Inputs:
cfg: SurfConfig

Surface configuration

comp: str

Name of component (face/family)

opt: str

Name of poperty to set

Outputs:
val: object

Value to set for that property

get_prop_comp(comp: str, opt: str) Any

Get any property for one component, no recursion

Call:
>>> val = cfg.get_prop(comp, opt)
Inputs:
cfg: SurfConfig

Surface configuration

comp: str

Name of component (face/family)

opt: str

Name of poperty to set

Outputs:
val: object

Value to set for that property

parents

dict[list[str]]] List of parent components of each component

props

dict[dict] Properties for each face or family

read_json(fname: str)

Read surface configuration from JSON file

Call:
>>> cfg.read_json(fname)
Inputs:
cfg: SurfConfig

Surface component configuration instance

fname: str

Name of file to read

read_mapbc(fname_or_fp: IOBase | str)

Read a MapBC text file

Call:
>>> cfg.read_mapbc(fname)
>>> cfg.read_mapbc(fp)
Inputs:
cfg: SurfConfig

Surface component configuration instance

fname: str

Name of file to read

fp: IOBase

File handle to read from

remove_comp(comp: str)

Remove a component from configuration, including tree

Call:
>>> cfg.remove_comp(comp)
Inputs:
cfg: SurfConfig

Surface component configuration instance

comp: str

Name of component to remove

Attributes:

comp removed from both props and tree

renumber_comps()

Renumber used components 1, 2, …

Call:
>>> cfg.renumber_comps()
Inputs:
cfg: SurfConfig

Surface component configuration instance

restrict_comp_ids(comp_ids: list | ndarray)

Restrict configuration to comps with specified IDs

Call:
>>> cfg.restrict_comp_ids(comp_ids)
Inputs:
cfg: SurfConfig

Surface component configuration instance

comp_ids: list[int]

List/array of CompIDs to keep

set_prop(comp: str, opt: str, val: Any)

Set any property for one component

Call:
>>> cfg.set_prop(comp, opt, val)
Inputs:
cfg: SurfConfig

Surface configuration

comp: str

Name of component (face/family)

opt: str

Name of poperty to set

val: object

Value to set for that property

tree

dict[list[str]] Lists of direct children of each family component

cape.gruvoc.surfconfig.identify_config_filetype(fname: str) str

Identify the probable file format based on a file name

Call:
>>> ext = identify_config_filetype(fname)
Inputs:
fname: str

Name of file to read/write

Ouputs:
ext: str

Probable file type