Eidolon
Classes | Functions | Variables
eidolon.Utils Namespace Reference

Classes

class  DelayThread
 
class  enum
 
class  EventHandler
 
class  Future
 
class  FutureError
 
class  MutableDict
 
class  namedrecord
 
class  ObjectLocker
 
class  ParamDef
 
class  Task
 
class  TaskQueue
 

Functions

def lockobj (obj, locker=None)
 
def locking (func, locker=None)
 
def trylocking (func, locker=None)
 
def wrapper (func)
 
def delayedcall (func, args, kwargs, delay)
 
def delayedMethodWeak (obj, methname, delay=0)
 
def taskroutine (func, args, kwargs, taskLabel=None, selfName='task')
 
def taskmethod (meth, args, kwargs, taskLabel=None, taskName='task', mgrName='mgr')
 
def readBasicConfig (filename, evalfunc=ast.literal_eval)
 
def storeBasicConfig (filename, values)
 
def setTrace ()
 
def getAppDir ()
 
def getLibraryDir ()
 
def setLogging (logfile='eidolon.log', filemode='a')
 
def addLibraryFile (lib, append=True)
 
def getVersionsFromRepoURL (url=None)
 
def processExists (pid)
 
def getWinDrives ()
 
def getUsername ()
 
def addPathVariable (varname, path, append=True)
 
def execfileExc (file_or_path, localvars, storeExcepts=True, streams=None)
 
def execBatchProgram (exefile, exeargs, kwargs)
 
def enumAllFiles (rootdir)
 
def checkValidPath (path)
 
def getValidFilename (name)
 
def hasExtension (path, exts)
 
def ensureExt (path, ext, replaceExt=False)
 
def splitPathExt (path, fullExt=False)
 
def timeBackupFile (filename, backDir=None)
 
def sortFilenameList (names, sortIndex, regex=None)
 
def isSameFile (src, dst)
 
def isTextFile (filename, bufferlen=512)
 
def copyfileSafe (src, dst, overwriteFile=False)
 
def renameFile (oldpath, newname, moveFile=True, overwriteFile=False)
 
def addCumulativeTime (name, val)
 
def printCumulativeTimes ()
 
def timing (func)
 
def cumulativeTime (func)
 
def timingBlock (name, printEntry=True, addCumulative=False)
 
def argtiming (func)
 
def tracing (func)
 
def setmethod (obj, methname=None)
 
def traverseObj (obj, func, visited=())
 
def isPicklable (obj)
 
def isIterable (obj)
 
def toIterable (obj)
 
def memoized (converter=lambda i:i, initialmemo={})
 
def isMainThread ()
 
def asyncfunc (func)
 
def partitionSequence (maxval, part, numparts)
 
def createShortName (comps, kwargs)
 
def uniqueStr (name, namelist, spacer='_')
 
def getStrSortIndices (strs, sortIndex, regex=None)
 
def getStrCommonality (str1, str2)
 
def getStrListCommonality (strs)
 
def findGlobMatch (globname, names)
 
def printFlush (args, kwargs)
 
def setStrIndent (s, indent=0, useTab=False)
 
def getUnitValue (val)
 
def getPaddedNum (val, maxval)
 
def parseSequenceSpec (spec, maxval)
 
def epsilonZero (val)
 
def isInEpsilonRange (val, minv, maxv)
 
def checkNan (val)
 
def indexList (indices, lst)
 
def rotateIndices (start, numinds)
 
def sortIndices (lst)
 
def sortedInsert (lst, val)
 
def minmaxIndices (lst)
 
def fcomp (funcs)
 
def first (iterable, default=None)
 
def last (iterable, default=None)
 
def prod (i, initial=1)
 
def listSum (lists)
 
def zipWith (op, vals)
 
def mulsum (ls, rs)
 
def successive (iterable, width=2, cyclic=False)
 
def group (iterable, width=2)
 
def matIter (mat)
 
def matIndices (mat, start=0)
 
def arrayIndex (inds, dims, circular)
 
def xisToPiecewiseXis (xis, dims, limits=None)
 
def frange (start, stop=None, step=None)
 
def trange (vals)
 
def binom (n, k)
 
def bern (n, i, u)
 
def clamp (val, minv, maxv)
 
def lerp (val, v1, v2)
 
def lerpXi (val, minv, maxv)
 
def avg (vals, initial=0.0)
 
def mag (vals)
 
def stddev (vals, initial=0.0)
 
def avgspan (vals)
 
def minmaxval (minv, maxv, val)
 
def minmax (items, kwargs)
 
def radCircularConvert (rad)
 
def radClamp (rad)
 
def getClosestPower (val)
 
def generatePoisson2D (width, height, ptscount, mindist=None, startpt=None)
 
def generatePoisson3D (width, height, depth, ptscount, mindist=None, startpt=None)
 
def unitWave2RGB (vis_range)
 
def wave2RGB (wavelength)
 
def arrayV (val, dims)
 
def assertMatDim (mat, n, m)
 

Variables

 py3
 
 halfpi
 
 epsilon
 
 logFilename
 
 isDarwin
 
 isWindows
 
 isLinux
 
 ConfVars
 
string desc = 'Variables in the Config object loaded from config files, these should be present and keyed to platformID group'
 
 ParamType
 
string doc = 'Types of parameters the ParamDef class can represent.',
 
tuple valtype = (str,)
 
 EventType
 
 cumulativeTimes
 

Function Documentation

◆ addCumulativeTime()

def eidolon.Utils.addCumulativeTime (   name,
  val 
)
Here is the caller graph for this function:

◆ addLibraryFile()

def eidolon.Utils.addLibraryFile (   lib,
  append = True 
)
Add the nominated egg/wheel file to the end of the system path, assuming this is in ${APPDIR}/Libs/python.
Here is the call graph for this function:

◆ addPathVariable()

def eidolon.Utils.addPathVariable (   varname,
  path,
  append = True 
)
Add the string `path' to the environment variable `varname' by appending (if `append` is True) or prepending `path'
using os.pathsep as the separator. This assumes `varname' is a path variable like PATH. Blank paths present in the
original variable are moved to the end to prevent consecutive os.pathsep characters appearing in the variable. If
`varname' does not name a variable with text it will be set to `path'.

◆ argtiming()

def eidolon.Utils.argtiming (   func)
This decorator is the same as timing() except it will additionally print the arguments and return value.
Here is the call graph for this function:

◆ arrayIndex()

def eidolon.Utils.arrayIndex (   inds,
  dims,
  circular 
)
For an array of dimensions `dims' flattened into a 1D list, get the index in that list corresponding to array
indices `inds'. All arguments must be lists/tuples of the same length. For each i in `inds' with corresponding
dimension d in `dims', the value used for calculation is i%d if the corresponding value in `circular' is True,
which allows for negative values and circular indexing. If the value in `circular' is False, the value is
clamp(i,0,d-1) which keeps the resulting index in range.

For example, for an array of dimensions (4,4,4) flattened into a 1D array of length 64, the index in the 1D array
for position (1,2,3) in the 3D array is given by arrayIndex((1,2,3),(4,4,4),[False]*3) which is 57.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ arrayV()

def eidolon.Utils.arrayV (   val,
  dims 
)
Return an array composed of lists containing copies of `val' of dimensions `dims'.
Here is the caller graph for this function:

◆ assertMatDim()

def eidolon.Utils.assertMatDim (   mat,
  n,
  m 
)
Assert that `mat' has dimensions (n,m).
Here is the caller graph for this function:

◆ asyncfunc()

def eidolon.Utils.asyncfunc (   func)
Wraps the callable `func' with a asynchronous version which executes the callable in a daemon thread. The
return value is the threading.Thread object executing the callable, with an extra member `result' containing the
Future object which will eventually store the return value or raised exception from calling `func'.

◆ avg()

def eidolon.Utils.avg (   vals,
  initial = 0.0 
)
Returns the average of the values derived from the iterable `vals', or `initial' if there are none.
Here is the caller graph for this function:

◆ avgspan()

def eidolon.Utils.avgspan (   vals)
Returns the average difference between successive values derived from the given iterable.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bern()

def eidolon.Utils.bern (   n,
  i,
  u 
)
Bernstein coefficient, (n choose i)*(u**i)*((1-u)**(n-i))
Here is the call graph for this function:
Here is the caller graph for this function:

◆ binom()

def eidolon.Utils.binom (   n,
  k 
)
Calculates the binomial coefficient (n choose k) using the multiplicative formula.
This is equivalent to the expression n!/(k!(n-k)!) but faster.
Here is the caller graph for this function:

◆ checkNan()

def eidolon.Utils.checkNan (   val)
Asserts that `val' is not NaN and then returns it.

◆ checkValidPath()

def eidolon.Utils.checkValidPath (   path)
Returns values to indicate if `path' is a valid pathname and if not why. This will return 0 if `path' exists or
otherwise is a valid path, 1 if not accessible, 2 if the filename component contains invalid characters, and 3 if
the extension contains invalid characters.
Here is the call graph for this function:

◆ clamp()

def eidolon.Utils.clamp (   val,
  minv,
  maxv 
)
Returns minv if val<minv, maxv if val>maxv, otherwise val.
Here is the caller graph for this function:

◆ copyfileSafe()

def eidolon.Utils.copyfileSafe (   src,
  dst,
  overwriteFile = False 
)
Copy file from path `src' to path `dst' only if they are not the same file. If `overwriteFile' is True, raise an
IOError if `dst' already exists.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ createShortName()

def eidolon.Utils.createShortName (   comps,
  kwargs 
)
Creates a string by joining components `comps' with _, shortening each component to max length `complen' or 10.

◆ cumulativeTime()

def eidolon.Utils.cumulativeTime (   func)
Add the time taken to execute `func' to a stored cumulative time counter for that function.
Here is the call graph for this function:

◆ delayedcall()

def eidolon.Utils.delayedcall (   func,
  args,
  kwargs,
  delay 
)
Here is the caller graph for this function:

◆ delayedMethodWeak()

def eidolon.Utils.delayedMethodWeak (   obj,
  methname,
  delay = 0 
)
Replaces the method named `methname' of object `obj' with an equivalent delayed call with a delay value of `delay'.
The new method assigned to `obj' replaces `methname' but keeps only a weak reference to `obj'. Once `obj' has been
collected an exception will be thrown when attempting to call this method, this will cause the delay thread to be
removed from the DelayThread global list. This allows objects to be assigned individual delay threads for their
methods, otherwise using delayedcall() directly means a thread is assigned to a method which is shared amongst all
instances. Using the weak reference prevents the delay mechanism from affecting collection behaviour.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ensureExt()

def eidolon.Utils.ensureExt (   path,
  ext,
  replaceExt = False 
)
Ensures the returned path ends with extension `ext'. If the path doesn't have `ext' as its extension, this returns
`path' with `ext' appended, replacing any existing extension if `replaceExt' is True. Eg. ensureExt('foo','.bar')
returns 'foo.bar' as does ensureExt('foo.baz','.bar',True), but ensureExt('foo.baz','.bar') returns 'foo.baz.bar'.
Here is the caller graph for this function:

◆ enumAllFiles()

def eidolon.Utils.enumAllFiles (   rootdir)
Yields all absolute path regular files in the given directory.

◆ epsilonZero()

def eidolon.Utils.epsilonZero (   val)
Return 0.0 if `val' is within 'epsilon' of 0.0, otherwise return 'val' converted to a float value.
Here is the caller graph for this function:

◆ execBatchProgram()

def eidolon.Utils.execBatchProgram (   exefile,
  exeargs,
  kwargs 
)
Executes the program `exefile' with the string arguments `exeargs' as a batch process. The return result is a return
code and output string pair. The integer return code is taken from the program, in the usual case 0 indicating a
correct execution and any other value indicating failure, and the output is a string of the merged stdout
and stderr text. If the program requires input it will deadlock, this is a batch operation routine only. A
keyword value `timeout' can be given indicating how long to wait for the program in seconds before killing it,
otherwise the routine will wait forever. If the keyword `logcmd' is True then the command line to be executed is
printed to stdout before being run. If a log file path is given in keyword `logfile', the output from the program
will be piped to that file. An environment map can be provided as `env' which will be used to override the inherited
environment during the execution.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ execfileExc()

def eidolon.Utils.execfileExc (   file_or_path,
  localvars,
  storeExcepts = True,
  streams = None 
)
Executes the file or file path `file_or_path' in the same manner as execfile() with `localvars' as the local variable
environment. If `storeExcepts' is True, whenever the code encounters an exception it is added to a list and the
routine will then attempt to continue interpreting the code. The list of raised exceptions is then returned by the
routine. If `storeExcepts' is False execution stops on the first exception raised. If `streams' is given, it must be 
a triple of objects suitable to substitute for the streams (sys.stdin, sys.stdout, sys.stderr) which are temporarily 
reassigned for the duration of execution.

◆ fcomp()

def eidolon.Utils.fcomp (   funcs)
Functional composition operator, fcomp(f0,f1,...,fn) is equivalent to lambda i:f0(f1(...fn(i)...)).

◆ findGlobMatch()

def eidolon.Utils.findGlobMatch (   globname,
  names 
)
If `globname' is a globulated name (that is one ending with *) then return the first string in `names' which
begins with `globname' minus the *, or None if there is no match. If `globname' doesn't end with * it is returned.
This does NOT do regex matching using `globname', it only works with names created with globulateStrList().
Here is the call graph for this function:

◆ first()

def eidolon.Utils.first (   iterable,
  default = None 
)
Returns the first item in the given iterable, meaningful mostly with 'for' expressions.

◆ frange()

def eidolon.Utils.frange (   start,
  stop = None,
  step = None 
)
Same as 'range', just with floats.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ generatePoisson2D()

def eidolon.Utils.generatePoisson2D (   width,
  height,
  ptscount,
  mindist = None,
  startpt = None 
)
Generates a randomly distributed set of 2D points across the rectangle defined by `width' and `height'. The
`mindist' distance is the closest any two points can be and `ptscount' value is the maximum number of points
returned, thus if `mindist' is too large fewer points are returned owing to too little space on the rectangle. If
no `mindist' value is given, one is chosen which tends to distribute points evenly across the whole rectangle and
return almost exactly 'ptscount' points. If `startpt' is provided the generation process begins at that point in
the rectangle, otherwise a random point is chosen. This value and the returned points are all float pairs.
Here is the call graph for this function:

◆ generatePoisson3D()

def eidolon.Utils.generatePoisson3D (   width,
  height,
  depth,
  ptscount,
  mindist = None,
  startpt = None 
)
Generates a randomly distributed set of 3D points across the rectangle defined by `width', `height', and `depth'.
The other arguments and general behaviour of this algorithm are the same as that for generatePoisson2D() except
return values and `startpt' are float triples.
Here is the call graph for this function:

◆ getAppDir()

def eidolon.Utils.getAppDir ( )
Returns the application's directory as stored in the __init__.__appdir__t variable.
Here is the caller graph for this function:

◆ getClosestPower()

def eidolon.Utils.getClosestPower (   val)
returns the power of 10 closest to the absolute value of `val'.

◆ getLibraryDir()

def eidolon.Utils.getLibraryDir ( )
Returns the application's shared object library directory as stored in the __init__.__libdir__ variable.

◆ getPaddedNum()

def eidolon.Utils.getPaddedNum (   val,
  maxval 
)
Return the string form of `val' with enough pad zeros for as many digits as `maxval'.

◆ getStrCommonality()

def eidolon.Utils.getStrCommonality (   str1,
  str2 
)
Returns the maximal length initial substring that the two arguments strings have in common and the percentage of
the minimal length this value represents. A result of (0,0.0) indicates the two strings have nothing in common. A
value of (X,1.0) indicates that the shorter of the two strings is the prefix of the longer which has length X.
Eg. getStrCommonality('foo','foul') = (2,0.6666666) indicating that the first 2 letters of 'foo' are common and
represent 2/3rds of its length.
Here is the call graph for this function:

◆ getStrListCommonality()

def eidolon.Utils.getStrListCommonality (   strs)
Returns the index of the first character which is not common in all the strings of the list `strs'.
Here is the call graph for this function:

◆ getStrSortIndices()

def eidolon.Utils.getStrSortIndices (   strs,
  sortIndex,
  regex = None 
)
Determine the sort order of iterable `strs' based on the component indexed by `sortIndex'. Each string is split
using `regex' as the regular expression to use with re.split (by default it splits names by _-\. | characters),
then the component at position `sortIndex' is used to determine the sort order either by casting to an integer or
through string comparison if it isn't a number. The result is the index list specifying the sorted ordering, or is
the empty list if `strs' is an empty sequence.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getUnitValue()

def eidolon.Utils.getUnitValue (   val)
Given a size `val' in bytes, returns a string with the size rounded to the nearest base 2 unit (B, kB, MB, etc.)
with the appropriate unit suffix addded to the end. These are base-2 units, ie. MB is given in stead of MiB.

◆ getUsername()

def eidolon.Utils.getUsername ( )
Returns the username in a portable and secure way which works with 'su' and non-terminal processes.

◆ getValidFilename()

def eidolon.Utils.getValidFilename (   name)
Replaces all invalid filename characters with underscore.
Here is the caller graph for this function:

◆ getVersionsFromRepoURL()

def eidolon.Utils.getVersionsFromRepoURL (   url = None)
Returns the current application version, the most recent released version at `url' otherwise None if `url' is None or 
the given URL cannot be connected to, and whether the current version is at least a new as the newest release.

◆ getWinDrives()

def eidolon.Utils.getWinDrives ( )
Returns available Windows drive letters.

◆ group()

def eidolon.Utils.group (   iterable,
  width = 2 
)
Groups successive items from `iterable' into `width' size tuples and yields each sequentially. If the number of 
items in `iterable' isn't a multiple of `width', the last shortened group is discarded. 
Eg. group(range(5))    -> (0,1), (2,3)
    group(range(10))   -> (0, 1), (2, 3), (4, 5), (6, 7), (8, 9)
    group(range(10),3) -> (0, 1, 2), (3, 4, 5), (6, 7, 8)
    group(range(2),3)  -> nil
Here is the caller graph for this function:

◆ hasExtension()

def eidolon.Utils.hasExtension (   path,
  exts 
)
Returns True if the filename `path' has any of the extensions in `exts', which can start with a period or not.

◆ indexList()

def eidolon.Utils.indexList (   indices,
  lst 
)
Returns a list containing `lst'[i] for each index i in `indices'. 
Here is the caller graph for this function:

◆ isInEpsilonRange()

def eidolon.Utils.isInEpsilonRange (   val,
  minv,
  maxv 
)
Returns true if `val' is in the range [minv,maxv] expanded in both directions by 'epsilon'.

◆ isIterable()

def eidolon.Utils.isIterable (   obj)
Returns True if `obj' is iterable container type, ie. list, tuple, dict.
Here is the caller graph for this function:

◆ isMainThread()

def eidolon.Utils.isMainThread ( )
Returns true if the call thread is the main thread. This relies on checking against the type _MainThread.
Here is the caller graph for this function:

◆ isPicklable()

def eidolon.Utils.isPicklable (   obj)
Returns True if `obj' can be pickled.

◆ isSameFile()

def eidolon.Utils.isSameFile (   src,
  dst 
)
Returns True if the files `src' and `dst' refer to the same extant file.
Here is the caller graph for this function:

◆ isTextFile()

def eidolon.Utils.isTextFile (   filename,
  bufferlen = 512 
)
Checks the first `bufferlen' characters in `filename' to assess whether the file is a text file or not.

◆ last()

def eidolon.Utils.last (   iterable,
  default = None 
)
Returns the last item in the given iterable, meaningful mostly with 'for' expressions.

◆ lerp()

def eidolon.Utils.lerp (   val,
  v1,
  v2 
)
Linearly interpolate between `v1' and `v2', val==0 results in `v1'.

◆ lerpXi()

def eidolon.Utils.lerpXi (   val,
  minv,
  maxv 
)
Calculates the linear interpolation xi value corresponding to `val' if interpolated over the range [minv,maxv],
ie. if lerpXi(V,A,B)==X then lerp(X,A,B)==V assuming A<B. If minv>=maxv then `val' is returned.

◆ listSum()

def eidolon.Utils.listSum (   lists)
Sums the iterable of lists into one long list.
Here is the caller graph for this function:

◆ locking()

def eidolon.Utils.locking (   func,
  locker = None 
)
This is a locking method decorator which uses 'lockobj' to synchronize access to the current object. This ensures
that calls to decorated methods are restricted to one thread at a time, which doesn't necessarily ensure exclusive
access to the all of the receiving object's members. A calling thread having a lock to the receiver already through
'lockobj' will be able to call decorated methods as well.
Here is the call graph for this function:

◆ lockobj()

def eidolon.Utils.lockobj (   obj,
  locker = None 
)
Returns a lock object which is be globally unique per input object. This lock can be used to synchronize access
to any arbitrary object. It uses weak references to ensure previously locked objects can be collected.
This function is thread-safe.
Here is the caller graph for this function:

◆ mag()

def eidolon.Utils.mag (   vals)
Return the magnitude of the n-dimensional vector `vals'.

◆ matIndices()

def eidolon.Utils.matIndices (   mat,
  start = 0 
)
Returns a matrix with the same dimensions as `mat' with ascending value entries starting from `start'.

◆ matIter()

def eidolon.Utils.matIter (   mat)
Iterate over each element of each iterable yielded by `mat' (ie. a list of lists).
Here is the caller graph for this function:

◆ memoized()

def eidolon.Utils.memoized (   converter = lambda i: i,
  initialmemo = {} 
)
Produces a memoized version of the applied function. This is only useful for functions which always return the
same result for given arguments. When the function is called, the memo dictionary is checked to see if there's a
result keyed to the given arguments. If so this is returned, otherwise the original function is called and the
result is stored and returned. The `converter' argument is used to convert the results from the original
function into a storable form (eg. use `tuple' to store results from generators). All arguments must be hashable.
The dictionary `initialmemo' can be used to initialize the stored memo with given arg-result value pairs.

◆ minmax()

def eidolon.Utils.minmax (   items,
  kwargs 
)
Returns the minimum and maximum values, like a combined min and max. If the keyword argument `ranges' is True then
the members of `items' are treated as (min value, max value) pairs and the result is the minimal of the min values
and the maximal of the max values.
Here is the caller graph for this function:

◆ minmaxIndices()

def eidolon.Utils.minmaxIndices (   lst)
Returns the lowest indices of the minimal and maximal values in iterable `lst'.
Here is the caller graph for this function:

◆ minmaxval()

def eidolon.Utils.minmaxval (   minv,
  maxv,
  val 
)
Returns min(val,minv),max(val,maxv) or val,val if either `minv' or `maxv' is None.

◆ mulsum()

def eidolon.Utils.mulsum (   ls,
  rs 
)
Returns the sum of each element of `ls' multiplied by the equivalent element in `rs'.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseSequenceSpec()

def eidolon.Utils.parseSequenceSpec (   spec,
  maxval 
)
Creates a list of integer values based on the sequence string specification. The specifier string `spec' is a
comma-separated list of specifiers, which are either a integer number, an integer range N-M for integers N and M-1
or N-* where * is taken to be `maxval'-1, or an integer range N-S-M or N-S-* where S is the skip interval.
For example: "1,6-8,9-2-14,16-*" yields [1, 6, 7, 9, 11, 13, 16, 17, 18, 19] for a `maxval' of 20. The resulting
list is sorted with duplicates removed.

◆ partitionSequence()

def eidolon.Utils.partitionSequence (   maxval,
  part,
  numparts 
)
Calculate the begin and end indices in the sequence [0,maxval) for partition `part' out of `numparts' total
partitions. This is used to equally divide a sequence of numbers (eg. matrix rows or array indices) so that they
may be assigned to multiple procs/threads. The result `start,end' defines a sequence [start,end) of numbers.
Here is the caller graph for this function:

◆ printCumulativeTimes()

def eidolon.Utils.printCumulativeTimes ( )
Print the cumulative times to the stdout.
Here is the call graph for this function:

◆ printFlush()

def eidolon.Utils.printFlush (   args,
  kwargs 
)
Converts each element of 'args' into a string and prints them to a stream separated by spaces. The same string is
also printed to the log. The keyword argument `end' is used to specify the end string, the default is '\n'. If the
keyword argument `stream' is omitted the string is printed to sys.stdout, otherwise this argument can be used to
supply a different object with write() and flush() methods.
Here is the caller graph for this function:

◆ processExists()

def eidolon.Utils.processExists (   pid)
Returns true if the process identified by `pid' is running and active, false if it doesn't exist or has crashed.
Here is the caller graph for this function:

◆ prod()

def eidolon.Utils.prod (   i,
  initial = 1 
)
Returns the product of the given iterable, starting with the given initial value.
Here is the caller graph for this function:

◆ radCircularConvert()

def eidolon.Utils.radCircularConvert (   rad)
Converts the given rad angle value to the equivalent angle on the interval [-pi,pi].
Here is the caller graph for this function:

◆ radClamp()

def eidolon.Utils.radClamp (   rad)
Clamps the given value between pi*0.5 and pi*-0.5.
Here is the call graph for this function:

◆ readBasicConfig()

def eidolon.Utils.readBasicConfig (   filename,
  evalfunc = ast.literal_eval 
)
Read the config (.ini) file `filename' into a map of name/value pairs. The values must be acceptable inputs to
`evalfunc' which is ast.literal_eval() by default, ie. literals. Using literal_eval is for security since eval() 
on untrusted input can do interesting things.
Here is the caller graph for this function:

◆ renameFile()

def eidolon.Utils.renameFile (   oldpath,
  newname,
  moveFile = True,
  overwriteFile = False 
)
Replace the basename without extension in `oldpath' with `newname' and keeping the old extension. If `moveFile' is
True, copy the old file to the new location and overwrite existing file if `overwriteFile' is True; IOError
is thrown if this isn't possible or if the file exists and `overwriteFile' is False. Setting `moveFile' to False
allows a "dry run" where the checks are performed but the file isn't moved. Returns the new path.
Eg. renameFile('/foo/bar.baz.plonk','thunk') -> '/foo/thunk.baz.plonk'
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rotateIndices()

def eidolon.Utils.rotateIndices (   start,
  numinds 
)
Produces the indices for a list `numinds' long rotated so that index `start' is the new first index.

◆ setLogging()

def eidolon.Utils.setLogging (   logfile = 'eidolon.log',
  filemode = 'a' 
)
Enables logging to the given file (by default same file as the renderer writes to) with the given filemode.
Here is the call graph for this function:

◆ setmethod()

def eidolon.Utils.setmethod (   obj,
  methname = None 
)
Applying this decorator to a routine replaces the method of `obj' with name `methname' (or the name of the applied
routine if this is None) with the routine. 

Eg.:
    x=type('test',(),{}) # test object with no members
    
    @setmethod(x)
    def foo():
        return str(x)
        
    x.foo()
    >>> "<class '__main__.test'>"

◆ setStrIndent()

def eidolon.Utils.setStrIndent (   s,
  indent = 0,
  useTab = False 
)
Remove the indentation from the code string `s' and set the leading indentation to be `indent' number of characters,
spaces if `useTab' is False, tabs otherwise.
Here is the caller graph for this function:

◆ setTrace()

def eidolon.Utils.setTrace ( )
Enables tracing for the calling thread. This behaviour is unreliable and spews to logs or stdout.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sortedInsert()

def eidolon.Utils.sortedInsert (   lst,
  val 
)
Given a sorted list `lst', insert `val' in the first position in `lst' which maintains the ordering.
Here is the call graph for this function:

◆ sortFilenameList()

def eidolon.Utils.sortFilenameList (   names,
  sortIndex,
  regex = None 
)
Sort the list of filenames `names' based on a common numerical component. This assumes the files have a sequential
numbering scheme which may not prefix numbers with zeros and so the alphabetical ordering is not the same as numerical.
This function parses out the numerical component of each name and sorts using these as integer values.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sortIndices()

def eidolon.Utils.sortIndices (   lst)
Returns a list of indices into iterable `lst' which index the members of `lst' in sorted order.
Here is the caller graph for this function:

◆ splitPathExt()

def eidolon.Utils.splitPathExt (   path,
  fullExt = False 
)
For the given path, return the containing directory, filename without extension, and extension. If `fullExt' is
True, consider everything to the right of the first period as the extension rather than from the last. For example,
splitPathExt('foo.bar.baz')[2] produces '.baz' whereas splitPathExt('foo.bar.baz',True)[2] produces '.bar.baz'.
Here is the caller graph for this function:

◆ stddev()

def eidolon.Utils.stddev (   vals,
  initial = 0.0 
)
Returns the standard deviation of the values derived from the iterable `vals', or `initial' if there are fewer than 2.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ storeBasicConfig()

def eidolon.Utils.storeBasicConfig (   filename,
  values 
)
Store the name/value map `values' into file `filename' as a config (.ini) file. The keys of `values' must be
strings and the values must be literal types. All values go into the DEFAULT section of the file.
Here is the caller graph for this function:

◆ successive()

def eidolon.Utils.successive (   iterable,
  width = 2,
  cyclic = False 
)
Yields tuples of `width' values in order from `iterable' starting from the first value, then from the second value,
etc. If `cyclic' is True then `iterable' is treated as a cycle of values and the last `width' tuples will have
values starting from the end of the sequence then looping back to the beginning.
Eg. successive(range(5))        -> (0, 1), (1, 2), (2, 3), (3, 4)
    successive(range(5),3,True) -> (0, 1, 2), (1, 2, 3), (2, 3, 4), (3, 4, 0), (4, 0, 1)
    successive([],2)            -> nil
Here is the caller graph for this function:

◆ taskmethod()

def eidolon.Utils.taskmethod (   meth,
  args,
  kwargs,
  taskLabel = None,
  taskName = 'task',
  mgrName = 'mgr' 
)
Wraps a given method such that it will execute the method's body in a task and store the result in a returned
Future object. This assumes the method's receiver has a member named by `mgrName' which references a TaskQueue
object. This will also add the keywod argument named `taskName' which will refer to the Task object when called.
The string `taskLabel' is used to identify the task, typically in a status bar, ie. the same as in @taskroutine.

For example, the method:

    def meth(self,*args,**kwargs):
        f=Future()
        @taskroutine('msg')
        def _func(task):
            with f:
                f.setObject(doSomething())

        return self.mgr.runTasks(_func(),f)

is equivalent to:

    @taskmethod('msg')
    def meth(self,*args,**kwargs):
        return doSomething()
Here is the caller graph for this function:

◆ taskroutine()

def eidolon.Utils.taskroutine (   func,
  args,
  kwargs,
  taskLabel = None,
  selfName = 'task' 
)
Routine decorator which produces a wrapper function returning a task that will execute the original function when
processedby the task queue. The first argument indicates the name of the variable used to pass the Task instance
to the function call or is None if no passing is wanted. If the task argument is present it must be the last and
when the function is called no value for it must be provided, thus it must have a default value (usually None).
The optional second argument defines whether the task is a threaded one or not (default is False).

◆ timeBackupFile()

def eidolon.Utils.timeBackupFile (   filename,
  backDir = None 
)
Copies `filename' if it exists to the same directory (or `backDir' if not None) with the system time and ".old"
appended to the name. The new base filename is returned if this was done, otherwise None.
Here is the caller graph for this function:

◆ timing()

def eidolon.Utils.timing (   func)
This simple timing function decorator prints to stdout/logfile (it uses printFlush) how many seconds a call to the
original function took to execute, as well as the name before and after the call.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ timingBlock()

def eidolon.Utils.timingBlock (   name,
  printEntry = True,
  addCumulative = False 
)
Provides a timing facility for 'with' code blocks. Argument `name' is printed when entering if `printEntry', and
always printed when exiting. If `addCumulative' is True then add the value to the cumulative time counter.
The yielded value is the starting time of the block.
Here is the call graph for this function:

◆ toIterable()

def eidolon.Utils.toIterable (   obj)
Returns an iterable of objects, which is `obj' if it's not a string and iterable, otherwise (obj,).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tracing()

def eidolon.Utils.tracing (   func)
This decorator prints a stack trace when the wrapped function is called.
Here is the call graph for this function:

◆ trange()

def eidolon.Utils.trange (   vals)
Produces a sequence of cartesian product tuples derived from multiple sequences as defined by the given arguments.
An integer argument 'a' corresponds to  'range(a)', a float argument corresponds to 'frange(a)'. Tuple arguments
are either pairs or triples of ints or floats which correspond to the start,stop,step set of values for range or
frange. If 'a' is otherwise iterable it is used directly to derive values.

Eg. list(trange((0,6,2),(0.0,0.6,0.2))) yields
   [(0, 0.0), (0, 0.2), (0, 0.4), (2, 0.0), (2, 0.2), (2, 0.4), (4, 0.0), (4, 0.2), (4, 0.4)]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ traverseObj()

def eidolon.Utils.traverseObj (   obj,
  func,
  visited = () 
)
Attempt to visit every member of `obj' and every member of members etc. recursively. The callable `func' is applied
to `obj' to determine when to stop traversing, returning False if a stop is requested. The set `visited' is the
recursive accumulated list of visited objects used to prevent cycles.

◆ trylocking()

def eidolon.Utils.trylocking (   func,
  locker = None 
)
Same as 'locking' except it only attempts to acquire the lock without blocking, and does nothing if the acquire fails.
Here is the call graph for this function:

◆ uniqueStr()

def eidolon.Utils.uniqueStr (   name,
  namelist,
  spacer = '_' 
)
Derive a string from `name' guaranteed to not be in `namelist'. If `name' isn't in `namelist', it will be returned
unmodified, otherwise the created name will be `name' followed by `spacer' and a number which makes it unique.
Here is the caller graph for this function:

◆ unitWave2RGB()

def eidolon.Utils.unitWave2RGB (   vis_range)
Returns the colour value corresponding to the position in the visible spectrum designated by the unit value
'vis_range'. If vis_range==0.0 then the colour is equivalent to 380nm, if vis_range==1.0 the colour is 780nm.
Here is the call graph for this function:

◆ wave2RGB()

def eidolon.Utils.wave2RGB (   wavelength)
Converts a wavelength value between 380nm and 780nm into a RGB color tuple. Requires 380 <= wavelength <= 780.
Here is the caller graph for this function:

◆ wrapper()

def eidolon.Utils.wrapper (   func)
This decorator is applied to functions to simplify the definitions of decorators. A function this is applied to
becomes a decorator itself. Its first three arguments must be the function to wrap, the list of positional arguments,
and the dictionary of keyword arguments. The remaining arguments are those provided by the decorator call itself.
The body of the function is responsible for replacing or augmenting the behaviour of the provided function just like
any other decorator. This results in a decorator function which expects the arguments after the first three to be
provided, and so must always be called with (), but which doesn't require the definition of nested functions.

For example, the following decorator prints the function and a message provided through the decorator before calling
the wrapped function and returning the result:

    @wrapper
    def printdeco(func,args,kwargs,msg='No Message'):
        print('Calling',func,msg)
        return func(*args,**kwargs)

This is equivalent to:

    def printdeco(msg='No Message'):
        def _outer(func):
            @wraps(func)
            def _wrapper(*args,**kwargs):
                print('Calling',func,msg)
                return func(*args,**kwargs)

This is used as such:

    @printdeco('Ni!')
    def spam(x):
        print('Spam and',x)

Calling this function with "Eggs" as the argument prints the following:

    Calling <function tostr at 0x7f91d747a1b8> Ni!
    Spam and Eggs
    
The null wrapper decorator which simply calls the function with the given arguments is:
    
    @wrapper
    def null(func,args,kwargs):
        return func(*args,**kwargs)

◆ xisToPiecewiseXis()

def eidolon.Utils.xisToPiecewiseXis (   xis,
  dims,
  limits = None 
)
Given a set of xi values `xis' and assuming a piecewise basis function on an grid of control points with dimensions
`dim', calculate the xi values for the local element to apply to the basis function, and the indices for the control
point of that element at xi=0. The unit values in `xis' represent a position in the xi space covering the whole
object defined by the control point grid, the resuting xi values represent the equivalent position within one element
within this control point grid. The returned indices denote which control point in the grid is this element's control
point at the xi space origin. The xi coordinates of the other control points are assumed to be integers, so one can
figure out what the other control point indices in the grid are by adding the element's control point xis to this
index. The list `limits' must contain pairs of integers for each dimension of `dims' and state how many indices
from the edges/faces of the grid are control points. If `limits' is None the the value [(1,1)]*len(dims) is used which
implies that the first and last values in the grid in every dimension are control points.
Here is the caller graph for this function:

◆ zipWith()

def eidolon.Utils.zipWith (   op,
  vals 
)
Starmap `op' to each tuple derived from zipping the iterables in `vals'.
Here is the caller graph for this function:

Variable Documentation

◆ ConfVars

ConfVars

◆ cumulativeTimes

cumulativeTimes

◆ desc

string desc = 'Variables in the Config object loaded from config files, these should be present and keyed to platformID group'

◆ doc

string doc = 'Types of parameters the ParamDef class can represent.',

◆ epsilon

epsilon

◆ EventType

EventType

◆ halfpi

halfpi

◆ isDarwin

isDarwin

◆ isLinux

isLinux

◆ isWindows

isWindows

◆ logFilename

logFilename

◆ ParamType

ParamType

◆ py3

py3

◆ valtype

tuple valtype = (str,)