| | 169 | |
| | 170 | |
| | 171 | == Processing == |
| | 172 | |
| | 173 | {{{ |
| | 174 | psphotStack output cmf is run through psastro to calibrate zero point |
| | 175 | and to produce the 'cff' file - the list of objects which will be |
| | 176 | measured by psphotFullForce |
| | 177 | |
| | 178 | The cff is produced by pmSourcesWrite_CFF which is called if |
| | 179 | a output file "PSPHOT.OUTPUT.CFF" is defined. |
| | 180 | |
| | 181 | This file contains a single fits binary table with 1 row for each source. |
| | 182 | The values in the row depend on whether or not the source is selected |
| | 183 | for galaxy fitting. The boolean fitGalayx is set to be true if |
| | 184 | |
| | 185 | 1. The extended model fits were performed on the source and one of |
| | 186 | the models was set to be the source's modelEXT |
| | 187 | and |
| | 188 | 2. The model params SXX, SYY, SXY, and model magnitude are finite |
| | 189 | |
| | 190 | Here are the values for each row in the cff file |
| | 191 | |
| | 192 | ID source->seq (IPP_IDET) (XXX: need to make sure that these are set to the |
| | 193 | same values as the psf extension. Insure that we |
| | 194 | write cmf first.) |
| | 195 | X fitGalaxy ? modelEXT->params[PM_PAR_XPOS] : modelPSF->params[PM_PAR_XPOS] |
| | 196 | Y fitGalaxy ? modelEXT->params[PM_PAR_YPOS] : modelPSF->params[PM_PAR_YPOS] |
| | 197 | FLUX (fitGalaxy ? 10**-0.4*modelEXT->mag : source->psfFlux) / CELL.EXPOSURE |
| | 198 | AP_RADIUS source->apRadius |
| | 199 | KRON_RADIUS source->moments->Mrf*2.5 |
| | 200 | PETRO_RADIUS source->extpars ? source->extpars->petrosianRadius : NAN |
| | 201 | FIT_GALAXY see above |
| | 202 | PSF_STAR source->mode & PM_SOURCE_MODE_PSFSTAR ? true : false |
| | 203 | R_MAJOR fitGalaxy ? axes.major : 0 |
| | 204 | R_MINOR fitGalaxy ? axes.major : 0 |
| | 205 | THETA fitGalaxy ? axes.theta : 0 |
| | 206 | MODEL_TYPE fitGalaxy ? modelEXT->type : 0 |
| | 207 | INDEX fitGalaxy && modelEXT->type == sersic : 0 |
| | 208 | |
| | 209 | Notes: |
| | 210 | The flux is converted to counts per second. |
| | 211 | |
| | 212 | It would be feasible to fit multiple models for each source but this would require that psphotFullForce and |
| | 213 | the function that reads cff files to be enhanced to deal with multiple models. |
| | 214 | |
| | 215 | |
| | 216 | Full Force Pipeline |
| | 217 | ------------------- |
| | 218 | The full force pipeline consists of two stages. First psphotFullForce is run on all warp skycells for each |
| | 219 | stack. Then the program psphotFullForceSummary combines the results to get a single set of parameters for |
| | 220 | each source. |
| | 221 | |
| | 222 | psphotFullForce |
| | 223 | --------------- |
| | 224 | INPUTS |
| | 225 | ------ |
| | 226 | The cff file defines the set of sources to be processed. |
| | 227 | The data is read by a function in psModules and a source is created for each row. |
| | 228 | A psf model of the type given by the PSFMODEL keyword is created for each source. X and Y are used to set the |
| | 229 | parameters. A peak is allocated at the position with detValue, rawFlux, and smoothFlux set to the value of |
| | 230 | the FLUX column. The flux value (in counts per second) is later multipled by the warp exposure time by the |
| | 231 | function psphotLoadExtSources. |
| | 232 | |
| | 233 | moments are allocated with Mx = X, My = Y, Mrf = 0.4 *KRON_RADIUS |
| | 234 | tmpFlag PM_SOURCE_TMPF_MOMENTS_MEASURED is set. Note that this leaves the higher orde moments NAN |
| | 235 | |
| | 236 | if FIT_GALAXY is set and the model type is a recognized galaxy model type and extended source model is created. |
| | 237 | The model parameters are set based on X, Y, R_MAJOR, R_MINOR, and THETA. If the model type has an 8th parameter |
| | 238 | it is set to 0.5/SERISC_INDEX (BUG: this will result in INF if sersic index is zero) |
| | 239 | |
| | 240 | The warp image, mask, and variance images are read. If passed as an argument the warp stage psf file is read |
| | 241 | as well. Currently the script does not pass the psf file because Gene told me not to. I don't recall the |
| | 242 | reason. |
| | 243 | |
| | 244 | Processing |
| | 245 | ---------- |
| | 246 | Here are the important steps in full force processing. |
| | 247 | |
| | 248 | psphotSetMaskAndVariance (config, view, filerule); |
| | 249 | |
| | 250 | // generate a background model (median, smoothed image) |
| | 251 | if (!psphotModelBackground (config, view, filerule)) { |
| | 252 | return psphotReadoutCleanup (config, view, filerule); |
| | 253 | } |
| | 254 | if (!psphotSubtractBackground (config, view, filerule)) { |
| | 255 | return psphotReadoutCleanup (config, view, filerule); |
| | 256 | } |
| | 257 | if (!strcasecmp (breakPt, "BACKMDL")) { |
| | 258 | return psphotReadoutCleanup (config, view, filerule); |
| | 259 | } |
| | 260 | |
| | 261 | if (!psphotLoadPSF (config, view, filerule)) { |
| | 262 | // this only happens if we had a programming error in psphotLoadPSF |
| | 263 | psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model"); |
| | 264 | return psphotReadoutCleanup (config, view, filerule); |
| | 265 | } |
| | 266 | |
| | 267 | NOTE: This is where the flux is multiplied by the exposure time to convert from counts per second to counts |
| | 268 | // include externally-supplied sources (loaded onto detections->newSources) |
| | 269 | psphotLoadExtSources (config, view, filerule); |
| | 270 | |
| | 271 | // merge the newly selected sources into the existing list (detections->allSources) |
| | 272 | // NOTE: merge OLD and NEW |
| | 273 | NOTE: (we only have NEW) |
| | 274 | psphotMergeSources (config, view, filerule); |
| | 275 | |
| | 276 | // construct sources and measure moments and other basic stats (saved on detections->allSources) |
| | 277 | // all sources use the auto-scaled window appropriate to a PSF, except for the saturated |
| | 278 | // stars : these use a larger window (3x the basic window) |
| | 279 | |
| | 280 | From comment in psphotFullForceSourceStats |
| | 281 | // construct pixels and measure moments for sources. |
| | 282 | // NOTE: this function differs from psphotSourceStats in the following ways: |
| | 283 | // 1) detections->allSources are used instead of newSources |
| | 284 | // 2) the sources are used directly (peaks are not assigned to sources here) |
| | 285 | |
| | 286 | // NOTE: this function is meant to be used by psphotFullForce, and the mode of the loaded |
| | 287 | // sources should have (MODE_EXTERNAL) set. If so, the Mx,My values will not be recalculated |
| | 288 | |
| | 289 | |
| | 290 | if (!psphotFullForceSourceStats (config, view, filerule, true)) { // pass 1 |
| | 291 | psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources"); |
| | 292 | return psphotReadoutCleanup (config, view, filerule); |
| | 293 | } |
| | 294 | |
| | 295 | // generate a psf model for any readouts which need one |
| | 296 | // psphotFullForcePSF (config, view, filerule); |
| | 297 | // XXX I'm not sure we need a different algorithm here or not : we are supplying the |
| | 298 | // sources; we should mark with a flag bit the ones we actually want to use as PSF |
| | 299 | // stars (this means we need to supply this info in the load). |
| | 300 | psphotChoosePSF (config, view, filerule, false); |
| | 301 | |
| | 302 | // Construct an initial model for each object, set the radius to fitRadius, set circular |
| | 303 | // fit mask. NOTE: only applied to sources without guess models |
| | 304 | // XXX this currently only generates a PSF model |
| | 305 | psphotGuessModels (config, view, filerule); |
| | 306 | |
| | 307 | // linear PSF fit to source peaks, subtract the models from the image (in PSF mask) |
| | 308 | // XXX this will fit non-PSF sources if they are supplied |
| | 309 | psphotFitSourcesLinear (config, view, filerule, false, false); |
| | 310 | |
| | 311 | // measure kron fluxes |
| | 312 | psphotKronFlux (config, view, filerule); |
| | 313 | |
| | 314 | // measure petro fluxes |
| | 315 | psphotPetroFlux (config, view, filerule); |
| | 316 | |
| | 317 | // measure radial apertures |
| | 318 | psphotRadialApertures (config, view, filerule, 0); |
| | 319 | |
| | 320 | // measure galaxy shapes |
| | 321 | psphotGalaxyShape (config, view, filerule); |
| | 322 | |
| | 323 | // calculate source magnitudes (psf mag and ap mag) |
| | 324 | psphotMagnitudes(config, view, filerule); |
| | 325 | |
| | 326 | // replace background in residual image |
| | 327 | psphotSkyReplace (config, view, filerule); |
| | 328 | |
| | 329 | Galaxy Fitting |
| | 330 | -------------- |
| | 331 | Most of the functions performed by psphotFullForce are the same as standard psphot. |
| | 332 | |
| | 333 | psphotGalaxyShape is the function that creates extended models for the objects selected for |
| | 334 | galaxy fitting over a range of galaxy parameters and measures the chisq for each trial. |
| | 335 | |
| | 336 | The results of this are saved in a new cmf extension table refered to as 'XGAL'. |
| | 337 | |
| | 338 | Currently the only parameters varied are the major an minor radii. The range of values is |
| | 339 | determined by recipe. Currently 49 combinations are tried with the range in axes of |
| | 340 | 0.85 to 1.15 times the input values in steps of 0.05 * the input values. |
| | 341 | |
| | 342 | In processing the source's modelEXT is left equal to the model for the nominal (input values). |
| | 343 | We do this so that the nominal values are available in psphotFullForceSummary but this yields |
| | 344 | a less useful residual image. |
| | 345 | |
| | 346 | XXX: Perhaps psphotFullForceSummary should just read the CFF file (not as sources |
| | 347 | but as a table) and get the nominal values from there. |
| | 348 | |
| | 349 | |
| | 350 | OUTPUTS |
| | 351 | The output of the psphotFullForce consists of a standard cmf file and optionally a residual image. |
| | 352 | |
| | 353 | psphotFullForceSummary |
| | 354 | ---------------------- |
| | 355 | Once psphotFullForce has been run on all of the warps for a given skycell filter combination |
| | 356 | the program psphotFullForceSummary is run to combine the results. |
| | 357 | |
| | 358 | Inputs |
| | 359 | ------ |
| | 360 | The cmfs from the full force runs on the individual warps. |
| | 361 | |
| | 362 | Computations |
| | 363 | ------------ |
| | 364 | |
| | 365 | psf measurements |
| | 366 | |
| | 367 | petrosian radius and magnitude |
| | 368 | TBD mean radius? |
| | 369 | |
| | 370 | galaxy fits |
| | 371 | |
| | 372 | For each R_MAJOR, R_MINOR combination (i) the chisq of the combintation is measured by summing |
| | 373 | over the measurements on the indvidual warps (k). Note that sources which are masked in an input |
| | 374 | are not included in these sums. This is determined by requiring that PSF_QF_PERFECT > 0.9 |
| | 375 | |
| | 376 | chisq[i] = sum(chisq[k] * nPix[k]) / sum(nPix[k]) |
| | 377 | flux[i] = sum( (flux[k] / dFlux[k])**2) / sum ( 1 / dFlux[k]**2) |
| | 378 | dFlux[i] = sum ( 1 / dFlux[k]**2 ) |
| | 379 | |
| | 380 | Once these values are computed the trial with the lowest chisq value is chosen as the "best fit" |
| | 381 | and the extended source model paramters are set |
| | 382 | |
| | 383 | Outputs |
| | 384 | ------- |
| | 385 | These values are written to a summary cmf in the standard format |
| | 386 | |
| | 387 | |
| | 388 | }}} |
| | 389 | |