-
Notifications
You must be signed in to change notification settings - Fork 37
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
Basic visualization utilities #29
Conversation
Here's an example with an event picker:
By the way, this is why |
…aw them, as individual lines or line collections, and re-implement the top-level get_leaves accordingly. Also changed the definition of height to match @ChrisBeaumont's definition and removed merge_level.
@ChrisBeaumont - what do you think of something along the lines of the current code? Each structure has a method that allows me to get the list of leaves sorted by some criterion (and taking into account hierarchy). This is then used by
Here's an example of a simple viz with line picking:
Lots of hard-coded stuff for now, this is just to show how the simplistic line_picker works. It's kind of slow, but I want to get it working first, then figure out the bottleneck. One issue for now that Structure.get_lines requires a |
Will be writing up the simple visualizer as a class now to avoid the use of |
I've written up a visualization class here: https://gist.github.com/astrofrog/5831143 It's very simple for now and quite slow, but is this the type of basic visualization we want? Where should it live in the package? I will be adding the option to click in the image and highlight the dendrogram. I also wonder whether it would be more efficient to plot the tree as a LineCollection and figure out ourselves which structure was intersected (rather than plot potentially hundreds or thousands of Another issue - the picker doesn't pick just the closest artist, it picks all the artists within a certain radius and cycles through them, which we don't want. |
It turns out if one uses a LineCollection, |
This screenshot looks good! Something like this will be very useful for mapping dendrogram ids to image features. A few comments;
|
I havent digested it yet, but If not, can we at least split this up into easier subroutines? One easy change is to separate the logic that generates structure x/y vertices with the logic that packs them into MPL artists. |
@ChrisBeaumont - thanks for all the suggestions - I'll try and address them all today or tomorrow. I've managed to get a version working locally which only uses LineCollection, so I think I can already simplify some of the code in |
…t easy to cache the positions of all the leaves for plotting purposes.
@ChrisBeaumont - well, I guess you were right, it's much easier if I put all the plotting stuff in a dedicated class ;) If you try out this version of the branch with
it should look correct - let me know if not! By the way, you can now already click in the image and highlight the dendrogram. I'm working on the remaining features. |
Regarding performance, it turns out that simply instantiating |
3-d slicing and sliders for the stretch are now done! |
By the way, the tests are failing because of the new definition of |
|
||
from matplotlib.widgets import Slider | ||
|
||
self._clim = array.min(), array.max() |
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.
Change these to np.nanmin
and np.nanmax
, so the Slider's don't break with NANs
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'm actually going to write a custom function as we also need to exclude inf
|
||
plt.show() | ||
|
||
def update_slice(self, pos=None): |
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.
If a dendrogram structure is selected, update_slice should also redraw the contour
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.
Fixed
This looks great! I left some minor comments inline; otherwise, this is ready to merge |
return "<Structure type=branch idx={0}>".format(self.idx) | ||
|
||
def get_sorted_leaves(self, sort_key=lambda s: s.get_peak(subtree=True)[1], reverse=False, subtree=False): | ||
if self.is_leaf: |
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.
docstring
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.
Fixed
@ChrisBeaumont - I've now also updates the tests to reflect the new definition of height. I'm wondering whether we should rename it to prevent confusion for anyone who's used that variable before since it changes quite dramatically now? |
I'm not sure what to do about height, since I don't know how many people used the old code enough to be confused by a new definition. Furthermore, this definition is what was used in the IDL code. I say we use whatever name makes most sense, and not sacrifice clarity for backwards compatibility |
@ChrisBeaumont - once Travis passes, is this good to go? I opened #32 to remind us to create a section in the docs for people who've used previous versions of |
👍 |
Basic visualization utilities
This pull request implements basic visualization-related methods for Dendrogam. The first method is a sorting method that will sort the tree according to a key function, which by default is set to the peak flux of the substructure (including subtree). The other method is one that returns a list of lines, including a mapping from line objects to structures. With this in place, it's already possible to make simple plots:
The reason for returning the 'mapping' is that one can then set the picker attribute on the line objects to enable matplotlib object picking. Once this is done, we need the event handling function to access the structure for a given line. We might also need an inverse mapping since one may want to find e.g. all the lines belonging to the subtree of a structure. This would be easy too add.
Ultimately, we want
Dendrogram
to have aplot
method, but I decided to start with these as a first step.@ChrisBeaumont - what do you think of this so far?