IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 25, 2010, 2:45:41 PM (16 years ago)
Author:
eugene
Message:

merge changes from eam_branches/ipp-20100823

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/imcombine/pmSubtractionStamps.c

    r29019 r29543  
    5151    psFree(list->y);
    5252    psFree(list->flux);
     53    psFree(list->window);
    5354    psFree(list->window1);
    5455    psFree(list->window2);
     
    9697
    9798    // fprintf (stderr, "xMin, xMax: %d, %d -> ", xMin, xMax);
     99    // float xRaw = xMin;
     100    // float yRaw = yMin;
    98101
    99102    // Ensure we're not going to go outside the bounds of the image
     
    103106    yMax = PS_MIN(numRows - border - 1, yMax);
    104107
    105     if (xMax < xMin) return false;
    106     if (yMax < yMin) return false;
     108    if (xMax < xMin) {
     109        // fprintf (stderr, "%f,%f : x-border\n", xRaw, yRaw);
     110        return false;
     111    }
     112    if (yMax < yMin) {
     113        // fprintf (stderr, "%f,%f : y-border\n", xRaw, yRaw);
     114        return false;
     115    }
    107116
    108117    psAssert (xMin <= xMax, "x mismatch?");
     
    118127            if (subMask && subMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] &
    119128                (PM_SUBTRACTION_MASK_BORDER | PM_SUBTRACTION_MASK_REJ)) {
     129                // fprintf (stderr, "%f,%f : masked\n", xRaw, yRaw);
    120130                return false;
    121131            }
     
    133143    }
    134144
     145    // if (!found) {
     146    //  fprintf (stderr, "%f,%f : fails flux test\n", xRaw, yRaw);
     147    // }
     148
    135149    return found;
    136150}
     
    232246    list->flux = NULL;
    233247    list->normFrac = normFrac;
     248    list->normValue = NAN;
     249    list->window = NULL;
    234250    list->window1 = NULL;
    235251    list->window2 = NULL;
     
    256272    out->y = NULL;
    257273    out->flux = NULL;
     274    out->window = psMemIncrRefCounter(in->window);
    258275    out->window1 = psMemIncrRefCounter(in->window1);
    259276    out->window2 = psMemIncrRefCounter(in->window2);
     
    331348    stamp->vector = NULL;
    332349    stamp->norm = NAN;
     350    stamp->normI1 = NAN;
     351    stamp->normI2 = NAN;
     352    stamp->normSquare1 = NAN;
     353    stamp->normSquare2 = NAN;
     354
     355    stamp->MxxI1 = NULL;
     356    stamp->MyyI1 = NULL;
     357    stamp->MxxI2 = NULL;
     358    stamp->MyyI2 = NULL;
     359
     360    stamp->MxxI1raw = NAN;
     361    stamp->MyyI1raw = NAN;
     362    stamp->MxxI2raw = NAN;
     363    stamp->MyyI2raw = NAN;
    333364
    334365    return stamp;
     
    431462                // Take stamps off the top of the (sorted) list
    432463                for (int j = xList->n - 1; j >= 0 && !goodStamp; j--) {
     464                    // fprintf (stderr, "%d : xList: %ld elements\n", i, xList->n);
    433465                    // Chop off the top of the list
    434466                    xList->n = j;
     
    459491                                            yList->data.F32[j], yList->data.F32[j], numCols, numRows, border);
    460492#endif
    461                     if (0 && goodStamp) {
    462                         fprintf (stderr, "find: %6.1f < %6.1f < %6.1f, %6.1f < %6.1f %6.1f\n",
    463                                  region->x0 + size, xStamp, region->x1 - size,
    464                                  region->y0 + size, yStamp, region->y1 - size);
    465                     }
    466493                }
    467494            } else {
     
    656683    psImageInit(stamps->window2->image, 0.0);
    657684
     685    // Generate a weighting window based on the fwhms (20% larger than the largest)
     686    {
     687        float fwhm1, fwhm2;
     688
     689        // XXX this is annoyingly hack-ish
     690        pmSubtractionGetFWHMs(&fwhm1, &fwhm2);
     691
     692        float sigma = 1.5 * PS_MAX(fwhm1, fwhm2) / 2.35;
     693
     694        psFree (stamps->window);
     695        stamps->window = psKernelAlloc(-size, size, -size, size);
     696        psImageInit(stamps->window->image, 0.0);
     697
     698        for (int y = -size; y <= size; y++) {
     699            for (int x = -size; x <= size; x++) {
     700                stamps->window->kernel[y][x] = exp(-0.5*(x*x + y*y)/(sigma*sigma));
     701            }
     702        }
     703    }
     704
    658705    // generate normalizations for each stamp
    659706    psVector *norm1 = psVectorAlloc(stamps->num, PS_TYPE_F32);
     
    678725
    679726    // storage vector for flux data
    680     psStats *stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
     727    psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
    681728    psVector *flux1 = psVectorAllocEmpty(2*stamps->num, PS_TYPE_F32);
    682729    psVector *flux2 = psVectorAllocEmpty(2*stamps->num, PS_TYPE_F32);
     
    706753                psAbort ("failed to generate stats");
    707754            }
    708             float f1 = stats->robustMedian;
     755            float f1 = stats->sampleMedian;
    709756
    710757            psStatsInit (stats);
     
    712759                psAbort ("failed to generate stats");
    713760            }
    714             float f2 = stats->robustMedian;
     761            float f2 = stats->sampleMedian;
    715762
    716763            stamps->window1->kernel[y][x] = f1;
     
    728775    }
    729776
     777#if 0
     778    {
     779        psFits *fits = NULL;
     780        fits = psFitsOpen ("window1.raw.fits", "w");
     781        psFitsWriteImage (fits, NULL, stamps->window1->image, 0, NULL);
     782        psFitsClose (fits);
     783        fits = psFitsOpen ("window2.raw.fits", "w");
     784        psFitsWriteImage (fits, NULL, stamps->window2->image, 0, NULL);
     785        psFitsClose (fits);
     786    }
     787#endif
     788
    730789    psTrace("psModules.imcombine", 3, "Window total (1): %f, threshold: %f\n", sum1, (1.0 - stamps->normFrac) * sum1);
    731790    psTrace("psModules.imcombine", 3, "Window total (2): %f, threshold: %f\n", sum2, (1.0 - stamps->normFrac) * sum2);
    732791
    733 # if (0)
     792# if (1)
    734793    // this block attempts to calculate the radius based on the first radial moment
    735     bool done1 = false;
    736     bool done2 = false;
    737     double prior1 = 0.0;
    738     double prior2 = 0.0;
     794    double Sr1 = 0.0;
     795    double Sr2 = 0.0;
     796    double Sf1 = 0.0;
     797    double Sf2 = 0.0;
    739798    for (int y = -size; y <= size; y++) {
    740799        for (int x = -size; x <= size; x++) {
     
    750809    float R2 = Sr2 / Sf2;
    751810
    752     stamps->normWindow1 = 2.5*R1;
    753     stamps->normWindow1 = 2.5*R2;
     811    stamps->normWindow1 = 2.0*R1;
     812    stamps->normWindow2 = 2.0*R2;
     813    psLogMsg ("psModules.imcombine", PS_LOG_DETAIL, "Kron Radii: %f for 1, %f for 2\n", stamps->normWindow1, stamps->normWindow2);
     814
    754815# else
    755816    // XXX : this block attempts to calculate the radius by looking at the curve of growth (or something vaguely equivalent).
     
    778839            // interpolate to the radius at which delta2 is normFrac:
    779840            stamps->normWindow1 = radius - (stamps->normFrac - delta1) / (delta1o - delta1);
    780             fprintf (stderr, "choosing %f (%d) for 1 (%f : %f)\n", stamps->normWindow1, radius, within1, delta1);
     841            psLogMsg ("psModules.imcombine", PS_LOG_DETAIL, "choosing %f (%d) for 1 (%f : %f)\n", stamps->normWindow1, radius, within1, delta1);
    781842            done1 = true;
    782843        }
     
    785846            // interpolate to the radius at which delta2 is normFrac:
    786847            stamps->normWindow2 = radius - (stamps->normFrac - delta2) / (delta2o - delta2);
    787             fprintf (stderr, "choosing %f (%d) for 2 (%f : %f)\n", stamps->normWindow2, radius, within2, delta2);
     848            psLogMsg ("psModules.imcombine", PS_LOG_DETAIL, "choosing %f (%d) for 2 (%f : %f)\n", stamps->normWindow2, radius, within2, delta2);
    788849            done2 = true;
    789850        }
     
    833894    {
    834895        psFits *fits = NULL;
    835         fits = psFitsOpen ("window1.fits", "w");
     896        fits = psFitsOpen ("window1.norm.fits", "w");
    836897        psFitsWriteImage (fits, NULL, stamps->window1->image, 0, NULL);
    837898        psFitsClose (fits);
    838         fits = psFitsOpen ("window2.fits", "w");
     899        fits = psFitsOpen ("window2.norm.fits", "w");
    839900        psFitsWriteImage (fits, NULL, stamps->window2->image, 0, NULL);
    840901        psFitsClose (fits);
     
    906967        float M2 = pmSubtractionKernelPenaltySingle(kernel->kernel, zeroNull);
    907968
    908         penalty1 = M2 + PS_SQR(fwhm1 / 2.35); // rescale the unconvolved second-moment by the image second moment
    909         penalty2 = M2 + PS_SQR(fwhm2 / 2.35); // rescale the unconvolved second-moment by the image second moment
     969        if (1) {
     970            penalty1 = M2 * PS_SQR(fwhm1 / 2.35); // rescale the unconvolved second-moment by the image second moment
     971            penalty2 = M2 * PS_SQR(fwhm2 / 2.35); // rescale the unconvolved second-moment by the image second moment
     972            // penalty1 = M2 + PS_SQR(fwhm1 / 2.35); // rescale the unconvolved second-moment by the image second moment
     973            // penalty2 = M2 + PS_SQR(fwhm2 / 2.35); // rescale the unconvolved second-moment by the image second moment
     974        } else {
     975            penalty1 = PS_SQR(fwhm1 / 2.35); // rescale the unconvolved second-moment by the image second moment
     976            penalty2 = PS_SQR(fwhm2 / 2.35); // rescale the unconvolved second-moment by the image second moment
     977        }
    910978    }
    911979    kernels->penalties1->data.F32[index] = kernels->penalty * penalty1;
     
    915983    psAssert (isfinite(kernels->penalties2->data.F32[index]), "invalid penalty");
    916984
    917     fprintf(stderr, "penalty1: %f, penalty2: %f\n", penalty1, penalty2);
     985    // fprintf(stderr, "penalty1: %f, penalty2: %f\n", penalty1, penalty2);
    918986
    919987    return true;
     
    9421010    penalty *= 1.0 / sum2;
    9431011
    944     if (1) {
    945         fprintf(stderr, "min: %lf, max: %lf, moment: %lf, flux^2: %lf\n", min, max, penalty, sum2);
     1012    if (0) {
     1013        // fprintf(stderr, "min: %lf, max: %lf, moment: %lf, flux^2: %lf\n", min, max, penalty, sum2);
    9461014        // psTrace("psModules.imcombine", 7, "Kernel %d: %f %d %d %f\n", index, fwhm, uOrder, vOrder, penalty);
    9471015    }
     
    9831051
    9841052        if (x < bounds.x0 + size || x > bounds.x1 - size || y < bounds.y0 + size || y > bounds.y1 - size) {
    985             psError(PM_ERR_PROG, false, "Stamp %d (%d,%d) is within the region border.\n", i, x, y);
    986             return false;
     1053          psLogMsg("psModules.imcombine", 3, "Stamp %d (%d,%d) is within the region border.\n", i, x, y);
     1054          stamp->status = PM_SUBTRACTION_STAMP_NONE;
     1055          continue;
    9871056        }
    9881057
Note: See TracChangeset for help on using the changeset viewer.