IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4642


Ignore:
Timestamp:
Jul 28, 2005, 7:04:10 AM (21 years ago)
Author:
eugene
Message:

cleanup memory leaks

Location:
trunk/psphot/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/LocalSky.c

    r4630 r4642  
    2525    mySource->mask = subImageMask;
    2626    mySource->noise = subImageNoise;
     27    psFree (srcRegion);
    2728
    2829    return(mySource);
     
    4748    myStats = psImageStats(myStats, image, mask, 0xff);
    4849    psImageMaskRegion (mask, srcRegion, AND, 0x7f);
     50    psFree (srcRegion);
    4951
    5052    psF64 tmpF64;
     
    5456    source->moments = pmMomentsAlloc();
    5557    source->moments->Sky = (psF32) tmpF64;
    56 
    5758    return (true);
    5859}
  • trunk/psphot/src/apply_psf_model.c

    r4630 r4642  
    3939        if (source->type == PS_SOURCE_SATURATED) continue;
    4040
    41         source->modelPSF = NULL;
     41        // do I even need to test?
     42        if (source->modelPSF != NULL) {
     43          psFree (source->modelPSF);
     44        }
    4245
    4346        // use the source moments, etc to guess basic model parameters
  • trunk/psphot/src/basic_classes.c

    r4582 r4642  
    88    psfClump = pmSourcePSFClump (sources, config);
    99    pmSourceRoughClass (sources, config, psfClump);
    10 
    11     // make this optional
    12     // DumpMoments (sources, "moments.dat");
    1310    return (true);
    1411}
  • trunk/psphot/src/choose_psf_model.c

    r4630 r4642  
    3434        modelName = psMetadataLookupPtr (&status, config, key);
    3535        tests->data[i] = pmPSF_TestModel (stars, modelName, RADIUS);
     36        psFree (modelName);
    3637
    37         sprintf (filename, "metric.%d.dat", i);
    38         DumpPSFTestData (tests->data[i], filename);
     38        // make this an option:
     39        // sprintf (filename, "metric.%d.dat", i);
     40        // DumpPSFTestData (tests->data[i], filename);
    3941    }
     42    psFree (stars);
    4043
    4144    // select the best of the test models
     
    4649    for (int i = 1; i < Ntest; i++) {
    4750        test = tests->data[i];
    48         int M = test->dApResid;
     51        float M = test->dApResid;
    4952        if (M < bestM) {
    5053            bestM = M;
     
    5558    modelName = psModelGetType (test->modelType);
    5659    psLogMsg ("psphot.pspsf", 3, "selected psf model %s, ApResid: %f +/- %f\n", modelName, test->ApResid, test->dApResid);
     60    psFree (modelName);
    5761
     62    // we are keeping the modelPSF fits from the PSF test,
     63    // but we replace these later on (apply_psf_model)
    5864    // set source->model based on best psf model fit
    5965    for (int i = 0; i < test->sources->n; i++) {
     
    6773        }
    6874    }
    69     return (test->psf);
     75    pmPSF *psf = test->psf;
     76
     77    // free unused test models:
     78    psFree (test);
     79    psFree (stars);
     80
     81    return (psf);
    7082}
  • trunk/psphot/src/find_peaks.c

    r4216 r4642  
    99
    1010    // smooth the image
    11     // should we also subtract a super-binned image? (as an option?)
    1211
    1312    psTimerStart ("psphot");
     
    1817    psImage *smooth = psImageCopy (NULL, imdata->image, PS_TYPE_F32);
    1918    psImageSmooth (smooth, SIGMA, NSIGMA);
    20 
    2119    psLogMsg ("psphot", 4, "smooth: %f sec\n", psTimerMark ("psphot"));
    22 
    23     // find the peaks in the smoothed image
    2420
    2521    psTimerStart ("psphot");
    2622
     23    // find the peaks in the smoothed image
    2724    NSIGMA    = psMetadataLookupF32 (&status, config, "PEAK_NSIGMA");
    2825    threshold = NSIGMA*sky->sampleStdev + sky->sampleMean;
     
    3229    if (peaks == NULL) psAbort ("find peaks", "no peaks found");
    3330    psFree (smooth);
    34     // XXX Need to gracefully handle no source detections
    3531
    3632    // make this optional
     
    4137    return (peaks);
    4238}
     39
     40// In this function, we smooth the image, then search for the peaks
     41// Should we also subtract a super-binned image? (as an option?)
     42// We need to gracefully handle no source detections
  • trunk/psphot/src/fit_galaxies.c

    r4630 r4642  
    3232        if (source->type == PS_SOURCE_SATSTAR) continue;
    3333        if (source->type == PS_SOURCE_GOODSTAR) continue;
     34
    3435        // skip all likely defects
    3536        if (source->type == PS_SOURCE_DEFECT) continue;
    3637        if (source->type == PS_SOURCE_SATURATED) continue;
    37         //
     38
     39        // skip poorly fitted stars
    3840        if (source->type == PS_SOURCE_FAINTSTAR) continue;
    3941        if (source->type == PS_SOURCE_POOR_FIT_PSF) continue;
  • trunk/psphot/src/image_stats.c

    r4216 r4642  
    3535        stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
    3636        stats = psVectorStats (stats, subset, NULL, NULL, 0); // use a mask?
     37        psFree (subset);
     38        psFree (rnd)
    3739    }
    3840
  • trunk/psphot/src/pspsf.c

    r4375 r4642  
    2121        psf->params->data[i] = Polynomial2DAlloc(1, 1, PS_POLYNOMIAL_ORD);
    2222    }
     23    // set the destructors
    2324    return(psf);
    2425}
     
    4849        test->fitMag->data.F64[i] = 0;
    4950    }   
     51    // set the destructors
     52
    5053    return (test);
    5154}
     
    9295    psLogMsg ("psphot.psftest", 4, "fit flt:   %f sec for %d sources\n", psTimerMark ("fit"), sources->n);
    9396    psTrace ("psphot.psftest", 3, "keeping %d of %d PSF candidates (FLT)\n", Nflt, sources->n);
    94     DumpModelFits (test->modelFLT, "modelsFLT.dat");
     97
     98    // make this optional?
     99    // DumpModelFits (test->modelFLT, "modelsFLT.dat");
    95100
    96101    // stage 2: construct a psf (pmPSF) from this collection of model fits
     
    141146    psLogMsg ("psphot.psftest", 4, "fit psf:   %f sec for %d sources\n", psTimerMark ("fit"), sources->n);
    142147    psTrace ("psphot.psftest", 3, "keeping %d of %d PSF candidates (PSF)\n", Npsf, sources->n);
    143     DumpModelFits (test->modelPSF, "modelsPSF.dat");
     148
     149    // make this optional
     150    // DumpModelFits (test->modelPSF, "modelsPSF.dat");
    144151
    145152    // XXX this function wants aperture radius from pmSourcePhotometry
     
    188195        // psPolynomial2DDump (psf->params->data[i]);
    189196    }
     197   
     198    psFree (x);
     199    psFree (y);
     200    psFree (z);
     201    psFree (dz);
    190202    return (true);
    191203}
     
    228240    rflux->data.F64[i] = pow(10.0, 0.4*test->fitMag->data.F64[i]);
    229241  }
    230   // psScalar *t1 = psScalar(0.4);
    231   // psVector *v1 = psBinaryOp (NULL, test->fitMag, "*", t1);
    232   // psVector *rflux = psUnaryOp (NULL, v1, "ten");
    233   // psFree (t1);
    234   // psFree (v1);
    235242
    236243  // find min and max of (1/flux):
     
    247254  psTrace ("psphot.metricmodel", 3, "rflux max: %g, min: %g, delta: %g\n", stats->max, stats->min, dBin);
    248255
     256  // group data in daBin bins, measure lower 50% mean
    249257  for (int i = 0; i < daBin->n; i++) {
    250258
     
    277285    // dA values are contaminated with low outliers
    278286    // measure statistics only on upper 50% of points
     287    // this would be easier if we could sort in reverse:
     288    //
     289    // psVectorSort (tmp, tmp);
     290    // tmp->n = 0.5*tmp->n;
     291    // stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
     292    // psVectorStats (stats, tmp, NULL, NULL, 0);
     293    // psTrace ("psphot.metricmodel", 4, "rfBin %d (%g): %d pts, %g\n", i, rfBin->data.F64[i], tmp->n, stats->sampleMedian);
     294
    279295    psVectorSort (tmp, tmp);
    280296    nKeep = 0.5*tmp->n;
     
    291307
    292308    daBin->data.F64[i] = stats->sampleMedian;
     309
     310    psFree (stats);
     311    psFree (tmp);
     312    psFree (tmp2);
    293313  }
    294314
     
    307327  test->skyBias = poly->coeff[1] / (M_PI * PS_SQR(RADIUS));
    308328
     329  psFree (maskB);
     330  psFree (rfBin);
     331  psFree (daBin);
     332  psFree (daBinFit);
     333  psFree (daResid);
     334  psFree (poly);
     335  psFree (stats);
     336
    309337  return true;
    310338}
  • trunk/psphot/src/setup.c

    r4641 r4642  
    8383    float YMAX  = psMetadataLookupF32 (&status, config, "YMAX");
    8484    psRegion *keep = psRegionAlloc (XMIN, XMAX, YMIN, YMAX);
    85     keep           = psRegionForImage (keep, image, keep);
     85    keep = psRegionForImage (keep, image, keep);
    8686    psImageKeepRegion (mask, keep, OR, 0x01);
     87    psFree (keep);
    8788
    8889    // mask the saturated pixels
Note: See TracChangeset for help on using the changeset viewer.