| 1 |
# ex: set sts=4 ts=4 sw=4 noet: |
| 2 |
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## |
| 3 |
# |
| 4 |
# See COPYING file distributed along with the datalad package for the |
| 5 |
# copyright and license terms. |
| 6 |
# |
| 7 |
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## |
| 8 |
"""Benchmarks for some use cases, typically at datalad.api level""" |
| 9 |
|
| 10 |
import os.path as osp |
| 11 |
import sys |
| 12 |
import tempfile |
| 13 |
from os.path import join as opj |
| 14 |
|
| 15 |
from datalad.api import create |
| 16 |
from datalad.utils import ( |
| 17 |
create_tree, |
| 18 |
get_tempfile_kwargs, |
| 19 |
rmtree, |
| 20 |
) |
| 21 |
|
| 22 |
from .common import SuprocBenchmarks |
| 23 |
|
| 24 |
|
| 25 |
class study_forrest(SuprocBenchmarks): |
| 26 |
""" |
| 27 |
Benchmarks for Study Forrest use cases |
| 28 |
""" |
| 29 |
|
| 30 |
timeout = 180 # especially with profiling might take longer than default 60s |
| 31 |
|
| 32 |
def setup(self): |
| 33 |
self.path = tempfile.mkdtemp(**get_tempfile_kwargs({}, prefix='bm_forrest')) |
| 34 |
|
| 35 |
def teardown(self): |
| 36 |
if osp.exists(self.path): |
| 37 |
rmtree(self.path) |
| 38 |
|
| 39 |
def time_make_studyforrest_mockup(self): |
| 40 |
path = self.path |
| 41 |
# Carries a copy of the |
| 42 |
# datalad.tests.utils_testdatasets.py:make_studyforrest_mockup |
| 43 |
# as of 0.12.0rc2-76-g6ba6d53b |
| 44 |
# A copy is made so we do not reflect in the benchmark results changes |
| 45 |
# to that helper's code. This copy only tests on 2 not 3 analyses |
| 46 |
# subds |
| 47 |
public = create(opj(path, 'public'), description="umbrella dataset") |
| 48 |
# the following tries to capture the evolution of the project |
| 49 |
phase1 = public.create('phase1', |
| 50 |
description='old-style, no connection to RAW') |
| 51 |
structural = public.create('structural', description='anatomy') |
| 52 |
tnt = public.create('tnt', description='image templates') |
| 53 |
tnt.clone(source=phase1.path, path=opj('src', 'phase1'), reckless=True) |
| 54 |
tnt.clone(source=structural.path, path=opj('src', 'structural'), reckless=True) |
| 55 |
aligned = public.create('aligned', description='aligned image data') |
| 56 |
aligned.clone(source=phase1.path, path=opj('src', 'phase1'), reckless=True) |
| 57 |
aligned.clone(source=tnt.path, path=opj('src', 'tnt'), reckless=True) |
| 58 |
# new acquisition |
| 59 |
labet = create(opj(path, 'private', 'labet'), description="raw data ET") |
| 60 |
phase2_dicoms = create(opj(path, 'private', 'p2dicoms'), description="raw data P2MRI") |
| 61 |
phase2 = public.create('phase2', |
| 62 |
description='new-style, RAW connection') |
| 63 |
phase2.clone(source=labet.path, path=opj('src', 'labet'), reckless=True) |
| 64 |
phase2.clone(source=phase2_dicoms.path, path=opj('src', 'dicoms'), reckless=True) |
| 65 |
# add to derivatives |
| 66 |
tnt.clone(source=phase2.path, path=opj('src', 'phase2'), reckless=True) |
| 67 |
aligned.clone(source=phase2.path, path=opj('src', 'phase2'), reckless=True) |
| 68 |
# never to be published media files |
| 69 |
media = create(opj(path, 'private', 'media'), description="raw data ET") |
| 70 |
# assuming all annotations are in one dataset (in reality this is also |
| 71 |
# a superdatasets with about 10 subdatasets |
| 72 |
annot = public.create('annotations', description='stimulus annotation') |
| 73 |
annot.clone(source=media.path, path=opj('src', 'media'), reckless=True) |
| 74 |
# a few typical analysis datasets |
| 75 |
# (just doing 2, actual status quo is just shy of 10) |
| 76 |
# and also the real goal -> meta analysis |
| 77 |
metaanalysis = public.create('metaanalysis', description="analysis of analyses") |
| 78 |
for i in range(1, 2): |
| 79 |
ana = public.create('analysis{}'.format(i), |
| 80 |
description='analysis{}'.format(i)) |
| 81 |
ana.clone(source=annot.path, path=opj('src', 'annot'), reckless=True) |
| 82 |
ana.clone(source=aligned.path, path=opj('src', 'aligned'), reckless=True) |
| 83 |
ana.clone(source=tnt.path, path=opj('src', 'tnt'), reckless=True) |
| 84 |
# link to metaanalysis |
| 85 |
metaanalysis.clone(source=ana.path, path=opj('src', 'ana{}'.format(i)), |
| 86 |
reckless=True) |
| 87 |
# simulate change in an input (but not raw) dataset |
| 88 |
create_tree( |
| 89 |
aligned.path, |
| 90 |
{'modification{}.txt'.format(i): 'unique{}'.format(i)}) |
| 91 |
aligned.save('.') |
| 92 |
# finally aggregate data |
| 93 |
aggregate = public.create('aggregate', description='aggregate data') |
| 94 |
aggregate.clone(source=aligned.path, path=opj('src', 'aligned'), reckless=True) |
| 95 |
# the toplevel dataset is intentionally left dirty, to reflect the |
| 96 |
# most likely condition for the joint dataset to be in at any given |
| 97 |
# point in time |