Skip to content

Commit

Permalink
Merge pull request #12 from jjjermiah/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
jjjermiah committed Nov 25, 2023
2 parents 0d638cb + b199a83 commit 931eb4a
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
os: [ubuntu-latest, macos-latest]
python-version: ["3.12"]

steps:
Expand Down
216 changes: 152 additions & 64 deletions docs/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,12 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-11-20 16:49:13,681 | NBIAClient | INFO | Setting up OAuth2 client... with username nbia_guest\n"
]
}
],
"outputs": [],
"source": [
"from nbiatoolkit import NBIAClient\n",
"from pprint import pprint\n",
"\n",
"# Instantiate the client. \n",
"client = NBIAClient()"
Expand All @@ -64,22 +57,75 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Counts of Patients grouped by Body Parts\n",
"`getBodyPartCounts(collection: str = \"\", modality: str = \"\")`"
"#### get list of collection (names)\n",
"`getCollections()`"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stderr",
"name": "stdout",
"output_type": "stream",
"text": [
"2023-11-20 16:49:13,981 | NBIAClient | INFO | Querying API endpoint: https://services.cancerimagingarchive.net/nbia-api/services/getBodyPartValuesAndCounts\n"
"['4D-Lung',\n",
" 'A091105',\n",
" 'ACNS0332',\n",
" 'ACRIN-6698',\n",
" 'ACRIN-Contralateral-Breast-MR']\n"
]
},
}
],
"source": [
"collections = client.getCollections()\n",
"pprint(collections[0:5])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### get Counts of Patients for each collection\n",
"`getCollectionPatientCount()`"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[{'Collection': '4D-Lung', 'PatientCount': '20'},\n",
" {'Collection': 'A091105', 'PatientCount': '83'},\n",
" {'Collection': 'ACNS0332', 'PatientCount': '85'},\n",
" {'Collection': 'ACRIN-6698', 'PatientCount': '385'},\n",
" {'Collection': 'ACRIN-Contralateral-Breast-MR', 'PatientCount': '984'}]\n"
]
}
],
"source": [
"collectionsPatientCount = client.getCollectionPatientCount()\n",
"pprint(collectionsPatientCount[0:5])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### get Counts of Patients grouped by Body Parts\n",
"`getBodyPartCounts(collection: str = \"\", modality: str = \"\")`"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
Expand All @@ -95,7 +141,6 @@
}
],
"source": [
"from pprint import pprint\n",
"bodypart_count = client.getBodyPartCounts()\n",
"print(\"Total Number of Collections:\" + str(len(bodypart_count)))\n",
"\n",
Expand All @@ -107,7 +152,47 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Get Series Data\n",
"# Get Patient Methods"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### get Patient IDs by Collection and Modality\n",
"`getPatientData(collection: str = \"\", modality: str = \"\")`"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['100_HM10395', '101_HM10395', '102_HM10395', '103_HM10395', '104_HM10395']\n"
]
}
],
"source": [
"patients = client.getPatients(collection=\"4D-Lung\", modality=\"CT\")\n",
"pprint(patients[0:5])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Get Series Data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### get Series Data queried by parameters\n",
"\n",
"``` python\n",
"getSeries(\n",
Expand All @@ -124,75 +209,78 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stderr",
"name": "stdout",
"output_type": "stream",
"text": [
"2023-11-20 16:51:10,330 | NBIAClient | INFO | Querying API endpoint: https://services.cancerimagingarchive.net/nbia-api/services/v2/getSeries\n"
"There are 6690 series in the 4D-Lung collection.\n",
"{'BodyPartExamined': 'LUNG',\n",
" 'Collection': '4D-Lung',\n",
" 'CollectionURI': 'https://doi.org/10.7937/K9/TCIA.2016.ELN8YGLE',\n",
" 'FileSize': 26405988,\n",
" 'ImageCount': 50,\n",
" 'LicenseName': 'Creative Commons Attribution 3.0 Unported License',\n",
" 'LicenseURI': 'http://creativecommons.org/licenses/by/3.0/',\n",
" 'Manufacturer': 'Varian Imaging Laboratories, Switzerland',\n",
" 'ManufacturerModelName': 'Trilogy Cone Beam CT',\n",
" 'Modality': 'CT',\n",
" 'PatientID': '100_HM10395',\n",
" 'ProtocolName': '5.1 4DCT & ITV FB + 4D + INSP/EXP',\n",
" 'SeriesDate': '1997-10-03 00:00:00.0',\n",
" 'SeriesDescription': 'P4^P100^S113^I0, Gated, 70.0%',\n",
" 'SeriesInstanceUID': '1.3.6.1.4.1.14519.5.2.1.6834.5010.189721824525842725510380467695',\n",
" 'SeriesNumber': 507,\n",
" 'SoftwareVersions': 'LightSpeedverrel',\n",
" 'StudyInstanceUID': '1.3.6.1.4.1.14519.5.2.1.6834.5010.552215730027211807644647167706',\n",
" 'TimeStamp': '2015-07-20 17:58:54.0'}\n"
]
}
],
"source": [
"seriesJSON = client.getSeries(Collection=\"4D-Lung\")"
"seriesJSON = client.getSeries(Collection=\"4D-Lung\")\n",
"print(f\"There are {len(seriesJSON)} series in the 4D-Lung collection.\")\n",
"pprint(seriesJSON[0])"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[{'BodyPartExamined': 'LUNG',\n",
" 'Collection': '4D-Lung',\n",
" 'CollectionURI': 'https://doi.org/10.7937/K9/TCIA.2016.ELN8YGLE',\n",
" 'FileSize': 26405988,\n",
" 'ImageCount': 50,\n",
" 'LicenseName': 'Creative Commons Attribution 3.0 Unported License',\n",
" 'LicenseURI': 'http://creativecommons.org/licenses/by/3.0/',\n",
" 'Manufacturer': 'Varian Imaging Laboratories, Switzerland',\n",
" 'ManufacturerModelName': 'Trilogy Cone Beam CT',\n",
" 'Modality': 'CT',\n",
" 'PatientID': '100_HM10395',\n",
" 'ProtocolName': '5.1 4DCT & ITV FB + 4D + INSP/EXP',\n",
" 'SeriesDate': '1997-10-03 00:00:00.0',\n",
" 'SeriesDescription': 'P4^P100^S113^I0, Gated, 70.0%',\n",
" 'SeriesInstanceUID': '1.3.6.1.4.1.14519.5.2.1.6834.5010.189721824525842725510380467695',\n",
" 'SeriesNumber': 507,\n",
" 'SoftwareVersions': 'LightSpeedverrel',\n",
" 'StudyInstanceUID': '1.3.6.1.4.1.14519.5.2.1.6834.5010.552215730027211807644647167706',\n",
" 'TimeStamp': '2015-07-20 17:58:54.0'},\n",
" {'BodyPartExamined': 'LUNG',\n",
" 'Collection': '4D-Lung',\n",
" 'CollectionURI': 'https://doi.org/10.7937/K9/TCIA.2016.ELN8YGLE',\n",
" 'FileSize': 26405988,\n",
" 'ImageCount': 50,\n",
" 'LicenseName': 'Creative Commons Attribution 3.0 Unported License',\n",
" 'LicenseURI': 'http://creativecommons.org/licenses/by/3.0/',\n",
" 'Manufacturer': 'Varian Imaging Laboratories, Switzerland',\n",
" 'ManufacturerModelName': 'Trilogy Cone Beam CT',\n",
" 'Modality': 'CT',\n",
" 'PatientID': '100_HM10395',\n",
" 'ProtocolName': '5.1 4DCT & ITV FB + 4D + INSP/EXP',\n",
" 'SeriesDate': '1997-10-07 00:00:00.0',\n",
" 'SeriesDescription': 'P4^P100^S116^I0, Gated, 70.0%',\n",
" 'SeriesInstanceUID': '1.3.6.1.4.1.14519.5.2.1.6834.5010.336250251691987239290048605884',\n",
" 'SeriesNumber': 507,\n",
" 'SoftwareVersions': 'LightSpeedverrel',\n",
" 'StudyInstanceUID': '1.3.6.1.4.1.14519.5.2.1.6834.5010.980344486630714096442107526343',\n",
" 'TimeStamp': '2015-07-20 17:40:07.0'}]\n"
"There are 350 series for patient 100_HM10395.\n",
"{'BodyPartExamined': 'LUNG',\n",
" 'Collection': '4D-Lung',\n",
" 'CollectionURI': 'https://doi.org/10.7937/K9/TCIA.2016.ELN8YGLE',\n",
" 'FileSize': 26405988,\n",
" 'ImageCount': 50,\n",
" 'LicenseName': 'Creative Commons Attribution 3.0 Unported License',\n",
" 'LicenseURI': 'http://creativecommons.org/licenses/by/3.0/',\n",
" 'Manufacturer': 'Varian Imaging Laboratories, Switzerland',\n",
" 'ManufacturerModelName': 'Trilogy Cone Beam CT',\n",
" 'Modality': 'CT',\n",
" 'PatientID': '100_HM10395',\n",
" 'ProtocolName': '5.1 4DCT & ITV FB + 4D + INSP/EXP',\n",
" 'SeriesDate': '1997-10-03 00:00:00.0',\n",
" 'SeriesDescription': 'P4^P100^S113^I0, Gated, 70.0%',\n",
" 'SeriesInstanceUID': '1.3.6.1.4.1.14519.5.2.1.6834.5010.189721824525842725510380467695',\n",
" 'SeriesNumber': 507,\n",
" 'SoftwareVersions': 'LightSpeedverrel',\n",
" 'StudyInstanceUID': '1.3.6.1.4.1.14519.5.2.1.6834.5010.552215730027211807644647167706',\n",
" 'TimeStamp': '2015-07-20 17:58:54.0'}\n"
]
}
],
"source": [
"from pprint import pprint\n",
"\n",
"pprint(seriesJSON[0:2])"
"seriesbyPatientJSON = client.getSeries(PatientID=patients[0])\n",
"print(f\"There are {len(seriesbyPatientJSON)} series for patient {patients[0]}.\")\n",
"pprint(seriesbyPatientJSON[0])"
]
},
{
Expand Down
8 changes: 7 additions & 1 deletion driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@
PASSWORD = "q6mJyLD8cPeGTwg!"


client = NBIAClient(username=USERNAME, password=PASSWORD)
client = NBIAClient(
username=USERNAME,
password=PASSWORD,
log_level="DEBUG")

series = client.getSeries(Collection="RADCURE")

seriesList = [_["SeriesInstanceUID"] for _ in series]
seriesList = seriesList[0:5]




def download(series) -> bool:
response = client.downloadSeries(
SeriesInstanceUID = series,
Expand Down
7 changes: 5 additions & 2 deletions src/nbiatoolkit/nbia.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ def __init__(self,

# Setup logger
self.logger = setup_logger(
name = "NBIAClient", console_logging=True, log_level=log_level)
name = "NBIAClient",
console_logging=True,
log_level=log_level,
log_file = None)

# Setup OAuth2 client
self.logger.debug("Setting up OAuth2 client... with username %s", username)
Expand All @@ -33,7 +36,7 @@ def query_api(self, endpoint: NBIA_ENDPOINTS, params: dict = {}) -> dict:
query_url = base_url + endpoint.value

self.logger.debug("Querying API endpoint: %s", query_url)
self.logger.debug("API headers: %s", (self._createDebugURL(endpoint, params)))
# self.logger.debug("API headers: %s", (self._createDebugURL(endpoint, params)))

try:
response = requests.get(
Expand Down
4 changes: 3 additions & 1 deletion src/nbiatoolkit/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from .logger import setup_logger
from .nbia_endpoints import NBIA_ENDPOINTS
from .md5 import validateMD5
__all__ = [
"setup_logger",
"NBIA_ENDPOINTS"
"NBIA_ENDPOINTS",
"validateMD5"
]
8 changes: 3 additions & 5 deletions src/nbiatoolkit/utils/nbia_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ class NBIA_ENDPOINTS(Enum):

DOWNLOAD_SERIES = 'v2/getImageWithMD5Hash'

# TIMES OUT???
GET_SERIES_SIZE = 'v2/getSeriesSize'
GET_UPDATED_SERIES = 'v2/getUpdatedSeries'

# curl -H 'Authorization:Bearer eyJhbGciOiJIUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJkZGFhMGY3YS1kZTBmLTRkYWQtYjM1ZS05MjljYjBiM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ZSJdfX0sInNjb3BlIjoib3BlbmlkIHByb2ZpbGUgZW1haWwiLCJzaWQiOiIyODNkNzQyNi1kYTViLTQ1MTEtYjYzMS03ZjIzNjliMDYyZTQiLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwibmFtZSI6Ik5CSUEgR3Vlc3QiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJuYmlhX2d1ZXN0IiwiZ2l2ZW5fbmFtZSI6Ik5CSUEiLCJmYW1pbHlfbmFtZSI6Ikd1ZXN0IiwiZW1haWwiOiJuYmlhX2d1ZXN0QGNhbmNlcmltYWdpbmdhcmNoaXZlLm5ldCJ9.YIrmcZcDT9w22diON2bFxDVcY1-BU59FwcklsnYHBT0' -k "https://services.cancerimagingarchive.net/nbia-api/services/v2/getSeriesMetaData?SeriesInstanceUID=1.3.6.1.4.1.9590.100.1.2.374115997511889073021386151921807063992"

GET_SERIES_SIZE = 'v2/getSeriesSize' # TIMES OUT???
GET_UPDATED_SERIES = 'v2/getUpdatedSeries'

# https://services.cancerimagingarchive.net/nbia-api/services/v2/getSeriesMetaData?SeriesInstanceUID=1.3.6.1.4.1.9590.100.1.2.374115997511889073021386151921807063992

# https://services.cancerimagingarchive.net/nbia-api/services/v2/getSeriesSize?SeriesInstanceUID=1.3.6.1.4.1.9590.100.1.2.374115997511889073021386151921807063992
Expand Down

0 comments on commit 931eb4a

Please sign in to comment.