From d3a89fc4779bdb340183119e660442ee9084b87c Mon Sep 17 00:00:00 2001 From: Pat Gunn Date: Wed, 24 Jul 2024 18:02:19 -0400 Subject: [PATCH] Initial go at updating notebooks to use the logger we're calling caiman --- demos/notebooks/demo_OnACID_mesoscope.ipynb | 14 ++++++++++---- demos/notebooks/demo_Ring_CNN.ipynb | 14 ++++++++++---- demos/notebooks/demo_VST.ipynb | 14 ++++++++++---- demos/notebooks/demo_caiman_cnmf_3D.ipynb | 13 +++++++++---- demos/notebooks/demo_dendritic.ipynb | 12 ++++++++---- demos/notebooks/demo_motion_correction.ipynb | 13 +++++++++---- demos/notebooks/demo_online_3D.ipynb | 13 +++++++++---- demos/notebooks/demo_online_cnmfE.ipynb | 13 +++++++++---- demos/notebooks/demo_pipeline.ipynb | 12 +++++++++--- demos/notebooks/demo_pipeline_cnmfE.ipynb | 12 +++++++++--- .../notebooks/demo_pipeline_voltage_imaging.ipynb | 13 +++++++++---- demos/notebooks/demo_realtime_cnmfE.ipynb | 13 +++++++++---- demos/notebooks/demo_seeded_CNMF.ipynb | 13 +++++++++---- 13 files changed, 119 insertions(+), 50 deletions(-) diff --git a/demos/notebooks/demo_OnACID_mesoscope.ipynb b/demos/notebooks/demo_OnACID_mesoscope.ipynb index 14a8020b4..b6d2407ab 100644 --- a/demos/notebooks/demo_OnACID_mesoscope.ipynb +++ b/demos/notebooks/demo_OnACID_mesoscope.ipynb @@ -34,10 +34,16 @@ "from caiman.source_extraction import cnmf\n", "from caiman.utils.utils import download_demo\n", "\n", - "logging.basicConfig(format=\n", - " \"%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s] [%(process)d] %(message)s\",\n", - " # filename=\"/tmp/caiman.log\",\n", - " level=logging.INFO)\n", + "logfile = None # Replace with a path if you want to log to a file\n", + "logger = logging.getLogger('caiman')\n", + "logger.setLevel(logging.INFO)\n", + "logfmt = '%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s] [%(process)d] %(message)s'\n", + "if logfile is not None:\n", + " handler = logging.FileHandler(logfile)\n", + "else:\n", + " handler = logging.StreamHandler()\n", + "handler.setFormatter(logfmt)\n", + "logger.addHandler(handler)\n", "\n", "try:\n", " if __IPYTHON__:\n", diff --git a/demos/notebooks/demo_Ring_CNN.ipynb b/demos/notebooks/demo_Ring_CNN.ipynb index 06149b57a..277d94fb0 100644 --- a/demos/notebooks/demo_Ring_CNN.ipynb +++ b/demos/notebooks/demo_Ring_CNN.ipynb @@ -23,10 +23,16 @@ "import numpy as np\n", "import os\n", "\n", - "logging.basicConfig(format=\n", - " \"%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s] [%(process)d] %(message)s\",\n", - " # filename=\"/tmp/caiman.log\",\n", - " level=logging.WARNING)\n", + "logfile = None # Replace with a path if you want to log to a file\n", + "logger = logging.getLogger('caiman')\n", + "logger.setLevel(logging.INFO)\n", + "logfmt = '%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s] [%(process)d] %(message)s'\n", + "if logfile is not None:\n", + " handler = logging.FileHandler(logfile)\n", + "else:\n", + " handler = logging.StreamHandler()\n", + "handler.setFormatter(logfmt)\n", + "logger.addHandler(handler)\n", "\n", "import caiman as cm\n", "import caiman.base.movies\n", diff --git a/demos/notebooks/demo_VST.ipynb b/demos/notebooks/demo_VST.ipynb index cc7c86e37..295789785 100644 --- a/demos/notebooks/demo_VST.ipynb +++ b/demos/notebooks/demo_VST.ipynb @@ -24,10 +24,16 @@ "import os\n", "import timeit\n", "\n", - "logging.basicConfig(format=\n", - " \"%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s] [%(process)d] %(message)s\",\n", - " # filename=\"/tmp/caiman.log\",\n", - " level=logging.DEBUG)\n", + "logfile = None # Replace with a path if you want to log to a file\n", + "logger = logging.getLogger('caiman')\n", + "logger.setLevel(logging.INFO)\n", + "logfmt = '%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s] [%(process)d] %(message)s'\n", + "if logfile is not None:\n", + " handler = logging.FileHandler(logfile)\n", + "else:\n", + " handler = logging.StreamHandler()\n", + "handler.setFormatter(logfmt)\n", + "logger.addHandler(handler)\n", "\n", "import caiman.external.houghvst.estimation as est\n", "from caiman.external.houghvst.gat import compute_gat, compute_inverse_gat\n", diff --git a/demos/notebooks/demo_caiman_cnmf_3D.ipynb b/demos/notebooks/demo_caiman_cnmf_3D.ipynb index 2a0c3be84..7529a4dc3 100644 --- a/demos/notebooks/demo_caiman_cnmf_3D.ipynb +++ b/demos/notebooks/demo_caiman_cnmf_3D.ipynb @@ -39,10 +39,15 @@ "import bokeh.plotting as bpl\n", "bpl.output_notebook()\n", "\n", - "logging.basicConfig(format=\n", - " \"%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s] [%(process)d] %(message)s\",\n", - " # filename=\"/tmp/caiman.log\",\n", - " level=logging.WARNING)" + "logfile = None # Replace with a path if you want to log to a file\n", + "logger = logging.getLogger('caiman')\n", + "logger.setLevel(logging.INFO)\n", + "logfmt = '%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s] [%(process)d] %(message)s'\n", + "if logfile is not None:\n", + " handler = logging.FileHandler(logfile)\n", + "else:\n", + " handler = logging.StreamHandler()\n", + "handler.setFormatter(logfmt)\n" ] }, { diff --git a/demos/notebooks/demo_dendritic.ipynb b/demos/notebooks/demo_dendritic.ipynb index 3c69dfdb6..58b329bf8 100644 --- a/demos/notebooks/demo_dendritic.ipynb +++ b/demos/notebooks/demo_dendritic.ipynb @@ -69,10 +69,14 @@ " print(f\"Will save logging data to {log_file}\")\n", "else:\n", " log_file = None\n", - "log_format = \"{asctime} - {levelname} - [{filename} {funcName}() {lineno}] - pid {process} - {message}\"\n", - "logging.basicConfig(format=log_format,\n", - " filename=log_file, \n", - " level=logging.WARNING, style=\"{\") #DEBUG, INFO, WARNING, ERROR, CRITICAL" + "logger = logging.getLogger('caiman')\n", + "logger.setLevel(logging.INFO)\n", + "logfmt = '%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s] [%(process)d] %(message)s'\n", + "if log_file is not None:\n", + " handler = logging.FileHandler(log_file)\n", + "else:\n", + " handler = logging.StreamHandler()\n", + "handler.setFormatter(logfmt)\n" ] }, { diff --git a/demos/notebooks/demo_motion_correction.ipynb b/demos/notebooks/demo_motion_correction.ipynb index d3c6fcc81..e62abbe0d 100644 --- a/demos/notebooks/demo_motion_correction.ipynb +++ b/demos/notebooks/demo_motion_correction.ipynb @@ -40,10 +40,15 @@ "except NameError:\n", " pass\n", "\n", - "logging.basicConfig(format=\n", - " \"%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s] [%(process)d] %(message)s\",\n", - " # filename=\"/tmp/caiman.log\",\n", - " level=logging.DEBUG)\n", + "logfile = None # Replace with a path if you want to log to a file\n", + "logger = logging.getLogger('caiman')\n", + "logger.setLevel(logging.INFO)\n", + "logfmt = '%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s] [%(process)d] %(message)s'\n", + "if logfile is not None:\n", + " handler = logging.FileHandler(logfile)\n", + "else:\n", + " handler = logging.StreamHandler()\n", + "handler.setFormatter(logfmt)\n", "\n", "import caiman as cm\n", "from caiman.motion_correction import MotionCorrect, tile_and_correct, motion_correction_piecewise\n", diff --git a/demos/notebooks/demo_online_3D.ipynb b/demos/notebooks/demo_online_3D.ipynb index 674ae1504..333bcc3b2 100644 --- a/demos/notebooks/demo_online_3D.ipynb +++ b/demos/notebooks/demo_online_3D.ipynb @@ -36,10 +36,15 @@ "import bokeh.plotting as bpl\n", "bpl.output_notebook()\n", "\n", - "logging.basicConfig(format=\n", - " \"%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s] [%(process)d] %(message)s\",\n", - " # filename=\"/tmp/caiman.log\",\n", - " level=logging.WARNING)" + "logfile = None # Replace with a path if you want to log to a file\n", + "logger = logging.getLogger('caiman')\n", + "logger.setLevel(logging.WARNING)\n", + "logfmt = '%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s] [%(process)d] %(message)s'\n", + "if logfile is not None:\n", + " handler = logging.FileHandler(logfile)\n", + "else:\n", + " handler = logging.StreamHandler()\n", + "handler.setFormatter(logfmt)\n" ] }, { diff --git a/demos/notebooks/demo_online_cnmfE.ipynb b/demos/notebooks/demo_online_cnmfE.ipynb index 1783024b0..f788df595 100644 --- a/demos/notebooks/demo_online_cnmfE.ipynb +++ b/demos/notebooks/demo_online_cnmfE.ipynb @@ -36,10 +36,15 @@ "except NameError:\n", " pass\n", "\n", - "logging.basicConfig(format=\n", - " \"%(relativeCreated)12d [%(filename)s:%(funcName)10s():%(lineno)s] [%(process)d] %(message)s\",\n", - " # filename=\"/tmp/caiman.log\",\n", - " level=logging.WARNING)\n", + "logfile = None # Replace with a path if you want to log to a file\n", + "logger = logging.getLogger('caiman')\n", + "logger.setLevel(logging.WARNING)\n", + "logfmt = '%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s] [%(process)d] %(message)s'\n", + "if logfile is not None:\n", + " handler = logging.FileHandler(logfile)\n", + "else:\n", + " handler = logging.StreamHandler()\n", + "handler.setFormatter(logfmt)\n", "\n", "bpl.output_notebook()\n", "hv.notebook_extension('bokeh')" diff --git a/demos/notebooks/demo_pipeline.ipynb b/demos/notebooks/demo_pipeline.ipynb index 7fb668cc3..5458ef3cf 100644 --- a/demos/notebooks/demo_pipeline.ipynb +++ b/demos/notebooks/demo_pipeline.ipynb @@ -93,9 +93,15 @@ "outputs": [], "source": [ "# set up logging\n", - "logging.basicConfig(format=\"{asctime} - {levelname} - [{filename} {funcName}() {lineno}] - pid {process} - {message}\",\n", - " filename=None, \n", - " level=logging.WARNING, style=\"{\") #logging level can be DEBUG, INFO, WARNING, ERROR, CRITICAL\n", + "logfile = None # Replace with a path if you want to log to a file\n", + "logger = logging.getLogger('caiman')\n", + "logger.setLevel(logging.WARNING)\n", + "logfmt = '%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s] [%(process)d] %(message)s'\n", + "if logfile is not None:\n", + " handler = logging.FileHandler(logfile)\n", + "else:\n", + " handler = logging.StreamHandler()\n", + "handler.setFormatter(logfmt)\n", "\n", "# set env variables \n", "os.environ[\"MKL_NUM_THREADS\"] = \"1\"\n", diff --git a/demos/notebooks/demo_pipeline_cnmfE.ipynb b/demos/notebooks/demo_pipeline_cnmfE.ipynb index 839b44075..32599fe9e 100644 --- a/demos/notebooks/demo_pipeline_cnmfE.ipynb +++ b/demos/notebooks/demo_pipeline_cnmfE.ipynb @@ -83,9 +83,15 @@ "outputs": [], "source": [ "# set up logging\n", - "logging.basicConfig(format=\"{asctime} - {levelname} - [{filename} {funcName}() {lineno}] - pid {process} - {message}\",\n", - " filename=None, \n", - " level=logging.WARNING, style=\"{\") #logging level can be DEBUG, INFO, WARNING, ERROR, CRITICAL\n", + "logfile = None # Replace with a path if you want to log to a file\n", + "logger = logging.getLogger('caiman')\n", + "logger.setLevel(logging.WARNING)\n", + "logfmt = '%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s] [%(process)d] %(message)s'\n", + "if logfile is not None:\n", + " handler = logging.FileHandler(logfile)\n", + "else:\n", + " handler = logging.StreamHandler()\n", + "handler.setFormatter(logfmt)\n", "\n", "# set env variables in case they weren't already set\n", "os.environ[\"MKL_NUM_THREADS\"] = \"1\"\n", diff --git a/demos/notebooks/demo_pipeline_voltage_imaging.ipynb b/demos/notebooks/demo_pipeline_voltage_imaging.ipynb index 3db090b78..524368f5a 100644 --- a/demos/notebooks/demo_pipeline_voltage_imaging.ipynb +++ b/demos/notebooks/demo_pipeline_voltage_imaging.ipynb @@ -60,10 +60,15 @@ "from caiman.summary_images import mean_image\n", "from caiman.paths import caiman_datadir\n", "\n", - "logging.basicConfig(format=\n", - " \"%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s]\" \\\n", - " \"[%(process)d] %(message)s\",\n", - " level=logging.ERROR)" + "logfile = None # Replace with a path if you want to log to a file\n", + "logger = logging.getLogger('caiman')\n", + "logger.setLevel(logging.ERROR)\n", + "logfmt = '%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s] [%(process)d] %(message)s'\n", + "if logfile is not None:\n", + " handler = logging.FileHandler(logfile)\n", + "else:\n", + " handler = logging.StreamHandler()\n", + "handler.setFormatter(logfmt)\n" ] }, { diff --git a/demos/notebooks/demo_realtime_cnmfE.ipynb b/demos/notebooks/demo_realtime_cnmfE.ipynb index 0122b9e0b..f4c4f478b 100644 --- a/demos/notebooks/demo_realtime_cnmfE.ipynb +++ b/demos/notebooks/demo_realtime_cnmfE.ipynb @@ -51,10 +51,15 @@ "except NameError:\n", " pass\n", "\n", - "logging.basicConfig(format=\n", - " \"%(relativeCreated)12d [%(filename)s:%(funcName)10s():%(lineno)s] [%(process)d] %(message)s\",\n", - " # filename=\"/tmp/caiman.log\",\n", - " level=logging.WARNING)\n", + "logfile = None # Replace with a path if you want to log to a file\n", + "logger = logging.getLogger('caiman')\n", + "logger.setLevel(logging.WARNING)\n", + "logfmt = '%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s] [%(process)d] %(message)s'\n", + "if logfile is not None:\n", + " handler = logging.FileHandler(logfile)\n", + "else:\n", + " handler = logging.StreamHandler()\n", + "handler.setFormatter(logfmt)\n", "\n", "import caiman as cm\n", "from caiman.source_extraction import cnmf\n", diff --git a/demos/notebooks/demo_seeded_CNMF.ipynb b/demos/notebooks/demo_seeded_CNMF.ipynb index 4f1ad1e60..2c1c3bfed 100644 --- a/demos/notebooks/demo_seeded_CNMF.ipynb +++ b/demos/notebooks/demo_seeded_CNMF.ipynb @@ -45,10 +45,15 @@ "except NameError:\n", " pass\n", "\n", - "logging.basicConfig(format=\n", - " \"%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s] [%(process)d] %(message)s\",\n", - " # filename=\"/tmp/caiman.log\",\n", - " level=logging.WARNING)\n", + "logfile = None # Replace with a path if you want to log to a file\n", + "logger = logging.getLogger('caiman')\n", + "logger.setLevel(logging.WARNING)\n", + "logfmt = '%(relativeCreated)12d [%(filename)s:%(funcName)20s():%(lineno)s] [%(process)d] %(message)s'\n", + "if logfile is not None:\n", + " handler = logging.FileHandler(logfile)\n", + "else:\n", + " handler = logging.StreamHandler()\n", + "handler.setFormatter(logfmt)\n", "\n", "import caiman as cm\n", "from caiman.motion_correction import MotionCorrect\n",