From d92cc132c163a970ecbb894b563411d7e3cbece4 Mon Sep 17 00:00:00 2001 From: angerhang <514140809@qq.com> Date: Wed, 26 Apr 2023 17:05:20 +0100 Subject: [PATCH] update output format --- .gitignore | 1 + pyproject.toml | 2 +- src/asleep/get_sleep.py | 13 ++++++++++++- tox.ini | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2d8f5d0..80bce23 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ assets/*.joblib.* *.ipynb src/asleep/models *mdl +*.lzma \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index a1f4c5e..9469a7f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ name = "asleep" # Required # # For a discussion on single-sourcing the version, see # https://packaging.python.org/guides/single-sourcing-package-version/ -version = "0.3.5" # Required +version = "0.3.6" # Required # This is a one-line description or tagline of what your project does. This # corresponds to the "Summary" metadata field: diff --git a/src/asleep/get_sleep.py b/src/asleep/get_sleep.py index 1f9f3a3..27ab077 100644 --- a/src/asleep/get_sleep.py +++ b/src/asleep/get_sleep.py @@ -178,6 +178,11 @@ def main(): help="asleep package won't rerun the analysis to save " "time. force_run will make sure everything is " "regenerated") + parser.add_argument( + "--remove_intermediate_files", + action="store_true", + help="Remove intermediate files to save space but it " + "will take longer to run the next time.") parser.add_argument( "--pytorch_device", "-d", @@ -197,6 +202,7 @@ def main(): # get file name and create a folder for the output filename = os.path.basename(args.filepath) + filename = filename.split('.')[0] os.makedirs(args.outdir, exist_ok=True) args.outdir = os.path.join(args.outdir, filename) @@ -211,6 +217,9 @@ def main(): # Add non-wear detection data, info = get_parsed_data( raw_data_path, info_data_path, resample_hz, args) + if args.remove_intermediate_files: + os.remove(raw_data_path) + os.remove(info_data_path) print(data.head()) # 1.1 Transform data into a usable format for inference @@ -219,6 +228,8 @@ def main(): data2model_path, times_path, data, args) print("data2model shape: {}".format(data2model.shape)) print("times shape: {}".format(times.shape)) + if args.remove_intermediate_files: + os.remove(data2model_path) # 2. sleep window detection and inference (binary_y, all_sleep_wins_df, @@ -279,8 +290,8 @@ def main(): # 4.2 Generate daily summary statistics output_json_path = os.path.join(args.outdir, 'summary.json') + day_summary_path = os.path.join(args.outdir, 'day_summary.csv') # save day level df to csv - day_summary_path = os.path.join('outputs', 'day_summary.csv') day_summary_df = generate_sleep_parameters( all_sleep_wins_df, times, predictions_df, day_summary_path) diff --git a/tox.ini b/tox.ini index 4ac04b6..6875a33 100644 --- a/tox.ini +++ b/tox.ini @@ -37,7 +37,7 @@ commands = check-manifest --ignore 'tox.ini,tests/**,assets/*.graffle,hubconf.py' python -m build python -m twine check dist/* - flake8 . --max-line-length=99 --ignore=W503,W504 + flake8 . --max-line-length=99 --ignore=W503,W504,E402 py.test tests {posargs} [flake8]