Skip to content

Commit

Permalink
Merge pull request #3 from greole/0.6.1
Browse files Browse the repository at this point in the history
0.6.1
  • Loading branch information
greole committed Feb 26, 2015
2 parents 7c6b160 + 4ae4a9e commit b5e7f48
Show file tree
Hide file tree
Showing 10 changed files with 588 additions and 299 deletions.
281 changes: 78 additions & 203 deletions Owls/frames.py → Owls/FoamFrame.py

Large diffs are not rendered by default.

108 changes: 108 additions & 0 deletions Owls/MultiFrame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
from collections import OrderedDict
import plot

class MultiFrame():
""" Class for storage of multiple case items
or faceted data from FoamFrame
"""
#TODO: implememt multi-facetting
# e.g. (cases.by_index('Loc') <- returns a MultiFrame
# .by_case(overlay=True) <- MultiFrame method
# .show('T')
#TODO: implement __repr__ method
def __init__(self, cases=None):
if type(cases) == list:
self.cases = OrderedDict([(case.name,case) for case in cases])
elif type(cases) == OrderedDict:
self.cases=cases
else:
self.cases={}

def __getitem__(self, field):
return [serie[field] for serie in self.cases.itervalues()]

def names(self):
return [name for name in self.cases]

def select(self, case):
""" select a specific item """
return self.cases[case]

def filter(self, selector):
""" select a specific item """
if type(selector) == list:
return MultiFrame({name:case for name,case in self.cases if
name in selector})
else:
return MultiFrame({name:case for name,case in self.cases if
func(name)})

def iteritems(self):
for name,case in self.cases.iteritems():
yield name,case

def by(self, overlay=True):
"""
recursiv grouping function
Examples:
mi.by(overlay=True) -> { cat1_1:{cat2_1:FoamFrame1,
cat2_2:FoamFrame2,
... }
cat1_2:{cat2_1:FoamFrame3,
... }
}
m1.by(overlay=False) -> { (cat1_1,cat2_1): FoamFrame1,
(cat1_1,cat2_2): FoamFrame2,
...
}
needs .show() to check if self.data is recursive
"""
pass

def scatter(self, y, x='Pos', z=False, overlay=False, **kwargs):
import bokeh.plotting as bk
return self._draw(x, y, z=z, overlay=overlay,
inst_func="scatter", **kwargs)

def plot(self, y, x='Pos', z=False, overlay=False, **kwargs):
return self._draw(x, y, z=z, overlay=overlay,
inst_func="plot", **kwargs)

def show(self, y, x='Pos', z=False, overlay=False, **kwargs):
return self._draw(x, y, z=z, overlay=overlay,
inst_func="show", **kwargs)

def _draw(self, x, y, z, overlay, inst_func, **kwargs):
import bokeh.plotting as bk
import numpy as np
def greatest_divisor(number):
if number == 1:
return 1
for i in reversed(range(number)):
if number % i == 0:
return i
else:
return 1

if not overlay:
rows=[]
for name, instance in self.cases.iteritems():
bk.figure()
rows.append(
getattr(instance, inst_func)
(x=x, y=y, title=str(name), **kwargs) #FIXME num cars
)
rows = np.array(rows).reshape(greatest_divisor(len(rows)),-1).tolist()
return bk.GridPlot(children=rows, title="Scatter")
else:
bk.hold()
colors = plot.next_color()
for name, instance in self.cases.iteritems():
color = next(colors)
getattr(instance, inst_func)(x=x, y=y, title="", color=color, legend=name, **kwargs)
bk.hold(False)
return bk.curplot()
4 changes: 3 additions & 1 deletion Owls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from .version import __version__
from io import *
from plot import *
from frames import *
from foam import *
from FoamFrame import *
from MultiFrame import *

print "Owls Version: " + __version__
58 changes: 58 additions & 0 deletions Owls/foam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""
Launchers for openfoam utilities
"""
import os
import subprocess

def execute(cmd):
return subprocess.check_call(cmd, shell=True) == 0

def execute_in_path(path, cmd, func=execute):
print(os.getcwd())
old_dir = os.getcwd()
os.chdir(path)
try:
ret = func(cmd)
except:
ret = False
os.chdir(old_dir)
return ret

class genericHook(object):

def __init__(self, path, cmd):
self.path = path
self.cmd = cmd

def execute(self):
return execute_in_path(self.path, self.cmd)

class cellCentres(genericHook):

def __init__(self, path):
genericHook.__init__(self, path, "writeCellCentres")

class decompose(genericHook):

def __init__(self, path, latest=False):
cmd = "decomposePar"
if latest:
cmd += " -latestTime"
genericHook.__init__(self, path, cmd)

class reconstruct(genericHook):

def __init__(self, path, latest=False):
cmd = "reconstructPar"
if latest:
cmd += " -latestTime"
genericHook.__init__(self, path, cmd)

class sample(genericHook):

def __init__(self, path, latest=False):
cmd = "sample"
if latest:
cmd += " -latestTime"
genericHook.__init__(self, path, cmd)
Loading

0 comments on commit b5e7f48

Please sign in to comment.