Skip to content
Merged
1,225 changes: 1,225 additions & 0 deletions DP2/300_Science_demos/303_Galaxies/303_1_Galaxy_photometry.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@
"id": "325aa8a5-92fd-4913-a471-ad1617343be6",
"metadata": {},
"source": [
"# 303.2. Galaxy Shapes in DP2\n",
"# 303.2. Galaxy shapes in DP2\n",
"\n",
"<div style=\"max-width:300px; float: left; margin-right: 1em\">\n",
"\n",
"![logo.png](attachment:b3f74554-30d1-4f62-94e5-92dd84359107.png)\n",
"\n",
"</div>\n",
"\n",
"For the Rubin Science Platform at data.lsst.cloud. <br>\n",
"Data Release: <a href=\"https://dp2.lsst.io/\">Data Preview 2</a> <br>\n",
"Container Size: Large <br>\n",
"LSST Science Pipelines version: r30.0.10 <br>\n",
"Last verified to run: 2026-08-18 <br>\n",
"Repository: <a href=\"https://github.com/lsst/tutorial-notebooks\">github.com/lsst/tutorial-notebooks</a> <br>"
"For the Rubin Science Platform at data.lsst.cloud.\\\n",
"Data Release: [Data Preview 2](https://dp2.lsst.io/)\\\n",
"Container Size: Large\\\n",
"LSST Science Pipelines version: r30.0.11\\\n",
"Last verified to run: 2026-09-04\\\n",
"Repository: [github.com/lsst/tutorial-notebooks](https://github.com/lsst/tutorial-notebooks)\\\n",
"DOI: [10.11578/rubin/dc.20250909.20](https://doi.org/10.11578/rubin/dc.20250909.20)"
]
},
{
Expand Down Expand Up @@ -97,9 +98,8 @@
"import matplotlib.pyplot as plt\n",
"import io\n",
"\n",
"from pyvo.dal.adhoc import DatalinkResults, SodaQuery\n",
"from pyvo.dal.adhoc import SodaQuery\n",
"\n",
"from astropy.wcs import WCS\n",
"from astropy.coordinates import SkyCoord\n",
"import astropy.units as u\n",
"\n",
Expand All @@ -110,7 +110,6 @@
"import lsst.afw.display as afwDisplay\n",
"import lsst.afw.geom.ellipses as ellipses\n",
"from lsst.gauss2d import Ellipse, EllipseMajor, Covariance\n",
"import lsst.images\n",
"from lsst.images.serialization import read_archive\n",
"\n",
"import galsim as gs"
Expand Down Expand Up @@ -151,7 +150,7 @@
" -------\n",
" cutout : 'lsst.images object'\n",
" \"\"\"\n",
" \n",
"\n",
" sia_client = discovery.get_sia_client()\n",
"\n",
" eff_wl = 622.1e-09\n",
Expand Down Expand Up @@ -182,7 +181,7 @@
" sq.circle = (cutout_ra, cutout_dec, Radius)\n",
" cutout_bytes = sq.execute_stream().read()\n",
" sq.raise_if_error()\n",
" \n",
"\n",
" cutout = read_archive(io.BytesIO(cutout_bytes))\n",
" return cutout"
]
Expand Down Expand Up @@ -222,7 +221,7 @@
"metadata": {},
"outputs": [],
"source": [
"afwDisplay.setDefaultBackend('matplotlib')\n"
"afwDisplay.setDefaultBackend('matplotlib')"
]
},
{
Expand All @@ -241,9 +240,7 @@
"outputs": [],
"source": [
"discovery = RSPDiscovery(\"dp2\")\n",
"service = discovery.get_tap_client()\n",
"\n",
"assert service is not None"
"service = discovery.get_tap_client()"
]
},
{
Expand Down Expand Up @@ -380,7 +377,7 @@
"id": "265a726e-38a3-4767-bbb1-dc1126927a5d",
"metadata": {},
"source": [
"### 3.1 Gaussian ellipse \n",
"### 3.1. Gaussian ellipse \n",
"\n",
"In the next cell, use `Object` table shape parameters to reconstruct the galaxy shape, approximated as a 2D Gaussian. The LSST pipelines measures this shape, parameterized by three parameters or \"moments\" measured on the `deep_coadd` in each band individually: `<band>_ixx`, `<band>_iyy`, `<band>_ixy` (weak lensing experts may recognize these come from the measured re-Gaussianization method of <a href=\"https://ui.adsabs.harvard.edu/abs/2003MNRAS.343..459H/abstract\">Hirata & Seljak 2003</a>, implemented by <a href=\"https://ui.adsabs.harvard.edu/abs/2005MNRAS.361.1287M/abstract\">Mandelbaum et al. 2005</a>, and called HSM moments. The corresponding moments measured on the reference band or `refBand` are also stored as `shape_xx`, `shape_yy`, and `shape_xy`. These moments have not been corrected for the point spread function (PSF; thus not applicable for weak lensing) but PSF effects are small for galaxy sizes much larger than the PSF. These shape parameters can be converted to more commonly used set of morphological parameters using the LSST package `ellipses`. \n",
"\n",
Expand Down Expand Up @@ -462,7 +459,7 @@
"id": "25d6f1f5-c09b-4442-b2a1-d333a2cd510c",
"metadata": {},
"source": [
"### 3.2 Kron ellipse\n",
"### 3.2. Kron ellipse\n",
"\n",
"In the next cell, reconstruct the Kron aperture. The method of the Kron implementation in the LSST pipelines is to use the `Object` table parameter `<band>_kronRad`, in combination with the same axis-ratio and rotation angle that come from the Gaussian shape parameters from section 3.1.\n",
"\n",
Expand Down Expand Up @@ -510,9 +507,9 @@
"id": "88d3dc48-b511-4f1a-83ef-ebd526912402",
"metadata": {},
"source": [
"### 3.3 Sersic profiles\n",
"### 3.3. Sersic profiles\n",
"\n",
"#### 3.3.1 Sersic parameters in x-y\n",
"#### 3.3.1. Sersic parameters in x-y\n",
"\n",
"Convert the Sersic morphological parameters stored in the `Object` table (the effective Sersic radii in x and y directions, `sersic_reff_x`, `sersic_reff_y`, and the correlation coefficient from the multiband Sersic model fit `sersic_rho` that is related to orientation angle) into the more conventional sersic parameters (axis ratio `ba` defined as the ratio of the semi-minor half-light radius divided to semi-major half-light radius, the position angle `pa`, and the semi-major half-light radius `r_major`). The position angle (`pa`) convention is counter-clockwise relative to the x-axis. In this case, return the `pa` in units of degrees instead of the previous example in radians, to demonstrate its use with `photutils`."
]
Expand Down Expand Up @@ -570,8 +567,8 @@
"source": [
"cutout_size = 0.008\n",
"\n",
"cutout = make_image_cutout(tab['coord_ra'][0],\n",
" tab['coord_dec'][0], cutout_size=cutout_size)"
"cutout = make_image_cutout(tab['coord_ra'][0], tab['coord_dec'][0],\n",
" cutout_size=cutout_size)"
]
},
{
Expand All @@ -596,7 +593,7 @@
"plt.subplot(projection=astropy_wcs)\n",
"\n",
"plt.imshow(cutout.image.array, origin='lower', cmap='gray', vmin=1,\n",
" vmax=1000, norm='asinh',aspect='equal')\n",
" vmax=1000, norm='asinh', aspect='equal')\n",
"\n",
"gaussell_pix_ellipse = gaussell_ellipse.to_pixel(astropy_wcs)\n",
"gaussell_pix_ellipse.plot(color=colors[0], lw=3, label='Gaussian (shape) ellipse')\n",
Expand Down Expand Up @@ -641,7 +638,7 @@
"id": "bfd70329-c439-413b-8de1-521b7f975809",
"metadata": {},
"source": [
"### 4.1 Standard Sersic parameters\n",
"### 4.1. Standard Sersic parameters\n",
"\n",
"New in DP2, the `Object` table now contains standard Sersic parameters (semi-major and minor half-light radii, position angle) which can be used in place of the x-y parameters that were needed in DP1. For this section, as a demonstration, replace those calculated in Section 3.3.1 using the x-y Sersic parameters with the ones stored in the `Object` table."
]
Expand Down Expand Up @@ -678,7 +675,7 @@
" flux=tab['i_sersicFlux'][0]).shear(q=ba, beta=pa * gs.degrees)\n",
"img_h, img_w = cutout.image.array.shape\n",
"\n",
"sersic_model = sersic.drawImage(nx=img_w, ny=img_h, scale=arcsec_per_pix).array\n",
"sersic_model = sersic.drawImage(nx=img_w, ny=img_h, scale=arcsec_per_pix).array\n",
"\n",
"print('Total flux of model = ', np.sum(sersic_model),\n",
" 'nJy, very close to flux from Object table = ',\n",
Expand Down Expand Up @@ -725,11 +722,11 @@
"outputs": [],
"source": [
"ba = tab['exponential_reff_minor'][0]/tab['exponential_reff_major'][0]\n",
"use_beta = (tab['exponential_theta'][0] + 90) * gs.degrees\n",
"sm = gs.Sersic(n=1, half_light_radius=tab['exponential_reff_major'][0] * np.sqrt(ba),\n",
" flux=tab['i_exponentialFlux'][0]).shear(q=ba,\n",
" beta=(tab['exponential_theta'][0] + 90) * gs.degrees)\n",
" flux=tab['i_exponentialFlux'][0]).shear(q=ba, beta=use_beta)\n",
"\n",
"exp_model = sm.drawImage(nx=img_w, ny=img_h, scale=arcsec_per_pix).array\n",
"exp_model = sm.drawImage(nx=img_w, ny=img_h, scale=arcsec_per_pix).array\n",
"\n",
"print('Total flux of model = ', np.sum(exp_model), 'nJy, very close to flux from Object table = ',\n",
" tab['i_exponentialFlux'][0], ' nJy')\n",
Expand Down Expand Up @@ -818,7 +815,7 @@
"source": [
"Next, have `galsim` generate an image of the best `cModel` shape.\n",
"\n",
"> Note: de Vaucouleurs profiles have sharp central cusps and also large wings which ideally requires a large grid of frequencies for the Fast Fourier Transform (FFT). Since we are only trying to visualize the light profile and are not concerned with re-calculating photometry with high accuracy, this warning can be safely ignored. "
"> **Warning**: The following cell produces a pink warning message that is safe to ignore. It appears because the de Vaucouleurs profiles have sharp central cusps and also large wings which ideally requires a large grid of frequencies for the Fast Fourier Transform (FFT). Because this demonstration is only visualizing the light profile, and is not concerned with re-calculating photometry with high accuracy, this warning can be safely ignored. "
]
},
{
Expand Down Expand Up @@ -920,7 +917,7 @@
"print('Total flux of model = ', np.sum(img_w_psf), 'nJy, very close to flux from Object table = ',\n",
" tab['i_cModelFlux'][0], ' nJy')\n",
"\n",
"plt.title(f\"Reconstructed cModel (convolved with PSF)\")\n",
"plt.title(\"Reconstructed cModel (convolved with PSF)\")\n",
"plt.colorbar(label='Pixel Flux')\n",
"plt.show()"
]
Expand Down
1,023 changes: 1,023 additions & 0 deletions DP2/300_Science_demos/303_Galaxies/303_3_Color_selections.ipynb

Large diffs are not rendered by default.

Loading