Skip to content

Commit 18f444b

Browse files
authored
Merge pull request #111 from fedorov/add-clinical-index
ENH: add clinical_index
2 parents dfafae1 + 986e004 commit 18f444b

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

idc_index/index.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class IDCClient:
4141
CITATION_FORMAT_BIBTEX = "application/x-bibtex"
4242

4343
# Singleton pattern
44-
# NOTE: In the future, one may want to use multiple clients e.g. for sub-datasets so a attribute-singleton as shown bewlo seems a better option.
44+
# NOTE: In the future, one may want to use multiple clients e.g. for sub-datasets so a attribute-singleton as shown below seems a better option.
4545
# _instance: IDCClient
4646
# def __new__(cls):
4747
# if not hasattr(cls, "_instance") or getattr(cls, "_instance") is None:
@@ -74,6 +74,8 @@ def __init__(self):
7474
{"Modality": pd.Series.unique, "series_size_MB": "sum"}
7575
)
7676

77+
idc_version = f"v{Version(idc_index_data.__version__).major}"
78+
7779
self.indices_overview = {
7880
"index": {
7981
"description": "Main index containing one row per DICOM series.",
@@ -95,6 +97,11 @@ def __init__(self):
9597
"installed": False,
9698
"url": f"{asset_endpoint_url}/sm_instance_index.parquet",
9799
},
100+
"clinical_index": {
101+
"description": "Index of clinical data accompanying the available images.",
102+
"installed": False,
103+
"url": f"https://idc-open-metadata.s3.amazonaws.com/bigquery_export/idc_{idc_version}_clinical/column_metadata/000000000000.parquet",
104+
},
98105
}
99106

100107
# Lookup s5cmd

tests/idcindex.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import pandas as pd
1111
import pytest
12+
import requests
1213
from click.testing import CliRunner
1314
from idc_index import IDCClient, cli
1415

@@ -18,6 +19,17 @@
1819
logging.basicConfig(level=logging.DEBUG)
1920

2021

22+
def remote_file_exists(url):
23+
try:
24+
response = requests.head(url, allow_redirects=True)
25+
# Check if the status code indicates success
26+
return response.status_code == 200
27+
except requests.RequestException as e:
28+
# Handle any exceptions (e.g., network issues)
29+
print(f"An error occurred: {e}")
30+
return False
31+
32+
2133
@pytest.fixture(autouse=True)
2234
def _change_test_dir(request, monkeypatch):
2335
monkeypatch.chdir(request.fspath.dirname)
@@ -494,6 +506,12 @@ def test_fetch_index(self):
494506
assert i.indices_overview["sm_index"]["installed"] is True
495507
assert hasattr(i, "sm_index")
496508

509+
def test_indices_urls(self):
510+
i = IDCClient()
511+
for index in i.indices_overview:
512+
if i.indices_overview[index]["url"] is not None:
513+
assert remote_file_exists(i.indices_overview[index]["url"])
514+
497515

498516
if __name__ == "__main__":
499517
unittest.main()

0 commit comments

Comments
 (0)