Skip to content

Commit

Permalink
update output format
Browse files Browse the repository at this point in the history
  • Loading branch information
angerhang committed Apr 26, 2023
1 parent 8e8892f commit d92cc13
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ assets/*.joblib.*
*.ipynb
src/asleep/models
*mdl
*.lzma
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 12 additions & 1 deletion src/asleep/get_sleep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit d92cc13

Please sign in to comment.