Skip to content

Commit

Permalink
Added conditional logger settings for Colab
Browse files Browse the repository at this point in the history
  • Loading branch information
kirbyju committed Dec 13, 2023
1 parent c8fa4c5 commit e6d9ad6
Showing 1 changed file with 19 additions and 39 deletions.
58 changes: 19 additions & 39 deletions TCIA_Segmentations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
"source": [
"# 2 Setup\n",
"\n",
"The following installs and imports **[tcia_utils](https://pypi.org/project/tcia-utils/)**, which contains a variety of useful functions for accessing TCIA via Python and Juptyter Notebooks. It also ensures you have pandas installed and that the necessary imports are performed."
"The following installs and imports **[tcia_utils](https://pypi.org/project/tcia-utils/)**, which contains a variety of useful functions for accessing TCIA via Python and Juptyter Notebooks. It also ensures you have pandas installed and that the necessary imports are performed.\n",
"\n",
"**Note:** You can ignore dependency errors related to the **lida** package if they appear."
],
"metadata": {
"id": "bqulqBEDMSS6"
Expand All @@ -55,8 +57,7 @@
{
"cell_type": "code",
"source": [
"!pip install --upgrade -q tcia_utils\n",
"!pip install -q pandas"
"!pip install --upgrade -q tcia_utils"
],
"metadata": {
"id": "zP4VRfgg-QXU"
Expand All @@ -70,51 +71,30 @@
"source": [
"import requests\n",
"import pandas as pd\n",
"from tcia_utils import nbia"
],
"metadata": {
"id": "p3zEqnxi9rk2"
},
"execution_count": null,
"outputs": [],
"id": "p3zEqnxi9rk2"
},
{
"cell_type": "markdown",
"source": [
"### Set logging level to INFO (optional)\n",
"This step isn't necessary on local Jupyter Labs, but Google Colab's logging root handler only shows warnings and errors by default. If you'd like to see INFO statements you can run the following code. "
],
"metadata": {
"id": "4EB4OlFNE1EK"
},
"id": "4EB4OlFNE1EK"
},
{
"cell_type": "code",
"source": [
"import logging\n",
"import sys\n",
"from tcia_utils import nbia\n",
"\n",
"# Check current handlers\n",
"#print(logging.root.handlers)\n",
"# set logging level to INFO in Google Colab (not necessary in Jupyter)\n",
"if 'google.colab' in sys.modules:\n",
" import logging\n",
"\n",
"# Remove all handlers associated with the root logger object.\n",
"for handler in logging.root.handlers[:]:\n",
" logging.root.removeHandler(handler)\n",
"#print(logging.root.handlers)\n",
" # Remove all handlers associated with the root logger object.\n",
" for handler in logging.root.handlers[:]:\n",
" logging.root.removeHandler(handler)\n",
" #print(logging.root.handlers)\n",
"\n",
"# Set handler with level = info\n",
"logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s',\n",
" level=logging.INFO)\n",
" # Set handler with level = info\n",
" logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s',\n",
" level=logging.INFO)\n",
"\n",
"print(\"Logging set to INFO\")"
" print(\"Google Colab Logging set to INFO\")"
],
"metadata": {
"id": "y4bh_j40-fia"
"id": "p3zEqnxi9rk2"
},
"execution_count": null,
"outputs": [],
"id": "y4bh_j40-fia"
"id": "p3zEqnxi9rk2"
},
{
"cell_type": "markdown",
Expand Down

0 comments on commit e6d9ad6

Please sign in to comment.