Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packaging #7

Closed
wants to merge 12 commits into from
39 changes: 39 additions & 0 deletions . github/workflows/github-actions-demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Sagittal_Average python package
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: [push]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install the dependencies
run: |
python -m pip install --upgrade pip
- name: Install the package
run: |
pip install -e .
- name: Test with pytest
run: |
pytest
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Sagittal_Average.egg-info/

.pytest_cache
Sagittal_Average/__pycache__
Sagittal_Average/tests/__pycache__

Sagittal_Average/tests/brain_average.csv
Sagittal_Average/tests/brain_sample.csv

brain_sample.csv
brain_average.csv
4 changes: 4 additions & 0 deletions CITATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
If you wish to refer to this course, please cite the URL
http://github-pages.ucl.ac.uk/rsd-engineeringcourse/

Portions of the material are taken from [Software Carpentry](http://software-carpentry.org/)
3 changes: 3 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(C) University College London 2014

This "sagittal_average" example package is granted into the public domain.
19 changes: 19 additions & 0 deletions READMD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
This is a very simple example package used as part of the UCL
[Research Software Engineering with Python](development.rc.ucl.ac.uk/training/engineering) course.

## Installation

```bash
pip install git+git://github.com/ucl-rits/greeter
pip install git+git://github.com/chongfengling/sagittal_average_packaging
```

## Usage

Invoke the tool with `sagittal_average_run <file_input> <file_output>` or use it on your own library:

```python
from Sagittal_Average import sagittal_brain

sagittal_brain.run_averages(file_input, file_output)
```
Empty file added Sagittal_Average/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions Sagittal_Average/command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
from .sagittal_brain import *


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.",
)
arguments = parser.parse_args()

run_averages(arguments.file_input, arguments.file_output)
# print('processed')


if __name__ == "__main__":
process()
22 changes: 22 additions & 0 deletions Sagittal_Average/sagittal_brain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter

import numpy as np


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
The rows are intersections of the sagittal/horizontal planes

The result is the average for each sagittal/horizontal plane (rows)
"""
# Open the file to analyse
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=",")
Empty file.
17 changes: 17 additions & 0 deletions Sagittal_Average/tests/test_sth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import numpy as np
from Sagittal_Average.sagittal_brain import *
def test_sth():
data_input = np.zeros((20, 20))
data_input[-1, :] = 1
np.savetxt("brain_sample.csv", data_input, fmt='%d', delimiter=',')

# The expected result is all zeros, except the last one, it should be 1
expected = np.zeros(20)
expected[-1] = 1

run_averages(file_input="brain_sample.csv",
file_output="brain_average.csv")

result = np.loadtxt("brain_average.csv", delimiter=',')

np.testing.assert_array_equal(result, expected)
34 changes: 0 additions & 34 deletions sagittal_brain.py

This file was deleted.

10 changes: 10 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from setuptools import setup, find_packages

setup(
name="Sagittal_Average",
version="0.1.2",
packages=find_packages(),
entry_points={
'console_scripts':['sagittal_average_run = Sagittal_Average.command:process']
}
)