diff --git a/.github/workflows/python-deploy_to_pypi.yml b/.github/workflows/python-deploy_to_pypi.yml index 9089603..1845dbd 100644 --- a/.github/workflows/python-deploy_to_pypi.yml +++ b/.github/workflows/python-deploy_to_pypi.yml @@ -7,15 +7,17 @@ on: jobs: deploy: name: Build and publish to PyPI - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.7.6 - uses: actions/setup-python@v2 + - uses: actions/checkout@v3 with: - python-version: 3.7.6 + fetch-depth: 0 + - name: Set up Python 3.9 + uses: actions/setup-python@v4 + with: + python-version: 3.9 - name: Install pypa/build - run: pip install build + run: pip install build pbr wheel - name: Build a binary wheel and a source tarball run: python -m build --sdist --wheel --outdir dist/ . - name: Publish distribution to PyPI diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index b0c668f..cef81ad 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -12,39 +12,37 @@ on: jobs: pytest: name: Run PHOTONAI_neuro tests - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.7.6 - uses: actions/setup-python@v2 + - uses: actions/checkout@v3 + - name: Set up Python 3.9 + uses: actions/setup-python@v4 with: - python-version: 3.7.6 + python-version: 3.9 - name: Install dependencies run: | pip install wheel flake8 - python setup.py egg_info - pip install pytest pytest-cov coveralls -r photonai_neuro.egg-info/requires.txt + pip install pytest pytest-cov coveralls -r requirements.txt - name: Test with pytest run: | - PYTHONPATH=./ pytest ./test --cov=./photonai_neuro --tb=long + PYTHONPATH=./ pytest ./test --cov-report lcov:./coverage/lcov.info --cov=./photonai_neuro --tb=long - name: Coveralls - run: coveralls - env: - COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} deploy: name: Build and publish to TestPyPI - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 needs: pytest if: github.ref == 'refs/heads/master' steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.7.6 - uses: actions/setup-python@v2 + - uses: actions/checkout@v3 + - name: Set up Python 3.9 + uses: actions/setup-python@v4 with: - python-version: 3.7.6 + python-version: 3.9 - name: Replace version number with commit hash run: | dt=$(date '+%Y.%m.%d.%H.%M.%S') diff --git a/README.md b/README.md index 2f27013..76b691f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +[![PHOTONAI_neuro tests + TestPyPI deployment @master](https://github.com/wwu-mmll/photonai_neuro/actions/workflows/python-test.yml/badge.svg)](https://github.com/wwu-mmll/photonai_neuro/actions/workflows/python-test.yml) +[![Coverage Status](https://coveralls.io/repos/github/wwu-mmll/photonai_neuro/badge.svg?branch=master)](https://coveralls.io/github/wwu-mmll/photonai_neuro?branch=master) +[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=wwu-mmll_photonai_neuro&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=wwu-mmll_photonai_neuro) +![GitHub](https://img.shields.io/github/license/wwu-mmll/photonai_neuro) +[![Twitter URL](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Ftwitter.com%2Fwwu_mmll)](https://twitter.com/wwu_mmll) # PHOTONAI Neuro PHOTONAI Neuro is an add-on module to simplify machine learning analyses for multimodal Magnetic Resonance Imaging (MRI) with PHOTONAI. @@ -5,9 +10,9 @@ Overall, this module combines the functionality of the famous [Nilearn](https:// with the pipeline structure of [PHOTONAI](https://photon-ai.com). ## Project setup -Install the latest version directly from Github: +Install the latest version directly via pip: ``` -pip install git+https://github.com/wwu-mmll/photonai_neuro +pip install photonai-neuro ``` ## Features diff --git a/photonai_neuro/__init__.py b/photonai_neuro/__init__.py index f70eb15..6d900a7 100644 --- a/photonai_neuro/__init__.py +++ b/photonai_neuro/__init__.py @@ -1,23 +1,39 @@ import os -from datetime import datetime - +from photonai.base import PhotonRegistry from photonai.photonlogger import logger from .util import register_photonai_neuro - - -# REGISTRATION -current_path = os.path.dirname(os.path.abspath(__file__)) -registered_file = os.path.join(current_path, "registered") -logger.info("Checking Neuro Module Registration") -if not os.path.isfile(registered_file): - logger.info("Registering Neuro Module") - register_photonai_neuro() - with open(os.path.join(registered_file), "w") as f: - f.write(str(datetime.now())) +from .version import __version__ from .atlas_mapper import AtlasMapper from .brain_mask import BrainMask from .brain_atlas import BrainAtlas from .atlas_library import AtlasLibrary from .neuro_branch import NeuroBranch + + +# REGISTRATION +def do_register(current_path, registered_file): # pragma: no cover + reg = PhotonRegistry() + reg.add_module(os.path.join(current_path, "photonai_neuro.json")) + with open(os.path.join(registered_file), "w") as f: + f.write(str(__version__)) + + +def register(): # pragma: no cover + current_path = os.path.dirname(os.path.abspath(__file__)) + registered_file = os.path.join(current_path, "registered") + logger.info("Checking Neuro Module Registration") + if not os.path.isfile(registered_file): # pragma: no cover + logger.info("Registering Neuro Module") + do_register(current_path=current_path, registered_file=registered_file) + else: + with open(os.path.join(registered_file), "r") as f: + if f.read() == __version__: + logger.info("Current version already registered") + else: + logger.info("Updating Neuro Module") + do_register(current_path=current_path, registered_file=registered_file) + + +register() diff --git a/photonai_neuro/neuro_branch.py b/photonai_neuro/neuro_branch.py index 4ce2c67..414b343 100644 --- a/photonai_neuro/neuro_branch.py +++ b/photonai_neuro/neuro_branch.py @@ -49,6 +49,10 @@ def __iadd__(self, pipe_element: PipelineElement): self """ + if pipe_element.name not in NeuroBranch.NEURO_ELEMENTS: + # reload + PhotonRegistry.ELEMENT_DICTIONARY = PhotonRegistry().get_package_info() + NeuroBranch.NEURO_ELEMENTS = PhotonRegistry().get_package_info(['photonai_neuro']) if pipe_element.name in NeuroBranch.NEURO_ELEMENTS: # as the neuro branch is parallelized and processes several images subsequently on # different cores, we need to stop the children to process on several cores as well diff --git a/photonai_neuro/version.py b/photonai_neuro/version.py new file mode 100644 index 0000000..de89e1c --- /dev/null +++ b/photonai_neuro/version.py @@ -0,0 +1,3 @@ +from pbr.version import VersionInfo + +__version__ = VersionInfo('photonai_neuro').release_string() diff --git a/requirements.txt b/requirements.txt index ca83f72..3180fb4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ pandas photonai scikit-learn scikit-image +pbr \ No newline at end of file diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..e27d8a4 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,24 @@ +[metadata] +name = photonai_neuro +description-file = README.md +author = PHOTONAI Team +author_email = hahnt@uni-muenster.de +url = https://www.photon-ai.com/ +license = GPLv3 +long_description_content_type = text/markdown +project_urls: + Source Code = https://github.com/wwu-mmll/photonai_neuro + Bug Tracker = https://github.com/wwu-mmll/photonai_neuro/issues +download_url = https://pypi.org/project/photonai_neuro/#files +keywords = + machine learning + neuroimaging + MRI +classifiers = + License :: OSI Approved :: GNU General Public License v3 (GPLv3) + Topic :: Software Development :: Libraries :: Python Modules + Topic :: Scientific/Engineering :: Artificial Intelligence + Intended Audience :: Science/Research + +[files] +package = photonai_neuro diff --git a/setup.py b/setup.py index 68fb7ea..472b616 100644 --- a/setup.py +++ b/setup.py @@ -1,33 +1,5 @@ -try: - from setuptools import setup, find_packages -except ImportError: - from ez_setup import use_setuptools - use_setuptools() - from setuptools import setup, find_packages - - -__version__ = '0.1.0' +from setuptools import setup setup( - name='photonai_neuro', - packages=find_packages(), - include_package_data=True, - version=__version__, - description=""" -PHOTONAI NEURO -The Neuro Module enables loading and preprocessing neuroimaging data such as structural and -functional Magnetic Resonance Imaging (MRI) data. -In addition, it supports a range of advanced feature extraction and feature engineering as well as atlas-based analyses. -""", - author='PHOTONAI Team', - author_email='hahnt@wwu.de', - url='https://github.com/mmll-wwu/photonai_neuro.git', - download_url='https://github.com/wwu-mmll/photonai_neuro/archive/' + __version__ + '.tar.gz', - keywords=['machine learning', 'neuroimaging', 'MRI'], - classifiers=[], - install_requires=[ - 'photonai', - 'nibabel', - 'nilearn', - 'scikit-image'] + pbr=True ) diff --git a/test/test_atlas_mapper.py b/test/test_atlas_mapper.py index dacbc5b..ba77049 100644 --- a/test/test_atlas_mapper.py +++ b/test/test_atlas_mapper.py @@ -32,11 +32,13 @@ def create_hyperpipe(self): @staticmethod def create_data(): n_subjects = 20 - dataset_files = fetch_oasis_vbm(n_subjects=n_subjects) - _ = dataset_files.ext_vars['age'].astype(float) - gender = dataset_files.ext_vars['mf'].astype(str) - y = np.array(gender) - X = np.array(dataset_files.gray_matter_maps) + y = [0] + while len(np.unique(y)) == 1: + dataset_files = fetch_oasis_vbm(n_subjects=n_subjects) + _ = dataset_files.ext_vars['age'].astype(float) + gender = dataset_files.ext_vars['mf'].astype(str) + y = np.array(gender) + X = np.array(dataset_files.gray_matter_maps) return X, y def test_fit_reload_all(self):