From 5b41fea5d92d25e6c2a2694d0a396e5c38271e2c Mon Sep 17 00:00:00 2001 From: Joe Filippazzo Date: Wed, 25 Jun 2025 16:01:02 -0400 Subject: [PATCH 1/3] Old nbs --- .../notebooks/Contamination Validation.ipynb | 368 +----------------- .../contamination_and_visibility_demo.ipynb | 44 +-- 2 files changed, 40 insertions(+), 372 deletions(-) diff --git a/exoctk/notebooks/Contamination Validation.ipynb b/exoctk/notebooks/Contamination Validation.ipynb index f958e2462..27228737a 100644 --- a/exoctk/notebooks/Contamination Validation.ipynb +++ b/exoctk/notebooks/Contamination Validation.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "61cd6088-1220-49e8-bedd-f82b3dca966c", + "id": "0", "metadata": {}, "source": [ "# Validation Testing for the Contamination and Visibility Tool\n", @@ -11,332 +11,10 @@ }, { "cell_type": "code", - "execution_count": 1, - "id": "c1a0077f-21f2-4f6d-8da1-7d2c2c3e8af0", + "execution_count": null, + "id": "1", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "pandeia not installed. Functionality limited.\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "**WARNING**: LOCAL JWST PRD VERSION PRDOPSSOC-062 CANNOT BE CHECKED AGAINST ONLINE VERSION\n" - ] - }, - { - "data": { - "text/html": [ - "\n", - "
\n", - " \n", - " Loading BokehJS ...\n", - "
\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/javascript": [ - "(function(root) {\n", - " function now() {\n", - " return new Date();\n", - " }\n", - "\n", - " const force = true;\n", - "\n", - " if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n", - " root._bokeh_onload_callbacks = [];\n", - " root._bokeh_is_loading = undefined;\n", - " }\n", - "\n", - "const JS_MIME_TYPE = 'application/javascript';\n", - " const HTML_MIME_TYPE = 'text/html';\n", - " const EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n", - " const CLASS_NAME = 'output_bokeh rendered_html';\n", - "\n", - " /**\n", - " * Render data to the DOM node\n", - " */\n", - " function render(props, node) {\n", - " const script = document.createElement(\"script\");\n", - " node.appendChild(script);\n", - " }\n", - "\n", - " /**\n", - " * Handle when an output is cleared or removed\n", - " */\n", - " function handleClearOutput(event, handle) {\n", - " const cell = handle.cell;\n", - "\n", - " const id = cell.output_area._bokeh_element_id;\n", - " const server_id = cell.output_area._bokeh_server_id;\n", - " // Clean up Bokeh references\n", - " if (id != null && id in Bokeh.index) {\n", - " Bokeh.index[id].model.document.clear();\n", - " delete Bokeh.index[id];\n", - " }\n", - "\n", - " if (server_id !== undefined) {\n", - " // Clean up Bokeh references\n", - " const cmd_clean = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n", - " cell.notebook.kernel.execute(cmd_clean, {\n", - " iopub: {\n", - " output: function(msg) {\n", - " const id = msg.content.text.trim();\n", - " if (id in Bokeh.index) {\n", - " Bokeh.index[id].model.document.clear();\n", - " delete Bokeh.index[id];\n", - " }\n", - " }\n", - " }\n", - " });\n", - " // Destroy server and session\n", - " const cmd_destroy = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n", - " cell.notebook.kernel.execute(cmd_destroy);\n", - " }\n", - " }\n", - "\n", - " /**\n", - " * Handle when a new output is added\n", - " */\n", - " function handleAddOutput(event, handle) {\n", - " const output_area = handle.output_area;\n", - " const output = handle.output;\n", - "\n", - " // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n", - " if ((output.output_type != \"display_data\") || (!Object.prototype.hasOwnProperty.call(output.data, EXEC_MIME_TYPE))) {\n", - " return\n", - " }\n", - "\n", - " const toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n", - "\n", - " if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n", - " toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n", - " // store reference to embed id on output_area\n", - " output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n", - " }\n", - " if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n", - " const bk_div = document.createElement(\"div\");\n", - " bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n", - " const script_attrs = bk_div.children[0].attributes;\n", - " for (let i = 0; i < script_attrs.length; i++) {\n", - " toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n", - " toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n", - " }\n", - " // store reference to server id on output_area\n", - " output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n", - " }\n", - " }\n", - "\n", - " function register_renderer(events, OutputArea) {\n", - "\n", - " function append_mime(data, metadata, element) {\n", - " // create a DOM node to render to\n", - " const toinsert = this.create_output_subarea(\n", - " metadata,\n", - " CLASS_NAME,\n", - " EXEC_MIME_TYPE\n", - " );\n", - " this.keyboard_manager.register_events(toinsert);\n", - " // Render to node\n", - " const props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n", - " render(props, toinsert[toinsert.length - 1]);\n", - " element.append(toinsert);\n", - " return toinsert\n", - " }\n", - "\n", - " /* Handle when an output is cleared or removed */\n", - " events.on('clear_output.CodeCell', handleClearOutput);\n", - " events.on('delete.Cell', handleClearOutput);\n", - "\n", - " /* Handle when a new output is added */\n", - " events.on('output_added.OutputArea', handleAddOutput);\n", - "\n", - " /**\n", - " * Register the mime type and append_mime function with output_area\n", - " */\n", - " OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n", - " /* Is output safe? */\n", - " safe: true,\n", - " /* Index of renderer in `output_area.display_order` */\n", - " index: 0\n", - " });\n", - " }\n", - "\n", - " // register the mime type if in Jupyter Notebook environment and previously unregistered\n", - " if (root.Jupyter !== undefined) {\n", - " const events = require('base/js/events');\n", - " const OutputArea = require('notebook/js/outputarea').OutputArea;\n", - "\n", - " if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n", - " register_renderer(events, OutputArea);\n", - " }\n", - " }\n", - " if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n", - " root._bokeh_timeout = Date.now() + 5000;\n", - " root._bokeh_failed_load = false;\n", - " }\n", - "\n", - " const NB_LOAD_WARNING = {'data': {'text/html':\n", - " \"
\\n\"+\n", - " \"

\\n\"+\n", - " \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n", - " \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n", - " \"

\\n\"+\n", - " \"\\n\"+\n", - " \"\\n\"+\n", - " \"from bokeh.resources import INLINE\\n\"+\n", - " \"output_notebook(resources=INLINE)\\n\"+\n", - " \"\\n\"+\n", - " \"
\"}};\n", - "\n", - " function display_loaded() {\n", - " const el = document.getElementById(\"e93f0f46-e36c-4ff9-8b17-dd5fb73965d7\");\n", - " if (el != null) {\n", - " el.textContent = \"BokehJS is loading...\";\n", - " }\n", - " if (root.Bokeh !== undefined) {\n", - " if (el != null) {\n", - " el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n", - " }\n", - " } else if (Date.now() < root._bokeh_timeout) {\n", - " setTimeout(display_loaded, 100)\n", - " }\n", - " }\n", - "\n", - " function run_callbacks() {\n", - " try {\n", - " root._bokeh_onload_callbacks.forEach(function(callback) {\n", - " if (callback != null)\n", - " callback();\n", - " });\n", - " } finally {\n", - " delete root._bokeh_onload_callbacks\n", - " }\n", - " console.debug(\"Bokeh: all callbacks have finished\");\n", - " }\n", - "\n", - " function load_libs(css_urls, js_urls, callback) {\n", - " if (css_urls == null) css_urls = [];\n", - " if (js_urls == null) js_urls = [];\n", - "\n", - " root._bokeh_onload_callbacks.push(callback);\n", - " if (root._bokeh_is_loading > 0) {\n", - " console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", - " return null;\n", - " }\n", - " if (js_urls == null || js_urls.length === 0) {\n", - " run_callbacks();\n", - " return null;\n", - " }\n", - " console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", - " root._bokeh_is_loading = css_urls.length + js_urls.length;\n", - "\n", - " function on_load() {\n", - " root._bokeh_is_loading--;\n", - " if (root._bokeh_is_loading === 0) {\n", - " console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n", - " run_callbacks()\n", - " }\n", - " }\n", - "\n", - " function on_error(url) {\n", - " console.error(\"failed to load \" + url);\n", - " }\n", - "\n", - " for (let i = 0; i < css_urls.length; i++) {\n", - " const url = css_urls[i];\n", - " const element = document.createElement(\"link\");\n", - " element.onload = on_load;\n", - " element.onerror = on_error.bind(null, url);\n", - " element.rel = \"stylesheet\";\n", - " element.type = \"text/css\";\n", - " element.href = url;\n", - " console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n", - " document.body.appendChild(element);\n", - " }\n", - "\n", - " for (let i = 0; i < js_urls.length; i++) {\n", - " const url = js_urls[i];\n", - " const element = document.createElement('script');\n", - " element.onload = on_load;\n", - " element.onerror = on_error.bind(null, url);\n", - " element.async = false;\n", - " element.src = url;\n", - " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", - " document.head.appendChild(element);\n", - " }\n", - " };\n", - "\n", - " function inject_raw_css(css) {\n", - " const element = document.createElement(\"style\");\n", - " element.appendChild(document.createTextNode(css));\n", - " document.body.appendChild(element);\n", - " }\n", - "\n", - " const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-3.2.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-3.2.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-3.2.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-3.2.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-3.2.2.min.js\"];\n", - " const css_urls = [];\n", - "\n", - " const inline_js = [ function(Bokeh) {\n", - " Bokeh.set_log_level(\"info\");\n", - " },\n", - "function(Bokeh) {\n", - " }\n", - " ];\n", - "\n", - " function run_inline_js() {\n", - " if (root.Bokeh !== undefined || force === true) {\n", - " for (let i = 0; i < inline_js.length; i++) {\n", - " inline_js[i].call(root, root.Bokeh);\n", - " }\n", - "if (force === true) {\n", - " display_loaded();\n", - " }} else if (Date.now() < root._bokeh_timeout) {\n", - " setTimeout(run_inline_js, 100);\n", - " } else if (!root._bokeh_failed_load) {\n", - " console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n", - " root._bokeh_failed_load = true;\n", - " } else if (force !== true) {\n", - " const cell = $(document.getElementById(\"e93f0f46-e36c-4ff9-8b17-dd5fb73965d7\")).parents('.cell').data().cell;\n", - " cell.output_area.append_execute_result(NB_LOAD_WARNING)\n", - " }\n", - " }\n", - "\n", - " if (root._bokeh_is_loading === 0) {\n", - " console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n", - " run_inline_js();\n", - " } else {\n", - " load_libs(css_urls, js_urls, function() {\n", - " console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n", - " run_inline_js();\n", - " });\n", - " }\n", - "}(window));" - ], - "application/vnd.bokehjs_load.v0+json": "(function(root) {\n function now() {\n return new Date();\n }\n\n const force = true;\n\n if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n root._bokeh_onload_callbacks = [];\n root._bokeh_is_loading = undefined;\n }\n\n\n if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n const NB_LOAD_WARNING = {'data': {'text/html':\n \"
\\n\"+\n \"

\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"

\\n\"+\n \"\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"\\n\"+\n \"
\"}};\n\n function display_loaded() {\n const el = document.getElementById(\"e93f0f46-e36c-4ff9-8b17-dd5fb73965d7\");\n if (el != null) {\n el.textContent = \"BokehJS is loading...\";\n }\n if (root.Bokeh !== undefined) {\n if (el != null) {\n el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(display_loaded, 100)\n }\n }\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) {\n if (callback != null)\n callback();\n });\n } finally {\n delete root._bokeh_onload_callbacks\n }\n console.debug(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(css_urls, js_urls, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n\n root._bokeh_onload_callbacks.push(callback);\n if (root._bokeh_is_loading > 0) {\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n }\n if (js_urls == null || js_urls.length === 0) {\n run_callbacks();\n return null;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n function on_load() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n run_callbacks()\n }\n }\n\n function on_error(url) {\n console.error(\"failed to load \" + url);\n }\n\n for (let i = 0; i < css_urls.length; i++) {\n const url = css_urls[i];\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error.bind(null, url);\n element.rel = \"stylesheet\";\n element.type = \"text/css\";\n element.href = url;\n console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n document.body.appendChild(element);\n }\n\n for (let i = 0; i < js_urls.length; i++) {\n const url = js_urls[i];\n const element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error.bind(null, url);\n element.async = false;\n element.src = url;\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n };\n\n function inject_raw_css(css) {\n const element = document.createElement(\"style\");\n element.appendChild(document.createTextNode(css));\n document.body.appendChild(element);\n }\n\n const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-3.2.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-3.2.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-3.2.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-3.2.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-3.2.2.min.js\"];\n const css_urls = [];\n\n const inline_js = [ function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\nfunction(Bokeh) {\n }\n ];\n\n function run_inline_js() {\n if (root.Bokeh !== undefined || force === true) {\n for (let i = 0; i < inline_js.length; i++) {\n inline_js[i].call(root, root.Bokeh);\n }\nif (force === true) {\n display_loaded();\n }} else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n } else if (force !== true) {\n const cell = $(document.getElementById(\"e93f0f46-e36c-4ff9-8b17-dd5fb73965d7\")).parents('.cell').data().cell;\n cell.output_area.append_execute_result(NB_LOAD_WARNING)\n }\n }\n\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n run_inline_js();\n } else {\n load_libs(css_urls, js_urls, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n}(window));" - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "# Imports\n", "from astropy.io import fits\n", @@ -349,7 +27,7 @@ }, { "cell_type": "markdown", - "id": "9726b720-7084-4ff9-9f62-3507d2d072e0", + "id": "2", "metadata": {}, "source": [ "## Download the data\n", @@ -359,7 +37,7 @@ { "cell_type": "code", "execution_count": null, - "id": "6ed2a951-e321-4c33-a97f-7d432ec494ea", + "id": "3", "metadata": {}, "outputs": [], "source": [ @@ -368,7 +46,7 @@ }, { "cell_type": "markdown", - "id": "acc5b684-6cda-499f-bc88-4a46109f4808", + "id": "4", "metadata": {}, "source": [ "## Load the data into the session\n", @@ -377,11 +55,9 @@ }, { "cell_type": "code", - "execution_count": 2, - "id": "d4595010-c0c5-44d8-8ebe-eea9cdaee502", - "metadata": { - "scrolled": true - }, + "execution_count": null, + "id": "5", + "metadata": {}, "outputs": [], "source": [ "# Check the header if you like\n", @@ -391,7 +67,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f0fc7bae-b1e4-4086-ba93-43b49be1e80c", + "id": "6", "metadata": {}, "outputs": [], "source": [ @@ -403,7 +79,7 @@ }, { "cell_type": "markdown", - "id": "d92af0ff-920a-469b-8217-1a3b24242524", + "id": "7", "metadata": {}, "source": [ "## Run the Contamination and Visibility Tool" @@ -412,7 +88,7 @@ { "cell_type": "code", "execution_count": null, - "id": "b5fba590-8964-4992-a150-65d342991572", + "id": "8", "metadata": {}, "outputs": [], "source": [ @@ -423,18 +99,10 @@ }, { "cell_type": "code", - "execution_count": 24, - "id": "c9c5255f-2ab1-4c37-a992-1ef95546a244", + "execution_count": null, + "id": "9", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "INFO: Query finished. [astroquery.utils.tap.core]\n" - ] - } - ], + "outputs": [], "source": [ "# Calculate contamination\n", "result_onsky, plot_onsky = fs.calc_v3pa(pa, sources, 'NIS_SUBSTRIP256', data=rate_data, plot=True, verbose=False)\n", @@ -446,7 +114,7 @@ { "cell_type": "code", "execution_count": null, - "id": "cc62fc83-48fe-4ed3-8e57-7d0730974cea", + "id": "10", "metadata": {}, "outputs": [], "source": [ @@ -460,7 +128,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d8134c6f-3c7d-43b3-bb4a-624d98725deb", + "id": "11", "metadata": {}, "outputs": [], "source": [] diff --git a/exoctk/notebooks/contamination_and_visibility_demo.ipynb b/exoctk/notebooks/contamination_and_visibility_demo.ipynb index 99ad36648..9ef6fb522 100644 --- a/exoctk/notebooks/contamination_and_visibility_demo.ipynb +++ b/exoctk/notebooks/contamination_and_visibility_demo.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "61cd6088-1220-49e8-bedd-f82b3dca966c", + "id": "0", "metadata": {}, "source": [ "# ExoCTK Contamination and Visibility Tool Demo\n", @@ -12,7 +12,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c1a0077f-21f2-4f6d-8da1-7d2c2c3e8af0", + "id": "1", "metadata": {}, "outputs": [], "source": [ @@ -29,7 +29,7 @@ }, { "cell_type": "markdown", - "id": "03885993-f11d-4c46-91a3-6a45f27ba48d", + "id": "2", "metadata": {}, "source": [ "## Using the Contamination and Visibility Tool\n", @@ -42,7 +42,7 @@ { "cell_type": "code", "execution_count": null, - "id": "963f2c9e-9571-4a41-a47f-0fe3dc767f9f", + "id": "3", "metadata": {}, "outputs": [], "source": [ @@ -54,7 +54,7 @@ }, { "cell_type": "markdown", - "id": "c02e56b2-85d6-4955-8808-c4aae8abdfdc", + "id": "4", "metadata": {}, "source": [ "Next we can calculate the contamination for a given instrument at a given PA. PA values can range from (0, 360) and supported subarrays currently include 'NIS_SUBSTRIP256' and 'NIS_SUBSTRIP96'." @@ -63,7 +63,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ade498f1-fb71-44a6-a18d-c6da06c97189", + "id": "5", "metadata": {}, "outputs": [], "source": [ @@ -78,7 +78,7 @@ }, { "cell_type": "markdown", - "id": "17eec029-69f4-44c2-a378-10cb85dcf512", + "id": "6", "metadata": {}, "source": [ "In the top plot, the red lines indicate stars and the pink lines indicate extended sources. The solid lines indicate the target traces and the dashed lines indicate contaminant traces. The circles indicate 0th order contaminant traces. Hover over any glyph to see more information about the source.\n", @@ -92,7 +92,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d9febedf-fcd4-46c4-9d16-3ba04ff58341", + "id": "7", "metadata": {}, "outputs": [], "source": [ @@ -103,7 +103,7 @@ { "cell_type": "code", "execution_count": null, - "id": "2d440f82-2df6-46ba-8154-79e8cfae278c", + "id": "8", "metadata": {}, "outputs": [], "source": [ @@ -121,7 +121,7 @@ }, { "cell_type": "markdown", - "id": "1f347b68-2c76-4245-8aa5-9ccccb2ed718", + "id": "9", "metadata": {}, "source": [ "### Explore contamination for all valid position angles\n", @@ -131,7 +131,7 @@ { "cell_type": "code", "execution_count": null, - "id": "2f590d2e-4199-4b0e-a297-d7f3ecbf07a6", + "id": "10", "metadata": {}, "outputs": [], "source": [ @@ -141,7 +141,7 @@ }, { "cell_type": "markdown", - "id": "398ab0fd-7c6a-4bce-8fcb-5834a90ff970", + "id": "11", "metadata": {}, "source": [ "## Validation Tests\n", @@ -150,7 +150,7 @@ }, { "cell_type": "markdown", - "id": "9726b720-7084-4ff9-9f62-3507d2d072e0", + "id": "12", "metadata": {}, "source": [ "### Download the data\n", @@ -160,7 +160,7 @@ { "cell_type": "code", "execution_count": null, - "id": "64ba55e4-906f-4ba4-bda3-c4baacd8632a", + "id": "13", "metadata": {}, "outputs": [], "source": [ @@ -182,7 +182,7 @@ }, { "cell_type": "markdown", - "id": "acc5b684-6cda-499f-bc88-4a46109f4808", + "id": "14", "metadata": {}, "source": [ "### Load the data into the session\n", @@ -192,7 +192,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f0fc7bae-b1e4-4086-ba93-43b49be1e80c", + "id": "15", "metadata": {}, "outputs": [], "source": [ @@ -207,7 +207,7 @@ }, { "cell_type": "markdown", - "id": "2f34e256-bd9e-49a5-a341-d2a5b821b2db", + "id": "16", "metadata": {}, "source": [ "### Find all nearby sources\n", @@ -217,7 +217,7 @@ { "cell_type": "code", "execution_count": null, - "id": "b5fba590-8964-4992-a150-65d342991572", + "id": "17", "metadata": {}, "outputs": [], "source": [ @@ -227,7 +227,7 @@ }, { "cell_type": "markdown", - "id": "d92af0ff-920a-469b-8217-1a3b24242524", + "id": "18", "metadata": {}, "source": [ "### Run the Contamination and Visibility Tool\n", @@ -237,7 +237,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c9c5255f-2ab1-4c37-a992-1ef95546a244", + "id": "19", "metadata": {}, "outputs": [], "source": [ @@ -251,7 +251,7 @@ { "cell_type": "code", "execution_count": null, - "id": "cc62fc83-48fe-4ed3-8e57-7d0730974cea", + "id": "20", "metadata": {}, "outputs": [], "source": [ @@ -265,7 +265,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d8134c6f-3c7d-43b3-bb4a-624d98725deb", + "id": "21", "metadata": {}, "outputs": [], "source": [] From f71fb8558a027398ae536c6a8defb2335b575441 Mon Sep 17 00:00:00 2001 From: Joe Filippazzo Date: Fri, 8 Aug 2025 17:01:32 -0400 Subject: [PATCH 2/3] Added order 0 trace library and code to choose closest Teff --- exoctk/contam_visibility/field_simulator.py | 41 +++++++++++++++------ 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/exoctk/contam_visibility/field_simulator.py b/exoctk/contam_visibility/field_simulator.py index 472e461d1..e795b180a 100755 --- a/exoctk/contam_visibility/field_simulator.py +++ b/exoctk/contam_visibility/field_simulator.py @@ -700,9 +700,6 @@ def calc_v3pa(V3PA, stars, aperture, data=None, tilt=0, plot=False, verbose=Fals targframes = [np.zeros((subY, subX))] * n_traces starframe = np.zeros((subY, subX)) - # Get order 0 - order0 = get_order0(aperture.AperName) * 1.5e8 # Scaling factor based on observations - # Get trace masks trace_masks = NIRCam_DHS_trace_mask(aperture.AperName) if 'NRCA5' in aperture.AperName else NIRISS_SOSS_trace_mask(aperture.AperName) @@ -726,6 +723,9 @@ def calc_v3pa(V3PA, stars, aperture, data=None, tilt=0, plot=False, verbose=Fals # Add all orders to the same frame (if it is a STAR) else: + # Get correct order 0 + order0 = get_order0(aperture.AperName, star['Teff'], stype=star['type']) * 1.5e4 # Scaling factor based on observations + # Scale the order 0 image and add it to the starframe scale0 = copy(order0) * star['fluxscale'] * aper['empirical_scale'][0] starframe = add_array_at_position(starframe, scale0, int(star['xord0'] - aper['subarr_x'][0]), int(star['yord0'] - aper['subarr_y'][1]), centered=True) @@ -1197,7 +1197,7 @@ def contam_slider_plot(contam_results, threshold=0.05, plot=False): return layout -def get_order0(aperture): +def get_order0(aperture, teff, stype='STAR', verbose=False): """Get the order 0 image for the given aperture Parameters @@ -1210,15 +1210,34 @@ def get_order0(aperture): np.ndarray The 2D order 0 image """ - # Get file - # TODO: Add order 0 files for other modes - filename = 'NIS_order0.npy' if 'NIS' in aperture else 'NIS_order0.npy' + if 'DHS' in aperture: + trace = np.zeros((50,50)) + else: - # Get the path to the trace files - trace_path = os.path.join(os.environ['EXOCTK_DATA'], f'exoctk_contam/order0/{filename}') + if stype == 'STAR': + + # Get the path to the trace files + traces_path = os.path.join(os.environ['EXOCTK_DATA'], f'exoctk_contam/order0/NIS_order0_*.npy') + + # Glob the file names + trace_files = glob.glob(traces_path) + + # Get closest Teff + teffs = np.array([int(os.path.basename(file).split('_')[-1][:-4]) for file in trace_files]) + trace_file = trace_files[np.argmin((teffs - teff)**2)] + if verbose: + print(f'Fetching {aperture} {teffs[np.argmin((teffs - teff)**2)]}K trace from {trace_file}') + + # Make frame + trace = np.load(trace_file) + + else: - # Make frame - trace = np.load(trace_path) + # Get stand-in for galaxy order 0 + gal_path = os.path.join(os.environ['EXOCTK_DATA'], f'exoctk_contam/order0/NIS_gal_order0.npy') + if verbose: + print('Fetching {} galaxy trace from {}'.format(aperture, gal_path)) + trace = np.load(gal_path) return trace From f8c2dfd0c169870d400a8cf88c6440da5767079f Mon Sep 17 00:00:00 2001 From: Joe Filippazzo Date: Thu, 14 Aug 2025 15:04:40 -0400 Subject: [PATCH 3/3] Updated scaling for order 0s --- exoctk/contam_visibility/field_simulator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exoctk/contam_visibility/field_simulator.py b/exoctk/contam_visibility/field_simulator.py index e795b180a..8dd35359c 100755 --- a/exoctk/contam_visibility/field_simulator.py +++ b/exoctk/contam_visibility/field_simulator.py @@ -724,7 +724,7 @@ def calc_v3pa(V3PA, stars, aperture, data=None, tilt=0, plot=False, verbose=Fals else: # Get correct order 0 - order0 = get_order0(aperture.AperName, star['Teff'], stype=star['type']) * 1.5e4 # Scaling factor based on observations + order0 = get_order0(aperture.AperName, star['Teff'], stype=star['type'], verbose=verbose) * 1.5e3 # Scaling factor based on observations # Scale the order 0 image and add it to the starframe scale0 = copy(order0) * star['fluxscale'] * aper['empirical_scale'][0]