Skip to content

Commit

Permalink
Merge pull request #66 from eunkyuh/pandeia
Browse files Browse the repository at this point in the history
Updating the pandeia notebook
  • Loading branch information
tddesjardins authored Dec 16, 2024
2 parents f862b3c + a0728aa commit 3de2201
Showing 1 changed file with 180 additions and 46 deletions.
226 changes: 180 additions & 46 deletions content/notebooks/pandeia/pandeia.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "b96c3c70-16d1-4349-8904-00f3828d4f79",
"metadata": {},
"outputs": [],
Expand All @@ -74,7 +74,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "eb47af89-3fc1-4984-b28a-06e0edf6cee4",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -105,14 +105,14 @@
"source": [
"### Calculate a Scene's Signal-to-Noise Ratio\n",
"\n",
"In this first example, we calculate the expected SNR for a point source with a flat spectral distribution (default target) normalized to 25 AB magnitudes. We take three exposures in band F129 with the multi-accumulation (MA) table \"High Latitude Wide Area Survey - Imaging\", truncated after 5 resultants (91.20 seconds of total exposure time). MA tables describe the sequence of individual reads that are combined into resultants and comprise the up-the-ramp sampling during a single exposure of the WFI detectors. For more information on the WFI MA tables, please refer to the [RDox documentation](https://roman-docs.stsci.edu/raug/astronomers-proposal-tool-apt/appendix/appendix-wfi-multiaccum-tables).\n",
"In this first example, we calculate the expected SNR for a point source with a flat spectral distribution (default target) normalized to 25 AB magnitudes. We place the source on Detector #1 (internally: SCA01) and take three exposures in band F129 with the multi-accumulation (MA) table \"c2a_img_hlwas\", truncated after 9 resultants (407.96 seconds of total exposure time). MA tables describe the sequence of individual reads that are combined into resultants and comprise the up-the-ramp sampling during a single exposure of the WFI detectors. For more information on the WFI detectors, please refer to the RDox documentation on [WFI](https://roman-docs.stsci.edu/roman-instruments-home/wfi-imaging-mode-user-guide/wfi-design/description-of-wfi) and for the MA tables, please refer to the RDox documentation on [MA tables](https://roman-docs.stsci.edu/raug/astronomers-proposal-tool-apt/appendix/appendix-wfi-multiaccum-tables).\n",
"\n",
"We first create a default calculation using Pandeia's built-in function `build_default_calc(<telescope>, <instrument>, <mode>)`: "
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "41bf5746-e8c1-41ee-8f64-9af598d13022",
"metadata": {},
"outputs": [],
Expand All @@ -128,12 +128,6 @@
"Let's take a look at how the default calculation is set up:"
]
},
{
"cell_type": "markdown",
"id": "db27d9f0",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -149,18 +143,19 @@
"id": "013b4561",
"metadata": {},
"source": [
"The `build_default_calc` created a scene with a single point source to observe with F087 filter, High Latitude Wide Area Survey - Imaging (hlwas_imaging) MA table, truncated after 5 resultants, and with a single exposure. With the WFI, an exposure refers to a single multi-accum sequence of the detector array at a single dither point in the dither pattern. Next, we define the observing setup and make some changes to the default setting:"
"The `build_default_calc` created a scene with a single point source to observe with SCA01, F158 filter, \"c2a_img_hlwas\" MA table, with no truncatation, and with a single exposure. With the WFI, an exposure refers to a single multi-accum sequence of the detector array at a single dither point in the dither pattern. Next, we define the observing setup and make some changes to the default setting:"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "d5cdd524",
"metadata": {},
"outputs": [],
"source": [
"calc['configuration']['instrument']['filter'] = FILTER # Setting the filter to F129\n",
"calc['configuration']['detector']['nexp'] = 3 # Taking three exposures of multi-accum sequence"
"calc['configuration']['detector']['nexp'] = 3 # Taking three exposures of multi-accum sequence\n",
"calc['configuration']['detector']['nresultants'] = 9 # Truncate after 9 resultant"
]
},
{
Expand All @@ -173,7 +168,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "d4a78b80-ce4f-4840-9a28-1426b9bb5925",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -216,19 +211,37 @@
},
{
"cell_type": "markdown",
"id": "ca56cbc7-ade0-4cc3-8e21-81a2c1b4edf9",
"id": "d61559f5-68b1-40f3-8f80-7edab8f332bb",
"metadata": {},
"source": [
"### Calculate Corresponding Magnitude for a Given Setup\n",
"### Calculating Magnitude and Optimizing Exposures for Roman WFI Simulations\n",
"\n",
"In this example, we are interested in understanding the corresponding magnitude for a given SNR and for a specific observing setup.\n",
"For the next example, we begin by determining the corresponding magnitude for a given signal-to-noise ratio (SNR) and setup parameters. Next, we extend this analysis to calculate the optimal number of exposures required to reach a target SNR for a given source flux.\n",
"\n",
"The following helper functions use Pandeia to simulate a range of scenes at different magnitudes in order to estimate the corresponding magnitude for a given SNR and a number of exposures. As above, we assume a point source with a flat spectrum, and the MA table is set to the \"High Latitude Wide Area Survey - Imaging\" table with 5 resultants."
"The following helper functions use Pandeia to simulate a range of scenes at different magnitudes in order to estimate the corresponding magnitude for a given SNR and a number of exposures. As above, we assume a point source with a flat spectrum, and the MA table is set to the \"c2a_img_hlwas\" table but this time without any truncation."
]
},
{
"cell_type": "markdown",
"id": "81aa2576-4638-481b-9978-bf96cd285b10",
"metadata": {},
"source": [
"#### Step 1: Calculating Corresponding Magnitude for a Given Setup\n",
"\n",
"In the first step, we estimate the limiting magnitude for a point source at a desired SNR. This involves iterating over a range of magnitudes, computing the SNR for each, and interpolating the results to determine the magnitude corresponding to the target SNR. The observing parameters include the number of exposures and a specified filter.\n",
"\n",
"Example Use Case:\n",
"\n",
"SNR = <span style=\"color:red\">5</p>\n",
"\n",
"Number of exposures = <span style=\"color:red\">10</p>\n",
"\n",
"Filter = <span style=\"color:red\">F129</p>"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"id": "e6e68758-cef5-471b-89f1-0877c1d64b26",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -299,17 +312,6 @@
" return mag"
]
},
{
"cell_type": "markdown",
"id": "da7050ff-9bda-44a7-b2d7-5f7bf13716fc",
"metadata": {},
"source": [
"For example, we can use the helper functions to calculate the limiting magnitude corresponding to SNR = 5 and the following observing setup:\n",
"\n",
"- Number of exposures: 10\n",
"- Filter: F129 (defined earlier)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -328,19 +330,26 @@
},
{
"cell_type": "markdown",
"id": "0a547b7c-34d7-4b83-be71-977700f6e244",
"id": "d0d5a005-0cec-4288-9602-38e328e432d0",
"metadata": {},
"source": [
"### Determine Optimal Number of Exposures\n",
"#### Step 2: Determining Optimal Number of Exposures\n",
"With the magnitude determined, we then calculate the optimal number of exposures required to achieve a specified SNR for a known flux. This is done by simulating observations with varying numbers of exposures, identifying the minimum exposure count necessary to meet or exceed the target SNR. This ensures efficient use of telescope time while maintaining data quality.\n",
"\n",
"The following helper functions use Pandeia to simulate a range of scenes with different numbers of exposures in order to estimate the optimal observing time to reach the expected limiting magnitude for a source with a given flux. As above, we assume a point source with a flat spetrum, and the MA table is set to the \"c2a_img_hlwas\" table, truncated to 8 resultants.\n",
"\n",
"Now, let's assume that we want to reach a specific SNR when observing a target of known flux, and ask how many exposures we should take of the default MA table.\n",
"Example Use Case:\n",
"\n",
"The following helper functions use Pandeia to simulate a range of scenes with different numbers of exposures in order to estimate the optimal observing time to reach the expected limiting magnitude for a source with a given flux. As above, we assume a point source with a flat spetrum, and the MA table is set to the \"High Latitude Wide Area Survey - Imaging\" table, truncated to 5 resultants."
"SNR = <span style=\"color:red\">20</span>\n",
"\n",
"Magnitude = <span style=\"color:red\">26.84</span> (calculated from above, or known)\n",
"\n",
"Filter = <span style=\"color:red\">F129</span>"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"id": "b363d0f3-a2f6-4953-b4cd-f90872639cce",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -406,6 +415,7 @@
" # Check that the minimum of 1 exposure has a S/N lower than requested,\n",
" # otherwise there is no sense in attempting to minimize nexp.\n",
" calc['configuration']['detector']['nexp'] = 1\n",
" calc['configuration']['detector']['nresultants'] = 8\n",
" report = perform_calculation(calc)\n",
" \n",
" if report['scalar']['sn'] > sn:\n",
Expand Down Expand Up @@ -439,7 +449,7 @@
"id": "7687c324-debf-41b9-a586-8bc1d17696a3",
"metadata": {},
"source": [
"For example, we can use the functions above to determine the optimal number of exposures to reach a SNR of 20 when observing a point source of magnitude 26 in the F129 band:"
"For example, we can use the functions above to determine the optimal number of exposures to reach a SNR of 20 when observing a point source of magnitude 26.84 in the F129 band:"
]
},
{
Expand All @@ -450,7 +460,7 @@
"outputs": [],
"source": [
"sn = 20.\n",
"mag = 26.\n",
"mag = 26.84\n",
" \n",
"nexp, etc, exptime = compute_nexp(FILTER, sn, mag)\n",
"print(f'number of exposures: {nexp}')\n",
Expand All @@ -465,12 +475,12 @@
"source": [
"### Modifying the Spectral Energy Distribution\n",
"\n",
"While previous examples assume a point source with a flat SED, Pandeia also offers the ability to use a a variety of different shapes and spectral inputs. In the example below, we calculate the SNR for an A0V star (Phoenix model) of magnitude 25 AB, observed in the F129 band, with 3 exposures of the default MA table (\"High Latitude Wide Area Survey - Imaging\", truncated to 5 resultants). For more information on how to implement complex scenes with a variety of shapes and SEDs, please refer to the [JWST Tutorials](https://jwst-docs.stsci.edu/jwst-exposure-time-calculator-overview/jwst-etc-pandeia-engine-tutorial/pandeia-quickstart#PandeiaQuickstart-Samplecode)."
"While previous examples assume a point source with a flat SED, Pandeia also offers the ability to use a a variety of different shapes and spectral inputs. In the example below, we calculate the SNR for an A0V star (Phoenix model) of magnitude 25 AB, observed in the F129 band, with 3 exposures of the default MA table (\"c2a_img_hlwas\", with no truncation). For more information on how to implement complex scenes with a variety of shapes and SEDs, please refer to the [JWST Tutorials](https://jwst-docs.stsci.edu/jwst-exposure-time-calculator-overview/jwst-etc-pandeia-engine-tutorial/pandeia-quickstart#PandeiaQuickstart-Samplecode)."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"id": "26569041-1670-4285-ab13-3a837523b078",
"metadata": {},
"outputs": [],
Expand All @@ -484,7 +494,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"id": "95a2da69-828a-4e0f-9c79-10de708b2f5e",
"metadata": {},
"outputs": [],
Expand All @@ -511,8 +521,132 @@
},
{
"cell_type": "markdown",
"id": "f3b4f34e-6dab-4d83-8f0e-0dc900c0e2b6",
"id": "33e9c5ee-f41c-4fc0-a9ea-ce4344c1b116",
"metadata": {},
"source": [
"### Observing NGC2506-G31 with Roman WFI\n",
"\n",
"In this example, we show a real science case using NGC2506-G31, a G1V standard star that is used as a cross-mission calibration standard for both JWST and HST observations. We would like to see if Roman can observe the same star and if so, with which observing setup. We are interested in placing the star on SCA11. "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8222af0a-127e-4acd-9214-296f2f93e05c",
"metadata": {},
"outputs": [],
"source": [
"calc = build_default_calc('roman', 'wfi', 'imaging') # Creating a default calculation using Roman's WFI with an imaing mode\n",
"\n",
"calc['configuration']['instrument']['filter'] = FILTER # Setting the filter to F129\n",
"calc['configuration']['instrument']['detector'] = 'sca11' # Setting the detector fo SCA11\n",
"calc['configuration']['detector']['nexp'] = 1 # Taking one exposure of multi-accum sequence\n",
"\n",
"calc['configuration']['detector']['ma_table_name'] = 'c2a_img_hlwas' # Using the default MA table\n",
"calc['configuration']['detector']['nresultants'] = -1 # No truncation of the MA table\n",
"\n",
"\n",
"# Setting up the source SED\n",
"calc['scene'][0]['spectrum']['sed']['sed_type'] = 'phoenix'\n",
"calc['scene'][0]['spectrum']['sed']['key'] = 'g2v' # Using the closest spectral type available to G1V\n",
"\n",
"\n",
"# Setting up the normalization parameters\n",
"calc['scene'][0]['spectrum']['normalization']['type'] = 'photsys'\n",
"calc['scene'][0]['spectrum']['normalization']['norm_flux'] = 16.260 # K-band magnitude of the source\n",
"calc['scene'][0]['spectrum']['normalization']['norm_fluxunit'] = 'vegamag'\n",
"calc['scene'][0]['spectrum']['normalization']['bandpass'] = '2mass,ks'\n",
"\n",
"\n",
"# Run the calculation\n",
"report = perform_calculation(calc)"
]
},
{
"cell_type": "markdown",
"id": "b9c01070-2eed-4e3c-8d92-70c749726232",
"metadata": {},
"source": [
"With the calculation ran, we would like to check to see if there are any warning messages from the report. You can access the warnings through the the \"warnings\" dictionary. "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8caa3387-f783-46c8-b5b4-5ccf4b781197",
"metadata": {},
"outputs": [],
"source": [
"print(report['warnings'])"
]
},
{
"cell_type": "markdown",
"id": "49d23740-edb9-4cd9-9713-65a842c79d0a",
"metadata": {},
"source": [
"We see that there is a pixel that is partially saturated. If you are concerned that there is a partially saturated pixel, you can check the report to see what the maximum number of resultants is to avoid having the brighest pixel on the detector getting saturated. You can access this information through the \"sat_nresultants\" key within the \"scalar\" dictionary."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "18beff8e-083e-4aec-917a-eff5e7bf0c6a",
"metadata": {},
"outputs": [],
"source": [
"print(report['scalar']['sat_nresultants'])"
]
},
{
"cell_type": "markdown",
"id": "d0ba4335-57bb-444b-94b3-bb3afda85a06",
"metadata": {},
"source": [
"Let's check manually that it indeed is nresultant=5. The maximum nresultant for \"c2a_img_hlwas\" MA table is 10 and we will calculate backward, from no truncation to incremented truncation. "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6f050b9e-ddf1-40cc-b1c5-dbb388b102f4",
"metadata": {},
"outputs": [],
"source": [
"for n in reversed(range(10)):\n",
" # Check to see if there is any warning message about the saturation (both partial and full)\n",
" # Stop the loop if the saturation warning no longer exists\n",
" # Adding 1 for the resultant because python indexing starts with 0. \n",
" resultant = n + 1\n",
" calc['configuration']['detector']['nresultants'] = resultant\n",
" report = perform_calculation(calc)\n",
" partial = report['warnings'].get('partial_saturated')\n",
" full = report['warnings'].get('full_saturated')\n",
"\n",
" if (partial == None) and (full == None):\n",
" nresultant = resultant\n",
" print(f'No saturation happens with resultant {nresultant}')\n",
" break"
]
},
{
"cell_type": "markdown",
"id": "81bcdfa5-3bc8-4677-a05c-2053411a7fab",
"metadata": {},
"source": [
"The answer turns out to be 5 indeed. \n",
"\n",
"Although we know the actual coordinate of this star, Pandeia engine does not support a simulation at a specific location or time\n",
"as the engine comes with 7 canned backgrounds at 2 different locations (see the JDox on the [Pandeia backgrounds](https://jwst-docs.stsci.edu/jwst-exposure-time-calculator-overview/jwst-etc-pandeia-engine-tutorial/pandeia-backgrounds#gsc.tab=0) for more details). If you would like to see how the SNR changes with time at the specific location of this star, you have to use the web application of the ETC that is available at the [Roman WFI ETC](roman.etc.stsci.edu).\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "f3b4f34e-6dab-4d83-8f0e-0dc900c0e2b6",
"metadata": {
"jp-MarkdownHeadingCollapsed": true
},
"source": [
"## Additional Resources\n",
"\n",
Expand All @@ -533,8 +667,8 @@
"source": [
"## About this notebook\n",
"\n",
"**Author:** Justin Otor, Eunkyu Han \n",
"**Updated On:** 2024-09"
"**Author:** Justin Otor, Eunkyu Han, Harish Khandrika \n",
"**Updated On:** 2024-12"
]
},
{
Expand All @@ -557,9 +691,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Roman Calibration latest (2024-03-25)",
"display_name": "pandeia_dev",
"language": "python",
"name": "roman-cal"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -571,7 +705,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.11.3"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 3de2201

Please sign in to comment.