IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 17, 2006, 7:13:42 AM (20 years ago)
Author:
magnier
Message:

bulk merge of eam_rel9_p0 onto this branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/rel10_ifa/psModules/src/objects/pmPSF.c

    r5844 r6448  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2005-12-24 01:24:32 $
     8 *  @version $Revision: 1.4.4.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-02-17 17:13:42 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    5757        return;
    5858
     59    psFree (psf->ApTrend);
     60    psFree (psf->growth);
    5961    psFree (psf->params);
    6062    return;
     
    6971 X-center
    7072 Y-center
    71  ???: Sky background value?
    72  ???: Zo?
     73 Sky background value
     74 Object Normalization
    7375 *****************************************************************************/
    7476pmPSF *pmPSFAlloc (pmModelType type)
     
    8385    psf->dApResid = 0.0;
    8486    psf->skyBias  = 0.0;
     87    psf->skySat   = 0.0;
     88
     89    // the ApTrend components are (x, y, r2rflux, flux)
     90    psf->ApTrend = psPolynomial4DAlloc (PS_POLYNOMIAL_ORD, 2, 2, 1, 1);
     91    pmPSF_MaskApTrend (psf, PM_PSF_SKYBIAS);
     92
     93    // don't define a growth curve : user needs to choose radius bins
     94    psf->growth = NULL;
    8595
    8696    Nparams = pmModelParameterCount (type);
     
    93103    for (int i = 0; i < psf->params->n; i++) {
    94104        // XXX EAM : make this a user-defined value?
    95         psf->params->data[i] = psPolynomial2DAlloc(1, 1, PS_POLYNOMIAL_ORD);
     105        psf->params->data[i] = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, 1, 1);
    96106    }
    97107
     
    169179
    170180/*****************************************************************************
    171 pmModelFromPSF (*modelFLT, *psf):  use the model position parameters to
     181pmModelFromPSF (*modelEXT, *psf):  use the model position parameters to
    172182construct a realization of the PSF model at the object coordinates
    173183 *****************************************************************************/
    174 pmModel *pmModelFromPSF (pmModel *modelFLT, pmPSF *psf)
    175 {
    176 
    177     // need to define the relationship between the modelFLT and modelPSF ?
     184pmModel *pmModelFromPSF (pmModel *modelEXT, pmPSF *psf)
     185{
     186
     187    // need to define the relationship between the modelEXT and modelPSF ?
    178188
    179189    // find function used to set the model parameters
     
    184194
    185195    // set model parameters for this source based on PSF information
    186     modelFromPSFFunc (modelPSF, modelFLT, psf);
     196    modelFromPSFFunc (modelPSF, modelEXT, psf);
    187197
    188198    return (modelPSF);
    189199}
     200
     201// zero and mask out all terms:
     202static bool maskAllTerms (psPolynomial4D *trend)
     203{
     204
     205    for (int i = 0; i < trend->nX + 1; i++) {
     206        for (int j = 0; j < trend->nY + 1; j++) {
     207            for (int k = 0; k < trend->nZ + 1; k++) {
     208                for (int m = 0; m < trend->nT + 1; m++) {
     209                    trend->mask[i][j][k][m] = 1;  // mask coeff
     210                    trend->coeff[i][j][k][m] = 0;  // zero coeff
     211                }
     212            }
     213        }
     214    }
     215    return true;
     216}
     217
     218/***********************************************
     219 * this function masks the psf.ApTrend polynomial
     220 * to enable the specific subset of the coefficients
     221 **********************************************/
     222bool pmPSF_MaskApTrend (pmPSF *psf, pmPSF_ApTrendOptions option)
     223{
     224
     225    switch (option) {
     226    case PM_PSF_NONE:
     227        maskAllTerms (psf->ApTrend);
     228        return true;
     229
     230    case PM_PSF_CONSTANT:
     231        maskAllTerms (psf->ApTrend);
     232        psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
     233        return true;
     234
     235    case PM_PSF_SKYBIAS:
     236        maskAllTerms (psf->ApTrend);
     237        psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
     238        psf->ApTrend->mask[0][0][1][0] = 0;  // unmask skybias
     239        return true;
     240
     241    case PM_PSF_SKYSAT:
     242        maskAllTerms (psf->ApTrend);
     243        psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
     244        psf->ApTrend->mask[0][0][1][0] = 0;  // unmask skybias
     245        psf->ApTrend->mask[0][0][0][1] = 0;  // unmask skybias
     246        return true;
     247
     248    case PM_PSF_XY_LIN:
     249        maskAllTerms (psf->ApTrend);
     250        psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
     251        psf->ApTrend->mask[1][0][0][0] = 0;  // unmask x
     252        psf->ApTrend->mask[0][1][0][0] = 0;  // unmask y
     253        return true;
     254
     255    case PM_PSF_XY_QUAD:
     256        maskAllTerms (psf->ApTrend);
     257        psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
     258        psf->ApTrend->mask[1][0][0][0] = 0;  // unmask x
     259        psf->ApTrend->mask[2][0][0][0] = 0;  // unmask x^2
     260        psf->ApTrend->mask[1][1][0][0] = 0;  // unmask x y
     261        psf->ApTrend->mask[0][1][0][0] = 0;  // unmask y
     262        psf->ApTrend->mask[0][2][0][0] = 0;  // unmask y^2
     263        return true;
     264
     265    case PM_PSF_SKY_XY_LIN:
     266        maskAllTerms (psf->ApTrend);
     267        psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
     268        psf->ApTrend->mask[1][0][0][0] = 0;  // unmask x
     269        psf->ApTrend->mask[0][1][0][0] = 0;  // unmask y
     270        psf->ApTrend->mask[0][0][1][0] = 0;  // unmask skybias
     271        return true;
     272
     273    case PM_PSF_SKYSAT_XY_LIN:
     274        maskAllTerms (psf->ApTrend);
     275        psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
     276        psf->ApTrend->mask[1][0][0][0] = 0;  // unmask x
     277        psf->ApTrend->mask[0][1][0][0] = 0;  // unmask y
     278        psf->ApTrend->mask[0][0][1][0] = 0;  // unmask skybias
     279        psf->ApTrend->mask[0][0][0][1] = 0;  // unmask skysat
     280        return true;
     281
     282    case PM_PSF_ALL:
     283    default:
     284        maskAllTerms (psf->ApTrend);
     285        psf->ApTrend->mask[0][0][0][0] = 0;  // unmask constant
     286        psf->ApTrend->mask[0][0][1][0] = 0;  // unmask skybias
     287        psf->ApTrend->mask[0][0][0][1] = 0;  // unmask skysat
     288
     289        psf->ApTrend->mask[1][0][0][0] = 0;  // unmask x
     290        psf->ApTrend->mask[2][0][0][0] = 0;  // unmask x^2
     291        psf->ApTrend->mask[1][1][0][0] = 0;  // unmask x y
     292        psf->ApTrend->mask[0][1][0][0] = 0;  // unmask y
     293        psf->ApTrend->mask[0][2][0][0] = 0;  // unmask y^2
     294        return true;
     295    }
     296    return false;
     297}
     298
     299psMetadata *pmPSFtoMD (psMetadata *metadata, pmPSF *psf)
     300{
     301
     302    if (metadata == NULL) {
     303        metadata = psMetadataAlloc ();
     304    }
     305
     306    char *modelName = pmModelGetType (psf->type);
     307    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_MODEL_NAME", PS_DATA_STRING, "PSF model name", modelName);
     308
     309    int nPar = pmModelParameterCount (psf->type)    ;
     310    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_MODEL_NPAR", PS_DATA_S32, "PSF model parameter count", nPar);
     311
     312    for (int i = 0; i < nPar - 4; i++) {
     313        psPolynomial2D *poly = psf->params->data[i];
     314        psPolynomial2DtoMD (metadata, poly, "PSF_PAR%02d", i);
     315    }
     316    psPolynomial4DtoMD (metadata, psf->ApTrend, "APTREND");
     317
     318    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_AP_RESID", PS_DATA_F32, "aperture residual", psf->ApResid);
     319    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_dAP_RESID", PS_DATA_F32, "aperture residual scatter", psf->dApResid);
     320    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_SKY_BIAS", PS_DATA_F32, "sky bias level", psf->skyBias);
     321
     322    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_CHISQ", PS_DATA_F32, "chi-square for fit", psf->chisq);
     323    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_NSTARS", PS_DATA_S32, "number of stars used to measure PSF", psf->nPSFstars);
     324
     325    return metadata;
     326}
     327
     328pmPSF *pmPSFfromMD (psMetadata *metadata)
     329{
     330
     331    bool status;
     332    char keyword[80];
     333
     334    char *modelName = psMetadataLookupPtr (&status, metadata, "PSF_MODEL_NAME");
     335    pmModelType type = pmModelSetType (modelName);
     336
     337    pmPSF *psf = pmPSFAlloc (type);
     338
     339    int nPar = psMetadataLookupS32 (&status, metadata, "PSF_MODEL_NPAR");
     340    if (nPar != pmModelParameterCount (psf->type))
     341        psAbort ("read PSF" , "mismatch model par count");
     342
     343    for (int i = 0; i < nPar - 4; i++) {
     344        sprintf (keyword, "PSF_PAR%02d", i);
     345        psMetadata *folder = psMetadataLookupPtr (&status, metadata, keyword);
     346        psPolynomial2D *poly = psPolynomial2DfromMD (folder);
     347        psFree (psf->params->data[i]);
     348        psf->params->data[i] = poly;
     349    }
     350    sprintf (keyword, "APTREND");
     351    psMetadata *folder = psMetadataLookupPtr (&status, metadata, keyword);
     352    psPolynomial4D *poly = psPolynomial4DfromMD (folder);
     353    psFree (psf->ApTrend);
     354    psf->ApTrend = poly;
     355
     356    psf->ApResid = psMetadataLookupF32 (&status, metadata, "PSF_AP_RESID");
     357    psf->dApResid = psMetadataLookupF32 (&status, metadata, "PSF_dAP_RESID");
     358    psf->skyBias = psMetadataLookupF32 (&status, metadata, "PSF_SKY_BIAS");
     359
     360    psf->chisq = psMetadataLookupF32 (&status, metadata, "PSF_CHISQ");
     361    psf->nPSFstars = psMetadataLookupS32 (&status, metadata, "PSF_NSTARS");
     362
     363    psFree (metadata);
     364    return (psf);
     365}
Note: See TracChangeset for help on using the changeset viewer.