{ "info": { "author": "Yiorgos Christakis", "author_email": "elyiorgos@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2.7" ], "description": "# SleepPy\nA Python(2.7) package for sleep analysis from accelerometer data\n\n## Overview\nMeasures of sleep quality and quantity can provide valuable insights into the health and well-being of an individual. \nTraditionally, sleep assessments are performed in the clinic/hospital setting using polysomnography tests. \nRecent advances in wearable sensor technology have enabled objective assessment of sleep at home. \nActigraphy has been widely used for this purpose and several algorithms have been published in the literature \nover the years. However, implementation of these algorithms is not widely available, which creates a barrier for wider \nadoption of wearable devices in clinical research.\n\n``SleepPy`` is an open source python package incorporating several published algorithms in a modular framework and \nproviding a suite of measures for the assessment of sleep quantity and quality. The package can process multi-day \nstreams of raw accelerometer data (X, Y & Z) from wrist-worn wearable devices to produce sleep reports and \nvisualizations for each recording day (24-hour period). The reports are formatted to facilitate statistical \nanalysis of sleep measures. Visualization acts as a quick debugging tool, provides insights into sleep patterns of \nindividual subjects and can be used for presentation of data to diverse audiences.\n\n## Requirements\n``SleepPy`` can be installed through pip, which will handle requirement installation for you (please note that SleepPy \nwill use specific versions of all required packages, to avoid possible issues with your existing environments \nwe suggest using a [virtual environment](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/)):\n\n```sh\npip install sleeppy\n```\n\nIt can also be installed from source:\n\n```sh\ngit clone https://github.com/elyiorgos/sleeppy.git\ncd sleeppy\npython setup.py install\n```\n\nIf given a permissions error, you may have to run the following and input your password:\n\n```sh\nsudo python setup.py install\n```\n\nIf necessary the listed requirements can be installed as follows:\n\n```sh\npip install -r requirements.txt\n```\n\n\n## What does SleepPy do?\n``SleepPy`` follows seven steps when processing data:\n\n1.\tSplit data by day: Load raw accelerometer data from input file and split it into 24-hour segments (noon to noon).\n\n2.\tDerive activity index: Calculate activity index for each 1 minute epoch of the day.\n\n3.\tPerform off-body detection: Run off-body detection algorithm and generate a label (on or off body) for each 15 \nminute epoch of the day.\n\n4.\tIdentify major rest period: Estimate the major rest period (i.e. sleep window) for each day.\n\n5.\tPerform sleep/wake classification: Run sleep/wake classification algorithm to generate sleep/wake labels for each \n1 minute epoch of the day.\n\n6.\tCalculate sleep measures: Calculate sleep measures based on sleep/wake states only during the major rest period for \neach day.\n\n7.\tGenerate reports and visualizations: Create a set of tables and charts for analysis and presentation of processed \noutputs and sleep measures for each day.\n\n## How to run SleepPy\nSleepPy is designed for ease of use in a research environment, and therefore attempts to remove as much of the burden \nas possible from the user. The following syntax will run ``SleepPy`` in full and generate all necessary data and \nreports, saving all intermediate data in various folders. ``SleepPy`` can be run with both GeneActiv .bin files, as \nwell as the raw .csv outputs of the GeneActiv software. Processing the .bin files adds a non trivial amount of \nprocessing time to the running of SleepPy, and for quick results we recommend using the .csv version where possible.\n\n```sh\nfrom sleeppy.sleep import *\n\nSleepPy(input_file='/Users/user/input_files/data.csv',\n results_directory='/Users/user/Results/',\n sampling_frequency=100)\n```\n\n``SleepPy`` can also be run with the following arguments. Start and stop buffer allow for the specification of ignored \ntime at the beginning and end of the GeneActiv file. If a research site knows, for instance, that the watch will not be \non the subject for one hour at the beginning and end of the recorded session, that data can be excluded. The same can \nalso be done with the start and stop time arguments, which allow for the specification of a date and time for starting \nand stopping the analysis. A description of the purpose and formats for these, and other arguments can be found in the \nsleep.py docs.\n\n```sh\nfrom sleeppy.sleep import *\n\nSleepPy(input_file='/Users/user/input_files/data.csv',\n results_directory='/Users/user/Results/',\n sampling_frequency=100,\n start_buffer=\"0s\",\n stop_buffer=\"0s\",\n start_time=\"\",\n stop_time=\"\",\n run_config=0,\n temperature_threshold=25.0,\n minimum_rest_block=30,\n allowed_rest_break=60,\n minimum_rest_threshold=0.0,\n maximum_rest_threshold=1000.0,\n minimum_hours=6,\n clear_intermediate_data=False,\n aws_object=None,\n```\n\n## Running the demo files\n#### Try it out with binder\n[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/elyiorgos/sleeppy/master?filepath=example_notebook%2Fexample.ipynb)\n\n#### From the terminal window you can run the demo directly:\n\n```sh\ncd sleeppy/sleeppy/tests\npython demo.py\n```\n\n#### You can also run the demo through the python interpreter:\n\nAssuming you've installed the package, in the terminal window start python simply by typing \n\n```sh\npython\n```\n\nIn the interpreter window you can then import and run the demo with the following two commands:\n\n```sh\n>>> import sleeppy.tests as demo\n>>> demo.run_demo()\n```\n\nThe demo script will prompt you to type in a results directory, if simply testing you can type something like \n/Users/username/Desktop to have the results saved to your desktop.\n\nAny of the above should take approximately 10-15 minutes, though depending on your machine this may vary. It should \ngenerate and save all intermediate data, as well as all the relevant reports. Due to file size constraints, the demo \nfile type is .bin which adds a nontrivial amount to the processing time.\n\n## Interpreting the results\nThe most informative reports are the reports provided for each individual day, which resemble the image below (demo report):\n\n![Demo Report](https://raw.githubusercontent.com/elyiorgos/sleeppy/master/images/Visual_Results_Day_1_demo.png)\n\nAs shown above, the report includes the source file name, the number of the day in the series of days provided, the \nstart date of the data being shown, and a table of all calculated endpoints. Below the table is a graph of the data \navailable during the 24-hour window specified. The subplots are set up to show the multiple forms that the data can \ntake during the analysis. They are layed out as follows:\n\n1.\tXYZ: The raw tri-axial accelerometer signals (X, Y, and Z).\n\n2. Temperature: The near-body temperature reading of the wrist-worn device.\n\n3. Light: The light reading of the wrist-worn device over the specified period.\n\n4.\tActivity index: The minute-by-minute activity index values, which reflect the intensity \nof activity for each minute.\n\n5.\tArm-angle: The arm-angle over 24 hours, this data stream is used to determine the \nmajor rest period.\n\n6.\tWake: The sleep/wake classification for the entire day. However, sleep measures are \ncomputed during the major rest period only.\n\n7.\tRest periods: All rest periods detected by the algorithm. Only the longest rest \nperiod (i.e. major rest period) is used for calculating sleep measures.\n\n8.\tOn-body: All periods identified by the on-body detection algorithm (without filtering \nor re-scoring).\n\n9.\tOn-body (re-scored): The on-body periods after re-scoring has been applied.\n\n#### Note: There is no logic tying either on-body detection to the calculation of sleep endpoints. The on-body detection is currently used *only* as a visual aid to determine possible sources of error in major rest period calculation.\n\n#### Suggested use of the current package is to evaluate the results of each day visually, to ensure that the proper/expected behavior is in fact what is being produced.\n\n## References\n#### The major rest period detection and wear detection functions of this package are based off of the following papers, as well as their implementation in the R package GGIR:\n\nvan Hees V, Fang Z, Zhao J, Heywood J, Mirkes E, Sabia S, Migueles J (2019). GGIR: Raw Accelerometer Data Analysis.\ndoi: 10.5281/zenodo.1051064, R package version 1.9-1, https://CRAN.R-project.org/package=GGIR.\n\nvan Hees V, Fang Z, Langford J, Assah F, Mohammad Mirkes A, da Silva I, Trenell M, White T, Wareham N, Brage S (2014).\n'Autocalibration of accelerometer data or free-living physical activity assessment using local gravity and\ntemperature: an evaluation on four continents.' Journal of Applied Physiology, 117(7), 738-744.\ndoi: 10.1152/japplphysiol.00421.2014, https://www.physiology.org/doi/10.1152/japplphysiol.00421.2014\n\nvan Hees V, Sabia S, Anderson K, Denton S, Oliver J, Catt M, Abell J, Kivimaki M, Trenell M, Singh-Maoux A (2015).\n'A Novel, Open Access Method to Assess Sleep Duration Using a Wrist-Worn Accelerometer.' PloS One, 10(11).\ndoi: 10.1371/journal.pone.0142533, http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0142533.\n\n#### The detection of sleep and wake states uses a heuristic model based on the algorithm described in:\n\nCole, R.J., Kripke, D.F., Gruen, W.'., Mullaney, D.J., & Gillin, J.C. (1992). Automatic sleep/wake identification\nfrom wrist activity. Sleep, 15 5, 461-9.\n\n#### The activity index feature is based on the index described in:\n\nBai J, Di C, Xiao L, Evenson KR, LaCroix AZ, Crainiceanu CM, et al. (2016) An Activity Index for Raw Accelerometry\nData and Its Comparison with Other Activity Metrics. PLoS ONE 11(8): e0160644.\nhttps://doi.org/10.1371/journal.pone.0160644\n\n## Contributing to the project\nWe welcome and encourage project contributions! Please see the [CONTRIBUTING.md](https://github.com/elyiorgos/sleeppy/blob/master/CONTRIBUTING.md) file for details.\n\n## Acknowledgements\nThe Digital Medicine & Translational Imaging group at Pfizer, Inc supported the development of this package.\n\n## Author\nYiorgos Christakis\n\n## License\nThis project is licensed under the MIT License - see the [LICENSE.md](https://github.com/elyiorgos/sleeppy/blob/master/LICENSE.md) file for details\n\n\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/elyiorgos/sleeppy", "keywords": "sleep,wake,sensor,digital,wearable,python,rest,period,christakis", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "sleeppy", "package_url": "https://pypi.org/project/sleeppy/", "platform": "", "project_url": "https://pypi.org/project/sleeppy/", "project_urls": { "Homepage": "http://github.com/elyiorgos/sleeppy" }, "release_url": "https://pypi.org/project/sleeppy/0.2.21/", "requires_dist": [ "pandas (==0.23.4)", "numpy (==1.16.4)", "matplotlib (==2.2.4)", "scipy (==1.2.2)", "seaborn (==0.9.0)", "bitstring (==3.1.5)", "argparse (==1.1)", "tables (==3.5.2)" ], "requires_python": "", "summary": "Python package for sleep analysis of raw accelerometer data from GeneActiv wrist watches", "version": "0.2.21", "yanked": false, "yanked_reason": null }, "last_serial": 6267723, "releases": { "0.2.0": [ { "comment_text": "", "digests": { "md5": "4f4756f611d83fbae692767159e31e9d", "sha256": "90d66d9d471b95aedb8198895bb92b8c3385c6f866382fd49975fbd79ea6476f" }, "downloads": -1, "filename": "sleeppy-0.2.0-py2-none-any.whl", "has_sig": false, "md5_digest": "4f4756f611d83fbae692767159e31e9d", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 19894, "upload_time": "2019-10-21T15:50:59", "upload_time_iso_8601": "2019-10-21T15:50:59.254778Z", "url": "https://files.pythonhosted.org/packages/44/41/afee7ee7571175e30d9ca8220178614e3ce1489cc7177e746b5e3cdbf64d/sleeppy-0.2.0-py2-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "67218ac7a25e53bb1d732d325a654b2a", "sha256": "97f351c323297060f0c31bad0dbef77895feba5662c7e196e4a0bf793bb5bff5" }, "downloads": -1, "filename": "sleeppy-0.2.1-py2-none-any.whl", "has_sig": false, "md5_digest": "67218ac7a25e53bb1d732d325a654b2a", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 19925, "upload_time": "2019-10-24T14:45:16", "upload_time_iso_8601": "2019-10-24T14:45:16.965544Z", "url": "https://files.pythonhosted.org/packages/d4/72/75ae09e6e2de91766cf840ba091575e33c1a2d7c2f60f6b3b86c8e33d8b2/sleeppy-0.2.1-py2-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.2.21": [ { "comment_text": "", "digests": { "md5": "c94efa93bb6efcbc348c399fb880b558", "sha256": "d77a1267816ea937b869fae6e890bb20105fc1fa4e883ba059cb245e88143460" }, "downloads": -1, "filename": "sleeppy-0.2.21-py2-none-any.whl", "has_sig": false, "md5_digest": "c94efa93bb6efcbc348c399fb880b558", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 22860434, "upload_time": "2019-12-09T18:00:49", "upload_time_iso_8601": "2019-12-09T18:00:49.509863Z", "url": "https://files.pythonhosted.org/packages/be/78/b1bf5d91b1ed79412ef2bf5ffb66839101b23cde449e4ca70c3d763ed5d2/sleeppy-0.2.21-py2-none-any.whl", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c94efa93bb6efcbc348c399fb880b558", "sha256": "d77a1267816ea937b869fae6e890bb20105fc1fa4e883ba059cb245e88143460" }, "downloads": -1, "filename": "sleeppy-0.2.21-py2-none-any.whl", "has_sig": false, "md5_digest": "c94efa93bb6efcbc348c399fb880b558", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 22860434, "upload_time": "2019-12-09T18:00:49", "upload_time_iso_8601": "2019-12-09T18:00:49.509863Z", "url": "https://files.pythonhosted.org/packages/be/78/b1bf5d91b1ed79412ef2bf5ffb66839101b23cde449e4ca70c3d763ed5d2/sleeppy-0.2.21-py2-none-any.whl", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }