Skip to content

Commit

Permalink
Merge pull request #151 from neuroscout/fix/download
Browse files Browse the repository at this point in the history
Fix incorrect CLI flags
  • Loading branch information
adelavega authored Feb 21, 2022
2 parents d1278a3 + 8caf6bb commit 974e7a4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 32 deletions.
6 changes: 1 addition & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ RUN git config --global user.email "user@example.edu"
COPY [".", "/src/neuroscout"]

RUN /bin/bash -c "source activate neuro \
&& pip install -q --no-cache-dir -e /src/neuroscout/" \
&& sync

RUN /bin/bash -c "source activate neuro \
&& pip install -q --no-cache-dir --upgrade -r /src/neuroscout/requirements.txt" \
&& pip install -q --no-cache-dir /src/neuroscout/" \
&& sync

WORKDIR /work
Expand Down
12 changes: 7 additions & 5 deletions neuroscout_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
import click
import warnings
warnings.filterwarnings("ignore", category=FutureWarning)
import neuroscout_cli.commands as ncl
from fitlins.cli.run import run_fitlins
logging.getLogger().setLevel(logging.INFO)

def fitlins_help(ctx, param, value):
from fitlins.cli.run import run_fitlins
if not value or ctx.resilient_parsing:
return
run_fitlins(['--help'])
Expand Down Expand Up @@ -69,7 +68,8 @@ def run(**kwargs):
docker run --rm -it -v /local/dir:/out neuroscout/neuroscout-cli run a54oo /out
"""
sys.exit(ncl.Run(kwargs).run())
from neuroscout_cli.commands import Run
sys.exit(Run(kwargs).run())


@click.argument('out_dir', type=click.Path())
Expand All @@ -87,7 +87,8 @@ def get(**kwargs):
Note: `run` automatically calls `get` prior to execution, by default.
"""
sys.exit(ncl.Get(kwargs).run())
from neuroscout_cli.commands import Get
sys.exit(Get(kwargs).run())

@click.argument('out_dir', type=click.Path())
@click.argument('analysis_id')
Expand All @@ -101,4 +102,5 @@ def upload(**kwargs):
Note: `run` automatically calls `upload` after execution, by default.
"""
sys.exit(ncl.Upload(kwargs).run())
from neuroscout_cli.commands import Upload
sys.exit(Upload(kwargs).run())
1 change: 0 additions & 1 deletion neuroscout_cli/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class Command(metaclass=ABCMeta):

def __init__(self, options):
self.options = options
print(self.options)
self.bundle_id = self.options['analysis_id']
self.api = Neuroscout()
self.main_dir = Path(self.options['out_dir']) / f'neuroscout-{self.bundle_id}'
Expand Down
20 changes: 10 additions & 10 deletions neuroscout_cli/commands/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ class Get(Command):

def __init__(self, options):
super().__init__(options)
self.resources = None
self.download_dir = self.options.get('--download-dir', None)
self.download_dir = self.options['download_dir']
if self.download_dir is not None:
self.download_dir = Path(self.download_dir)

self.preproc_dir = None

# Make dirs
self.main_dir.mkdir(parents=True, exist_ok=True)
self.bundle_dir.mkdir(parents=True, exist_ok=True)
Expand Down Expand Up @@ -83,13 +80,11 @@ def download_bundle(self):

def download_data(self):
""" Use DataLad to download necessary data to disk """
self.download_bundle()
with self.model_path.open() as f:
model = convert_JSON(json.load(f))

try:
# Custom logic to fetch and avoid indexing dataset
preproc_dir = self.preproc_dir
paths = []

# Custom logic to fetch relevant files
Expand All @@ -114,14 +109,14 @@ def download_data(self):
for run in runs:
for task in tasks:
pre = f'sub-{sub}/**/func/*{task}{run}space-MNI152NLin2009cAsym*'
paths += list(preproc_dir.glob(pre + 'preproc*.nii.gz'))
paths += list(preproc_dir.glob(pre + 'brain_mask.nii.gz'))
paths += list(self.preproc_dir.glob(pre + 'preproc*.nii.gz'))
paths += list(self.preproc_dir.glob(pre + 'brain_mask.nii.gz'))

if not paths:
raise Exception("No images suitable for download.")

# Get all JSON files
paths += list(preproc_dir.rglob('*.json'))
paths += list(self.preproc_dir.rglob('*.json'))

# Get with DataLad
get([str(p) for p in paths], dataset=self.preproc_dir.parent)
Expand Down Expand Up @@ -154,5 +149,10 @@ def _check_version(self):
sys.exit(1)

def run(self):
return self.download_data()
retcode = self.download_bundle()

if not self.options.get('bundle_only', False):
retcode = self.download_data()

return retcode

8 changes: 4 additions & 4 deletions neuroscout_cli/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ class Run(Get):

def run(self):
# Download bundle and get dataset if necessary
if not self.options.get('--no-get', False):
if not self.options['no_get']:
retcode = super().run()

# Need to retrieve this from fitlins output once it's available
fitlins_args = [
str(self.preproc_dir),
str(self.main_dir),
'dataset',
f'--model={self.model_path}',
f'--model={str(self.model_path.absolute())}',
'--ignore=/(.*desc-confounds_regressors.*)/',
f'--derivatives={str(self.bundle_dir)} {str(self.preproc_dir)}',
f'--derivatives={str(self.bundle_dir.absolute())} {str(self.preproc_dir.absolute())}',
]

# Append pass through options
Expand Down Expand Up @@ -52,7 +52,7 @@ def run(self):
)
return retcode

if self.options.get('--no-upload', False):
if not self.options['no_upload']:
# Upload results
up = Upload(self.options)
up.run(preproc_dir=self.preproc_dir)
Expand Down
16 changes: 9 additions & 7 deletions neuroscout_cli/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@ def __init__(self, options):
super().__init__(options)

def run(self, preproc_dir=None):
subject_level = self.options.get('--upload-first-level', False)
nv_force = self.options.get('--force-upload', False)
subject_level = self.options['upload_first_level']
nv_force = self.options['force_upload']
resources = json.load((self.bundle_dir / 'resources.json').open())

model = json.load(open(self.model_path, 'r'))
n_subjects = len(model['Input']['Subject'])

# Load esimator from file in case of upload only
# Load esimator from fitlins output & neuroscout-cli options
saved_options = json.load(
(self.main_dir / 'options.json').open('r'))
try:
saved_options = json.load((self.main_dir / 'options.json').open('r'))
estimator = saved_options.get('--estimator')
dataset_description = json.load(
(self.main_dir / 'fitlins' / 'dataset_description.json').open('r'))
estimator = dataset_description['PipelineDescription']['Parameters']['estimator']
except:
estimator = None
saved_options = None
print("No saved options found skipping...")
logging.info("No estimator information found skipping...")

fmriprep_version = None
if preproc_dir:
Expand Down

0 comments on commit 974e7a4

Please sign in to comment.