Skip to content

Commit

Permalink
Merge pull request #926 from neuropsychology/dev
Browse files Browse the repository at this point in the history
0.2.8
  • Loading branch information
DominiqueMakowski authored Apr 6, 2024
2 parents 3d004b4 + 8e4ee00 commit e3f4469
Show file tree
Hide file tree
Showing 34 changed files with 737 additions and 281 deletions.
43 changes: 0 additions & 43 deletions .codeclimate.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,4 @@ studies/complexity_structure/README_cache/
studies/complexity_structure/manuscript_cache/
studies/complexity_eeg/data_attractor.csv
studies/complexity_eeg/data_delay.csv
testing.ipynb
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ include NEWS.rst
include LICENSE
include README.rst

recursive-include tests *
recursive-exclude tests *
recursive-exclude * __pycache__
recursive-exclude * *.py[co]

recursive-include docs *.rst conf.py *.jpg *.png *.gif

11 changes: 11 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
News
=====

0.2.8
-------------------
New Features
+++++++++++++

* New feature `events_find()`: is now able to combine multiple digital input channels,
retrieve events from the combined events channel and differentiate between the inputs that
occur simultaneously.



0.2.4
-------------------
Fixes
Expand Down
Binary file modified data/eeg_1min_200hz.pickle
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/examples/ecg_hrv/ecg_hrv.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Heart Rate Varability (HRV)"
"# Heart Rate Variability (HRV)"
]
},
{
Expand Down
5 changes: 3 additions & 2 deletions neurokit2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Top-level package for NeuroKit."""

import datetime
import platform

Expand Down Expand Up @@ -32,12 +33,12 @@
from .video import *

# Info
__version__ = "0.2.7"
__version__ = "0.2.8"


# Maintainer info
__author__ = "The NeuroKit development team"
__email__ = "[email protected]"
__email__ = "[email protected]"


# Citation
Expand Down
17 changes: 9 additions & 8 deletions neurokit2/complexity/utils_complexity_symbolize.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def complexity_symbolize(signal, method="mean", c=3, random_state=None, show=Fal
symbolic = (signal > np.nanmean(signal)).astype(int)
if show is True:
df = pd.DataFrame({"A": signal, "B": signal})
df["A"][df["A"] > np.nanmean(signal)] = np.nan
df["B"][df["B"] <= np.nanmean(signal)] = np.nan
df.loc[df["A"] > np.nanmean(signal), "A"] = np.nan
df.loc[df["B"] <= np.nanmean(signal), "B"] = np.nan
df.plot()
plt.axhline(y=np.nanmean(signal), color="r", linestyle="dotted")
plt.title("Method A")
Expand All @@ -194,8 +194,8 @@ def complexity_symbolize(signal, method="mean", c=3, random_state=None, show=Fal
symbolic = (signal > np.nanmedian(signal)).astype(int)
if show is True:
df = pd.DataFrame({"A": signal, "B": signal})
df["A"][df["A"] > np.nanmedian(signal)] = np.nan
df["B"][df["B"] <= np.nanmedian(signal)] = np.nan
df.loc[df["A"] > np.nanmedian(signal), "A"] = np.nan
df.loc[df["B"] <= np.nanmedian(signal), "B"] = np.nan
df.plot()
plt.axhline(y=np.nanmean(signal), color="r", linestyle="dotted")
plt.title("Binarization by median")
Expand All @@ -206,8 +206,9 @@ def complexity_symbolize(signal, method="mean", c=3, random_state=None, show=Fal
symbolic = np.logical_or(signal < m - sd, signal > m + sd).astype(int)
if show is True:
df = pd.DataFrame({"A": signal, "B": signal})
df["A"][np.logical_or(signal < m - sd, signal > m + sd)] = np.nan
df["B"][~np.isnan(df["A"])] = np.nan
condition = np.logical_or(signal < m - sd, signal > m + sd)
df.loc[condition, "A"] = np.nan
df.loc[~np.isnan(df["A"]), "B"] = np.nan
df.plot()
plt.axhline(y=m - sd, color="r", linestyle="dotted")
plt.axhline(y=m + sd, color="r", linestyle="dotted")
Expand All @@ -217,8 +218,8 @@ def complexity_symbolize(signal, method="mean", c=3, random_state=None, show=Fal
symbolic = np.signbit(np.diff(signal)).astype(int)
if show is True:
df = pd.DataFrame({"A": signal, "B": signal})
df["A"][np.insert(symbolic, 0, False)] = np.nan
df["B"][~np.isnan(df["A"])] = np.nan
df.loc[np.insert(symbolic, 0, False), "A"] = np.nan
df.loc[~np.isnan(df["A"]), "B"] = np.nan
df.plot()
plt.title("Method C")

Expand Down
6 changes: 2 additions & 4 deletions neurokit2/data/database.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import pathlib
import urllib.parse
import urllib
import zipfile

import requests


def download_from_url(url, destination_path=None):
"""**Download Files from URLs**
Expand All @@ -26,7 +24,7 @@ def download_from_url(url, destination_path=None):
destination_path = _download_path_sanitize(url, destination_path)

# Download the file
response = requests.get(url)
response = urllib.request.urlopen(url)

if response.status_code == 200:
with destination_path.open("wb") as file:
Expand Down
31 changes: 19 additions & 12 deletions neurokit2/data/read_acqknowledge.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# -*- coding: utf-8 -*-
import os

from collections import Counter

import numpy as np
import pandas as pd

from ..signal import signal_resample


def read_acqknowledge(
filename, sampling_rate="max", resample_method="interpolation", impute_missing=True
):
def read_acqknowledge(filename, sampling_rate="max", resample_method="interpolation", impute_missing=True):
"""**Read and format a BIOPAC's AcqKnowledge file into a pandas' dataframe**
The function outputs both the dataframe and the sampling rate (retrieved from the
Expand Down Expand Up @@ -69,10 +69,7 @@ def read_acqknowledge(
filename += ".acq"

if os.path.exists(filename) is False:
raise ValueError(
"NeuroKit error: read_acqknowledge(): couldn't"
" find the following file: " + filename
)
raise ValueError("NeuroKit error: read_acqknowledge(): couldn't" " find the following file: " + filename)

# Read file
file = bioread.read(filename)
Expand All @@ -84,24 +81,34 @@ def read_acqknowledge(
freq_list.append(file.named_channels[channel].samples_per_second)
sampling_rate = np.max(freq_list)

# Counter for checking duplicate channel names
channel_counter = Counter()

# Loop through channels
data = {}
for channel in file.named_channels:
signal = np.array(file.named_channels[channel].data)
for channel_num, channel in enumerate(file.channels):
signal = np.array(file.channels[channel_num].data)

# Fill signal interruptions
if impute_missing is True and np.isnan(np.sum(signal)):
signal = pd.Series(signal).fillna(method="pad").values

# Resample if necessary
if file.named_channels[channel].samples_per_second != sampling_rate:
if file.channels[channel_num].samples_per_second != sampling_rate:
signal = signal_resample(
signal,
sampling_rate=file.named_channels[channel].samples_per_second,
sampling_rate=file.channels[channel_num].samples_per_second,
desired_sampling_rate=sampling_rate,
method=resample_method,
)
data[channel] = signal

# If there is a duplicate channel name, append a number
if channel_counter[channel.name] == 0:
data[channel.name] = signal
else:
data[f"{channel.name} ({channel_counter[channel.name]})"] = signal

channel_counter[channel.name] += 1

# Sanitize lengths
lengths = []
Expand Down
10 changes: 8 additions & 2 deletions neurokit2/data/read_xdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,16 @@ def read_xdf(filename, upsample=2, fillmissing=None):

# Special treatment for some devices
if stream["info"]["name"][0] == "Muse":
# Rename GYRO channels and add ACCelerometer
# Rename GYRO channels
if stream["info"]["type"][0] == "GYRO":
dat = dat.rename(columns={"X": "GYRO_X", "Y": "GYRO_Y", "Z": "GYRO_Z"})
dat["ACC"] = np.sqrt(dat["GYRO_X"] ** 2 + dat["GYRO_Y"] ** 2 + dat["GYRO_Z"] ** 2)
# Compute movement
dat["GYRO"] = np.sqrt(dat["GYRO_X"] ** 2 + dat["GYRO_Y"] ** 2 + dat["GYRO_Z"] ** 2)

if stream["info"]["type"][0] == "ACC":
dat = dat.rename(columns={"X": "ACC_X", "Y": "ACC_Y", "Z": "ACC_Z"})
# Compute acceleration
dat["ACC"] = np.sqrt(dat["ACC_X"] ** 2 + dat["ACC_Y"] ** 2 + dat["ACC_Z"] ** 2)

# Muse - PPG data has three channels: ambient, infrared, red
if stream["info"]["type"][0] == "PPG":
Expand Down
Loading

0 comments on commit e3f4469

Please sign in to comment.