IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26573


Ignore:
Timestamp:
Jan 12, 2010, 3:53:09 PM (16 years ago)
Author:
eugene
Message:

sign has changed on convolution coefficients; require -visual as normal

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20091201/psModules/src/imcombine/pmSubtractionVisual.c

    r26562 r26573  
    238238
    239239    for (int i = 0; i < kernels->num; i++) {
    240         pmSubtractionKernelPreCalc *preCalc = kernels->preCalc->data[i];
    241         psKernel *kernel = preCalc->kernel;
    242 
    243         int xSub = i % NXsub;
    244         int ySub = i / NXsub;
    245 
    246         int xPix = xSub * (2*footprint + 1 + 3) + footprint;
    247         int yPix = ySub * (2*footprint + 1 + 3) + footprint;
    248 
    249         double sum = 0.0;
    250         for (int y = -footprint; y <= footprint; y++) {
    251             for (int x = -footprint; x <= footprint; x++) {
    252                 output->data.F32[y + yPix][x + xPix] = kernel->kernel[y][x];
    253                 sum += kernel->kernel[y][x];
    254             }
    255         }
    256         fprintf (stderr, "kernel %d, sum %f\n", i, sum);
    257     }
    258 
     240        pmSubtractionKernelPreCalc *preCalc = kernels->preCalc->data[i];
     241        psKernel *kernel = preCalc->kernel;
     242
     243        int xSub = i % NXsub;
     244        int ySub = i / NXsub;
     245
     246        int xPix = xSub * (2*footprint + 1 + 3) + footprint;
     247        int yPix = ySub * (2*footprint + 1 + 3) + footprint;
     248
     249        double sum = 0.0;
     250        for (int y = -footprint; y <= footprint; y++) {
     251            for (int x = -footprint; x <= footprint; x++) {
     252                output->data.F32[y + yPix][x + xPix] = kernel->kernel[y][x];
     253                sum += kernel->kernel[y][x];
     254            }
     255        }
     256        fprintf (stderr, "kernel %d, sum %f\n", i, sum);
     257    }                                                   
     258       
    259259    pmVisualScaleImage(kapa1, output, "Image", 0, true);
    260260    pmVisualAskUser(&plotImage);
     
    276276    float maxFlux = NAN;
    277277    for (int i = 0; i < stamps->num; i++) {
    278         pmSubtractionStamp *stamp = stamps->stamps->data[i];
    279         if (!isfinite(stamp->flux)) continue;
    280         if (!stamp->convolutions1 && !stamp->convolutions2) continue;
    281         if (!maxStamp) {
    282             maxFlux = stamp->flux;
    283             maxStamp = stamp;
    284             continue;
    285         }
    286         if (stamp->flux > maxFlux) {
    287             maxFlux = stamp->flux;
    288             maxStamp = stamp;
    289         }
     278        pmSubtractionStamp *stamp = stamps->stamps->data[i];
     279        if (!isfinite(stamp->flux)) continue;
     280        if (!stamp->convolutions1 && !stamp->convolutions2) continue;
     281        if (!maxStamp) {
     282            maxFlux = stamp->flux;
     283            maxStamp = stamp;
     284            continue;
     285        }
     286        if (stamp->flux > maxFlux) {
     287            maxFlux = stamp->flux;
     288            maxStamp = stamp;
     289        }
    290290    }
    291291
    292292    if (!isfinite(maxStamp->flux)) {
    293         fprintf (stderr, "no valid stamps?\n");
     293        fprintf (stderr, "no valid stamps?\n");
    294294    }
    295295
     
    297297
    298298    if (maxStamp->convolutions1) {
    299         // output image is a grid of NXsub by NYsub sub-images
    300         nKernels = maxStamp->convolutions1->n;
    301         int NXsub = sqrt(nKernels);
    302         int NYsub = nKernels / NXsub;
    303         if (nKernels % NXsub) NYsub++;
    304 
    305         int NXpix = NXsub * (2*footprint + 1 + 3);
    306         int NYpix = NYsub * (2*footprint + 1 + 3);
    307 
    308         psImage *output = psImageAlloc(NXpix, NYpix, PS_TYPE_F32);
    309         psImageInit (output, 0.0);
    310 
    311         for (int i = 0; i < nKernels; i++) {
     299        // output image is a grid of NXsub by NYsub sub-images
     300        nKernels = maxStamp->convolutions1->n;
     301        int NXsub = sqrt(nKernels);
     302        int NYsub = nKernels / NXsub;
     303        if (nKernels % NXsub) NYsub++;
     304
     305        int NXpix = NXsub * (2*footprint + 1 + 3);
     306        int NYpix = NYsub * (2*footprint + 1 + 3);
     307
     308        psImage *output = psImageAlloc(NXpix, NYpix, PS_TYPE_F32);
     309        psImageInit (output, 0.0);
     310
     311        for (int i = 0; i < nKernels; i++) {
    312312            psKernel *kernel = maxStamp->convolutions1->data[i];
    313 
    314             int xSub = i % NXsub;
    315             int ySub = i / NXsub;
    316 
    317             int xPix = xSub * (2*footprint + 1 + 3) + footprint;
    318             int yPix = ySub * (2*footprint + 1 + 3) + footprint;
    319 
    320             double sum = 0.0;
    321             for (int y = -footprint; y <= footprint; y++) {
    322                 for (int x = -footprint; x <= footprint; x++) {
    323                     output->data.F32[y + yPix][x + xPix] = kernel->kernel[y][x];
    324                     sum += kernel->kernel[y][x];
    325                 }
    326             }
    327             fprintf (stderr, "kernel %d, sum %f\n", i, sum);
    328         }
    329         pmVisualScaleImage(kapa2, output, "Image", 0, true);
    330     }
    331 
     313           
     314            int xSub = i % NXsub;
     315            int ySub = i / NXsub;
     316           
     317            int xPix = xSub * (2*footprint + 1 + 3) + footprint;
     318            int yPix = ySub * (2*footprint + 1 + 3) + footprint;
     319           
     320            double sum = 0.0;
     321            for (int y = -footprint; y <= footprint; y++) {
     322                for (int x = -footprint; x <= footprint; x++) {
     323                    output->data.F32[y + yPix][x + xPix] = kernel->kernel[y][x];
     324                    sum += kernel->kernel[y][x];
     325                }
     326            }
     327            fprintf (stderr, "kernel %d, sum %f\n", i, sum);
     328        }               
     329        pmVisualScaleImage(kapa2, output, "Image", 0, true);
     330    }                                   
     331       
    332332    if (maxStamp->convolutions2) {
    333         // output image is a grid of NXsub by NYsub sub-images
    334         nKernels = maxStamp->convolutions2->n;
    335         int NXsub = sqrt(nKernels);
    336         int NYsub = nKernels / NXsub;
    337         if (nKernels % NXsub) NYsub++;
    338 
    339         int NXpix = NXsub * (2*footprint + 1 + 3);
    340         int NYpix = NYsub * (2*footprint + 1 + 3);
    341 
    342         psImage *output = psImageAlloc(NXpix, NYpix, PS_TYPE_F32);
    343         psImageInit (output, 0.0);
    344 
    345         for (int i = 0; i < nKernels; i++) {
     333        // output image is a grid of NXsub by NYsub sub-images
     334        nKernels = maxStamp->convolutions2->n;
     335        int NXsub = sqrt(nKernels);
     336        int NYsub = nKernels / NXsub;
     337        if (nKernels % NXsub) NYsub++;
     338
     339        int NXpix = NXsub * (2*footprint + 1 + 3);
     340        int NYpix = NYsub * (2*footprint + 1 + 3);
     341
     342        psImage *output = psImageAlloc(NXpix, NYpix, PS_TYPE_F32);
     343        psImageInit (output, 0.0);
     344
     345        for (int i = 0; i < nKernels; i++) {
    346346            psKernel *kernel = maxStamp->convolutions2->data[i];
    347 
    348             int xSub = i % NXsub;
    349             int ySub = i / NXsub;
    350 
    351             int xPix = xSub * (2*footprint + 1 + 3) + footprint;
    352             int yPix = ySub * (2*footprint + 1 + 3) + footprint;
    353 
    354             double sum = 0.0;
    355             for (int y = -footprint; y <= footprint; y++) {
    356                 for (int x = -footprint; x <= footprint; x++) {
    357                     output->data.F32[y + yPix][x + xPix] = kernel->kernel[y][x];
    358                     sum += kernel->kernel[y][x];
    359                 }
    360             }
    361             fprintf (stderr, "kernel %d, sum %f\n", i, sum);
    362         }
    363         pmVisualScaleImage(kapa2, output, "Image", 1, true);
    364     }
    365 
     347           
     348            int xSub = i % NXsub;
     349            int ySub = i / NXsub;
     350           
     351            int xPix = xSub * (2*footprint + 1 + 3) + footprint;
     352            int yPix = ySub * (2*footprint + 1 + 3) + footprint;
     353           
     354            double sum = 0.0;
     355            for (int y = -footprint; y <= footprint; y++) {
     356                for (int x = -footprint; x <= footprint; x++) {
     357                    output->data.F32[y + yPix][x + xPix] = kernel->kernel[y][x];
     358                    sum += kernel->kernel[y][x];
     359                }
     360            }
     361            fprintf (stderr, "kernel %d, sum %f\n", i, sum);
     362        }               
     363        pmVisualScaleImage(kapa2, output, "Image", 1, true);
     364    }                                   
     365       
    366366    pmVisualAskUser(&plotImage);
    367367    return true;
     
    390390
    391391        overlay[Noverlay].type = KII_OVERLAY_BOX;
    392         if ((stamp->x < 1.0) && (stamp->y < 1.0)) {
    393             // fprintf (stderr, "stamp zero: %f %f\n", stamp->x, stamp->y);
    394             continue;
    395         }
    396         if (!isfinite(stamp->x) && !isfinite(stamp->y)) {
    397             // fprintf (stderr, "stamp nan: %f %f\n", stamp->x, stamp->y);
    398             continue;
    399         }
     392        if ((stamp->x < 1.0) && (stamp->y < 1.0)) {
     393            // fprintf (stderr, "stamp zero: %f %f\n", stamp->x, stamp->y);
     394            continue;
     395        }
     396        if (!isfinite(stamp->x) && !isfinite(stamp->y)) {
     397            // fprintf (stderr, "stamp nan: %f %f\n", stamp->x, stamp->y);
     398            continue;
     399        }
    400400        overlay[Noverlay].x = stamp->x;
    401401        overlay[Noverlay].y = stamp->y;
     
    425425bool pmSubtractionVisualShowFitInit(pmSubtractionStampList *stamps) {
    426426
    427     // if (!pmVisualIsVisual()) return true;
     427    if (!pmVisualIsVisual()) return true;
    428428
    429429    // generate 4 storage images large enough to hold the N stamps:
     
    433433    float NXf = sqrt(stamps->num);
    434434    NX = (int) NXf == NXf ? NXf : NXf + 1.0;
    435 
     435   
    436436    float NYf = stamps->num / NX;
    437437    NY = (int) NYf == NY ? NYf : NYf + 1.0;
     
    449449    differenceImage  = psImageAlloc (NXpix, NYpix, PS_TYPE_F32);
    450450    convolutionImage = psImageAlloc (NXpix, NYpix, PS_TYPE_F32);
    451 
     451   
    452452    psImageInit (sourceImage,      0.0);
    453453    psImageInit (targetImage,      0.0);
     
    462462bool pmSubtractionVisualShowFitAddStamp(psKernel *target, psKernel *source, psKernel *convolution, double background, double norm, int index) {
    463463
    464     // if (!pmVisualIsVisual()) return true;
     464    if (!pmVisualIsVisual()) return true;
    465465
    466466    double sum;
     
    475475    sum = 0.0;
    476476    for (int y = -footprint; y <= footprint; y++) {
    477         for (int x = -footprint; x <= footprint; x++) {
    478             targetImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x];
    479             sum += targetImage->data.F32[y + NYpix][x + NXpix];
    480         }
     477        for (int x = -footprint; x <= footprint; x++) {
     478            targetImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x];
     479            sum += targetImage->data.F32[y + NYpix][x + NXpix];
     480        }
    481481    }
    482482    targetImage->data.F32[footprint + 1 + NYpix][NXpix] = sum;
     
    485485    sum = 0.0;
    486486    for (int y = -footprint; y <= footprint; y++) {
    487         for (int x = -footprint; x <= footprint; x++) {
    488             sourceImage->data.F32[y + NYpix][x + NXpix] = source->kernel[y][x];
    489             sum += sourceImage->data.F32[y + NYpix][x + NXpix];
    490         }
     487        for (int x = -footprint; x <= footprint; x++) {
     488            sourceImage->data.F32[y + NYpix][x + NXpix] = source->kernel[y][x];
     489            sum += sourceImage->data.F32[y + NYpix][x + NXpix];
     490        }
    491491    }
    492492    sourceImage->data.F32[footprint + 1 + NYpix][NXpix] = sum;
     
    495495    sum = 0.0;
    496496    for (int y = -footprint; y <= footprint; y++) {
    497         for (int x = -footprint; x <= footprint; x++) {
    498             convolutionImage->data.F32[y + NYpix][x + NXpix] = -convolution->kernel[y][x];
    499             sum += convolutionImage->data.F32[y + NYpix][x + NXpix];
    500         }
     497        for (int x = -footprint; x <= footprint; x++) {
     498            convolutionImage->data.F32[y + NYpix][x + NXpix] = -convolution->kernel[y][x];
     499            sum += convolutionImage->data.F32[y + NYpix][x + NXpix];
     500        }
    501501    }
    502502    convolutionImage->data.F32[footprint + 1 + NYpix][NXpix] = sum;
    503 
     503   
    504504    // insert the (difference) kernel into the (difference) image:
    505505    sum = 0.0;
    506506    for (int y = -footprint; y <= footprint; y++) {
    507         for (int x = -footprint; x <= footprint; x++) {
    508             differenceImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x] - background - source->kernel[y][x] * norm;
    509             sum += differenceImage->data.F32[y + NYpix][x + NXpix];
    510         }
     507        for (int x = -footprint; x <= footprint; x++) {
     508            differenceImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x] - background - source->kernel[y][x] * norm;
     509            sum += differenceImage->data.F32[y + NYpix][x + NXpix];
     510        }
    511511    }
    512512    differenceImage->data.F32[footprint + 1 + NYpix][NXpix] = sum;
     
    515515    sum = 0.0;
    516516    for (int y = -footprint; y <= footprint; y++) {
    517         for (int x = -footprint; x <= footprint; x++) {
    518             residualImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x] - background - source->kernel[y][x] * norm + convolution->kernel[y][x];
    519             sum += residualImage->data.F32[y + NYpix][x + NXpix];
    520         }
     517        for (int x = -footprint; x <= footprint; x++) {
     518            residualImage->data.F32[y + NYpix][x + NXpix] = target->kernel[y][x] - background - source->kernel[y][x] * norm - convolution->kernel[y][x];
     519            sum += residualImage->data.F32[y + NYpix][x + NXpix];
     520        }
    521521    }
    522522    residualImage->data.F32[footprint + 1 + NYpix][NXpix] = sum;
     
    524524    // insert the (fresidual) kernel into the (fresidual) image:
    525525    for (int y = -footprint; y <= footprint; y++) {
    526         for (int x = -footprint; x <= footprint; x++) {
    527             fresidualImage->data.F32[y + NYpix][x + NXpix] = residualImage->data.F32[y + NYpix][x + NXpix] / sqrt(PS_MAX(target->kernel[y][x], 100.0));
    528         }
     526        for (int x = -footprint; x <= footprint; x++) {
     527            fresidualImage->data.F32[y + NYpix][x + NXpix] = residualImage->data.F32[y + NYpix][x + NXpix] / sqrt(PS_MAX(target->kernel[y][x], 100.0));
     528        }
    529529    }
    530530    return true;
     
    533533bool pmSubtractionVisualShowFit(double norm) {
    534534
     535    // for testing, dump the residual image and exit
     536    if (0) {
     537        psMetadata *header = psMetadataAlloc();
     538        psMetadataAddF32 (header, PS_LIST_TAIL, "NORM", 0, "Normalization", norm);
     539        psFits *fits = psFitsOpen("resid.fits", "w");
     540        psFitsWriteImage(fits, header, residualImage, 0, NULL);
     541        psFitsClose(fits);
     542        // exit (0);
     543    }
     544
    535545    if (!pmVisualIsVisual()) return true;
    536 
    537     // XXX a dumb test : dump the residual image and exit
    538     {
    539         psMetadata *header = psMetadataAlloc();
    540         psMetadataAddF32 (header, PS_LIST_TAIL, "NORM", 0, "Normalization", norm);
    541         psFits *fits = psFitsOpen("resid.fits", "w");
    542         psFitsWriteImage(fits, header, residualImage, 0, NULL);
    543         psFitsClose(fits);
    544         exit (0);
    545     }
    546 
    547546    if (!pmVisualInitWindow(&kapa1, "ppSub:Images")) return false;
    548547    if (!pmVisualInitWindow(&kapa2, "ppSub:Misc")) return false;
     
    558557    pmVisualScaleImage(kapa2, fresidualImage, "Frac Residual Stamps", 2, true);
    559558    pmVisualScaleImage(kapa2, differenceImage, "Difference Stamps", 0, true);
    560     pmVisualScaleImage(kapa2, residualImage, "Residual Stamps", 1, true);
     559
     560    if (1) {
     561        KiiImage image;
     562        KapaImageData data;
     563        Coords coords;
     564        strcpy (coords.ctype, "RA---TAN");
     565
     566        image.data2d = residualImage->data.F32;
     567        image.Nx = residualImage->numCols;
     568        image.Ny = residualImage->numRows;
     569        strcpy (data.name, "Residual Stamps");
     570        strcpy (data.file, "Residual Stamps");
     571
     572        data.zero  = -300.0;
     573        data.range = +600.0;
     574        data.logflux = 0;
     575
     576        KiiSetChannel (kapa2, 1);
     577        KiiNewPicture2D (kapa2, &image, &data, &coords);
     578    } else {
     579        pmVisualScaleImage(kapa2, residualImage, "Residual Stamps", 1, true);
     580    }
     581
    561582    KiiCenter (kapa2, 0.5*residualImage->numCols, 0.5*residualImage->numRows, 1);
    562583
     
    603624    for (int i = 0; i < kernels->num; i++) {
    604625        x->data.F32[i] = i;
    605         y->data.F32[i] = p_pmSubtractionSolutionCoeff(kernels, polyValues, i, false);
     626        y->data.F32[i] = p_pmSubtractionSolutionCoeff(kernels, polyValues, i, false);
    606627        graphdata.ymin = PS_MIN(graphdata.ymin, y->data.F32[i]);
    607628        graphdata.ymax = PS_MAX(graphdata.ymax, y->data.F32[i]);
Note: See TracChangeset for help on using the changeset viewer.