Skip to content

Commit

Permalink
Merge pull request #20 from CINPLA/modernize
Browse files Browse the repository at this point in the history
Modernize package and add actions
  • Loading branch information
nicolossus authored Nov 21, 2024
2 parents 2087206 + 30acbcc commit 4e97d52
Show file tree
Hide file tree
Showing 21 changed files with 481 additions and 424 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/full_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Test on Ubuntu

on:
pull_request:
branches: [dev]
types: [synchronize, opened, reopened]


jobs:
build-and-test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install package
run: |
python -m pip install --upgrade pip
pip install .[test]
- name: Pytest
run: |
pytest -v
28 changes: 28 additions & 0 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Release to PyPI

on:
push:
tags:
- '*'
jobs:
release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install Tools
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine build
- name: Package and Upload
env:
STACKMANAGER_VERSION: ${{ github.event.release.tag_name }}
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m build --sdist --wheel
twine upload dist/*
36 changes: 36 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: fix-encoding-pragma
exclude: tests/test_data
- id: trailing-whitespace
exclude: tests/test_data
- id: end-of-file-fixer
exclude: tests/test_data
- id: check-docstring-first
- id: debug-statements
- id: check-toml
- id: check-yaml
exclude: tests/test_data
- id: requirements-txt-fixer
- id: detect-private-key
- id: check-merge-conflict

- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
exclude: tests/test_data
- id: black-jupyter

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: ruff
116 changes: 76 additions & 40 deletions examples/tracking_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@
from scipy.ndimage.measurements import center_of_mass


def plot_path(x, y, t, box_size, spike_times=None,
color='grey', alpha=0.5, origin='upper',
spike_color='r', rate_markersize=False, markersize=10.,
animate=False, ax=None):
def plot_path(
x,
y,
t,
box_size,
spike_times=None,
color="grey",
alpha=0.5,
origin="upper",
spike_color="r",
rate_markersize=False,
markersize=10.0,
animate=False,
ax=None,
):
"""
Plot path visited
Expand Down Expand Up @@ -39,8 +50,7 @@ def plot_path(x, y, t, box_size, spike_times=None,
"""
if ax is None:
fig = plt.figure()
ax = fig.add_subplot(
111, xlim=[0, box_size], ylim=[0, box_size], aspect=1)
ax = fig.add_subplot(111, xlim=[0, box_size], ylim=[0, box_size], aspect=1)

ax.plot(x, y, c=color, alpha=alpha)
if spike_times is not None:
Expand All @@ -49,20 +59,36 @@ def plot_path(x, y, t, box_size, spike_times=None,

if rate_markersize:
markersize = spikes_in_bin[is_spikes_in_bin] * markersize
ax.scatter(x[:-1][is_spikes_in_bin], y[:-1][is_spikes_in_bin],
facecolor=spike_color, edgecolor=spike_color,
s=markersize)
ax.scatter(
x[:-1][is_spikes_in_bin],
y[:-1][is_spikes_in_bin],
facecolor=spike_color,
edgecolor=spike_color,
s=markersize,
)

ax.grid(False)
if origin == 'upper':
if origin == "upper":
ax.invert_yaxis()
return ax


def animate_path(x, y, t, box_size, spike_times=None,
color='grey', alpha=0.5, origin='upper',
spike_color='r', rate_markersize=False, markersize=10.,
animate=False, ax=None, title=''):
def animate_path(
x,
y,
t,
box_size,
spike_times=None,
color="grey",
alpha=0.5,
origin="upper",
spike_color="r",
rate_markersize=False,
markersize=10.0,
animate=False,
ax=None,
title="",
):
"""
Plot path visited
Expand Down Expand Up @@ -93,35 +119,35 @@ def animate_path(x, y, t, box_size, spike_times=None,
"""
if ax is None:
fig = plt.figure()
ax = fig.add_subplot(
111, xlim=[0, box_size], ylim=[0, box_size], aspect=1)
ax = fig.add_subplot(111, xlim=[0, box_size], ylim=[0, box_size], aspect=1)
if spike_times is not None:
spikes_in_bin, _ = np.histogram(spike_times, t)
is_spikes_in_bin = np.array(spikes_in_bin, dtype=bool)

if rate_markersize:
markersizes = spikes_in_bin[is_spikes_in_bin]*markersize
markersizes = spikes_in_bin[is_spikes_in_bin] * markersize
else:
markersizes = markersize*np.ones(is_spikes_in_bin.size)
markersizes = markersize * np.ones(is_spikes_in_bin.size)
ax.set_title(title)
ax.grid(False)
if origin == 'upper':
if origin == "upper":
ax.invert_yaxis()
import time

plt.show()
for idx, x, y, active, msize in zip(range(len(x)), x, y):
ax.plot(x, y, c=color, alpha=alpha)
if spike_times is not None:
if is_spikes_in_bin[idx]:
ax.scatter(x, y, facecolor=spike_color, edgecolor=spike_color,
s=markersizes[idx])
ax.scatter(x, y, facecolor=spike_color, edgecolor=spike_color, s=markersizes[idx])
time.sleep(0.1) # plt.pause(0.0001)
plt.draw()
return ax


def plot_head_direction_rate(spike_times, ang_bins, rate_in_ang, projection='polar',
normalization=False, ax=None, color='k'):
def plot_head_direction_rate(
spike_times, ang_bins, rate_in_ang, projection="polar", normalization=False, ax=None, color="k"
):
"""
Expand All @@ -142,26 +168,38 @@ def plot_head_direction_rate(spike_times, ang_bins, rate_in_ang, projection='pol
out : ax
"""
import math

if normalization:
rate_in_ang = normalize(rate_in_ang, mode='minmax')
rate_in_ang = normalize(rate_in_ang, mode="minmax")
if ax is None:
fig = plt.figure()
ax = fig.add_subplot(111, projection=projection)
bin_size = ang_bins[1] - ang_bins[0]
if projection is None:
ax.set_xticks(range(0, 360 + 60, 60))
ax.set_xlim(0, 360)
elif projection == 'polar':
elif projection == "polar":
ang_bins = [math.radians(deg) for deg in ang_bins]
bin_size = math.radians(bin_size)
ax.set_xticks([0, np.pi])
ax.bar(ang_bins, rate_in_ang, width=bin_size, color=color)
return ax


def plot_ratemap(x, y, t, spike_times, bin_size=0.05, box_size=1,
box_size=1, vmin=0, ax=None, smoothing=.05,
origin='upper', cmap='viridis'):
def plot_ratemap(
x,
y,
t,
spike_times,
bin_size=0.05,
box_size=1,
box_size=1,
vmin=0,
ax=None,
smoothing=0.05,
origin="upper",
cmap="viridis",
):
"""
Expand All @@ -184,19 +222,17 @@ def plot_ratemap(x, y, t, spike_times, bin_size=0.05, box_size=1,
fig = plt.figure()
ax = fig.add_subplot(111, xlim=[0, 1], ylim=[0, 1], aspect=1)

map = SpatialMap(
x, y, t, spike_times, bin_size=bin_size, box_size=box_size)
map = SpatialMap(x, y, t, spike_times, bin_size=bin_size, box_size=box_size)
rate_map = map.rate_map(smoothing)
ax.imshow(rate_map, interpolation='none', origin=origin,
extent=(0, 1, 0, 1), vmin=vmin, cmap=cmap)
ax.set_title('%.2f Hz' % np.nanmax(rate_map))
ax.imshow(rate_map, interpolation="none", origin=origin, extent=(0, 1, 0, 1), vmin=vmin, cmap=cmap)
ax.set_title("%.2f Hz" % np.nanmax(rate_map))
ax.grid(False)
return ax


def plot_occupancy(x, y, t, bin_size=0.05, box_size=1, box_size=1,
vmin=0, ax=None, convolve=True,
origin='upper', cmap='jet'):
def plot_occupancy(
x, y, t, bin_size=0.05, box_size=1, box_size=1, vmin=0, ax=None, convolve=True, origin="upper", cmap="jet"
):
"""
Expand All @@ -219,10 +255,10 @@ def plot_occupancy(x, y, t, bin_size=0.05, box_size=1, box_size=1,
fig = plt.figure()
ax = fig.add_subplot(111, xlim=[0, 1], ylim=[0, 1], aspect=1)

occ_map = occupancy_map(x, y, t, bin_size=bin_size, box_size=box_size,
box_size=box_size, convolve=convolve)
cax = ax.imshow(occ_map, interpolation='none', origin=origin,
extent=(0, 1, 0, 1), vmin=vmin, cmap=cmap, aspect='auto')
occ_map = occupancy_map(x, y, t, bin_size=bin_size, box_size=box_size, box_size=box_size, convolve=convolve)
cax = ax.imshow(
occ_map, interpolation="none", origin=origin, extent=(0, 1, 0, 1), vmin=vmin, cmap=cmap, aspect="auto"
)
# ax.set_title('%.2f s' % np.nanmax(occ_map))
ax.grid(False)
return cax, np.nanmax(occ_map)
58 changes: 58 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[project]
name = "spatial_maps"
version = "0.2.0"
authors = [
{ name = "Mikkel Lepperod", email = "mikkel@simula.no" },
{ name = "Alessio Buccino", email = "alessiop.buccino@gmail.com" },
]

description = "Compute spatial maps for neural data."
readme = "README.md"
requires-python = ">=3.10"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]

dependencies = [
"numpy<2",
"scipy",
"scikit-image",
"astropy",
"pandas",
"elephant",
"matplotlib"
]

[project.urls]
homepage = "https://github.com/CINPLA/spatial-maps"
repository = "https://github.com/CINPLA/spatial-maps"

[build-system]
requires = ["setuptools>=62.0"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
include-package-data = true

[tool.setuptools.packages.find]
where = ["src"]
include = ["spatial_maps*"]
namespaces = false

[project.optional-dependencies]
dev = ["pre-commit", "black[jupyter]", "isort", "ruff"]
test = ["pytest", "pytest-cov", "pytest-dependency", "mountainsort5"]
docs = ["sphinx-gallery", "sphinx_rtd_theme"]
full = [
"spatial_maps[dev]",
"spatial_maps[test]",
"spatial_maps[docs]",
]

[tool.coverage.run]
omit = ["tests/*"]

[tool.black]
line-length = 120
31 changes: 3 additions & 28 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
# -*- coding: utf-8 -*-
from setuptools import setup
import os

from setuptools import setup, find_packages
import setuptools

long_description = open("README.md").read()

install_requires = [
'numpy>=1.9',
'scipy',
'astropy',
'pandas>=0.14.1',
'elephant',
'matplotlib']
extras_require = {
'testing': ['pytest'],
'docs': ['numpydoc>=0.5',
'sphinx>=1.2.2',
'sphinx_rtd_theme']
}

setup(
name="spatial_maps",
install_requires=install_requires,
tests_require=install_requires,
extras_require=extras_require,
packages=find_packages(),
include_package_data=True,
version='0.1',
)
if __name__ == "__main__":
setuptools.setup()
Loading

0 comments on commit 4e97d52

Please sign in to comment.