RangeSelection on image data?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

RangeSelection on image data?

Michael Sarahan
Hi everyone,

Is there a way to apply the RangeSelection tool to image plots?

I have spectral data that is either 2D (a stack of spectra) or 3D (a
2D array of spectra, with the spectral dimension being the 3rd).  I am
building a viewer, and would like to provide a spectrum selection tool
to the user.  For the 2D case, a RangeSelection tool would allow the
user to select any number of spectra, which would be summed, and the
sum displayed on another plot.  For the 3D case, users can use a lasso
tool to pick pixels from the 2D array (like a top-down view).

I am trying this using the code below.  I think the mapper for the
image plot is not agreeing with what the RangeSelection tool expects.
What happens using the code below is that the plot loads fine, but
right-clicking on the plot to activate the range selection yields a
traceback, ending in:

C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\tools\range_selection.pyc in n
ormal_right_down(self, event)
    401         """
    402         pos = self._get_axis_coord(event)
--> 403         mapped_pos = self.mapper.map_data(pos)
    404         self.selection = (mapped_pos, mapped_pos)
    405         self._set_sizing_cursor(event)

C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\grid_mapper.pyc in map_data(se
lf, screen_pts)
    118         Maps values from screen space into data space.
    119         """
--> 120         screen_xs, screen_ys = transpose(screen_pts)
    121         xs = self._xmapper.map_data(screen_xs)
    122         ys = self._ymapper.map_data(screen_ys)

TypeError: 'numpy.float64' object is not iterable


Can anyone suggest how to get these in agreement?  Any tips much appreciated.
-Mike



Code below
-----------------------------------------
TypeError: 'numpy.float64' object is not iterable

    def render_image(self):
        d=self.img_plotdata.get_data('imagedata')
        plot = Plot(self.img_plotdata,default_origin="top left")
        img=plot.img_plot("imagedata", colormap=gray)[0]
        plot.aspect_ratio=float(d.shape[1])/float(d.shape[0])

        if len(self.sig.data.shape)==2:
            csr = RangeSelection(component=img)
            csr_overlay=RangeSelectionOverlay(component=img,alpha=0.8)
        if len(self.sig.data.shape)==3:
            csr = LassoSelection(component=img)
            csr.on_trait_change(lasso_updated, "disjoint_selections")
            csr_overlay=LassoOverlay(lasso_selection = csr, component=img)
        img.tools.append(csr)
        img.overlays.append(csr_overlay)
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: RangeSelection on image data?

John Wiggins
Hello Mike,

This is possible if you use the RangeSelection2D tool.
Using your example:

from chaco.layers.svg_range_selection_overlay import SvgRangeSelectionOverlay

def render_image(self):
       d=self.img_plotdata.get_data('imagedata')
       plot = Plot(self.img_plotdata,default_origin="top left")
       img=plot.img_plot("imagedata", colormap=gray)[0]
       plot.aspect_ratio=float(d.shape[1])/float(d.shape[0])

       if len(self.sig.data.shape)==2:
           csr = RangeSelection2D(component=img)
           csr_overlay = SvgRangeSelectionOverlay(component=img, alpha=1)
       if len(self.sig.data.shape)==3:
           csr = LassoSelection(component=img)
           csr.on_trait_change(lasso_updated, "disjoint_selections")
           csr_overlay=LassoOverlay(lasso_selection = csr, component=img)
       img.tools.append(csr)
       img.overlays.append(csr_overlay)

As you can see, it should just be as simple as replacing
RangeSelection with RangeSelection2D and RangeSelectionOverlay with
SvgRangeSelectionOverlay.

- John

On Mon, Sep 19, 2011 at 9:18 AM, Michael Sarahan <[hidden email]> wrote:

> Hi everyone,
>
> Is there a way to apply the RangeSelection tool to image plots?
>
> I have spectral data that is either 2D (a stack of spectra) or 3D (a
> 2D array of spectra, with the spectral dimension being the 3rd).  I am
> building a viewer, and would like to provide a spectrum selection tool
> to the user.  For the 2D case, a RangeSelection tool would allow the
> user to select any number of spectra, which would be summed, and the
> sum displayed on another plot.  For the 3D case, users can use a lasso
> tool to pick pixels from the 2D array (like a top-down view).
>
> I am trying this using the code below.  I think the mapper for the
> image plot is not agreeing with what the RangeSelection tool expects.
> What happens using the code below is that the plot loads fine, but
> right-clicking on the plot to activate the range selection yields a
> traceback, ending in:
>
> C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\tools\range_selection.pyc in n
> ormal_right_down(self, event)
>    401         """
>    402         pos = self._get_axis_coord(event)
> --> 403         mapped_pos = self.mapper.map_data(pos)
>    404         self.selection = (mapped_pos, mapped_pos)
>    405         self._set_sizing_cursor(event)
>
> C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\grid_mapper.pyc in map_data(se
> lf, screen_pts)
>    118         Maps values from screen space into data space.
>    119         """
> --> 120         screen_xs, screen_ys = transpose(screen_pts)
>    121         xs = self._xmapper.map_data(screen_xs)
>    122         ys = self._ymapper.map_data(screen_ys)
>
> TypeError: 'numpy.float64' object is not iterable
>
>
> Can anyone suggest how to get these in agreement?  Any tips much appreciated.
> -Mike
>
>
>
> Code below
> -----------------------------------------
> TypeError: 'numpy.float64' object is not iterable
>
>    def render_image(self):
>        d=self.img_plotdata.get_data('imagedata')
>        plot = Plot(self.img_plotdata,default_origin="top left")
>        img=plot.img_plot("imagedata", colormap=gray)[0]
>        plot.aspect_ratio=float(d.shape[1])/float(d.shape[0])
>
>        if len(self.sig.data.shape)==2:
>            csr = RangeSelection(component=img)
>            csr_overlay=RangeSelectionOverlay(component=img,alpha=0.8)
>        if len(self.sig.data.shape)==3:
>            csr = LassoSelection(component=img)
>            csr.on_trait_change(lasso_updated, "disjoint_selections")
>            csr_overlay=LassoOverlay(lasso_selection = csr, component=img)
>        img.tools.append(csr)
>        img.overlays.append(csr_overlay)
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: RangeSelection on image data?

Michael Sarahan
Hi John,

Thanks!  That gets me a little closer.  Making that change, I get a
rangeselection tool that allows me to select along the energy axis
(The X-axis in the 2D image plot.)  To switch it to the Y-axis, I have
attempted to pass the 'axis' keyword to the RangeSelection2D
instantiation, as so:

        if len(self.sig.data.shape)==2:
            csr = RangeSelection2D(component=img,axis='value')
            csr_overlay=SvgRangeSelectionOverlay(component=img,alpha=0.95)

When I try to drag the tool on my plot, I get a huge traceback about
IPython crashing (I have attached the Ipython crash report), followed
by this smaller traceback:

Original exception was:
Traceback (most recent call last):
  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\abstract_window.py",
line 448, in _on_right_down
    self._handle_mouse_event( 'right_down', event, set_focus = True )
  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\abstract_window.py",
line 341, in _handle_mouse_event
    self.component.dispatch(mouse_event, event_name)
  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\component.py", line 8
99, in dispatch
    self._new_dispatch(event, suffix)
  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\component.py", line 9
39, in _new_dispatch
    self._dispatch_stateful_event(event, suffix)
  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\container.py", line 5
69, in _dispatch_stateful_event
    component.dispatch(event, suffix)
  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\component.py", line 8
99, in dispatch
    self._new_dispatch(event, suffix)
  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\component.py", line 9
52, in _new_dispatch
    tool.dispatch(event, suffix)
  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\interactor.py", line
92, in dispatch
    self._dispatch_stateful_event(event, suffix)
  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\interactor.py", line
108, in _dispatch_stateful_event
    handler(event)
  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\tools\range_selection_
2d.py", line 182, in normal_right_down
    mapped_pos = self._map_data([(x_pos,y_pos)])[0][self.axis_index]
  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\tools\range_selection_
2d.py", line 282, in _map_data
    return self.mapper.map_data(screen_pts)
  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\abstract_colormap.py",
 line 37, in map_data
    raise NotImplementedError()
NotImplementedError

If I instead pass the axis_index argument as 1, I get strange
behavior: the selection is still along the same axis as it is for
axis_index=0, but it starts at some space off the left of the image
plot.  The exact amount of space is a function of where the selection
starts - starting further left on the image results in a smaller
offset left of the image plot.

I am at a loss after a hunt through the RangeSelection source code as
to what is behind this.  Sorry to keep needing help.  If you point me
where to look I'll try to fix this myself & submit a patch.

Best,
Mike

On 19 September 2011 16:27, John Wiggins <[hidden email]> wrote:

> Hello Mike,
>
> This is possible if you use the RangeSelection2D tool.
> Using your example:
>
> from chaco.layers.svg_range_selection_overlay import SvgRangeSelectionOverlay
>
> def render_image(self):
>       d=self.img_plotdata.get_data('imagedata')
>       plot = Plot(self.img_plotdata,default_origin="top left")
>       img=plot.img_plot("imagedata", colormap=gray)[0]
>       plot.aspect_ratio=float(d.shape[1])/float(d.shape[0])
>
>       if len(self.sig.data.shape)==2:
>           csr = RangeSelection2D(component=img)
>           csr_overlay = SvgRangeSelectionOverlay(component=img, alpha=1)
>       if len(self.sig.data.shape)==3:
>           csr = LassoSelection(component=img)
>           csr.on_trait_change(lasso_updated, "disjoint_selections")
>           csr_overlay=LassoOverlay(lasso_selection = csr, component=img)
>       img.tools.append(csr)
>       img.overlays.append(csr_overlay)
>
> As you can see, it should just be as simple as replacing
> RangeSelection with RangeSelection2D and RangeSelectionOverlay with
> SvgRangeSelectionOverlay.
>
> - John
>
> On Mon, Sep 19, 2011 at 9:18 AM, Michael Sarahan <[hidden email]> wrote:
>> Hi everyone,
>>
>> Is there a way to apply the RangeSelection tool to image plots?
>>
>> I have spectral data that is either 2D (a stack of spectra) or 3D (a
>> 2D array of spectra, with the spectral dimension being the 3rd).  I am
>> building a viewer, and would like to provide a spectrum selection tool
>> to the user.  For the 2D case, a RangeSelection tool would allow the
>> user to select any number of spectra, which would be summed, and the
>> sum displayed on another plot.  For the 3D case, users can use a lasso
>> tool to pick pixels from the 2D array (like a top-down view).
>>
>> I am trying this using the code below.  I think the mapper for the
>> image plot is not agreeing with what the RangeSelection tool expects.
>> What happens using the code below is that the plot loads fine, but
>> right-clicking on the plot to activate the range selection yields a
>> traceback, ending in:
>>
>> C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\tools\range_selection.pyc in n
>> ormal_right_down(self, event)
>>    401         """
>>    402         pos = self._get_axis_coord(event)
>> --> 403         mapped_pos = self.mapper.map_data(pos)
>>    404         self.selection = (mapped_pos, mapped_pos)
>>    405         self._set_sizing_cursor(event)
>>
>> C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\grid_mapper.pyc in map_data(se
>> lf, screen_pts)
>>    118         Maps values from screen space into data space.
>>    119         """
>> --> 120         screen_xs, screen_ys = transpose(screen_pts)
>>    121         xs = self._xmapper.map_data(screen_xs)
>>    122         ys = self._ymapper.map_data(screen_ys)
>>
>> TypeError: 'numpy.float64' object is not iterable
>>
>>
>> Can anyone suggest how to get these in agreement?  Any tips much appreciated.
>> -Mike
>>
>>
>>
>> Code below
>> -----------------------------------------
>> TypeError: 'numpy.float64' object is not iterable
>>
>>    def render_image(self):
>>        d=self.img_plotdata.get_data('imagedata')
>>        plot = Plot(self.img_plotdata,default_origin="top left")
>>        img=plot.img_plot("imagedata", colormap=gray)[0]
>>        plot.aspect_ratio=float(d.shape[1])/float(d.shape[0])
>>
>>        if len(self.sig.data.shape)==2:
>>            csr = RangeSelection(component=img)
>>            csr_overlay=RangeSelectionOverlay(component=img,alpha=0.8)
>>        if len(self.sig.data.shape)==3:
>>            csr = LassoSelection(component=img)
>>            csr.on_trait_change(lasso_updated, "disjoint_selections")
>>            csr_overlay=LassoOverlay(lasso_selection = csr, component=img)
>>        img.tools.append(csr)
>>        img.overlays.append(csr_overlay)
>> _______________________________________________
>> Enthought-Dev mailing list
>> [hidden email]
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev

Crash_report_ipython.txt (28K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: RangeSelection on image data?

John Wiggins
Mike,
I'm sorry, but I've misled you. It turns out that the functionality
that I thought I was pointing you towards is actually implemented in a
helper class in one of our client projects. The 2D selection box that
we implemented is a custom tool that uses DataBox from
chaco.overlays.api as a base class. It's possible that similar
functionality will eventually be rolled into chaco, but I can't give
you a firm timeline at this moment.

- John

On Mon, Sep 19, 2011 at 11:22 AM, Michael Sarahan
<[hidden email]> wrote:

> Hi John,
>
> Thanks!  That gets me a little closer.  Making that change, I get a
> rangeselection tool that allows me to select along the energy axis
> (The X-axis in the 2D image plot.)  To switch it to the Y-axis, I have
> attempted to pass the 'axis' keyword to the RangeSelection2D
> instantiation, as so:
>
>        if len(self.sig.data.shape)==2:
>            csr = RangeSelection2D(component=img,axis='value')
>            csr_overlay=SvgRangeSelectionOverlay(component=img,alpha=0.95)
>
> When I try to drag the tool on my plot, I get a huge traceback about
> IPython crashing (I have attached the Ipython crash report), followed
> by this smaller traceback:
>
> Original exception was:
> Traceback (most recent call last):
>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\abstract_window.py",
> line 448, in _on_right_down
>    self._handle_mouse_event( 'right_down', event, set_focus = True )
>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\abstract_window.py",
> line 341, in _handle_mouse_event
>    self.component.dispatch(mouse_event, event_name)
>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\component.py", line 8
> 99, in dispatch
>    self._new_dispatch(event, suffix)
>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\component.py", line 9
> 39, in _new_dispatch
>    self._dispatch_stateful_event(event, suffix)
>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\container.py", line 5
> 69, in _dispatch_stateful_event
>    component.dispatch(event, suffix)
>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\component.py", line 8
> 99, in dispatch
>    self._new_dispatch(event, suffix)
>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\component.py", line 9
> 52, in _new_dispatch
>    tool.dispatch(event, suffix)
>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\interactor.py", line
> 92, in dispatch
>    self._dispatch_stateful_event(event, suffix)
>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\interactor.py", line
> 108, in _dispatch_stateful_event
>    handler(event)
>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\tools\range_selection_
> 2d.py", line 182, in normal_right_down
>    mapped_pos = self._map_data([(x_pos,y_pos)])[0][self.axis_index]
>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\tools\range_selection_
> 2d.py", line 282, in _map_data
>    return self.mapper.map_data(screen_pts)
>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\abstract_colormap.py",
>  line 37, in map_data
>    raise NotImplementedError()
> NotImplementedError
>
> If I instead pass the axis_index argument as 1, I get strange
> behavior: the selection is still along the same axis as it is for
> axis_index=0, but it starts at some space off the left of the image
> plot.  The exact amount of space is a function of where the selection
> starts - starting further left on the image results in a smaller
> offset left of the image plot.
>
> I am at a loss after a hunt through the RangeSelection source code as
> to what is behind this.  Sorry to keep needing help.  If you point me
> where to look I'll try to fix this myself & submit a patch.
>
> Best,
> Mike
>
> On 19 September 2011 16:27, John Wiggins <[hidden email]> wrote:
>> Hello Mike,
>>
>> This is possible if you use the RangeSelection2D tool.
>> Using your example:
>>
>> from chaco.layers.svg_range_selection_overlay import SvgRangeSelectionOverlay
>>
>> def render_image(self):
>>       d=self.img_plotdata.get_data('imagedata')
>>       plot = Plot(self.img_plotdata,default_origin="top left")
>>       img=plot.img_plot("imagedata", colormap=gray)[0]
>>       plot.aspect_ratio=float(d.shape[1])/float(d.shape[0])
>>
>>       if len(self.sig.data.shape)==2:
>>           csr = RangeSelection2D(component=img)
>>           csr_overlay = SvgRangeSelectionOverlay(component=img, alpha=1)
>>       if len(self.sig.data.shape)==3:
>>           csr = LassoSelection(component=img)
>>           csr.on_trait_change(lasso_updated, "disjoint_selections")
>>           csr_overlay=LassoOverlay(lasso_selection = csr, component=img)
>>       img.tools.append(csr)
>>       img.overlays.append(csr_overlay)
>>
>> As you can see, it should just be as simple as replacing
>> RangeSelection with RangeSelection2D and RangeSelectionOverlay with
>> SvgRangeSelectionOverlay.
>>
>> - John
>>
>> On Mon, Sep 19, 2011 at 9:18 AM, Michael Sarahan <[hidden email]> wrote:
>>> Hi everyone,
>>>
>>> Is there a way to apply the RangeSelection tool to image plots?
>>>
>>> I have spectral data that is either 2D (a stack of spectra) or 3D (a
>>> 2D array of spectra, with the spectral dimension being the 3rd).  I am
>>> building a viewer, and would like to provide a spectrum selection tool
>>> to the user.  For the 2D case, a RangeSelection tool would allow the
>>> user to select any number of spectra, which would be summed, and the
>>> sum displayed on another plot.  For the 3D case, users can use a lasso
>>> tool to pick pixels from the 2D array (like a top-down view).
>>>
>>> I am trying this using the code below.  I think the mapper for the
>>> image plot is not agreeing with what the RangeSelection tool expects.
>>> What happens using the code below is that the plot loads fine, but
>>> right-clicking on the plot to activate the range selection yields a
>>> traceback, ending in:
>>>
>>> C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\tools\range_selection.pyc in n
>>> ormal_right_down(self, event)
>>>    401         """
>>>    402         pos = self._get_axis_coord(event)
>>> --> 403         mapped_pos = self.mapper.map_data(pos)
>>>    404         self.selection = (mapped_pos, mapped_pos)
>>>    405         self._set_sizing_cursor(event)
>>>
>>> C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\grid_mapper.pyc in map_data(se
>>> lf, screen_pts)
>>>    118         Maps values from screen space into data space.
>>>    119         """
>>> --> 120         screen_xs, screen_ys = transpose(screen_pts)
>>>    121         xs = self._xmapper.map_data(screen_xs)
>>>    122         ys = self._ymapper.map_data(screen_ys)
>>>
>>> TypeError: 'numpy.float64' object is not iterable
>>>
>>>
>>> Can anyone suggest how to get these in agreement?  Any tips much appreciated.
>>> -Mike
>>>
>>>
>>>
>>> Code below
>>> -----------------------------------------
>>> TypeError: 'numpy.float64' object is not iterable
>>>
>>>    def render_image(self):
>>>        d=self.img_plotdata.get_data('imagedata')
>>>        plot = Plot(self.img_plotdata,default_origin="top left")
>>>        img=plot.img_plot("imagedata", colormap=gray)[0]
>>>        plot.aspect_ratio=float(d.shape[1])/float(d.shape[0])
>>>
>>>        if len(self.sig.data.shape)==2:
>>>            csr = RangeSelection(component=img)
>>>            csr_overlay=RangeSelectionOverlay(component=img,alpha=0.8)
>>>        if len(self.sig.data.shape)==3:
>>>            csr = LassoSelection(component=img)
>>>            csr.on_trait_change(lasso_updated, "disjoint_selections")
>>>            csr_overlay=LassoOverlay(lasso_selection = csr, component=img)
>>>        img.tools.append(csr)
>>>        img.overlays.append(csr_overlay)
>>> _______________________________________________
>>> Enthought-Dev mailing list
>>> [hidden email]
>>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>>
>> _______________________________________________
>> Enthought-Dev mailing list
>> [hidden email]
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>
>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: RangeSelection on image data?

Michael Sarahan
No problem, thanks anyway!  At least what is there is a decent start.

Best,
Mike

On 19 September 2011 20:53, John Wiggins <[hidden email]> wrote:

> Mike,
> I'm sorry, but I've misled you. It turns out that the functionality
> that I thought I was pointing you towards is actually implemented in a
> helper class in one of our client projects. The 2D selection box that
> we implemented is a custom tool that uses DataBox from
> chaco.overlays.api as a base class. It's possible that similar
> functionality will eventually be rolled into chaco, but I can't give
> you a firm timeline at this moment.
>
> - John
>
> On Mon, Sep 19, 2011 at 11:22 AM, Michael Sarahan
> <[hidden email]> wrote:
>> Hi John,
>>
>> Thanks!  That gets me a little closer.  Making that change, I get a
>> rangeselection tool that allows me to select along the energy axis
>> (The X-axis in the 2D image plot.)  To switch it to the Y-axis, I have
>> attempted to pass the 'axis' keyword to the RangeSelection2D
>> instantiation, as so:
>>
>>        if len(self.sig.data.shape)==2:
>>            csr = RangeSelection2D(component=img,axis='value')
>>            csr_overlay=SvgRangeSelectionOverlay(component=img,alpha=0.95)
>>
>> When I try to drag the tool on my plot, I get a huge traceback about
>> IPython crashing (I have attached the Ipython crash report), followed
>> by this smaller traceback:
>>
>> Original exception was:
>> Traceback (most recent call last):
>>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\abstract_window.py",
>> line 448, in _on_right_down
>>    self._handle_mouse_event( 'right_down', event, set_focus = True )
>>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\abstract_window.py",
>> line 341, in _handle_mouse_event
>>    self.component.dispatch(mouse_event, event_name)
>>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\component.py", line 8
>> 99, in dispatch
>>    self._new_dispatch(event, suffix)
>>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\component.py", line 9
>> 39, in _new_dispatch
>>    self._dispatch_stateful_event(event, suffix)
>>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\container.py", line 5
>> 69, in _dispatch_stateful_event
>>    component.dispatch(event, suffix)
>>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\component.py", line 8
>> 99, in dispatch
>>    self._new_dispatch(event, suffix)
>>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\component.py", line 9
>> 52, in _new_dispatch
>>    tool.dispatch(event, suffix)
>>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\interactor.py", line
>> 92, in dispatch
>>    self._dispatch_stateful_event(event, suffix)
>>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\interactor.py", line
>> 108, in _dispatch_stateful_event
>>    handler(event)
>>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\tools\range_selection_
>> 2d.py", line 182, in normal_right_down
>>    mapped_pos = self._map_data([(x_pos,y_pos)])[0][self.axis_index]
>>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\tools\range_selection_
>> 2d.py", line 282, in _map_data
>>    return self.mapper.map_data(screen_pts)
>>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\abstract_colormap.py",
>>  line 37, in map_data
>>    raise NotImplementedError()
>> NotImplementedError
>>
>> If I instead pass the axis_index argument as 1, I get strange
>> behavior: the selection is still along the same axis as it is for
>> axis_index=0, but it starts at some space off the left of the image
>> plot.  The exact amount of space is a function of where the selection
>> starts - starting further left on the image results in a smaller
>> offset left of the image plot.
>>
>> I am at a loss after a hunt through the RangeSelection source code as
>> to what is behind this.  Sorry to keep needing help.  If you point me
>> where to look I'll try to fix this myself & submit a patch.
>>
>> Best,
>> Mike
>>
>> On 19 September 2011 16:27, John Wiggins <[hidden email]> wrote:
>>> Hello Mike,
>>>
>>> This is possible if you use the RangeSelection2D tool.
>>> Using your example:
>>>
>>> from chaco.layers.svg_range_selection_overlay import SvgRangeSelectionOverlay
>>>
>>> def render_image(self):
>>>       d=self.img_plotdata.get_data('imagedata')
>>>       plot = Plot(self.img_plotdata,default_origin="top left")
>>>       img=plot.img_plot("imagedata", colormap=gray)[0]
>>>       plot.aspect_ratio=float(d.shape[1])/float(d.shape[0])
>>>
>>>       if len(self.sig.data.shape)==2:
>>>           csr = RangeSelection2D(component=img)
>>>           csr_overlay = SvgRangeSelectionOverlay(component=img, alpha=1)
>>>       if len(self.sig.data.shape)==3:
>>>           csr = LassoSelection(component=img)
>>>           csr.on_trait_change(lasso_updated, "disjoint_selections")
>>>           csr_overlay=LassoOverlay(lasso_selection = csr, component=img)
>>>       img.tools.append(csr)
>>>       img.overlays.append(csr_overlay)
>>>
>>> As you can see, it should just be as simple as replacing
>>> RangeSelection with RangeSelection2D and RangeSelectionOverlay with
>>> SvgRangeSelectionOverlay.
>>>
>>> - John
>>>
>>> On Mon, Sep 19, 2011 at 9:18 AM, Michael Sarahan <[hidden email]> wrote:
>>>> Hi everyone,
>>>>
>>>> Is there a way to apply the RangeSelection tool to image plots?
>>>>
>>>> I have spectral data that is either 2D (a stack of spectra) or 3D (a
>>>> 2D array of spectra, with the spectral dimension being the 3rd).  I am
>>>> building a viewer, and would like to provide a spectrum selection tool
>>>> to the user.  For the 2D case, a RangeSelection tool would allow the
>>>> user to select any number of spectra, which would be summed, and the
>>>> sum displayed on another plot.  For the 3D case, users can use a lasso
>>>> tool to pick pixels from the 2D array (like a top-down view).
>>>>
>>>> I am trying this using the code below.  I think the mapper for the
>>>> image plot is not agreeing with what the RangeSelection tool expects.
>>>> What happens using the code below is that the plot loads fine, but
>>>> right-clicking on the plot to activate the range selection yields a
>>>> traceback, ending in:
>>>>
>>>> C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\tools\range_selection.pyc in n
>>>> ormal_right_down(self, event)
>>>>    401         """
>>>>    402         pos = self._get_axis_coord(event)
>>>> --> 403         mapped_pos = self.mapper.map_data(pos)
>>>>    404         self.selection = (mapped_pos, mapped_pos)
>>>>    405         self._set_sizing_cursor(event)
>>>>
>>>> C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\grid_mapper.pyc in map_data(se
>>>> lf, screen_pts)
>>>>    118         Maps values from screen space into data space.
>>>>    119         """
>>>> --> 120         screen_xs, screen_ys = transpose(screen_pts)
>>>>    121         xs = self._xmapper.map_data(screen_xs)
>>>>    122         ys = self._ymapper.map_data(screen_ys)
>>>>
>>>> TypeError: 'numpy.float64' object is not iterable
>>>>
>>>>
>>>> Can anyone suggest how to get these in agreement?  Any tips much appreciated.
>>>> -Mike
>>>>
>>>>
>>>>
>>>> Code below
>>>> -----------------------------------------
>>>> TypeError: 'numpy.float64' object is not iterable
>>>>
>>>>    def render_image(self):
>>>>        d=self.img_plotdata.get_data('imagedata')
>>>>        plot = Plot(self.img_plotdata,default_origin="top left")
>>>>        img=plot.img_plot("imagedata", colormap=gray)[0]
>>>>        plot.aspect_ratio=float(d.shape[1])/float(d.shape[0])
>>>>
>>>>        if len(self.sig.data.shape)==2:
>>>>            csr = RangeSelection(component=img)
>>>>            csr_overlay=RangeSelectionOverlay(component=img,alpha=0.8)
>>>>        if len(self.sig.data.shape)==3:
>>>>            csr = LassoSelection(component=img)
>>>>            csr.on_trait_change(lasso_updated, "disjoint_selections")
>>>>            csr_overlay=LassoOverlay(lasso_selection = csr, component=img)
>>>>        img.tools.append(csr)
>>>>        img.overlays.append(csr_overlay)
>>>> _______________________________________________
>>>> Enthought-Dev mailing list
>>>> [hidden email]
>>>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>>>
>>> _______________________________________________
>>> Enthought-Dev mailing list
>>> [hidden email]
>>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>>
>>
>> _______________________________________________
>> Enthought-Dev mailing list
>> [hidden email]
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>
>>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: RangeSelection on image data?

Fredrik Östlund
Hi Mike,

I have once done exactly what you want. I solved it by adding an empty
lineplot to my plot and then adding the RangeSelection to the renderer of
that plot:

renderer = self.xyplot.plot(('x', 'y'), name='dummy')[0]

self.y_range_selection = RangeSelection(renderer, axis='value')
renderer.tools.append( self.y_range_selection )
renderer.overlays.append(RangeSelectionOverlay(component=renderer,
axis='value', border_color='purple', alpha=0.3))

It's an ugly solution, but it works.

Fredrik Östlund


-----Original Message-----
From: Michael Sarahan
Sent: Monday, September 19, 2011 10:38 PM
To: [hidden email]
Subject: Re: [Enthought-Dev] RangeSelection on image data?

No problem, thanks anyway!  At least what is there is a decent start.

Best,
Mike

On 19 September 2011 20:53, John Wiggins <[hidden email]> wrote:

> Mike,
> I'm sorry, but I've misled you. It turns out that the functionality
> that I thought I was pointing you towards is actually implemented in a
> helper class in one of our client projects. The 2D selection box that
> we implemented is a custom tool that uses DataBox from
> chaco.overlays.api as a base class. It's possible that similar
> functionality will eventually be rolled into chaco, but I can't give
> you a firm timeline at this moment.
>
> - John
>
> On Mon, Sep 19, 2011 at 11:22 AM, Michael Sarahan
> <[hidden email]> wrote:
>> Hi John,
>>
>> Thanks!  That gets me a little closer.  Making that change, I get a
>> rangeselection tool that allows me to select along the energy axis
>> (The X-axis in the 2D image plot.)  To switch it to the Y-axis, I have
>> attempted to pass the 'axis' keyword to the RangeSelection2D
>> instantiation, as so:
>>
>>        if len(self.sig.data.shape)==2:
>>            csr = RangeSelection2D(component=img,axis='value')
>>            csr_overlay=SvgRangeSelectionOverlay(component=img,alpha=0.95)
>>
>> When I try to drag the tool on my plot, I get a huge traceback about
>> IPython crashing (I have attached the Ipython crash report), followed
>> by this smaller traceback:
>>
>> Original exception was:
>> Traceback (most recent call last):
>>  File
>> "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\abstract_window.py",
>> line 448, in _on_right_down
>>    self._handle_mouse_event( 'right_down', event, set_focus = True )
>>  File
>> "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\abstract_window.py",
>> line 341, in _handle_mouse_event
>>    self.component.dispatch(mouse_event, event_name)
>>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\component.py",
>> line 8
>> 99, in dispatch
>>    self._new_dispatch(event, suffix)
>>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\component.py",
>> line 9
>> 39, in _new_dispatch
>>    self._dispatch_stateful_event(event, suffix)
>>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\container.py",
>> line 5
>> 69, in _dispatch_stateful_event
>>    component.dispatch(event, suffix)
>>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\component.py",
>> line 8
>> 99, in dispatch
>>    self._new_dispatch(event, suffix)
>>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\component.py",
>> line 9
>> 52, in _new_dispatch
>>    tool.dispatch(event, suffix)
>>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\interactor.py",
>> line
>> 92, in dispatch
>>    self._dispatch_stateful_event(event, suffix)
>>  File "C:\Users\Mike\epd_7_1_x64\lib\site-packages\enable\interactor.py",
>> line
>> 108, in _dispatch_stateful_event
>>    handler(event)
>>  File
>> "C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\tools\range_selection_
>> 2d.py", line 182, in normal_right_down
>>    mapped_pos = self._map_data([(x_pos,y_pos)])[0][self.axis_index]
>>  File
>> "C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\tools\range_selection_
>> 2d.py", line 282, in _map_data
>>    return self.mapper.map_data(screen_pts)
>>  File
>> "C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\abstract_colormap.py",
>>  line 37, in map_data
>>    raise NotImplementedError()
>> NotImplementedError
>>
>> If I instead pass the axis_index argument as 1, I get strange
>> behavior: the selection is still along the same axis as it is for
>> axis_index=0, but it starts at some space off the left of the image
>> plot.  The exact amount of space is a function of where the selection
>> starts - starting further left on the image results in a smaller
>> offset left of the image plot.
>>
>> I am at a loss after a hunt through the RangeSelection source code as
>> to what is behind this.  Sorry to keep needing help.  If you point me
>> where to look I'll try to fix this myself & submit a patch.
>>
>> Best,
>> Mike
>>
>> On 19 September 2011 16:27, John Wiggins <[hidden email]> wrote:
>>> Hello Mike,
>>>
>>> This is possible if you use the RangeSelection2D tool.
>>> Using your example:
>>>
>>> from chaco.layers.svg_range_selection_overlay import
>>> SvgRangeSelectionOverlay
>>>
>>> def render_image(self):
>>>       d=self.img_plotdata.get_data('imagedata')
>>>       plot = Plot(self.img_plotdata,default_origin="top left")
>>>       img=plot.img_plot("imagedata", colormap=gray)[0]
>>>       plot.aspect_ratio=float(d.shape[1])/float(d.shape[0])
>>>
>>>       if len(self.sig.data.shape)==2:
>>>           csr = RangeSelection2D(component=img)
>>>           csr_overlay = SvgRangeSelectionOverlay(component=img, alpha=1)
>>>       if len(self.sig.data.shape)==3:
>>>           csr = LassoSelection(component=img)
>>>           csr.on_trait_change(lasso_updated, "disjoint_selections")
>>>           csr_overlay=LassoOverlay(lasso_selection = csr, component=img)
>>>       img.tools.append(csr)
>>>       img.overlays.append(csr_overlay)
>>>
>>> As you can see, it should just be as simple as replacing
>>> RangeSelection with RangeSelection2D and RangeSelectionOverlay with
>>> SvgRangeSelectionOverlay.
>>>
>>> - John
>>>
>>> On Mon, Sep 19, 2011 at 9:18 AM, Michael Sarahan
>>> <[hidden email]> wrote:
>>>> Hi everyone,
>>>>
>>>> Is there a way to apply the RangeSelection tool to image plots?
>>>>
>>>> I have spectral data that is either 2D (a stack of spectra) or 3D (a
>>>> 2D array of spectra, with the spectral dimension being the 3rd).  I am
>>>> building a viewer, and would like to provide a spectrum selection tool
>>>> to the user.  For the 2D case, a RangeSelection tool would allow the
>>>> user to select any number of spectra, which would be summed, and the
>>>> sum displayed on another plot.  For the 3D case, users can use a lasso
>>>> tool to pick pixels from the 2D array (like a top-down view).
>>>>
>>>> I am trying this using the code below.  I think the mapper for the
>>>> image plot is not agreeing with what the RangeSelection tool expects.
>>>> What happens using the code below is that the plot loads fine, but
>>>> right-clicking on the plot to activate the range selection yields a
>>>> traceback, ending in:
>>>>
>>>> C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\tools\range_selection.pyc
>>>> in n
>>>> ormal_right_down(self, event)
>>>>    401         """
>>>>    402         pos = self._get_axis_coord(event)
>>>> --> 403         mapped_pos = self.mapper.map_data(pos)
>>>>    404         self.selection = (mapped_pos, mapped_pos)
>>>>    405         self._set_sizing_cursor(event)
>>>>
>>>> C:\Users\Mike\epd_7_1_x64\lib\site-packages\chaco\grid_mapper.pyc in
>>>> map_data(se
>>>> lf, screen_pts)
>>>>    118         Maps values from screen space into data space.
>>>>    119         """
>>>> --> 120         screen_xs, screen_ys = transpose(screen_pts)
>>>>    121         xs = self._xmapper.map_data(screen_xs)
>>>>    122         ys = self._ymapper.map_data(screen_ys)
>>>>
>>>> TypeError: 'numpy.float64' object is not iterable
>>>>
>>>>
>>>> Can anyone suggest how to get these in agreement?  Any tips much
>>>> appreciated.
>>>> -Mike
>>>>
>>>>
>>>>
>>>> Code below
>>>> -----------------------------------------
>>>> TypeError: 'numpy.float64' object is not iterable
>>>>
>>>>    def render_image(self):
>>>>        d=self.img_plotdata.get_data('imagedata')
>>>>        plot = Plot(self.img_plotdata,default_origin="top left")
>>>>        img=plot.img_plot("imagedata", colormap=gray)[0]
>>>>        plot.aspect_ratio=float(d.shape[1])/float(d.shape[0])
>>>>
>>>>        if len(self.sig.data.shape)==2:
>>>>            csr = RangeSelection(component=img)
>>>>            csr_overlay=RangeSelectionOverlay(component=img,alpha=0.8)
>>>>        if len(self.sig.data.shape)==3:
>>>>            csr = LassoSelection(component=img)
>>>>            csr.on_trait_change(lasso_updated, "disjoint_selections")
>>>>            csr_overlay=LassoOverlay(lasso_selection = csr,
>>>> component=img)
>>>>        img.tools.append(csr)
>>>>        img.overlays.append(csr_overlay)
>>>> _______________________________________________
>>>> Enthought-Dev mailing list
>>>> [hidden email]
>>>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>>>
>>> _______________________________________________
>>> Enthought-Dev mailing list
>>> [hidden email]
>>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>>
>>
>> _______________________________________________
>> Enthought-Dev mailing list
>> [hidden email]
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>
>>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev 

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev