-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from greole/0.6.1
0.6.1
- Loading branch information
Showing
10 changed files
with
588 additions
and
299 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.