Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump joblib from 1.1.0 to 1.2.0 #212

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,5 @@ doc/source/savefig/

# Sample files, etc.
data/
accelerometer/activityModels/
accelerometer/activityModels/
accelerometer/models/
2 changes: 1 addition & 1 deletion accelerometer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "accelerometer"
__version__ = "5.1.3"
__version__ = "6.2.0"
__author__ = "Aiden Doherty, Shing Chan, Rosemary Walmsley, Hang Yuan"
__email__ = "[email protected], [email protected], [email protected], [email protected]"
__license__ = "See LICENSE.md"
2 changes: 1 addition & 1 deletion accelerometer/accPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
'vehicle': 'saddlebrown',
'light': 'darkorange',
'mixed': 'seagreen',
'walking': 'green',
'walking': 'limegreen',
'moderate-vigorous': 'green',
'bicycling': 'springgreen',
'tasks-light': 'darkorange',
Expand Down
26 changes: 24 additions & 2 deletions accelerometer/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def activityClassification(epoch, activityModel="walmsley"):
:rtype: list(str)
"""

use_cutpoints = 'chan' in activityModel
smooth_sleep = 'chan' in activityModel

activityModel = resolveModelPath(activityModel)

featureCols = joblib.load(getFileFromTar(activityModel, 'featureCols'))
Expand All @@ -51,8 +54,29 @@ def activityClassification(epoch, activityModel="walmsley"):

model = joblib.load(getFileFromTar(activityModel, 'model'))
hmmParams = joblib.load(getFileFromTar(activityModel, 'hmmParams'))
labels = joblib.load(getFileFromTar(activityModel, 'labels')).tolist()

Y = viterbi(model.predict(X), hmmParams)

if smooth_sleep:
sleep = pd.Series(Y == 'sleep')
sleep_streak = (
sleep.ne(sleep.shift())
.cumsum()
.pipe(lambda x: x.groupby(x).transform('count') * sleep)
)
# TODO: hardcoded 120 = 1hr
Y[(Y == 'sleep') & (sleep_streak < 120)] = 'sedentary'

if use_cutpoints:
enmo = epoch['enmoTrunc'].to_numpy()
enmo = enmo[mask]
Y[(Y == 'other') & (enmo < .1)] = 'light'
Y[(Y == 'other') & (enmo >= .1)] = 'moderate-vigorous'
labels.remove('other')
labels.append('light')
labels.append('moderate-vigorous')

# Append predicted activities to epoch dataframe
epoch["label"] = np.nan
epoch.loc[mask, "label"] = Y
Expand All @@ -62,8 +86,6 @@ def activityClassification(epoch, activityModel="walmsley"):
if METs is not None:
epoch["MET"] = epoch["label"].replace(METs)

labels = joblib.load(getFileFromTar(activityModel, 'labels')).tolist()

# One-hot encoding
for lab in labels:
epoch[lab] = 0
Expand Down
39 changes: 19 additions & 20 deletions accelerometer/models.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
import pathlib

ROOT_DIR = pathlib.Path(__file__).parent
MODEL_VER = "10Feb2022"
MODEL_DIR = ROOT_DIR / "models"
MODEL_URL = "https://wearables-files.ndph.ox.ac.uk/files/models"
MODEL_DIR = pathlib.Path(__file__).parent / "models"
MODEL_ROOT_URL = "https://wearables-files.ndph.ox.ac.uk/files/models/biobankAccelerometerAnalysis"


MODELS = {

'willetts': {
"pth": MODEL_DIR / MODEL_VER / "willetts/model.tar",
"url": f"{MODEL_URL}/{MODEL_VER}/willetts/model.tar",
"pth": MODEL_DIR / "willetts" / "20220210.tar",
"url": f"{MODEL_ROOT_URL}/willetts/20220210.tar",
},

'doherty': {
"pth": MODEL_DIR / MODEL_VER / "doherty/model.tar",
"url": f"{MODEL_URL}/{MODEL_VER}/doherty/model.tar",
"pth": MODEL_DIR / "doherty" / "20220210.tar",
"url": f"{MODEL_ROOT_URL}/doherty/20220210.tar",
},

'walmsley': {
"pth": MODEL_DIR / MODEL_VER / "walmsley/model.tar",
"url": f"{MODEL_URL}/{MODEL_VER}/walmsley/model.tar",
"pth": MODEL_DIR / "walmsley" / "20220210.tar",
"url": f"{MODEL_ROOT_URL}/walmsley/20220210.tar",
},

'willetts-10Feb2022': {
"pth": MODEL_DIR / "10Feb2022" / "willetts/model.tar",
"url": f"{MODEL_URL}/10Feb2022/walmsley/model.tar",
},
'doherty-10Feb2022': {
"pth": MODEL_DIR / "10Feb2022" / "doherty/model.tar",
"url": f"{MODEL_URL}/10Feb2022/walmsley/model.tar",
'chan': {
"pth": MODEL_DIR / "chan" / "20230103.tar",
"url": f"{MODEL_ROOT_URL}/chan/20230103.tar",

},
'walmsley-10Feb2022': {
"pth": MODEL_DIR / "10Feb2022" / "walmsley/model.tar",
"url": f"{MODEL_URL}/10Feb2022/walmsley/model.tar",

'chanw': {
"pth": MODEL_DIR / "chanw" / "20230106.tar",
"url": f"{MODEL_ROOT_URL}/chanw/20230106.tar"
},

}
4 changes: 4 additions & 0 deletions build_scripts/build_clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

rm -r actipy.egg-info build dist
rm -r conda-recipe
16 changes: 16 additions & 0 deletions build_scripts/build_conda.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# Note: Be sure package already in PyPI

conda install anaconda-client &&
conda install conda-build &&
# TODO: allow user-specified version and append this to next line: --version x.x.x
conda skeleton pypi accelerometer --output-dir conda-recipe &&
conda build -c conda-forge conda-recipe/accelerometer

printf "\nNext steps:\n-----------\n"
printf "Login to Anaconda:\n> anaconda login\n"
printf "\nUpload package (path is printed in previous steps):\n> anaconda upload --user oxwear /path/to/package.tar.bz2\n\n"

# anaconda login
# anaconda upload --user oxwear /path/to/package.tar.bz2
16 changes: 16 additions & 0 deletions build_scripts/build_pypi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# You must have Java Development Kit (JDK) 8 (1.8). If higher (>8) then it must
# support --release flag to pin down the version when compiling.
# Always compile with 8 (1.8) to keep backward compatibility.
# In conda, you can get a JDK version that supports --release flag:
# conda install openjdk
javac --version && # java version
javac -cp accelerometer/java/JTransforms-3.1-with-dependencies.jar accelerometer/java/*.java --release 8 && # compile java files (using release 8)
python setup.py sdist bdist_wheel && # setuptools
twine check dist/* &&
printf "\nTo upload to Test PyPI:\n> twine upload --repository-url https://test.pypi.org/legacy/ dist/*\n" &&
printf "\nTo upload to PyPI:\n> twine upload dist/*\n\n"

# twine upload --repository-url https://test.pypi.org/legacy/ dist/*
# twine upload dist/*
18 changes: 17 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,25 @@ def get_string(string, rel_path="accelerometer/__init__.py"):
'statsmodels>=0.12.2',
'imbalanced-learn==0.8.1',
'scikit-learn==1.0.1',
'joblib==1.1.0',
'joblib==1.2.0',
'tqdm>=4.59.0',
],
extras_require={
"dev": [
"flake8",
"autopep8",
"ipython",
"ipdb",
"twine",
],
"docs": [
"sphinx>=4.2",
"sphinx_rtd_theme>=1.0",
"readthedocs-sphinx-search>=0.1",
"sphinxcontrib-programoutput>=0.17",
"docutils<0.18",
],
},
classifiers=[
"Programming Language :: Python :: 3",
"Operating System :: MacOS :: MacOS X",
Expand Down
31 changes: 0 additions & 31 deletions utilities/downloadDataModels.sh

This file was deleted.