Skip to content

Commit

Permalink
cleaning notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
gviejo committed Apr 11, 2022
1 parent 92b3cbb commit b9a694b
Show file tree
Hide file tree
Showing 4 changed files with 373 additions and 337 deletions.
216 changes: 108 additions & 108 deletions docs/notebooks/pynapple-core-notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"source": [
"# Core Tutorial\n",
"\n",
"This script will introduce you to the basics of time series handling with pynapple."
"This script will introduce the basics of handling time series data with pynapple."
]
},
{
Expand All @@ -30,7 +30,7 @@
"source": [
"## Time series object\n",
"\n",
"Let's create a Tsd object with fake data. In this case, every time point is 1 second apart. A Tsd object is a wrapper of pandas series."
"Let's create a Tsd object with artificial data. In this example, every time point is 1 second apart. A Tsd object is a wrapper of a [pandas series](https://pandas.pydata.org/docs/reference/series.html)."
]
},
{
Expand All @@ -44,17 +44,17 @@
"output_type": "stream",
"text": [
"Time (s)\n",
"0.0 0.926051\n",
"1.0 0.849987\n",
"2.0 0.034611\n",
"3.0 0.241067\n",
"4.0 0.931331\n",
"0.0 0.563213\n",
"1.0 0.378064\n",
"2.0 0.814118\n",
"3.0 0.280128\n",
"4.0 0.355886\n",
" ... \n",
"95.0 0.388211\n",
"96.0 0.219992\n",
"97.0 0.327807\n",
"98.0 0.959152\n",
"99.0 0.416207\n",
"95.0 0.172626\n",
"96.0 0.984622\n",
"97.0 0.972610\n",
"98.0 0.748225\n",
"99.0 0.678745\n",
"Length: 100, dtype: float64\n"
]
}
Expand All @@ -70,7 +70,7 @@
"id": "c450e33c",
"metadata": {},
"source": [
"It is possible to switch between seconds, milliseconds and microseconds. Note that when using *as_units*, the returned object is a simple pandas series."
"It is possible to toggle between seconds, milliseconds and microseconds. Note that when using *as_units*, the returned object is a simple pandas series."
]
},
{
Expand All @@ -84,30 +84,30 @@
"output_type": "stream",
"text": [
"Time (ms)\n",
"0.0 0.926051\n",
"1000.0 0.849987\n",
"2000.0 0.034611\n",
"3000.0 0.241067\n",
"4000.0 0.931331\n",
"0.0 0.563213\n",
"1000.0 0.378064\n",
"2000.0 0.814118\n",
"3000.0 0.280128\n",
"4000.0 0.355886\n",
" ... \n",
"95000.0 0.388211\n",
"96000.0 0.219992\n",
"97000.0 0.327807\n",
"98000.0 0.959152\n",
"99000.0 0.416207\n",
"95000.0 0.172626\n",
"96000.0 0.984622\n",
"97000.0 0.972610\n",
"98000.0 0.748225\n",
"99000.0 0.678745\n",
"Length: 100, dtype: float64\n",
"Time (us)\n",
"0 0.926051\n",
"1000000 0.849987\n",
"2000000 0.034611\n",
"3000000 0.241067\n",
"4000000 0.931331\n",
"0 0.563213\n",
"1000000 0.378064\n",
"2000000 0.814118\n",
"3000000 0.280128\n",
"4000000 0.355886\n",
" ... \n",
"95000000 0.388211\n",
"96000000 0.219992\n",
"97000000 0.327807\n",
"98000000 0.959152\n",
"99000000 0.416207\n",
"95000000 0.172626\n",
"96000000 0.984622\n",
"97000000 0.972610\n",
"98000000 0.748225\n",
"99000000 0.678745\n",
"Length: 100, dtype: float64\n"
]
}
Expand All @@ -122,7 +122,7 @@
"id": "6c67b9d9",
"metadata": {},
"source": [
"If only timestamps are available, for example spike times, we can construct a Ts object which holds only times. In this case, we generate 10 random spike times between 0 and 100 ms."
"Pynapple is able to handle data that only contains timestamps, such as an object containing only spike times. To do so, we construct a Ts object which holds only times. In this case, we generate 10 random spike times between 0 and 100 ms."
]
},
{
Expand All @@ -136,16 +136,16 @@
"output_type": "stream",
"text": [
"Time (s)\n",
"0.000332 NaN\n",
"0.007557 NaN\n",
"0.015512 NaN\n",
"0.017357 NaN\n",
"0.019130 NaN\n",
"0.036301 NaN\n",
"0.052718 NaN\n",
"0.068055 NaN\n",
"0.079949 NaN\n",
"0.099882 NaN\n",
"0.000694 NaN\n",
"0.002771 NaN\n",
"0.011280 NaN\n",
"0.017841 NaN\n",
"0.017896 NaN\n",
"0.027838 NaN\n",
"0.030595 NaN\n",
"0.051214 NaN\n",
"0.054824 NaN\n",
"0.073896 NaN\n",
"dtype: float64\n"
]
}
Expand All @@ -161,7 +161,7 @@
"id": "3954a05f",
"metadata": {},
"source": [
"If the time series contains multiple columns, we can use a TsdFrame."
"If the time series contains multiple columns, we use a TsdFrame."
]
},
{
Expand All @@ -176,17 +176,17 @@
"text": [
" a b c\n",
"Time (s) \n",
"0.0 0.710777 0.045811 0.419415\n",
"1.0 0.010244 0.496336 0.253601\n",
"2.0 0.075987 0.079342 0.714916\n",
"3.0 0.195139 0.773036 0.518782\n",
"4.0 0.021775 0.313341 0.819941\n",
"0.0 0.402090 0.625281 0.008010\n",
"1.0 0.458671 0.878846 0.590229\n",
"2.0 0.451745 0.019802 0.636421\n",
"3.0 0.519470 0.891268 0.732998\n",
"4.0 0.450690 0.153512 0.408216\n",
"... ... ... ...\n",
"95.0 0.603578 0.319764 0.984949\n",
"96.0 0.788123 0.534558 0.886920\n",
"97.0 0.957802 0.675862 0.140417\n",
"98.0 0.393128 0.887271 0.061764\n",
"99.0 0.196731 0.357804 0.517005\n",
"95.0 0.600820 0.242669 0.700129\n",
"96.0 0.512757 0.927772 0.578880\n",
"97.0 0.981968 0.474559 0.648078\n",
"98.0 0.117539 0.792938 0.744750\n",
"99.0 0.853042 0.745129 0.351100\n",
"\n",
"[100 rows x 3 columns]\n"
]
Expand All @@ -208,7 +208,7 @@
"source": [
"## Interval Sets object\n",
"\n",
"The [IntervalSet](https://peyrachelab.github.io/pynapple/core.interval_set/) object stores multiple epochs with a common time units. It can then be used to restrict time series to this particular set of epochs."
"The [IntervalSet](https://peyrachelab.github.io/pynapple/core.interval_set/) object stores multiple epochs with a common time unit. It can then be used to restrict time series to this particular set of epochs."
]
},
{
Expand All @@ -227,18 +227,18 @@
"\n",
"\n",
"Time (s)\n",
"0.0 0.926051\n",
"1.0 0.849987\n",
"2.0 0.034611\n",
"3.0 0.241067\n",
"4.0 0.931331\n",
"5.0 0.287283\n",
"10.0 0.603891\n",
"11.0 0.336611\n",
"12.0 0.631118\n",
"13.0 0.343460\n",
"14.0 0.608318\n",
"15.0 0.000967\n",
"0.0 0.563213\n",
"1.0 0.378064\n",
"2.0 0.814118\n",
"3.0 0.280128\n",
"4.0 0.355886\n",
"5.0 0.583105\n",
"10.0 0.778229\n",
"11.0 0.843115\n",
"12.0 0.251995\n",
"13.0 0.868508\n",
"14.0 0.952296\n",
"15.0 0.277837\n",
"dtype: float64\n"
]
}
Expand Down Expand Up @@ -301,7 +301,7 @@
"source": [
"## TsGroup\n",
"\n",
"Multiple time series with different time stamps (.i.e. a group of neurons with different spike times from one session) can be grouped with the TsGroup object. The TsGroup behaves like a dictionnary but it is also possible to slice with a list of indexes"
"Multiple time series with different time stamps (.i.e. a group of neurons with different spike times from one session) can be grouped with the TsGroup object. The TsGroup behaves like a dictionary but it is also possible to slice with a list of indexes"
]
},
{
Expand All @@ -316,40 +316,40 @@
"text": [
" Index Freq. (Hz)\n",
"------- ------------\n",
" 0 10\n",
" 1 20.01\n",
" 2 30.01 \n",
" 0 10\n",
" 1 20\n",
" 2 30 \n",
"\n",
"Time (s)\n",
"0.019797 NaN\n",
"0.451827 NaN\n",
"0.464079 NaN\n",
"0.465697 NaN\n",
"0.517745 NaN\n",
"0.004007 NaN\n",
"0.133850 NaN\n",
"0.193702 NaN\n",
"0.229563 NaN\n",
"0.302664 NaN\n",
" ..\n",
"99.468552 NaN\n",
"99.492707 NaN\n",
"99.520110 NaN\n",
"99.849291 NaN\n",
"99.993950 NaN\n",
"99.697703 NaN\n",
"99.749609 NaN\n",
"99.843855 NaN\n",
"99.937553 NaN\n",
"99.940693 NaN\n",
"Length: 1000, dtype: float64 \n",
"\n",
" Index Freq. (Hz)\n",
"------- ------------\n",
" 0 10\n",
" 2 30.01\n"
" 0 10\n",
" 2 30\n"
]
}
],
"source": [
"my_ts = {0:nap.Ts(t = np.sort(np.random.uniform(0, 100, 1000)), time_units = 's'), # here a simple dictionnary\n",
"my_ts = {0:nap.Ts(t = np.sort(np.random.uniform(0, 100, 1000)), time_units = 's'), # here a simple dictionary\n",
" 1:nap.Ts(t = np.sort(np.random.uniform(0, 100, 2000)), time_units = 's'),\n",
" 2:nap.Ts(t = np.sort(np.random.uniform(0, 100, 3000)), time_units = 's')}\n",
"\n",
"tsgroup = nap.TsGroup(my_ts)\n",
"\n",
"print(tsgroup, '\\n')\n",
"print(tsgroup[0], '\\n') # dictionnary like indexing returns directly the Ts object\n",
"print(tsgroup[0], '\\n') # dictionary like indexing returns directly the Ts object\n",
"print(tsgroup[[0,2]]) # list like indexing"
]
},
Expand All @@ -373,16 +373,16 @@
"text": [
" 0 1 2\n",
"Time (s) \n",
"0.5 7 15 29\n",
"1.5 13 14 36\n",
"2.5 8 19 32\n",
"3.5 8 15 23\n",
"4.5 11 17 36\n",
"10.5 15 19 34\n",
"11.5 14 26 20\n",
"12.5 11 19 41\n",
"13.5 13 20 27\n",
"14.5 9 24 40\n"
"0.5 16 19 36\n",
"1.5 8 20 35\n",
"2.5 9 27 26\n",
"3.5 9 18 27\n",
"4.5 13 21 24\n",
"10.5 15 17 34\n",
"11.5 12 23 28\n",
"12.5 12 21 24\n",
"13.5 6 16 26\n",
"14.5 8 24 27\n"
]
}
],
Expand All @@ -399,7 +399,7 @@
"id": "b902a51c",
"metadata": {},
"source": [
"One advantage of grouping time series is that metainformation can be added about each elements. In this case, we add labels to each Ts object when instantiating the group and after. We can then use this label to split the group. See the documentation about [TsGroup](https://peyrachelab.github.io/pynapple/core.ts_group/) for all the ways to split TsGroup."
"One advantage of grouping time series is that metainformation can be appended directly on an element-wise basis. In this case, we add labels to each Ts object when instantiating the group and after. We can then use this label to split the group. See the [TsGroup](https://peyrachelab.github.io/pynapple/core.ts_group/) documentation for a complete methodology for splitting TsGroup objects."
]
},
{
Expand All @@ -414,18 +414,18 @@
"text": [
" Index Freq. (Hz) label1 label2\n",
"------- ------------ -------- --------\n",
" 0 10 0 a\n",
" 1 20.01 1 a\n",
" 2 30.01 0 b \n",
" 0 10 0 a\n",
" 1 20 1 a\n",
" 2 30 0 b \n",
"\n",
" Index Freq. (Hz) label1 label2\n",
"------- ------------ -------- --------\n",
" 0 10 0 a\n",
" 2 30.01 0 b \n",
" 0 10 0 a\n",
" 2 30 0 b \n",
"\n",
" Index Freq. (Hz) label1 label2\n",
"------- ------------ -------- --------\n",
" 1 20.01 1 a\n"
" 1 20 1 a\n"
]
}
],
Expand All @@ -449,9 +449,9 @@
"source": [
"## Time support\n",
"\n",
"A key element of the manipulation of time series by pynapple is the inherent time support defined for Ts, Tsd, TsdFrame and TsGroup objects. The time support is defined as an IntervalSet that provides the time serie with a context. For example,, the restrict operation will update automatically the time support to the new time series. Ideally the time support should be defined for all time series when instantiating them. If no time series is given, the time support is inferred from the start and end of the time series. \n",
"A key feature of how pynapple manipulates time series is an inherent time support object defined for Ts, Tsd, TsdFrame and TsGroup objects. The time support object is defined as an IntervalSet that provides the time serie with a context. For example, the restrict operation will automatically update the time support object for the new time series. Ideally, the time support object should be defined for all time series when instantiating them. If no time series is given, the time support is inferred from the start and end of the time series. \n",
"\n",
"In this example, a TsGroup is instantiated with and without a time support. Notice how the frequency of each Ts element is changed when the time support is defined explicitely."
"In this example, a TsGroup is instantiated with and without a time support. Notice how the frequency of each Ts element is changed when the time support is defined explicitly."
]
},
{
Expand All @@ -466,9 +466,9 @@
"text": [
" Index Freq. (Hz)\n",
"------- ------------\n",
" 0 0.1\n",
" 1 0.2\n",
" 2 0.31 \n",
" 0 0.1\n",
" 1 0.2\n",
" 2 0.3 \n",
"\n",
" Index Freq. (Hz)\n",
"------- ------------\n",
Expand Down
Loading

0 comments on commit b9a694b

Please sign in to comment.