iode.Comments.get_names_from_pattern

Comments.get_names_from_pattern(list_name: str, pattern: str, xdim: str | List[str], ydim: str | list[str] = None) List[str]

Generate an IODE list containing the names of objects that match a given pattern.

Parameters:
list_name: str

Name of the IODE list which will contain the resulting list of names.

pattern: str

Pattern to which the name of the objects must conform, where “x” is replaced by the elements from ‘xdim’ and, if specified, “y” by the elements from ‘ydim’.

xdim: str or list(str)

x dimension of the list. It can be a list of strings or an existing IODE list. If it is an existing IODE list, it must be referred as “$<list_name>”.

ydim: str or list(str), optional

y dimension of the list. It can be a list of strings or an existing IODE list. If it is an existing IODE list, it must be referred as “$<list_name>”. Defaults to None.

Returns:
list(str)

Examples

>>> import numpy as np
>>> from iode import variables, lists
>>> # fill the variables database
>>> variables.sample = "2000Y1:2010Y1"
>>> variables["R1C1"] = np.nan
>>> variables["R1C2"] = np.nan
>>> variables["R1C3"] = np.nan
>>> variables["R2C1"] = np.nan
>>> variables["R2C2"] = np.nan
>>> variables["R2C3"] = np.nan
>>> variables["R3C1"] = np.nan
>>> variables["R3C2"] = np.nan
>>> variables["R3C3"] = np.nan
>>> # create an IODE list X
>>> lists["X"] = ["R1", "R2", "R3"]
>>> # create an IODE list Y
>>> lists["Y"] = ["C1", "C2", "C3"]
>>> # generate the IODE list of variables names 
>>> # given a pattern
>>> variables.get_names_from_pattern("RC", "xy", "$X", "$Y")
['R1C1', 'R1C2', 'R1C3', 'R2C1', 'R2C2', 'R2C3', 'R3C1', 'R3C2', 'R3C3']
>>> lists["RC"]
['R1C1', 'R1C2', 'R1C3', 'R2C1', 'R2C2', 'R2C3', 'R3C1', 'R3C2', 'R3C3']