-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Choldgraf optimize trisurf #481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -753,6 +753,17 @@ def test_trisurf_all_args(self): | |||
self.assert_dict_equal(test_trisurf_plot['data'][1], | |||
exp_trisurf_plot['data'][1]) | |||
|
|||
def test_optimize_trisurf(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take it you'd like to do this in a later PR?
facecolor = ([FigureFactory._map_z2color(zz, colormap, min_mean_dists, | ||
max_mean_dists) for zz in mean_dists]) | ||
ii, jj, kk = FigureFactory._tri_indices(simplices) | ||
facecolor = FigureFactory._map_z2color(mean_dists, colormap, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be the way that trisurf defines color of the faces, no? It looks here like it will expect dist_func
to be callable on an x, y, z
tuple, so don't we want to support someone giving an array of shape (n_triangles,) that just has rgb strings in it? Alternatively, if it's relatively easy to change the colors after the data has been created, maybe it's better to have a different high level function that changes them post-hoc, so that we don't re-do the triangle computations each time the colors change. In either case, I'd vote for a different variable name than dist_func
...maybe color_func
or just colors
, and then explain in the docs that it could be a function. WDYT?
Sounds all good. I can fix this all up now. |
I haven't (and won't) push anything now that this PR is up and running! |
@Kully , GH seems to think you made different pushes. Not sure if that's the case or not. At any rate. I'll leave it to @Kully to fix-up/discuss as necessary. As long as tests are passing, This can 💃 into Thanks for all the help @choldgraf! |
I actually changed version.py once and tried to push but got an error, so I changed it back and tried again with success. |
thanks for the help as well! I imagine that we'll need to make tweaks here and there, and can open (hopefully tiny) PRs as necessary. @jackparmer any idea on whether the time to first plot can be improved on the JS side? Also, once we get this working I can write some high-level functions to calculate facecolors based on neural activation and write a blog post of some sort if it's useful. |
ps @theengineear where are those stacks in your profile picture? Reminds me of when I was a radio DJ back in college :D |
ack crap - I missed one thing. I just noticed that the |
I can do now. Besides, I forgot to switch dist_func to color_func ;) |
ok cool :) I swear PRs are like emails...every time I send one off I have an "oh shoot I missed XXX" moment |
A couple other random things:
|
Okay, easy.
You want both functionalities right? I think I can do this in the same PR. |
Yeah I think it should be "check if the input is a list / array. if yes, then assert that it's the same length as if colors is None:
# mean values of z-coordinates of triangle vertices
mean_dists = tri_vertices[:, :, 2].mean(-1)
elif isinstance(colors, (list, np.ndarray)):
if len(color_func) != len(simplices):
raise ValueError('If colors is array-like, '
'it must be the same length as simplices')
mean_dists = color_func
else:
# apply user inputted function to calculate
# custom coloring for triangle vertices
mean_dists = []
for triangle in tri_vertices:
dists = []
for vertex in triangle:
dist = colors(vertex[0], vertex[1], vertex[2])
dists.append(dist)
mean_dists.append(np.mean(dists)) around line |
Though note that we'll probably lose all the benefits of the optimization if someone gives a function, since it's a looping and appending to lists. It'd be faster to expect a function that takes an (n x 3) array and returns an array of shape (n,). That way the user could decide to optimize the function however they like. So you could just collapse that code to:
|
(but I think that might be worth a different PR if it seems like people are often using that functionality...my guess is that people would often pre-compute their colors) |
Fair enough. Yes, let's make it a separate PR then. I was a little confused by your penultimate message: Is colors supposed to be the colors_func? |
ah yeah, sorry...locally I've been just calling it |
@theengineear @jackparmer @choldgraf @yankev
I made a new branch off of my duplicate of choldgraf:optimize_trisurf
Modified the main test for trisurf and hopefully will pass on circle. They passed locally for my on both Python 2 and 3.