Skip to content

Commit

Permalink
Fix non plotting due to index errors
Browse files Browse the repository at this point in the history
  • Loading branch information
haticekaratay committed Oct 10, 2024
1 parent 4237e4d commit 5d13473
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 56 deletions.
92 changes: 43 additions & 49 deletions notebooks/COS/SplitTag/SplitTag.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -530,52 +530,25 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cleared-tradition",
"id": "7e4d0889-be32-46b1-a0cf-c2bd232132e4",
"metadata": {},
"outputs": [],
"source": [
"# Check if \"lref\" is not set in the environment variables\n",
"# 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",
" # If on STScI Network/VPN\n",
" if os.path.exists('/grp/hst/cdbs/lref/'):\n",
" os.environ['lref'] = '/grp/hst/cdbs/lref/'\n",
" print(\"It looks like you are on the STScI \" +\n",
" \"network; setting lref to '/grp/hst/cdbs/lref/'\")\n",
" # If not on STScI Network/VPN\n",
" else:\n",
" if os.name == \"nt\":\n",
" home_directory = os.environ[\"USERPROFILE\"]\n",
" home_directory = os.environ[\"HOME\"]\n",
" crds_path = os.path.join(home_directory, \"crds_cache\")\n",
" os.environ[\"CRDS_PATH\"] = crds_path\n",
" # URL for the STScI CRDS page\n",
" crds_server_url = \"https://hst-crds.stsci.edu\"\n",
" # Setting env variable to URL\n",
" os.environ[\"CRDS_SERVER_URL\"] = crds_server_url\n",
" # Synchronize CRDS and fetch references\n",
" !crds sync --contexts hst_cos_0347.imap --fetch-references\n",
" lref = os.path.join(crds_path, \"references/hst/cos\")\n",
" os.environ['lref'] = lref\n",
" # Check if that path exists\n",
" if not os.path.exists(os.environ['lref']):\n",
" print(\"It doesn't look like that's a valid path. Deleting it.\")\n",
" # delete this nonexistant path\n",
" del os.environ['lref']\n",
" lref = os.path.join(crds_path, \"references/hst/cos\")\n",
" os.environ['lref'] = lref\n",
"else:\n",
" # Set home_directory\n",
" # For windows: \n",
" if os.name == \"nt\":\n",
" home_directory = os.environ[\"USERPROFILE\"]\n",
" # Other operating systems\n",
" else:\n",
" home_directory = os.path.expanduser(\"~\")\n",
" # Get the home directory from the lref\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",
"\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']})\""
]
Expand Down Expand Up @@ -642,6 +615,10 @@
"source": [
"# Find all the `x1d` files:\n",
"processed_files = sorted(glob.glob('output/calcos/epoch*/*x1d.fits'))\n",
"num_files = len(processed_files)\n",
"\n",
"cmap = plt.colormaps.get_cmap('viridis')\n",
"colors = np.linspace(0,1,len(processed_files))\n",
"\n",
"# Set up figure\n",
"plt.figure(figsize=(18, 12))\n",
Expand All @@ -653,6 +630,9 @@
" # Mark the transit\n",
" if \"2\" in epoch_label:\n",
" epoch_label += \" (transit)\"\n",
" alpha_value = 1\n",
" else:\n",
" alpha_value = 0.5\n",
"\n",
" with warnings.catch_warnings():\n",
" warnings.filterwarnings('ignore',\n",
Expand All @@ -669,8 +649,8 @@
" # Plot each epoch\n",
" plt.plot(w, f,\n",
" # Epoch2 should stand out\n",
" alpha=[0.5, 1, 0.5][i],\n",
" c=['b', 'purple', 'r'][i],\n",
" alpha=alpha_value,\n",
" c=cmap(colors[i]),\n",
" # Label with the epoch name\n",
" label=epoch_label)\n",
"\n",
Expand Down Expand Up @@ -720,6 +700,9 @@
" epoch_label = processed_files[i].split('/')[2]\n",
" if \"2\" in epoch_label:\n",
" epoch_label += \" (transit)\"\n",
" alpha_value = 1\n",
" else:\n",
" alpha_value = 0.5\n",
"\n",
" with warnings.catch_warnings():\n",
" warnings.filterwarnings('ignore',\n",
Expand All @@ -736,20 +719,20 @@
" # Plot each epoch\n",
" ax0.plot(w, f,\n",
" # Epoch2 should stand out\n",
" alpha=[0.5, 1, 0.5][i],\n",
" c=['b', 'purple', 'r'][i],\n",
" alpha=alpha_value,\n",
" c=cmap(colors[i]),\n",
" linestyle='-',\n",
" # Label with the epoch name\n",
" label=epoch_label)\n",
"\n",
" # Plot each epoch\n",
" ax1.errorbar(w, f, yerr=ferr,\n",
" # Epoch2 should stand out\n",
" alpha=[0.5, 1, 0.5][i],\n",
" alpha=alpha_value,\n",
" marker='.',\n",
" markerfacecolor=['b', 'purple', 'r'][i],\n",
" markerfacecolor=cmap(colors[i]),\n",
" linestyle='',\n",
" ecolor=['b', 'purple', 'r'][i],\n",
" ecolor=cmap(colors[i]),\n",
" # Label with the epoch name\n",
" label=epoch_label)\n",
"\n",
Expand Down Expand Up @@ -808,6 +791,9 @@
" epoch_label = processed_files[i].split('/')[2]\n",
" if \"2\" in epoch_label:\n",
" epoch_label += \" (transit)\"\n",
" alpha_value = 1\n",
" else:\n",
" alpha_value = 0.5\n",
"\n",
" with warnings.catch_warnings():\n",
" warnings.filterwarnings('ignore',\n",
Expand All @@ -824,20 +810,20 @@
" # Plot each epoch\n",
" ax0.plot(w, f,\n",
" # Epoch2 should stand out\n",
" alpha=[0.5, 1, 0.5][i],\n",
" c=['b', 'purple', 'r'][i],\n",
" alpha=alpha_value,\n",
" c=cmap(colors[i]),\n",
" linestyle='-',\n",
" # Label with the epoch name\n",
" label=epoch_label)\n",
"\n",
" # Plot each epoch\n",
" ax1.errorbar(w, f, yerr=ferr,\n",
" # Epoch2 should stand out\n",
" alpha=[0.5, 1, 0.5][i],\n",
" alpha=alpha_value,\n",
" marker='.',\n",
" markerfacecolor=['b', 'purple', 'r'][i],\n",
" markerfacecolor=cmap(colors[i]),\n",
" linestyle='',\n",
" ecolor=['b', 'purple', 'r'][i],\n",
" ecolor=cmap(colors[i]),\n",
" # Label with the epoch name\n",
" label=epoch_label)\n",
"\n",
Expand Down Expand Up @@ -1270,6 +1256,14 @@
"\n",
"Note that epoch 1 contains all the counts from epoch 1.5, while epoch 2 does not. Thus this is not a perfect test. However, the vast majority of epoch 1's counts do *not* overlap with epoch 1.5 (see fig 2.1), so this is an acceptable \"first pass\" test. It's also possible that the very low number of counts, especially in epochs 1.5 and 2, does not give us the signal-to-noise we would need to accurately distinguish the epochs."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f9380ce0-9f41-48b8-99f8-5871cf53fc02",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -1291,7 +1285,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
},
"nbdime-conflicts": {
"local_diff": [
Expand Down
14 changes: 7 additions & 7 deletions notebooks/COS/SplitTag/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
astropy==5.3.3
astroquery==0.4.6
calcos==3.4.4
costools==1.2.6
matplotlib==3.7.0
numpy==1.23.4
crds==11.17.0
astropy>=5.3.3
astroquery>=0.4.6
calcos>=3.4.4
costools>=1.2.6
matplotlib>=3.7.0
numpy>=1.23.4
crds>=11.17.0

0 comments on commit 5d13473

Please sign in to comment.