Skip to content

Commit

Permalink
First version of the multiplate export / download of experiments.
Browse files Browse the repository at this point in the history
Goal is to allow users download multiples experiments (inside a project).
Useful for experiment / metadata export
  • Loading branch information
killianrochet committed Dec 13, 2023
1 parent 7099729 commit 6e1db6b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
16 changes: 16 additions & 0 deletions elab_bridge/server_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
import pandas as pd


def extended_download(server_config_json, experiment_tags):
api_client = get_elab_config(server_config_json)
experiment_api = elabapi_python.ExperimentsApi(api_client)

response = experiment_api.read_experiments_with_http_info(tags=experiment_tags)

experiments = response[0]

experiment_ids = []

for experiment in experiments:
experiment_ids.append(experiment.id)

return experiment_ids


def download_experiment(save_to, server_config_json, experiment_id, format='json', experiment_axis='columns'):
"""
Download an individual experiment.
Expand Down
21 changes: 20 additions & 1 deletion elab_bridge/tests/test_server_interface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from diglab_utils.test_utils import (test_directory, initialize_test_dir)
from elab_bridge.server_interface import (download_experiment, upload_template, upload_experiment,
delete_template, delete_experiment)
delete_template, delete_experiment, extended_download)

SERVER_CONFIG_YAML = (test_directory / 'testfiles_elab' / 'TestProject' / 'project.json').resolve()

Expand Down Expand Up @@ -52,3 +52,22 @@ def test_download_experiment(initialize_test_dir):
# cleanup
delete_experiment(server_config_json=SERVER_CONFIG_YAML, experiment_id=experiment_id)
json_file.unlink()


def test_extended_download(initialize_test_dir):
json_file = test_directory / 'testfiles_elab' / 'downloaded_experiment.json'

experiments_ids = extended_download(server_config_json=SERVER_CONFIG_YAML, experiment_tags=['BIDS'])
print(experiments_ids)

for experiment_id in experiments_ids:

experiment = download_experiment(save_to=json_file,
server_config_json=SERVER_CONFIG_YAML,
experiment_id=experiment_id,
format='json')
assert json_file.exists()
assert 'extra_fields' in experiment

# cleanup
json_file.unlink()

0 comments on commit 6e1db6b

Please sign in to comment.