Skip to content

Commit

Permalink
Error analysis tutorial: print -> logging
Browse files Browse the repository at this point in the history
  • Loading branch information
biermanncarl committed Jun 2, 2021
1 parent cfb14f0 commit 6036f3e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
14 changes: 9 additions & 5 deletions doc/tutorials/error_analysis/error_analysis_part1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"plt.rcParams.update({'font.size': 18})\n",
"import sys\n",
"import logging\n",
"logging.basicConfig(level=logging.INFO, stream=sys.stdout)\n",
"\n",
"np.random.seed(43)\n",
"\n",
Expand All @@ -54,7 +57,7 @@
"\n",
"# generate simulation data using the AR(1) process\n",
"\n",
"print(\"Generating data sets for the tutorial ...\\n\")\n",
"logging.info(\"Generating data sets for the tutorial ...\")\n",
"\n",
"N_SAMPLES = 100000\n",
"\n",
Expand All @@ -69,7 +72,7 @@
"time_series_2 = ar_1_process(N_SAMPLES, C_2, PHI_2, EPS_2)\n",
"\n",
"\n",
"print(\"Done\")"
"logging.info(\"Done\")"
]
},
{
Expand Down Expand Up @@ -292,8 +295,8 @@
"metadata": {},
"outputs": [],
"source": [
"print(\"Best guess for measured quantity:\",avg)\n",
"print(\"Standard error of the mean:\",sem)"
"print(f\"Best guess for measured quantity: {avg:.3f}\")\n",
"print(f\"Standard error of the mean: {sem:.3f}\")"
]
},
{
Expand Down Expand Up @@ -413,7 +416,7 @@
"plt.ylabel(\"SEM\")\n",
"plt.show()\n",
"\n",
"print(\"Final Standard Error of the Mean: {:.3f}\".format(fit_params[2]))"
"print(f\"Final Standard Error of the Mean: {fit_params[2]:.3f}\")"
]
},
{
Expand Down Expand Up @@ -489,3 +492,4 @@
"nbformat": 4,
"nbformat_minor": 4
}

22 changes: 13 additions & 9 deletions doc/tutorials/error_analysis/error_analysis_part2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"plt.rcParams.update({'font.size': 18})\n",
"import sys\n",
"import logging\n",
"logging.basicConfig(level=logging.INFO, stream=sys.stdout)\n",
"\n",
"np.random.seed(43)\n",
"\n",
Expand All @@ -52,7 +55,7 @@
"\n",
"# generate simulation data using the AR(1) process\n",
"\n",
"print(\"Generating data sets for the tutorial ...\\n\")\n",
"logging.info(\"Generating data sets for the tutorial ...\\n\")\n",
"\n",
"N_SAMPLES = 100000\n",
"\n",
Expand All @@ -67,7 +70,7 @@
"time_series_2 = ar_1_process(N_SAMPLES, C_2, PHI_2, EPS_2)\n",
"\n",
"\n",
"print(\"Done\")"
"logging.info(\"Done\")"
]
},
{
Expand Down Expand Up @@ -267,7 +270,7 @@
"plt.ylabel(\"$\\hat{R}^{XX}_j$\")\n",
"plt.show()\n",
"\n",
"print(\"Exponential autocorrelation time: {:.2f} sampling intervals\".format(popt[1]))"
"print(f\"Exponential autocorrelation time: {popt[1]:.2f} sampling intervals\")"
]
},
{
Expand Down Expand Up @@ -385,7 +388,7 @@
" * `C` (which is the criterion to find $j_\\mathrm{max}$) and \n",
" * `window` (an integer that defines how much of the auto-covariance function is computed during the analysis).\n",
" \n",
" The function shall return the SEM and print out:\n",
" The function shall return the SEM and logging.info out:\n",
" * mean\n",
" * SEM\n",
" * integrated autocorrelation time\n",
Expand Down Expand Up @@ -456,11 +459,11 @@
" plt.title(\"\")\n",
" plt.show()\n",
" \n",
" # print out stuff\n",
" print(\"Mean value: {:.4f}\".format(avg))\n",
" print(\"Standard error of the mean: {:.4f}\".format(sem))\n",
" print(\"Integrated autocorrelation time: {:.2f} time steps\".format(tau_int))\n",
" print(\"Effective number of samples: {:.2f}\".format(N_eff))\n",
" # logging.info out stuff\n",
" logging.info(\"Mean value: {:.4f}\".format(avg))\n",
" logging.info(\"Standard error of the mean: {:.4f}\".format(sem))\n",
" logging.info(\"Integrated autocorrelation time: {:.2f} time steps\".format(tau_int))\n",
" logging.info(\"Effective number of samples: {:.2f}\".format(N_eff))\n",
"\n",
" return sem\n",
"\n",
Expand Down Expand Up @@ -531,3 +534,4 @@
"nbformat": 4,
"nbformat_minor": 4
}

0 comments on commit 6036f3e

Please sign in to comment.