{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Summarizing pupillometric data" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import sys\n", "sys.path.insert(0,\"..\")\n", "import pypillometry as pp" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `pypillometry` package provides several functions for summarizing datasets. Simply `print()`ing a `PupilData` object gives a readable summary of the main properties of the dataset and also prints the complete history of operations applied to the dataset." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "PupilData(fake_nutuheho, 13.9MiB):\n", " n : 113453\n", " nmiss : 0\n", " perc_miss : 0.0\n", " nevents : 200\n", " nblinks : 0\n", " ninterpolated : 0\n", " blinks_per_min : 0.0\n", " fs : 1000.0\n", " duration_minutes : 1.8908833333333335\n", " start_min : 0.0\n", " end_min : 1.8908780800185903\n", " baseline_estimated: False\n", " response_estimated: False\n", " History:\n", " *\n", "\n" ] } ], "source": [ "d=pp.create_fake_pupildata(ntrials=100)\n", "print(d)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " By calling the function `summary()`, summary data is returned in `dict` form:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'name': 'fake_nutuheho',\n", " 'n': 113453,\n", " 'nmiss': 0,\n", " 'perc_miss': 0.0,\n", " 'nevents': 200,\n", " 'nblinks': 0,\n", " 'ninterpolated': 0,\n", " 'blinks_per_min': 0.0,\n", " 'fs': 1000.0,\n", " 'duration_minutes': 1.8908833333333335,\n", " 'start_min': 0.0,\n", " 'end_min': 1.8908780800185903,\n", " 'baseline_estimated': False,\n", " 'response_estimated': False}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d.summary()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Using the package `pandas`, this allows to rapidly summarize properties of many datasets in a table.\n", "\n", "To illustrate, we create a list of datasets, each corresponding to one individual subject:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "nsubjs=10\n", "datasets=[pp.create_fake_pupildata(ntrials=100) for _ in range(nsubjs)]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can now call `summary()` for each of the objects and merge the resulting `dict` into a table form:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
namennmissperc_missneventsnblinksninterpolatedblinks_per_minfsduration_minutesstart_minend_minbaseline_estimatedresponse_estimated
0fake_tamofase11383200.0200000.01000.01.8972000.01.897196FalseFalse
1fake_lobavifu11442500.0200000.01000.01.9070830.01.907083FalseFalse
2fake_paketomu11297700.0200000.01000.01.8829500.01.882941FalseFalse
3fake_hiligovi11434500.0200000.01000.01.9057500.01.905735FalseFalse
4fake_kolavebo11373200.0200000.01000.01.8955330.01.895517FalseFalse
5fake_ropopodi11366100.0200000.01000.01.8943500.01.894346FalseFalse
6fake_rilimolo11440200.0200000.01000.01.9067000.01.906698FalseFalse
7fake_gapudome11389100.0200000.01000.01.8981830.01.898178FalseFalse
8fake_belobeva11393200.0200000.01000.01.8988670.01.898865FalseFalse
9fake_rihatofi11330400.0200000.01000.01.8884000.01.888393FalseFalse
\n", "
" ], "text/plain": [ " name n nmiss perc_miss nevents nblinks ninterpolated \\\n", "0 fake_tamofase 113832 0 0.0 200 0 0 \n", "1 fake_lobavifu 114425 0 0.0 200 0 0 \n", "2 fake_paketomu 112977 0 0.0 200 0 0 \n", "3 fake_hiligovi 114345 0 0.0 200 0 0 \n", "4 fake_kolavebo 113732 0 0.0 200 0 0 \n", "5 fake_ropopodi 113661 0 0.0 200 0 0 \n", "6 fake_rilimolo 114402 0 0.0 200 0 0 \n", "7 fake_gapudome 113891 0 0.0 200 0 0 \n", "8 fake_belobeva 113932 0 0.0 200 0 0 \n", "9 fake_rihatofi 113304 0 0.0 200 0 0 \n", "\n", " blinks_per_min fs duration_minutes start_min end_min \\\n", "0 0.0 1000.0 1.897200 0.0 1.897196 \n", "1 0.0 1000.0 1.907083 0.0 1.907083 \n", "2 0.0 1000.0 1.882950 0.0 1.882941 \n", "3 0.0 1000.0 1.905750 0.0 1.905735 \n", "4 0.0 1000.0 1.895533 0.0 1.895517 \n", "5 0.0 1000.0 1.894350 0.0 1.894346 \n", "6 0.0 1000.0 1.906700 0.0 1.906698 \n", "7 0.0 1000.0 1.898183 0.0 1.898178 \n", "8 0.0 1000.0 1.898867 0.0 1.898865 \n", "9 0.0 1000.0 1.888400 0.0 1.888393 \n", "\n", " baseline_estimated response_estimated \n", "0 False False \n", "1 False False \n", "2 False False \n", "3 False False \n", "4 False False \n", "5 False False \n", "6 False False \n", "7 False False \n", "8 False False \n", "9 False False " ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "pd.DataFrame([d.summary() for d in datasets])" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }