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

Make the accelerometer dependency optional #161

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions pyActigraphy/io/bba/bba.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import importlib
import json
import os
import pandas as pd
import re

from ..base import BaseRaw
from accelerometer.utils import date_parser
from accelerometer.summarisation import imputeMissing


class RawBBA(BaseRaw):
Expand Down Expand Up @@ -69,6 +68,18 @@ def __init__(
use_metadata_json=True,
metadata_fname=None
):
# The accelerometer package causes some dependency conflicts,
# so instead of always including it as a hard dependency, we
# try to import it as an optional one. Users with BBA files
# likely already have accelerometer installed, or should be
# able to sort out the dependency conflicts as needed.
try:
utils = importlib.import_module('accelerometer.utils')
except ModuleNotFoundError as e:
raise Exception(
'Unable to load the required accelerometer.utils module.'
' Install the package with "pip install accelerometer".'
) from e

# get absolute file path
input_fname = os.path.abspath(input_fname)
Expand All @@ -79,7 +90,7 @@ def __init__(
engine=engine,
index_col=['time'],
parse_dates=['time'],
date_parser=date_parser
date_parser=utils.date_parser
)

# read meta-data file (if found):
Expand Down Expand Up @@ -139,7 +150,8 @@ def __init__(

# Impute missing data (if required)
if impute_missing:
data = imputeMissing(data)
s11n = importlib.import_module('accelerometer.summarization')
data = s11n.imputeMissing(data)

# LIGHT
self.__white_light = self.__extract_baa_data(
Expand Down Expand Up @@ -343,6 +355,10 @@ def read_raw_bba(
r"""Reader function for files produced by the biobankAccelerometerAnalysis
package.

Note that the required 'accelerometer' package is not automatically
included as a dependency of pyActigraphy. You need to explicitly install
it with something like 'pip install accelerometer' to use this function.

Parameters
----------
input_fname: str
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def find_version(*file_paths):
install_requires=[
'joblib', 'lmfit', 'pandas', 'plotly', 'numba', 'numpy', 'pyexcel',
'pyexcel-ods3', 'pyexcel-xlsx', 'scipy', 'spm1d', 'statsmodels>=0.10',
'stochastic>=0.6.0', 'accelerometer>=6.2.2'
'stochastic>=0.6.0'
], # Optional

# Data files included in your packages that need to be installed.
Expand Down