pypillometry 2.2.0__tar.gz → 2.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. {pypillometry-2.2.0/pypillometry.egg-info → pypillometry-2.2.1}/PKG-INFO +1 -1
  2. pypillometry-2.2.1/VERSION +1 -0
  3. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/__init__.py +5 -4
  4. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/epochs.py +11 -0
  5. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/events.py +130 -21
  6. pypillometry-2.2.1/pypillometry/example_data.py +353 -0
  7. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/eyedata/experimental_setup.py +36 -30
  8. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/eyedata/eyedata.py +1 -1
  9. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/eyedata/spatial_calibration.py +17 -19
  10. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/intervals.py +24 -19
  11. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/io.py +164 -1
  12. pypillometry-2.2.1/pypillometry/plot/_axes.py +84 -0
  13. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/plot/gaze.py +78 -81
  14. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/plot/generic.py +97 -103
  15. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/plot/pupil.py +85 -84
  16. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/roi.py +20 -22
  17. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/segmented.py +4 -2
  18. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/signal/pupil.py +22 -10
  19. {pypillometry-2.2.0 → pypillometry-2.2.1/pypillometry.egg-info}/PKG-INFO +1 -1
  20. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry.egg-info/SOURCES.txt +3 -0
  21. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_api_conventions.py +2 -2
  22. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_event_meta.py +82 -0
  23. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_events.py +3 -3
  24. pypillometry-2.2.1/tests/test_example_data.py +129 -0
  25. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_experimental_setup.py +10 -7
  26. pypillometry-2.2.1/tests/test_figshare.py +142 -0
  27. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_layer_stats.py +1 -1
  28. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_namespaces.py +3 -3
  29. pypillometry-2.2.1/tests/test_plotting_conventions.py +244 -0
  30. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_plotting_edge_cases.py +23 -28
  31. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_plotting_overlay.py +21 -27
  32. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_plotting_parameters.py +60 -73
  33. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_plotting_pdf.py +6 -6
  34. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_plotting_return_values.py +7 -8
  35. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_plotting_smoke.py +52 -46
  36. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_public_api.py +2 -0
  37. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_single_class.py +1 -1
  38. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_units.py +2 -2
  39. pypillometry-2.2.0/VERSION +0 -1
  40. pypillometry-2.2.0/pypillometry/example_data.py +0 -329
  41. pypillometry-2.2.0/tests/test_example_data.py +0 -67
  42. {pypillometry-2.2.0 → pypillometry-2.2.1}/LICENSE +0 -0
  43. {pypillometry-2.2.0 → pypillometry-2.2.1}/MANIFEST.in +0 -0
  44. {pypillometry-2.2.0 → pypillometry-2.2.1}/README.md +0 -0
  45. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/cli.py +0 -0
  46. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/config.py +0 -0
  47. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/convenience.py +0 -0
  48. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/data/002_rlmw_events_short.asc +0 -0
  49. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/data/002_rlmw_samples_short.asc +0 -0
  50. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/data/__init__.py +0 -0
  51. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/eyedata/__init__.py +0 -0
  52. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/eyedata/eyedatadict.py +0 -0
  53. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/eyedata/fake_eyedata.py +0 -0
  54. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/eyedata/foreshortening_calibration.py +0 -0
  55. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/eyedata/gaze.py +0 -0
  56. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/eyedata/history.py +0 -0
  57. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/eyedata/namespace.py +0 -0
  58. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/eyedata/pipes.py +0 -0
  59. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/eyedata/pupil.py +0 -0
  60. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/eyedata/steps.py +0 -0
  61. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/hdf5.py +0 -0
  62. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/logging.py +0 -0
  63. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/plot/__init__.py +0 -0
  64. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/quality.py +0 -0
  65. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/signal/__init__.py +0 -0
  66. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/signal/baseline.py +0 -0
  67. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/signal/fake.py +0 -0
  68. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/signal/preproc.py +0 -0
  69. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/stan/baseline_model_asym_laplac.stan +0 -0
  70. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/state.py +0 -0
  71. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/study.py +0 -0
  72. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/table.py +0 -0
  73. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/templates/__init__.py +0 -0
  74. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/templates/eyedata_repr.html +0 -0
  75. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/templates/quality_macros.html +0 -0
  76. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/templates/quality_page.html +0 -0
  77. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/templates/quality_report.html +0 -0
  78. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/templates/quality_summary.html +0 -0
  79. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/templates/repr_macros.html +0 -0
  80. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/templates/segmented_repr.html +0 -0
  81. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/units.py +0 -0
  82. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/viewer/__init__.py +0 -0
  83. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/viewer/canvas.py +0 -0
  84. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/viewer/navigation.py +0 -0
  85. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/viewer/tweak_canvas.py +0 -0
  86. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry/viewer/visuals.py +0 -0
  87. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry.egg-info/dependency_links.txt +0 -0
  88. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry.egg-info/entry_points.txt +0 -0
  89. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry.egg-info/requires.txt +0 -0
  90. {pypillometry-2.2.0 → pypillometry-2.2.1}/pypillometry.egg-info/top_level.txt +0 -0
  91. {pypillometry-2.2.0 → pypillometry-2.2.1}/pyproject.toml +0 -0
  92. {pypillometry-2.2.0 → pypillometry-2.2.1}/setup.cfg +0 -0
  93. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/__init__.py +0 -0
  94. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/format2/dict_of_eyedata.pypil +0 -0
  95. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/format2/eyedata.h5 +0 -0
  96. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/format2/eyedata.pypil +0 -0
  97. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/format2/gazedata.h5 +0 -0
  98. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/format2/gazedata.pypil +0 -0
  99. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/format2/make_fixtures.py +0 -0
  100. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/format2/manifest.json +0 -0
  101. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/format2/pupildata.h5 +0 -0
  102. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/format2/pupildata.pypil +0 -0
  103. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/format2/pupildata_uncompressed.pypil +0 -0
  104. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/format2/segmented.h5 +0 -0
  105. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/format2/segmented.pypil +0 -0
  106. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/a.blinks_detect.rlmw.default.npz +0 -0
  107. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/a.blinks_detect.rlmw.vel10.npz +0 -0
  108. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/a.blinks_detect.rlmw.zero.npz +0 -0
  109. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/a.blinks_detect.synth.default.npz +0 -0
  110. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/a.blinks_detect.synth.vel10.npz +0 -0
  111. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/a.blinks_detect.synth.zero.npz +0 -0
  112. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/b.blinks_interpolate.rlmw.npz +0 -0
  113. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/b.blinks_interpolate.synth.npz +0 -0
  114. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/c.lowpass.rlmw.npz +0 -0
  115. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/c.lowpass.synth.npz +0 -0
  116. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/d.divergence.rlmw.pct99.npz +0 -0
  117. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/d.divergence.rlmw.px100.npz +0 -0
  118. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/d.divergence.synth.pct99.npz +0 -0
  119. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/d.divergence.synth.px100.npz +0 -0
  120. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/d.offscreen.rlmw.npz +0 -0
  121. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/d.offscreen.synth.npz +0 -0
  122. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/e.segments.rlmw.interp.npz +0 -0
  123. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/e.segments.rlmw.raw.npz +0 -0
  124. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/e.segments.synth.interp.npz +0 -0
  125. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/e.segments.synth.raw.npz +0 -0
  126. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/e.stat_per_event.rlmw.interp.npz +0 -0
  127. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/e.stat_per_event.rlmw.raw.npz +0 -0
  128. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/e.stat_per_event.synth.interp.npz +0 -0
  129. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/e.stat_per_event.synth.raw.npz +0 -0
  130. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/f.quality.rlmw.interp.npz +0 -0
  131. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/f.quality.rlmw.raw.npz +0 -0
  132. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/f.quality.synth.interp.npz +0 -0
  133. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/f.quality.synth.raw.npz +0 -0
  134. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/g.crop.rlmw.npz +0 -0
  135. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/g.downsample.rlmw.100.npz +0 -0
  136. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/g.downsample.rlmw.250.npz +0 -0
  137. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/g.exclude_intervals.rlmw.npz +0 -0
  138. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/g.remove_intervals.rlmw.npz +0 -0
  139. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/h.merge_eyes.rlmw.npz +0 -0
  140. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/h.merge_eyes.synth.npz +0 -0
  141. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/h.scale.rlmw.npz +0 -0
  142. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/h.scale.synth.npz +0 -0
  143. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/make_reference.py +0 -0
  144. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/reference/reference.json +0 -0
  145. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/state/eyedata_v0.pkl +0 -0
  146. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/state/eyedata_v1.h5 +0 -0
  147. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/state/eyedata_v1.pypil +0 -0
  148. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/state/fakeeyedata_v0.pkl +0 -0
  149. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/state/gazedata_v0.pkl +0 -0
  150. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/state/make_v0_fixtures.py +0 -0
  151. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/state/pupildata_v0.pkl +0 -0
  152. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/state/segmented_v0.pkl +0 -0
  153. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/state/segmented_v1.h5 +0 -0
  154. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/data/test.edf +0 -0
  155. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_behaviour_events.py +0 -0
  156. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_channel_pairs.py +0 -0
  157. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_cli.py +0 -0
  158. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_convenience.py +0 -0
  159. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_epochs.py +0 -0
  160. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_excluded.py +0 -0
  161. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_eyedata.py +0 -0
  162. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_eyedata_events.py +0 -0
  163. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_eyedatadict.py +0 -0
  164. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_fake_data.py +0 -0
  165. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_foreshortening_calibration.py +0 -0
  166. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_format2_fixtures.py +0 -0
  167. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_gazedata.py +0 -0
  168. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_hdf5.py +0 -0
  169. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_import.py +0 -0
  170. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_import_time.py +0 -0
  171. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_inplace.py +0 -0
  172. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_intervals_class.py +0 -0
  173. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_intervals_spans.py +0 -0
  174. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_io.py +0 -0
  175. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_io_ssh.py +0 -0
  176. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_logging.py +0 -0
  177. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_mask_layers.py +0 -0
  178. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_migration.py +0 -0
  179. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_pipes.py +0 -0
  180. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_preproc.py +0 -0
  181. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_pupil.py +0 -0
  182. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_pupildata.py +0 -0
  183. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_quality.py +0 -0
  184. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_reference_outputs.py +0 -0
  185. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_response_valid.py +0 -0
  186. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_roi.py +0 -0
  187. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_segmented.py +0 -0
  188. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_state.py +0 -0
  189. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_study.py +0 -0
  190. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_suppress_output.py +0 -0
  191. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_templates.py +0 -0
  192. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_timebase.py +0 -0
  193. {pypillometry-2.2.0 → pypillometry-2.2.1}/tests/test_viewer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pypillometry
3
- Version: 2.2.0
3
+ Version: 2.2.1
4
4
  Summary: Pupillometry and Eye-tracking in Python.
5
5
  Author-email: Matthias Mittner <matthias.mittner@uit.no>
6
6
  License-Expression: MIT
@@ -0,0 +1 @@
1
+ v2.2.1
@@ -74,12 +74,12 @@ from .quality import QualityReport, QualityMetric
74
74
  # Reading and writing data
75
75
  from .io import (
76
76
  read_eyelink, read_file, write_file, download, fetch_url, local_copy,
77
- osf_authenticate,
77
+ osf_authenticate, get_figshare_files, fetch_figshare_file,
78
78
  )
79
79
  from .study import load_study_local, load_study_osf, get_osf_project_files
80
80
  from .example_data import (
81
81
  get_available_datasets, get_example_data, get_rlmw_002,
82
- get_rlmw_002_short, get_rlmw_010_edf,
82
+ get_rlmw_002_short, get_rlmw_010_edf, get_nback_001,
83
83
  )
84
84
 
85
85
  # ---------------------------------------------------------------------------
@@ -119,10 +119,11 @@ __all__ = [
119
119
  "QualityReport", "QualityMetric",
120
120
  # reading and writing data
121
121
  "read_eyelink", "read_file", "write_file", "download", "fetch_url",
122
- "local_copy", "osf_authenticate",
122
+ "local_copy", "osf_authenticate", "get_figshare_files",
123
+ "fetch_figshare_file",
123
124
  "load_study_local", "load_study_osf", "get_osf_project_files",
124
125
  "get_available_datasets", "get_example_data", "get_rlmw_002",
125
- "get_rlmw_002_short", "get_rlmw_010_edf",
126
+ "get_rlmw_002_short", "get_rlmw_010_edf", "get_nback_001",
126
127
  # viewer
127
128
  "view", "tweak",
128
129
  # units, settings and logging
@@ -280,6 +280,17 @@ class Epochs(Stateful):
280
280
  """
281
281
  return self._with_events(self.events.parse_labels(parser))
282
282
 
283
+ def merge_table(self, table, on, columns=None) -> 'Epochs':
284
+ """
285
+ Epochs with metadata from a table with one row per trial (see
286
+ :meth:`Events.merge_table <pypillometry.Events.merge_table>`).
287
+
288
+ Returns
289
+ -------
290
+ Epochs
291
+ """
292
+ return self._with_events(self.events.merge_table(table, on, columns))
293
+
283
294
  def to_intervals(self, units="ms", data=None):
284
295
  """
285
296
  The spans of the epochs as :class:`~pypillometry.Intervals`.
@@ -25,8 +25,21 @@ _RESERVED = ("onset", "label")
25
25
 
26
26
 
27
27
  def _is_missing(v) -> bool:
28
- """True for None and NaN (missing metadata values)."""
29
- return v is None or (isinstance(v, (float, np.floating)) and np.isnan(v))
28
+ """True for missing metadata values: None, NaN, "" and pandas' NA."""
29
+ return (v is None or (isinstance(v, (float, np.floating)) and np.isnan(v))
30
+ or (isinstance(v, str) and v == "") or type(v).__name__ == "NAType")
31
+
32
+
33
+ def _match_key(v):
34
+ """Value of `v` for matching rows (numbers as float, so 1 matches
35
+ 1.0); None for missing values."""
36
+ if _is_missing(v):
37
+ return None
38
+ if isinstance(v, (bool, np.bool_)):
39
+ return bool(v)
40
+ if isinstance(v, (int, float, np.integer, np.floating)):
41
+ return float(v)
42
+ return str(v)
30
43
 
31
44
 
32
45
  def _is_int(v) -> bool:
@@ -37,8 +50,8 @@ def _column_from_values(values) -> np.ndarray:
37
50
  """
38
51
  Metadata column from a list of values; None and NaN are missing.
39
52
 
40
- Without missing values, bools give a bool column and integers an int
41
- column. Otherwise, numbers give a float column (missing: NaN) and
53
+ Without missing values (None, NaN, "" or pandas' NA), bools give a
54
+ bool column and integers an int column. Otherwise, numbers give a float column (missing: NaN) and
42
55
  anything else a string column (missing: "").
43
56
  """
44
57
  present = [v for v in values if not _is_missing(v)]
@@ -182,7 +195,8 @@ class Events(Stateful):
182
195
  with one value per event. Missing values are NaN in numeric columns and "" in
183
196
  string columns. Metadata come from a behaviour log (see
184
197
  :meth:`from_table`), from the labels of the events (see
185
- :meth:`parse_labels`) or are added with :meth:`set_meta` and
198
+ :meth:`parse_labels`), from a table with one row per trial (see
199
+ :meth:`merge_table`) or are added with :meth:`set_meta` and
186
200
  :meth:`add_latency`; events are selected by their metadata with
187
201
  :meth:`filter`.
188
202
 
@@ -282,7 +296,8 @@ class Events(Stateful):
282
296
 
283
297
  A mapping of column name -> numpy array (one value per event). It
284
298
  cannot be changed in place; :meth:`set_meta`, :meth:`drop_meta`,
285
- :meth:`parse_labels`, :meth:`fill_meta` and :meth:`add_latency`
299
+ :meth:`parse_labels`, :meth:`merge_table`, :meth:`fill_meta` and
300
+ :meth:`add_latency`
286
301
  return new Events with changed metadata.
287
302
  """
288
303
  return MappingProxyType(self._meta)
@@ -757,8 +772,7 @@ class Events(Stateful):
757
772
 
758
773
  def _replace_column(self, name, values) -> 'Events':
759
774
  """New Events with column `name` set to `values` (list; None, NaN or "" = missing)."""
760
- values = [None if _is_missing(v) or (isinstance(v, str) and v == "") else v
761
- for v in values]
775
+ values = [None if _is_missing(v) else v for v in values]
762
776
  meta = dict(self.meta)
763
777
  meta[name] = _column_from_values(values)
764
778
  return Events(self.onsets, self.labels, units=self.units,
@@ -783,6 +797,94 @@ class Events(Stateful):
783
797
  data_time_range=self.data_time_range, meta=meta,
784
798
  needs_sync=self.needs_sync)
785
799
 
800
+ def merge_table(self, table, on, columns=None) -> 'Events':
801
+ r"""
802
+ Add metadata from a table with one row per trial.
803
+
804
+ Behaviour logs usually have one row per trial (e.g., stimulus,
805
+ response, reaction time). If the events already have metadata that
806
+ identify the trial (e.g., a "trial" column from
807
+ :meth:`parse_labels`), each event gets the values of the row with
808
+ the same values in the columns `on`, so all events of a trial
809
+ (e.g., fixation, stimulus and response) get the trial's data.
810
+
811
+ Unlike :meth:`from_table`, this does not create events and needs no
812
+ clock synchronization: the rows are matched by their values, not by
813
+ their times.
814
+
815
+ Parameters
816
+ ----------
817
+ table : pandas.DataFrame or dict
818
+ table with one row per trial
819
+ on : str or list of str
820
+ columns that identify a row; they must be metadata columns of
821
+ the events and columns of the table with the same names
822
+ columns : list or dict, optional
823
+ columns to add: list of column names, or dict mapping metadata
824
+ names to column names or to arrays of values (one per row);
825
+ default all columns of the table except `on`
826
+
827
+ Returns
828
+ -------
829
+ Events
830
+ new Events object with the columns added; events without a
831
+ matching row (e.g., events outside of the trials) get missing
832
+ values, or keep their values if the column exists already. Rows
833
+ without events are ignored.
834
+
835
+ Raises
836
+ ------
837
+ KeyError
838
+ if a column in `on` is not in the metadata or the table
839
+ ValueError
840
+ if several rows of the table have the same values in `on`
841
+
842
+ Examples
843
+ --------
844
+ >>> ev = Events([0, 100, 400, 1000], ["start", "S_1", "R_1", "S_2"])
845
+ >>> ev = ev.parse_labels(r"_(?P<trial>\d+)")
846
+ >>> log = {"trial": [1, 2], "cond": ["easy", "hard"], "rt": [0.3, np.nan]}
847
+ >>> ev = ev.merge_table(log, on="trial")
848
+ >>> ev.meta["cond"]
849
+ array(['', 'easy', 'easy', 'hard'], dtype='<U4')
850
+ >>> ev.meta["rt"]
851
+ array([nan, 0.3, 0.3, nan])
852
+ """
853
+ on = [on] if isinstance(on, str) else list(on)
854
+ for name in on:
855
+ if name not in self.meta:
856
+ raise KeyError(f"no metadata column '{name}'")
857
+ if name not in table:
858
+ raise KeyError(f"no column '{name}' in the table")
859
+ if columns is None:
860
+ columns = [name for name in table if name not in on]
861
+ if not isinstance(columns, dict):
862
+ columns = {name: name for name in columns}
863
+ for name in columns:
864
+ _as_column([], 0, name) # check the name
865
+
866
+ # row of the table for each combination of values in `on`
867
+ rows = {}
868
+ for i, key in enumerate(zip(*(map(_match_key, table[k]) for k in on))):
869
+ if None in key:
870
+ continue
871
+ if key in rows:
872
+ raise ValueError(f"rows {rows[key]} and {i} of the table have "
873
+ f"the same values: {dict(zip(on, key))}")
874
+ rows[key] = i
875
+ match = [rows.get(key) for key in
876
+ zip(*(map(_match_key, self.meta[k].tolist()) for k in on))]
877
+
878
+ values = {}
879
+ for name, col in columns.items():
880
+ vals = list(table[col] if isinstance(col, str) else col)
881
+ if len(vals) != len(table[on[0]]):
882
+ raise ValueError(f"'{name}' has {len(vals)} values, expected "
883
+ f"{len(table[on[0]])} (one per row)")
884
+ values[name] = [None if r is None or _is_missing(vals[r]) else vals[r]
885
+ for r in match]
886
+ return self._with_columns(values)
887
+
786
888
  def fill_meta(self, columns, by: str = "trial") -> 'Events':
787
889
  """
788
890
  Copy metadata to all events with the same value in column `by`.
@@ -826,10 +928,9 @@ class Events(Stateful):
826
928
  for name in columns:
827
929
  if name not in self.meta:
828
930
  raise KeyError(f"no metadata column '{name}'")
829
- vals = [None if _is_missing(v) or v == "" else v
830
- for v in self.meta[name].tolist()]
931
+ vals = [None if _is_missing(v) else v for v in self.meta[name].tolist()]
831
932
  for g in np.unique(group):
832
- if _is_missing(g) or g == "": # events without a group
933
+ if _is_missing(g): # events without a group
833
934
  continue
834
935
  ix = np.flatnonzero(group == g)
835
936
  present = {vals[i] for i in ix if vals[i] is not None}
@@ -890,7 +991,7 @@ class Events(Stateful):
890
991
  raise KeyError(f"no metadata column '{by}'")
891
992
  col = self.meta[by]
892
993
  groups = [(i1[col[i1] == v], i2[col[i2] == v])
893
- for v in np.unique(col[i1]) if not (_is_missing(v) or v == "")]
994
+ for v in np.unique(col[i1]) if not _is_missing(v)]
894
995
  latency = np.full(len(self), np.nan)
895
996
  for g1, g2 in groups:
896
997
  pairs, _, _ = _pair_with_next(self.onsets[g1], self.onsets[g2])
@@ -1068,6 +1169,8 @@ class Events(Stateful):
1068
1169
  show_labels: str = "auto",
1069
1170
  marker: str = ".",
1070
1171
  units: Optional[str] = "sec",
1172
+ title: Optional[str] = None,
1173
+ ax=None,
1071
1174
  **kwargs,
1072
1175
  ):
1073
1176
  """
@@ -1082,13 +1185,17 @@ class Events(Stateful):
1082
1185
  Matplotlib marker style for the events (default '.').
1083
1186
  units : str or None, optional
1084
1187
  Units to display in the plot. Defaults to "sec". Use None to keep existing units.
1188
+ title : str, optional
1189
+ title of the plot
1190
+ ax : matplotlib.axes.Axes, optional
1191
+ axes to plot on; default: the current axes
1085
1192
  **kwargs :
1086
- Additional keyword arguments passed to :func:`matplotlib.axes.Axes.plot`.
1193
+ Additional keyword arguments passed to :meth:`matplotlib.axes.Axes.plot`.
1087
1194
 
1088
1195
  Returns
1089
1196
  -------
1090
- None
1091
- Plot is drawn on the current matplotlib axes.
1197
+ matplotlib.axes.Axes
1198
+ the axes of the plot
1092
1199
 
1093
1200
  Examples
1094
1201
  --------
@@ -1099,15 +1206,17 @@ class Events(Stateful):
1099
1206
  >>> import pypillometry as pp
1100
1207
  >>> import matplotlib.pyplot as plt
1101
1208
  >>> d = pp.get_example_data("rlmw_002_short")
1102
- >>> fig = plt.figure(figsize=(10, 3))
1103
- >>> d.events.filter("S_").plot(units="sec")
1209
+ >>> fig, ax = plt.subplots(figsize=(10, 3))
1210
+ >>> ax = d.events.filter("S_").plot(units="sec", ax=ax)
1104
1211
  """
1105
- import matplotlib.pyplot as plt
1212
+ from .plot._axes import get_ax
1106
1213
 
1107
1214
  if show_labels not in {"auto", "all", "none"}:
1108
1215
  raise ValueError("show_labels must be one of {'auto', 'all', 'none'}")
1109
1216
 
1110
- ax = plt.gca()
1217
+ ax = get_ax(ax)
1218
+ if title is not None:
1219
+ ax.set_title(title)
1111
1220
 
1112
1221
  target_units = units if units is not None else self.units
1113
1222
  if target_units != self.units:
@@ -1122,7 +1231,7 @@ class Events(Stateful):
1122
1231
 
1123
1232
  if len(self) == 0:
1124
1233
  ax.set_ylim(0, 1)
1125
- return
1234
+ return ax
1126
1235
 
1127
1236
  y_positions = np.arange(1, len(self) + 1)
1128
1237
 
@@ -1184,7 +1293,7 @@ class Events(Stateful):
1184
1293
  rotation_mode="anchor",
1185
1294
  )
1186
1295
  last_label_x = onset
1187
- return
1296
+ return ax
1188
1297
 
1189
1298
  def filter(self, selector=None, exact: bool = False, **conditions) -> 'Events':
1190
1299
  """
@@ -0,0 +1,353 @@
1
+ """
2
+ example_data.py
3
+ ===============
4
+
5
+ Example datasets for pypillometry.
6
+
7
+ This module provides example datasets for pypillometry. The datasets are
8
+ used in the documentation and for testing purposes. Most of them are stored on
9
+ OSF (https://osf.io/p2u74/) or figshare
10
+ (https://figshare.com/articles/dataset/Example_pypillometry_dataset/28776617).
11
+ """
12
+
13
+ import numpy as np
14
+ from .eyedata import EyeData
15
+ from .table import RecordDict
16
+ from importlib.resources import files
17
+ import inspect
18
+ import os
19
+ import os.path
20
+ from .io import fetch_url, fetch_figshare_file
21
+ from .convenience import _user_cache_dir
22
+
23
+ __all__ = [
24
+ "get_available_datasets", "get_example_data", "get_rlmw_002",
25
+ "get_rlmw_002_short", "get_rlmw_010_edf", "get_nback_001",
26
+ ]
27
+
28
+ example_datasets = {
29
+ "rlmw_002": {
30
+ "source": "OSF",
31
+ "filetype": "asc",
32
+ "files": {
33
+ "samples": "https://osf.io/download/67cec1a4fb24855200fd6db7/",
34
+ "events": "https://osf.io/download/67cec1a183c337a5effd6fb6/",
35
+ },
36
+ "description":"Binocular data from a 20-minute reinforcement learning task. "
37
+ "Data from a single participant, features strong horizontal eye-movements "
38
+ "between the two stimuli presented on the left and right.",
39
+ },
40
+ "rlmw_002_short": {
41
+ "source": "local",
42
+ "filetype": "asc",
43
+ "files": {
44
+ "samples": files('pypillometry.data').joinpath('002_rlmw_samples_short.asc'),
45
+ "events": files('pypillometry.data').joinpath('002_rlmw_events_short.asc'),
46
+ },
47
+ "description":"Short version (first 40 sec) of a 20-minute reinforcement learning task. "
48
+ "Data from a single participant, features strong horizontal eye-movements "
49
+ "between the two stimuli presented on the left and right.",
50
+ },
51
+ "rlmw_010_edf": {
52
+ "source": "OSF",
53
+ "filetype": "edf",
54
+ "files": {"data": "https://osf.io/trsuq/download"},
55
+ "description":"Binocular data from a 20-minute reinforcement learning task "
56
+ "in EDF (Eyelink) format. "
57
+ "Data from a single participant, features strong horizontal eye-movements "
58
+ "between the two stimuli presented on the left and right.",
59
+ },
60
+ "nback_001": {
61
+ "source": "figshare",
62
+ "filetype": "pkl",
63
+ "figshare": {"id": 28776617, "version": 1},
64
+ # names in the figshare item
65
+ "files": {"data": "sub-001_ses-1.pypil", "behaviour": "sub-001_ses-1.csv"},
66
+ "description": "Binocular data from a 56-minute N-back task "
67
+ "(0-, 1- and 2-back blocks in three runs with grey, black and white "
68
+ "screen background), saved as a pypillometry file. "
69
+ "Data from a single participant, with events for fixation, stimulus "
70
+ "and response in each trial; the behavioural data (stimulus, "
71
+ "response, accuracy, reaction time) are in the events' metadata.",
72
+ },
73
+ }
74
+
75
+ class DatasetDict(RecordDict):
76
+ """The example datasets: name -> properties (description, files).
77
+
78
+ A dict that is displayed as a table with the name, source (OSF,
79
+ figshare, local, ssh), file type (asc, edf, pkl, hdf5) and description
80
+ of each dataset (see :class:`~pypillometry.RecordDict`).
81
+ """
82
+
83
+ def __init__(self, data=None):
84
+ super().__init__(data, index_names=("dataset",))
85
+
86
+ def _rows(self) -> list:
87
+ rows = []
88
+ for key, info in self.items():
89
+ rows.append(((key,), {"source": info.get("source", "unknown"),
90
+ "filetype": info.get("filetype", "unknown"),
91
+ "description": info.get("description", "")}))
92
+ return rows
93
+
94
+
95
+ def get_available_datasets():
96
+ """Return available example datasets.
97
+
98
+ Returns a dict (name -> properties) that is displayed as a table.
99
+
100
+ Returns
101
+ -------
102
+ DatasetDict
103
+ dataset name -> its properties (source, file type, description,
104
+ files); displayed as a table with the name, source, file type and
105
+ description of each dataset
106
+
107
+ Examples
108
+ --------
109
+ >>> datasets = get_available_datasets()
110
+ >>> datasets # in Jupyter, this displays as a table # doctest: +SKIP
111
+ >>> "rlmw_002_short" in datasets # but it is a normal dict
112
+ True
113
+ >>> datasets["rlmw_002"]["description"][:30]
114
+ 'Binocular data from a 20-minut'
115
+ """
116
+ return DatasetDict(example_datasets)
117
+
118
+ def get_example_data(key, cache_dir=None):
119
+ """Load example data for a given example (see `example_datasets`).
120
+
121
+ Parameters
122
+ ----------
123
+ key : str
124
+ Key of the example dataset. Available keys are in the dictionary
125
+ `example_datasets`.
126
+ cache_dir : str, optional
127
+ directory to store downloaded files in (reused in later calls);
128
+ default ``$XDG_CACHE_HOME/pypillometry`` (``~/.cache/pypillometry``).
129
+ Ignored for datasets included in the package.
130
+
131
+ Returns
132
+ -------
133
+ EyeData
134
+ The example dataset.
135
+ """
136
+ if key not in example_datasets:
137
+ raise ValueError(f"Key '{key}' not found in example datasets. "
138
+ f"Available keys are: {list(example_datasets.keys())}. "
139
+ f"Call get_available_datasets() to see all available datasets.")
140
+
141
+ # run the function with the same name as the key
142
+ funcname = f"get_{key}"
143
+ if funcname in globals():
144
+ func = globals()[funcname]
145
+ kwargs = {}
146
+ if "cache_dir" in inspect.signature(func).parameters:
147
+ kwargs["cache_dir"] = cache_dir
148
+ import warnings
149
+ with warnings.catch_warnings():
150
+ warnings.simplefilter(action='ignore')
151
+ r = func(**kwargs)
152
+ return r
153
+ else:
154
+ raise ValueError(f"Function '{funcname}' not found in example datasets.")
155
+
156
+
157
+ def _read_rlmw_asc(fname_samples, fname_events, name):
158
+ """EyeData from the samples and events ASC files of the "rlmw" task.
159
+
160
+ Events are the "MSG" lines after "experiment_start"; missing values
161
+ (" ." for gaze, 0 for pupil) are set to NaN; time is reset to start
162
+ at 0 and the original data are kept (`keep_orig=True`).
163
+ """
164
+ import pandas as pd
165
+ from .eyedata.experimental_setup import ExperimentalSetup
166
+
167
+ df = pd.read_table(fname_samples, index_col=False,
168
+ names=["time", "left_x", "left_y", "left_p",
169
+ "right_x", "right_y", "right_p"])
170
+
171
+ # Eyelink puts " ." when no gaze position is available
172
+ def gaze(col):
173
+ x = df[col].values
174
+ x[x == " ."] = np.nan
175
+ return x.astype(float)
176
+
177
+ # Eyelink codes missing pupil data (e.g., blinks) as 0
178
+ def pupil(col):
179
+ return np.where(df[col] == 0, np.nan, df[col])
180
+
181
+ # events: the "MSG" lines after "experiment_start"
182
+ with open(fname_events) as f:
183
+ events = [ev for ev in f if ev.startswith("MSG")]
184
+ start = np.where(["experiment_start" in ev for ev in events])[0][0]
185
+ df_ev = pd.DataFrame([ev.split() for ev in events[start + 1:]])[[1, 2]]
186
+ df_ev.columns = ["time", "event"]
187
+
188
+ setup = ExperimentalSetup(
189
+ screen_resolution=(1280, 1024),
190
+ physical_screen_size=("30 cm", "20 cm"),
191
+ eye_to_screen_center="60 cm",
192
+ )
193
+ return EyeData(time=df.time, name=name,
194
+ experimental_setup=setup,
195
+ left_x=gaze("left_x"), left_y=gaze("left_y"),
196
+ left_pupil=pupil("left_p"),
197
+ right_x=gaze("right_x"), right_y=gaze("right_y"),
198
+ right_pupil=pupil("right_p"),
199
+ event_onsets=df_ev.time, event_labels=df_ev.event,
200
+ keep_orig=True).reset_time()
201
+
202
+
203
+ def get_rlmw_002(cache_dir=None):
204
+ """Load the "rlmw_002" example dataset (downloaded from OSF).
205
+
206
+ Binocular gaze and pupil data from a 20-minute reinforcement learning
207
+ task (single participant). The ASC files are downloaded into
208
+ `cache_dir` on the first call and reused later. Events are the "MSG" lines after
209
+ "experiment_start"; missing pupil samples (coded as 0 by Eyelink) are
210
+ set to NaN; time is reset to start at 0 and the original data
211
+ are kept (`keep_orig=True`). Usually called via
212
+ :func:`~pypillometry.get_example_data`.
213
+
214
+ Parameters
215
+ ----------
216
+ cache_dir : str, optional
217
+ directory for the downloaded files; default
218
+ ``$XDG_CACHE_HOME/pypillometry`` (``~/.cache/pypillometry``)
219
+
220
+ Returns
221
+ -------
222
+ EyeData
223
+ the example dataset
224
+ """
225
+ cache_dir = cache_dir or _user_cache_dir()
226
+ urls = example_datasets["rlmw_002"]["files"]
227
+ fname_samples = fetch_url(urls["samples"],
228
+ cache_file=os.path.join(cache_dir, "002_rlmw_samples.asc"))
229
+ fname_events = fetch_url(urls["events"],
230
+ cache_file=os.path.join(cache_dir, "002_rlmw_events.asc"))
231
+ return _read_rlmw_asc(fname_samples, fname_events, "rlmw_002")
232
+
233
+
234
+ def get_rlmw_002_short():
235
+ """Load the "rlmw_002_short" example dataset (included in the package).
236
+
237
+ Short version (first 40 sec) of the "rlmw_002" dataset: binocular gaze
238
+ and pupil data from a reinforcement learning task. No download is
239
+ needed. Events are the "MSG" lines after "experiment_start"; missing
240
+ pupil samples (coded as 0 by Eyelink) are set to NaN; time is
241
+ reset to start at 0 and the original data are kept (`keep_orig=True`).
242
+ Usually called via :func:`~pypillometry.get_example_data`.
243
+
244
+ Returns
245
+ -------
246
+ EyeData
247
+ the example dataset
248
+ """
249
+ paths = example_datasets["rlmw_002_short"]["files"]
250
+ return _read_rlmw_asc(paths["samples"], paths["events"], "rlmw_002_short")
251
+
252
+
253
+ def get_rlmw_010_edf(cache_dir=None):
254
+ """Load the "rlmw_010_edf" example dataset (downloaded from OSF).
255
+
256
+ Binocular gaze and pupil data from a 20-minute reinforcement learning
257
+ task (single participant) in EDF (Eyelink) format, read with
258
+ :meth:`~pypillometry.EyeData.from_eyelink`. The EDF file is downloaded
259
+ into `cache_dir` on the first call and reused later. Usually called via
260
+ :func:`~pypillometry.get_example_data`.
261
+
262
+ Parameters
263
+ ----------
264
+ cache_dir : str, optional
265
+ directory for the downloaded files; default
266
+ ``$XDG_CACHE_HOME/pypillometry`` (``~/.cache/pypillometry``)
267
+
268
+ Returns
269
+ -------
270
+ EyeData
271
+ the example dataset
272
+ """
273
+ cache_dir = cache_dir or _user_cache_dir()
274
+ fname = fetch_url(example_datasets["rlmw_010_edf"]["files"]["data"],
275
+ cache_file=os.path.join(cache_dir, "010_rlmw.edf"))
276
+ d = EyeData.from_eyelink(fname)
277
+ d.name = "rlmw_010"
278
+ d.set_experimental_setup(
279
+ physical_screen_size=("30 cm", "20 cm"),
280
+ eye_to_screen_center="60 cm",
281
+ )
282
+ return d
283
+
284
+
285
+ def get_nback_001(cache_dir=None):
286
+ """Load the "nback_001" example dataset (downloaded from figshare).
287
+
288
+ Binocular gaze and pupil data from a 56-minute N-back task (single
289
+ participant), saved as a pypillometry file. Events mark fixation,
290
+ stimulus and response in each trial (e.g.,
291
+ ``run-1_scr-grey_block-1_task-0b_trial-1_stim_target-1``).
292
+
293
+ The behavioural log of the task is merged into the events' metadata
294
+ (see :attr:`Events.meta <pypillometry.Events.meta>`): ``run``,
295
+ ``screen``, ``block``, ``task`` (``0b``, ``1b``, ``2b`` or ``p``) and
296
+ ``trial`` are parsed from the labels, and ``stimulus``, ``target``,
297
+ ``response``, ``accuracy`` and ``rt`` (reaction time in s) are added to
298
+ all events of each trial. The log's header (date, ambient light, ...)
299
+ is in ``d.info["behaviour_log"]``.
300
+
301
+ The files are downloaded into `cache_dir` on the first call and reused
302
+ later. Usually called via :func:`~pypillometry.get_example_data`. The
303
+ tutorial :doc:`/notebooks/case_study_nback` analyses this dataset.
304
+
305
+ Parameters
306
+ ----------
307
+ cache_dir : str, optional
308
+ directory for the downloaded files; default
309
+ ``$XDG_CACHE_HOME/pypillometry`` (``~/.cache/pypillometry``)
310
+
311
+ Returns
312
+ -------
313
+ EyeData
314
+ the example dataset
315
+ """
316
+ import pandas as pd
317
+ info = example_datasets["nback_001"]
318
+ figshare_id, version = info["figshare"]["id"], info["figshare"]["version"]
319
+ cache_dir = cache_dir or _user_cache_dir()
320
+
321
+ # download the files from figshare (or use the cached copies)
322
+ fname_data = fetch_figshare_file(figshare_id, info["files"]["data"],
323
+ version=version, cache_dir=cache_dir,
324
+ cache_layout="mirror")
325
+ fname_log = fetch_figshare_file(figshare_id, info["files"]["behaviour"],
326
+ version=version, cache_dir=cache_dir,
327
+ cache_layout="mirror")
328
+
329
+ # eye-tracking data, saved with pypillometry
330
+ d = EyeData.from_file(fname_data)
331
+ d.name = "nback_001"
332
+
333
+ # behavioural log: a header of "# key: value" lines, then one row per trial
334
+ with open(fname_log) as f:
335
+ comments = [line.lstrip("# ").strip() for line in f if line.startswith("#")]
336
+ d.info["behaviour_log"] = dict(c.split(": ", 1) for c in comments if ": " in c)
337
+ log = pd.read_csv(fname_log, comment="#")
338
+
339
+ # run, screen, block, task and trial from the event labels, e.g.
340
+ # "run-1_scr-grey_block-1_task-0b_trial-1_stim_target-1"
341
+ events = (d.events.parse_labels(r"run-(?P<run>\d+)")
342
+ .parse_labels(r"scr-(?P<screen>[a-z]+)")
343
+ .parse_labels(r"block-(?P<block>\d+)")
344
+ .parse_labels(r"task-(?P<task>[^_]+)")
345
+ .parse_labels(r"trial-(?P<trial>\d+)"))
346
+
347
+ # add each trial's row of the log to all its events (fixation, stimulus,
348
+ # response), matched by run, block, task and trial
349
+ events = events.merge_table(
350
+ log, on=["run", "block", "task", "trial"],
351
+ columns=["stimulus", "target", "response", "accuracy", "rt"])
352
+ d.set_events(events)
353
+ return d