Skip to content

Commit

Permalink
Fix photutils 2.0 deprecation removals
Browse files Browse the repository at this point in the history
  • Loading branch information
larrybradley committed Oct 28, 2024
1 parent 3e01e5a commit 8a4a8fc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
"- *os* for setting environment variables\n",
"- *shutil* for managing directories\n",
"- *numpy* for math and array calculations\n",
"- *collections OrderedDict* for making dictionaries easily\n",
"- *matplotlib pyplot* for plotting\n",
"- *matplotlib.colors LogNorm* for scaling images\n",
"- *astropy.io fits* for working with FITS files\n",
Expand All @@ -110,10 +109,10 @@
"import os\n",
"import shutil\n",
"import numpy as np\n",
"from collections import OrderedDict\n",
"import matplotlib.pyplot as plt\n",
"from astropy.io import fits\n",
"from photutils import datasets\n",
"from astropy.modeling.models import Gaussian2D\n",
"from photutils.datasets import make_noise_image, make_model_params, make_model_image\n",
"from astroquery.mast import Observations\n",
"from acstools import acsccd\n",
"from acstools import acscte\n",
Expand Down Expand Up @@ -298,7 +297,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"First, we generate a table of random Gaussian sources of typical brightness for our 47 Tuc field with $\\mathrm{FWHM}\\sim2.5$ pixels. Because $\\mathrm{FWHM} = 2.355\\sigma$, we will generate Gaussian sources with $\\sigma \\sim 1.06$ pixels in both $x$ and $y$. "
"First, we generate a table of random Gaussian sources of typical brightness for our 47 Tuc field with $\\mathrm{FWHM}\\sim2.5$ pixels. Because $\\mathrm{FWHM} = 2.355\\sigma$, we will generate Gaussian sources with $\\sigma \\sim 1.06$ pixels in both $x$ and $y$. We get use the shape of one of the flc image SCI extensions for creating the (x, y) coordinates of the sources."
]
},
{
Expand All @@ -307,27 +306,31 @@
"metadata": {},
"outputs": [],
"source": [
"n_sources = 300\n",
"param_ranges = [('amplitude', [500, 30000]),\n",
" ('x_mean', [0, 4095]),\n",
" ('y_mean', [0, 2047]),\n",
" ('x_stddev', [1.05, 1.07]),\n",
" ('y_stddev', [1.05, 1.07]),\n",
" ('theta', [0, np.pi])]\n",
"wfc2 = fits.getdata('jd0q14ctq_flc.fits', ext=1)\n",
"\n",
"param_ranges = OrderedDict(param_ranges)\n",
"shape = wfc2.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"n_sources = 300\n",
"\n",
"sources = datasets.make_random_gaussians_table(n_sources, param_ranges, \n",
" seed=12345)\n",
"sources = make_model_params(shape, n_sources, x_name='x_mean', y_name='y_mean',\n",
" amplitude=(500, 30000), x_stddev=(1.05, 1.07), \n",
" y_stddev=(1.05, 1.07), theta=(0, np.pi), seed=12345)\n",
"\n",
"print(sources)"
"sources"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, we get the shape of one of the `flc` image `SCI` extensions and make an image from the table of Gaussian sources. Note that this step may take a few minutes. Finally, we run the synthetic image through a Poisson sampler in order to simulate the Poisson noise of the scene."
"Next, we make an image from the table of Gaussian sources. Finally, we run the synthetic image through a Poisson sampler in order to simulate the Poisson noise of the scene."
]
},
{
Expand All @@ -336,11 +339,9 @@
"metadata": {},
"outputs": [],
"source": [
"wfc2 = fits.getdata('jd0q14ctq_flc.fits', ext=1)\n",
"\n",
"shape = wfc2.shape\n",
"\n",
"synth_stars_image = datasets.make_gaussian_sources_image(shape, sources)\n",
"model = Gaussian2D()\n",
"synth_stars_image = make_model_image(shape, model, sources, \n",
" x_name='x_mean', y_name='y_mean', progress_bar=True)\n",
"\n",
"synth_stars_image = np.random.poisson(synth_stars_image)"
]
Expand Down Expand Up @@ -382,7 +383,7 @@
"ax.imshow(flc, vmin=0, vmax=200, interpolation='nearest', cmap='Greys_r', origin='lower')\n",
"\n",
"ax.set_xlim(2000, 2800)\n",
"ax.set_ylim(1200, 1700)"
"ax.set_ylim(800, 1300)"
]
},
{
Expand Down Expand Up @@ -442,7 +443,7 @@
" markerfacecolor='none', markeredgecolor='red', linestyle='none')\n",
"\n",
"ax.set_xlim(2000, 2800)\n",
"ax.set_ylim(1200, 1700)"
"ax.set_ylim(800, 1300)"
]
},
{
Expand Down Expand Up @@ -722,9 +723,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"metadata": {},
"outputs": [],
"source": [
"flt_stars = fits.getdata('jd0q14ctq_stars_ctefmod_flt.fits', ext=1)\n",
Expand All @@ -737,15 +736,13 @@
" markerfacecolor='none', markeredgecolor='red', linestyle='none')\n",
"\n",
"ax.set_xlim(2000, 2800)\n",
"ax.set_ylim(1200, 1700)"
"ax.set_ylim(800, 1300)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"metadata": {},
"outputs": [],
"source": [
"flc_stars = fits.getdata('jd0q14ctq_stars_ctefmod_flc.fits', ext=1)\n",
Expand All @@ -758,7 +755,7 @@
" markerfacecolor='none', markeredgecolor='red', linestyle='none')\n",
"\n",
"ax.set_xlim(2000, 2800)\n",
"ax.set_ylim(1200, 1700)"
"ax.set_ylim(800, 1300)"
]
},
{
Expand Down Expand Up @@ -829,7 +826,7 @@
"metadata": {},
"outputs": [],
"source": [
"noise_image = datasets.make_noise_image(shape, distribution='poisson', mean=40, seed=12345)\n",
"noise_image = make_noise_image(shape, distribution='poisson', mean=40, seed=12345)\n",
"\n",
"wfc1 += noise_image + synth_stars_image\n",
"wfc2 += noise_image + synth_stars_image\n",
Expand Down Expand Up @@ -860,7 +857,7 @@
" markerfacecolor='none', markeredgecolor='red', linestyle='none')\n",
"\n",
"ax.set_xlim(2000, 2800)\n",
"ax.set_ylim(1200, 1700)"
"ax.set_ylim(800, 1300)"
]
},
{
Expand Down Expand Up @@ -986,14 +983,14 @@
"rn_C = hdr['READNSEC']\n",
"rn_D = hdr['READNSED']\n",
"\n",
"img_rn_A = datasets.make_noise_image((shape[0], int(shape[1]/2)), distribution='gaussian', \n",
" mean=0., stddev=rn_A)\n",
"img_rn_B = datasets.make_noise_image((shape[0], int(shape[1]/2)), distribution='gaussian', \n",
" mean=0., stddev=rn_B)\n",
"img_rn_C = datasets.make_noise_image((shape[0], int(shape[1]/2)), distribution='gaussian', \n",
" mean=0., stddev=rn_C)\n",
"img_rn_D = datasets.make_noise_image((shape[0], int(shape[1]/2)), distribution='gaussian', \n",
" mean=0., stddev=rn_D)\n",
"img_rn_A = make_noise_image((shape[0], int(shape[1]/2)), distribution='gaussian', \n",
" mean=0., stddev=rn_A)\n",
"img_rn_B = make_noise_image((shape[0], int(shape[1]/2)), distribution='gaussian', \n",
" mean=0., stddev=rn_B)\n",
"img_rn_C = make_noise_image((shape[0], int(shape[1]/2)), distribution='gaussian', \n",
" mean=0., stddev=rn_C)\n",
"img_rn_D = make_noise_image((shape[0], int(shape[1]/2)), distribution='gaussian', \n",
" mean=0., stddev=rn_D)\n",
"\n",
"wfc1_rn = np.hstack((img_rn_A, img_rn_B))\n",
"wfc2_rn = np.hstack((img_rn_C, img_rn_D))"
Expand Down Expand Up @@ -1290,7 +1287,7 @@
" markerfacecolor='none', markeredgecolor='red', linestyle='none')\n",
"\n",
"ax.set_xlim(2000, 2800)\n",
"ax.set_ylim(1200, 1700)"
"ax.set_ylim(800, 1300)"
]
},
{
Expand All @@ -1309,7 +1306,7 @@
" markerfacecolor='none', markeredgecolor='red', linestyle='none')\n",
"\n",
"ax.set_xlim(2000, 2800)\n",
"ax.set_ylim(1200, 1700)"
"ax.set_ylim(800, 1300)"
]
},
{
Expand Down Expand Up @@ -1365,7 +1362,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions notebooks/ACS/acs_cte_forward_model/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ astropy>=5.3.3
astroquery>=0.4.6
matplotlib>=3.7.0
numpy>=1.23.4
photutils>=1.6.0
photutils>=2.0.2
crds>=11.17.7
stsci.tools>=4.1.0
stsci.tools>=4.1.0

0 comments on commit 8a4a8fc

Please sign in to comment.