IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12592


Ignore:
Timestamp:
Mar 26, 2007, 5:36:18 PM (19 years ago)
Author:
eugene
Message:

using common psImageBinning tools

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/dvoTools/src/dvoMakeCorrUnbin.c

    r11805 r12592  
    2626    assert (trimsec);
    2727
    28     // dimensions of input image:
    29     int nx = inData->image->numCols;
    30     int ny = inData->image->numRows;
     28    // I have the fine and ruff image sizes, determine the binning factor
     29    psImageBinning *binning = psImageBinningAlloc();
     30    binning->nXruff = inData->numCols;
     31    binning->nYruff = inData->numRows;
     32    binning->nXfine = trimsec->x1 - trimsec->x0;
     33    binning->nYfine = trimsec->y1 - trimsec->y0;
     34    psImageBinningSetBinning (binning, PS_IMAGE_BINNING_CENTER);
     35    psImageBinningSetSkip(binning, inData);
    3136
    32     // dimensions of output image:
    33     int Nx = trimsec->x1 - trimsec->x0;
    34     int Ny = trimsec->y1 - trimsec->y0;
    35 
    36     // choose the binning factor which would yield nx,ny pixels from Nx,Ny
    37     int DX = Nx / nx;                   // 36 / 3 = 12, 35 / 3 = 11, 34 / 3 = 11
    38     if (Nx % nx) DX ++;                 // 36, 35, 34 -> DX = 12
    39     int xOffset = (Nx % nx) / 2;        // for nx = 3, xOffset = 0 or 1
    40    
    41     int DY = Ny / ny;
    42     if (Ny % ny) DY ++;
    43     int yOffset = (Ny % ny) / 2;
    44 
     37    // construct the supporing pmFPA/pmChip/pmCell structures
    4538    pmReadout *outData = pmFPAviewThisReadout (view, outFile->fpa);
    4639    if (outData == NULL) {
     
    4841        pmChip *outChip = pmFPAviewThisChip (view, outFile->fpa);
    4942
    50         pmChipCopyStructure (outChip, inChip, DX, DY);
     43        pmChipCopyStructure (outChip, inChip, binning->nXbin, binning->nYbin);
    5144        outData = pmFPAviewThisReadout (view, outFile->fpa);
    5245        assert (outData != NULL);
    5346    }
    5447
    55     psImageRecycle (outData->image, Nx, Ny, PS_TYPE_F32);
     48    // generate the output (fine-scale) image array
     49    psImageRecycle (outData->image, binning->nXfine, binning->nYfine, PS_TYPE_F32);
    5650
    57     // linear interpolation to full-scale
    58     if (!psImageUnbin (outData->image, inData->image, DX, DY, xOffset, yOffset)) {
     51    // linear interpolation to full fine scale
     52    if (!psImageUnbin (outData->image, inData->image, binning)) {
    5953        psError (PS_ERR_UNKNOWN, true, "failed to unbin image");
     54        psFree (binning);
    6055        return false;
    6156    }
     
    7469    // exit (0);
    7570
     71    psFree (binning);
    7672    return true;
    7773}
  • trunk/ppImage/src/ppImageRebinReadout.c

    r10589 r12592  
    6363}
    6464
     65// XXX this should be made consistent with psImageBinning
    6566bool ppImageRebinReadout (pmReadout *output, pmReadout *input, pmFPAfile *outFile)
    6667{
  • trunk/psphot/src/psphotImageLoop.c

    r12587 r12592  
    6363        while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
    6464            psLogMsg ("psphot", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     65            // XXX who should be setting cell->process?
    6566            // if (! cell->process || ! cell->file_exists) { continue; }
    66             if (! cell->process) { continue; }
     67            // if (! cell->process) { continue; }
    6768           
    6869            // process each of the readouts
  • trunk/psphot/src/psphotImageMedian.c

    r12587 r12592  
    11# include "psphot.h"
     2// # define TESTSAVE
    23
    34// generate the median in NxN boxes, clipping heavily
     
    89    pmFPA *inFPA;
    910    pmFPAfile *file;
    10     psRegion region;
    1111    static char *defaultStatsName = "FITTED_MEAN";
    1212
     
    8585    psImage *mask  = readout->mask;
    8686
    87     // dimensions of input & output image
    88     int Nx = image->numCols;
    89     int Ny = image->numRows;
    90 
    91     // scaling factor
    92     int DX = psMetadataLookupS32 (&status, recipe, "BACKGROUND.XBIN");
    93     int DY = psMetadataLookupS32 (&status, recipe, "BACKGROUND.YBIN");
    94 
    95     // overhang : we will balance this evenly
    96     int xExtra = (Nx % DX) / 2;
    97     int yExtra = (Ny % DY) / 2;
    98     int xOffset = (xExtra > 0) ? DX - xExtra : 0;
    99     int yOffset = (yExtra > 0) ? DY - yExtra : 0;
    100     xOffset -= image->col0;
    101     yOffset -= image->row0;
    102 
    103     // dimensions of binned image
    104     int nx, ny;
    105     if (Nx % DX == 0) {
    106         nx = Nx / DX;
    107     } else {
    108         nx = (xExtra) ? (Nx / DX) + 2 : (Nx / DX) + 1;
    109     }
    110     if (Ny % DY == 0) {
    111         ny = Ny / DY;
    112     } else {
    113         ny = (yExtra) ? (Ny / DY) + 2 : (Ny / DY) + 1;
    114     }
     87    // I have the fine image size, I know the binning factor, determine the ruff image size
     88    psImageBinning *binning = psImageBinningAlloc();
     89    binning->nXfine = image->numCols;
     90    binning->nYfine = image->numRows;
     91    binning->nXbin  = psMetadataLookupS32 (&status, recipe, "BACKGROUND.XBIN");
     92    binning->nYbin  = psMetadataLookupS32 (&status, recipe, "BACKGROUND.YBIN");
     93
     94    psImageBinningSetRuffSize(binning, PS_IMAGE_BINNING_CENTER);
     95    psImageBinningSetSkip(binning, image);
     96    status = psMetadataAddPtr(recipe, PS_LIST_TAIL, "PSPHOT.BACKGROUND.BINNING", PS_DATA_UNKNOWN, "Background binning", binning);
     97    if (!status) {
     98        psError (PSPHOT_ERR_PROG, false, "failed to save bininnng");
     99        return false;
     100    }
     101
     102    // we save the binning structure for use in psphotMagnitudes
    115103
    116104    // we have 4 possibilities: (INTERNAL or I/O file) and (exists or not)
     
    119107    if (file == NULL) {
    120108        // we are not using PSPHOT.BACKMDL as an I/O file: define an internal version
    121         model = pmFPAfileDefineInternal (config->files, "PSPHOT.BACKMDL", nx, ny, PS_TYPE_F32);
     109        model = pmFPAfileDefineInternal (config->files, "PSPHOT.BACKMDL", binning->nXruff, binning->nYruff, PS_TYPE_F32);
    122110    } else {
    123111        if (file->mode == PM_FPA_MODE_INTERNAL) {
     
    130118                // readout does not yet exist: create from input
    131119                // XXX we have an inconsistency in this calculation here and in pmFPACopy
    132                 pmFPAfileCopyStructureView (file->fpa, inFPA, DX, DY, view);
     120                // XXX use the psImageBinning functions to set the output image size
     121                pmFPAfileCopyStructureView (file->fpa, inFPA, binning->nXbin, binning->nYbin, view);
    133122                model = pmFPAviewThisReadout (view, file->fpa);
    134                 if ((nx != model->image->numCols) || (ny != model->image->numRows)) {
    135                     psError (PSPHOT_ERR_PROG, true, "inconsistent sizes for model dimensions");
    136                     return false;
    137                 }
     123                assert (binning->nXruff == model->image->numCols);
     124                assert (binning->nYruff == model->image->numRows);
    138125            }
    139126        }
     
    141128    psF32 **modelData = model->image->data.F32;
    142129
    143     assert(model->analysis != NULL);
    144     psMetadataAdd(model->analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.XBIN", PS_DATA_S32 | PS_META_REPLACE,
    145                   "Background x-binsize", DX);
    146     psMetadataAdd(model->analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.YBIN", PS_DATA_S32 | PS_META_REPLACE,
    147                   "Background x-binsize", DY);
    148     psMetadataAdd(model->analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.XOFF", PS_DATA_S32 | PS_META_REPLACE,
    149                   "Background x-overhang", xOffset);
    150     psMetadataAdd(model->analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.YOFF", PS_DATA_S32 | PS_META_REPLACE,
    151                   "Background y-overhang", yOffset);
    152 
    153 
    154130    // measure clipped median for subimages
    155     for (int iy = 0; iy < ny; iy++) {
    156         for (int ix = 0; ix < nx; ix++) {
    157             // sx, sy are in parent coords
    158             int sx = ix*DX - xOffset;
    159             int sy = iy*DY - yOffset;
    160 
    161             // XXX test override
    162             // sx = 1955;
    163             // sy = 4;
    164 
    165             region = psRegionSet (sx, sx + 2*DX, sy, sy + 2*DY);
    166             region = psRegionForImage (image, region);
    167             psImage *subset  = psImageSubset (image, region);
     131    psRegion ruffRegion = {0,0,0,0};
     132    psRegion fineRegion = {0,0,0,0};
     133    for (int iy = 0; iy < model->image->numRows; iy++) {
     134        for (int ix = 0; ix < model->image->numCols; ix++) {
     135           
     136            // convert the ruff grid cell to the equivalent fine grid cell
     137            // XXX we need to watch out for row0,col0
     138            ruffRegion = psRegionSet (ix, ix + 2, iy, iy + 2);
     139            fineRegion = psImageBinningSetFineRegion (binning, ruffRegion);
     140            fineRegion = psRegionForImage (image, fineRegion);
     141
     142            psImage *subset  = psImageSubset (image, fineRegion);
    168143            if (!subset->numCols || !subset->numRows) {
    169144                psFree (subset);
    170145                continue;
    171146            }
    172             psImage *submask = psImageSubset (mask, region);
     147            psImage *submask = psImageSubset (mask, fineRegion);
    173148
    174149            // reset the default values
     
    210185
    211186    // patch over bad regions (use average of 8 possible neighbor pixels)
    212     // XXX consider testing pixels against the 8 neighbors and replacing outliers...
     187    // XXX consider testing all pixels against the 8 neighbors and replacing outliers...
    213188    float Count = 0;
    214189    float Value = 0;
    215     for (int iy = 0; iy < ny; iy++) {
    216         for (int ix = 0; ix < nx; ix++) {
     190    for (int iy = 0; iy < model->image->numRows; iy++) {
     191        for (int ix = 0; ix < model->image->numCols; ix++) {
    217192            if (!isnan(modelData[iy][ix])) {
    218193                Value += modelData[iy][ix];
     
    224199            for (int jy = iy - 1; jy <= iy + 1; jy++) {
    225200                if (jy <   0) continue;
    226                 if (jy >= ny) continue;
     201                if (jy >= model->image->numRows) continue;
    227202                for (int jx = ix - 1; jx <= ix + 1; jx++) {
    228203                    if (!jx && !jy) continue;
    229204                    if (jx   <   0) continue;
    230                     if (jx   >= nx) continue;
     205                    if (jx   >= model->image->numCols) continue;
    231206                    value += modelData[jy][jx];
    232207                    count += 1.0;
     
    240215
    241216    // patch over remaining bad regions (use global average)
    242     for (int iy = 0; iy < ny; iy++) {
    243         for (int ix = 0; ix < nx; ix++) {
     217    for (int iy = 0; iy < model->image->numRows; iy++) {
     218        for (int ix = 0; ix < model->image->numCols; ix++) {
    244219            if (!isnan(modelData[iy][ix])) continue;
    245220            modelData[iy][ix] = Value;
     
    253228    psImageStats (statsBck, model->image, NULL, 0);
    254229    psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_MEAN", PS_DATA_F32 | PS_META_REPLACE, "sky model mean",          statsBck->sampleMean);
    255     psMetadataAdd (recipe, PS_LIST_TAIL, "SKYSTDEV", PS_DATA_F32 | PS_META_REPLACE, "sky model stdev",        statsBck->sampleStdev);
     230    psMetadataAdd (recipe, PS_LIST_TAIL, "SKYSTDEV", PS_DATA_F32 | PS_META_REPLACE, "sky model stdev",         statsBck->sampleStdev);
    256231    psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_MAX",  PS_DATA_F32 | PS_META_REPLACE, "sky model maximum value", statsBck->max);
    257232    psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_MIN",  PS_DATA_F32 | PS_META_REPLACE, "sky model minimum value", statsBck->min);
    258     psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_NX",   PS_DATA_S32 | PS_META_REPLACE, "sky model size (x)",      nx);
    259     psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_NY",   PS_DATA_S32 | PS_META_REPLACE, "sky model size (y)",      ny);
     233    psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_NX",   PS_DATA_S32 | PS_META_REPLACE, "sky model size (x)",      model->image->numCols);
     234    psMetadataAdd (recipe, PS_LIST_TAIL, "SKY_NY",   PS_DATA_S32 | PS_META_REPLACE, "sky model size (y)",      model->image->numRows);
    260235    psLogMsg ("psphot", PS_LOG_INFO, "background sky : min %f mean %f max %f stdev %f",
    261236              statsBck->min, statsBck->sampleMean, statsBck->max, statsBck->sampleStdev);
     
    275250            pmFPAfileCopyStructureView (file->fpa, inFPA, 1, 1, view);
    276251            background = pmFPAviewThisReadout (view, file->fpa);
    277             if ((Nx != background->image->numCols) || (Ny != background->image->numRows)) {
     252            if ((image->numCols != background->image->numCols) || (image->numRows != background->image->numRows)) {
    278253                psError (PSPHOT_ERR_PROG, true, "inconsistent sizes for background dimensions");
    279254                return false;
     
    281256        }
    282257    } else {
    283         background = pmFPAfileDefineInternal (config->files, "PSPHOT.BACKGND", Nx, Ny, PS_TYPE_F32);
     258        background = pmFPAfileDefineInternal (config->files, "PSPHOT.BACKGND", image->numCols, image->numRows, PS_TYPE_F32);
    284259    }
    285260    psF32 **backData = background->image->data.F32;
    286261
    287262    // linear interpolation to full-scale
    288     if (!psImageUnbin (background->image, model->image, DX, DY, xOffset, yOffset)) {
    289         psError (PSPHOT_ERR_PROG, true, "failed to build background iamge");
     263    if (!psImageUnbin (background->image, model->image, binning)) {
     264        psError (PSPHOT_ERR_PROG, true, "failed to build background image");
    290265        return false;
    291266    }
     
    330305    psFree(stats);
    331306    psFree(statsDefaults);
     307    psFree(binning);
    332308    psFree(rng);
    333309
     
    335311    return true;
    336312}
     313
     314
     315# if (0)
     316
     317    // dimensions of input & output image
     318    int Nx = image->numCols;
     319    int Ny = image->numRows;
     320
     321    // scaling factor
     322    int DX = psMetadataLookupS32 (&status, recipe, "BACKGROUND.XBIN");
     323    int DY = psMetadataLookupS32 (&status, recipe, "BACKGROUND.YBIN");
     324
     325    // overhang : we will balance this evenly
     326    int xExtra = (Nx % DX) / 2;
     327    int yExtra = (Ny % DY) / 2;
     328    int xOffset = (xExtra > 0) ? DX - xExtra : 0;
     329    int yOffset = (yExtra > 0) ? DY - yExtra : 0;
     330    xOffset -= image->col0;
     331    yOffset -= image->row0;
     332
     333    // dimensions of binned image
     334    int nx, ny;
     335    if (Nx % DX == 0) {
     336        nx = Nx / DX;
     337    } else {
     338        nx = (xExtra) ? (Nx / DX) + 2 : (Nx / DX) + 1;
     339    }
     340    if (Ny % DY == 0) {
     341        ny = Ny / DY;
     342    } else {
     343        ny = (yExtra) ? (Ny / DY) + 2 : (Ny / DY) + 1;
     344    }
     345
     346    // we have 4 possibilities: (INTERNAL or I/O file) and (exists or not)
     347    // select model pixels (from output background model file, or create internal file)
     348    file = psMetadataLookupPtr (&status, config->files, "PSPHOT.BACKMDL");
     349    if (file == NULL) {
     350        // we are not using PSPHOT.BACKMDL as an I/O file: define an internal version
     351        model = pmFPAfileDefineInternal (config->files, "PSPHOT.BACKMDL", nx, ny, PS_TYPE_F32);
     352    } else {
     353        if (file->mode == PM_FPA_MODE_INTERNAL) {
     354            // we are not using PSPHOT.BACKMDL as an I/O file: already defined above
     355            model = file->readout;
     356        } else {
     357            // we are using PSPHOT.BACKMDL as an I/O file: select readout or create
     358            model = pmFPAviewThisReadout (view, file->fpa);
     359            if (model == NULL) {
     360                // readout does not yet exist: create from input
     361                // XXX we have an inconsistency in this calculation here and in pmFPACopy
     362                pmFPAfileCopyStructureView (file->fpa, inFPA, DX, DY, view);
     363                model = pmFPAviewThisReadout (view, file->fpa);
     364                if ((nx != model->image->numCols) || (ny != model->image->numRows)) {
     365                    psError (PSPHOT_ERR_PROG, true, "inconsistent sizes for model dimensions");
     366                    return false;
     367                }
     368            }
     369        }
     370    }
     371    psF32 **modelData = model->image->data.F32;
     372
     373
     374
     375            // sx, sy are in parent coords
     376            int sx = ix*DX - xOffset;
     377            int sy = iy*DY - yOffset;
     378            region = psRegionSet (sx, sx + 2*DX, sy, sy + 2*DY);
     379
     380# endif
  • trunk/psphot/src/psphotMagnitudes.c

    r11312 r12592  
    1818    // Get enough information to return sky level
    1919    assert(background != NULL);
    20     assert(background->analysis != NULL);
    21     int DX = psMetadataLookupS32(&status, background->analysis, "PSPHOT.BACKGROUND.XBIN");
    22     assert (status == true);
    23     int DY = psMetadataLookupS32(&status, background->analysis, "PSPHOT.BACKGROUND.YBIN");
    24     assert (status == true);
    25     int dx = psMetadataLookupS32(&status, background->analysis, "PSPHOT.BACKGROUND.XOFF");
    26     assert (status == true);
    27     int dy = psMetadataLookupS32(&status, background->analysis, "PSPHOT.BACKGROUND.YOFF");
     20
     21    // the binning details are saved on the analysis metadata
     22    psImageBinning *binning = psMetadataLookupPtr(&status, recipe, "PSPHOT.BACKGROUND.BINNING");
    2823    assert (status == true);
    2924
     
    4035        if (status) Nap ++;
    4136
    42         source->sky = psImageUnbinPixel(source->peak->x, source->peak->y, background->image, DX, DY, dx, dy);
     37        source->sky = psImageUnbinPixel(source->peak->x, source->peak->y, background->image, binning);
    4338        if (isnan(source->sky) && false) {
    4439          psError(PSPHOT_ERR_SKY, false, "Setting pmSource.sky");
Note: See TracChangeset for help on using the changeset viewer.