neurotools.util.tools module

neurotools.util.tools.varexists(varname)[source]
neurotools.util.tools.nowarn()[source]
neurotools.util.tools.okwarn()[source]
neurotools.util.tools.dowarn(*a, **kw)[source]
neurotools.util.tools.warn(*a, **kw)[source]
neurotools.util.tools.debug(*a, **kw)
neurotools.util.tools.wait(prompt='--- press enter to continue ---')[source]
neurotools.util.tools.matlab(commands)[source]

Runs Matlab commands through the shell TODO: make matlabpath configurable

neurotools.util.tools.history(n)[source]

Return last n lines of shell history

neurotools.util.tools.p2c(p)[source]

Convert a point in terms of a length-2 iterable into a complex number

neurotools.util.tools.c2p(z)[source]

Convert complex point to tuple

class neurotools.util.tools.emitter(operation=None)[source]

Bases: object

This is a toy example test of a concept used in the piper dectorator below. It extends callables so that using them with the logical or operator “|” will apply the callable as a side effect before returning the original value of the expression. The default side effect is printing the object value.

Example

>>> emit = emitter()
>>> emit | cos(10)
class neurotools.util.tools.piper(operation)[source]

Bases: object

Piper extends callables such that they can be called by using infix operators. This is just for fun and you should probably not use it.

Example

>>> def foo(x):
>>>     return x+1
>>> pip = piper(foo)
>>> 1 + 1 | pip
>>> @piper
>>> def zscore(x):
>>>     return (x-mean(x,0))/std(x,0)
>>> zscore < rand(10)
neurotools.util.tools.globalize(function, *args, **krgs)[source]

globalize allows the positional argument list of a python to be truncated.

Missing arguments will be filled in by name from the globals dictionary.

neurotools.util.tools.exists(varname)
neurotools.util.tools.metaloadmat(path)[source]

Loads a matfile from the provided path, caching it in the global dict “matfilecache” using path as the lookup key.

Parameters:

path (string) – unique absolute path to matfile to be loaded

neurotools.util.tools.find_all_extension(d, ext='png')[source]

Locate all files with a given extension

Parameters:
  • d (string) – String representing a path in the filesystem

  • ext (string) – extension to locate. search is not case-sensitive.

Returns:

found – List of files with matching extension

Return type:

string

neurotools.util.tools.setinrange(data, a, b)
neurotools.util.tools.mapdict(data, function)
neurotools.util.tools.getdict(data, index)
neurotools.util.tools.ensure_dir(dirname)[source]

Ensure that a named directory exists; if it does not, attempt to create it. http://stackoverflow.com/questions/944536/efficient-way-of-creating-recursive-paths-python

Parameters:

dirname (str)

neurotools.util.tools.getsize(obj)[source]

Recursively iterate to sum size of object & members. http://stackoverflow.com/questions/449560/how-do-i-determine-the-size-of-an-object-in-python

neurotools.util.tools.saveContext()[source]
neurotools.util.tools.clear()
neurotools.util.tools.restoreContext()[source]
neurotools.util.tools.getVariable(path, var)[source]

Reads a variable from a .mat or .hdf5 file The read result is cached in ram for later access

class neurotools.util.tools.TolerantDict[source]

Bases: dict

neurotools.util.tools.yank(argnames)[source]

Turns a string of whitespace-delimited variable names 'name1 name2 ...' accessible in the local or global scope into a dictionary {'name1':name1, ...}.

Parameters:

argnames (str) – A single string containing all variable identifiers to grab, delimited by whitespace.