Skip to content

Commit

Permalink
added more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Jermiah committed Nov 25, 2023
1 parent eb038d4 commit 3a2fca2
Showing 1 changed file with 152 additions and 64 deletions.
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

0 comments on commit 3a2fca2

Please sign in to comment.