IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 7, 2009, 4:08:25 PM (17 years ago)
Author:
Paul Price
Message:

Merging trunk (r25026) to get up-to-date on old branch.

Location:
branches/pap
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/pap

  • branches/pap/psModules

    • Property svn:mergeinfo deleted
  • branches/pap/psModules/src/imcombine/pmReadoutCombine.c

    r21363 r25027  
    173173    for (int i = 0; i < inputs->n; i++) {
    174174        pmReadout *readout = inputs->data[i]; // Readout of interest
     175        psAssert(readout, "readout was not defined");
     176        if (!readout->process) continue;
    175177        if (!readout->image) {
    176178            psError(PS_ERR_UNEXPECTED_NULL, true, "Image data is missing for image %d.\n", i);
     
    271273        for (int r = 0; r < inputs->n; r++) {
    272274            pmReadout *readout = inputs->data[r]; // Input readout
     275            if (!readout->process) continue;
    273276            psTrace("psModules.imcombine", 3, "Iterating input %d: %d --> %d, %d --> %d\n", r,
    274277                    minInputCols - readout->col0, maxInputCols - readout->col0,
     
    277280    }
    278281    #endif
     282
     283    // set up windows for visualization (if selected)
     284    pmReadoutCombineVisualInit();
    279285
    280286    // Dereference output products
     
    308314            for (int r = 0; r < inputs->n; r++) {
    309315                pmReadout *readout = inputs->data[r]; // Input readout
     316                if (!readout->process) {
     317                    maskData[r] = 1;
     318                    continue;
     319                }
    310320                int yIn = i - readout->row0; // y position on input readout
    311321                int xIn = j - readout->col0; // x position on input readout
     
    384394            // Combination
    385395            if (!psVectorStats(stats, pixels, errors, mask, 1)) {
    386                 // Can't do much about it, but it's not worth worrying about
    387                 psErrorClear();
     396                psError(PS_ERR_UNKNOWN, false, "error in pixel stats");
     397                return false;
     398            }
     399           
     400            outputImage[yOut][xOut] = psStatsGetValue(stats, params->combine);
     401
     402            if (!isfinite(outputImage[yOut][xOut])) {
     403                pmReadoutCombineVisualPixels(pixels, mask, outputImage[yOut][xOut]);
     404            }
     405
     406            if (isnan(outputImage[yOut][xOut])) {
    388407                outputImage[yOut][xOut] = NAN;
    389408                outputMask[yOut][xOut] = params->blank;
     409                sigma->data.F32[yOut][xOut] = NAN;
    390410                if (params->variances) {
    391411                    outputVariance[yOut][xOut] = NAN;
    392412                }
    393                 sigma->data.F32[yOut][xOut] = NAN;
    394             } else {
    395                 outputImage[yOut][xOut] = psStatsGetValue(stats, params->combine);
    396                 outputMask[yOut][xOut] = isfinite(outputImage[yOut][xOut]) ? 0 : params->blank;
    397                 if (params->variances) {
    398                     float stdev = psStatsGetValue(stats, combineStdev);
    399                     outputVariance[yOut][xOut] = PS_SQR(stdev); // Variance
    400                     // XXXX this is not the correct formal error.
    401                     // also, the weighted mean is not obviously the correct thing here
    402                 }
    403                 sigma->data.F32[yOut][xOut] = psStatsGetValue(stats, combineStdev);
    404             }
     413                continue;
     414            }
     415            outputMask[yOut][xOut] = 0;
     416            sigma->data.F32[yOut][xOut] = psStatsGetValue(stats, combineStdev);
     417            if (params->variances) {
     418                float stdev = psStatsGetValue(stats, combineStdev);
     419                outputVariance[yOut][xOut] = PS_SQR(stdev); // Variance
     420                // XXXX this is not the correct formal error.
     421                // also, the weighted mean is not obviously the correct thing here
     422            }
    405423        }
    406424    }
     
    423441}
    424442
     443#if (HAVE_KAPA)
     444#include <kapa.h>
     445#include "pmKapaPlots.h"
     446#include "pmVisual.h"
     447
     448static int kapa = -1;
     449static bool plotFlag = true;
     450
     451// this init function only gets the ordinates for the first readout...
     452bool pmReadoutCombineVisualInit(void) {
     453   
     454    if (!pmVisualIsVisual()) return true;
     455
     456    // skip if we have already opened the windows (or if none are requested...)
     457    if (kapa != -1) return true;
     458
     459    pmVisualInitWindow(&kapa, "ppmerge");
     460    return true;
     461}
     462
     463bool pmReadoutCombineVisualPixels(psVector *pixels, psVector *mask, float mean) {
     464
     465    Graphdata graphdata;
     466    float xline[2], yline[2];
     467   
     468    if (!pmVisualIsVisual()) return true;
     469
     470    if (!plotFlag) return true;
     471
     472    KapaInitGraph(&graphdata);
     473
     474    psVector *xAll = psVectorAlloc(pixels->n, PS_TYPE_F32);
     475    psVector *xSub = psVectorAlloc(pixels->n, PS_TYPE_F32);
     476    psVector *ySub = psVectorAlloc(pixels->n, PS_TYPE_F32);
     477
     478    // generate vectors of the unmasked values
     479    int nSub = 0;
     480    for (int j = 0; j < pixels->n; j++) {
     481        xAll->data.F32[j] = j;
     482        if (mask && mask->data.PS_TYPE_VECTOR_MASK_DATA[j]) continue;
     483        xSub->data.F32[nSub] = j;
     484        ySub->data.F32[nSub] = pixels->data.F32[j];
     485        nSub ++;
     486    }
     487    xSub->n = ySub->n = nSub;
     488    xAll->n = pixels->n;
     489       
     490    xline[0] = 0;
     491    xline[1] = pixels->n;
     492    yline[0] = mean;
     493    yline[1] = mean;
     494
     495    // plot the unmasked values
     496    pmVisualScaleGraphdata (&graphdata, xAll, pixels, false);
     497    KapaSetGraphData(kapa, &graphdata);
     498    KapaSetLimits(kapa, &graphdata);
     499    KapaClearPlots (kapa);
     500
     501    KapaSetFont (kapa, "courier", 14);
     502    KapaBox (kapa, &graphdata);
     503    KapaSendLabel (kapa, "ordinate", KAPA_LABEL_XM);
     504    KapaSendLabel (kapa, "pixel values", KAPA_LABEL_YM);
     505
     506    graphdata.color = KapaColorByName("black");
     507    graphdata.style = 2;
     508    graphdata.ptype = 2;
     509    KapaPrepPlot  (kapa, xSub->n, &graphdata);
     510    KapaPlotVector(kapa, xSub->n, xSub->data.F32, "x");
     511    KapaPlotVector(kapa, xSub->n, ySub->data.F32, "y");
     512
     513    graphdata.color = KapaColorByName("red");
     514    graphdata.style = 2;
     515    graphdata.ptype = 7;
     516    KapaPrepPlot  (kapa, xAll->n, &graphdata);
     517    KapaPlotVector(kapa, xAll->n, xAll->data.F32, "x");
     518    KapaPlotVector(kapa, xAll->n, pixels->data.F32, "y");
     519
     520    graphdata.color = KapaColorByName("blue");
     521    graphdata.style = 0;
     522    graphdata.ptype = 7;
     523    KapaPrepPlot  (kapa, 2, &graphdata);
     524    KapaPlotVector(kapa, 2, xline, "x");
     525    KapaPlotVector(kapa, 2, yline, "y");
     526
     527    pmVisualAskUser (&plotFlag);
     528    return true;
     529}
     530
     531bool pmReadoutCombineVisualCleanup(void) {
     532
     533    if (!pmVisualIsVisual()) return true;
     534    if (kapa == -1) return true;
     535
     536    KapaClose(kapa);
     537    return true;
     538}
     539
     540# else
     541
     542bool pmReadoutCombineVisualInit(void) { return true; }
     543bool pmReadoutCombineVisualPixels(psVector *pixels, psVector *mask, float mean) { return true; }
     544bool pmReadoutCombineVisualCleanup(void) { return true; }
     545
     546# endif
Note: See TracChangeset for help on using the changeset viewer.