Skip to content

Commit

Permalink
Small optimizations to trimesh pd_mesh utility
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored and jbednar committed Jan 17, 2018
1 parent a14a61d commit 049f385
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions datashader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def dataframe_from_multiple_sequences(x_values, y_values):
# Return a dataframe with this new set of x and y values
return pd.DataFrame({'x': x, 'y': y.flatten()})


def _pd_mesh(vertices, simplices):
"""Helper for ``datashader.utils.mesh()``. Both arguments are assumed to be
Pandas DataFrame objects.
Expand All @@ -396,8 +396,10 @@ def _pd_mesh(vertices, simplices):
winding = [0, 2, 1]

# Construct mesh by indexing into vertices with simplex indices
vertex_idxs = simplices.values[:, winding].astype(np.int64)
vals = vertices.values[vertex_idxs]
vertex_idxs = simplices.values[:, winding]
if not vertex_idxs.dtype == 'int64':
vertex_idxs = vertex_idxs.astype(np.int64)
vals = np.take(vertices.values, vertex_idxs, axis=0)
vals = vals.reshape(np.prod(vals.shape[:2]), vals.shape[2])
res = pd.DataFrame(vals, columns=vertices.columns)

Expand Down

0 comments on commit 049f385

Please sign in to comment.