From 60706a258cf0af0caa1e2e7916075fc1b4606f7e Mon Sep 17 00:00:00 2001 From: Hatice Karatay Date: Thu, 10 Oct 2024 16:12:46 -0400 Subject: [PATCH] Fix style errors, and simplify env setup logic --- notebooks/COS/SplitTag/SplitTag.ipynb | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/notebooks/COS/SplitTag/SplitTag.ipynb b/notebooks/COS/SplitTag/SplitTag.ipynb index 51959118e..3bd514d30 100644 --- a/notebooks/COS/SplitTag/SplitTag.ipynb +++ b/notebooks/COS/SplitTag/SplitTag.ipynb @@ -95,7 +95,9 @@ "\n", "# For supressing an unhelpful warning:\n", "import warnings\n", - "from astropy.units import UnitsWarning" + "from astropy.units import UnitsWarning\n", + "\n", + "from IPython.display import clear_output" ] }, { @@ -524,7 +526,7 @@ "## 3.1 Getting the `lref` reference files\n", "To run `CalCOS`, your computer will need an `lref` system variable to tell the pipeline where to find your reference files. If you are on the STScI internet network (including via VPN), you may set this to the shared Institute `lref` directory. However, if you're not on the network, you will need to use the `CRDS` command to download the necessary reference files. This process is described in detail in Chapter 3 of our [notebook on setting up an environment for working with COS data](https://github.com/spacetelescope/hst_notebooks/blob/main/notebooks/COS/Setup/Setup.ipynb#crdsS). \n", "\n", - "The code in this cell ensures that the \"lref\" path is correctly set in the environment variables. If \"lref\" is not already defined, it will be defined and the crds files will be downloaded. If you have already downloaded the files, the CRDS cache on your computer will be used, as shown in the \"else\" block." + "The code in this cell ensures that the \"lref\" path is correctly set in the environment variables and the crds files will be downloaded." ] }, { @@ -534,23 +536,11 @@ "metadata": {}, "outputs": [], "source": [ - "# This cell is for ensuring you have a valid \"lref\" directory of reference files.\n", - "home_directory = os.environ.get(\"USERPROFILE\", os.path.expanduser(\"~\"))\n", - "crds_path = os.path.join(home_directory, \"crds_cache\")\n", - "os.environ[\"CRDS_PATH\"] = crds_path\n", "os.environ[\"CRDS_SERVER_URL\"] = \"https://hst-crds.stsci.edu\"\n", - "if not os.environ.get('lref'):\n", - " lref = os.path.join(crds_path, \"references/hst/cos\")\n", - " os.environ['lref'] = lref\n", - "else:\n", - " lref = os.environ['lref']\n", - " # Replace the {HOME} placeholder with the home directory path\n", - " expanded_path = lref.replace(\"{HOME}\", home_directory)\n", - " os.environ['lref'] = expanded_path\n", - " print(f\"You already have an lref path in your env variables: {lref}\\n\")\n", + "os.environ[\"CRDS_PATH\"] = './crds_cache'\n", + "os.environ['lref'] = \"./crds_cache/references/hst/cos\"\n", "!crds sync --contexts hst_cos_0347.imap --fetch-references\n", - "assert os.path.exists(os.environ['lref']), \"Path to lref directory \" + \\\n", - " \"is invalid ({os.environ['lref']})\"" + "clear_output()" ] }, { @@ -618,7 +608,7 @@ "num_files = len(processed_files)\n", "\n", "cmap = plt.colormaps.get_cmap('viridis')\n", - "colors = np.linspace(0,1,len(processed_files))\n", + "colors = np.linspace(0, 1, len(processed_files))\n", "\n", "# Set up figure\n", "plt.figure(figsize=(18, 12))\n",