API reference
ska_telmodel.data
- class ska_telmodel.data.TMData(source_uris: Optional[list[str]] = None, prefix: str = '', update: bool = False, backend_pars: dict = {})[source]
Represents a tree of telescope model data.
Data is retrieved from specified
sources
(or using default sources if not passed). Depending on backend, this might cause data to be loaded from remote locations, such as the SKAO central artefact repository or Gitlab.Objects of this class provide a hierarchical
dict
/h5py
-like interface. For instance, you can print all objects with keys starting withinstrument/layout
as follows:layouts = tmdata['instrument/layout'] for key in layouts: print(f"Data for {key}: ", layouts[key].get())
This works because
__getitem__()
will redirect toget_subtree()
orget()
depending on whether a valid key is passed (i.e. it has an extension). TheTMObject
object can then be used to access the underlying telescope model data.- Parameters
source_uris – List of telescope model data sources. If not passed, defaults to
SKA_TELMODEL_SOURCES
enviroment variable, then in-builtDEFAULT_SOURCES
.prefix – Key prefix for sub-tree selection
update – Update cached data sources (if any)
backend_pars – Extra parameters to specific backend (types)
- get(key: str) ska_telmodel.data.frontend.TMObject [source]
Returns the telescope model object with the given key
- Parameters
key – Key to retrive. Must be a valid telescope model key (i.e. have a file type extension)
- Returns
TMObject
object- Raises
KeyError
if object doesn’t exist
- get_sources(pinned: bool = False) list[str] [source]
Returns list of source URIs
- Parameters
pinned – Attempt to return URIs that will continue to refer to this specific version of telescope model data. E.g. for GitLab URIs, this replaces tags or branches by the concrete commit hash.
- Returns
list of sources
- get_subtree(prefix: str) ska_telmodel.data.frontend.TMData [source]
Returns clone of
TMData
object with given prefixNote that no checking is done whether any keys with the given prefix exist.
- Parameters
prefix – Prefix to narrow scope to. Must be a valid telescope model prefix
- Returns
TMData
object using prefix
- class ska_telmodel.data.TMObject(source: ska_telmodel.data.backend.TMDataBackend, key: str)[source]
Represents a telescope model data object. Provides a number of ways to access the data.
- Parameters
source – Backend to use to retrieve object data
key – Key associated with object
ska_telmodel.schema
Support for validating and generating examples for SKA telescope model schemas.
- class ska_telmodel.schema.SchemaUri(version: str)[source]
Convenience class for manipulating version URIs.
- Parameters
version – Interface URI
- ska_telmodel.schema.example_by_uri(version: str, *args) dict [source]
Generates an example for a particular schema
- Parameters
version – Interface URI
args – Extra parameters depending on interface (strings)
- Returns
Dictionary
- ska_telmodel.schema.schema_by_uri(version: str, strict: int = 1, **kwargs) schema.Schema [source]
Looks up interface schema based on interface identifier
- Parameters
version – Interface URI
strict – Strictness level
- Returns
Interface schema
- ska_telmodel.schema.validate(version: Optional[str], config: dict, strictness: int = 1)[source]
Validate a dictionary against schema
Will automatically determine the schema to check against
- Parameters
version – Interface with version
config – Dictionary to validate
strictness –
Strictness level (0: permissive warnings, 1: permissive errors + strict warnings, 2: strict errors).
Note that with strictness level 2, a lot of generally harmless schema violations will cause an exception to be raised. This is generally inadvisable in production consumer code (“be liberal in what you accept”!).
- Raises
SchemaError – Raised if the object fails permissive checks at strictness level 1. At strictness level 2, raised if the object fails any schema check.