Skip to content

Commit

Permalink
Update wfc3 notebook dependencies (#299)
Browse files Browse the repository at this point in the history
* Update WFC3 requirements

* Update requirements.txt

* Replace ginga zscale with astropy visualization zscale

* Install hst-cal via conda-forge

* Remove the numpy pinning on the uvis_pam nb

* Revert hstcal to old version to demo specific API

* Pin photutils
  • Loading branch information
haticekaratay authored Sep 4, 2024
1 parent b48b3d8 commit c54f2ef
Show file tree
Hide file tree
Showing 27 changed files with 219 additions and 199 deletions.
4 changes: 2 additions & 2 deletions notebooks/WFC3/calwf3_recalibration/calwf3_recal_tvb.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"\n",
"## Learning Goals\n",
"\n",
"This notebook shows two reprocessing examples for WFC3/IR observations impacted by time-variable background (TVB).\n",
"This notebook shows two reprocessing examples for WFC3/IR observations impacted by time-variable background (TVB). \n",
"\n",
"By the end of this tutorial, you will:\n",
"- Analyze exposure statistics for each read in an IMA file using `pstat`.\n",
Expand Down Expand Up @@ -768,7 +768,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down
19 changes: 10 additions & 9 deletions notebooks/WFC3/calwf3_recalibration/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
astropy==5.3.3
astroquery==0.4.6
ccdproc==2.4.0
crds==11.17.9
drizzlepac==3.5.1
matplotlib==3.7.0
numpy==1.23.4
stwcs==1.7.2
wfc3tools==1.4.0
photutils==1.12.0 # The notebook uses deprecated methods such as DAOGroup.
astropy>=5.3.3
astroquery>=0.4.6
ccdproc>=2.4.0
crds>=11.17.9
drizzlepac>=3.5.1
matplotlib>=3.7.0
numpy>=1.23.4
stwcs>=1.7.2
wfc3tools>=1.4.0
4 changes: 2 additions & 2 deletions notebooks/WFC3/calwf3_v1.0_cte/calwf3_with_v1.0_PCTE.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"\n",
"By the end of this tutorial, you will:\n",
"\n",
"- Download a raw WFC3 image from MAST.\n",
"- Download a raw WFC3 image from MAST. \n",
"- Find the necessary reference files needed for calibration.\n",
"- Edit header keywords.\n",
"- Run `calwf3` `v3.5.2` to calibrate the raw image with the v1.0 pixel based CTE-correction.\n",
Expand Down Expand Up @@ -990,7 +990,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
"version": "3.12.4"
},
"varInspector": {
"cols": {
Expand Down
2 changes: 1 addition & 1 deletion notebooks/WFC3/calwf3_v1.0_cte/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ crds
jupyter
matplotlib
numpy
photutils
photutils==1.12.0
scipy
wfc3tools
35 changes: 20 additions & 15 deletions notebooks/WFC3/filter_transformations/filter_transformations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"metadata": {},
"source": [
"<a id=\"title\"></a>\n",
"# WFC3/UVIS Filter Transformations with stsynphot\n",
"# WFC3/UVIS Filter Transformations with stsynphot \n",
"***\n",
"## Learning Goals\n",
"\n",
Expand Down Expand Up @@ -289,7 +289,8 @@
"STMAG = True\n",
"VEGAMAG = False\n",
"\n",
"mags = [('ABMAG', u.ABmag, ABMAG), ('STMAG', u.STmag, STMAG), ('VEGAMAG', su.VEGAMAG, VEGAMAG)]"
"mags = [('ABMAG', u.ABmag, ABMAG), ('STMAG', u.STmag, STMAG),\n",
" ('VEGAMAG', su.VEGAMAG, VEGAMAG)]"
]
},
{
Expand Down Expand Up @@ -363,12 +364,12 @@
"for pair in filter_pairs:\n",
" comparison_filter, uvis_filter = pair # Unpack filters\n",
" filt_str = comparison_filter + ' - ' + uvis_filter\n",
" \n",
"\n",
" for i, toggle in enumerate(chips):\n",
" if not toggle:\n",
" continue\n",
" chip_str = 'UVIS' + str(i + 1)\n",
" \n",
"\n",
" # Generate observation mode strings, bandpasses, observations\n",
" comparison_obsmode = comparison_filter\n",
" uvis_obsmode = 'wfc3, ' + chip_str + ', ' + uvis_filter\n",
Expand All @@ -383,11 +384,13 @@
" for name, unit, toggle in mags:\n",
" if not toggle:\n",
" continue\n",
" comparison_countrate = comparison_observation.effstim(flux_unit=unit, vegaspec=vegaspec) \n",
" uvis_countrate = uvis_observation.effstim(flux_unit=unit, vegaspec=vegaspec)\n",
" color = comparison_countrate - uvis_countrate # Find color term\n",
" comparison_countrate = comparison_observation.effstim(\n",
" flux_unit=unit, vegaspec=vegaspec)\n",
" uvis_countrate = uvis_observation.effstim(\n",
" flux_unit=unit, vegaspec=vegaspec)\n",
" color = comparison_countrate - uvis_countrate # Find color term\n",
" row.append(f'{color.value:.3f}') # Append color term\n",
" \n",
"\n",
" rows.append(row) # Append row to list of rows"
]
},
Expand Down Expand Up @@ -448,27 +451,29 @@
"metadata": {},
"outputs": [],
"source": [
"fig, axs = plt.subplots(1, len(filter_pairs), sharey=True, figsize=(4*len(filter_pairs), 5)) # Instantiate subplots\n",
"fig, axs = plt.subplots(1, len(filter_pairs), sharey=True, figsize=(\n",
" 4*len(filter_pairs), 5)) # Instantiate subplots\n",
"axs[0].set_ylabel('Throughput')\n",
"for i, pair in enumerate(filter_pairs):\n",
" \n",
"\n",
" f1, f2 = pair\n",
" bp1 = stsyn.band(f1)\n",
" bp2 = stsyn.band('wfc3, uvis1,' + f2)\n",
" \n",
"\n",
" # Create wavelength array for subplot based on average bandpass wavelength and width\n",
" 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",
" left = max((avgwave - 1.5 * width).value, 1)\n",
" right = (avgwave + 1.5 * width).value\n",
" \n",
"\n",
" wl = np.arange(left, right) * u.nm\n",
"\n",
" # Normalize curves to fit on one set of axes\n",
" bp1_norm = bp1(wl) / np.max(bp1(wl)) * np.max(bp2(wl))\n",
" spec_norm = source_spectrum(wl) / np.max(source_spectrum(wl)) * np.max(bp2(wl))\n",
" \n",
" # Plot bandpasses and spectrum on subplot \n",
" spec_norm = source_spectrum(\n",
" wl) / np.max(source_spectrum(wl)) * np.max(bp2(wl))\n",
"\n",
" # Plot bandpasses and spectrum on subplot\n",
" axs[i].plot(wl, bp1_norm, ls='--', label=f1, c='tab:blue')\n",
" axs[i].plot(wl, bp2(wl), ls='-.', label=f2, c='tab:red')\n",
" axs[i].plot(wl, spec_norm, label='source spectrum', c='tab:purple')\n",
Expand Down
10 changes: 5 additions & 5 deletions notebooks/WFC3/filter_transformations/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
astropy
matplotlib==3.8.3
numpy==1.26.4
pandas==2.2.1
stsynphot==1.2.0
synphot==1.1.1
matplotlib>=3.8.3
numpy>=1.26.4
pandas>=2.2.1
stsynphot>=1.2.0
synphot>=1.1.1
64 changes: 36 additions & 28 deletions notebooks/WFC3/flux_conversion_tool/flux_conversion_tool.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"metadata": {},
"source": [
"<a id=\"title\"></a>\n",
"# Flux Unit Conversions with synphot and stsynphot\n",
"# Flux Unit Conversions with synphot and stsynphot \n",
"***\n",
"## Learning Goals\n",
"By the end of this tutorial, you will:\n",
Expand Down Expand Up @@ -275,7 +275,7 @@
"value_in = 0.0\n",
"unit_in = su.VEGAMAG\n",
"waveband_in = 'johnson, v'\n",
"wavelength_unit = u.nm "
"wavelength_unit = u.nm"
]
},
{
Expand Down Expand Up @@ -349,7 +349,7 @@
"source": [
"quantity_in = value_in * unit_in\n",
"mag_systems = [u.STmag, u.ABmag, su.VEGAMAG]\n",
"flux_systems = ['spectral flux density', 'spectral flux density wav', \n",
"flux_systems = ['spectral flux density', 'spectral flux density wav',\n",
" 'photon flux density', 'photon flux density wav']"
]
},
Expand Down Expand Up @@ -392,7 +392,7 @@
" plot_flux_in = convert_flux(wavelength_in, flux_in, plot_unit)\n",
"elif unit_in.physical_type in flux_systems:\n",
" flux_in = quantity_in\n",
" wavelength_in = waveband_in * wavelength_unit \n",
" wavelength_in = waveband_in * wavelength_unit\n",
" plot_unit = unit_in\n",
" plot_flux_in = convert_flux(wavelength_in, flux_in, plot_unit)\n",
"else:\n",
Expand Down Expand Up @@ -431,7 +431,7 @@
"elif unit_out.physical_type in flux_systems:\n",
" wavelength_out = waveband_out * wavelength_unit\n",
"else:\n",
" print('unit_out not a flux density unit or magnitude system') "
" print('unit_out not a flux density unit or magnitude system')"
]
},
{
Expand All @@ -449,7 +449,8 @@
"metadata": {},
"outputs": [],
"source": [
"scale = convert_flux(wavelength_in, flux_in, su.PHOTLAM) / spectrum(wavelength_in)\n",
"scale = convert_flux(wavelength_in, flux_in, su.PHOTLAM) / \\\n",
" spectrum(wavelength_in)\n",
"scaled_spectrum = spectrum * scale"
]
},
Expand All @@ -474,11 +475,14 @@
"if unit_out in mag_systems:\n",
" flux_out = convert_flux(wavelength_out, scaled_spectrum(wavelength_out), unit_out,\n",
" vegaspec=vegaspec)\n",
" plot_flux_out = convert_flux(wavelength_out, scaled_spectrum(wavelength_out), plot_unit)\n",
" plot_flux_out = convert_flux(\n",
" wavelength_out, scaled_spectrum(wavelength_out), plot_unit)\n",
"else:\n",
" flux_out = convert_flux(wavelength_out, scaled_spectrum(wavelength_out), unit_out)\n",
" plot_flux_out = convert_flux(wavelength_out, scaled_spectrum(wavelength_out), plot_unit)\n",
" \n",
" flux_out = convert_flux(\n",
" wavelength_out, scaled_spectrum(wavelength_out), unit_out)\n",
" plot_flux_out = convert_flux(\n",
" wavelength_out, scaled_spectrum(wavelength_out), plot_unit)\n",
"\n",
"value_out = flux_out.value"
]
},
Expand Down Expand Up @@ -550,7 +554,7 @@
"if wavelength_in.value > wavelength_out.value:\n",
" c_in = 'r'\n",
" c_out = 'b'\n",
"else: \n",
"else:\n",
" c_in = 'b'\n",
" c_out = 'r'"
]
Expand All @@ -573,19 +577,20 @@
"plt.figure()\n",
"\n",
"# Plot spectrum\n",
"plt.plot(wavelength_space, scaled_spectrum(wavelength_space, flux_unit=plot_unit), c='k', label='Source Spectrum')\n",
"plt.plot(wavelength_space, scaled_spectrum(wavelength_space,\n",
" flux_unit=plot_unit), c='k', label='Source Spectrum')\n",
"\n",
"# Plot input\n",
"plt.plot(wavelength_in.value, plot_flux_in.value,\n",
" marker='o', color=c_in, ls='none', \n",
" marker='o', color=c_in, ls='none',\n",
" label='Input: {:.4} {} at {:.1f} {}'.format(\n",
" float(value_in), str(unit_in), wavelength_in.value, str(wavelength_in.unit)))\n",
" float(value_in), str(unit_in), wavelength_in.value, str(wavelength_in.unit)))\n",
"\n",
"# Plot output\n",
"plt.plot(wavelength_out.value, plot_flux_out.value,\n",
" marker='s', color=c_out, ls='none', \n",
" marker='s', color=c_out, ls='none',\n",
" label='Output: {:.4} {} at {:.1f} {}'.format(\n",
" float(value_out), str(unit_out), wavelength_out.value, str(wavelength_out.unit)))\n",
" float(value_out), str(unit_out), wavelength_out.value, str(wavelength_out.unit)))\n",
"\n",
"# Set heights for dotted lines to markers as % of plot range\n",
"bottom, top = plt.ylim()\n",
Expand All @@ -594,13 +599,15 @@
"outheight = (plot_flux_out.value - bottom) / yrange\n",
"\n",
"# Plot dotted lines to markers\n",
"plt.axvline(wavelength_in.to(wavelength_unit).value, ymax=inheight, ls=':', c=c_in)\n",
"plt.axvline(wavelength_out.to(wavelength_unit).value, ymax=outheight, ls=':', c=c_out)\n",
"plt.axvline(wavelength_in.to(wavelength_unit).value,\n",
" ymax=inheight, ls=':', c=c_in)\n",
"plt.axvline(wavelength_out.to(wavelength_unit).value,\n",
" ymax=outheight, ls=':', c=c_out)\n",
"\n",
"# Miscellaneous\n",
"plt.ylabel('Flux ({})'.format(str(plot_unit)))\n",
"plt.xlabel('Wavelength ({})'.format(str(wavelength_unit)))\n",
"plt.legend(fontsize='small') \n",
"plt.legend(fontsize='small')\n",
"plt.tight_layout()"
]
},
Expand All @@ -627,15 +634,15 @@
"outputs": [],
"source": [
"# Input: 3631 Jy at 550. nm\n",
"value_in = 3631. \n",
"value_in = 3631.\n",
"unit_in = u.Jy\n",
"waveband_in = 550.\n",
"wavelength_unit = u.nm\n",
"\n",
"# Output: Johnson V mag (AB)\n",
"unit_out = u.ABmag\n",
"waveband_out = 'Johnson, V'\n",
" \n",
"\n",
"# Spectrum: Flat power law in F_nu\n",
"pl_index = 0\n",
"model = PowerLawFlux1D(amplitude=flux_in, x_0=wavelength_in, alpha=pl_index)\n",
Expand All @@ -660,15 +667,15 @@
"outputs": [],
"source": [
"# Input: 1.234e-8 flam at 500. nm\n",
"value_in = 1.234e-8 \n",
"value_in = 1.234e-8\n",
"unit_in = su.FLAM\n",
"waveband_in = 500.\n",
"wavelength_unit = u.nm\n",
"\n",
"# Output: flam at 800. nm\n",
"unit_out = su.FLAM\n",
"waveband_out = 800.\n",
" \n",
"\n",
"# Spectrum: 5800 K blackbody\n",
"bb_temp = 5800 * u.K\n",
"model = BlackBody1D(bb_temp)\n",
Expand All @@ -693,15 +700,15 @@
"outputs": [],
"source": [
"# Input: 1.234e-21 fnu at 686. nm\n",
"value_in = 1.234e-21 \n",
"value_in = 1.234e-21\n",
"unit_in = su.FNU\n",
"waveband_in = 686.\n",
"wavelength_unit = u.nm\n",
"\n",
"# Output: photnu at 686. nm\n",
"unit_out = su.PHOTNU\n",
"waveband_out = 686.\n",
" \n",
"\n",
"# Spectrum: 5800 K blackbody\n",
"bb_temp = 5800 * u.K\n",
"model = BlackBody1D(bb_temp)\n",
Expand All @@ -726,18 +733,19 @@
"outputs": [],
"source": [
"# Input: STmag = 12.240, F606W filter on WFC3 UVIS 2\n",
"value_in = 12.240 \n",
"value_in = 12.240\n",
"unit_in = u.STmag\n",
"waveband_in = 'wfc3, uvis2, f606w, mjd#59367'\n",
"wavelength_unit = u.nm\n",
"\n",
"# Output: Johnson V mag (AB)\n",
"unit_out = u.STmag\n",
"waveband_out = 'Johnson, V'\n",
" \n",
"\n",
"# Spectrum: Flat power law in F_lambda\n",
"pl_index = 0\n",
"model = PowerLawFlux1D(amplitude=convert_flux(606 * u.nm, 1., su.FLAM), x_0=606 * u.nm, alpha=pl_index)\n",
"model = PowerLawFlux1D(amplitude=convert_flux(\n",
" 606 * u.nm, 1., su.FLAM), x_0=606 * u.nm, alpha=pl_index)\n",
"spec = SourceSpectrum(model)\n",
"model = PowerLawFlux1D(amplitude=flux_in, x_0=wavelength_in, alpha=pl_index)"
]
Expand Down
8 changes: 4 additions & 4 deletions notebooks/WFC3/flux_conversion_tool/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
astropy
matplotlib==3.8.3
numpy==1.26.4
stsynphot==1.2.0
synphot==1.1.1
matplotlib>=3.8.3
numpy>=1.26.4
stsynphot>=1.2.0
synphot>=1.1.1
Loading

0 comments on commit c54f2ef

Please sign in to comment.