IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 5, 2009, 5:20:02 PM (17 years ago)
Author:
Paul Price
Message:

Updating to work following merge of pap_branch_20090128. Compiles, but not tested.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppSub/src/ppSubReadoutPhotometry.c

    r21360 r21374  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-06 01:37:17 $
     8 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-06 03:20:02 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
     
    2525
    2626    if (!psMetadataLookupBool(NULL, recipe, "PHOTOMETRY")) {
    27         pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL");
    28         pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL.STDEV");
    29         return true;
     27        pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL");
     28        pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL.STDEV");
     29        return true;
    3030    }
    3131
     
    4040    pmPSF *psf = psMetadataLookupPtr(NULL, psfInputChip->analysis, "PSPHOT.PSF");
    4141    if (!psf) {
    42         psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find PSF from psphot");
    43         return false;
     42        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find PSF from psphot");
     43        return false;
    4444    }
    4545    psMetadataAddPtr(psfLoadChip->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN | PS_META_REPLACE, "PSF from matched addition", psf);
     
    5555    pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout with the sources
    5656    if (!photRO) {
    57         pmCell *cell = pmFPAfileThisCell(config->files, view, "PSPHOT.RESID"); // Output cell
    58         photRO = pmReadoutAlloc(cell); // Output readout: subtraction
     57        pmCell *cell = pmFPAfileThisCell(config->files, view, "PSPHOT.RESID"); // Output cell
     58        photRO = pmReadoutAlloc(cell); // Output readout: subtraction
    5959    }
    6060    photRO->image = psImageCopy(photRO->image, outRO->image, PS_TYPE_F32);
    61     if (outRO->weight) {
    62         photRO->weight = psImageCopy(photRO->weight, outRO->weight, PS_TYPE_F32);
     61    if (outRO->variance) {
     62        photRO->variance = psImageCopy(photRO->variance, outRO->variance, PS_TYPE_F32);
    6363    } else {
    64         psFree (photRO->weight);
    65         photRO->weight = NULL;
     64        psFree (photRO->variance);
     65        photRO->variance = NULL;
    6666    }
    6767    if (outRO->mask) {
    68         photRO->mask = psImageCopy(photRO->mask, outRO->mask, PS_TYPE_IMAGE_MASK);
     68        photRO->mask = psImageCopy(photRO->mask, outRO->mask, PS_TYPE_IMAGE_MASK);
    6969    } else {
    70         psFree (photRO->mask);
    71         photRO->mask = NULL;
     70        psFree (photRO->mask);
     71        photRO->mask = NULL;
    7272    }
    7373
     
    7777    // old-style variance renormalization
    7878    if (!ppSubReadoutRenormPhot (config, recipe, photRO)) {
    79         psError(PS_ERR_UNKNOWN, false, "failure in renormalization");
    80         return false;
     79        psError(PS_ERR_UNKNOWN, false, "failure in renormalization");
     80        return false;
    8181    }
    8282
    8383    if (!psphotReadoutMinimal(config, view)) {
    84         psWarning("Unable to perform photometry on subtracted image.");
    85         psErrorStackPrint(stderr, "Error stack from photometry:");
    86         psErrorClear();
     84        psWarning("Unable to perform photometry on subtracted image.");
     85        psErrorStackPrint(stderr, "Error stack from photometry:");
     86        psErrorClear();
    8787    }
    8888
    8989    if (stats) {
    90         psArray *sources = psMetadataLookupPtr(NULL, photRO->analysis, "PSPHOT.SOURCES"); // Sources
    91         psMetadataAddS32(stats, PS_LIST_TAIL, "NUM_SOURCES", 0, "Number of sources detected",
    92                         sources ? sources->n : 0);
    93         psMetadataAddF32(stats, PS_LIST_TAIL, "TIME_PHOT", 0, "Time to do photometry",
    94                         psTimerClear("PPSUB_PHOT"));
     90        psArray *sources = psMetadataLookupPtr(NULL, photRO->analysis, "PSPHOT.SOURCES"); // Sources
     91        psMetadataAddS32(stats, PS_LIST_TAIL, "NUM_SOURCES", 0, "Number of sources detected",
     92                        sources ? sources->n : 0);
     93        psMetadataAddF32(stats, PS_LIST_TAIL, "TIME_PHOT", 0, "Time to do photometry",
     94                        psTimerClear("PPSUB_PHOT"));
    9595    }
    9696
     
    103103    // XXX not sure that this is still needed (only if psphotReadoutMinimal measures the background)
    104104    // if (!pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL") ||
    105     //  !pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL.STDEV") ||
    106     //  !pmFPAfileDropInternal (config->files, "PSPHOT.BACKGND")) {
    107     //  psError(PS_ERR_UNKNOWN, false, "Unable to drop PSPHOT internal files.");
    108     //  return false;
     105    //  !pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL.STDEV") ||
     106    //  !pmFPAfileDropInternal (config->files, "PSPHOT.BACKGND")) {
     107    //  psError(PS_ERR_UNKNOWN, false, "Unable to drop PSPHOT internal files.");
     108    //  return false;
    109109    // }
    110110
     
    116116    // Record data about sources: not everything gets into the output CMF files
    117117    {
    118         pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout with the sources
    119         psArray *sources = psMetadataLookupPtr(NULL, photRO->analysis, "PSPHOT.SOURCES"); // Sources
    120         FILE *sourceFile = fopen("sources.dat", "w"); // File for sources
    121         fprintf(sourceFile,
    122                 "# x y mag mag_err psf_chisq cr_nsigma ext_nsigma psf_qf flags m_x m_y m_xx m_xy m_yy\n");
    123         for (int i = 0; i < sources->n; i++) {
    124             pmSource *source = sources->data[i];
    125             if (!source) {
    126                 continue;
    127             }
     118        pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout with the sources
     119        psArray *sources = psMetadataLookupPtr(NULL, photRO->analysis, "PSPHOT.SOURCES"); // Sources
     120        FILE *sourceFile = fopen("sources.dat", "w"); // File for sources
     121        fprintf(sourceFile,
     122                "# x y mag mag_err psf_chisq cr_nsigma ext_nsigma psf_qf flags m_x m_y m_xx m_xy m_yy\n");
     123        for (int i = 0; i < sources->n; i++) {
     124            pmSource *source = sources->data[i];
     125            if (!source) {
     126                continue;
     127            }
    128128
    129             float x, y;             // Position of source
    130             float chi2;             // chi^2 for source
    131             if (source->modelPSF) {
    132                 x = source->modelPSF->params->data.F32[PM_PAR_XPOS];
    133                 y = source->modelPSF->params->data.F32[PM_PAR_YPOS];
    134                 chi2 = source->modelPSF->chisq;
    135             } else if (source->peak) {
    136                 x = source->peak->xf;
    137                 y = source->peak->yf;
    138                 chi2 = NAN;
    139             } else {
    140                 psWarning("No position available for source.");
    141                 continue;
    142             }
     129            float x, y;             // Position of source
     130            float chi2;             // chi^2 for source
     131            if (source->modelPSF) {
     132                x = source->modelPSF->params->data.F32[PM_PAR_XPOS];
     133                y = source->modelPSF->params->data.F32[PM_PAR_YPOS];
     134                chi2 = source->modelPSF->chisq;
     135            } else if (source->peak) {
     136                x = source->peak->xf;
     137                y = source->peak->yf;
     138                chi2 = NAN;
     139            } else {
     140                psWarning("No position available for source.");
     141                continue;
     142            }
    143143
    144             float xMoment = NAN, yMoment = NAN, xxMoment = NAN, xyMoment = NAN, yyMoment = NAN;
    145             if (source->moments) {
    146                 xMoment = source->moments->Mx;
    147                 yMoment = source->moments->My;
    148                 xxMoment = source->moments->Mxx;
    149                 xyMoment = source->moments->Mxy;
    150                 yyMoment = source->moments->Myy;
    151             }
     144            float xMoment = NAN, yMoment = NAN, xxMoment = NAN, xyMoment = NAN, yyMoment = NAN;
     145            if (source->moments) {
     146                xMoment = source->moments->Mx;
     147                yMoment = source->moments->My;
     148                xxMoment = source->moments->Mxx;
     149                xyMoment = source->moments->Mxy;
     150                yyMoment = source->moments->Myy;
     151            }
    152152
    153             fprintf(sourceFile, "%f %f %f %f %f %f %f %f %d %f %f %f %f %f\n",
    154                     x, y, source->psfMag, source->errMag, chi2, source->crNsigma, source->extNsigma,
    155                     source->pixWeight, source->mode, xMoment, yMoment, xxMoment, xyMoment, yyMoment);
    156         }
    157         fclose(sourceFile);
     153            fprintf(sourceFile, "%f %f %f %f %f %f %f %f %d %f %f %f %f %f\n",
     154                    x, y, source->psfMag, source->errMag, chi2, source->crNsigma, source->extNsigma,
     155                    source->pixWeight, source->mode, xMoment, yMoment, xxMoment, xyMoment, yyMoment);
     156        }
     157        fclose(sourceFile);
    158158    }
    159159#endif
Note: See TracChangeset for help on using the changeset viewer.