From 8cd1f027b303b9ca7ff8c8e03bcbcbdc04b2e167 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 21 Mar 2016 08:51:56 -0400 Subject: [PATCH] bug fixing. --- lib/damask/asciitable.py | 3 +-- lib/damask/util.py | 38 ++++++++++++++++++++------------------ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/damask/asciitable.py b/lib/damask/asciitable.py index 62d38e4dd..f76cf6627 100644 --- a/lib/damask/asciitable.py +++ b/lib/damask/asciitable.py @@ -540,5 +540,4 @@ class ASCIItable(): microstructure[i:i+s] = items[:s] i += len(items) - return (microstructure, i == N and not self.data_read() if strict # check for proper point count and end of file - else microstructure) + return (microstructure, i == N and not self.data_read()) if strict else microstructure # check for proper point count and end of file diff --git a/lib/damask/util.py b/lib/damask/util.py index c64a8cd00..244aaa25c 100644 --- a/lib/damask/util.py +++ b/lib/damask/util.py @@ -58,6 +58,24 @@ def emph(what): """emphasizes string on screen""" return bcolors.BOLD+srepr(what)+bcolors.ENDC +# ----------------------------- +def execute(cmd, + streamIn = None, + wd = './'): + """executes a command in given directory and returns stdout and stderr for optional stdin""" + initialPath = os.getcwd() + os.chdir(wd) + process = subprocess.Popen(shlex.split(cmd), + stdout = subprocess.PIPE, + stderr = subprocess.PIPE, + stdin = subprocess.PIPE) + out,error = [i.replace("\x08","") for i in (process.communicate() if streamIn is None + else process.communicate(streamIn.read()))] + os.chdir(initialPath) + if process.returncode != 0: raise RuntimeError('{} failed with returncode {}'.format(cmd,process.returncode)) + return out,error + + # ----------------------------- # Matlab like trigonometric functions that take and return angles in degrees. # ----------------------------- @@ -75,7 +93,7 @@ def gridLocation(idx,res): # ----------------------------- def gridIndex(location,res): - return ( location[0] % res[0] + \ + return ( location[0] % res[0] + \ ( location[1] % res[1]) * res[0] + \ ( location[2] % res[2]) * res[1] * res[0] ) @@ -432,20 +450,4 @@ def curve_fit_bound(f, xdata, ydata, p0=None, sigma=None, bounds=None, **kw): else: pcov = np.inf - return popt, pcov, infodict, errmsg, ier if return_full else popt, pcov - - -def execute(cmd,streamIn = None,wd = './'): - """executes a command in given directory and returns stdout and stderr for optional stdin""" - initialPath = os.getcwd() - os.chdir(wd) - process = subprocess.Popen(shlex.split(cmd), - stdout = subprocess.PIPE, - stderr = subprocess.PIPE, - stdin = subprocess.PIPE) - out,error = [i.replace("\x08","") for i in (process.communicate if streamIn is None - else process.communicate(streamIn.read()))] - os.chdir(initialPath) - if process.returncode != 0: raise RuntimeError('{} failed with returncode {}'.format(cmd,process.returncode)) - return out,error - + return (popt, pcov, infodict, errmsg, ier) if return_full else (popt, pcov)