Commit e588f303 authored by Daniel Boeckenhoff's avatar Daniel Boeckenhoff
Browse files

examples and performance tests added

parent 075f21ab
make/python/Makefile
\ No newline at end of file
import tfields
import numpy as np
t = tfields.TensorFields([[0.3, 0.3]], [[1, 2]])
# Rotation matrix by 3/4 pi
r = tfields.Tensors([[[-1., +1.],
[-1., -1.]]]) / np.sqrt(2)
t_rotated = np.dot(t, r)
print(t_rotated, t_rotated.fields[0])
Subproject commit 11b3077255a934533eca0c1e681cb7220b8afe99
Subproject commit c603498c3d12fb386cfee0a8976517891dca17d0
import loggingTools
import tfields
import numpy as np
import cPickle as pickle
with tfields.lib.log.timeit("Building Grid"):
mesh = tfields.Mesh3D.grid((0, 1, 10), (2, 1, 10), (2, 3, 20))
# mesh = tfields.Mesh3D.grid((0, 1, 50), (2, 1, 20), (2, 3, 50))
print mesh.nfaces()
with open(tfields.lib.in_out.resolve('~/tmp/node.pickle'), 'r') as f:
tree = pickle.load(f)
# with tfields.lib.log.timeit("SEARCHING TREE OFFSET"):
# # tree = tfields.bounding_box.Searcher(mesh, n_sections=[2, 1, 2])
tree = tfields.bounding_box.Searcher(mesh)
points = tfields.Tensors([[0.5, 1, 2.1],
[0.5, 0, 0],
[0.5, 2, 2]])
with tfields.lib.log.timeit("SEARCHING TREE METHOD"):
box_res = tree.in_faces(points, delta=0.0001)
with tfields.lib.log.timeit("STANDARD METHOD"):
usual_res = mesh.in_faces(points, delta=0.0001)
assert np.array_equal(box_res, usual_res)
with open(tfields.lib.in_out.resolve('~/tmp/node.pickle'), 'w') as f:
pickle.dump(tree, f)
......@@ -17,7 +17,7 @@ __all__ = [
"__classifiers__",
]
__version__ = '0.1.0.dev12'
__version__ = '0.1.1'
__title__ = os.path.basename(os.path.abspath('.'))
__summary__ = "numpy + sympy implementation of tensor fields with attached coordinate systems"
__keywords__ = "tensors coordinate system trafo sympy numpy"
......
......@@ -154,7 +154,7 @@ class AbstractNdarray(np.ndarray):
def __setstate__(self, state):
"""
important for unpickling
Counterpart to __reduce__. Important for unpickling.
"""
# Call the parent's __setstate__ with the other tuple elements.
super(AbstractNdarray, self).__setstate__(state[0:-len(self._iter_slots())])
......
......@@ -15,6 +15,7 @@ import mpl_toolkits.mplot3d as plt3D
from mpl_toolkits.axes_grid1 import make_axes_locatable
import matplotlib.dates as dates
from itertools import cycle
from functools import partial
import logging
......@@ -654,9 +655,60 @@ def set_legend(axis, artists, **kwargs):
return axis.legend(handles=handles, **kwargs)
class set_zoomable(object):
"""
Left click a colorbar and release in order to zoom.
Upper and lower 5% of the colorbar will zoom out.
"""
def __init__(self, cbar):
self._cbar = cbar
self._v_press = None
self._v_release = None
artist = self._cbar.mappable
self._press_connection_id = artist.axes.figure.canvas.mpl_connect(
'button_press_event',
partial(self.on_press))
self._release_connection_id = artist.axes.figure.canvas.mpl_connect(
'button_release_event',
partial(self.on_release))
def on_press(self, event):
if event.inaxes is self._cbar.ax:
self._v_press = event.ydata
def on_release(self, event):
if event.inaxes is self._cbar.ax:
self._v_release = event.ydata
self.update_v_min_max()
def update_v_min_max(self):
# sort press and release event
if self._v_press > self._v_release:
x_up = self._v_press
x_low = self._v_release
if self._v_press < self._v_release:
x_up = self._v_release
x_low = self._v_press
# zoom out if in 5% margin
if x_up > 0.95:
x_up = 1.5
if x_low < 0.05:
x_low = -0.5
artist = self._cbar.mappable
vmin, vmax = artist.get_clim()
v_range = vmax - vmin
vmax = vmin + x_up * v_range
vmin = vmin + x_low * v_range
artist.set_clim(vmin, vmax)
artist.axes.figure.canvas.draw()
def set_colorbar(axis, artist, label=None, divide=True,
position='right', size="2%", pad=0.05,
labelpad = None,
labelpad = None, zoom=False,
**kwargs):
"""
Note:
......@@ -703,6 +755,10 @@ def set_colorbar(axis, artist, label=None, divide=True,
label = art_label
if label is not None:
cbar.set_label(label, rotation=rotation, labelpad=labelpad)
if zoom:
set_zoomable(cbar)
return cbar
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment