IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 12, 2011, 9:32:08 PM (16 years ago)
Author:
eugene
Message:

add errors to kernel coeffs; calculate and plot chisq and moments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20101205/psModules/src/imcombine/pmSubtractionVisual.c

    r29600 r30266  
    210210        psImageOverlaySection(canvas, im, x0, y0, "=");
    211211        stampNum++;
     212
     213        // renormalize the section
     214        float maxValue = 0;
     215        for (int iy = 0; iy < im->numRows; iy++) {
     216            for (int ix = 0; ix < im->numCols; ix++) {
     217                maxValue = PS_MAX(maxValue, im->data.F64[iy][ix]);
     218            }
     219        }
     220        if (maxValue == 0.0) continue;
     221        for (int iy = 0; iy < im->numRows; iy++) {
     222            for (int ix = 0; ix < im->numCols; ix++) {
     223                canvas->data.F64[y0 + iy][x0 + ix] /= maxValue;
     224            }
     225        }
    212226    }
    213227
    214228    psImage *canvas32 = pmVisualImageToFloat(canvas);
    215229    pmVisualScaleImage(kapa1, canvas32, "Least_Squares", 0, true);
     230
     231    if (0) {
     232        static int count = 0;
     233        char filename[64];
     234        sprintf (filename, "chisq.%02d.fits", count);
     235        count ++;
     236        psFits *fits = psFitsOpen (filename, "w");
     237        psFitsWriteImage (fits, NULL, canvas32, 0, NULL);
     238        psFitsClose (fits);
     239    }
     240
     241    pmVisualAskUser(&plotLeastSquares);
     242    psFree(canvas);
     243    psFree(canvas32);
     244    return true;
     245}
     246
     247/** Plot the least-squares matrix of each stamp */
     248bool pmSubtractionVisualPlotLeastSquaresResid (const pmSubtractionStampList *stamps, psImage *matrixIn, int nUsed) {
     249
     250    if (!pmVisualTestLevel("ppsub.chisq", 1)) return true;
     251
     252    if (!plotLeastSquares) return true;
     253
     254    if (!pmVisualInitWindow (&kapa1, "PPSub:Images")) {
     255        return false;
     256    }
     257
     258    psImage *matrixNorm = psImageCopy(NULL, matrixIn, PS_TYPE_F64);
     259    {
     260        // renormalize the matrix
     261        float maxValue = 0;
     262        for (int iy = 0; iy < matrixNorm->numRows; iy++) {
     263            for (int ix = 0; ix < matrixNorm->numCols; ix++) {
     264                maxValue = PS_MAX(maxValue, matrixNorm->data.F64[iy][ix]);
     265            }
     266        }
     267        for (int iy = 0; iy < matrixNorm->numRows; iy++) {
     268            for (int ix = 0; ix < matrixNorm->numCols; ix++) {
     269                matrixNorm->data.F64[iy][ix] /= maxValue;
     270            }
     271        }
     272    }
     273
     274    // Find the stamp size
     275    int imageMax = -1;
     276    int numStamps = 0;
     277    psElemType type = PS_TYPE_F64;
     278
     279    for(int i = 0; i < stamps->num; i++) {
     280        pmSubtractionStamp *stamp = stamps->stamps->data[i];
     281        if (stamp == NULL) continue;
     282
     283        psImage *im = stamp->matrix;
     284        if (im == NULL) continue;
     285
     286        imageMax = PS_MAX(imageMax, im->numCols);
     287        imageMax = PS_MAX(imageMax, im->numRows);
     288        numStamps++;
     289        type = im->type.type;
     290    }
     291    if (imageMax == -1) return false;
     292
     293    int border = 15;
     294    imageMax += border;
     295    int tileRowCount = (int) ceil(sqrt(numStamps));
     296    int canvasX = tileRowCount * (imageMax);
     297    int canvasY = tileRowCount * (imageMax);
     298    psImage *canvas = psImageAlloc (canvasX, canvasY, type);
     299    psImageInit (canvas, NAN);
     300
     301    // overlay the images
     302    int stampNum = 0;
     303    int stampListNum = 0;
     304    while (stampNum < numStamps) {
     305        int x0 = (imageMax) * (stampNum % tileRowCount);
     306        int y0 = (imageMax) * (stampNum / tileRowCount);
     307
     308        pmSubtractionStamp *stamp = stamps->stamps->data[stampListNum++];
     309        if (stamp == NULL) continue;
     310
     311        psImage *im = stamp->matrix;
     312        if (im == NULL) continue;
     313
     314        stampNum++;
     315
     316        if (stamp->status != PM_SUBTRACTION_STAMP_USED) continue;
     317
     318        // renormalize the section
     319        float maxValue = 0;
     320        for (int iy = 0; iy < im->numRows; iy++) {
     321            for (int ix = 0; ix < im->numCols; ix++) {
     322                maxValue = PS_MAX(maxValue, im->data.F64[iy][ix]);
     323            }
     324        }
     325        if (maxValue == 0.0) continue;
     326        for (int iy = 0; iy < im->numRows; iy++) {
     327            for (int ix = 0; ix < im->numCols; ix++) {
     328                canvas->data.F64[y0 + iy][x0 + ix] = (im->data.F64[iy][ix] / maxValue - matrixNorm->data.F64[iy][ix]) / matrixNorm->data.F64[iy][ix];
     329            }
     330        }
     331    }
     332
     333    psImage *canvas32 = pmVisualImageToFloat(canvas);
     334    pmVisualRangeImage(kapa2, canvas32, "Least_Squares", 0, -100.0, 100.0);
    216335
    217336    if (0) {
     
    722841}
    723842
     843// plot log(flux) vs log(chisq), log(flux) vs log(moments), log(chisq) vs log(moments)
     844bool pmSubtractionVisualPlotChisqAndMoments(psVector *fluxes, psVector *chisq, psVector *moments) {
     845
     846    Graphdata graphdata;
     847    KapaSection section;
     848
     849    if (!pmVisualTestLevel("ppsub.fit", 1)) return true;
     850
     851    if (!pmVisualInitWindow(&kapa3, "ppSub:plots")) return false;
     852
     853    KapaClearSections (kapa3);
     854    KapaInitGraph (&graphdata);
     855    KiiResize(kapa3, 1500, 500);
     856
     857    psVector *lchi = psVectorAlloc (fluxes->n, PS_TYPE_F32);
     858    psVector *lflx = psVectorAlloc (fluxes->n, PS_TYPE_F32);
     859    psVector *lMxx = psVectorAlloc (fluxes->n, PS_TYPE_F32);
     860
     861    // construct the plot vectors
     862    for (int i = 0; i < fluxes->n; i++) {
     863        lchi->data.F32[i] = log10(chisq->data.F32[i]);
     864        lflx->data.F32[i] = log10(fluxes->data.F32[i]);
     865        lMxx->data.F32[i] = log10(moments->data.F32[i]);
     866    }
     867
     868    section.bg = KapaColorByName ("none"); // XXX probably should be 'none'
     869
     870    // section 1: lflux vs lchi
     871    section.dx = 0.33;
     872    section.dy = 1.00;
     873    section.x  = 0.00;
     874    section.y  = 0.00;
     875    section.name = psStringCopy ("flux.v.chi");
     876    KapaSetSection (kapa3, &section);
     877    psFree (section.name);
     878
     879    graphdata.color = KapaColorByName ("black");
     880    pmVisualScaleGraphdata(&graphdata, lflx, lchi, false);
     881    KapaSetLimits (kapa3, &graphdata);
     882
     883    KapaSetFont (kapa3, "helvetica", 14);
     884    KapaBox (kapa3, &graphdata);
     885    KapaSendLabel (kapa3, "log(flux)", KAPA_LABEL_XM);
     886    KapaSendLabel (kapa3, "log(chisq)", KAPA_LABEL_YM);
     887
     888    graphdata.color = KapaColorByName ("black");
     889    graphdata.ptype = 2;
     890    graphdata.size = 0.5;
     891    graphdata.style = 2;
     892
     893    KapaPrepPlot   (kapa3, lflx->n, &graphdata);
     894    KapaPlotVector (kapa3, lflx->n, lflx->data.F32, "x");
     895    KapaPlotVector (kapa3, lflx->n, lchi->data.F32, "y");
     896
     897    // section 2: lflux vs lMxx
     898    section.dx = 0.33;
     899    section.dy = 1.00;
     900    section.x  = 0.33;
     901    section.y  = 0.00;
     902    section.name = psStringCopy ("flux.v.mom");
     903    KapaSetSection (kapa3, &section);
     904    psFree (section.name);
     905
     906    graphdata.color = KapaColorByName ("black");
     907    pmVisualScaleGraphdata(&graphdata, lflx, lMxx, false);
     908    KapaSetLimits (kapa3, &graphdata);
     909
     910    KapaSetFont (kapa3, "helvetica", 14);
     911    KapaBox (kapa3, &graphdata);
     912    KapaSendLabel (kapa3, "log(flux)", KAPA_LABEL_XM);
     913    KapaSendLabel (kapa3, "log(moments)", KAPA_LABEL_YM);
     914
     915    graphdata.color = KapaColorByName ("black");
     916    graphdata.ptype = 2;
     917    graphdata.size = 0.5;
     918    graphdata.style = 2;
     919
     920    KapaPrepPlot   (kapa3, lflx->n, &graphdata);
     921    KapaPlotVector (kapa3, lflx->n, lflx->data.F32, "x");
     922    KapaPlotVector (kapa3, lflx->n, lMxx->data.F32, "y");
     923
     924    // section 1: lflux vs lchi
     925    section.dx = 0.33;
     926    section.dy = 1.00;
     927    section.x  = 0.66;
     928    section.y  = 0.00;
     929    section.name = psStringCopy ("chi.v.mom");
     930    KapaSetSection (kapa3, &section);
     931    psFree (section.name);
     932
     933    graphdata.color = KapaColorByName ("black");
     934    pmVisualScaleGraphdata(&graphdata, lchi, lMxx, false);
     935    KapaSetLimits (kapa3, &graphdata);
     936
     937    KapaSetFont (kapa3, "helvetica", 14);
     938    KapaBox (kapa3, &graphdata);
     939    KapaSendLabel (kapa3, "log(chisq)", KAPA_LABEL_XM);
     940    KapaSendLabel (kapa3, "log(moments)", KAPA_LABEL_YM);
     941
     942    graphdata.color = KapaColorByName ("black");
     943    graphdata.ptype = 2;
     944    graphdata.size = 0.5;
     945    graphdata.style = 2;
     946
     947    KapaPrepPlot   (kapa3, lflx->n, &graphdata);
     948    KapaPlotVector (kapa3, lflx->n, lchi->data.F32, "x");
     949    KapaPlotVector (kapa3, lflx->n, lMxx->data.F32, "y");
     950
     951    pmVisualAskUser(NULL);
     952    return true;
     953}
     954
    724955#else
    725956bool pmSubtractionVisualClose(void) {return true;}
Note: See TracChangeset for help on using the changeset viewer.