iode.Scalars.__getitem__
- Scalars.__getitem__(key: str | List[str]) Scalar | Self[source]
Return the (subset of) scalar(s) referenced by key.
The key can represent a single object name (e.g. “ACAF”) or a list of object names (“ACAF;ACAG;AOUC”) or a pattern (e.g. “A*”) or a list of sub-patterns (e.g. “A*;*_”).
If the key represents a list of object names or of sub-patterns, each name or sub-pattern is separated by a separator character which is either a whitespace ` , or a comma `,, or a semi-colon ;, or a tabulation t, or a newline n.
A (sub-)`pattern` is a list of characters representing a group of object names. It includes some special characters which have a special meaning:
* : any character sequence, even empty
? : any character (one and only one)
@ : any alphanumerical char [A-Za-z0-9]
& : any non alphanumerical char
| : any alphanumeric character or none at the beginning and end of a string
! : any non-alphanumeric character or none at the beginning and end of a string
`` : escape the next character
Note that the key can contain references to IODE lists which are prefixed with the symbol $.
- Parameters:
- key: str or list(str)
(the list of) name(s) of the scalar(s) to get. The list of scalars to get can be specified by a pattern or by a list of sub-patterns (e.g. “A*;*_”).
- Returns:
- Single scalar or a subset of the database.
Examples
>>> from iode import SAMPLE_DATA_DIR >>> from iode import scalars >>> scalars.load(f"{SAMPLE_DATA_DIR}/fun.scl") Loading .../fun.scl 161 objects loaded
>>> # a) get one scalar >>> acaf1 = scalars["acaf1"] >>> acaf1 Scalar(0.0157684, 1, 0.00136871) >>> acaf1.value 0.01576840691268444 >>> acaf1.relax 1.0 >>> acaf1.std 0.0013687137980014086
>>> # b) get a subset of the Scalars database using a pattern >>> scalars_subset = scalars["a*"] >>> scalars_subset.names ['acaf1', 'acaf2', 'acaf3', 'acaf4']
>>> # c) get a subset of the Scalars database using a list of names >>> scalars_subset = scalars[["acaf1", "acaf4", "dpuh_1", "dpuh_2"]] >>> scalars_subset.names ['acaf1', 'acaf4', 'dpuh_1', 'dpuh_2']