MekQuery#
- class pyCGM2.Mek.mek.mekQuery.MekQuery(source)#
Chainable, lazy query over a moveck data store.
- Parameters:
source – moveck
data_storeordata_groupused as query root.
- __init__(source)#
Methods
__init__(source)attributes([inherited, names])dict: Attributes of the matching nodes, by path.
count()int: Number of matching nodes.
depth([min, max])Restrict the depth of the results, relative to the traversal start.
exclude(*patterns)Skip groups (and their whole sub-tree) and datasets matching glob patterns.
first([default])Return the first matching
MekNode, ordefault.group_by(key[, inherited])Group the matching nodes.
groups()Keep groups only.
has_attr(*names[, inherited])Keep nodes carrying all the given attributes.
match(pattern)Keep nodes whose full path matches a glob pattern.
named(*patterns)Keep nodes whose name matches one of the glob patterns (e.g.
"L*Angles").nodes()Keep both groups and datasets (default).
one()Return the single matching
MekNode.paths()list of str: Paths of the matching nodes.
read()dict: Values of the matching datasets, by path (groups are ignored).
regex(pattern)Keep nodes whose full path contains a match of a regular expression.
sets()Keep datasets only.
to_dataframe([attributes, inherited, shapes])Build an inventory of the matching nodes.
tree([show_shape])str: Indented view of the matching nodes (best with no or few filters).
under(path)Start the traversal from a sub-group (chained calls are concatenated).
where(predicate)Keep nodes for which
predicate(node)is True (nodeis aMekNode).where_attr([criteria, inherited])Keep nodes whose attributes satisfy all the criteria.
with_shape(*dims)Keep datasets with a given shape;
Noneis a wildcard.- attributes(inherited=False, names=None)#
dict: Attributes of the matching nodes, by path.
- Parameters:
inherited (bool) – Complete with attributes of the parent groups (only for the names given in
names).names (list, optional) – Attribute names to keep. All by default.
- count()#
int: Number of matching nodes.
- depth(min=None, max=None)#
Restrict the depth of the results, relative to the traversal start.
Depth 1 is a direct child.
maxalso stops the recursion.
- exclude(*patterns)#
Skip groups (and their whole sub-tree) and datasets matching glob patterns.
A pattern containing
/is matched against the full path, otherwise against the node name (e.g."EMG","*Temp*","*/Extraction").
- group_by(key, inherited=False)#
Group the matching nodes.
- Parameters:
key (str or callable) – Attribute name, or function
node -> key.inherited (bool) – Look the attribute up on parent groups.
- Returns:
dict – Lists of
MekNodeby key (Noneif the attribute is missing).
- groups()#
Keep groups only.
- has_attr(*names, inherited=False)#
Keep nodes carrying all the given attributes.
- match(pattern)#
Keep nodes whose full path matches a glob pattern.
*also matches/, so"*/Angles/*"matches at any depth.
- named(*patterns)#
Keep nodes whose name matches one of the glob patterns (e.g.
"L*Angles").
- nodes()#
Keep both groups and datasets (default).
- one()#
Return the single matching
MekNode.- Raises:
LookupError – If there is no match or more than one.
- paths()#
list of str: Paths of the matching nodes.
- read()#
dict: Values of the matching datasets, by path (groups are ignored).
- regex(pattern)#
Keep nodes whose full path contains a match of a regular expression.
- sets()#
Keep datasets only.
- to_dataframe(attributes=True, inherited=False, shapes=True)#
Build an inventory of the matching nodes.
- Parameters:
attributes (bool or list) – True for all attributes, a list of names to select some, False for none.
inherited (bool) – Look the selected attributes up on parent groups (only when
attributesis a list).shapes (bool) – Fill the
shapecolumn. With some moveck versions this reads every dataset; set False for a fast inventory.
- Returns:
pandas.DataFrame – One row per node with
path,name,kind,``depth``, ``shape`` and attribute columns (prefixed by ``attr_`` if
they clash with these names).
- tree(show_shape=True)#
str: Indented view of the matching nodes (best with no or few filters).
show_shapemay read every dataset with some moveck versions.
- under(path)#
Start the traversal from a sub-group (chained calls are concatenated).
- Parameters:
path (str) – Group path relative to the current start, e.g.
"Session 2/Analysis 1".
- where(predicate)#
Keep nodes for which
predicate(node)is True (nodeis aMekNode).Example:
q.sets().where(lambda n: np.isnan(n.read()).any())
- where_attr(criteria=None, inherited=False, **kwargs)#
Keep nodes whose attributes satisfy all the criteria.
Each criterion is either a value (equality) or a callable predicate. Use the
criteriadictionary for names that are not valid Python identifiers (e.g."flow-userSettings").Examples:
q.where_attr(context="Left") q.where_attr(SampleRate=lambda fs: fs > 1000) q.where_attr({"flow-userSettings": lambda s: "CGM2.3" in s}) q.where_attr(context="Left", inherited=True) # attribute set on a parent group
- with_shape(*dims)#
Keep datasets with a given shape;
Noneis a wildcard.Example:
with_shape(None, 3)keeps (n x 3) datasets.