Skip to content

Commit

Permalink
Merge pull request #118 from coganlab/mac-port
Browse files Browse the repository at this point in the history
Mac port
  • Loading branch information
Aaronearlerichardson authored May 3, 2024
2 parents d03b4e5 + e9fc799 commit 03ee56f
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 23 deletions.
44 changes: 39 additions & 5 deletions .github/workflows/Package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ on:
branches: [ main ]

jobs:
packaging:
build:
runs-on: ubuntu-latest
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
environment: release
steps:
- uses: actions/checkout@v4
# Python
- uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: '3.10'
cache: 'pip'
# Publish (moved to end of document later)
- name: Build source distribution
Expand All @@ -27,10 +25,46 @@ jobs:
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
uses: pypa/gh-action-pypi-publish@release/v1

publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/ieeg

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
7 changes: 5 additions & 2 deletions .github/workflows/Python-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ jobs:
strategy:
matrix:
include:
- os: ubuntu-latest
- os: windows-latest
python: '3.12'
kind: pip
- os: windows-latest
- os: macos-latest
python: '3.11'
kind: pip
- os: ubuntu-latest
python: '3.10'
kind: pip
environment: release
steps:
- uses: actions/checkout@v4
Expand Down
1 change: 0 additions & 1 deletion envs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
bids>=0.0
EDFlib-Python
mne
mne-bids
numpy
Expand Down
2 changes: 1 addition & 1 deletion ieeg/calc/mat.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def combine(self, levels: tuple[int, int]) -> 'LabeledArray':
all_idx = ([slice(None) if i != levels[0] else sl for i in
range(self.ndim)] for sl in range(self.shape[levels[0]]))

arrs = [self.__array__()[*idx] for idx in all_idx]
arrs = [self.__array__()[tuple(idx)] for idx in all_idx]
new_array = concatenate_arrays(arrs, axis=levels[1] - 1)

return LabeledArray(new_array, new_labels, dtype=self.dtype)
Expand Down
36 changes: 24 additions & 12 deletions ieeg/calc/scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from mne.time_frequency import AverageTFR, EpochsTFR
from mne.utils import logger, verbose

TFR = EpochsTFR | AverageTFR


def _log_rescale(baseline, mode='mean'):
"""Log the rescaling method."""
Expand Down Expand Up @@ -126,7 +124,7 @@ def _(line: BaseEpochs, baseline: BaseEpochs,

@rescale.register
@verbose
def _(line: TFR, baseline: TFR,
def _(line: EpochsTFR, baseline: EpochsTFR,
mode: str = 'mean', copy: bool = False, picks: list = 'data',
verbose=None) -> Epochs:
"""Rescale (baseline correct) Epochs"""
Expand All @@ -138,18 +136,32 @@ def _(line: TFR, baseline: TFR,

# Average the baseline across epochs
basedata = baseline.pick(picks)._data
axes = list(range(basedata.ndim))

# within channels
axes.pop(1)
# If time frequency then within frequency
axes = (0, 3)

line.pick(picks)._data = rescale(line.pick(picks)._data, basedata, mode,
False, axes)
return line


@rescale.register
@verbose
def _(line: AverageTFR, baseline: AverageTFR,
mode: str = 'mean', copy: bool = False, picks: list = 'data',
verbose=None) -> Epochs:
"""Rescale (baseline correct) Epochs"""
if copy:
line: Epochs = line.copy()
if verbose is not False:
msg = _log_rescale(baseline, mode)
logger.info(msg)

# Average the baseline across epochs
basedata = baseline.pick(picks)._data

# If time frequency then within frequency
if isinstance(line, EpochsTFR):
axes = (0, 3)
elif isinstance(line, AverageTFR):
axes = 2
else:
axes = tuple(axes)
axes = 2

line.pick(picks)._data = rescale(line.pick(picks)._data, basedata, mode,
False, axes)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ authors = [
]
dynamic = ["dependencies", "version"]
readme = "README.md"
requires-python = ">=3.11"
requires-python = ">=3.10"

[tool.setuptools.packages.find]
where = ["."]
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def get_file_list(path, ext):
compile_args = ["/O2"]
elif sys.platform == 'linux':
compile_args = ["-O3"]
elif sys.platform == 'darwin':
compile_args = ["-O3"]
else:
raise NotImplementedError(f"Platform {sys.platform} not supported.")

Expand Down Expand Up @@ -77,7 +79,7 @@ def get_file_list(path, ext):

setup(
name='ieeg',
version='0.4',
version='0.5',
packages=find_packages(
where='.',
include=['ieeg*'],
Expand Down

0 comments on commit 03ee56f

Please sign in to comment.