Skip to content

Commit

Permalink
Merge branch 'Inria-Empenn:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
bclenet authored Sep 4, 2023
2 parents d6e67f3 + 5c20c6b commit c3bfc53
Show file tree
Hide file tree
Showing 6 changed files with 334 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pipeline_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
pytest:
needs: identify-tests
runs-on: self-hosted
timeout-minutes: 2880 # 48h
steps:
- name: Checkout PR branch
uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
pytest:
needs: identify-tests
runs-on: self-hosted
timeout-minutes: 2880 # 48h
steps:
- name: Checkout PR branch
uses: actions/checkout@v3
Expand Down
6 changes: 3 additions & 3 deletions narps_open/data/results/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def get_uid(self):

def get_file_urls(self):
""" Return a dict containing the download url for each file of the collection.
* dict key is the file base name (with no extension)
* dict key is the file base name (with extension)
* dict value is the download url for the file on Neurovault
"""

Expand All @@ -69,7 +69,7 @@ def get_file_urls(self):
file_urls = {}
for result in json['results']:
# Get data for a file in the collection
file_urls[result['name']] = result['file']
file_urls[result['name']+'.nii.gz'] = result['file']

return file_urls

Expand All @@ -84,7 +84,7 @@ def download(self):
for file_name, file_url in self.files.items():
urlretrieve(
file_url,
join(self.directory, file_name+'.nii.gz'),
join(self.directory, file_name),
show_download_progress
)

Expand Down
17 changes: 11 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,20 @@ def test_pipeline_execution(
# Get missing subjects
missing_subjects = set()
for file in runner.get_missing_first_level_outputs():
missing_subjects.add(get_subject_id(file))
subject_id = get_subject_id(file)
if subject_id is not None:
missing_subjects.add(subject_id)

# Leave if no missing subjects
if not missing_subjects:
break

# Start pipeline
runner.subjects = missing_subjects
runner.start(True, False)
try: # This avoids errors in the workflow to make the test fail
runner.start(True, False)
except(RuntimeError) as err:
print('RuntimeError: ', err)

# Check missing files for the last time
missing_files = runner.get_missing_first_level_outputs()
Expand All @@ -80,15 +85,15 @@ def test_pipeline_execution(

# Indices and keys to the unthresholded maps
indices = list(range(1, 18, 2))
keys = [f'hypo{i}_unthresh.nii.gz' for i in range(1, 10)]

# Retrieve the paths to the reproduced files
reproduced_files = runner.pipeline.get_hypotheses_outputs()
reproduced_files = [reproduced_files[i] for i in indices]

# Retrieve the paths to the results files
collection = ResultsCollection(team_id)
results_files = [join(collection.directory, collection.files[k]) for k in keys]
results_files = [join(collection.directory, f) for f in collection.files.keys()]
results_files = [results_files[i] for i in indices]

# Compute the correlation coefficients
return [
Expand Down Expand Up @@ -142,10 +147,10 @@ def test_pipeline_evaluation(team_id: str):

for subjects in [20, 40, 60, 80, 108]:
# Execute pipeline
results = helpers.test_pipeline_execution(team_id, subjects)
results = test_pipeline_execution(team_id, subjects)

# Compute correlation with results
passed = helpers.test_correlation_results(results, subjects)
passed = test_correlation_results(results, subjects)

# Write values in a file
with open(file_name, 'a', encoding = 'utf-8') as file:
Expand Down
4 changes: 2 additions & 2 deletions tests/data/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ def test_create():
assert collection.uid == '4881'
assert 'results/orig/4881_2T6S' in collection.directory
test_str = 'http://neurovault.org/media/images/4881/hypo1_thresholded_revised.nii.gz'
assert collection.files['hypo1_thresh'] == test_str
assert collection.files['hypo1_thresh.nii.gz'] == test_str

collection = ResultsCollection('43FJ')
assert collection.team_id == '43FJ'
assert collection.uid == '4824'
assert 'results/orig/4824_43FJ' in collection.directory
test_str = 'http://neurovault.org/media/images/4824/'
test_str += 'Zstat_Thresholded_Negative_Effect_of_Loss_Equal_Indifference.nii.gz'
assert collection.files['hypo5_thresh'] == test_str
assert collection.files['hypo5_thresh.nii.gz'] == test_str

@staticmethod
@mark.unit_test
Expand Down
Loading

0 comments on commit c3bfc53

Please sign in to comment.