From 4b2976f7ee743ba7818fbd939af55b2674512b71 Mon Sep 17 00:00:00 2001 From: Larry Bradley Date: Thu, 24 Oct 2024 23:19:38 -0400 Subject: [PATCH 1/2] Fix background subtraction notebook --- .../Imaging_Sky_Background_Estimation.ipynb | 44 +++++++++++-------- .../requirements.txt | 2 +- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/notebooks/cross_instrument/background_estimation_imaging/Imaging_Sky_Background_Estimation.ipynb b/notebooks/cross_instrument/background_estimation_imaging/Imaging_Sky_Background_Estimation.ipynb index 06d9b977d..fc0fdf296 100644 --- a/notebooks/cross_instrument/background_estimation_imaging/Imaging_Sky_Background_Estimation.ipynb +++ b/notebooks/cross_instrument/background_estimation_imaging/Imaging_Sky_Background_Estimation.ipynb @@ -63,7 +63,7 @@ "from photutils.background import (Background2D,\n", " BkgIDWInterpolator, BkgZoomInterpolator,\n", " MedianBackground)\n", - "from photutils.datasets import make_gaussian_sources_image\n", + "from photutils.datasets import make_model_image\n", "from photutils.segmentation import detect_sources, make_2dgaussian_kernel\n", "from scipy.ndimage import median_filter" ] @@ -413,7 +413,9 @@ "metadata": {}, "outputs": [], "source": [ - "source_img = make_gaussian_sources_image(sky_bkgd.shape, sources)\n", + "model = models.Gaussian2D()\n", + "source_img = make_model_image(sky_bkgd.shape, model, sources, \n", + " x_name='x_mean', y_name='y_mean')\n", "scene = source_img + sky_bkgd" ] }, @@ -485,7 +487,8 @@ " bkg_estimator=MedianBackground(),\n", " interpolator=BkgZoomInterpolator(order=3))\n", "plt.figure(figsize=(6, 6))\n", - "plt.imshow(bkg.background-noiseless_sky, vmin=0.1*zmin, vmax=0.1*zmax, origin='lower')" + "bkgimg = bkg.background\n", + "plt.imshow(bkgimg-noiseless_sky, vmin=0.1*zmin, vmax=0.1*zmax, origin='lower')" ] }, { @@ -525,9 +528,9 @@ "metadata": {}, "outputs": [], "source": [ - "mask_2sigma = make_source_mask(scene-bkg.background, nsigma=2, npixels=3,\n", + "mask_2sigma = make_source_mask(scene-bkgimg, nsigma=2, npixels=3,\n", " dilate_size=5, filter_fwhm=3)\n", - "mask_3sigma = make_source_mask(scene-bkg.background, nsigma=3, npixels=3,\n", + "mask_3sigma = make_source_mask(scene-bkgimg, nsigma=3, npixels=3,\n", " dilate_size=5, filter_fwhm=3)\n", "plot_two(mask_2sigma, mask_3sigma, 0, 1)" ] @@ -551,7 +554,9 @@ " sigma_clip=sigma_clip, bkg_estimator=bkg_estimator)\n", "bkg2 = Background2D(scene, (15, 15), filter_size=(3, 3), mask=mask_3sigma,\n", " sigma_clip=sigma_clip, bkg_estimator=bkg_estimator)\n", - "plot_two(bkg1.background-noiseless_sky, bkg2.background-noiseless_sky,\n", + "bkg1img = bkg1.background\n", + "bkg2img = bkg2.background\n", + "plot_two(bkg1img-noiseless_sky, bkg2img-noiseless_sky,\n", " 0.1*zmin, 0.1*zmax, titles=['bkg1', 'bkg2'])" ] }, @@ -862,7 +867,8 @@ "outputs": [], "source": [ "bkg3 = my_background(scene, box_size=10, filter_size=5, mask=mask)\n", - "plot_bkgd(scene, mask, bkg1.background, noiseless_sky, sources, zmin, zmax)" + "bkg3img = bkg3.background\n", + "plot_bkgd(scene, mask, bkg3img, noiseless_sky, sources, zmin, zmax)" ] }, { @@ -885,7 +891,8 @@ "interpolator = BkgIDWInterpolator(n_neighbors=20, power=1, reg=30)\n", "bkg4 = my_background(scene, box_size=10, filter_size=5, mask=mask,\n", " interp=interpolator, exclude_percentile=90)\n", - "plot_bkgd(scene, mask, bkg4.background, noiseless_sky, sources, zmin, zmax)" + "bkg4img = bkg4.background\n", + "plot_bkgd(scene, mask, bkg4img, noiseless_sky, sources, zmin, zmax)" ] }, { @@ -902,10 +909,10 @@ "metadata": {}, "outputs": [], "source": [ - "sm = SourceMask(scene-bkg4.background, nsigma=1.5)\n", + "sm = SourceMask(scene-bkg4img, nsigma=1.5)\n", "mask = sm.multiple(filter_fwhm=[1, 3, 5],\n", " tophat_size=[4, 2, 1])\n", - "plot_mask(scene, bkg4.background, mask, zmin, zmax)\n", + "plot_mask(scene, bkg4img, mask, zmin, zmax)\n", "mask.sum()" ] }, @@ -926,7 +933,8 @@ "interpolator = BkgIDWInterpolator(n_neighbors=20, power=0, reg=30)\n", "bkg5 = my_background(scene, box_size=6, filter_size=3, mask=mask,\n", " interp=interpolator, exclude_percentile=90)\n", - "plot_bkgd(scene, mask, bkg5.background, noiseless_sky, sources, zmin, zmax)" + "bkg5img = bkg5.background\n", + "plot_bkgd(scene, mask, bkg5img, noiseless_sky, sources, zmin, zmax)" ] }, { @@ -946,7 +954,7 @@ "metadata": {}, "outputs": [], "source": [ - "bkgd = bkg5.background\n", + "bkgd = bkg5img\n", "residual_image = bkgd-noiseless_sky\n", "\n", "# Create columns in the table for the background estimate, the residual,\n", @@ -1196,11 +1204,11 @@ "source": [ "rms = Table()\n", "widths = rms['widths'] = np.arange(3, 30, 1)\n", - "rms['bkg1'] = calculate_stats(scene-bkg1.background, mask, widths)\n", - "rms['bkg2'] = calculate_stats(scene-bkg2.background, mask, widths)\n", - "rms['bkg3'] = calculate_stats(scene-bkg3.background, mask, widths)\n", - "rms['bkg4'] = calculate_stats(scene-bkg4.background, mask, widths)\n", - "rms['bkg5'] = calculate_stats(scene-bkg5.background, mask, widths)\n", + "rms['bkg1'] = calculate_stats(scene-bkg1img, mask, widths)\n", + "rms['bkg2'] = calculate_stats(scene-bkg2img, mask, widths)\n", + "rms['bkg3'] = calculate_stats(scene-bkg3img, mask, widths)\n", + "rms['bkg4'] = calculate_stats(scene-bkg4img, mask, widths)\n", + "rms['bkg5'] = calculate_stats(scene-bkg5img, mask, widths)\n", "rms['perfect'] = calculate_stats(sky_bkgd-noiseless_sky, mask, widths)" ] }, @@ -1252,7 +1260,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.12.7" } }, "nbformat": 4, diff --git a/notebooks/cross_instrument/background_estimation_imaging/requirements.txt b/notebooks/cross_instrument/background_estimation_imaging/requirements.txt index e8f57a4c4..1749d44f8 100644 --- a/notebooks/cross_instrument/background_estimation_imaging/requirements.txt +++ b/notebooks/cross_instrument/background_estimation_imaging/requirements.txt @@ -2,6 +2,6 @@ numpy >= 2.0.0 astropy >= 6.1.1 matplotlib >= 3.9.1 scipy >= 1.14.0 -photutils >= 1.13.0 +photutils >= 2.0.2 scikit-image >= 0.21.0 jdaviz >= 3.10.2 From 60e16d52b8124782e9f3b1f101456b1e113454e5 Mon Sep 17 00:00:00 2001 From: Larry Bradley Date: Thu, 24 Oct 2024 23:21:01 -0400 Subject: [PATCH 2/2] Update requirements for PSF photometry notebook --- notebooks/NIRCam/psf_photometry/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebooks/NIRCam/psf_photometry/requirements.txt b/notebooks/NIRCam/psf_photometry/requirements.txt index 17553e36e..e28207cdb 100644 --- a/notebooks/NIRCam/psf_photometry/requirements.txt +++ b/notebooks/NIRCam/psf_photometry/requirements.txt @@ -2,7 +2,7 @@ numpy>=1.25.2 pandas>=2.1.0 jwst>=1.11.4 astropy>=5.3.3 -photutils>=1.11.0 +photutils>=2.0.2 ipywidgets>=8.1.1 matplotlib>=3.7.2 webbpsf>=1.2.1