105.3. Forced photometry#
105.3. Forced photometry¶
For the Rubin Science Platform at data.lsst.cloud.
Data Release: Data Preview 2
Container Size: Large
LSST Science Pipelines version: r30.0.11
Last verified to run: 2026-11-16
Repository: github.com/lsst/tutorial-notebooks
DOI: 10.11578/rubin/dc.20250909.20
Learning objective: Make forced measurements on an image for a set of coordinates.
LSST data products: deep_coadd, Object table
Packages: lsst.pipe.tasks, lsst.daf.butler
Credit: Originally developed by the Rubin Community Science team working with Erfan Nourbakhsh. Please consider acknowledging them if this notebook is used for the preparation of journal articles, software releases, or other notebooks.
Get Support: Everyone is encouraged to ask questions or raise issues in the Support Category of the Rubin Community Forum. Rubin staff will respond to all questions posted there.
Warning: This tutorial makes use of an
ExposureFobject because the pipeline tasks being demonstrated currently require this. However,ExposureFobjects are being deprecated in favor oflsst.imagesobjects (https://images.lsst.io/).
1. Introduction¶
In general, "forced" photometry refers to a measurement made at a fixed coordinate in an image, regardless of whether an above-threshold (SNR $>5$) source was detected at that location in that particular image. Forced photometry uses the point-spread-function (PSF) of the image, and measures the flux assuming the shape and size of the PSF at the provided coordinates.
This notebook performs forced photometry using the Data Preview 2 (DP2) data products on an input image, given a set of input coordinates (RA/Dec).
The ForcedMeasurementDriverTask serves as a convenience function, allowing users to measure sources without running a full-scale pipetask command or dealing with additional pipeline setup.
This task can measure fluxes, shapes, and other properties at known source positions (e.g., from a pre-existing catalog) on a given image, without running source detection.
For brevity, shape measurement is disabled in this tutorial.
Related tutorials: The 100-level tutorial on how to detect and measure sources, which was used to create the input file of sub-threshold detections used later in this tutorial. The 200-level tutorials on the PSF.
1.1. Import packages¶
Import standard python packages numpy, matplotlib, and astropy.
From the lsst package, import the TAP service (RSPDiscovery) and the Butler for data access, and ForcedMeasurementDriverConfig and ForcedMeasurementDriverTask: mid-level configuration and task classes used to set up and execute forced photometry.
import matplotlib.pyplot as plt
import numpy as np
import astropy.units as u
from astropy.table import Table
from lsst.rsp import RSPDiscovery
from lsst.daf.butler import Butler
from lsst.pipe.tasks.measurementDriver import (
ForcedMeasurementDriverConfig,
ForcedMeasurementDriverTask,
)
1.2. Define parameters and functions¶
Create an instance of the butler, and assert that it exists.
butler = Butler("dp2", collections="dp2")
assert butler is not None
Instantiate the TAP service and assert that it exists.
discovery = RSPDiscovery("dp2")
service = discovery.get_tap_client()
assert service is not None
Create a function called fix_flux_columns to rename output columns from the forced measurement task that are incorrectly labeled as instrument fluxes, when they are in fact not instrumental (i.e., in units of counts) but are calibrated fluxes in units of nJy.
This mistake will be fixed in future versions of the LSST Science Pipelines.
def fix_flux_columns(table):
"""Rename the columns in an output table from the ForcedMeasurementDriverTask.
This task is necessary to rename "instFlux" columns to "flux" and units from
"ct" to "nJy".
Parameters
----------
table : Astropy Table
An Astropy table resulting from executing the ForcedMeasurementDriver
Outputs
-------
table : Astropy Table
Transformed version of the input table, with columns and units updated.
"""
cols_with_instflux = [col for col in np.array(table.colnames) if 'instFlux' in col]
for col in cols_with_instflux:
new_colname = str.replace(col, 'instFlux', 'flux')
table.rename_column(col, new_colname)
table[new_colname].unit = u.nJy
return table
2. Measure objects in a deep coadd¶
Note: The fluxes in the Object catalog are already forced photometry measurements, and re-measuring them is not necessary for scientific analysis. The Object table is just used to get a set of coordinates for this tutorial.
2.1. Load an image and catalog¶
Identify coadded images overlapping a particular sky position and select one to run forced photometry on. Also load the corresponding Object table using the TAP service so that forced photometry can be run at the positions of already-detected objects.
Adopt Right Ascension and Declination values near the center of the ECDFS field, and use the $r$ band.
ra = 53.1
dec = -28.1
band = 'r'
Execute a butler query for deep coadd images.
query = f"band='{band}' AND \
patch.region OVERLAPS POINT({ra}, {dec})"
coadd_img_refs = butler.query_datasets('deep_coadd', where=query,
order_by='patch')
Assert that at least one matching image was returned. Retrieve the first in the sorted list.
assert len(coadd_img_refs) > 0
ref = coadd_img_refs[0]
deep_coadd = butler.get(ref)
Query for point-like objects from the Object table in a 0.3 degree radius near the position of interest that overlap the deep coadd image's tract and patch.
query = f"""SELECT TOP 50 objectId, coord_ra, coord_dec, {band}_psfMag, {band}_psfFlux
FROM dp2.Object
WHERE CONTAINS(POINT('ICRS', coord_ra, coord_dec), CIRCLE('ICRS', {ra}, {dec}, 0.3)) = 1
AND refExtendedness < 0.5
AND {band}_psfMag < 26 AND {band}_psfMag > 17
AND tract = {ref.dataId['tract']}
AND patch = {ref.dataId['patch']}"""
job = service.submit_job(query)
job.run()
job.wait(phases=['COMPLETED', 'ERROR'])
print('Job phase is', job.phase)
if job.phase == 'ERROR':
job.raise_if_error()
Job phase is COMPLETED
Retrieve the search results as objtable.
This table will be used both as an input list for forced measurement, and as a comparison for the results.
assert job.phase == 'COMPLETED'
objtable = job.fetch_result().to_table()
Assert that the objtable is not empty.
assert len(objtable) > 0
Option to display the objtable.
# objtable
2.2. Run the forced measurement driver¶
Configure the forced measurement driver to use base_PsfFlux as the algorithm for the PSF flux slot, and base_TransformedCentroidFromCoord for centroids transformed from the reference catalog. Set other config parameters to disable shape measurement and avoid replacing other detected footprints with noise. These are simply examples of how to set configuration options, and are not required to run the task. Aperture corrections are not applied by the driver, because the ExposureF version of a cell-based coadd, which the driver requires, cannot carry the cell coadd’s aperture corrections. The corrections themselves are available from the CellCoadd (in its aperture_corrections attribute), and could be evaluated at each source’s position and applied to the forced fluxes after measurement.
Note: base_PsfFlux and base_TransformedCentroidFromCoord are included by default in the measurement plugins, so there's no need to add them manually to config.measurement.plugins.names. They’ll be picked up automatically.
config = ForcedMeasurementDriverConfig()
config.measurement.slots.psfFlux = "base_PsfFlux"
config.measurement.slots.centroid = "base_TransformedCentroidFromCoord"
config.measurement.slots.shape = None
config.measurement.doReplaceWithNoise = False
Option to examine the configuration.
# config
Create the forced photometry driver task using the configuration.
driver = ForcedMeasurementDriverTask(config=config)
ForcedMeasurementDriverTask requires the image to be of type ExposureF, so convert the deep coadd to type ExposureF here. However, users should in general use lsst.images image formats whenever possible rather than ExposureF.
legacy_coadd = deep_coadd.to_legacy()
Run the task using the input table of source positions and IDs, the legacy_coadd image, and required parameters: column names for ID, RA, and Dec, plus a PSF footprint scaling factor (used to create synthetic footprints since detection is skipped in forced photometry).
result = driver.runFromAstropy(
objtable,
legacy_coadd,
id_column_name="objectId",
ra_column_name="coord_ra",
dec_column_name="coord_dec",
psf_footprint_scaling=3.0,
)
lsst.forcedMeasurementDriver INFO: Measuring 50 sources in a single band using 'ForcedMeasurementTask'
lsst.forcedMeasurementDriver.measurement INFO: Performing forced measurement on 50 sources
lsst.forcedMeasurementDriver INFO: Finished processing for a single band; output catalog has 85 fields and 50 records
Because the ForcedMeasurementDriverTask relies on code that is typically used in early stages of data processing, it assumes that fluxes are instrumental fluxes and appends the suffixes _instFlux and _instFluxErr to the output columns.
It also sets the units for these columns to "ct" (counts).
However, these assumptions about the types of fluxes are incorrect when running this task on calibrated visit and deep coadd images, whose pixel values are in nJy.
Confirm that the pixel values are in units of nJy.
deep_coadd.unit
Use the function defined in Section 1.2 to fix the column names. This step is temporary as the column names will be fixed in the future.
result = fix_flux_columns(result)
Examine the resulting Astropy table containing the measured sources. Each row corresponds to a record from the input table, with columns for source ID, RA, and Dec, along with additional measurement fields defined by the configuration.
result[:5]
| coord_ra | coord_dec | parent | objectId | parentObjectId | deblend_nChild | base_TransformedCentroidFromCoord_x | slot_Centroid_x | base_TransformedCentroidFromCoord_y | slot_Centroid_y | base_CircularApertureFlux_3_0_flux | base_CircularApertureFlux_3_0_fluxErr | base_CircularApertureFlux_3_0_flag | base_CircularApertureFlux_3_0_flag_apertureTruncated | base_CircularApertureFlux_3_0_flag_sincCoeffsTruncated | base_CircularApertureFlux_4_5_flux | base_CircularApertureFlux_4_5_fluxErr | base_CircularApertureFlux_4_5_flag | base_CircularApertureFlux_4_5_flag_apertureTruncated | base_CircularApertureFlux_4_5_flag_sincCoeffsTruncated | base_CircularApertureFlux_6_0_flux | base_CircularApertureFlux_6_0_fluxErr | base_CircularApertureFlux_6_0_flag | base_CircularApertureFlux_6_0_flag_apertureTruncated | base_CircularApertureFlux_6_0_flag_sincCoeffsTruncated | base_CircularApertureFlux_9_0_flux | base_CircularApertureFlux_9_0_fluxErr | base_CircularApertureFlux_9_0_flag | base_CircularApertureFlux_9_0_flag_apertureTruncated | base_CircularApertureFlux_9_0_flag_sincCoeffsTruncated | base_CircularApertureFlux_12_0_flux | base_CircularApertureFlux_12_0_fluxErr | base_CircularApertureFlux_12_0_flag | base_CircularApertureFlux_12_0_flag_apertureTruncated | base_CircularApertureFlux_17_0_flux | base_CircularApertureFlux_17_0_fluxErr | base_CircularApertureFlux_17_0_flag | base_CircularApertureFlux_17_0_flag_apertureTruncated | base_CircularApertureFlux_25_0_flux | base_CircularApertureFlux_25_0_fluxErr | base_CircularApertureFlux_25_0_flag | base_CircularApertureFlux_25_0_flag_apertureTruncated | base_CircularApertureFlux_35_0_flux | base_CircularApertureFlux_35_0_fluxErr | base_CircularApertureFlux_35_0_flag | base_CircularApertureFlux_35_0_flag_apertureTruncated | base_CircularApertureFlux_50_0_flux | base_CircularApertureFlux_50_0_fluxErr | base_CircularApertureFlux_50_0_flag | base_CircularApertureFlux_50_0_flag_apertureTruncated | base_CircularApertureFlux_70_0_flux | base_CircularApertureFlux_70_0_fluxErr | base_CircularApertureFlux_70_0_flag | base_CircularApertureFlux_70_0_flag_apertureTruncated | base_PixelFlags_flag | base_PixelFlags_flag_offimage | base_PixelFlags_flag_edge | base_PixelFlags_flag_nodata | base_PixelFlags_flag_interpolated | base_PixelFlags_flag_saturated | base_PixelFlags_flag_cr | base_PixelFlags_flag_bad | base_PixelFlags_flag_suspect | base_PixelFlags_flag_edgeCenter | base_PixelFlags_flag_nodataCenter | base_PixelFlags_flag_interpolatedCenter | base_PixelFlags_flag_saturatedCenter | base_PixelFlags_flag_crCenter | base_PixelFlags_flag_badCenter | base_PixelFlags_flag_suspectCenter | base_PixelFlags_flag_edgeCenterAll | base_PixelFlags_flag_nodataCenterAll | base_PixelFlags_flag_interpolatedCenterAll | base_PixelFlags_flag_saturatedCenterAll | base_PixelFlags_flag_crCenterAll | base_PixelFlags_flag_badCenterAll | base_PixelFlags_flag_suspectCenterAll | base_PsfFlux_flux | slot_PsfFlux_flux | base_PsfFlux_fluxErr | slot_PsfFlux_fluxErr | base_PsfFlux_area | slot_PsfFlux_area | base_PsfFlux_chi2 | slot_PsfFlux_chi2 | base_PsfFlux_npixels | slot_PsfFlux_npixels | base_PsfFlux_flag | slot_PsfFlux_flag | base_PsfFlux_flag_noGoodPixels | slot_PsfFlux_flag_noGoodPixels | base_PsfFlux_flag_edge | slot_PsfFlux_flag_edge | base_InvalidPsf_flag |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| rad | rad | pix | pix | pix | pix | nJy | nJy | nJy | nJy | nJy | nJy | nJy | nJy | nJy | nJy | nJy | nJy | nJy | nJy | nJy | nJy | nJy | nJy | nJy | nJy | nJy | nJy | nJy | nJy | pix | pix | pix | pix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| float64 | float64 | int64 | int64 | int64 | int32 | float64 | float64 | float64 | float64 | float64 | float64 | bool | bool | bool | float64 | float64 | bool | bool | bool | float64 | float64 | bool | bool | bool | float64 | float64 | bool | bool | bool | float64 | float64 | bool | bool | float64 | float64 | bool | bool | float64 | float64 | bool | bool | float64 | float64 | bool | bool | float64 | float64 | bool | bool | float64 | float64 | bool | bool | bool | bool | bool | bool | bool | bool | bool | bool | bool | bool | bool | bool | bool | bool | bool | bool | bool | bool | bool | bool | bool | bool | bool | float64 | float64 | float64 | float64 | float32 | float32 | float32 | float32 | int32 | int32 | bool | bool | bool | bool | bool | bool | bool |
| 0.9294947549469645 | -0.49092510675066225 | 0 | 755369573523392182 | 0 | 0 | 12322.95630933277 | 12322.95630933277 | 4065.7753885797774 | 4065.7753885797774 | 108.91565704345703 | 21.735374450683594 | False | False | False | 128.52635192871094 | 32.70494842529297 | False | False | False | 192.19970703125 | 43.78263854980469 | False | False | False | 176.27334594726562 | 66.03450775146484 | False | False | False | 149.46380841732025 | 88.89865859728553 | False | False | 286.200607419014 | 125.81807930216019 | False | False | 520.4032746553421 | 186.15053439046966 | False | False | 3248.0369876623154 | 276.30719507798676 | False | False | 5249.594314813614 | 417.0079822828307 | False | False | 9269.24615252018 | 606.4056465725844 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | 180.2006258262286 | 180.2006258262286 | 36.72323540890552 | 36.72323540890552 | 76.85476 | 76.85476 | 1099.0295 | 1099.0295 | 1225 | 1225 | False | False | False | False | False | False | False |
| 0.9276529904199908 | -0.4909290195078257 | 0 | 755369573523392174 | 0 | 0 | 13998.182137986985 | 13998.182137986985 | 4063.335988157336 | 4063.335988157336 | 215.65512084960938 | 24.409852981567383 | False | False | False | 356.0856018066406 | 36.46016311645508 | False | False | False | 418.28778076171875 | 48.847991943359375 | False | False | False | 420.7357177734375 | 72.64543151855469 | False | False | False | 343.1510456800461 | 97.05032455020587 | False | False | 258.4669065475464 | 136.3971407615811 | False | False | 181.79527473449707 | 199.5839169769142 | False | False | 658.5095093250275 | 276.3322227564614 | False | False | 1580.9449481964111 | 389.2196565119027 | False | False | 10668.209899425507 | 538.9618921308639 | False | False | False | False | False | False | False | True | False | False | False | False | False | False | True | False | False | False | False | False | False | True | False | False | False | 406.0645322872526 | 406.0645322872526 | 40.89182531340214 | 40.89182531340214 | 76.17635 | 76.17635 | 1236.2097 | 1236.2097 | 1225 | 1225 | False | False | False | False | False | False | False |
| 0.9285272815803919 | -0.4909529509090676 | 0 | 755369573523392145 | 0 | 0 | 13202.97356352795 | 13202.97356352795 | 4038.0757107004356 | 4038.0757107004356 | 87.92168426513672 | 22.118722915649414 | False | False | False | 135.82391357421875 | 33.32065200805664 | False | False | False | 139.2987060546875 | 44.69348907470703 | False | False | False | 208.1266632080078 | 67.37799835205078 | False | False | False | 92.7037810087204 | 89.77689471836062 | False | False | -6.9043461084365845 | 127.70877644813085 | False | False | 307.0156193971634 | 188.2261736205589 | False | False | 7405.01281619072 | 264.01074576905154 | False | False | 37385.492900013924 | 377.4317745274139 | False | False | 43878.07745540142 | 527.7252060249118 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | 175.93494069744773 | 175.93494069744773 | 37.52365414997515 | 37.52365414997515 | 77.141846 | 77.141846 | 1249.806 | 1249.806 | 1225 | 1225 | False | False | False | False | False | False | False |
| 0.9276431262771949 | -0.49089706930719057 | 0 | 755369573523392218 | 0 | 0 | 14007.137677745844 | 14007.137677745844 | 4096.295336045192 | 4096.295336045192 | 167.11087036132812 | 22.148574829101562 | False | False | False | 249.91323852539062 | 33.20283508300781 | False | False | False | 265.0390930175781 | 44.45890426635742 | False | False | False | 281.19549560546875 | 67.0239486694336 | False | False | False | 232.3135015964508 | 90.44914270841383 | False | False | -26.197577476501465 | 127.92550761748528 | False | False | -82.71895563602448 | 187.96679213622784 | False | False | 526.5014535188675 | 264.8544977884637 | False | False | 2334.0343874692917 | 382.7844900815802 | False | False | 8046.372070789337 | 538.2289378026977 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | 318.70548253171444 | 318.70548253171444 | 37.206654983236334 | 37.206654983236334 | 76.19508 | 76.19508 | 1289.4988 | 1289.4988 | 1225 | 1225 | False | False | False | False | False | False | False |
| 0.9266656075394462 | -0.490918412694609 | 0 | 755369573523392193 | 0 | 0 | 14896.276572770686 | 14896.276572770686 | 4074.5331401796047 | 4074.5331401796047 | 203.54505920410156 | 22.796859741210938 | False | False | False | 289.38671875 | 34.07534408569336 | False | False | False | 385.1264343261719 | 45.67351531982422 | False | False | False | 479.4609069824219 | 68.83203887939453 | False | False | False | 453.5571701526642 | 93.09562619237224 | False | False | 431.8891874551773 | 131.42201423932443 | False | False | 191.43079698085785 | 193.21073308357543 | False | False | 541.0727775096893 | 270.50836792728404 | False | False | 2916.392729282379 | 386.4249590782691 | False | False | 7468.072153687477 | 541.047746056837 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | 390.02719733849364 | 390.02719733849364 | 38.58748551042744 | 38.58748551042744 | 77.76878 | 77.76878 | 1330.1981 | 1330.1981 | 1225 | 1225 | False | False | False | False | False | False | False |
The table now includes PSF fluxes (base_psfFlux_flux) and aperture fluxes (e.g., base_CircularApertureFlux_3_0_flux for a 3-pixel aperture), among many other columns.
Most of the output columns are similar to columns that exist in the Source table -- refer to the schema for the DP2 Source table and the 200-level tutorial notebook on the Source catalog for descriptions.
Each flux measurement has an associated flux error and one or more flag columns to allow filtering of bad measurements. Additionally, there are many pixel-based flags (denoted base_PixelFlags_*) highlighting possible issues with the data for each source.
Columns that begin with slot_ are duplicates of other columns in the table.
These exist as a way of telling algorithms in the Science Pipelines which is the "preferred" measurement for things like positions, shapes, and fluxes.
Because there are multiple ways of measuring shapes (for example), this lets processing algorithms know which of these to select.
Note that the specific measurements populating (some of) the slots were configured above, for example config.measurement.slots.psfFlux = "base_PsfFlux" was specified.
The forced measurement functionality is limited to a handful of measurement plugins (for example, model-fitting algorithms will not work with this task because they require more ancillary information than it is set up to receive). Nonetheless, it offers a quick and easy way to extract measurements at arbitrary positions.
2.3. Compare forced measurements to the Object table¶
Make a plot showing the ratio of the measured PSF fluxes from the forced measurement task to the psfFlux for the same objects in the Object table. Plot these as a function of magnitude, using Astropy units to convert slot_PsfFlux_flux from the result table to AB magnitudes.
meas_mag = (result['slot_PsfFlux_flux'].value*u.nJy).to(u.ABmag)
fig, ax = plt.subplots(figsize=(6, 4))
ax.plot(meas_mag, result['slot_PsfFlux_flux']/objtable['r_psfFlux'],
'o', alpha=0.5, mew=1, mec='black', color='black')
ax.hlines(1.0, 17.3, 26.3, linestyle=':', color='gray')
ax.set_xlim(17.3, 26.3)
ax.set_xlabel('force-measured PSF magnitude')
ax.set_ylabel('flux ratio (forced / Object)')
plt.show()
Figure 1: The flux ratio of the force-measured PSF flux divided by the PSF flux from the
Objecttable, vs. the force-measured PSF magnitude (all for $r$-band).
The plot above demonstrates that the forced fluxes can sometimes be higher (brighter) than fluxes in the Object table.
This is usually due to contaminating flux from nearby objects, as deblending is not performed as part of forced measurement, but it is performed when the fluxes in the Object table are derived.
Delete the catalogs from memory.
del objtable, result
3. Measurements for user-specified coordinates¶
Often, the motivation for doing forced photometry is to make forced measurements at a set of coordinates where no object or source has been detected with SNR $>5$ in the deep coadd or visit image (i.e., at coordinates that are not in the Object or Source tables).
These coordinates might be for subthreshold detections (e.g., SNR $<5$) or for detections from other (non-Rubin) surveys, e.g., infrared, space-based.
For this demonstration, a prepared input file of coordinates is loaded, and then forced photometry is run on a deep coadd.
The input file was generated with the detection, deblending, and measurement 105-series tutorial notebook, by running source detection with config.thresholdValue = 4 (followed by deblending and measurement) on the same $r$-band deep coadd used in this notebook, and saving the coordinates of all sources in that patch with a PSF flux $4 < SNR < 5$ to the file.
Only isolated sources and deblended children were saved; blend parents, which describe a whole blend rather than an individual object, were not.
The sub-threshold detection magnitudes were also saved in the file.
Note that some of these coordinates may nonetheless have counterparts in the Object table, because the production pipeline detects objects using all bands together, so an object that is sub-threshold in the $r$-band coadd alone can still be detected.
Load the file as an astropy table, add units to the coordinates columns, and print the column names.
filepath = '/rubin/cst_repos/tutorial-notebooks-data/data/'
filename = 'dp2_105_3_subthreshold_deep_coadd.dat'
subthresh = Table.read(filepath+filename, format="ascii")
subthresh["ra"].unit = u.deg
subthresh["dec"].unit = u.deg
print('file columns: ', subthresh.colnames)
print('file length: ', len(subthresh))
file columns: ['id', 'ra', 'dec', 'r_mag', 'r_mag_err'] file length: 1337
Option to view the loaded table.
# subthresh
Run the forced measurement driver with the same configuration as used in Section 2, but pass the subthresh table and use column names that match the input file.
config = ForcedMeasurementDriverConfig()
config.measurement.slots.psfFlux = "base_PsfFlux"
config.measurement.slots.centroid = "base_TransformedCentroidFromCoord"
config.measurement.slots.shape = None
config.measurement.doReplaceWithNoise = False
driver = ForcedMeasurementDriverTask(config=config)
src_result = driver.runFromAstropy(
subthresh,
legacy_coadd,
id_column_name="id",
ra_column_name="ra",
dec_column_name="dec",
psf_footprint_scaling=3.0,
)
src_result = fix_flux_columns(src_result)
lsst.forcedMeasurementDriver INFO: Measuring 1337 sources in a single band using 'ForcedMeasurementTask'
lsst.forcedMeasurementDriver.measurement INFO: Performing forced measurement on 1337 sources
lsst.forcedMeasurementDriver INFO: Finished processing for a single band; output catalog has 85 fields and 1337 records
Assert that the input and output tables have the same length.
assert len(subthresh) == len(src_result)
Option to display the first five lines of the output table.
# src_result[:5]
Convert fluxes to magnitudes (and vice versa) and plot the flux ratio between the forced and sub-threshold detection fluxes as a function of the forced photometry magnitudes.
src_result['mag'] = (src_result['slot_PsfFlux_flux'].value*u.nJy).to(u.ABmag)
subthresh['r_flux'] = (subthresh['r_mag'].value*u.ABmag).to(u.nJy)
fig, ax = plt.subplots(figsize=(6, 4))
ax.plot(subthresh['r_mag'], src_result['slot_PsfFlux_flux']/subthresh['r_flux'],
'o', ms=3, alpha=0.5, mew=1, mec='black', color='black')
ax.hlines(1.0, 24.7, 26.2, linestyle=':', color='gray')
ax.set_xlim(24.7, 26.2)
ax.set_xlabel('input file magnitude')
ax.set_ylabel('flux ratio (forced / input)')
plt.show()
Figure 2: The flux ratio of the force-measured PSF flux divided by the PSF flux from the original sub-threshold detection (from the input file) vs. the input file's sub-threshold detection magnitude.
The forced and sub-threshold detection fluxes were both measured on the same deep coadd at the same positions, but they need not agree exactly. As in Section 2.3, no deblending is performed during forced measurement, so the forced fluxes of sources with close neighbors can be contaminated by flux from those neighbors.