IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 28, 2006, 10:32:57 AM (20 years ago)
Author:
eugene
Message:

this is an important change. I have changed the way in which the psf
elliptical contour parameters are defined and fitted. SXX,SYY ->
1/SXX,1/SYY (ie, they are now ~ sigma, not ~1/sigma). SXY is now
fitted with the form SXY/(1/SXX2 + 1/SYY2)2

also added some additional tests and checks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotApResid.c

    r9734 r9771  
    11# include "psphot.h"
     2// XXXX this code fails if there are too few sources to measure the aperture residual
     3// the larger problem is that the rules for accepting more polynomial terms are weak.
    24
    35static pmPSFApTrendOptions DEFAULT_OPTION = PM_PSF_APTREND_SKYBIAS;
     
    1214    pmModel *model;
    1315    pmSource *source;
     16
     17    PS_ASSERT_PTR_NON_NULL(psf, false);
     18    PS_ASSERT_PTR_NON_NULL(psf->ApTrend, false);
     19    PS_ASSERT_PTR_NON_NULL(readout, false);
     20    PS_ASSERT_PTR_NON_NULL(sources, false);
     21    PS_ASSERT_PTR_NON_NULL(recipe, false);
    1422
    1523    psTimerStart ("psphot");
     
    115123        break;
    116124      case PM_PSF_APTREND_CONSTANT:
    117         stats->clipIter = 2;
    118         pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
    119         psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    120         if (psf->ApTrend == NULL) {
    121             psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
    122             return false;
    123         }
    124         // apply the fit
    125         stats->clipIter = 3;
    126         pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
    127         psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    128         if (psf->ApTrend == NULL) {
    129             psError(PSPHOT_ERR_PHOTOM, false, "Fitting aperture correction");
    130             return false;
    131         }
    132         break;
     125        stats->clipIter = 2;
     126        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
     127        if (!psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux)) {
     128            psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
     129            return false;
     130        }
     131        // apply the fit
     132        stats->clipIter = 3;
     133        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
     134        if (!psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux)) {
     135            psError(PSPHOT_ERR_PHOTOM, false, "Fitting aperture correction");
     136            return false;
     137        }
     138        break;
    133139      case PM_PSF_APTREND_SKYBIAS:
    134         // first clip out objects which are too far from the median
    135         stats->clipIter = 2;
    136         pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
    137         psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    138         if (psf->ApTrend == NULL) {
    139             psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
    140             return false;
    141         }
    142         // apply the fit
    143         stats->clipIter = 3;
    144         pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYBIAS);
    145         psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    146         if (psf->ApTrend == NULL) {
    147             psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting sky bias");
    148             return false;
    149         }
    150         break;
     140        // first clip out objects which are too far from the median
     141        stats->clipIter = 2;
     142        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
     143        if (!psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux)) {
     144            psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
     145            return false;
     146        }
     147        // apply the fit
     148        stats->clipIter = 3;
     149        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYBIAS);
     150        if (!psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux)) {
     151            psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting sky bias");
     152            return false;
     153        }
     154        break;
    151155      case PM_PSF_APTREND_SKYSAT:
    152         // first clip out objects which are too far from the median
    153         stats->clipIter = 2;
    154         pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
    155         psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    156         if (psf->ApTrend == NULL) {
    157             psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
    158             return false;
    159         }
    160         // apply the fit
    161         stats->clipIter = 2;
    162         pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYBIAS);
    163         psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    164         if (psf->ApTrend == NULL) {
    165             psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting sky bias");
    166             return false;
    167         }
    168         // apply the fit
    169         stats->clipIter = 3;
    170         pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYSAT);
    171         psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    172         if (psf->ApTrend == NULL) {
    173             psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting skysat");
    174             return false;
    175         }
    176         break;
     156        // first clip out objects which are too far from the median
     157        stats->clipIter = 2;
     158        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
     159        if (!psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux)) {
     160            psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
     161            return false;
     162        }
     163        // apply the fit
     164        stats->clipIter = 2;
     165        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYBIAS);
     166        if (!psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux)) {
     167            psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting sky bias");
     168            return false;
     169        }
     170        // apply the fit
     171        stats->clipIter = 3;
     172        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYSAT);
     173        if (!psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux)) {
     174            psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting skysat");
     175            return false;
     176        }
     177        break;
    177178      case PM_PSF_APTREND_XY_LIN:
    178         // first clip out objects which are too far from the median
    179         stats->clipIter = 2;
    180         pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
    181         psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    182         if (psf->ApTrend == NULL) {
    183             psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
    184             return false;
    185         }
    186         // apply the fit
    187         stats->clipIter = 3;
    188         pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_XY_LIN);
    189         psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    190         if (psf->ApTrend == NULL) {
    191             psError(PSPHOT_ERR_PHOTOM, false, "fitting, XY_LIN");
    192             return false;
    193         }
    194         break;
     179        // first clip out objects which are too far from the median
     180        stats->clipIter = 2;
     181        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
     182        if (!psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux)) {
     183            psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
     184            return false;
     185        }
     186        // apply the fit
     187        stats->clipIter = 3;
     188        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_XY_LIN);
     189        if (!psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux)) {
     190            psError(PSPHOT_ERR_PHOTOM, false, "fitting, XY_LIN");
     191            return false;
     192        }
     193        break;
    195194      case PM_PSF_APTREND_XY_QUAD:
    196         // first clip out objects which are too far from the median
    197         stats->clipIter = 2;
    198         pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
    199         psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    200         if (psf->ApTrend == NULL) {
    201             psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
    202             return false;
    203         }
    204         // apply the fit
    205         stats->clipIter = 3;
    206         pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_XY_QUAD);
    207         psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    208         if (psf->ApTrend == NULL) {
    209             psError(PSPHOT_ERR_PHOTOM, false, "Fitting XY_QUAD");
    210             return false;
    211         }
    212         break;
     195        // first clip out objects which are too far from the median
     196        stats->clipIter = 2;
     197        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
     198        if (!psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux)) {
     199            psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
     200            return false;
     201        }
     202        // apply the fit
     203        stats->clipIter = 3;
     204        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_XY_QUAD);
     205        if (!psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux)) {
     206            psError(PSPHOT_ERR_PHOTOM, false, "Fitting XY_QUAD");
     207            return false;
     208        }
     209        break;
    213210      case PM_PSF_APTREND_SKY_XY_LIN:
    214         // first clip out objects which are too far from the median
    215         stats->clipIter = 2;
    216         pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
    217         psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    218         if (psf->ApTrend == NULL) {
    219             psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
    220             return false;
    221         }
    222         // apply the fit
    223         stats->clipIter = 3;
    224         pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKY_XY_LIN);
    225         psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    226         if (psf->ApTrend == NULL) {
    227             psError(PSPHOT_ERR_PHOTOM, false, "Fitting sky xy_lin");
    228             return false;
    229         }
    230         break;
     211        // first clip out objects which are too far from the median
     212        stats->clipIter = 2;
     213        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
     214        if (!psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux)) {
     215            psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
     216            return false;
     217        }
     218        // apply the fit
     219        stats->clipIter = 3;
     220        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKY_XY_LIN);
     221        if (!psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux)) {
     222            psError(PSPHOT_ERR_PHOTOM, false, "Fitting sky xy_lin");
     223            return false;
     224        }
     225        break;
    231226      case PM_PSF_APTREND_SKYSAT_XY_LIN:
    232         // first clip out objects which are too far from the median
    233         stats->clipIter = 2;
    234         pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
    235         psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    236         if (psf->ApTrend == NULL) {
    237             psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
    238             return false;
    239         }
    240         // apply the fit
    241         stats->clipIter = 3;
    242         pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYBIAS);
    243         psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    244         if (psf->ApTrend == NULL) {
    245             psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting sky bias");
    246             return false;
    247         }
    248         // apply the fit
    249         stats->clipIter = 3;
    250         pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYSAT_XY_LIN);
    251         psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    252         if (psf->ApTrend == NULL) {
    253             psError(PSPHOT_ERR_PHOTOM, false, "Fitting skyset xy_lin");
    254             return false;
    255         }
    256         break;
     227        // first clip out objects which are too far from the median
     228        stats->clipIter = 2;
     229        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
     230        if (!psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux)) {
     231            psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
     232            return false;
     233        }
     234        // apply the fit
     235        stats->clipIter = 3;
     236        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYBIAS);
     237        if (!psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux)) {
     238            psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting sky bias");
     239            return false;
     240        }
     241        // apply the fit
     242        stats->clipIter = 3;
     243        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYSAT_XY_LIN);
     244        if (!psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux)) {
     245            psError(PSPHOT_ERR_PHOTOM, false, "Fitting skyset xy_lin");
     246            return false;
     247        }
     248        break;
    257249      case PM_PSF_APTREND_ALL:
    258         // first clip out objects which are too far from the median
    259         stats->clipIter = 2;
    260         pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
    261         psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    262         if (psf->ApTrend == NULL) {
    263             psError(PSPHOT_ERR_PHOTOM, false, "Failed to measure apTrend");
    264             return false;
    265         }
    266         // fit just SkyBias and clip out objects which are too far from the median
    267         stats->clipIter = 2;
    268         pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYBIAS);
    269         psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    270         if (psf->ApTrend == NULL) {
    271             psError(PSPHOT_ERR_PHOTOM, false, "fitting skyBias");
    272             return false;
    273         }
    274         // finally, fit x, y, SkyBias and clip out objects which are too far from the median
    275         stats->clipIter = 3;
    276         pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_ALL);
    277         psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    278         if (psf->ApTrend == NULL) {
    279             psError(PSPHOT_ERR_PHOTOM, false, "fitting all");
    280             return false;
    281         }
    282         break;
     250        // first clip out objects which are too far from the median
     251        stats->clipIter = 2;
     252        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
     253        if (!psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux)) {
     254            psError(PSPHOT_ERR_PHOTOM, false, "Failed to measure apTrend");
     255            return false;
     256        }
     257        // fit just SkyBias and clip out objects which are too far from the median
     258        stats->clipIter = 2;
     259        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYBIAS);
     260        if (!psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux)) {
     261            psError(PSPHOT_ERR_PHOTOM, false, "fitting skyBias");
     262            return false;
     263        }
     264        // finally, fit x, y, SkyBias and clip out objects which are too far from the median
     265        stats->clipIter = 3;
     266        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_ALL);
     267        if (!psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux)) {
     268            psError(PSPHOT_ERR_PHOTOM, false, "fitting all");
     269            return false;
     270        }
     271        break;
    283272      default:
    284273        psError(PSPHOT_ERR_PHOTOM, true, "Unknown APTREND value: %s", optionName);
Note: See TracChangeset for help on using the changeset viewer.