Skip to content

Commit

Permalink
py3 bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
François Laurent committed Feb 27, 2018
1 parent 9fe2b37 commit 20de488
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions tramway/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

from warnings import filterwarnings
filterwarnings('ignore', category=FutureWarning, module='h5py', lineno=36)
from . import core
from . import tessellation
from . import inference
Expand Down
6 changes: 5 additions & 1 deletion tramway/core/scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,11 @@ def scale_size(self, size, dim=None, inplace=True, _unscale=False):
dim = _dim
if _dim < min(1, dim):
raise ValueError('not enough euclidean dimensions')
factor = self.factor[self.euclidean[0]]
try:
factor = self.factor[self.euclidean[0]]
except KeyError: # Py3 bugfix on loading Py2-generated rwa files
self.euclidean = [ name.decode('utf-8') for name in self.euclidean ]
factor = self.factor[self.euclidean[0]]
if self.euclidean[1:] and not np.all(self.factor[self.euclidean[1:]] == factor):
raise ValueError('the scaling factors for the euclidean variables are not all equal')
if not inplace:
Expand Down
15 changes: 13 additions & 2 deletions tramway/feature/curl.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self, cells=None, map=None):
self._variables = None
self._cells = None
self._map = None
self._map_index = None
self._cell_centers = None
self._cell_adjacency = None
self._dilation_adjacency = None
Expand All @@ -46,6 +47,7 @@ def map(self, m):
self._map = m
if self._map is not None:
self._variables = None
self._map_index = None

@property
def variables(self):
Expand Down Expand Up @@ -117,11 +119,20 @@ def local_curl(self, variable, cell, distance):
return self.curl_integral(v, cs, ws)

def curl_integral(self, variable, contour, inner):
field = self.field(variable, contour)
tangent = self.tangent(contour)
area = self.surface_area(contour, inner)
if np.isclose(area, 0.):
return 0.
ok = np.array([ c in self.map_index for c in contour ])
field = self.field(variable, np.asarray(contour)[ok])
tangent = np.asarray(self.tangent(contour))[ok]
return np.sum(field * tangent) / area

@property
def map_index(self):
if self._map_index is None:
self._map_index = set(self.map.index)
return self._map_index

def field(self, v, cs):
return self.map.loc[cs, self.variables[v]].values

Expand Down

0 comments on commit 20de488

Please sign in to comment.