Presents a provided figure (normally a time series) and provides an interface to mark events shown in the plot. The user interface is explained in analyze() and results are returned by get_events()
Other Parameters: | |
---|---|
ax : maplotlib.axes.AxesSubplot
n_phases : int (optional, default 1)
interval : (optional)
auto_interval : boolean (optional)
auto_scale : boolean (optional, default True):
ymin : (optional, default None)
ymax : (optional, default None)
line : matplotlib.lines.Line2D (optional)
|
Examples
>>> import spacepy.plot.utils
>>> import numpy
>>> import matplotlib.pyplot as plt
>>> x = numpy.arange(630) / 100.0 * numpy.pi
>>> y = numpy.sin(x)
>>> clicker = spacepy.plot.utils.EventClicker(
... n_phases=2, #Two picks per event
... interval=numpy.pi * 2) #Display one cycle at a time
>>> plt.plot(x, y)
>>> clicker.analyze() #Double-click on max and min of each cycle; close
>>> e = clicker.get_events()
>>> peaks = e[:, 0, 0] #x value of event starts
>>> peaks -= 2 * numpy.pi * numpy.floor(peaks / (2 * numpy.pi)) #mod 2pi
>>> max(numpy.abs(peaks - numpy.pi / 2)) < 0.2 #Peaks should be near pi/2
True
>>> troughs = e[:, 1, 0] #x value of event ends
>>> troughs -= 2 * numpy.pi * numpy.floor(troughs / (2 * numpy.pi))
>>> max(numpy.abs(peaks - 3 * numpy.pi / 2)) < 0.2 #troughs near 3pi/2
True
>>> d = clicker.get_events_data() #snap-to-data of events
>>> peakvals = d[:, 0, 1] #y value, snapped near peaks
>>> max(peakvals) <= 1.0 #should peak at 1
True
>>> min(peakvals) > 0.9 #should click near 1
True
>>> troughvals = d[:, 1, 1] #y value, snapped near peaks
>>> max(troughvals) <= -0.9 #should click near -1
True
>>> min(troughvals) <= -1.0 #should bottom-out at -1
True
analyze() | Displays the figure provided and allows the user to select events. |
get_events() | Get back the list of events. |
get_events_data() | Get a list of events, “snapped” to the data. |
Displays the figure provided and allows the user to select events.
All matplot lib controls for zooming, panning, etc. the figure remain active.
Mark this point as an event phase. One-phase events are the simplest: they occur at a particular time. Two-phase events have two times associated with them; an example is any event with a distinct start and stop time. In that case, the first double-click would mark the beginning, the second one, the end; the next double-click would mark the beginning of the next event. Each phase of an event is annotated with a vertical line on the plot; the color and line style is the same for all events, but different for each phase.
After marking the final phase of an event, the X axis will scroll and zoom to place that phase near the left of the screeen and include one full interval of data (as defined in the constructor). The Y axis will be scaled to cover the data in that X range.
When finished, close the figure window (if necessary) and call get_events() to get the list of events.
Get back the list of events.
Call after analyze().
Returns: | out : array
|
---|
Get a list of events, “snapped” to the data.
For each point selected as a phase of an event, selects the point from the original data which is closest to the clicked point. Distance from point to data is calculated based on the screen distance, not in data coordinates.
Note that this snaps to data points, not to the closest point on the line between points.
Call after analyze().
Returns: | out : array
|
---|