Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 6 commits into from
May 25, 2016
Merged

Choldgraf optimize trisurf #481

merged 6 commits into from
May 25, 2016

Conversation

Kully
Copy link
Contributor

@Kully Kully commented May 25, 2016

@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.

@@ -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):
Copy link
Contributor

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,
Copy link
Contributor

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?

@Kully
Copy link
Contributor Author

Kully commented May 25, 2016

@theengineear

@Kully
Copy link
Contributor Author

Kully commented May 25, 2016

@choldgraf

Sounds all good. I can fix this all up now.
Did you push anything just now? I'm wondering why the tests are running after they looked finished.

@choldgraf
Copy link
Contributor

I haven't (and won't) push anything now that this PR is up and running!

@theengineear
Copy link
Contributor

@Kully , GH seems to think you made different pushes.

image

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 master whenever.

Thanks for all the help @choldgraf!

@Kully
Copy link
Contributor Author

Kully commented May 25, 2016

Not sure if that's the case or not.

I actually changed version.py once and tried to push but got an error, so I changed it back and tried again with success.

@choldgraf
Copy link
Contributor

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.

@choldgraf
Copy link
Contributor

ps @theengineear where are those stacks in your profile picture? Reminds me of when I was a radio DJ back in college :D

@Kully Kully merged commit a8f905b into master May 25, 2016
@Kully Kully deleted the choldgraf-optimize_trisurf branch May 25, 2016 16:40
@choldgraf
Copy link
Contributor

ack crap - I missed one thing. I just noticed that the create_trisurf function still doesn't have a plot_edges argument. We should add that in and then pass it in the call to _trisurf. I can make a PR but it's a pretty simple fix if someone wants to just edit master.

@Kully
Copy link
Contributor Author

Kully commented May 25, 2016

ack crap - I missed one thing. I just noticed that the create_trisurf function still doesn't have a plot_edges argument. We should add that in and then pass it in the call to _trisurf. I can make a PR but it's a pretty simple fix if someone wants to just edit master.

I can do now. Besides, I forgot to switch dist_func to color_func ;)

@choldgraf
Copy link
Contributor

ok cool :) I swear PRs are like emails...every time I send one off I have an "oh shoot I missed XXX" moment

@choldgraf
Copy link
Contributor

A couple other random things:

  1. The plot_edges argument should default to False IMO, not None, since it's a bool
  2. We should let the user specify an array/list of rgb colors instead of color_func, in case they've got pre-computed colors (e.g., activation patterns relative to certain electrodes). Maybe just a quick isinstance(color_func, (np.ndarray, list)) then a check to make sure it's full of rgb strings. Or is that for another PR?

@Kully
Copy link
Contributor Author

Kully commented May 25, 2016

The plot_edges argument should default to False IMO, not None, since it's a bool

Okay, easy.

We should let the user specify an array/list of rgb colors instead of color_func, in case they've got pre-computed colors (e.g., activation patterns relative to certain electrodes). Maybe just a quick isinstance(color_func, (np.ndarray, list)) then a check to make sure it's full of rgb strings. Or is that for another PR?

You want both functionalities right? I think I can do this in the same PR.

@choldgraf
Copy link
Contributor

choldgraf commented May 25, 2016

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 simplices. Something like:

        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 1536

@choldgraf
Copy link
Contributor

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:

mean_dists = colors(tri_vertices)

@choldgraf
Copy link
Contributor

(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)

@Kully
Copy link
Contributor Author

Kully commented May 25, 2016

(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: mean_dists = colors(tri_vertices)

Is colors supposed to be the colors_func?

@choldgraf
Copy link
Contributor

ah yeah, sorry...locally I've been just calling it colors since it is allowed to be a list or array.

@choldgraf
Copy link
Contributor

Been spending the morning writing some activity functions too, so when the lighting is fixed it should look relatively purdy:

image

@choldgraf choldgraf mentioned this pull request May 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants