Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jermiah committed Nov 20, 2023
1 parent e591acd commit 65ba441
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit Testsfrom nbiatoolkit import NBIAClient
name: Unit Tests

on: [push]

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,4 @@ old_src
resources/*
dicomsort.py
NBIA-toolkit.code-workspace
docs/data/*
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Required
https://github.com/jjjermiah/NBIA-toolkit/tree/main# Required
version: 2

# Image to use
Expand Down
249 changes: 184 additions & 65 deletions docs/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Example Usage: python3 examples.ipynb\n",
"# Example Usage: \n",
"### Description: \n",
"This is a simple example of how to use the `nbiatoolkit` package."
]
Expand All @@ -13,7 +13,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Setup \n",
"# Setup \n",
"\n",
"By default the client will use the Public API with the Guest Login credentials.\n",
"from the nbia which has access to all public data. \n",
Expand All @@ -25,9 +25,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"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"
]
}
],
"source": [
"from nbiatoolkit import NBIAClient\n",
"\n",
Expand All @@ -37,7 +45,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -49,7 +57,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Get Collection Methods"
"# Get Collection Methods"
]
},
{
Expand All @@ -62,9 +70,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"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"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total Number of Collections:98\n",
"First 5 body parts:\n",
"[{'BodyPartExamined': 'NOT SPECIFIED', 'Count': '8490'},\n",
" {'BodyPartExamined': 'ABDOMEN', 'Count': '2968'},\n",
" {'BodyPartExamined': 'ABDOMEN CAVIT', 'Count': '2'},\n",
" {'BodyPartExamined': 'ABDOMENPELVIC', 'Count': '2'},\n",
" {'BodyPartExamined': 'ABDOMENPELVIS', 'Count': '51'}]\n"
]
}
],
"source": [
"from pprint import pprint\n",
"bodypart_count = client.getBodyPartCounts()\n",
Expand All @@ -74,94 +103,184 @@
"pprint(bodypart_count[0:5])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Get Series Data\n",
"\n",
"``` python\n",
"getSeries(\n",
" Collection: str = \"\", \n",
" PatientID: str = \"\",\n",
" StudyInstanceUID: str = \"\",\n",
" Modality: str = \"\",\n",
" SeriesInstanceUID: str = \"\",\n",
" BodyPartExamined: str = \"\",\n",
" ManufacturerModelName: str = \"\",\n",
" Manufacturer: str = \"\") \n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"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"
]
}
],
"source": [
"# add /home/bioinf/bhklab/jermiah/projects/NBIA-toolkit/src to path\n",
"import sys, os\n",
"import requests\n",
"sys.path.append(os.path.abspath(\"/home/bioinf/bhklab/jermiah/projects/NBIA-toolkit/src\"))\n",
"seriesJSON = client.getSeries(Collection=\"4D-Lung\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"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"
]
}
],
"source": [
"from pprint import pprint\n",
"\n",
"from nbiatoolkit.utils import NBIA_ENDPOINTS\n",
"import pandas as pd\n",
"from pprint import pprint"
"pprint(seriesJSON[0:2])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# download Series Data\n",
"``` python\n",
"downloadSeries(\n",
" SeriesInstanceUID: str,\n",
" downloadDir: str)\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"['1.3.6.1.4.1.14519.5.2.1.6834.5010.189721824525842725510380467695',\n",
" '1.3.6.1.4.1.14519.5.2.1.6834.5010.336250251691987239290048605884',\n",
" '1.3.6.1.4.1.14519.5.2.1.6834.5010.227929163446067537882961857921',\n",
" '1.3.6.1.4.1.14519.5.2.1.6834.5010.925990093742075237571072608963',\n",
" '1.3.6.1.4.1.14519.5.2.1.6834.5010.139116724721865252687455544825']"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"response = client.getSeries(Collection=\"4D-Lung\")\n",
"pprint(response[0:5])\n",
"# df = pd.DataFrame(response)\n",
"# df.head()"
"# first get a list of the SeriesInstanceUIDs\n",
"seriesUIDS = [series['SeriesInstanceUID'] for series in seriesJSON]\n",
"seriesUIDS[0:5]"
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-11-20 16:08:28,847 | NBIAClient | INFO | Setting up OAuth2 client... with username nbia_guest\n",
"2023-11-20 16:08:29,136 | NBIAClient | INFO | Querying API endpoint: https://services.cancerimagingarchive.net/nbia-api/services/v2/getSeries\n",
"2023-11-20 16:08:29,136 | NBIAClient | DEBUG | API headers: 'Authorization:Bearer eyJhbGciOiJIUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJkZGFhMGY3YS1kZTBmLTRkYWQtYjM1ZS05MjljYjBiMTY3YjgifQ.eyJleHAiOjE3MDA1MDM3MDksImlhdCI6MTcwMDQ5NjUwOSwianRpIjoiNGIwNzQ2ZGYtN2VkNS00ZTllLTg5NGQtZDgzZWIxMTViOWNlIiwiaXNzIjoiaHR0cHM6Ly9rZXljbG9hay5kYm1pLmNsb3VkL2F1dGgvcmVhbG1zL1RDSUEiLCJhdWQiOiJhY2NvdW50Iiwic3ViIjoiZjowMTliNTYzNC1kYWJkLTQyMTEtYTQxZC03MjNjNDRhZmNmZmQ6bmJpYV9ndWVzdCIsInR5cCI6IkJlYXJlciIsImF6cCI6Im5iaWEiLCJzZXNzaW9uX3N0YXRlIjoiNWZjNjZlMzMtMjM0ZS00OTNiLWI1NGMtOWVkYjMzYjMwYmRmIiwiYWNyIjoiMSIsImFsbG93ZWQtb3JpZ2lucyI6WyJodHRwczovL3NlcnZpY2VzLmNhbmNlcmltYWdpbmdlYXJjaGl2ZS5uZXQiLCJodHRwczovL25iaWEuY2FuY2VyaW1hZ2luZ2VhcmNoaXZlLm5ldCIsImh0dHBzOi8vd3d3LmNhbmNlcmltYWdpbmdlYXJjaGl2ZS5uZXQiLCIqIiwiaHR0cDovL3RjaWEtbmJpYS0yLmFkLnVhbXMuZWR1OjQ1MjEwIiwiaHR0cHM6Ly9jYW5jZXJpbWFnaW5nZWFyY2hpdmUubmV0IiwiaHR0cDovL3RjaWEtbmJpYS0xLmFkLnVhbXMuZWR1OjQ1MjEwIiwiaHR0cHM6Ly9wdWJsaWMuY2FuY2VyaW1hZ2luZ2VhcmNoaXZlLm5ldCJdLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsib2ZmbGluZV9hY2Nlc3MiLCJkZWZhdWx0LXJvbGVzLXRjaWEiLCJ1bWFfYXV0aG9yaXphdGlvbiJdfSwicmVzb3VyY2VfYWNjZXNzIjp7ImFjY291bnQiOnsicm9sZXMiOlsibWFuYWdlLWFjY291bnQiLCJtYW5hZ2UtYWNjb3VudC1saW5rcyIsInZpZXctcHJvZmlsZSJdfX0sInNjb3BlIjoib3BlbmlkIHByb2ZpbGUgZW1haWwiLCJzaWQiOiI1ZmM2NmUzMy0yMzRlLTQ5M2ItYjU0Yy05ZWRiMzNiMzBiZGYiLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwibmFtZSI6Ik5CSUEgR3Vlc3QiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJuYmlhX2d1ZXN0IiwiZ2l2ZW5fbmFtZSI6Ik5CSUEiLCJmYW1pbHlfbmFtZSI6Ikd1ZXN0IiwiZW1haWwiOiJuYmlhX2d1ZXN0QGNhbmNlcmltYWdpbmdhcmNoaXZlLm5ldCJ9.7nI2jqCgAu646UGEp0uQWG5vxu_K_9dGGHHEcrgGMnE' -k 'https://services.cancerimagingarchive.net/nbia-api/services/v2/getSeries?Collection=4D-Lung&params={'Collection': '4D-Lung', 'params': {...}}'\n"
"2023-11-20 16:55:28,455 | NBIAClient | INFO | Querying API endpoint: https://services.cancerimagingarchive.net/nbia-api/services/v2/getImageWithMD5Hash\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Downloading to: /home/bioinf/bhklab/jermiah/projects/NBIA-toolkit/docs/data\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-11-20 16:55:33,722 | NBIAClient | INFO | Querying API endpoint: https://services.cancerimagingarchive.net/nbia-api/services/v2/getImageWithMD5Hash\n",
"2023-11-20 16:55:39,813 | NBIAClient | INFO | Querying API endpoint: https://services.cancerimagingarchive.net/nbia-api/services/v2/getImageWithMD5Hash\n",
"2023-11-20 16:55:44,858 | NBIAClient | INFO | Querying API endpoint: https://services.cancerimagingarchive.net/nbia-api/services/v2/getImageWithMD5Hash\n",
"2023-11-20 16:55:49,399 | NBIAClient | INFO | Querying API endpoint: https://services.cancerimagingarchive.net/nbia-api/services/v2/getImageWithMD5Hash\n"
]
},
{
"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",
"<class 'dict'>\n",
"\n",
"v2/getImageWithMD5Hash\n",
"<Response [200]>\n"
"['1.3.6.1.4.1.14519.5.2.1.6834.5010.227929163446067537882961857921', '1.3.6.1.4.1.14519.5.2.1.6834.5010.336250251691987239290048605884', '1.3.6.1.4.1.14519.5.2.1.6834.5010.189721824525842725510380467695', '1.3.6.1.4.1.14519.5.2.1.6834.5010.925990093742075237571072608963', '1.3.6.1.4.1.14519.5.2.1.6834.5010.139116724721865252687455544825']\n"
]
}
],
"source": [
"from nbiatoolkit import NBIAClient\n",
"import requests\n",
"from pprint import pprint\n",
"import io, zipfile\n",
"\n",
"client = NBIAClient(log_level=\"DEBUG\")\n",
"series = client.getSeries(Collection=\"4D-Lung\")\n",
"pprint(series[0])\n",
"print(type(series[0]))\n",
"print()\n",
"response = client.downloadSeries(series[0][\"SeriesInstanceUID\"])\n",
"pprint(response)\n",
"\n",
"file = zipfile.ZipFile(io.BytesIO(response.content))\n",
"file.extractall(path = \".\")"
"# call client.downloadSeries() on each SeriesInstanceUID\n",
"import os\n",
"downloadDir = \"./data\"\n",
"os.makedirs(downloadDir, exist_ok=True)\n",
"print(\"Downloading to: \" + os.path.abspath(downloadDir))\n",
"for seriesUID in seriesUIDS[0:5]:\n",
" client.downloadSeries(seriesUID, downloadDir)\n",
" \n",
"pprint(os.listdir(downloadDir))\n",
" "
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
```

```{toctree}
:maxdepth: 1
:maxdepth: 2
:hidden:
example.ipynb
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pytest==7.2.2
pytest-cov==4.0.0
ruff==v0.0.260
coverage-badge~=1.1.0
requests==2.31.0
requests==2.31.0

0 comments on commit 65ba441

Please sign in to comment.