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

Add custom range to flirt #3

Open
wants to merge 3 commits 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
12 changes: 8 additions & 4 deletions flirt/hrv/feature_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __generate__(self, data: np.array) -> dict:
}


def get_hrv_features(data: pd.Series, window_length: int = 180, window_step_size: int = 1,
def get_hrv_features(data: pd.Series, window_length: int = 180, window_step_size: int = 1, custom_range = None,
domains: List[str] = ['td', 'fd', 'stat'], threshold: float = 0.2,
clean_data: bool = True, num_cores: int = 0):
"""
Expand Down Expand Up @@ -118,9 +118,13 @@ def get_hrv_features(data: pd.Series, window_length: int = 180, window_step_size

first_index = clean_data.index[0].floor('s')
last_index = clean_data.index[-1].ceil('s')
target_index = pd.date_range(start=first_index,
end=max(first_index, last_index - window_length_timedelta),
freq=window_step_size_timedelta)

if custom_range is None:
target_index = pd.date_range(start=first_index,
end=max(first_index, last_index - window_length_timedelta),
freq=window_step_size_timedelta)
else:
target_index = first_index + pd.to_timedelta(custom_range, unit='s')

def process(memmap_data) -> pd.DataFrame:
with Parallel(n_jobs=num_cores, max_nbytes=None) as parallel:
Expand Down
12 changes: 8 additions & 4 deletions flirt/stats/feature_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

import pandas as pd
from joblib import Parallel, delayed
from tqdm.autonotebook import trange
from tqdm.autonotebook import trange, tqdm
from ..util import processing

from .common import get_stats


def get_stat_features(data: pd.DataFrame, window_length: int = 60, window_step_size: int = 1, data_frequency: int = 32,
entropies: bool = True, num_cores: int = 0):
custom_range = None, entropies: bool = True, num_cores: int = 0):
"""
Computes several statistical and entropy-based time series features for each column in the provided DataFrame.

Expand Down Expand Up @@ -49,8 +49,12 @@ def get_stat_features(data: pd.DataFrame, window_length: int = 60, window_step_s
num_cores = multiprocessing.cpu_count()

input_data = data.copy()
# advance by window_step_size * data_frequency
inputs = trange(0, len(input_data) - 1, window_step_size * data_frequency, desc="Stat features")

if custom_range is None:
# advance by window_step_size * data_frequency
inputs = trange(0, len(input_data) - 1, window_step_size * data_frequency, desc="Stat features")
else:
inputs = tqdm(custom_range, desc="Stat features")

def process(memmap_data):
with Parallel(n_jobs=num_cores, max_nbytes=None) as parallel:
Expand Down