-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DANDI upload to YAML spec (#1089)
Co-authored-by: Heberto Mayorquin <[email protected]>
- Loading branch information
1 parent
4ba1e82
commit 4b3172c
Showing
9 changed files
with
182 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...on_data/test_yaml/conversion_specifications/GIN_conversion_specification_dandi_upload.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
metadata: | ||
NWBFile: | ||
lab: My Lab | ||
institution: My Institution | ||
|
||
conversion_options: | ||
stub_test: True | ||
|
||
data_interfaces: | ||
ap: SpikeGLXRecordingInterface | ||
lf: SpikeGLXRecordingInterface | ||
phy: PhySortingInterface | ||
|
||
upload_to_dandiset: "200560" | ||
|
||
experiments: | ||
ymaze: | ||
metadata: | ||
NWBFile: | ||
session_description: Subject navigating a Y-shaped maze. | ||
|
||
sessions: | ||
- nwbfile_name: example_converter_spec_1 | ||
source_data: | ||
ap: | ||
file_path: spikeglx/Noise4Sam_g0/Noise4Sam_g0_imec0/Noise4Sam_g0_t0.imec0.ap.bin | ||
metadata: | ||
NWBFile: | ||
session_start_time: "2020-10-09T21:19:09+00:00" | ||
session_id: "test-yaml-1" | ||
Subject: | ||
subject_id: "yaml-1" | ||
sex: F | ||
age: P35D | ||
species: Mus musculus | ||
- nwbfile_name: example_converter_spec_2.nwb | ||
metadata: | ||
NWBFile: | ||
session_start_time: "2020-10-10T21:19:09+00:00" | ||
session_id: "test-yaml-2" | ||
Subject: | ||
subject_id: "yaml-002" | ||
sex: F | ||
age: P35D | ||
species: Mus musculus | ||
source_data: | ||
lf: | ||
file_path: spikeglx/Noise4Sam_g0/Noise4Sam_g0_imec0/Noise4Sam_g0_t0.imec0.lf.bin | ||
|
||
open_explore: | ||
sessions: | ||
- nwbfile_name: example_converter_spec_3 | ||
source_data: | ||
lf: | ||
file_path: spikeglx/Noise4Sam_g0/Noise4Sam_g0_imec0/Noise4Sam_g0_t0.imec0.lf.bin | ||
phy: | ||
folder_path: phy/phy_example_0/ | ||
metadata: | ||
NWBFile: | ||
session_start_time: "2020-10-11T21:19:09+00:00" | ||
session_id: test YAML 3 | ||
Subject: | ||
subject_id: YAML Subject Name | ||
sex: F | ||
age: P35D | ||
species: Mus musculus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import os | ||
import platform | ||
import time | ||
from datetime import datetime, timedelta | ||
from pathlib import Path | ||
|
||
import dandi.dandiapi | ||
import pytest | ||
from packaging.version import Version | ||
|
||
from neuroconv import run_conversion_from_yaml | ||
|
||
from ..setup_paths import ECEPHY_DATA_PATH, OUTPUT_PATH | ||
|
||
DANDI_API_KEY = os.getenv("DANDI_API_KEY") | ||
HAVE_DANDI_KEY = DANDI_API_KEY is not None and DANDI_API_KEY != "" # can be "" from external forks | ||
_PYTHON_VERSION = platform.python_version() | ||
|
||
|
||
@pytest.mark.skipif( | ||
not HAVE_DANDI_KEY or Version(".".join(_PYTHON_VERSION.split(".")[:2])) != Version("3.12"), | ||
reason="You must set your DANDI_API_KEY to run this test!", | ||
) | ||
def test_run_conversion_from_yaml_with_dandi_upload(): | ||
path_to_test_yml_files = Path(__file__).parent / "conversion_specifications" | ||
yaml_file_path = path_to_test_yml_files / "GIN_conversion_specification_dandi_upload.yml" | ||
run_conversion_from_yaml( | ||
specification_file_path=yaml_file_path, | ||
data_folder_path=ECEPHY_DATA_PATH, | ||
output_folder_path=OUTPUT_PATH, | ||
overwrite=True, | ||
) | ||
|
||
time.sleep(60) # Give some buffer room for server to process before making assertions against DANDI API | ||
|
||
client = dandi.dandiapi.DandiAPIClient(api_url="https://api-staging.dandiarchive.org/api") | ||
dandiset = client.get_dandiset("200560") | ||
|
||
expected_asset_paths = [ | ||
"sub-yaml-1/sub-yaml-1_ses-test-yaml-1_ecephys.nwb", | ||
"sub-yaml-002/sub-yaml-002_ses-test-yaml-2_ecephys.nwb", | ||
"sub-YAML-Subject-Name/sub-YAML-Subject-Name_ses-test-YAML-3_ecephys.nwb", | ||
] | ||
for asset_path in expected_asset_paths: | ||
test_asset = dandiset.get_asset_by_path(path=asset_path) # Will error if not found | ||
test_asset_metadata = test_asset.get_raw_metadata() | ||
|
||
# Past uploads may have created the same apparent file, so look at the modification time to ensure | ||
# this test is actually testing the most recent upload | ||
date_modified = datetime.fromisoformat( | ||
test_asset_metadata["dateModified"].split("Z")[0] # Timezones look a little messy | ||
) | ||
assert datetime.now() - date_modified < timedelta(minutes=10) |