diff --git a/DP1/300_Science_Demos/306_Extragalactic_transients/306_4_Recalculate_reliabilty_scores.ipynb b/DP1/300_Science_Demos/306_Extragalactic_transients/306_4_Recalculate_reliabilty_scores.ipynb index 2138d9b2..a75b3503 100644 --- a/DP1/300_Science_Demos/306_Extragalactic_transients/306_4_Recalculate_reliabilty_scores.ipynb +++ b/DP1/300_Science_Demos/306_Extragalactic_transients/306_4_Recalculate_reliabilty_scores.ipynb @@ -100,6 +100,8 @@ "outputs": [], "source": [ "import os\n", + "import sys\n", + "from contextlib import contextmanager\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from astropy.coordinates import SkyCoord\n", @@ -176,6 +178,32 @@ "targ_band = \"r\"" ] }, + { + "cell_type": "markdown", + "id": "7a6a4e19-109c-440c-9ad7-c9c3d7ec4379", + "metadata": {}, + "source": [ + "Define a function that will prevent the `RBTransiNetTask` from attempting to write a `pycache` file while running.\n", + "This file is not necessary in the context of this tutorial." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "84e1ffa3-29ee-4e55-9ed7-196049d48147", + "metadata": {}, + "outputs": [], + "source": [ + "@contextmanager\n", + "def suppress_bytecode():\n", + " prev_bc = sys.dont_write_bytecode\n", + " sys.dont_write_bytecode = True\n", + " try:\n", + " yield\n", + " finally:\n", + " sys.dont_write_bytecode = prev_bc" + ] + }, { "cell_type": "markdown", "id": "7546554b-b650-4334-a169-80ae8ad96832", @@ -631,7 +659,8 @@ "metadata": {}, "source": [ "Run the task by passing it the template, science, and difference images, and the sources table.\n", - "Extract the reliability scores (classifications) as an `astropy` table." + "Extract the reliability scores (classifications) as an `astropy` table.\n", + "Use the `suppress_bytecode` function defined in Section 1.2 to avoid the creation of unnecessary auxiliary files." ] }, { @@ -641,8 +670,9 @@ "metadata": {}, "outputs": [], "source": [ - "results = reliabilityTask.run(new_template.template, science, difference,\n", - " sources, pretrainedModel=None)\n", + "with suppress_bytecode():\n", + " results = reliabilityTask.run(new_template.template, science, difference,\n", + " sources, pretrainedModel=None)\n", "rb_table = results.classifications.asAstropy()\n", "del results" ]