TagExpression#

Module providing routines to check and convert between tag expressions. This simplfies the handling of list of files from using regular expressions to tag expression.

A tag is a simple placeholder for a string or number in a file name. An expression is a filename with any number of tags.

A tag has the format <Name,Type,Width>.
  • Name : str that specifies the tag name

  • Type : ‘I’ or ‘S’ for integer or string, optional and defaults to ‘I’

  • Width : int, if given indicates a fixed width and missing digist or chars are replaced by trailing zeros or spaces.

The module also provides functions to infer the tag expressions from a list of file names via the function detect().

Expressions can also be converted to glob or regular expressions.

Example

An example tag expression would be ‘file_<X,2>_<Y,3>.npy’ and would for example match the filename ‘file_01_013.npy’

>>> import ClearMap.Utils.TagExpression as te
>>> e = te.Expression('file_<X,2>_<Y,3>.npy')
>>> e.tag_names()
e.tag_names()
>>> e.glob()
'file_[0-9][0-9]_[0-9][0-9].npy'
>>> e.indices('file_01_013.npy')
[1, 13]
>>> e.re()
'file_(?P<X>\d{2})_(?P<Y>\d{3})\.npy'
>>> e.string({'X':1, 'Y':10})
'file_01_010.npy'
class Expression(pattern=None)[source]#

Bases: object

detect(strings, names=None, max_check=None, with_trange=False)[source]#
glob(values=None)[source]#
indices(string)[source]#
ntags()[source]#
parse(expression)[source]#
re()[source]#
string(values=None)[source]#
string_from_index(indices)[source]#
tag()[source]#
tag_names()[source]#
values(string)[source]#
class Tag(tag=None, name=None, ttype='I', width=None, reference=None, trange=None)[source]#

Bases: object

dtype()[source]#
glob()[source]#
index(value)[source]#
label(index=None)[source]#
parse(tag)[source]#
re(name=None)[source]#
string(value=None)[source]#
string_from_index(index=None)[source]#
tag()[source]#
value(string)[source]#
default_tag_name(index=None)[source]#
detect(strings, names=None, max_check=None, with_trange=False)[source]#
escape_glob(string)[source]#
parse(expression)[source]#
ttype_to_dtype(ttype)[source]#