PyDynPeak “magics” quickstart

The main PyDynPeak interface is a Python API interface explained in the Quickstart and API Reference.

Additionally, PyDynPeak provides access to some of its functionalities via the magic %dyne command (more information on magics are available here).

The %dyne command can be used in two variants:

  • simplified (line magic command):

%dyne <subcommand> [arg]
  • extended (cell magic command, begins with %%):

%%dyne <subcommand>
arg1: value1
arg2: value2
...

For more information on API, please refer to Quickstart and API Reference.

The simplified form of the command (%dyne) is useful when there is a maximum of one mandatory argument and the default values are suitable for optional arguments.

The extended form (%%dyne) is recommended in all other cases. In the extended form, the first line of the cell contains only the command %%dyne followed by the subcommand. Arguments are provided on the following lines of the same cell one per line, in the form argument: value

Initialize %dyne magic

To initialize the command, simply import the pydynpeak module:

[1]:
import pydynpeak

If you run %dyne alone, the list of available subcommands is displayed:

[2]:
%dyne
[2]:

Use the magic command %dyne with one of the following subcommands:

Copy and paste some csv content to dynpeak

When a small csv content is not available as a file (e.g. a web page) you can copy and paste it like this:

[3]:
%%dyne paste_csv
0.043       0.026   0.607   0.143   1.998   0.156   0.802   0.458   0.521   0.199
0.035       0.021   0.543   0.232   1.316   0.175   0.779   1.131   0.586   0.153
0.032       0.020   0.476   0.240   1.268   0.269   1.767   1.108   0.430   0.128
0.037       0.019   0.372   0.213   1.052   0.215   1.397   0.883   0.335   0.125
0.049       0.022   0.300   0.143   0.876   0.156   1.061   0.646   0.266   0.084

Init Dyne

Load a .csv file

The different loading parameters are explained in the quickstart and in the API doc (see pydynpeak.model.DynpeakExecuter.load_csv).

In the simplified form, as an exception to the rule stated above, the sep parameter does not take the default value (“,”) but a value inferred from the file to be imported:

[4]:
%dyne load_csv ../data/LacauneData.csv

In the extended format, parameters are provided in YAML-alike format, one per line:

[5]:
%%dyne load_csv
filepath: ../data/LacauneData.csv
sep: \t
seriesname: Lacaune ewes

Two convenience subcommands

The info and describe subcommands below are directly mapped on their pandas homonymes:

[6]:
%dyne info
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 144 entries, 0 to 1430
Data columns (total 10 columns):
 #   Column          Non-Null Count  Dtype
---  ------          --------------  -----
 0   Lacaune ewes1   144 non-null    float64
 1   Lacaune ewes2   144 non-null    float64
 2   Lacaune ewes3   144 non-null    float64
 3   Lacaune ewes4   144 non-null    float64
 4   Lacaune ewes5   144 non-null    float64
 5   Lacaune ewes6   144 non-null    float64
 6   Lacaune ewes7   144 non-null    float64
 7   Lacaune ewes8   144 non-null    float64
 8   Lacaune ewes9   144 non-null    float64
 9   Lacaune ewes10  144 non-null    float64
dtypes: float64(10)
memory usage: 11.4 KB
[7]:
%dyne describe
[7]:
Lacaune ewes1 Lacaune ewes2 Lacaune ewes3 Lacaune ewes4 Lacaune ewes5 Lacaune ewes6 Lacaune ewes7 Lacaune ewes8 Lacaune ewes9 Lacaune ewes10
count 144.000000 144.000000 144.000000 144.000000 144.000000 144.000000 144.000000 144.000000 144.000000 144.000000
mean 0.264472 0.145194 0.498083 0.407708 0.404243 0.550729 0.521813 0.503549 0.465653 0.139687
std 0.290718 0.213927 0.327581 0.241843 0.367381 0.322401 0.264376 0.262902 0.248285 0.082228
min 0.032000 0.013000 0.086000 0.111000 0.003000 0.062000 0.079000 0.121000 0.156000 0.051000
25% 0.085000 0.030500 0.268000 0.239750 0.165000 0.352500 0.365000 0.327250 0.299000 0.078000
50% 0.169000 0.053000 0.407000 0.341000 0.284000 0.473500 0.500000 0.412000 0.405500 0.120000
75% 0.343250 0.132500 0.615250 0.520750 0.528000 0.694750 0.650250 0.602250 0.555500 0.188000
max 2.004000 1.016000 1.610000 1.654000 2.005000 2.042000 1.767000 1.385000 1.476000 0.473000

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.

[8]:
%dyne view_head 15

It is also possible to view last n lines of data or whole data using view_tail or view_all methods respectively.

[9]:
%dyne view_tail 3
[10]:
%dyne view_all

Plot all series in data

Let’s plot all series in data.

[11]:
%dyne plot_lh_all '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.

[12]:
%dyne currentseries 3

Plot series

Let’s first plot the series that we are going to work on.

[13]:
%dyne plot_lh

Set detection interval

Update detection interval for current series

[15]:
%%dyne update_detection_params
interval: [10, 130]
[15]:
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.

[16]:
%dyne detect_peaks_and_plot

Display detected peaks

[17]:
%dyne print_peaks

Ignore peaks

We will work on 2nd series.

[18]:
%dyne currentseries 2

Let’s detect peaks:

[19]:
%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.

[20]:
%%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.

[21]:
%dyne currentseries 7

Let’s detect peaks:

[22]:
%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.

[23]:
%%dyne detect_peaks_and_plot
imposedpeaks: [33]

Imposed peaks are shown with a pink upwards arrow on the graph.