Skip to content

Commit

Permalink
Merge pull request #15 from theislab/develop
Browse files Browse the repository at this point in the history
Release 1.1.0
  • Loading branch information
hspitzer authored Nov 25, 2022
2 parents 572037e + 353ae23 commit 46544d5
Show file tree
Hide file tree
Showing 42 changed files with 5,008 additions and 2,902 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.0.5
current_version = 1.0.0
commit = True
tag = True
files = setup.py campa/__init__.py
Expand Down
50 changes: 26 additions & 24 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,30 @@ default_stages:
minimum_pre_commit_version: 2.9.3
repos:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910
rev: v0.982
hooks:
- id: mypy
additional_dependencies: [numpy==1.20.0, scipy, pandas, types-requests]
- repo: https://github.com/psf/black
rev: 21.6b0
rev: 22.10.0
hooks:
- id: black
additional_dependencies: [toml]
- repo: https://github.com/timothycrosley/isort
rev: 5.9.1
rev: 5.10.1
hooks:
- id: isort
additional_dependencies: [toml]
args: [--order-by-type]
- repo: https://github.com/asottile/yesqa
rev: v1.2.3
hooks:
- id: yesqa
additional_dependencies: [flake8-tidy-imports, flake8-docstrings, flake8-rst-docstrings, flake8-comprehensions, flake8-bugbear, flake8-logging-format, flake8-blind-except, flake8-builtins, flake8-pytest-style, flake8-mock, flake8-string-format]
# temporarily disable yesqa, because of: ValueError: not enough values to unpack (expected 2, got 1).
# Possibly related to https://github.com/asottile/yesqa/issues/132
#- repo: https://github.com/asottile/yesqa
# rev: v1.4.0
# hooks:
# - id: yesqa
# additional_dependencies: [flake8-tidy-imports, flake8-docstrings, flake8-rst-docstrings, flake8-comprehensions, flake8-bugbear, flake8-logging-format, flake8-blind-except, flake8-builtins, flake8-pytest-style, flake8-mock, flake8-string-format]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.3.0
hooks:
- id: detect-private-key
- id: check-merge-conflict
Expand All @@ -49,7 +51,7 @@ repos:
- id: check-toml
- id: requirements-txt-fixer
- repo: https://github.com/myint/autoflake
rev: v1.4
rev: v1.7.7
hooks:
- id: autoflake
args: [--in-place, --remove-all-unused-imports, --remove-unused-variable, --ignore-init-module-imports]
Expand All @@ -59,29 +61,29 @@ repos:
- id: flake8
additional_dependencies: [flake8-tidy-imports, flake8-docstrings, flake8-rst-docstrings, flake8-comprehensions, flake8-bugbear, flake8-logging-format, flake8-blind-except, flake8-builtins, flake8-pytest-style, flake8-mock, flake8-string-format]
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 2.1.5
rev: 3.0.0
hooks:
- id: script-must-have-extension
name: Check executable files use .sh extension
types: [shell, executable]
# YAML files
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.1.0
rev: v2.4.0
hooks:
- id: pretty-format-yaml
args: [--autofix, --indent, '4']
# docs (md/rst files)
- repo: https://github.com/myint/rstcheck
rev: 3f92957478422df87bd730abde66f089cc1ee19b
hooks:
- id: rstcheck
#- repo: https://github.com/myint/rstcheck
# rev: v6.1.0
# hooks:
# - id: rstcheck
- repo: https://github.com/asottile/blacken-docs
rev: v1.10.0
rev: v1.12.1
hooks:
- id: blacken-docs
additional_dependencies: [black==20.8b1]
additional_dependencies: [black==22.10.0]
- repo: https://github.com/asottile/pyupgrade
rev: v2.19.4
rev: v3.1.0
hooks:
- id: pyupgrade
args: [--py3-plus, --py37-plus]
Expand All @@ -95,26 +97,26 @@ repos:
- id: rst-directive-colons
- id: rst-inline-touching-normal
- repo: https://github.com/PyCQA/doc8
rev: 0.9.0a1
rev: v1.0.0
hooks:
- id: doc8
# jupyter notebooks
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.3.1
rev: 1.5.3
hooks:
- id: nbqa-black
additional_dependencies: [black==21.6b0]
additional_dependencies: [black==22.10.0]
- id: nbqa-isort
additional_dependencies: [isort==5.9.1]
args: [--order-by-type]
- id: nbqa
entry: nbqa autoflake
name: nbqa-autoflake
alias: nbqa-autoflake
additional_dependencies: [autoflake==v1.4]
additional_dependencies: [autoflake==v1.7.7]
args: [--in-place, --remove-all-unused-imports, --remove-unused-variable, --ignore-init-module-imports]
- id: nbqa-flake8
additional_dependencies: [flake8==3.9.2, flake8-tidy-imports, flake8-docstrings, flake8-rst-docstrings, flake8-comprehensions, flake8-bugbear, flake8-logging-format, flake8-blind-except, flake8-builtins, flake8-pytest-style, flake8-mock, flake8-string-format]
- id: nbqa-pyupgrade
args: [--py3-plus, --py37-plus]
additional_dependencies: [pyupgrade==v2.19.4]
additional_dependencies: [pyupgrade==v3.1.0]
2 changes: 1 addition & 1 deletion .rstcheck.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[rstcheck]
ignore_messages=(Unknown target name:.*|No (directive|role) entry for "(auto)?(bibliography|nbgallery|class|method|property|function|func|mod|module|attribute|argparse)" in module "docutils\.parsers\.rst\.languages\.en"\.|Hyperlink target "campatutorials" is not referenced.)
ignore_messages=(Unknown target name:.*|No (directive|role) entry for "(auto)?(bibliography|nbgallery|class|method|property|function|func|mod|module|attribute|argparse|currentmodule|autosummary)" in module "docutils\.parsers\.rst\.languages\.en"\.|Hyperlink target "campatutorials" is not referenced.)
report=info
6 changes: 1 addition & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@ Please see our preprint
Installation
------------

Install CAMPA by running::
CAMPA was developed for Python 3.9 and can be installed by running::

pip install campa

Setup `data and experiment paths`_ with::

campa setup


Contributing
------------
Expand Down
6 changes: 1 addition & 5 deletions README_pypi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@ Please see our preprint
Installation
------------

Install CAMPA by running::
CAMPA was developed for Python 3.9 and can be installed by running::

pip install campa

Setup `data and experiment paths`_ with::

campa setup


Contributing
------------
Expand Down
2 changes: 1 addition & 1 deletion campa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = __maintainer__ = "Hannah Spitzer, Scott Berry"
__email__ = ", ".join(["hannah.spitzer@helmholtz-muenchen.de", "scott.berry@unsw.edu.au"])
__version__ = "0.0.5"
__version__ = "1.0.0"


from importlib.metadata import version
Expand Down
45 changes: 28 additions & 17 deletions campa/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def _get_base_parser():
usage="""campa <command> [<args>]
Available subcommands are:
setup Create configuration file campa.ini
setup Create configuration file ``campa.ini``
create_dataset Create NNDataset using parameter file
train Train and evaluate models defined by experiment config
cluster Cluster data and project clustering
Expand All @@ -25,18 +25,18 @@ def _get_base_parser():


def _get_setup_parser():
parser = argparse.ArgumentParser(description="Create configuration file campa.ini.")
parser = argparse.ArgumentParser(description="Create configuration file ``campa.ini``.")
parser.add_argument(
"--force",
"--quiet",
action="store_true",
help="force recreation of campa.ini even if exists",
help="create default configuration file without asking for user input.",
)
return parser


def _get_create_dataset_parser():
parser = argparse.ArgumentParser(description=("Create NNDataset using parameter file"))
parser.add_argument("params", help="path to data_params.py")
parser.add_argument("params", help="path to ``data_params.py``")
return parser


Expand All @@ -48,10 +48,10 @@ def _get_train_parser():
choices=["all", "train", "evaluate", "trainval", "compare"],
)
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("--config", help="path_to_experiment_config.py")
group.add_argument("--config", help="path to ``experiment_config.py``")
group.add_argument(
"--experiment-dir",
help="experiment_dir containing experiment folders. Relative to EXPERIMENT_DIR",
help="``experiment_dir`` containing experiment folders. Relative to EXPERIMENT_DIR",
)
parser.add_argument(
"--exp-name",
Expand Down Expand Up @@ -80,37 +80,47 @@ def _get_cluster_parser():
)
create.add_argument(
"--save-dir",
help="directory to save subsampled cluster data, relative to experiment dir. Default is aggregated/sub-FRAC", # noqa: E501
help="directory to save subsampled cluster data, relative to ``experiment-dir``. Default is ``aggregated/sub-FRAC``", # noqa: E501
)
create.add_argument(
"--cluster",
help="use cluster params in Experiment config to cluster the subsetted data.",
help="use cluster parameters in Experiment config to cluster the subsetted data.",
action="store_true",
)
create.set_defaults(func=campa.tl.create_cluster_data)
# prepare-full
prepare = subparsers.add_parser("prepare-full", help="Prepare full data for clustering. Predicts cluster-rep.")
prepare.add_argument(
"--save-dir",
help="directory to save prepared full data to, relative to experiment dir.",
help="directory to save prepared full data to, relative to ``experiment-dir``.",
default="aggregated/full_data",
)
prepare.add_argument(
"--data-dirs",
help="Data directories to prepare. Defaults to experiment data directories",
nargs="+",
type=str,
default=None,
),
prepare.set_defaults(func=campa.tl.prepare_full_dataset)
# project
project = subparsers.add_parser("project", help="Project existing clustering.")
project.add_argument(
"cluster_data_dir",
metavar="cluster-data-dir",
help="directory in which clustering is stored relative to experiment dir. Usually in aggregated/sub-FRAC",
help="""
directory in which clustering is stored relative to ``experiment-dir``.
Usually in ``aggregated/sub-FRAC``
""",
)
project.add_argument(
"--save-dir",
help="directory in which data to be projected is stored, relative to experiment dir.",
help="directory in which data to be projected is stored, relative to ``experiment-dir``.",
default="aggregated/full_data",
)
project.add_argument(
"--data-dir",
help="data to project. If not specified, project all data_dirs in save_dir",
help="data to project. If not specified, project all ``data_dirs`` in ``save_dir``",
)
project.add_argument("--cluster-name", default="clustering", help="name of clustering to project")
project.set_defaults(func=campa.tl.project_cluster_data)
Expand All @@ -119,7 +129,7 @@ def _get_cluster_parser():

def _get_extract_features_parser():
parser = argparse.ArgumentParser(description=("Extract features from clustered dataset."))
parser.add_argument("params", help="path to feature_params.py")
parser.add_argument("params", help="path to ``feature_params.py``")
return parser


Expand All @@ -141,7 +151,7 @@ def setup(self):
parser = _get_setup_parser()
args = parser.parse_args(sys.argv[2:])
# create and populate campa.ini
prepare_config(args)
prepare_config(**vars(args))

def create_dataset(self):
parser = _get_create_dataset_parser()
Expand All @@ -165,11 +175,12 @@ def cluster(self):
parser = _get_cluster_parser()
args = parser.parse_args(sys.argv[2:])
init_logging()
vars_args = vars(args)
try:
func = args.func
func = vars_args.pop("func")
except AttributeError:
parser.error("too few arguments")
func(**vars(args))
func(**vars_args)

def extract_features(self):
parser = _get_extract_features_parser()
Expand Down
19 changes: 10 additions & 9 deletions campa/cli/prepare_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from campa.constants import campa_config


def prepare_config(args):
def prepare_config(quiet=False):
def get_yn_input():
r = input()
while r.lower() not in ("y", "n"):
Expand Down Expand Up @@ -49,14 +49,15 @@ def get_path_input(name, current_value=None):
)
campa_config.write()

print("Would you like to configure your campa.ini config now? (y/n)")
if get_yn_input():
# read config file
campa_config.EXPERIMENT_DIR = get_path_input("EXPERIMENT_DIR", campa_config.EXPERIMENT_DIR)
campa_config.BASE_DATA_DIR = get_path_input("BASE_DATA_DIR", campa_config.BASE_DATA_DIR)
campa_config.write()
else:
print("Exiting without setting up campa.ini")
if not quiet:
print("Would you like to configure your campa.ini config now? (y/n)")
if get_yn_input():
# read config file
campa_config.EXPERIMENT_DIR = get_path_input("EXPERIMENT_DIR", campa_config.EXPERIMENT_DIR)
campa_config.BASE_DATA_DIR = get_path_input("BASE_DATA_DIR", campa_config.BASE_DATA_DIR)
campa_config.write()
else:
print("Exiting without setting up campa.ini")

# print currently registered data config files
print(f"Currently registered data configs in {campa_config.config_fname}:")
Expand Down
Loading

0 comments on commit 46544d5

Please sign in to comment.