IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13411


Ignore:
Timestamp:
May 17, 2007, 11:53:28 AM (19 years ago)
Author:
Paul Price
Message:

Adding const to view.

Location:
trunk/psphot/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphot.h

    r13374 r13411  
    1717
    1818bool            psphotModelTest (pmReadout *readout, psMetadata *recipe);
    19 bool            psphotReadout (pmConfig *config, pmFPAview *view);
     19bool            psphotReadout (pmConfig *config, const pmFPAview *view);
    2020bool            psphotReadoutCleanup (pmConfig *config, pmReadout *readout, psMetadata *recipe, pmPSF *psf, psArray *sources);
    2121bool            psphotDefineFiles (pmConfig *config, pmFPAfile *input);
     
    2626
    2727// psphotReadout functions
    28 bool            psphotImageMedian (pmConfig *config, pmFPAview *view);
     28bool            psphotImageMedian (pmConfig *config, const pmFPAview *view);
    2929psArray        *psphotFindPeaks (pmReadout *readout, psMetadata *recipe,
    3030                                 const bool returnFootprints, const int pass);
    3131#include "pmFootprint.h"
    32 psErrorCode     psphotCullPeaks(const psImage *img, const psImage *weight,
     32psErrorCode     psphotCullPeaks(const psImage *img, const psImage *weight,
    3333                                const psMetadata *recipe, psArray *footprints);
    3434psArray        *psphotSourceStats (pmReadout *readout, psMetadata *recipe, psArray *allpeaks);
     
    4848bool            psphotApResid (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf);
    4949bool            psphotMagnitudes (psArray *sources, psMetadata *recipe, pmPSF *psf, pmReadout *background);
    50 bool            psphotSkyReplace (pmConfig *config, pmFPAview *view);
     50bool            psphotSkyReplace (pmConfig *config, const pmFPAview *view);
    5151
    5252// basic support functions
     
    6868
    6969// output functions
    70 bool            psphotAddPhotcode (psMetadata *recipe, pmConfig *config, pmFPAview *view);
     70bool            psphotAddPhotcode (psMetadata *recipe, pmConfig *config, const pmFPAview *view);
    7171bool            psphotDumpMoments (psMetadata *recipe, psArray *sources);
    7272psMetadata     *psphotDefineHeader (psMetadata *recipe);
    7373int             psphotSaveImage (psMetadata *header, psImage *image, char *filename);
    7474bool            psphotDumpConfig (pmConfig *config);
    75 pmReadout      *psphotSelectBackground (pmConfig *config, pmFPAview *view, const bool stdev);
     75pmReadout      *psphotSelectBackground (pmConfig *config, const pmFPAview *view, const bool stdev);
    7676
    7777// PSF / DBL / EXT evaluation functions
     
    9393
    9494// plotting functions (available if libkapa is installed)
    95 bool            psphotPlotMoments (pmConfig *config, pmFPAview *view, psArray *sources);
    96 bool            psphotPlotPSFModel (pmConfig *config, pmFPAview *view, psArray *sources);
    97 bool            psphotFitInit ();
    98 bool            psphotFitSummary ();
    99 bool            psphotMergeSources (psArray *oldSources, psArray *newSources);
    100 bool            psphotLoadExtSources (pmConfig *config, pmFPAview *view, psArray *sources);
    101 pmPSF          *psphotLoadPSF (pmConfig *config, pmFPAview *view, psMetadata *recipe);
    102 bool            psphotSetHeaderNstars (psMetadata *recipe, psArray *sources);
    103 bool            psphotAddNoise (pmReadout *readout, psArray *sources, psMetadata *recipe, bool add);
    104 bool            psphotRadialPlot (int *kapa, const char *filename, pmSource *source);
    105 bool            psphotSourcePlots (pmReadout *readout, psArray *sources, psMetadata *recipe);
    106 bool            psphotMosaicSubimage (psImage *outImage, pmSource *source, int Xo, int Yo, int DX, int DY);
     95bool            psphotPlotMoments (pmConfig *config, pmFPAview *view, psArray *sources);
     96bool            psphotPlotPSFModel (pmConfig *config, pmFPAview *view, psArray *sources);
     97bool            psphotFitInit ();
     98bool            psphotFitSummary ();
     99bool            psphotMergeSources (psArray *oldSources, psArray *newSources);
     100bool            psphotLoadExtSources (pmConfig *config, const pmFPAview *view, psArray *sources);
     101pmPSF          *psphotLoadPSF (pmConfig *config, const pmFPAview *view, psMetadata *recipe);
     102bool            psphotSetHeaderNstars (psMetadata *recipe, psArray *sources);
     103bool            psphotAddNoise (pmReadout *readout, psArray *sources, psMetadata *recipe, bool add);
     104bool            psphotRadialPlot (int *kapa, const char *filename, pmSource *source);
     105bool            psphotSourcePlots (pmReadout *readout, psArray *sources, psMetadata *recipe);
     106bool            psphotMosaicSubimage (psImage *outImage, pmSource *source, int Xo, int Yo, int DX, int DY);
    107107
    108 bool            psphotAddWithTest (pmSource *source, bool useState);
    109 bool            psphotSubWithTest (pmSource *source, bool useState);
    110 bool            psphotSetState (pmSource *source, bool curState);
    111 bool            psphotDeblendSatstars (psArray *sources, psMetadata *recipe);
     108bool            psphotAddWithTest (pmSource *source, bool useState);
     109bool            psphotSubWithTest (pmSource *source, bool useState);
     110bool            psphotSetState (pmSource *source, bool curState);
     111bool            psphotDeblendSatstars (psArray *sources, psMetadata *recipe);
    112112bool            psphotSourceSize (pmReadout *readout, psArray *sources, psMetadata *recipe);
    113113
  • trunk/psphot/src/psphotImageMedian.c

    r13013 r13411  
    22static int npass = 0;
    33
    4 // we have 4 possibilities: (INTERNAL or I/O file) and (exists or not) 
     4// we have 4 possibilities: (INTERNAL or I/O file) and (exists or not)
    55// select model pixels (from output background model file, or create internal file)
    66static pmReadout *get_model_readout(const char *name, // name of internal/external file
    7                                     const pmConfig *config, // configuration information
    8                                     pmFPAview *view,
    9                                     pmFPA *inFPA,
    10                                     const psImageBinning *binning) {
     7                                    const pmConfig *config, // configuration information
     8                                    const pmFPAview *view,
     9                                    pmFPA *inFPA,
     10                                    const psImageBinning *binning) {
    1111    pmReadout *model = NULL;
    1212
     
    1414    pmFPAfile *file = psMetadataLookupPtr(&status, config->files, name);
    1515    if (file == NULL) {
    16         // we are not using PSPHOT.BACKMDL as an I/O file: define an internal version
     16        // we are not using PSPHOT.BACKMDL as an I/O file: define an internal version
    1717        model = pmFPAfileDefineInternal (config->files, name, binning->nXruff, binning->nYruff, PS_TYPE_F32);
    1818    } else {
    19         if (file->mode == PM_FPA_MODE_INTERNAL) {
    20             // we are not using PSPHOT.BACKMDL as an I/O file: already defined above
    21             model = file->readout;
    22         } else {
    23             // we are using PSPHOT.BACKMDL as an I/O file: select readout or create
    24             model = pmFPAviewThisReadout (view, file->fpa);
    25             if (model == NULL) {
    26                 // readout does not yet exist: create from input
    27                 // XXX we have an inconsistency in this calculation here and in pmFPACopy
    28                 // XXX use the psImageBinning functions to set the output image size
    29                 pmFPAfileCopyStructureView (file->fpa, inFPA, binning->nXbin, binning->nYbin, view);
    30                 model = pmFPAviewThisReadout (view, file->fpa);
    31                 PS_ASSERT (binning->nXruff == model->image->numCols, false);
    32                 PS_ASSERT (binning->nYruff == model->image->numRows, false);
    33             }
    34         }
     19        if (file->mode == PM_FPA_MODE_INTERNAL) {
     20            // we are not using PSPHOT.BACKMDL as an I/O file: already defined above
     21            model = file->readout;
     22        } else {
     23            // we are using PSPHOT.BACKMDL as an I/O file: select readout or create
     24            model = pmFPAviewThisReadout (view, file->fpa);
     25            if (model == NULL) {
     26                // readout does not yet exist: create from input
     27                // XXX we have an inconsistency in this calculation here and in pmFPACopy
     28                // XXX use the psImageBinning functions to set the output image size
     29                pmFPAfileCopyStructureView (file->fpa, inFPA, binning->nXbin, binning->nYbin, view);
     30                model = pmFPAviewThisReadout (view, file->fpa);
     31                PS_ASSERT (binning->nXruff == model->image->numCols, false);
     32                PS_ASSERT (binning->nYruff == model->image->numRows, false);
     33            }
     34        }
    3535    }
    3636
     
    4040// generate the median in NxN boxes, clipping heavily
    4141// linear interpolation to generate full-scale model
    42 bool psphotImageMedian (pmConfig *config, pmFPAview *view)
     42bool psphotImageMedian (pmConfig *config, const pmFPAview *view)
    4343{
    4444    bool status = true;
     
    7070    char *statsName = psMetadataLookupStr (&status, recipe, "SKY_STAT");
    7171    if (statsName == NULL) {
    72         statsName = defaultStatsName;
     72        statsName = defaultStatsName;
    7373    }
    7474    psStatsOptions statsOptionLocation = psStatsOptionFromString(statsName);
    7575    if (!(statsOptionLocation & (PS_STAT_SAMPLE_MEAN |
    76                                 PS_STAT_SAMPLE_MEDIAN |
    77                                 PS_STAT_ROBUST_MEDIAN |
    78                                 PS_STAT_ROBUST_QUARTILE |
    79                                 PS_STAT_CLIPPED_MEAN |
    80                                 PS_STAT_FITTED_MEAN |
    81                                 PS_STAT_FITTED_MEAN_V2 |
    82                                 PS_STAT_FITTED_MEAN_V3))) {
    83         statsOptionLocation = PS_STAT_FITTED_MEAN;
     76                                PS_STAT_SAMPLE_MEDIAN |
     77                                PS_STAT_ROBUST_MEDIAN |
     78                                PS_STAT_ROBUST_QUARTILE |
     79                                PS_STAT_CLIPPED_MEAN |
     80                                PS_STAT_FITTED_MEAN |
     81                                PS_STAT_FITTED_MEAN_V2 |
     82                                PS_STAT_FITTED_MEAN_V3))) {
     83        statsOptionLocation = PS_STAT_FITTED_MEAN;
    8484    }
    8585
    8686    psStatsOptions statsOptionWidth = PS_STAT_NONE;
    8787    if (statsOptionLocation & (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_MEDIAN)) {
    88         statsOptionWidth = PS_STAT_SAMPLE_STDEV;
     88        statsOptionWidth = PS_STAT_SAMPLE_STDEV;
    8989    } else if (statsOptionLocation & (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_QUARTILE)) {
    9090#if 1
    91         statsOptionWidth = PS_STAT_ROBUST_STDEV; // not set; => NaN
     91        statsOptionWidth = PS_STAT_ROBUST_STDEV; // not set; => NaN
    9292#else
    93         statsOptionWidth = PS_STAT_FITTED_STDEV;
     93        statsOptionWidth = PS_STAT_FITTED_STDEV;
    9494#endif
    9595    } else if (statsOptionLocation & PS_STAT_FITTED_MEAN) {
    96         statsOptionWidth = PS_STAT_FITTED_STDEV;
     96        statsOptionWidth = PS_STAT_FITTED_STDEV;
    9797    } else if (statsOptionLocation & PS_STAT_CLIPPED_MEAN) {
    98         statsOptionWidth = PS_STAT_CLIPPED_STDEV;
     98        statsOptionWidth = PS_STAT_CLIPPED_STDEV;
    9999    } else if (statsOptionLocation & PS_STAT_FITTED_MEAN_V2) {
    100         statsOptionWidth = PS_STAT_FITTED_STDEV_V2;
     100        statsOptionWidth = PS_STAT_FITTED_STDEV_V2;
    101101    } else if (statsOptionLocation & PS_STAT_FITTED_MEAN_V3) {
    102         statsOptionWidth = PS_STAT_FITTED_STDEV_V3;
     102        statsOptionWidth = PS_STAT_FITTED_STDEV_V3;
    103103    } else {
    104         psAbort("Unable to estimate variance of selected statsOptionLocations 0x%x", statsOptionLocation);
     104        psAbort("Unable to estimate variance of selected statsOptionLocations 0x%x", statsOptionLocation);
    105105    }
    106106
     
    110110    // set range for old-version of sky statistic
    111111    if (statsOptionLocation & PS_STAT_ROBUST_QUARTILE) {
    112         stats->min = 0.25;
    113         stats->max = 0.75;
     112        stats->min = 0.25;
     113        stats->max = 0.75;
    114114    }
    115115
     
    130130    if (!status) {
    131131        if ((stats->options & PS_STAT_FITTED_MEAN) || (stats->options & PS_STAT_FITTED_MEAN_V2)) {
    132             stats->clipSigma = 1.0;
    133         } else {
    134             stats->clipSigma = 3.0;
    135         }
     132            stats->clipSigma = 1.0;
     133        } else {
     134            stats->clipSigma = 3.0;
     135        }
    136136    }
    137137
     
    172172    for (int iy = 0; iy < model->image->numRows; iy++) {
    173173        for (int ix = 0; ix < model->image->numCols; ix++) {
    174            
    175             // convert the ruff grid cell to the equivalent fine grid cell
    176             // XXX we need to watch out for row0,col0
    177             ruffRegion = psRegionSet (ix, ix + 2, iy, iy + 2);
    178             fineRegion = psImageBinningSetFineRegion (binning, ruffRegion);
     174
     175            // convert the ruff grid cell to the equivalent fine grid cell
     176            // XXX we need to watch out for row0,col0
     177            ruffRegion = psRegionSet (ix, ix + 2, iy, iy + 2);
     178            fineRegion = psImageBinningSetFineRegion (binning, ruffRegion);
    179179            fineRegion = psRegionForImage (image, fineRegion);
    180180
    181181            psImage *subset  = psImageSubset (image, fineRegion);
    182             if (!subset->numCols || !subset->numRows) {
    183                 psFree (subset);
    184                 continue;
    185             }
     182            if (!subset->numCols || !subset->numRows) {
     183                psFree (subset);
     184                continue;
     185            }
    186186            psImage *submask = psImageSubset (mask, fineRegion);
    187187
    188             // reset the default values
    189             *stats = *statsDefaults;
     188            // reset the default values
     189            *stats = *statsDefaults;
    190190
    191191            // Use the selected background statistic for the first pass
    192             // If it fails, fall back on the "ROBUST_MEDIAN" version
    193             // If both fail, set the pixel to NAN and (below) interpolate
    194             // XXX psImageBackground will probably be renamed psImageStats
    195             // XXX don't bother trying if there are no valid pixels...
    196 
    197             if (psImageBackground(stats, subset, submask, 0xff, rng)) {
    198                 if (stats->options & PS_STAT_ROBUST_QUARTILE) {
    199                     modelData[iy][ix] = stats->robustMedian;
    200                 } else {       
    201                     modelData[iy][ix] = psStatsGetValue(stats, statsOptionLocation);
    202                 }
    203                 modelStdevData[iy][ix] = psStatsGetValue(stats, statsOptionWidth);
    204             } else {
    205                 psStatsOptions currentOptions = stats->options;
    206                 stats->options = PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV;
    207                 if (!psImageBackground(stats, subset, submask, 0xff, rng)) {
    208                     psLogMsg ("psphot", PS_LOG_WARN, "Failed to estimate background using ROBUST_MEDIAN for "
    209                                "(%dx%d, (row0,col0) = (%d,%d)",
    210                                subset->numRows, subset->numCols, subset->row0, subset->col0);
    211                     modelData[iy][ix] = modelStdevData[iy][ix] = NAN;
    212                 } else {
    213                     modelData[iy][ix] = psStatsGetValue (stats, PS_STAT_ROBUST_MEDIAN);
    214                     modelStdevData[iy][ix] = psStatsGetValue(stats, PS_STAT_ROBUST_STDEV);
    215                 }
    216                 // drop errors caused by psImageBackground failures
    217                 // XXX we probably should trap and exit on serious failures
    218                 psErrorClear();
    219                 stats->options = currentOptions;
    220             }
    221             modelData[iy][ix] += SKY_BIAS;
     192            // If it fails, fall back on the "ROBUST_MEDIAN" version
     193            // If both fail, set the pixel to NAN and (below) interpolate
     194            // XXX psImageBackground will probably be renamed psImageStats
     195            // XXX don't bother trying if there are no valid pixels...
     196
     197            if (psImageBackground(stats, subset, submask, 0xff, rng)) {
     198                if (stats->options & PS_STAT_ROBUST_QUARTILE) {
     199                    modelData[iy][ix] = stats->robustMedian;
     200                } else {
     201                    modelData[iy][ix] = psStatsGetValue(stats, statsOptionLocation);
     202                }
     203                modelStdevData[iy][ix] = psStatsGetValue(stats, statsOptionWidth);
     204            } else {
     205                psStatsOptions currentOptions = stats->options;
     206                stats->options = PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV;
     207                if (!psImageBackground(stats, subset, submask, 0xff, rng)) {
     208                    psLogMsg ("psphot", PS_LOG_WARN, "Failed to estimate background using ROBUST_MEDIAN for "
     209                               "(%dx%d, (row0,col0) = (%d,%d)",
     210                               subset->numRows, subset->numCols, subset->row0, subset->col0);
     211                    modelData[iy][ix] = modelStdevData[iy][ix] = NAN;
     212                } else {
     213                    modelData[iy][ix] = psStatsGetValue (stats, PS_STAT_ROBUST_MEDIAN);
     214                    modelStdevData[iy][ix] = psStatsGetValue(stats, PS_STAT_ROBUST_STDEV);
     215                }
     216                // drop errors caused by psImageBackground failures
     217                // XXX we probably should trap and exit on serious failures
     218                psErrorClear();
     219                stats->options = currentOptions;
     220            }
     221            modelData[iy][ix] += SKY_BIAS;
    222222            psFree (subset);
    223223            psFree (submask);
     
    227227    // patch over bad regions (use average of 8 possible neighbor pixels)
    228228    // XXX consider testing all pixels against the 8 neighbors and replacing outliers...
    229     double Count = 0;                   // number of good pixels
    230     double Value = 0;                   // sum of good pixel's value
    231     double ValueStdev = 0;              // sum of good pixel's standard deviations
     229    double Count = 0;                   // number of good pixels
     230    double Value = 0;                   // sum of good pixel's value
     231    double ValueStdev = 0;              // sum of good pixel's standard deviations
    232232    for (int iy = 0; iy < model->image->numRows; iy++) {
    233233        for (int ix = 0; ix < model->image->numCols; ix++) {
    234             if (!isnan(modelData[iy][ix])) {
    235                 Value += modelData[iy][ix];
    236                 ValueStdev += modelStdevData[iy][ix];
    237                 Count++;
    238                 continue;
    239             }
    240 
    241             double value = 0;
    242             double count = 0;
    243             for (int jy = iy - 1; jy <= iy + 1; jy++) {
    244                 if (jy <   0) continue;
    245                 if (jy >= model->image->numRows) continue;
    246                 for (int jx = ix - 1; jx <= ix + 1; jx++) {
    247                     if (!jx && !jy) continue;
    248                     if (jx   <   0) continue;
    249                     if (jx   >= model->image->numCols) continue;
    250                     value += modelData[jy][jx];
    251                     count += 1.0;
    252                 }
    253             }
    254             if (count > 0) modelData[iy][ix] = value / count;
    255         }
     234            if (!isnan(modelData[iy][ix])) {
     235                Value += modelData[iy][ix];
     236                ValueStdev += modelStdevData[iy][ix];
     237                Count++;
     238                continue;
     239            }
     240
     241            double value = 0;
     242            double count = 0;
     243            for (int jy = iy - 1; jy <= iy + 1; jy++) {
     244                if (jy <   0) continue;
     245                if (jy >= model->image->numRows) continue;
     246                for (int jx = ix - 1; jx <= ix + 1; jx++) {
     247                    if (!jx && !jy) continue;
     248                    if (jx   <   0) continue;
     249                    if (jx   >= model->image->numCols) continue;
     250                    value += modelData[jy][jx];
     251                    count += 1.0;
     252                }
     253            }
     254            if (count > 0) modelData[iy][ix] = value / count;
     255        }
    256256    }
    257257    assert (Count > 0);
    258258    Value /= Count;
    259259    ValueStdev /= Count;
    260            
     260
    261261    // patch over remaining bad regions (use global average)
    262262    for (int iy = 0; iy < model->image->numRows; iy++) {
    263263        for (int ix = 0; ix < model->image->numCols; ix++) {
    264             if (!isnan(modelData[iy][ix])) continue;
    265             modelData[iy][ix] = Value;
    266             modelStdevData[iy][ix] = ValueStdev;
    267         }
     264            if (!isnan(modelData[iy][ix])) continue;
     265            modelData[iy][ix] = Value;
     266            modelStdevData[iy][ix] = ValueStdev;
     267        }
    268268    }
    269269
     
    273273    psMetadataAddF32(recipe, PS_LIST_TAIL, "SKY_STDEV", PS_META_REPLACE, "sky stdev", ValueStdev);
    274274    psLogMsg ("psphot", PS_LOG_INFO, "image sky : mean %f stdev %f", Value, ValueStdev);
    275    
     275
    276276    // measure image and background stats and save for later output
    277277    psStats *statsBck = psStatsAlloc (PS_STAT_SAMPLE_MEAN |
    278                                       PS_STAT_SAMPLE_STDEV |
    279                                       PS_STAT_MIN |
    280                                       PS_STAT_MAX);
     278                                      PS_STAT_SAMPLE_STDEV |
     279                                      PS_STAT_MIN |
     280                                      PS_STAT_MAX);
    281281    psImageStats (statsBck, model->image, NULL, 0);
    282282    psMetadataAddF32 (recipe, PS_LIST_TAIL, "SKY_MODEL_MEAN",
    283                       PS_META_REPLACE, "sky model mean",          statsBck->sampleMean);
     283                      PS_META_REPLACE, "sky model mean",          statsBck->sampleMean);
    284284    psMetadataAddF32 (recipe, PS_LIST_TAIL, "SKY_MODEL_STDEV",
    285                       PS_META_REPLACE, "sky model stdev",         statsBck->sampleStdev);
     285                      PS_META_REPLACE, "sky model stdev",         statsBck->sampleStdev);
    286286    psMetadataAddF32 (recipe, PS_LIST_TAIL, "SKY_MODEL_MAX",
    287                       PS_META_REPLACE, "sky model maximum value", statsBck->max);
     287                      PS_META_REPLACE, "sky model maximum value", statsBck->max);
    288288    psMetadataAddF32 (recipe, PS_LIST_TAIL, "SKY_MODEL_MIN",
    289                       PS_META_REPLACE, "sky model minimum value", statsBck->min);
     289                      PS_META_REPLACE, "sky model minimum value", statsBck->min);
    290290    psMetadataAddS32 (recipe, PS_LIST_TAIL, "SKY_MODEL_NX",
    291                       PS_META_REPLACE, "sky model size (x)",      model->image->numCols);
     291                      PS_META_REPLACE, "sky model size (x)",      model->image->numCols);
    292292    psMetadataAddS32 (recipe, PS_LIST_TAIL, "SKY_MODEL_NY",
    293                       PS_META_REPLACE, "sky model size (y)",      model->image->numRows);
    294     psLogMsg ("psphot", PS_LOG_INFO, "background sky : min %f mean %f max %f stdev %f", 
    295               statsBck->min, statsBck->sampleMean, statsBck->max, statsBck->sampleStdev);
     293                      PS_META_REPLACE, "sky model size (y)",      model->image->numRows);
     294    psLogMsg ("psphot", PS_LOG_INFO, "background sky : min %f mean %f max %f stdev %f",
     295              statsBck->min, statsBck->sampleMean, statsBck->max, statsBck->sampleStdev);
    296296    psFree (statsBck);
    297297
     
    299299    file = psMetadataLookupPtr (&status, config->files, "PSPHOT.BACKGND");
    300300    if (file) {
    301         // we are using PSPHOT.BACKGND as an I/O file: select readout or create
    302         if (file->mode == PM_FPA_MODE_INTERNAL) {
    303             background = file->readout;
    304         } else {
    305             background = pmFPAviewThisReadout (view, file->fpa);
    306         }
    307         if (background == NULL) {
    308             // readout does not yet exist: create from input
    309             pmFPAfileCopyStructureView (file->fpa, inFPA, 1, 1, view);
    310             background = pmFPAviewThisReadout (view, file->fpa);
    311             if ((image->numCols != background->image->numCols) || (image->numRows != background->image->numRows)) {
    312                 psError (PSPHOT_ERR_PROG, true, "inconsistent sizes for background dimensions");
    313                 return false;
    314             }
    315         }
     301        // we are using PSPHOT.BACKGND as an I/O file: select readout or create
     302        if (file->mode == PM_FPA_MODE_INTERNAL) {
     303            background = file->readout;
     304        } else {
     305            background = pmFPAviewThisReadout (view, file->fpa);
     306        }
     307        if (background == NULL) {
     308            // readout does not yet exist: create from input
     309            pmFPAfileCopyStructureView (file->fpa, inFPA, 1, 1, view);
     310            background = pmFPAviewThisReadout (view, file->fpa);
     311            if ((image->numCols != background->image->numCols) || (image->numRows != background->image->numRows)) {
     312                psError (PSPHOT_ERR_PROG, true, "inconsistent sizes for background dimensions");
     313                return false;
     314            }
     315        }
    316316    } else {
    317317        background = pmFPAfileDefineInternal (config->files, "PSPHOT.BACKGND", image->numCols, image->numRows, PS_TYPE_F32);
     
    321321    // linear interpolation to full-scale
    322322    if (!psImageUnbin (background->image, model->image, binning)) {
    323         psError (PSPHOT_ERR_PROG, true, "failed to build background image");
    324         return false;
    325     }
    326        
     323        psError (PSPHOT_ERR_PROG, true, "failed to build background image");
     324        return false;
     325    }
     326
    327327    psLogMsg ("psphot", PS_LOG_MINUTIA, "build resampled image: %f sec\n", psTimerMark ("psphot"));
    328328
     
    330330    file = psMetadataLookupPtr (&status, config->files, "PSPHOT.BACKSUB");
    331331    if (file) {
    332         // we are using PSPHOT.BACKSUB as an I/O file: select readout or create
    333         backSub = pmFPAviewThisReadout (view, file->fpa);
    334         if (backSub == NULL) {
    335             // readout does not yet exist: create from input
    336             pmFPAfileCopyStructureView (file->fpa, inFPA, 1, 1, view);
    337             backSub = pmFPAviewThisReadout (view, file->fpa);
    338         }
     332        // we are using PSPHOT.BACKSUB as an I/O file: select readout or create
     333        backSub = pmFPAviewThisReadout (view, file->fpa);
     334        if (backSub == NULL) {
     335            // readout does not yet exist: create from input
     336            pmFPAfileCopyStructureView (file->fpa, inFPA, 1, 1, view);
     337            backSub = pmFPAviewThisReadout (view, file->fpa);
     338        }
    339339    }
    340340
    341341    if (psTraceGetLevel("psphot") > 5) {
    342         char name[256];
    343         sprintf (name, "image.%02d.fits", npass);
    344         psphotSaveImage (NULL, image, name);
    345         sprintf (name, "back.%02d.fits", npass);
    346         psphotSaveImage (NULL, background->image, name);
    347         sprintf (name, "mask.%02d.fits", npass);
    348         psphotSaveImage (NULL, mask, name);
    349         sprintf (name, "backmdl.%02d.fits", npass);
    350         psphotSaveImage (NULL, model->image, name);
     342        char name[256];
     343        sprintf (name, "image.%02d.fits", npass);
     344        psphotSaveImage (NULL, image, name);
     345        sprintf (name, "back.%02d.fits", npass);
     346        psphotSaveImage (NULL, background->image, name);
     347        sprintf (name, "mask.%02d.fits", npass);
     348        psphotSaveImage (NULL, mask, name);
     349        sprintf (name, "backmdl.%02d.fits", npass);
     350        psphotSaveImage (NULL, model->image, name);
    351351    }
    352352
     
    354354    for (int j = 0; j < image->numRows; j++) {
    355355        for (int i = 0; i < image->numCols; i++) {
    356             image->data.F32[j][i] -= backData[j][i];
    357             if (backSub) {
    358                 backSub->image->data.F32[j][i] = image->data.F32[j][i];
    359             }
     356            image->data.F32[j][i] -= backData[j][i];
     357            if (backSub) {
     358                backSub->image->data.F32[j][i] = image->data.F32[j][i];
     359            }
    360360        }
    361361    }
    362362
    363363    if (psTraceGetLevel("psphot") > 5) {
    364         char name[256];
    365         sprintf (name, "backsub.%02d.fits", npass);
    366         psphotSaveImage (NULL, image, name);
     364        char name[256];
     365        sprintf (name, "backsub.%02d.fits", npass);
     366        psphotSaveImage (NULL, image, name);
    367367    }
    368368    npass ++;
  • trunk/psphot/src/psphotLoadPSF.c

    r13225 r13411  
    22
    33// load an externally supplied psf model
    4 pmPSF *psphotLoadPSF (pmConfig *config, pmFPAview *view, psMetadata *recipe) {
     4pmPSF *psphotLoadPSF (pmConfig *config, const pmFPAview *view, psMetadata *recipe) {
    55
    66    // find the currently selected readout
     
    1111    pmPSF *psf = psMetadataLookupPtr (NULL, readout->analysis, "PSPHOT.PSF");
    1212    if (psf == NULL) {
    13         psLogMsg ("psphot", 3, "no psf supplied for this readout");
    14         return NULL;
     13        psLogMsg ("psphot", 3, "no psf supplied for this readout");
     14        return NULL;
    1515    }
    1616
  • trunk/psphot/src/psphotMergeSources.c

    r13225 r13411  
    55
    66    for (int i = 0; i < newSources->n; i++) {
    7         pmSource *source = newSources->data[i];
    8         psArrayAdd (oldSources, 100, source);
     7        pmSource *source = newSources->data[i];
     8        psArrayAdd (oldSources, 100, source);
    99    }
    1010    return true;
    1111}
    1212
    13 // merge the externally supplied sources with the existing sources.  mark them as having 
     13// merge the externally supplied sources with the existing sources.  mark them as having
    1414// mode PM_SOURCE_MODE_EXTERNAL
    15 bool psphotLoadExtSources (pmConfig *config, pmFPAview *view, psArray *sources) {
     15bool psphotLoadExtSources (pmConfig *config, const pmFPAview *view, psArray *sources) {
    1616
    1717    // find the currently selected readout
    1818    pmReadout  *readout = pmFPAfileThisReadout (config->files, view, "PSPHOT.INPUT.CMF");
    1919    if (!readout) {
    20         psLogMsg ("psphot", 3, "no external sources supplied");
    21         return true;
     20        psLogMsg ("psphot", 3, "no external sources supplied");
     21        return true;
    2222    }
    2323
    2424    psArray *extSources = psMetadataLookupPtr (NULL, readout->analysis, "PSPHOT.SOURCES");
    2525    if (!extSources) {
    26         psLogMsg ("psphot", 3, "no external sources for this readout");
    27         return true;
     26        psLogMsg ("psphot", 3, "no external sources for this readout");
     27        return true;
    2828    }
    2929
    3030    for (int i = 0; i < extSources->n; i++) {
    31         pmSource *source = extSources->data[i];
    32         source->mode |= PM_SOURCE_MODE_EXTERNAL;
    33         pmModel *model = source->modelPSF;
     31        pmSource *source = extSources->data[i];
     32        source->mode |= PM_SOURCE_MODE_EXTERNAL;
     33        pmModel *model = source->modelPSF;
    3434
    35         float xpos = model->params->data.F32[PM_PAR_XPOS];
    36         float ypos = model->params->data.F32[PM_PAR_YPOS];
     35        float xpos = model->params->data.F32[PM_PAR_XPOS];
     36        float ypos = model->params->data.F32[PM_PAR_YPOS];
    3737
    38         source->peak = pmPeakAlloc(xpos, ypos, 1.0, PM_PEAK_LONE);
    39         source->peak->xf = xpos;
    40         source->peak->yf = ypos;
    41         source->peak->flux = 1.0;
    42        
    43         // drop the loaded source modelPSF
    44         psFree (source->modelPSF);
    45         source->modelPSF = NULL;
     38        source->peak = pmPeakAlloc(xpos, ypos, 1.0, PM_PEAK_LONE);
     39        source->peak->xf = xpos;
     40        source->peak->yf = ypos;
     41        source->peak->flux = 1.0;
     42
     43        // drop the loaded source modelPSF
     44        psFree (source->modelPSF);
     45        source->modelPSF = NULL;
    4646    }
    4747
  • trunk/psphot/src/psphotOutput.c

    r13035 r13411  
    22
    33pmReadout *psphotSelectBackground (pmConfig *config,
    4                                   pmFPAview *view,
    5                                    const bool stdev // return background's standard deviation?
    6                                    ) {
     4                                   const pmFPAview *view,
     5                                   const bool stdev // return background's standard deviation?
     6                                   ) {
    77
    88    bool status;
    9     pmReadout *background;   
     9    pmReadout *background;
    1010
    1111    pmFPAfile *file = psMetadataLookupPtr (&status, config->files, "PSPHOT.BACKMDL");
    1212    if (!file) return NULL;
    1313    if (file->mode == PM_FPA_MODE_INTERNAL) {
    14         background = file->readout;
     14        background = file->readout;
    1515    } else {
    16         background = pmFPAviewThisReadout (view, file->fpa);
     16        background = pmFPAviewThisReadout (view, file->fpa);
    1717    }
    1818    return background;
     
    6767            }
    6868
    69             fprintf (f, "%d %d %f %f %d\n",
    70                      (j + source->pixels->col0),
    71                      (i + source->pixels->row0),
    72                      source->pixels->data.F32[i][j],
    73                      1.0 / source->weight->data.F32[i][j],
    74                      source->maskObj->data.U8[i][j]);
     69            fprintf (f, "%d %d %f %f %d\n",
     70                     (j + source->pixels->col0),
     71                     (i + source->pixels->row0),
     72                     source->pixels->data.F32[i][j],
     73                     1.0 / source->weight->data.F32[i][j],
     74                     source->maskObj->data.U8[i][j]);
    7575        }
    7676    }
     
    7979}
    8080
    81 bool psphotAddPhotcode (psMetadata *recipe, pmConfig *config, pmFPAview *view) {
     81bool psphotAddPhotcode (psMetadata *recipe, pmConfig *config, const pmFPAview *view) {
    8282
    8383    bool status;
     
    128128    psMetadataItemSupplement (header, recipe, "SKYBIAS");
    129129    psMetadataItemSupplement (header, recipe, "SKYSAT");
    130    
     130
    131131    // PSF model parameters (shape values for image center)
    132132    psMetadataItemSupplement (header, recipe, "NPSFSTAR");
     
    148148    psMetadataItemSupplement (header, recipe, "SKY_NX");
    149149    psMetadataItemSupplement (header, recipe, "SKY_NY");
    150    
     150
    151151    // XXX : don't require any of these about values to exist
    152152    psErrorClear ();
  • trunk/psphot/src/psphotReadout.c

    r13375 r13411  
    11# include "psphotInternal.h"
    22
    3 bool psphotReadout (pmConfig *config, pmFPAview *view) {
     3bool psphotReadout(pmConfig *config, const pmFPAview *view) {
    44
    55    bool dump = (psTraceGetLevel("psphot") >= 6);
     
    6868       int growRadius = psMetadataLookupS32(NULL, recipe, "FOOTPRINT_GROW_RADIUS");
    6969       if (growRadius > 0) {
    70            psArray *tmp = pmGrowFootprintArray(footprints, growRadius);
    71            psFree(footprints);
    72            footprints = tmp;
     70           psArray *tmp = pmGrowFootprintArray(footprints, growRadius);
     71           psFree(footprints);
     72           footprints = tmp;
    7373       }
    7474       psphotCullPeaks(readout->image, readout->weight, recipe, footprints);
     
    180180       int growRadius = psMetadataLookupS32(NULL, recipe, "FOOTPRINT_GROW_RADIUS_2");
    181181       if (growRadius > 0) {
    182            psArray *tmp = pmGrowFootprintArray(newFootprints, growRadius);
    183            psFree(newFootprints);
    184            newFootprints = tmp;
     182           psArray *tmp = pmGrowFootprintArray(newFootprints, growRadius);
     183           psFree(newFootprints);
     184           newFootprints = tmp;
    185185       }
    186186
  • trunk/psphot/src/psphotSkyReplace.c

    r12792 r13411  
    33// XXX make this an option?
    44// in order to  successfully replace the sky, we must define a corresponding file...
    5 bool psphotSkyReplace (pmConfig *config, pmFPAview *view) {
     5bool psphotSkyReplace (pmConfig *config, const pmFPAview *view) {
    66
    77    psTimerStart ("psphot");
     
    2222    // replace the background model
    2323    for (int j = 0; j < readout->image->numRows; j++) {
    24         for (int i = 0; i < readout->image->numCols; i++) {
    25             if (!mask[j][i]) {
    26                 image[j][i] += back[j][i];
    27             }
    28         }
     24        for (int i = 0; i < readout->image->numCols; i++) {
     25            if (!mask[j][i]) {
     26                image[j][i] += back[j][i];
     27            }
     28        }
    2929    }
    3030    psLogMsg ("psphot.sky", PS_LOG_DETAIL, "replace background flux : %f sec\n", psTimerMark ("psphot"));
Note: See TracChangeset for help on using the changeset viewer.