viscid.vutil module

viscid.vutil.timeit(f, *args, **kwargs)[source]

overly simple timeit wrapper

Parameters:
  • f – callable to timeit
  • *args – positional arguments for f
  • **kwargs – keyword arguments for f
Keyword Arguments:
 
  • timeit_repeat (int) – number of times to call f (Default: 1)
  • timeit_print_stats (bool) – print min/max/mean/median when done
  • timeit_quet (bool) – quiets all output (useful if you only want the timeit_stats dict filled)
  • timeit_stats (dict) – Stats will be stuffed into here
Returns:

The result of f(*args, **kwargs)

viscid.vutil.resolve_path(dset, loc, first=False)[source]

Search for globbed paths in a nested dict-like hierarchy

Parameters:
  • dset (dict) – Root of some nested dict-like hierarchy
  • loc (str) – path as a glob pattern
  • first (bool) – Stop at first match and return a single value
Raises:

KeyError – If there are no glob matches

Returns:

If first == True, (value, path) else, ([value0, value1, …], [path0, path1, …])

viscid.vutil.find_item(dset, loc)[source]

Shortcut for first resolve_path(), item only

viscid.vutil.find_items(dset, loc)[source]

Shortcut for resolve_path(), items only

viscid.vutil.get_trilinear_field()[source]

get a generic trilinear field

viscid.vutil.slice_globbed_filenames(glob_pattern)[source]

Apply a slice to a glob pattern

Note

Slice by value works by adding an ‘f’ to a value, as like the rest of Viscid.

Parameters:glob_pattern (str) – A string
Returns:list of filenames

Examples

If a directory contains files,

>>> os.listdir()
["file.010.txt", "file.020.txt", "file.030.txt", "file.040.txt"]

then sliced globs can look like

>>> expand_glob_slice("f*.[:2].txt")
["file.010.txt", "file.020.txt"]
>>> expand_glob_slice("f*.[10.0j::2].txt")
["file.010.txt", "file.030.txt"]
>>> expand_glob_slice("f*.[20j:2].txt")
["file.020.txt", "file.040.txt"]
viscid.vutil.glob2(glob_pattern, *args, **kwargs)[source]

Wrap slice_globbed_filenames, but return [] on no match

viscid.vutil.interact(banner=None, ipython=True, stack_depth=0, global_ns=None, local_ns=None, viscid_ns=True, mpl_ns=False, mvi_ns=False)[source]

Start an interactive interpreter