Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forwardport PR 261 to main (ALOHA 2024: Clean up photometry contents) #264

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions 09-Photutils/01-aperture_basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
}
},
"source": [
"We'll start by reading science data and error arrays from FITS files located in the [**data/**](data) subdirectory. The FITS files contain 2D cutout images from the [Hubble Extreme-Deep Field (XDF)](https://archive.stsci.edu/prepds/xdf/) taken with the [Wide Field Camera 3 (WFC3)](https://www.stsci.edu/hst/instrumentation/wfc3) IR channel in the F160W filter (centered at ~1.6 $\\mu m$)."
"We'll start by reading science data and error arrays from FITS files located in the **data/** subdirectory. The FITS files contain 2D cutout images from the [Hubble Extreme-Deep Field (XDF)](https://archive.stsci.edu/prepds/xdf/) taken with the [Wide Field Camera 3 (WFC3)](https://www.stsci.edu/hst/instrumentation/wfc3) IR channel in the F160W filter (centered at ~1.6 $\\mu m$)."
]
},
{
Expand Down Expand Up @@ -219,7 +219,7 @@
"\n",
"Further, there are two types of aperture classes, defined either with pixel or sky (celestial) coordinates.\n",
"\n",
"These are the names of the [aperture classes](https://photutils.readthedocs.io/en/latest/aperture.html#classes) that are defined in pixel coordinates:\n",
"These are the names of the [aperture classes](https://photutils.readthedocs.io/en/stable/user_guide/aperture.html#apertures) that are defined in pixel coordinates:\n",
"\n",
"* `CircularAperture`\n",
"* `CircularAnnulus`\n",
Expand Down Expand Up @@ -298,7 +298,7 @@
"source": [
"First, let's define a circular aperture at a given (x, y) pixel position and radius (in pixels).\n",
"\n",
"Photutils has many tools for detecting sources (e.g., see [photutils.detection](https://photutils.readthedocs.io/en/latest/detection.html) and [photutils.segmentation](https://photutils.readthedocs.io/en/latest/segmentation.html)) and measuring source positions (e.g., [photutils.centroids](https://photutils.readthedocs.io/en/latest/centroids.html)). For this example, we'll assume we've already measured the source centroid."
"Photutils has many tools for detecting sources (e.g., see [photutils.detection](https://photutils.readthedocs.io/en/stable/user_guide/detection.html) and [photutils.segmentation](https://photutils.readthedocs.io/en/stable/user_guide/segmentation.html)) and measuring source positions (e.g., [photutils.centroids](https://photutils.readthedocs.io/en/stable/user_guide/centroids.html)). For this example, we'll assume we've already measured the source centroid."
]
},
{
Expand All @@ -322,7 +322,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Our `aperture` variable is now an instance of a [CircularAperture](https://photutils.readthedocs.io/en/latest/api/photutils.aperture.CircularAperture.html#photutils.aperture.CircularAperture) object."
"Our `aperture` variable is now an instance of a [CircularAperture](https://photutils.readthedocs.io/en/stable/api/photutils.aperture.CircularAperture.html) object."
]
},
{
Expand Down Expand Up @@ -365,11 +365,11 @@
"source": [
"Now let's perform photometry on the XDF data using this circular aperture.\n",
"\n",
"After the aperture object is created, we can perform the photometry using the [aperture_photometry](https://photutils.readthedocs.io/en/latest/api/photutils.aperture.aperture_photometry.html#photutils.aperture.aperture_photometry) function or the [ApertureStats](https://photutils.readthedocs.io/en/latest/api/photutils.aperture.ApertureStats.html#photutils.aperture.ApertureStats) class. We'll start by using the `aperture_photometry` function. The `ApertureStats` class will be introduced later in this notebook.\n",
"After the aperture object is created, we can perform the photometry using the [aperture_photometry](https://photutils.readthedocs.io/en/stable/api/photutils.aperture.aperture_photometry.html) function or the [ApertureStats](https://photutils.readthedocs.io/en/stable/api/photutils.aperture.ApertureStats.html) class. We'll start by using the `aperture_photometry` function. The `ApertureStats` class will be introduced later in this notebook.\n",
"\n",
"In the most basic case, we simply need to input the data array and the aperture object. The default aperture overlap method is `'exact'`.\n",
"\n",
"Note that the input data array is assumed to be background subtracted. If that is not the case, please see the documentation for the [photutils.background](https://photutils.readthedocs.io/en/latest/background.html) subpackage for tools to help subtract the background.\n",
"Note that the input data array is assumed to be background subtracted. If that is not the case, please see the documentation for the [photutils.background](https://photutils.readthedocs.io/en/stable/user_guide/background.html) subpackage for tools to help subtract the background.\n",
"\n",
"The background has already been subtracted from our XDF example data, so we skip that step in this example.\n",
"\n",
Expand Down Expand Up @@ -769,7 +769,7 @@
},
"outputs": [],
"source": [
"f160w_zpt = 25.9463 # HST/WFC3 F160W ABmag zero point for flux in e-/s\n",
"f160w_zpt = 25.936 # HST/WFC3 F160W ABmag zero point for flux in e-/s\n",
"\n",
"# NOTE that the log10 function can be applied only to dimensionless quantities,\n",
"# so we use the value attribute for Quantity objects to remove the units of the aperture sum\n",
Expand Down Expand Up @@ -801,7 +801,7 @@
"sky_coord = wcs.pixel_to_world(x, y) # a SkyCoord object\n",
"\n",
"# we can add the astropy SkyCoord object directly to the table\n",
"phot['sky_coord'] = sky_coord\n",
"phot['sky_center'] = sky_coord\n",
"phot"
]
},
Expand All @@ -811,7 +811,7 @@
"metadata": {},
"outputs": [],
"source": [
"phot['sky_coord'] # a SkyCoord object"
"phot['sky_center'] # a SkyCoord object"
]
},
{
Expand Down Expand Up @@ -884,7 +884,7 @@
"outputs": [],
"source": [
"# and the SkyCoord array\n",
"tbl['sky_coord']"
"tbl['sky_center']"
]
},
{
Expand Down Expand Up @@ -978,7 +978,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The [ApertureStats](https://photutils.readthedocs.io/en/latest/api/photutils.aperture.ApertureStats.html#photutils.aperture.ApertureStats) class can be used to create a catalog of statistics and properties for pixels within an aperture, including aperture photometry. \n",
"The [ApertureStats](https://photutils.readthedocs.io/en/stable/api/photutils.aperture.ApertureStats.html) class can be used to create a catalog of statistics and properties for pixels within an aperture, including aperture photometry. \n",
"\n",
"It can calculate many properties, including statistics like `min`, `max`, `mean`, `median`, `std`, `sum_aper_area`, and `sum`. It also can be used to calculate morphological properties like `centroid`, `fwhm`, `semimajor_sigma`, `semiminor_sigma`, `orientation`, and `eccentricity`. Please see `ApertureStats` for the the complete list of properties that can be calculated. The properties can be accessed using `ApertureStats` attributes or output to an Astropy `QTable` using the `to_table` method.\n",
"\n",
Expand Down Expand Up @@ -1122,7 +1122,7 @@
"\n",
"Hints:\n",
"\n",
"* The HST/WFC3 F160W ABmag zero point for data in units of e-/s is `25.9463`."
"* The HST/WFC3 F160W ABmag zero point for data in units of e-/s is `25.936`."
]
},
{
Expand Down Expand Up @@ -1195,7 +1195,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.1"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
4 changes: 1 addition & 3 deletions 09-Photutils/01-aperture_exercise_solution.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import astropy.units as u
import matplotlib.pyplot as plt
import numpy as np
from astropy.io import fits
from astropy.visualization import simple_norm
from photutils.aperture import CircularAperture, aperture_photometry

sci_fn = 'data/xdf_hst_wfc3ir_60mas_f160w_sci.fits'
Expand All @@ -20,7 +18,7 @@
snr = phot['aperture_sum'] / phot['aperture_sum_err']
phot['snr'] = snr

f160w_zpt = 25.9463
f160w_zpt = 25.936
abmag = -2.5 * np.log10(phot['aperture_sum'].value) + f160w_zpt
phot['f160w_abmag'] = abmag

Expand Down
3 changes: 3 additions & 0 deletions 09-Photutils/01-aperture_exercise_solution_plot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import matplotlib.pyplot as plt
from astropy.visualization import simple_norm

plt.figure(figsize=(5, 5))
norm = simple_norm(data, 'sqrt', percent=99.0)
plt.imshow(data, norm=norm)
Expand Down
10 changes: 5 additions & 5 deletions 09-Photutils/02-aperture_extended.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
}
},
"source": [
"We'll start by reading science data and error arrays from FITS files located in the [**data/**](data) subdirectory. The FITS files contain 2D cutout images from the [Hubble Extreme-Deep Field (XDF)](https://archive.stsci.edu/prepds/xdf/) taken with the [Wide Field Camera 3 (WFC3)](https://www.stsci.edu/hst/instrumentation/wfc3) IR channel in the F160W filter (centered at ~1.6 $\\mu m$)."
"We'll start by reading science data and error arrays from FITS files located in the **data/** subdirectory. The FITS files contain 2D cutout images from the [Hubble Extreme-Deep Field (XDF)](https://archive.stsci.edu/prepds/xdf/) taken with the [Wide Field Camera 3 (WFC3)](https://www.stsci.edu/hst/instrumentation/wfc3) IR channel in the F160W filter (centered at ~1.6 $\\mu m$)."
]
},
{
Expand Down Expand Up @@ -502,7 +502,7 @@
"\n",
"Instead of generating a big table with many columns (one for each radius), we'll simply loop over the apertures and extract the fluxes from individual tables.\n",
"\n",
"In this example, we manually compute the curve of growth using aperture photometry. However, note that Photutils has a [Radial Profiles subpackage](https://photutils.readthedocs.io/en/latest/profiles.html) that makes it easy to compute a radial profile or a curve of growth."
"In this example, we manually compute the curve of growth using aperture photometry. However, note that Photutils has a [Radial Profiles subpackage](https://photutils.readthedocs.io/en/stable/user_guide/profiles.html) that makes it easy to compute a radial profile or a curve of growth."
]
},
{
Expand Down Expand Up @@ -584,9 +584,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"All `PixelAperture` objects have a `to_mask` method that returns an [ApertureMask](https://photutils.readthedocs.io/en/latest/api/photutils.aperture.ApertureMask.html#photutils.aperture.ApertureMask) object (for a single aperture position) or a list of `ApertureMask` objects, one for each aperture position.\n",
"All `PixelAperture` objects have a `to_mask` method that returns an [ApertureMask](https://photutils.readthedocs.io/en/stable/api/photutils.aperture.ApertureMask.html) object (for a single aperture position) or a list of `ApertureMask` objects, one for each aperture position.\n",
"\n",
"The `ApertureMask` object contains a cutout of the aperture-mask weights and a [BoundingBox](https://photutils.readthedocs.io/en/latest/api/photutils.aperture.BoundingBox.html#photutils.aperture.BoundingBox) object that provides the bounding box where the mask is to be applied. The `ApertureMask` object is useful for extracting the data values within an aperture, either as a 1D or 2D array."
"The `ApertureMask` object contains a cutout of the aperture-mask weights and a [BoundingBox](https://photutils.readthedocs.io/en/stable/api/photutils.aperture.BoundingBox.html) object that provides the bounding box where the mask is to be applied. The `ApertureMask` object is useful for extracting the data values within an aperture, either as a 1D or 2D array."
]
},
{
Expand Down Expand Up @@ -802,7 +802,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.1"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions 09-Photutils/03-aperture_local_bkgsub.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
}
},
"source": [
"We'll start by reading science data and error arrays from FITS files located in the [**data/**](data) subdirectory. The FITS files contain 2D cutout images from the [Hubble Extreme-Deep Field (XDF)](https://archive.stsci.edu/prepds/xdf/) taken with the [Wide Field Camera 3 (WFC3)](https://www.stsci.edu/hst/instrumentation/wfc3) IR channel in the F160W filter (centered at ~1.6 $\\mu m$)."
"We'll start by reading science data and error arrays from FITS files located in the **data/** subdirectory. The FITS files contain 2D cutout images from the [Hubble Extreme-Deep Field (XDF)](https://archive.stsci.edu/prepds/xdf/) taken with the [Wide Field Camera 3 (WFC3)](https://www.stsci.edu/hst/instrumentation/wfc3) IR channel in the F160W filter (centered at ~1.6 $\\mu m$)."
]
},
{
Expand Down Expand Up @@ -460,7 +460,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.1"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
14 changes: 7 additions & 7 deletions 09-Photutils/04-segmentation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
}
},
"source": [
"We'll start by reading science data and error arrays from FITS files located in the [**data/**](data) subdirectory. The FITS files contain 2D cutout images from the [Hubble Extreme-Deep Field (XDF)](https://archive.stsci.edu/prepds/xdf/) taken with the [Wide Field Camera 3 (WFC3)](https://www.stsci.edu/hst/instrumentation/wfc3) IR channel in the F160W filter (centered at ~1.6 $\\mu m$)."
"We'll start by reading science data and error arrays from FITS files located in the **data/** subdirectory. The FITS files contain 2D cutout images from the [Hubble Extreme-Deep Field (XDF)](https://archive.stsci.edu/prepds/xdf/) taken with the [Wide Field Camera 3 (WFC3)](https://www.stsci.edu/hst/instrumentation/wfc3) IR channel in the F160W filter (centered at ~1.6 $\\mu m$)."
]
},
{
Expand Down Expand Up @@ -243,7 +243,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The result is a segmentation image ([SegmentationImage](https://photutils.readthedocs.io/en/stable/api/photutils.segmentation.SegmentationImage.html#photutils.segmentation.SegmentationImage) object). The segmentation image is an array with the same size as the science image in which each detected source is labeled with a unique integer value (>= 1). Background pixels have a value of 0. As a simple example, a segmentation map containing two distinct sources (labeled 1 and 2) might look like this:\n",
"The result is a segmentation image ([SegmentationImage](https://photutils.readthedocs.io/en/stable/api/photutils.segmentation.SegmentationImage.html) object). The segmentation image is an array with the same size as the science image in which each detected source is labeled with a unique integer value (>= 1). Background pixels have a value of 0. As a simple example, a segmentation map containing two distinct sources (labeled 1 and 2) might look like this:\n",
"\n",
"```\n",
"0 0 0 0 0 0 0 0 0 0\n",
Expand Down Expand Up @@ -294,7 +294,7 @@
}
},
"source": [
"Comparing the data array with the segmentation image, we see that several detected sources were blended together. We can deblend them using the [deblend_sources](https://photutils.readthedocs.io/en/stable/api/photutils.segmentation.deblend_sources.html#photutils.segmentation.deblend_sources) function, which uses a combination of multi-thresholding and watershed segmentation.\n",
"Comparing the data array with the segmentation image, we see that several detected sources were blended together. We can deblend them using the [deblend_sources](https://photutils.readthedocs.io/en/stable/api/photutils.segmentation.deblend_sources.html) function, which uses a combination of multi-thresholding and watershed segmentation.\n",
"\n",
"The amount of deblending can be controlled with the two `deblend_sources` keywords `nlevels` and `contrast`:\n",
"\n",
Expand Down Expand Up @@ -399,7 +399,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The [SourceCatalog](https://photutils.readthedocs.io/en/stable/api/photutils.segmentation.SourceCatalog.html#photutils.segmentation.SourceCatalog) class is the primary tool for measuring the photometry, centroids, and shape/morphological properties of sources defined in a segmentation image. In its most basic form, it takes as input the (background-subtracted) image and the segmentation image. Usually the convolved image is also input, from which the source centroids and shape/morphological properties are measured (if not input, the unconvolved image is used instead)."
"The [SourceCatalog](https://photutils.readthedocs.io/en/stable/api/photutils.segmentation.SourceCatalog.html) class is the primary tool for measuring the photometry, centroids, and shape/morphological properties of sources defined in a segmentation image. In its most basic form, it takes as input the (background-subtracted) image and the segmentation image. Usually the convolved image is also input, from which the source centroids and shape/morphological properties are measured (if not input, the unconvolved image is used instead)."
]
},
{
Expand Down Expand Up @@ -432,7 +432,7 @@
"\n",
"Here we’ll use the `to_table` method to generate a `QTable` of source photometry and properties. Each row in the table represents a source. The columns represent the calculated source properties. The label column corresponds to the label value in the input segmentation image.\n",
"\n",
"Please see the [SourceCatalog documentation](https://photutils.readthedocs.io/en/latest/api/photutils.segmentation.SourceCatalog.html#photutils.segmentation.SourceCatalog) for a complete list of the available source properties."
"Please see the [SourceCatalog documentation](https://photutils.readthedocs.io/en/stable/api/photutils.segmentation.SourceCatalog.html) for a complete list of the available source properties."
]
},
{
Expand Down Expand Up @@ -665,7 +665,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The [**data/**](data) subdirectory also contains a WFC3/IR F105W image of the same field used for the preceding examples. The F105W and F160W images are pixel aligned, so sources in the F105W image are located at the same pixel positions as the F160W image (if they are visible in the F105W image)."
"The **data/** subdirectory also contains a WFC3/IR F105W image of the same field used for the preceding examples. The F105W and F160W images are pixel aligned, so sources in the F105W image are located at the same pixel positions as the F160W image (if they are visible in the F105W image)."
]
},
{
Expand Down Expand Up @@ -766,7 +766,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.1"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions 09-Photutils/04-segmentation_exercise2_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
f105w_cat = SourceCatalog(f105w_data, f160w_segm)

# calculate the AB magnitudes using the filter zero points
f105w_abmag = -2.5 * np.log10(f105w_cat.segment_flux.value) + 26.2687
f160w_abmag = -2.5 * np.log10(f160w_tbl['segment_flux'].value) + 26.9463
f105w_abmag = -2.5 * np.log10(f105w_cat.segment_flux.value) + 26.264
f160w_abmag = -2.5 * np.log10(f160w_tbl['segment_flux'].value) + 25.936

# calculate the Y-H colors
yh_colors = f105w_abmag - f160w_abmag
Expand Down
4 changes: 2 additions & 2 deletions 09-Photutils/05-psf_photometry.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
"source": [
"fit_shape = (5, 5)\n",
"fit_shape = 5\n",
"finder= DAOStarFinder(6.0, 2.0)\n",
"finder = DAOStarFinder(6.0, 2.0)\n",
"psfphot = PSFPhotometry(psf_model, fit_shape, finder=finder, aperture_radius=5, progress_bar=True)"
]
},
Expand Down Expand Up @@ -430,7 +430,7 @@
"id": "245f9dbb-95ea-4421-a331-e08b81bb05ca",
"metadata": {},
"source": [
"Please consult the [PSF Photometry documentation](https://photutils.readthedocs.io/en/1.10.0/psf.html) for additional features including:\n",
"Please consult the [PSF Photometry documentation](https://photutils.readthedocs.io/en/stable/user_guide/psf.html) for additional features including:\n",
"\n",
"- Fitting a single (or few) sources in an image\n",
"- Forced Photometry\n",
Expand Down