Skip to content

Commit

Permalink
Merge pull request #123 from seermedical/optional-dependencies
Browse files Browse the repository at this point in the history
Move matplotlib and scipy into optional dependencies
  • Loading branch information
norrishd authored Feb 17, 2021
2 parents f4692e5 + b4dd16d commit a992ec7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 132 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Note that by default there is no public access to any data on the Seer Cloud. Yo

## Install

To install, simply clone or download this repository, then type `pip install .` which will install all the dependencies.
To install, simply clone or download this repository, then type `pip install .` which will install all the dependencies. To enable plotting signal data (required by the example notebook), use `pip install .[viz]`

### Epilepsy Ecosystem Data

Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
gql
requests
matplotlib
numpy
pandas
scipy
# TODO: graphql-core 3.0.0 has a problem as at 02/12/2019
# revisit in the future, we may be able to remove the restriction
graphql-core<3.0.0
Expand Down
124 changes: 8 additions & 116 deletions seerpy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@
from multiprocessing import Pool
import os

from matplotlib.collections import LineCollection
from matplotlib import gridspec
from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
import requests
from scipy.signal import butter, sosfilt


# pylint:disable=too-many-locals,too-many-statements
Expand Down Expand Up @@ -417,6 +413,14 @@ def plot_eeg(x, y=None, pred=None, squeeze=5.0, scaling_factor=None):
>>> data_series = data_df.iloc[:, 0]
>>> plot_eeg(x=data_series)
"""
try:
from matplotlib.collections import LineCollection
from matplotlib import gridspec
from matplotlib import pyplot as plt
except ModuleNotFoundError:
raise ModuleNotFoundError(
'Must have `matplotlib` installed. Try `pip install -U seerpy[viz]`')

if not isinstance(x, np.ndarray):
x = np.asarray(x)

Expand Down Expand Up @@ -469,118 +473,6 @@ def plot_eeg(x, y=None, pred=None, squeeze=5.0, scaling_factor=None):
return plt


def butter_bandstop(lowcut, highcut, fs, order=5):
"""
Get second-order-sections representation of an IIR Butterworth digital
bandstop filter.
Parameters
----------
lowcut : float
The lowcut critical frequency
highcut : float
The highcut critical frequency
fs : float
The sampling frequency of the digital system
order : int
The order of the filter
Returns
-------
filter_params : np.ndarray
Second-order-section filter parameters
"""
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
sos = butter(order, [low, high], analog=False, btype='bandstop', output='sos')
return sos


def butter_bandstop_filter(data, lowcut, highcut, fs, order=5):
"""
Apply a bandstop filter to data along one dimension using cascaded
second-order sections.
Parameters
----------
data : np.ndarray
Array of data to apply filter to
lowcut : float
The lowcut critical frequency
highcut : float
The highcut critical frequency
fs : float
The sampling frequency of the digital system
order : int
The order of the filter
Returns
-------
filtered_data : np.ndarray
The original data after applying the filter
"""
sos = butter_bandstop(lowcut, highcut, fs, order=order)
y = sosfilt(sos, data)
return y


def butter_bandpass(lowcut, highcut, fs, order=5):
"""
Get second-order-sections representation of an IIR Butterworth digital
bandpass filter.
Parameters
----------
lowcut : float
The lowcut critical frequency
highcut : float
The highcut critical frequency
fs : float
The sampling frequency of the digital system
order : int
The order of the filter
Returns
-------
filter_params : np.ndarray
Second-order-section filter parameters
"""
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
sos = butter(order, [low, high], analog=False, btype='bandpass', output='sos')
return sos


def butter_bandpass_filter(data, lowcut, highcut, fs, order=5):
"""
Apply a bandpass filter to data along one dimension using cascaded
second-order sections.
Parameters
----------
data : np.ndarray
Array of data to apply filter to
lowcut : float
The lowcut critical frequency
highcut : float
The highcut critical frequency
fs : float
The sampling frequency of the digital system
order : int
The order of the filter
Returns
-------
filtered_data : np.ndarray
The original data after applying the filter
"""
sos = butter_bandpass(lowcut, highcut, fs, order=order)
y = sosfilt(sos, data)
return y


def get_diary_fitbit_data(data_url):
"""
Download Fitbit data from a given URL and return as a DataFrame.
Expand Down
17 changes: 4 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='seerpy',
version='0.3.0',
version='0.4.0',
description='Seer Platform SDK for Python',
long_description=open('README.md').read(),
url='https://github.com/seermedical/seer-py',
Expand All @@ -18,16 +18,7 @@
],
keywords='api seer eeg ecg client',
packages=find_packages(include=["seerpy*"]),
install_requires=[
'gql',
'requests',
'matplotlib',
'numpy',
'pandas',
'scipy',
'pyjwt[crypto]'
],
tests_require=[
'pytest'
],
install_requires=['gql', 'requests', 'numpy', 'pandas', 'pyjwt[crypto]'],
extras_require={'viz': ['matplotlib']},
tests_require=['pytest'],
)

0 comments on commit a992ec7

Please sign in to comment.