Skip to content

Commit

Permalink
Fix style errors, and simplify env setup logic
Browse files Browse the repository at this point in the history
  • Loading branch information
haticekaratay committed Oct 10, 2024
1 parent 5d13473 commit 60706a2
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions notebooks/COS/SplitTag/SplitTag.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down Expand Up @@ -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."
]
},
{
Expand All @@ -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()"
]
},
{
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 60706a2

Please sign in to comment.