IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9568


Ignore:
Timestamp:
Oct 13, 2006, 3:01:35 PM (20 years ago)
Author:
eugene
Message:

cleanups of APTREND stuff, including name-to-enum conversion and a switch block

File:
1 edited

Legend:

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

    r9529 r9568  
    11# include "psphot.h"
    2 static char DEFAULT_OPTION[] = "SKYBIAS";
     2
     3static pmPSFApTrendOptions DEFAULT_OPTION = PM_PSF_APTREND_SKYBIAS;
    34
    45// measure the aperture residual statistics
     
    9394    }
    9495
    95     // APTREND options are defined by the if ... else if ... else if ... else block below
    96     char *ApTrendOption = psMetadataLookupPtr (&status, recipe, "APTREND");
    97     if (!status) ApTrendOption = DEFAULT_OPTION;
     96    // APTREND options : NONE SKYBIAS XY_LIN XY_QUAD SKY_XY_LIN FULL
     97    // APTREND options are used in the switch block below
     98    pmPSFApTrendOptions ApTrendOption = DEFAULT_OPTION;
     99    char *optionName = psMetadataLookupPtr (&status, recipe, "APTREND");
     100    if (status) ApTrendOption = pmPSFApTrendOptionFromName (optionName);
     101    if (ApTrendOption == PM_PSF_APTREND_ERROR) {
     102        psError(PSPHOT_ERR_APERTURE, true, "invalid aperture residual trend %s", optionName);
     103        return false;
     104    }
    98105
    99106    // 3hi/1lo sigma clipping on the rflux vs metric fit
     
    103110
    104111    // no correction
    105     if (!strcasecmp (ApTrendOption, "NONE")) {
     112    switch (ApTrendOption) {
     113      case PM_PSF_APTREND_NONE:
    106114        // remove ApTrend fit from pmPSFtry
    107115        psf->ApTrend->coeff[0][0][0][0] = 0;
    108     } else if (!strcasecmp (ApTrendOption, "CONSTANT")) { // constant only
    109         stats->clipIter = 2;
    110         pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
    111         psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    112         if (psf->ApTrend == NULL) {
    113             psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
    114             return false;
    115         }
    116 
    117         // apply the fit
    118         stats->clipIter = 3;
    119         pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
     116        break;
     117      case PM_PSF_APTREND_CONSTANT:
     118        stats->clipIter = 2;
     119        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
     120        psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
     121        if (psf->ApTrend == NULL) {
     122            psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
     123            return false;
     124        }
     125        // apply the fit
     126        stats->clipIter = 3;
     127        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
    120128        psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    121129        if (psf->ApTrend == NULL) {
     
    123131            return false;
    124132        }
    125     } else if (!strcasecmp (ApTrendOption, "SKYBIAS")) { // constant and skybias only
    126         // first clip out objects which are too far from the median
    127         stats->clipIter = 2;
    128         pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
    129         psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    130         if (psf->ApTrend == NULL) {
    131             psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
    132             return false;
    133         }
    134 
    135         // apply the fit
    136         stats->clipIter = 3;
    137         pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKYBIAS);
     133        break;
     134      case PM_PSF_APTREND_SKYBIAS:
     135        // first clip out objects which are too far from the median
     136        stats->clipIter = 2;
     137        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
     138        psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
     139        if (psf->ApTrend == NULL) {
     140            psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
     141            return false;
     142        }
     143        // apply the fit
     144        stats->clipIter = 3;
     145        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYBIAS);
    138146        psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    139147        if (psf->ApTrend == NULL) {
     
    141149            return false;
    142150        }
    143     } else if (!strcasecmp (ApTrendOption, "SKYSAT")) {
    144         // first clip out objects which are too far from the median
    145         stats->clipIter = 2;
    146         pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
    147         psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    148         if (psf->ApTrend == NULL) {
    149             psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
    150             return false;
    151         }
    152 
    153         // apply the fit
    154         stats->clipIter = 2;
    155         pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKYBIAS);
     151        break;
     152      case PM_PSF_APTREND_SKYSAT:
     153        // first clip out objects which are too far from the median
     154        stats->clipIter = 2;
     155        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
     156        psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
     157        if (psf->ApTrend == NULL) {
     158            psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
     159            return false;
     160        }
     161        // apply the fit
     162        stats->clipIter = 2;
     163        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYBIAS);
    156164        psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    157165        if (psf->ApTrend == NULL) {
     
    159167            return false;
    160168        }
    161 
    162         // apply the fit
    163         stats->clipIter = 3;
    164         pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKYSAT);
     169        // apply the fit
     170        stats->clipIter = 3;
     171        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYSAT);
    165172        psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    166173        if (psf->ApTrend == NULL) {
     
    168175            return false;
    169176        }
    170     } else if (!strcasecmp (ApTrendOption, "XY_LIN")) { // constant and linear X,Y only
    171         // first clip out objects which are too far from the median
    172         stats->clipIter = 2;
    173         pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
    174         psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    175         if (psf->ApTrend == NULL) {
    176             psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
    177             return false;
    178         }
    179 
    180         // apply the fit
    181         stats->clipIter = 3;
    182         pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_XY_LIN);
     177        break;
     178      case PM_PSF_APTREND_XY_LIN:
     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        psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
     183        if (psf->ApTrend == NULL) {
     184            psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
     185            return false;
     186        }
     187        // apply the fit
     188        stats->clipIter = 3;
     189        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_XY_LIN);
    183190        psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    184191        if (psf->ApTrend == NULL) {
     
    186193            return false;
    187194        }
    188     } else if (!strcasecmp (ApTrendOption, "XY_QUAD")) { // constant and quadratic X,Y only
    189         // first clip out objects which are too far from the median
    190         stats->clipIter = 2;
    191         pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
    192         psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    193         if (psf->ApTrend == NULL) {
    194             psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
    195             return false;
    196         }
    197 
    198         // apply the fit
    199         stats->clipIter = 3;
    200         pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_XY_QUAD);
     195        break;
     196      case PM_PSF_APTREND_XY_QUAD:
     197        // first clip out objects which are too far from the median
     198        stats->clipIter = 2;
     199        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
     200        psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
     201        if (psf->ApTrend == NULL) {
     202            psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
     203            return false;
     204        }
     205        // apply the fit
     206        stats->clipIter = 3;
     207        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_XY_QUAD);
    201208        psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    202209        if (psf->ApTrend == NULL) {
     
    204211            return false;
    205212        }
    206     } else if (!strcasecmp (ApTrendOption, "SKY_XY_LIN")) { // constant and sky, linear X,Y only
    207         // first clip out objects which are too far from the median
    208         stats->clipIter = 2;
    209         pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
    210         psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    211         if (psf->ApTrend == NULL) {
    212             psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
    213             return false;
    214         }
    215 
    216         // apply the fit
    217         stats->clipIter = 3;
    218         pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKY_XY_LIN);
     213        break;
     214      case PM_PSF_APTREND_SKY_XY_LIN:
     215        // first clip out objects which are too far from the median
     216        stats->clipIter = 2;
     217        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
     218        psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
     219        if (psf->ApTrend == NULL) {
     220            psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
     221            return false;
     222        }
     223        // apply the fit
     224        stats->clipIter = 3;
     225        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKY_XY_LIN);
    219226        psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    220227        if (psf->ApTrend == NULL) {
     
    222229            return false;
    223230        }
    224     } else if (!strcasecmp (ApTrendOption, "SKYSAT_XY_LIN")) { // constant and sky, linear X,Y only
    225         // first clip out objects which are too far from the median
    226         stats->clipIter = 2;
    227         pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
    228         psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    229         if (psf->ApTrend == NULL) {
    230             psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
    231             return false;
    232         }
    233 
    234         // apply the fit
    235         stats->clipIter = 3;
    236         pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKYBIAS);
     231        break;
     232      case PM_PSF_APTREND_SKYSAT_XY_LIN:
     233        // first clip out objects which are too far from the median
     234        stats->clipIter = 2;
     235        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
     236        psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
     237        if (psf->ApTrend == NULL) {
     238            psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
     239            return false;
     240        }
     241        // apply the fit
     242        stats->clipIter = 3;
     243        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYBIAS);
    237244        psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    238245        if (psf->ApTrend == NULL) {
     
    240247            return false;
    241248        }
    242 
    243         // apply the fit
    244         stats->clipIter = 3;
    245         pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKYSAT_XY_LIN);
     249        // apply the fit
     250        stats->clipIter = 3;
     251        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYSAT_XY_LIN);
    246252        psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    247253        if (psf->ApTrend == NULL) {
     
    249255            return false;
    250256        }
    251     } else if (!strcasecmp (ApTrendOption, "ALL")) {
    252         // first clip out objects which are too far from the median
    253         stats->clipIter = 2;
    254         pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
     257        break;
     258      case PM_PSF_APTREND_ALL:
     259        // first clip out objects which are too far from the median
     260        stats->clipIter = 2;
     261        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
    255262        psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    256263        if (psf->ApTrend == NULL) {
     
    258265            return false;
    259266        }
    260 
    261267        // fit just SkyBias and clip out objects which are too far from the median
    262268        stats->clipIter = 2;
    263         pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKYBIAS);
     269        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYBIAS);
    264270        psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    265271        if (psf->ApTrend == NULL) {
     
    267273            return false;
    268274        }
    269 
    270275        // finally, fit x, y, SkyBias and clip out objects which are too far from the median
    271276        stats->clipIter = 3;
    272         pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_ALL);
     277        pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_ALL);
    273278        psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    274279        if (psf->ApTrend == NULL) {
     
    276281            return false;
    277282        }
    278     } else {
    279         psError(PSPHOT_ERR_PHOTOM, true, "Unknown APTREND value: %s", ApTrendOption);
     283        break;
     284      default:
     285        psError(PSPHOT_ERR_PHOTOM, true, "Unknown APTREND value: %s", optionName);
    280286        return false;
    281287    }
Note: See TracChangeset for help on using the changeset viewer.