Skip to content

Commit

Permalink
💄 Linting library using ruff
Browse files Browse the repository at this point in the history
The two commands run were:
- `ruff check .` then with `--fix`
- `ruff format .`
  • Loading branch information
dpshelio committed Nov 17, 2024
1 parent d8a0265 commit 0663b60
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 28 deletions.
27 changes: 13 additions & 14 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,28 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'sagittal-average'
copyright = '2019, Charlene Bultoc'
author = 'Charlene Bultoc'
release = '0.1'
project = "sagittal-average"
copyright = "2019, Charlene Bultoc"
author = "Charlene Bultoc"
release = "0.1"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
'sphinx.ext.autodoc', # Support automatic documentation
'sphinx.ext.coverage', # Automatically check if functions are documented
'sphinx.ext.mathjax', # Allow support for algebra
'sphinx.ext.viewcode', # Include the source code in documentation
'sphinx.ext.githubpages', # Publish HTML docs in GitHub Pages¶
"sphinx.ext.autodoc", # Support automatic documentation
"sphinx.ext.coverage", # Automatically check if functions are documented
"sphinx.ext.mathjax", # Allow support for algebra
"sphinx.ext.viewcode", # Include the source code in documentation
"sphinx.ext.githubpages", # Publish HTML docs in GitHub Pages¶
]

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'alabaster'
html_static_path = ['_static']
html_theme = "alabaster"
html_static_path = ["_static"]
23 changes: 17 additions & 6 deletions src/sagittal_average/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@

from .sagittal_brain import run_averages


def process():
parser = ArgumentParser(description="Calculates the average for each sagittal-horizontal plane.",
formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument('file_input', nargs='?', default="brain_sample.csv",
help="Input CSV file with the results from scikit-brain binning algorithm.")
parser.add_argument('--file_output', '-o', default="brain_average.csv",
help="Name of the output CSV file.")
parser = ArgumentParser(
description="Calculates the average for each sagittal-horizontal plane.",
formatter_class=ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
"file_input",
nargs="?",
default="brain_sample.csv",
help="Input CSV file with the results from scikit-brain binning algorithm.",
)
parser.add_argument(
"--file_output",
"-o",
default="brain_average.csv",
help="Name of the output CSV file.",
)
arguments = parser.parse_args()

run_averages(arguments.file_input, arguments.file_output)
7 changes: 3 additions & 4 deletions src/sagittal_average/sagittal_brain.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter

import numpy as np


def run_averages(file_input='brain_sample.csv', file_output='brain_average.csv'):
def run_averages(file_input="brain_sample.csv", file_output="brain_average.csv"):
"""
Calculates the average through the coronal planes
The input file should has as many columns as coronal planes
Expand All @@ -12,11 +11,11 @@ def run_averages(file_input='brain_sample.csv', file_output='brain_average.csv')
The result is the average for each sagittal/horizontal plane (rows)
"""
# Open the file to analyse
planes = np.loadtxt(file_input, dtype=int, delimiter=',')
planes = np.loadtxt(file_input, dtype=int, delimiter=",")

# Calculates the averages through the sagittal/horizontal planes
# and makes it as a row vector
averages = planes.mean(axis=1)[np.newaxis, :]

# write it out on my file
np.savetxt(file_output, averages, fmt='%.1f', delimiter=',')
np.savetxt(file_output, averages, fmt="%.1f", delimiter=",")
11 changes: 7 additions & 4 deletions tests/test_sagittal_brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

TEST_DIR = Path(__file__).parent


def test_average():
# Creates input file
data_input = np.zeros((20, 20))
Expand All @@ -13,12 +14,14 @@ def test_average():
expected = np.zeros(20)
expected[-1] = 1

np.savetxt(TEST_DIR / "brain_sample.csv", data_input, fmt='%d', delimiter=',')
np.savetxt(TEST_DIR / "brain_sample.csv", data_input, fmt="%d", delimiter=",")

# run python program
run_averages(file_input=TEST_DIR / "brain_sample.csv",
file_output=TEST_DIR / "brain_average.csv")
run_averages(
file_input=TEST_DIR / "brain_sample.csv",
file_output=TEST_DIR / "brain_average.csv",
)

# Check result
result = np.loadtxt(TEST_DIR / "brain_average.csv", delimiter=',')
result = np.loadtxt(TEST_DIR / "brain_average.csv", delimiter=",")
np.testing.assert_array_equal(result, expected)

0 comments on commit 0663b60

Please sign in to comment.