IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 19, 2005, 5:24:40 PM (21 years ago)
Author:
eugene
Message:

added CMP, CMF output formats

File:
1 edited

Legend:

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

    r5068 r5073  
    7373    pmModel *model;
    7474    psF32 *PAR, *dPAR;
    75     float skyFlux, dmag, apMag, fitMag;
     75    float sky, dmag, apMag, fitMag;
    7676
    7777    psLine *line = psLineAlloc (104);  // 104 is dophot-defined line length
     
    117117        dPAR = model->dparams->data.F32;
    118118
     119        x = source->peak->x;
     120        y = source->peak->y;
     121
     122        // we have already (psphotApplyPSF) defined pixels at least OUTER_RADIUS from source
     123        // we need to mask pixels to measure the aperture magnitude
     124        // set aperture mask circle of PSF_FIT_RADIUS
     125        psImageKeepCircle (source->mask, x, y, RADIUS, "OR", PSPHOT_MASK_MARKED);
     126
    119127        // save local sky for later
    120         skyFlux = model->params->data.F32[0];
     128        sky = model->params->data.F32[0];
    121129
    122130        // replace source flux
     
    124132        model->params->data.F32[0] = 0;
    125133        pmSourceAddModel (source->pixels, source->mask, model, false);
    126         model->params->data.F32[0] = skyFlux;
     134        model->params->data.F32[0] = sky;
    127135
    128136        // measure object photometry
    129137        status = pmSourcePhotometry (&fitMag, &apMag, model, source->pixels, source->mask);
     138
     139        // correct both apMag and fitMag to same system, consistent with infinite flux star in aperture RADIUS
     140        rflux   = pow (10.0, 0.4*fitMag);
     141        apMag  -= rflux * psf->skyBias * (M_PI * PS_SQR(RADIUS));
    130142        fitMag += psf->ApResid;
    131143
     
    134146        model->params->data.F32[0] = 0;
    135147        pmSourceSubModel (source->pixels, source->mask, model, false);
    136         model->params->data.F32[0] = skyFlux;
     148        model->params->data.F32[0] = sky;
     149
     150        // unmask aperture
     151        psImageKeepCircle (source->mask, x, y, RADIUS, "AND", ~PSPHOT_MASK_MARKED);
    137152
    138153        if (status == FALSE) continue;
     
    178193
    179194    // aperture radius for ap magnitude
     195    // XXX EAM I probably need to measure the fit and ap magnitudes at one location elsewhere
     196    //         this would have to happen *after* all objects are detected and subtracted
    180197    float RADIUS = psMetadataLookupF32 (&result, config, "PSF_FIT_RADIUS");
    181198
     
    255272        if (status == FALSE) continue;
    256273
    257         // XXX EAM : fix this to match sextractor types?
     274        // XXX EAM : fix this to return sextractor type and flags
    258275        // type = pmSourceSextractType (source);
    259276
     
    300317    fseek (f, 0, SEEK_END);
    301318
    302     psLine *line = psLineAlloc (104);  // 104 is dophot-defined line length
     319    psLine *line = psLineAlloc (66);  // 66 is imclean-defined line length
    303320
    304321    // write sources with models first
     
    336353        dPAR = model->dparams->data.F32;
    337354
     355        x = source->peak->x;
     356        y = source->peak->y;
     357
     358        // we have already (psphotApplyPSF) defined pixels at least OUTER_RADIUS from source
     359        // we need to mask pixels to measure the aperture magnitude
     360        // set aperture mask circle of PSF_FIT_RADIUS
     361        psImageKeepCircle (source->mask, x, y, RADIUS, "OR", PSPHOT_MASK_MARKED);
     362
    338363        // save local sky for later
    339364        sky = model->params->data.F32[0];
    340 
    341         // XXX EAM : get Theta from PAR[4,5,6]
    342         Theta = 0.0;
    343365
    344366        // replace source flux
     
    350372        // measure object photometry
    351373        status = pmSourcePhotometry (&fitMag, &apMag, model, source->pixels, source->mask);
     374
     375        // correct both apMag and fitMag to same system, consistent with infinite flux star in aperture RADIUS
     376        rflux   = pow (10.0, 0.4*fitMag);
     377        apMag  -= rflux * psf->skyBias * (M_PI * PS_SQR(RADIUS));
    352378        fitMag += psf->ApResid;
    353379
     
    357383        pmSourceSubModel (source->pixels, source->mask, model, false);
    358384        model->params->data.F32[0] = sky;
     385
     386        // unmask aperture
     387        psImageKeepCircle (source->mask, x, y, RADIUS, "AND", ~PSPHOT_MASK_MARKED);
    359388
    360389        if (status == FALSE) continue;
     
    372401        psLineAdd (line, "%3.1f ", lsky);
    373402        psLineAdd (line, "%6.3f ", 32.0);    // should be 'Mgal
    374         psLineAdd (line, "%6.3f ", apMag + 25.0);
     403        psLineAdd (line, "%6.3f ", apMag + 25.0); // 25.0 should come from config
    375404        psLineAdd (line, "%6.2f ", PAR[4]);  // should be 'FHWM x'
    376405        psLineAdd (line, "%6.2f ", PAR[5]);  // should be 'FHWM y'
     
    383412
    384413// elixir-style FITS table output (header + table in 1st extension)
     414// this format consists of a header derived from the image header
     415// followed by a zero-size matrix, followed by the table data
    385416bool pmSourcesWriteCMF (eamReadout *imdata, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {
    386417
    387     // write imdata->header to file
    388 
    389     // write FITS table to file (use autocode tools)
     418    psArray *table;
     419    psMetadata *row;
     420    psMetadata *theader;
     421
     422    // set NAXIS to 0
     423    psMetadataAdd (header, PS_LIST_HEAD, "NAXIS", PS_META_S32 | PS_META_REPLACE, "", 0);
     424
     425    table = psArrayAlloc (sources->n);
     426    sources->n = 0;
     427
     428    for (i = 0; i < sources->n; i++) {
     429        pmSource *source = (pmSource *) sources->data[i];
     430
     431        // use the correct model
     432        switch (source->type) {
     433
     434            // use PSF model with stars
     435          case PM_SOURCE_PSFSTAR:
     436          case PM_SOURCE_SATSTAR:
     437          case PM_SOURCE_GOODSTAR:
     438            model = source->modelPSF;
     439            break;
     440
     441            // use FLT model with galaxies
     442          case PM_SOURCE_GALAXY:
     443            model = source->modelFLT;
     444            break;
     445           
     446            // skip defects and poorly fitted stars or galaxies
     447          case PM_SOURCE_DEFECT:
     448          case PM_SOURCE_SATURATED:
     449          case PM_SOURCE_FAINTSTAR:
     450          case PM_SOURCE_POOR_FIT_PSF:
     451          case PM_SOURCE_POOR_FIT_GAL:
     452          case PM_SOURCE_FAIL_FIT_GAL:
     453          default:
     454            model = NULL;
     455        }
     456        if (model == NULL) continue;
     457
     458        PAR = model->params->data.F32;
     459        dPAR = model->dparams->data.F32;
     460
     461        x = source->peak->x;
     462        y = source->peak->y;
     463
     464        // we have already (psphotApplyPSF) defined pixels at least OUTER_RADIUS from source
     465        // we need to mask pixels to measure the aperture magnitude
     466        // set aperture mask circle of PSF_FIT_RADIUS
     467        psImageKeepCircle (source->mask, x, y, RADIUS, "OR", PSPHOT_MASK_MARKED);
     468
     469        // save local sky for later
     470        sky = model->params->data.F32[0];
     471
     472        // replace source flux
     473        // XXX EAM : need to add 'sky' boolean option here
     474        model->params->data.F32[0] = 0;
     475        pmSourceAddModel (source->pixels, source->mask, model, false);
     476        model->params->data.F32[0] = sky;
     477
     478        // measure object photometry
     479        status = pmSourcePhotometry (&fitMag, &apMag, model, source->pixels, source->mask);
     480
     481        // correct both apMag and fitMag to same system, consistent with infinite flux star in aperture RADIUS
     482        rflux   = pow (10.0, 0.4*fitMag);
     483        apMag  -= rflux * psf->skyBias * (M_PI * PS_SQR(RADIUS));
     484        fitMag += psf->ApResid;
     485
     486        // subtract object, leave local sky
     487        // XXX EAM : need to add 'sky' boolean option here
     488        model->params->data.F32[0] = 0;
     489        pmSourceSubModel (source->pixels, source->mask, model, false);
     490        model->params->data.F32[0] = sky;
     491
     492        // unmask aperture
     493        psImageKeepCircle (source->mask, x, y, RADIUS, "AND", ~PSPHOT_MASK_MARKED);
     494
     495        if (status == FALSE) continue;
     496
     497        dmag = dPAR[1] / PAR[1];
     498        type = pmSourceDophotType (source);
     499        lsky = (PAR[0] < 1.0) ? 0.0 : log10(PAR[0]);
     500
     501        table = psMetdataAlloc ();
     502        psMetadataAdd (table, PS_LIST_HEAD, "X_PIX",   PS_META_F32, "", PAR[2]);
     503        psMetadataAdd (table, PS_LIST_HEAD, "Y_PIX",   PS_META_F32, "", PAR[3]);
     504        psMetadataAdd (table, PS_LIST_HEAD, "MAG_RAW", PS_META_F32, "", fitMag + 25.0);
     505        psMetadataAdd (table, PS_LIST_HEAD, "MAG_ERR", PS_META_F32, "", (int)(1000*dmag));
     506        psMetadataAdd (table, PS_LIST_HEAD, "MAG_GAL", PS_META_F32, "", type);
     507        psMetadataAdd (table, PS_LIST_HEAD, "MAG_AP",  PS_META_F32, "", lsky);
     508        psMetadataAdd (table, PS_LIST_HEAD, "LOG_SKY", PS_META_F32, "", 32.0);    // should be 'Mgal'
     509        psMetadataAdd (table, PS_LIST_HEAD, "FWHM_X",  PS_META_F32, "", apMag + 25.0); // 25.0 should come from config
     510        psMetadataAdd (table, PS_LIST_HEAD, "FWHM_Y",  PS_META_F32, "", PAR[4]);  // should be 'FHWM x'
     511        psMetadataAdd (table, PS_LIST_HEAD, "THETA",   PS_META_F32, "", PAR[5]);  // should be 'FHWM y'
     512        psMetadataAdd (table, PS_LIST_HEAD, "DOPHOT",  PS_META_S8,  "", Theta);   // should be theta
     513        // psMetadataAdd (header, PS_LIST_HEAD, "DUMMY",   PS_META_STR, "", NULL);
     514   
     515        psArrayAdd (table, 100, row);
     516        psFree (row);
     517    }
     518
     519    image = psImageAlloc (0, 0, PS_TYPE_F32);
     520    theader = psFitsHeaderFromTable (NULL, table, "SMPFILE");
     521
     522    unlink (filename);
     523    psFits *fits = psFitsAlloc (filename);
     524    psFitsWriteImage (fits, header, image, 0, NULL);
     525    psFitsWriteTable (fits, theader, table);
     526    psFree (fits);
    390527
    391528    return true;
Note: See TracChangeset for help on using the changeset viewer.