PyDynPeak Quickstart¶
PyDynPeak python API provides an interface for the users to load and review data, manipulate peak detection parameters and eventually detect peaks in the time series.
We will work on Lacaune ewes data. We will load and review data, manipulate peak detection parameters, and detect and visualize peaks.
The data can be downloaded from LacauneData.csv.
For more information on API, please refer to API Reference.
Initialize DynPeak executer¶
We need to create an instance of pydynpeak.model.DynpeakExecuter/pydynpeak.model.DynpeakExecuterWrapper to access the necessary functionality.
[1]:
from pydynpeak.model import DynpeakExecuterWrapper
dyne = DynpeakExecuterWrapper()
Load LacauneData.csv file¶
We will load the LacauneData.csv
file to DynpeakExecuter instance.
filepath
is the relative or absolute path of the data file.
sep
is the sepatator used in the CSV file.
sname
is the string to be used as series name with column index added at the end. ex: Lacaune ewes1, Lacaune ewes2, etc.
For more information on load_csv
method and possible parameters see pydynpeak.model.DynpeakExecuter.load_csv.
[2]:
dyne.load_csv(filepath='../data/LacauneData.csv', sep='\t', seriesname='Lacaune ewes')
Review data¶
We’ll first check first 15
lines of data to see if the data is loaded correctly.
By default view_head
method displays the first 10
lines.
The first column displays the sampling times
.
[3]:
dyne.view_head(15)
Note: As the LacauneData.csv
file does not contain sampling times, it is generated with a default timeinterval
value of 10 minutes.
It is possible to set timeinterval
parameter while loading data with load_csv
method. For more information see pydynpeak.model.DynpeakExecuter.load_csv.
It is also possible to view last n
lines of data or whole data using view_tail
or view_all
methods respectively.
[4]:
dyne.view_tail()
[5]:
dyne.view_all()
Plot all series in data¶
Let’s plot all series in data.
[6]:
dyne.plot_lh_all(header='Lacaune Data')
The graph is interactive. It is possible to show/hide series selecting/deselecting them from the legend. The value for each data point is displayed, when hovered on the data point with mouse. It is also possible to zoom, pan on the plot.
If we do not specify header
parameter, the header for the plot will be the value that we specified as seriesname
while loading data with load_csv
method.
Current series¶
By default the first series in data is set as current series. All operations are executed on the currently selected series if an index
parameter is not specified.
We will work on the 3rd series.
[7]:
dyne.currentseries = 3
Print peak detection parameters¶
When data is loaded, for each series in data, default peak detection parameters are set for each series.
[9]:
dyne.print_detection_params()
Detection threshold = 0 ng/ml
Coefficient of variation:
Range = [0, 1000] ng/ml
CV = [0, 0] %
Global relative threshold = 0.2 %
Local absolute threshold = 0.1 %
Nominal peaks period = 40 minutes
Three point threshold = 0.1 %
Interval = []
Ignored points = []
Imposed peaks = []
For more information on peak detection parameters see pydynpeak.model.DynpeakExecuter.print_detection_params.
Set detection interval¶
[10]:
# update detection interval for current series
dyne.update_detection_params(interval=[10, 130])
[10]:
True
Note: Each time interval
is set, peak detection parameters for the current series are reset to the default values.
For more information on updating peak detection parameters see pydynpeak.model.DynpeakExecuter.update_detection_params.
Detect peaks¶
After setting detection parameters, we can now detect peaks on the current series.
[11]:
dyne.detect_peaks_and_plot()
Ignore peaks¶
We will work on 2nd series.
[13]:
dyne.currentseries = 2
Let’s detect peaks:
[14]:
dyne.detect_peaks_and_plot()
We would like to ignore a peak at time value 810. To specify ignored peaks we should use time index which is 81 rather than real time value 810. It is possible to view the time index by hovering on the graph with the mouse.
[15]:
dyne.detect_peaks_and_plot(ignoredpoints=[81])
Ignored peaks are shown with a yellow cross on the graph.
Impose peaks¶
We will work on 7th series.
[16]:
dyne.currentseries = 7
Let’s detect peaks:
[17]:
dyne.detect_peaks_and_plot()
We would like to impose a peak at time value 330. To specify imposed peaks we should use time index which is 33 rather than real time value 330. It is possible to view the time index by hovering on the graph with the mouse.
[18]:
dyne.detect_peaks_and_plot(imposedpeaks=[33])
Imposed peaks are shown with a pink upwards arrow on the graph.