From c86e846dfa720e77b3e5988085a2828d33559439 Mon Sep 17 00:00:00 2001
From: "M.Gough" <60232355+mgough-970@users.noreply.github.com>
Date: Tue, 24 Oct 2023 15:12:17 -0400
Subject: [PATCH] Delete notebooks/WFC3/photometry_examples/.ipynb_checkpoints
directory
---
.../phot_examples-checkpoint.ipynb | 878 ------------------
1 file changed, 878 deletions(-)
delete mode 100644 notebooks/WFC3/photometry_examples/.ipynb_checkpoints/phot_examples-checkpoint.ipynb
diff --git a/notebooks/WFC3/photometry_examples/.ipynb_checkpoints/phot_examples-checkpoint.ipynb b/notebooks/WFC3/photometry_examples/.ipynb_checkpoints/phot_examples-checkpoint.ipynb
deleted file mode 100644
index f9e4f12d3..000000000
--- a/notebooks/WFC3/photometry_examples/.ipynb_checkpoints/phot_examples-checkpoint.ipynb
+++ /dev/null
@@ -1,878 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "markdown",
- "id": "3417f03b",
- "metadata": {},
- "source": [
- "\n",
- "# Synthetic Photometry Examples for WFC3\n",
- "***\n",
- "## Learning Goals\n",
- "\n",
- "By the end of this tutorial, you will:\n",
- "\n",
- "- Specify WFC3 bandpasses in `stsynphot` and define spectra with `synphot`.\n",
- "- Compute WFC3 zeropoint values and an encircled energy correction.\n",
- "- Renormalize a spectrum and predict its effective stimulus in another filter.\n",
- "- Find the photometric transformation between two bandpasses.\n",
- "- Find the UV color term across the two UVIS chips for different spectral types.\n",
- "- Plot bandpasses and spectra.\n",
- "\n",
- "## Table of Contents\n",
- "\n",
- "[Introduction](#intro)
\n",
- "[1. Imports](#imports)
\n",
- "[2. Bandpasses and spectra](#band_spec)
\n",
- "- [2.1 Set up bandpasses](#band)
\n",
- "- [2.2 Define spectra](#spec)
\n",
- "\n",
- "[3. Examples](#ex)
\n",
- "- [Example 1a: Compute the inverse sensitivity and zeropoint](#e1)
\n",
- "- [Example 1b: Compute an encircled energy correction](#e1b)
\n",
- "- [Example 2: Renormalize a spectrum and predict its effective stimulus in another filter](#e2)
\n",
- "- [Example 3: Find the photometric transformation between two bandpasses](#e3)
\n",
- "- [Example 4a: Find the UV color term across the two UVIS chips for different spectral types](#e4)
\n",
- "- [Example 4b: Plot bandpasses and spectra](#e4b)\n",
- "\n",
- "[4. Conclusions](#conclusion)
\n",
- "[Additional Resources](#resources)
\n",
- "[About the Notebook](#about)
\n",
- "[Citations](#cite)
"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "b3415f46",
- "metadata": {},
- "source": [
- "\n",
- "## Introduction\n",
- "\n",
- "This notebook contains several examples of how to use the `synphot` and `stsynphot` modules for various photometric purposes. \n",
- "\n",
- "`synphot` is a Python module that facilitates synthetic photometry, which has an extension module called `stsynphot` to add support for STScI missions. `synphot` is meant to be a replacement for AstroLib `pysynphot`. \n",
- "\n",
- "Examples 1, 2, and 3 are based on those found in Section 9.1.10 of the 2018 version of the WFC3 Data Handbook. \n",
- "\n",
- "`stsynphot` requires access to data distributed by the [Calibration Data Reference System](https://hst-crds.stsci.edu/) (CRDS) in order to operate. Both packages look for an environment variable called `PYSYN_CDBS` to find the directory containing these data.\n",
- "\n",
- "Users can obtain these data files from the CDRS. Information on how to obtain the most up-to-date reference files (and what they contain) can be found [here](https://www.stsci.edu/hst/instrumentation/reference-data-for-calibration-and-tools/synphot-throughput-tables). An example of how to download the files with `curl` and set up this environment variable is presented below.\n",
- "\n",
- "For detailed instructions on how to install and set up these packages, see the [synphot](https://synphot.readthedocs.io/en/latest/#installation-and-setup) and [stsynphot](https://stsynphot.readthedocs.io/en/latest/#installation-and-setup) documentation."
- ]
- },
- {
- "cell_type": "markdown",
- "id": "f4d1218e",
- "metadata": {},
- "source": [
- "\n",
- "## 1. Imports\n",
- "\n",
- "This notebook assumes you have created the virtual environment in [WFC3 Library's](https://github.com/spacetelescope/WFC3Library) installation instructions.\n",
- "\n",
- "We import:\n",
- "- *os* for setting environment variables\n",
- "\n",
- "- *numpy* for handling array functions\n",
- "- *pandas* for managing data\n",
- "- *matplotlib.pyplot* for plotting data\n",
- "\n",
- "- *synphot* and *stsynphot* for evaluating synthetic photometry\n",
- "- *astropy.units* and *synphot.units* for handling units\n",
- "\n",
- "Additionally, we will need to set the `PYSYN_CDBS` environment variable *before* importing stsynphot. We will also create a Vega spectrum using synphot's inbuilt `from_vega()` method, as the latter package will supercede this method's functionality and require a downloaded copy of the latest Vega spectrum to be provided."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "83593365",
- "metadata": {},
- "outputs": [],
- "source": [
- "%matplotlib notebook\n",
- "\n",
- "import os\n",
- "\n",
- "import numpy as np\n",
- "import pandas as pd\n",
- "import matplotlib.pyplot as plt\n",
- "\n",
- "import synphot as syn\n",
- "\n",
- "from astropy import units as u\n",
- "from synphot import units as su\n",
- "\n",
- "vegaspec = syn.SourceSpectrum.from_vega()"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "06d98189",
- "metadata": {},
- "source": [
- "This section obtains the WFC3 throughput component tables for use with `synphot`. If reference files need to be downloaded, please uncomment and execute the code block below."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "10709b0c",
- "metadata": {},
- "outputs": [],
- "source": [
- "# cmd_input = 'curl -O https://ssb.stsci.edu/trds/tarfiles/synphot1.tar.gz'\n",
- "# os.system(cmd_input)"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "054629f8",
- "metadata": {},
- "source": [
- "Once the downloaded is complete, unzip the file and set the environment variable `PYSYN_CDBS` to the path of the reference files. To do so, uncomment and execute the relevant line from the code block below. "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "162bc0c7",
- "metadata": {},
- "outputs": [],
- "source": [
- "# os.environ['PYSYN_CDBS'] = '/path/to/my/reference/files/'"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "ebbed337",
- "metadata": {},
- "source": [
- "Now, after having set up `PYSYN_CDBS`, we import stsynphot."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "487dd24c",
- "metadata": {},
- "outputs": [],
- "source": [
- "import stsynphot as stsyn"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "7f8346b2",
- "metadata": {},
- "source": [
- "## 2. Bandpasses and spectra \n",
- "\n",
- "### 2.1 Set up bandpasses \n",
- "\n",
- "All of the examples below require us to define a bandpass. Bandpasses are defined in `stsynphot` using a string of comma-separated keywords that represents a particular observation mode (obsmode). For WFC3, an obsmode string will, at minimum, look something like: `\"wfc3, [detector], [filter]\"`. E.g. `\"wfc3, uvis1, f606w\"` will get you the bandpass for the F606W filter on WFC3's UVIS1 detector. One may also specify an aperture size in arcseconds with `aper#value` and a Modified Julian Date (to account for time-dependent changes in the UVIS detector sensitivity) with `mjd#value`.\n",
- "\n",
- "The documentation [here](https://stsynphot.readthedocs.io/en/latest/stsynphot/obsmode.html) provides a further overview of how to construct an observation mode, and includes a link to the full set of available obsmode keywords.\n",
- "\n",
- "### 2.2 Define spectra \n",
- "\n",
- "Examples 2-4 require us to define a spectrum. Examples for generating some commonly useful spectra using `synphot` are embedded here:\n",
- "\n",
- "\n",
- "```python\n",
- "# Blackbody\n",
- "bb_temp = 5800 * u.K\n",
- "\n",
- "model = syn.models.BlackBody1D(bb_temp)\n",
- "spec = syn.SourceSpectrum(model)\n",
- "\n",
- "# Power law \n",
- "pl_index = 0\n",
- "\n",
- "model = syn.models.PowerLawFlux1D(amplitude=flux_in, x_0=wl_in, alpha=pl_index)\n",
- "spec = syn.SourceSpectrum(model)\n",
- " \n",
- "# Load from a FITS table (e.g. a CALSPEC spectrum)\n",
- "spec = syn.SourceSpectrum.from_file('/path/to/your/spectrum.fits')\n",
- "```\n",
- "\n",
- "Note:\n",
- "\n",
- "- `synphot.models.BlackBody1D` outputs a function according to Planck's law, which means that the output unit carries an *implicit* \"per unit solid angle,\" in steradians. `BlackBodyNorm1D`, outputs a spectrum that is normalized to a 1 solar radius star at a distance of 1 kpc.\n",
- "\n",
- "- `synphot.models.PowerLawFlux1D` uses the definition $ f(x) = A (\\frac{x}{x_0})^{-\\alpha} $. We pass `flux_in` as $A$, and `wl_in` as $x_0$. Note the negative sign in front of the power law index $\\alpha$. The model can generate curves with $x$ as either frequency or wavelength, but the example here assumes that wavelength will be used. The y-axis unit will be taken from $A$. \n",
- "\n",
- "- A wide array of reference spectra are available for download from spectral atlases located [here](https://www.stsci.edu/hst/instrumentation/reference-data-for-calibration-and-tools/astronomical-catalogs)."
- ]
- },
- {
- "cell_type": "markdown",
- "id": "aec1c476",
- "metadata": {},
- "source": [
- "\n",
- "## 3. Examples\n",
- "\n",
- "\n",
- "### Example 1a: Compute the inverse sensitivity and zeropoint \n",
- "**Compute inverse sensitivity (PHOTFLAM) and zeropoint values (STmag, ABmag, and Vegamag) for F814W on UVIS1 in an infinite (6.0”) aperture.**\n",
- "\n",
- "This example should reproduce the values found in Table 6 of [WFC3 ISR 2021-04](https://www.stsci.edu/files/live/sites/www/files/home/hst/instrumentation/wfc3/documentation/instrument-science-reports-isrs/_documents/2021/WFC3_ISR_2021-04.pdf), the relevant row of which is reproduced here:\n",
- "\n",
- "| Filter \t| Pivot Wavelength \t| PHOTFLAM \t| STMAG \t| ABMAG \t| VEGAMAG \t|\n",
- "|:--------\t|:-----------------\t|:------------\t|:--------\t|:--------\t|:---------\t|\n",
- "| F814W \t| 8039.1 Å \t| 1.4980e-19 \t| 25.961 \t| 25.127 \t| 24.699 \t|\n",
- "\n",
- "We include the keywords `'aper#6.0'` and `'mjd#55008'` in our obsmode string to match the aperture and reference epoch used for the calculations in this ISR.\n",
- "\n",
- "The WFC3 Zeropoints notebook, which can be found in the [WFC3 Library](https://github.com/spacetelescope/WFC3Library), contains an example to perform this calculation iteratively over all UVIS and IR bandpasses and to compute 'total system throughput tables' for each mode."
- ]
- },
- {
- "cell_type": "markdown",
- "id": "548ec9aa",
- "metadata": {},
- "source": [
- "First, we set up a bandpass based on our observation mode. "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "3b24c5f6",
- "metadata": {},
- "outputs": [],
- "source": [
- "obsmode = 'wfc3, uvis1, f814w, aper#6.0, mjd#55008'\n",
- "bp = stsyn.band(obsmode)"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "6ac74915",
- "metadata": {},
- "source": [
- "Then, we can find the unit response for the bandpass, which is the flux (in $\\text{erg } \\text{cm}^{-2} \\text{ s}^{-1} \\text{ Å}^{-1}$, aka FLAM) that produces 1 electron per second. For this calculation, we must pass the HST primary mirror area. "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "47c807c9",
- "metadata": {},
- "outputs": [],
- "source": [
- "uresp = bp.unit_response(stsyn.conf.area)"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "af7d302f",
- "metadata": {},
- "source": [
- "Next, we convert the unit response to magnitudes in the ST and AB systems. For the AB conversion, we need the bandpass pivot wavelength."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "5729fe90",
- "metadata": {},
- "outputs": [],
- "source": [
- "st = -2.5 * np.log10(uresp.value) - 21.1 \n",
- "\n",
- "pivot = bp.pivot() # Pivot wavelength for ABmag conversion\n",
- "ab = st - 5 * np.log10(pivot.value) + 18.6921"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "c7850a3c",
- "metadata": {},
- "source": [
- "Converting the unit response for the bandpass to the vegamag system requires us to generate a synthetic Observation, which consists of Vega's spectrum convolved with the bandpass."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "9df9b9ee",
- "metadata": {},
- "outputs": [],
- "source": [
- "obs = syn.Observation(vegaspec, bp, binset=bp.binset)\n",
- "effstim = obs.effstim(flux_unit=su.FLAM) # Effective stimulus for Vega observation\n",
- "ve = -2.5 * np.log10(uresp/effstim) # vegamag sensitivity value"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "540cfe18",
- "metadata": {},
- "source": [
- "Now, we can print our results."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "68ab0876",
- "metadata": {},
- "outputs": [],
- "source": [
- "print('Obsmode:', obsmode)\n",
- "print('Pivot Wavelength: {:.1f}'.format(pivot))\n",
- "print()\n",
- "print('PHOTFLAM: {:.6}'.format(uresp))\n",
- "print('STmag: {:.3f}'.format(st))\n",
- "print('ABmag: {:.3f}'.format(ab))\n",
- "print('VEGAMAG: {:.3f}'.format(ve))"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "5c21fe77",
- "metadata": {},
- "source": [
- "\n",
- "### Example 1b: Compute an encircled energy correction\n",
- "\n",
- "As an addendum to the previous example, we can calculate the unit response for the same bandpass, but with a ~10 pixel aperture (0.4\"), and compute the encircled energy correction, in magnitudes, with respect to the infinite aperture. \n",
- "\n",
- "First, we set up the new bandpass for the smaller aperture size."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "b2c1fbfa",
- "metadata": {},
- "outputs": [],
- "source": [
- "obsmode_04 = 'wfc3, uvis1, f814w, aper#0.4, mjd#55008' # Set obsmode string\n",
- "bp_04 = stsyn.band(obsmode_04)"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "3394ca94",
- "metadata": {},
- "source": [
- "Then, we find the unit response for the new bandpass."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "b628298a",
- "metadata": {},
- "outputs": [],
- "source": [
- "uresp_04 = bp_04.unit_response(stsyn.conf.area)"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "152caecf",
- "metadata": {},
- "source": [
- "Finally, we convert the unit response to a magnitude in the ST system, and find the difference between it and the corresponding value for the infinite aperture. This represents the encircled energy correction from 10 pixels to infinity."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "7cbdc0c2",
- "metadata": {},
- "outputs": [],
- "source": [
- "st_04 = -2.5 * np.log10(uresp_04.value) - 21.1\n",
- "\n",
- "st_eecorr = st - st_04\n",
- "\n",
- "print('EE Correction (10 pixels -> infinity): {:.3f}'.format(st_eecorr),'mag')"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "ffb4f8bf",
- "metadata": {},
- "source": [
- "\n",
- "### Example 2: Renormalize a spectrum and predict its magnitude in another bandpass\n",
- "**Renormalize a 2,500 K blackbody spectrum to have 1 count/sec in the Johnson V band, and compute the predicted AB magnitude through the F110W filter on WFC3/IR.**\n",
- "\n",
- "This example reproduces the methods described in section 3 of [WFC3 ISR 2014-16](https://www.stsci.edu/files/live/sites/www/files/home/hst/instrumentation/wfc3/documentation/instrument-science-reports-isrs/_documents/2014/WFC3-2014-16.pdf), but will automatically use the latest available spectra and throughput tables."
- ]
- },
- {
- "cell_type": "markdown",
- "id": "836fc659",
- "metadata": {},
- "source": [
- "First, we define a Johnson V bandpass to which we normalize our spectrum."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "2cbc838e",
- "metadata": {},
- "outputs": [],
- "source": [
- "vband = stsyn.band('johnson, v')"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "b26b07ca",
- "metadata": {},
- "source": [
- "Then, we define the output bandpass for the calculation."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "59037e43",
- "metadata": {},
- "outputs": [],
- "source": [
- "obsmode = 'wfc3, ir, f110w'\n",
- "bp = stsyn.band(obsmode)"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "deafa6d9",
- "metadata": {},
- "source": [
- "Next, we choose a 2500 K blackbody model, fit our spectrum to the model, and use the `normalize` method to normalize the spectrum to one count/sec in the V band."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "2f0f8f30",
- "metadata": {},
- "outputs": [],
- "source": [
- "model = syn.models.BlackBody1D(2500)\n",
- "spec = syn.SourceSpectrum(model)\n",
- "spec_norm = spec.normalize(1*u.ct, vband, area=stsyn.conf.area)"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "1b0a59ac",
- "metadata": {},
- "source": [
- "Finally, we generate a synthetic Observation, which consists of the normalized spectrum convolved with the bandpass, and print the predicted flux (in FLAM) and ABmag values for our Observation."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "04ae77f8",
- "metadata": {},
- "outputs": [],
- "source": [
- "obs = syn.Observation(spec_norm, bp)\n",
- "\n",
- "flux = obs.effstim(flux_unit=su.FLAM)\n",
- "ab = obs.effstim(flux_unit=u.ABmag)\n",
- "\n",
- "print('Predicted flux: {:.4} for Obsmode = {}'.format(flux, obsmode))\n",
- "print('Predicted ABmag: {:.3f} for Obsmode = {}'.format(ab, obsmode))"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "b5805e2e",
- "metadata": {},
- "source": [
- "\n",
- "### Example 3: Find the photometric transformation between two bandpasses\n",
- "**Find the color term for a 5,000 K blackbody between the Cousins-I and WFC3/UVIS1 F814W bandpasses in the ABmag system.**\n",
- "\n",
- "More examples may be found in the filter transformations notebook in the [WFC3 Library](https://github.com/spacetelescope/WFC3Library)."
- ]
- },
- {
- "cell_type": "markdown",
- "id": "19d55eac",
- "metadata": {},
- "source": [
- "First, we set up two bandpasses based on our observation modes. "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "c1b14d64",
- "metadata": {},
- "outputs": [],
- "source": [
- "obsmode1 = 'wfc3, uvis1, f814w'\n",
- "obsmode2 = 'cousins, i'\n",
- "\n",
- "bp1 = stsyn.band(obsmode1)\n",
- "bp2 = stsyn.band(obsmode2)"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "72079ed0",
- "metadata": {},
- "source": [
- "Then, we choose a 5000 K blackbody model and fit our spectrum to the model."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "2d16c712",
- "metadata": {},
- "outputs": [],
- "source": [
- "model = syn.models.BlackBody1D(5000.)\n",
- "spec = syn.SourceSpectrum(model)"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "98501f79",
- "metadata": {},
- "source": [
- "Next, we generate two synthetic Observations, which consists of the blackbody spectrum convolved with the bandpass."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "d693ca97",
- "metadata": {},
- "outputs": [],
- "source": [
- "obs1 = syn.Observation(spec, bp1, binset=bp1.binset)\n",
- "obs2 = syn.Observation(spec, bp2, binset=bp2.binset)"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "564d8592",
- "metadata": {},
- "source": [
- "Finally, we calculate the color term by finding the difference between the two effective stimuli in ABmag."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "0addd585",
- "metadata": {},
- "outputs": [],
- "source": [
- "stim1 = obs1.effstim(flux_unit=u.ABmag)\n",
- "stim2 = obs2.effstim(flux_unit=u.ABmag)\n",
- "\n",
- "color = stim2 - stim1\n",
- "\n",
- "print('ABmag({}) - ABmag({}) = {:.4f}'.format(obsmode2, obsmode1, color))"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "beedb731",
- "metadata": {},
- "source": [
- "\n",
- "### Example 4a: Find the UV color term across the two UVIS chips for different spectral types\n",
- "**Calculate the UV color terms (in the STmag system) for a white dwarf spectrum and a G-type spectrum across the two UVIS chips with the F225W filter. Then, find the difference between these two terms to find the magnitude offset on UVIS2 for the G-type star.**\n",
- "\n",
- "This example reproduces the results from Figure 4 of [WFC3 ISR 2018-08](https://www.stsci.edu/files/live/sites/www/files/home/hst/instrumentation/wfc3/documentation/instrument-science-reports-isrs/_documents/2018/WFC3-2018-08.pdf).\n",
- "\n",
- "The spectra required to run this example, which are the latest relevant spectra from CALSPEC, are provided in the `example_spectra` sub-directory which was packaged with this notebook."
- ]
- },
- {
- "cell_type": "markdown",
- "id": "a88968e2",
- "metadata": {},
- "source": [
- "First, we set up two bandpasses based on our observation modes, and define our area to be the HST primary mirror area."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "7d3aea32",
- "metadata": {},
- "outputs": [],
- "source": [
- "obsmode1 = 'wfc3, uvis1, f225w'\n",
- "obsmode2 = 'wfc3, uvis2, f225w'\n",
- "\n",
- "bp1 = stsyn.band(obsmode1)\n",
- "bp2 = stsyn.band(obsmode2)"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "73dd029f",
- "metadata": {},
- "source": [
- "Then, we define our spectra from the provided FITS files."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "d407ff54",
- "metadata": {},
- "outputs": [],
- "source": [
- "spec_wd = syn.SourceSpectrum.from_file('example_spectra/gd153_stiswfcnic_003.fits') # GD153 (white dwarf)\n",
- "spec_g = syn.SourceSpectrum.from_file('example_spectra/p330e_stiswfcnic_003.fits') # P330E (G-type)"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "392d4ed4",
- "metadata": {},
- "source": [
- "Next, we generate four synthetic Observations, one for each spectrum in each bandpass. Ignore the warning messages."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "8912d342",
- "metadata": {},
- "outputs": [],
- "source": [
- "obs1_wd = syn.Observation(spec_wd, bp1, binset=bp1.binset, force='extrap')\n",
- "obs2_wd = syn.Observation(spec_wd, bp2, binset=bp2.binset, force='extrap')\n",
- "\n",
- "obs1_g = syn.Observation(spec_g, bp1, binset=bp1.binset, force='extrap')\n",
- "obs2_g = syn.Observation(spec_g, bp2, binset=bp1.binset, force='extrap')"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "58e7043f",
- "metadata": {},
- "source": [
- "Following this, we calculate the effective stimuli (in STmag) for these Observations, and find the difference between these values across the two chips for each spectral type."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "be12eb31",
- "metadata": {},
- "outputs": [],
- "source": [
- "stim1_wd = obs1_wd.effstim(flux_unit = u.STmag)\n",
- "stim2_wd = obs2_wd.effstim(flux_unit = u.STmag)\n",
- "\n",
- "stim1_g = obs1_g.effstim(flux_unit = u.STmag)\n",
- "stim2_g = obs2_g.effstim(flux_unit = u.STmag)\n",
- "\n",
- "dstim_wd = stim1_wd - stim2_wd\n",
- "dstim_g = stim1_g - stim2_g"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "a12d97c2",
- "metadata": {},
- "source": [
- "Finally, we calculate the overall cross-chip color term for the G-type star by finding its offset from the white dwarf."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "a64b9b78",
- "metadata": {},
- "outputs": [],
- "source": [
- "print('Color Term (UVIS1 - UVIS2): {:.3f}'.format(dstim_g - dstim_wd))"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "73d4706b",
- "metadata": {},
- "source": [
- "\n",
- "### Example 4b: Plot bandpasses and spectra\n",
- "\n",
- "**Create a plot with the bandpasses and spectra used in Example 4a.**\n",
- "\n",
- "**Note:** For the purposes of these plots, the spectra will be scaled to the amplitude of the bandpasses, which reflect the actual total system throughput as a function of wavelength. You will see that the throughput is different between the two chips.\n",
- "\n",
- "First, define a set of wavelengths and a minimum/maximum bound for our plot, based on the average wavelength and witdth of the bandpasses."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "c0817185",
- "metadata": {},
- "outputs": [],
- "source": [
- "avgwave = (bp1.avgwave().to(u.nm) + bp2.avgwave().to(u.nm))/2\n",
- "width = (bp1.rectwidth().to(u.nm) + bp2.rectwidth().to(u.nm))/2\n",
- "\n",
- "left = max((avgwave - 1.5 * width).value, 1)\n",
- "right = (avgwave + 1.5 * width).value\n",
- "\n",
- "wl = np.arange(left, right) * u.nm"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "4c8c986e",
- "metadata": {},
- "source": [
- "Next, scale the spectra to the (average) amplitude of the bandpasses."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "55ec62d9",
- "metadata": {},
- "outputs": [],
- "source": [
- "avg_max = (np.max(bp1(wl)) + np.max(bp2(wl))) / 2\n",
- "scale_wd = avg_max / np.max(spec_wd(wl))\n",
- "scale_g = avg_max / np.max(spec_g(wl))\n",
- "\n",
- "spec_wd_scale = spec_wd(wl) * scale_wd\n",
- "spec_g_scale = spec_g(wl) * scale_g"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "cbdbd534",
- "metadata": {},
- "source": [
- "Then, plot the bandpasses and spectra."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "7fd87c5c",
- "metadata": {},
- "outputs": [],
- "source": [
- "plt.figure()\n",
- "\n",
- "plt.xlabel('Wavelength (nm)')\n",
- "plt.ylabel('Throughput')\n",
- "\n",
- "plt.plot(wl, spec_wd_scale, ls=':', c='blue', label='White dwarf spectrum')\n",
- "plt.plot(wl, spec_g_scale, ls=':', c='red', label='G-type spectrum')\n",
- "plt.plot(wl, bp1(wl), ls='-', c='orange', label='UVIS 1 bandpass')\n",
- "plt.plot(wl, bp2(wl), ls='-', c='purple', label='UVIS 2 bandpass')\n",
- "\n",
- "plt.legend(fontsize='small')\n",
- "\n",
- "plt.show()"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "06a62d49",
- "metadata": {},
- "source": [
- "\n",
- "## 4. Conclusions\n",
- "\n",
- "Thank you for walking through this notebook. Now using WFC3 data, you should be more familiar with:\n",
- "\n",
- "- Specify WFC3 bandpasses in `stsynphot` and define spectra with `synphot`.\n",
- "- Computing WFC3 zeropoint values and an encircled energy correction.\n",
- "- Renormalizing a spectrum and predict its effective stimulus in another filter.\n",
- "- Finding the photometric transformation between two bandpasses.\n",
- "- Finding the UV color term across the two UVIS chips for different spectral types.\n",
- "- Plotting bandpasses and spectra.\n",
- "\n",
- "#### Congratulations, you have completed the notebook!"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "24d1a132",
- "metadata": {},
- "source": [
- "\n",
- "## Additional Resources\n",
- "Below are some additional resources that may be helpful. Please send any questions through the [HST Helpdesk](https://stsci.service-now.com/hst).\n",
- "\n",
- "- [WFC3 Website](https://www.stsci.edu/hst/instrumentation/wfc3)\n",
- "- [WFC3 Instrument Handbook](https://hst-docs.stsci.edu/wfc3ihb)\n",
- "- [WFC3 Data Handbook](https://hst-docs.stsci.edu/wfc3dhb)\n",
- " - see sections 9.5.2 for reference to this notebook\n",
- " \n",
- "\n",
- "## About this Notebook\n",
- "\n",
- "**Authors:** Aidan Pidgeon, Jennifer Mack; WFC3 Instrument Team\n",
- "\n",
- "**Updated on:** 2021-09-14\n",
- "\n",
- "\n",
- "## Citations\n",
- "\n",
- "If you use `numpy`, `astropy`, `synphot`, or `stsynphot` for published research, please cite the\n",
- "authors. Follow these links for more information about citing the libraries below:\n",
- "\n",
- "* [Citing `numpy`](https://www.scipy.org/citing.html#numpy)\n",
- "* [Citing `astropy`](https://www.astropy.org/acknowledging.html)\n",
- "* [Citing `synphot`](https://synphot.readthedocs.io/en/latest/)\n",
- "* [Citing `stsynphot`](https://stsynphot.readthedocs.io/en/latest/index.html)\n",
- "\n",
- "***\n",
- "[Top of Page](#title)\n",
- " "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "9dd3642f",
- "metadata": {},
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3 (ipykernel)",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.7.12"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 5
-}