Skip to content

Commit

Permalink
WIP XDF segmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mwcraig committed Apr 6, 2024
1 parent 5f982a1 commit 92c82d7
Showing 1 changed file with 84 additions and 6 deletions.
90 changes: 84 additions & 6 deletions notebooks/photometry/01.04.02-image-segmentation-XDF.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,85 @@
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "4a539fa2-f180-4b88-a620-da47c6af8270",
"metadata": {},
"source": [
"## Data for this notebook \n",
"\n",
"We will be manipulating Hubble eXtreme Deep Field (XDF) data, which was collected using the Advanced Camera for Surveys (ACS) on Hubble between 2002 and 2012. The image we use here is the result of 1.8 million seconds (500 hours!) of exposure time, and includes some of the faintest and most distant galaxies that had ever been observed. \n",
"\n",
"*The methods demonstrated here are also available in the [`photutils.detection` documentation](http://photutils.readthedocs.io/en/stable/detection.html).*\n",
"\n",
"*The original authors of this notebook were Lauren Chambers, Erik Tollerud and Tom Wilson.*\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7e90842d-8f03-408e-8622-532d1fab18c7",
"metadata": {},
"outputs": [],
"source": [
"import warnings\n",
"\n",
"from astropy.nddata import CCDData\n",
"from astropy.stats import sigma_clipped_stats, SigmaClip\n",
"import astropy.units as u\n",
"from astropy.visualization import ImageNormalize, LogStretch\n",
"\n",
"import matplotlib.pyplot as plt\n",
"from matplotlib.ticker import LogLocator\n",
"\n",
"import numpy as np\n",
"\n",
"from photutils.background import Background2D, MeanBackground\n",
"from photutils.centroids import centroid_2dg\n",
"from photutils.detection import find_peaks, DAOStarFinder, IRAFStarFinder\n",
"from photutils.segmentation import detect_sources\n",
"\n",
"# Show plots in the notebook\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7fe76ad2-51c6-48fd-b91e-541a1ea9bd90",
"metadata": {},
"outputs": [],
"source": [
"xdf_image = CCDData.read('hlsp_xdf_hst_acswfc-60mas_hudf_f435w_v1_sci.fits')\n",
"# Define the mask\n",
"mask = xdf_image.data == 0\n",
"xdf_image.mask = mask"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "82f387f7-66af-4be6-bd2f-4f54f87ba6ed",
"metadata": {},
"outputs": [],
"source": [
"mean, median, std = sigma_clipped_stats(xdf_image.data, sigma=3.0, maxiters=5, mask=xdf_image.mask)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2b4110f0-a867-42fb-8eac-885a4883c4d6",
"metadata": {},
"outputs": [],
"source": [
"plt.style.use('../photutils_notebook_style.mplstyle')"
]
},
{
"cell_type": "markdown",
"id": "21c15890-d5d2-4f5a-a1dd-7795e0f609a7",
"metadata": {
"jp-MarkdownHeadingCollapsed": true
},
"metadata": {},
"source": [
"Beyond traditional source detection methods, an additional option for identifying sources in image data is a process called **image segmentation**. This method identifies and labels contiguous (connected) objects within an image. \n",
"\n",
Expand Down Expand Up @@ -48,7 +121,6 @@
"metadata": {},
"outputs": [],
"source": [
"from photutils import detect_sources\n",
"from photutils.utils import make_random_cmap"
]
},
Expand Down Expand Up @@ -80,8 +152,14 @@
"fig, [ax1, ax2] = plt.subplots(1, 2, figsize=(12, 6))\n",
"plt.tight_layout()\n",
"\n",
"# Plot the data\n",
"# Set up the normalization and colormap\n",
"norm_image = ImageNormalize(vmin=1e-4, vmax=5e-2, stretch=LogStretch(), clip=False)\n",
"cmap = plt.get_cmap('viridis')\n",
"cmap.set_bad('white') # Show masked data as white\n",
"\n",
"# Plot the original data\n",
"fitsplot = ax1.imshow(np.ma.masked_where(xdf_image.mask, xdf_image_clipped),\n",
"fitsplot = ax1.imshow(np.ma.masked_where(xdf_image.mask, xdf_image),\n",
" norm=norm_image, cmap=cmap)\n",
"ax1.set_ylabel('Y (pixels)')\n",
"ax1.set_title('Original Data')\n",
Expand Down Expand Up @@ -280,7 +358,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.11.8"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 92c82d7

Please sign in to comment.