Skip to content

Commit

Permalink
feat: add option to explicitly pass sample rate
Browse files Browse the repository at this point in the history
Co-authored-by: muschellij2 <[email protected]>
  • Loading branch information
chanshing and muschellij2 committed Jan 11, 2024
1 parent 2f98d72 commit f589667
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/stepcount/stepcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def main():
choices=['ssl', 'rf'], default='ssl')
parser.add_argument("--pytorch-device", "-d", help="Pytorch device to use, e.g.: 'cpu' or 'cuda:0' (for SSL only)",
type=str, default='cpu')
parser.add_argument("--sample-rate", "-r", help="Sample rate for measurement, otherwise inferred.",
type=int, default=None)
parser.add_argument('--quiet', '-q', action='store_true', help='Suppress output')
args = parser.parse_args()

Expand All @@ -45,7 +47,7 @@ def main():
resample_hz = 30
else:
resample_hz = None
data, info = read(args.filepath, resample_hz, verbose=verbose)
data, info = read(args.filepath, resample_hz, sample_rate=args.sample_rate, verbose=verbose)

# Output paths
basename = resolve_path(args.filepath)[1]
Expand Down Expand Up @@ -328,7 +330,7 @@ def nanint(x):
return int(x)


def read(filepath, resample_hz='uniform', verbose=True):
def read(filepath, resample_hz='uniform', sample_rate=None, verbose=True):

p = pathlib.Path(filepath)
ftype = p.suffixes[0].lower()
Expand All @@ -349,8 +351,9 @@ def read(filepath, resample_hz='uniform', verbose=True):
else:
raise ValueError(f"Unknown file format: {ftype}")

freq = infer_freq(data.index)
sample_rate = int(np.round(pd.Timedelta('1s') / freq))
if sample_rate in (None, False):
freq = infer_freq(data.index)
sample_rate = int(np.round(pd.Timedelta('1s') / freq))

# Quick fix: Drop duplicate indices. TODO: Maybe should be handled by actipy.
data = data[~data.index.duplicated(keep='first')]
Expand Down

0 comments on commit f589667

Please sign in to comment.