Skip to content

Commit

Permalink
Merge pull request #402 from SainsburyWellcomeCentre/gl-ruff-check
Browse files Browse the repository at this point in the history
Clear all CI checks on all platforms
  • Loading branch information
glopesdev authored Sep 20, 2024
2 parents 871f342 + 1de5c25 commit a889dba
Show file tree
Hide file tree
Showing 62 changed files with 756 additions and 658 deletions.
75 changes: 24 additions & 51 deletions .github/workflows/build_env_run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
name: build_env_run_tests
on:
pull_request:
branches: [ main ]
branches: [main]
types: [opened, reopened, synchronize]
workflow_dispatch: # allows running manually from Github's 'Actions' tab
workflow_dispatch: # allows running manually from Github's 'Actions' tab

jobs:
build_env_pip_pyproject: # checks only for building env using pip and pyproject.toml
name: Build env using pip and pyproject.toml
runs-on: ubuntu-latest
build_env_run_tests: # checks for building env using pyproject.toml and runs codebase checks and tests
name: Build env using pip and pyproject.toml on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
if: github.event.pull_request.draft == false
strategy:
matrix:
Expand All @@ -20,70 +20,43 @@ jobs:
fail-fast: false
defaults:
run:
shell: bash -l {0} # reset shell for each step
shell: ${{ matrix.os == 'windows-latest' && 'cmd' || 'bash' }} -l {0} # Adjust shell based on OS
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Create venv and install dependencies
run: |
python -m venv .venv
source .venv/bin/activate
.venv/Scripts/activate || source .venv/bin/activate
pip install -e .[dev]
pip list
.venv/bin/python -c "import aeon"
build_env_run_tests: # checks for building env using mamba and runs codebase checks and tests
name: Build env and run tests on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
if: github.event.pull_request.draft == false
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.11]
fail-fast: false
defaults:
run:
shell: bash -l {0} # reset shell for each step
steps:
- name: checkout repo
uses: actions/checkout@v2
- name: set up conda env
uses: conda-incubator/setup-miniconda@v2
with:
use-mamba: true
miniforge-variant: Mambaforge
python-version: ${{ matrix.python-version }}
environment-file: ./env_config/env.yml
activate-environment: aeon
- name: Update conda env with dev reqs
run: mamba env update -f ./env_config/env_dev.yml

# Only run codebase checks and tests for ubuntu.
python -c "import aeon"
- name: Activate venv for later steps
run: |
echo "VIRTUAL_ENV=$(pwd)/.venv" >> $GITHUB_ENV
echo "$(pwd)/.venv/bin" >> $GITHUB_PATH # For Unix-like systems
echo "$(pwd)/.venv/Scripts" >> $GITHUB_PATH # For Windows
# Only run codebase checks and tests for Linux (ubuntu).
- name: ruff
if: matrix.os == 'ubuntu-latest'
run: python -m ruff check --config ./pyproject.toml .
run: ruff check .
- name: pyright
if: matrix.os == 'ubuntu-latest'
run: python -m pyright --level error --project ./pyproject.toml .
run: pyright --level error --project ./pyproject.toml .
- name: pytest
if: matrix.os == 'ubuntu-latest'
run: python -m pytest tests/

run: pytest tests/ --ignore=tests/dj_pipeline
- name: generate test coverage report
if: matrix.os == 'ubuntu-latest'
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
python -m pytest --cov=aeon ./tests/ --cov-report=xml:./tests/test_coverage/test_coverage_report.xml
#python -m pytest --cov=aeon ./tests/ --cov-report=html:./tests/test_coverage/test_coverage_report_html
python -m pytest --cov=aeon tests/ --ignore=tests/dj_pipeline --cov-report=xml:tests/test_coverage/test_coverage_report.xml
- name: upload test coverage report to codecov
if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v2
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./tests/test_coverage/
directory: tests/test_coverage/
files: test_coverage_report.xml
fail_ci_if_error: true
verbose: true
21 changes: 7 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
# For info on running pre-commit manually, see `pre-commit run --help`

default_language_version:
python: python3.11

files: "^(test|aeon)\/.*$"
repos:
- repo: meta
hooks:
- id: identity

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: check-json
- id: check-yaml
Expand All @@ -25,20 +21,17 @@ repos:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]

- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
args: [--check, --config, ./pyproject.toml]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.286
rev: v0.6.4
hooks:
# Run the linter with the `--fix` flag.
- id: ruff
args: [--config, ./pyproject.toml]
args: [ --fix ]
# Run the formatter.
- id: ruff-format

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.324
rev: v1.1.380
hooks:
- id: pyright
args: [--level, error, --project, ./pyproject.toml]
Expand Down
2 changes: 1 addition & 1 deletion aeon/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#
#
4 changes: 2 additions & 2 deletions aeon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
finally:
del version, PackageNotFoundError

# Set functions avaialable directly under the 'aeon' top-level namespace
from aeon.io.api import load
# Set functions available directly under the 'aeon' top-level namespace
from aeon.io.api import load as load # noqa: PLC0414
1 change: 0 additions & 1 deletion aeon/analysis/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
#
26 changes: 5 additions & 21 deletions aeon/analysis/block_plotting.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import os
import pathlib
from colorsys import hls_to_rgb, rgb_to_hls
from contextlib import contextmanager
from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import plotly
import plotly.express as px
import plotly.graph_objs as go
import seaborn as sns
from numpy.lib.stride_tricks import as_strided

"""Standardize subject colors, patch colors, and markers."""

Expand All @@ -35,27 +25,21 @@
"star",
]
patch_markers_symbols = ["●", "⧓", "■", "⧗", "♦", "✖", "×", "▲", "★"]
patch_markers_dict = {
marker: symbol for marker, symbol in zip(patch_markers, patch_markers_symbols)
}
patch_markers_dict = dict(zip(patch_markers, patch_markers_symbols, strict=False))
patch_markers_linestyles = ["solid", "dash", "dot", "dashdot", "longdashdot"]


def gen_hex_grad(hex_col, vals, min_l=0.3):
"""Generates an array of hex color values based on a gradient defined by unit-normalized values."""
# Convert hex to rgb to hls
h, l, s = rgb_to_hls(
*[int(hex_col.lstrip("#")[i: i + 2], 16) / 255 for i in (0, 2, 4)]
)
h, l, s = rgb_to_hls(*[int(hex_col.lstrip("#")[i : i + 2], 16) / 255 for i in (0, 2, 4)]) # noqa: E741
grad = np.empty(shape=(len(vals),), dtype="<U10") # init grad
for i, val in enumerate(vals):
cur_l = (l * val) + (
min_l * (1 - val)
) # get cur lightness relative to `hex_col`
cur_l = (l * val) + (min_l * (1 - val)) # get cur lightness relative to `hex_col`
cur_l = max(min(cur_l, l), min_l) # set min, max bounds
cur_rgb_col = hls_to_rgb(h, cur_l, s) # convert to rgb
cur_hex_col = "#%02x%02x%02x" % tuple(
int(c * 255) for c in cur_rgb_col
cur_hex_col = "#{:02x}{:02x}{:02x}".format(
*tuple(int(c * 255) for c in cur_rgb_col)
) # convert to hex
grad[i] = cur_hex_col

Expand Down
24 changes: 14 additions & 10 deletions aeon/analysis/movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
from aeon.io import video


def gridframes(frames, width, height, shape=None):
"""Arranges a set of frames into a grid layout with the specified
pixel dimensions and shape.
def gridframes(frames, width, height, shape: None | int | tuple[int, int] = None):
"""Arranges a set of frames into a grid layout with the specified pixel dimensions and shape.
:param list frames: A list of frames to include in the grid layout.
:param int width: The width of the output grid image, in pixels.
Expand All @@ -21,7 +20,7 @@ def gridframes(frames, width, height, shape=None):
"""
if shape is None:
shape = len(frames)
if type(shape) not in [list, tuple]:
if isinstance(shape, int):
shape = math.ceil(math.sqrt(shape))
shape = (shape, shape)

Expand All @@ -44,7 +43,7 @@ def gridframes(frames, width, height, shape=None):

def averageframes(frames):
"""Returns the average of the specified collection of frames."""
return cv2.convertScaleAbs(sum(np.multiply(1 / len(frames), frames)))
return cv2.convertScaleAbs(np.sum(np.multiply(1 / len(frames), frames)))


def groupframes(frames, n, fun):
Expand All @@ -65,7 +64,7 @@ def groupframes(frames, n, fun):
i = i + 1


def triggerclip(data, events, before=pd.Timedelta(0), after=pd.Timedelta(0)):
def triggerclip(data, events, before=None, after=None):
"""Split video data around the specified sequence of event timestamps.
:param DataFrame data:
Expand All @@ -76,10 +75,16 @@ def triggerclip(data, events, before=pd.Timedelta(0), after=pd.Timedelta(0)):
:return:
A pandas DataFrame containing the frames, clip and sequence numbers for each event timestamp.
"""
if before is not pd.Timedelta:
if before is None:
before = pd.Timedelta(0)
elif before is not pd.Timedelta:
before = pd.Timedelta(before)
if after is not pd.Timedelta:

if after is None:
after = pd.Timedelta(0)
elif after is not pd.Timedelta:
after = pd.Timedelta(after)

if events is not pd.Index:
events = events.index

Expand Down Expand Up @@ -107,8 +112,7 @@ def collatemovie(clipdata, fun):


def gridmovie(clipdata, width, height, shape=None):
"""Collates a set of video clips into a grid movie with the specified pixel dimensions
and grid layout.
"""Collates a set of video clips into a grid movie with the specified pixel dimensions and grid layout.
:param DataFrame clipdata:
A pandas DataFrame where each row specifies video path, frame number, clip and sequence number.
Expand Down
26 changes: 15 additions & 11 deletions aeon/analysis/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from matplotlib import colors
from matplotlib.collections import LineCollection

from aeon.analysis.utils import *
from aeon.analysis.utils import rate, sessiontime


def heatmap(position, frequency, ax=None, **kwargs):
Expand All @@ -31,21 +31,20 @@ def heatmap(position, frequency, ax=None, **kwargs):
return mesh, cbar


def circle(x, y, radius, fmt=None, ax=None, **kwargs):
def circle(x, y, radius, *args, ax=None, **kwargs):
"""Plot a circle centered at the given x, y position with the specified radius.
:param number x: The x-component of the circle center.
:param number y: The y-component of the circle center.
:param number radius: The radius of the circle.
:param str, optional fmt: The format used to plot the circle line.
:param Axes, optional ax: The Axes on which to draw the circle.
"""
if ax is None:
ax = plt.gca()
points = pd.DataFrame(np.linspace(0, 2 * math.pi, 360), columns=["angle"])
points = pd.DataFrame({"angle": np.linspace(0, 2 * math.pi, 360)})
points["x"] = radius * np.cos(points.angle) + x
points["y"] = radius * np.sin(points.angle) + y
ax.plot(points.x, points.y, fmt, **kwargs)
ax.plot(points.x, points.y, *args, **kwargs)


def rateplot(
Expand All @@ -60,16 +59,17 @@ def rateplot(
ax=None,
**kwargs,
):
"""Plot the continuous event rate and raster of a discrete event sequence, given the specified
window size and sampling frequency.
"""Plot the continuous event rate and raster of a discrete event sequence.
The window size and sampling frequency can be specified.
:param Series events: The discrete sequence of events.
:param offset window: The time period of each window used to compute the rate.
:param DateOffset, Timedelta or str frequency: The sampling frequency for the continuous rate.
:param number, optional weight: A weight used to scale the continuous rate of each window.
:param datetime, optional start: The left bound of the time range for the continuous rate.
:param datetime, optional end: The right bound of the time range for the continuous rate.
:param datetime, optional smooth: The size of the smoothing kernel applied to the continuous rate output.
:param datetime, optional smooth: The size of the smoothing kernel applied to the rate output.
:param DateOffset, Timedelta or str, optional smooth:
The size of the smoothing kernel applied to the continuous rate output.
:param bool, optional center: Specifies whether to center the convolution kernels.
Expand Down Expand Up @@ -108,8 +108,8 @@ def colorline(
x,
y,
z=None,
cmap=plt.get_cmap("copper"),
norm=plt.Normalize(0.0, 1.0),
cmap=None,
norm=None,
ax=None,
**kwargs,
):
Expand All @@ -128,9 +128,13 @@ def colorline(
ax = plt.gca()
if z is None:
z = np.linspace(0.0, 1.0, len(x))
if cmap is None:
cmap = plt.get_cmap("copper")
if norm is None:
norm = colors.Normalize(0.0, 1.0)
z = np.asarray(z)
points = np.array([x, y]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
lines = LineCollection(segments, array=z, cmap=cmap, norm=norm, **kwargs)
lines = LineCollection(segments, array=z, cmap=cmap, norm=norm, **kwargs) # type: ignore
ax.add_collection(lines)
return lines
2 changes: 1 addition & 1 deletion aeon/analysis/readme.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#
#
Loading

0 comments on commit a889dba

Please sign in to comment.