-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
list_indices and fetch_index implemented #101
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9e1817c
ENH added functionality and tests to list available indices and fetch…
fedorov 3e5b526
ENH: Replaced dynamic Github release asset access with manually maint…
fedorov 85f4091
BUG: fixing CI issues
DanielaSchacherer 0c36cb1
DOC: add brief descriptions for indices
fedorov 98375be
ENH: now setting class variable within fetch_index function and inclu…
DanielaSchacherer aa021d5
STYLE: remove DF conversion function for the index overview
fedorov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
|
||
aws_endpoint_url = "https://s3.amazonaws.com" | ||
gcp_endpoint_url = "https://storage.googleapis.com" | ||
asset_endpoint_url = f"https://github.com/ImagingDataCommons/idc-index-data/releases/download/{idc_index_data.__version__}" | ||
|
||
logging.basicConfig(format="%(asctime)s - %(message)s", level=logging.INFO) | ||
logger = logging.getLogger(__name__) | ||
|
@@ -58,9 +59,8 @@ def client(cls) -> IDCClient: | |
return cls._client | ||
|
||
def __init__(self): | ||
# Read main index file | ||
file_path = idc_index_data.IDC_INDEX_PARQUET_FILEPATH | ||
|
||
# Read index file | ||
logger.debug(f"Reading index file v{idc_index_data.__version__}") | ||
self.index = pd.read_parquet(file_path) | ||
# self.index = self.index.astype(str).replace("nan", "") | ||
|
@@ -69,9 +69,26 @@ def __init__(self): | |
{"Modality": pd.Series.unique, "series_size_MB": "sum"} | ||
) | ||
|
||
self.indices_overview = { | ||
"index": { | ||
"description": "Main index containing one row per DICOM series.", | ||
"installed": True, | ||
"url": None, | ||
}, | ||
"sm_index": { | ||
"description": "DICOM Slide Microscopy series-level index.", | ||
"installed": False, | ||
"url": f"{asset_endpoint_url}/sm_index.parquet", | ||
}, | ||
"sm_instance_index": { | ||
"description": "DICOM Slide Microscopy instance-level index.", | ||
"installed": False, | ||
"url": f"{asset_endpoint_url}/sm_instance_index.parquet", | ||
}, | ||
} | ||
|
||
# Lookup s5cmd | ||
self.s5cmdPath = shutil.which("s5cmd") | ||
|
||
if self.s5cmdPath is None: | ||
# Workaround to support environment without a properly setup PATH | ||
# See https://github.com/Slicer/Slicer/pull/7587 | ||
|
@@ -80,16 +97,12 @@ def __init__(self): | |
if str(script).startswith("s5cmd/bin/s5cmd"): | ||
self.s5cmdPath = script.locate().resolve(strict=True) | ||
break | ||
|
||
if self.s5cmdPath is None: | ||
raise FileNotFoundError( | ||
"s5cmd executable not found. Please install s5cmd from https://github.com/peak/s5cmd#installation" | ||
) | ||
|
||
self.s5cmdPath = str(self.s5cmdPath) | ||
|
||
logger.debug(f"Found s5cmd executable: {self.s5cmdPath}") | ||
|
||
# ... and check it can be executed | ||
subprocess.check_call([self.s5cmdPath, "--help"], stdout=subprocess.DEVNULL) | ||
|
||
|
@@ -177,6 +190,36 @@ def get_idc_version(): | |
idc_version = Version(idc_index_data.__version__).major | ||
return f"v{idc_version}" | ||
|
||
def fetch_index(self, index) -> None: | ||
""" | ||
Downloads requested index. | ||
|
||
Args: | ||
index (str): Name of the index to be downloaded. | ||
""" | ||
|
||
if index not in self.indices_overview: | ||
logger.error(f"Index {index} is not available and can not be fetched.") | ||
elif self.indices_overview[index]["installed"]: | ||
logger.warning( | ||
f"Index {index} already installed and will not be fetched again." | ||
) | ||
else: | ||
response = requests.get(self.indices_overview[index]["url"], timeout=30) | ||
if response.status_code == 200: | ||
filepath = os.path.join( | ||
idc_index_data.IDC_INDEX_PARQUET_FILEPATH.parents[0], | ||
f"{index}.parquet", | ||
) | ||
with open(filepath, mode="wb") as file: | ||
file.write(response.content) | ||
setattr(self.__class__, index, pd.read_parquet(filepath)) | ||
self.indices_overview[index]["installed"] = True | ||
Comment on lines
+209
to
+217
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See related topic here: #107 |
||
else: | ||
logger.error( | ||
f"Failed to fetch index from URL {self.indices_overview[index]['url']}: {response.status_code}" | ||
) | ||
|
||
def get_collections(self): | ||
""" | ||
Returns the collections present in IDC | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this function I would not just fetch the file, but also load it into the class variable named as the index name - consistent with the main index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.