IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4901


Ignore:
Timestamp:
Aug 29, 2005, 5:44:55 PM (21 years ago)
Author:
eugene
Message:

various psphot updates

Location:
trunk
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/archive/scripts/Makefile

    r4048 r4901  
    1515LIBS    =       -lpsmodule $(LPSLIB)
    1616CFLAGS  =       $(INCS) -std=c99
    17 LFLAGS  =       $(LIBS) -static
     17LFLAGS  =       $(LIBS)
    1818
    1919PSPHOT = \
  • trunk/psphot/Makefile

    r4641 r4901  
    33        @echo "USAGE: make psphot"
    44
    5 CC      =       gcc -g -Wall
     5CC      =       gcc -g -Wall -O2
    66SRC     =       src
    77BIN     =       bin
     
    3636$(SRC)/fit_galaxies.$(ARCH).o \
    3737$(SRC)/LocalSky.$(ARCH).o \
    38 $(SRC)/basic_classes.$(ARCH).o
     38$(SRC)/basic_classes.$(ARCH).o \
     39$(SRC)/psLine.$(ARCH).o \
     40$(SRC)/output.$(ARCH).o
    3941
    4042FITSOURCE = \
  • trunk/psphot/src/LocalSky.c

    r4642 r4901  
    1818    //  psImage *subImageNoise = psImageSubset(imdata->noise, srcRegion);
    1919
    20     psImage *subImage = psImageSubset(imdata->image, srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1);
    21     psImage *subImageMask = psImageSubset(imdata->mask, srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1);
    22     psImage *subImageNoise = psImageSubset(imdata->noise, srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1);
    23 
    24     mySource->pixels = subImage;
    25     mySource->mask = subImageMask;
    26     mySource->noise = subImageNoise;
     20    mySource->pixels = psImageSubset(imdata->image, srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1);
     21    mySource->noise  = psImageSubset(imdata->noise, srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1);
     22    mySource->mask   = psImageSubset(imdata->mask,  srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1);
     23
    2724    psFree (srcRegion);
    28 
    2925    return(mySource);
    3026}
     
    4844    myStats = psImageStats(myStats, image, mask, 0xff);
    4945    psImageMaskRegion (mask, srcRegion, AND, 0x7f);
    50     psFree (srcRegion);
    5146
    5247    psF64 tmpF64;
    5348    p_psGetStatValue(myStats, &tmpF64);
     49
     50    psFree (myStats);
     51    psFree (srcRegion);
     52
    5453    if (isnan(tmpF64)) return (false);
    55 
    5654    source->moments = pmMomentsAlloc();
    5755    source->moments->Sky = (psF32) tmpF64;
  • trunk/psphot/src/apply_psf_model.c

    r4642 r4901  
    1414    int   Niter = 0;
    1515
     16    psMemoryId id = psMemGetId ();
    1617    psTimerStart ("psphot");
    1718
     
    3334
    3435    for (int i = 0; i < sources->n; i++) {
     36
    3537        psSource *source = sources->data[i];
    3638
     
    3941        if (source->type == PS_SOURCE_SATURATED) continue;
    4042
    41         // do I even need to test?
    42         if (source->modelPSF != NULL) {
    43           psFree (source->modelPSF);
    44         }
    45 
    4643        // use the source moments, etc to guess basic model parameters
    47         psModel *model  = pmSourceModelGuess (source, psf->type);
     44        psModel *modelFLT  = pmSourceModelGuess (source, psf->type);
    4845
    4946        // set PSF parameters for this model
    50         model  = psModelFromPSF (model, psf);
     47        psModel *model  = psModelFromPSF (modelFLT, psf);
    5148        x = model->params->data.F32[2];
    5249        y = model->params->data.F32[3];
     50        psFree (modelFLT);
    5351
    5452        // set the fit radius based on the object flux limit and the model
     
    7270          psLogMsg ("psphot", 3, "PSF fit failed for %f, %f (%d iterations)\n", x, y, model->nIter);
    7371          source->type = PS_SOURCE_FAIL_FIT_PSF;  // better choice?
     72          psFree (model);
    7473          continue;
    7574        }
  • trunk/psphot/src/basic_classes.c

    r4642 r4901  
    66
    77    // group into STAR, COSMIC, GALAXY, SATURATED
     8    // XXX - this has 1 leak
    89    psfClump = pmSourcePSFClump (sources, config);
    910    pmSourceRoughClass (sources, config, psfClump);
     11
    1012    return (true);
    1113}
  • trunk/psphot/src/choose_psf_model.c

    r4642 r4901  
    77    bool        status;
    88    char       *modelName;
    9     char        key[64], filename[64];
     9    char        key[64];
    1010    pmPSF_Test *test  = NULL;
    1111    psArray    *stars = NULL;
     
    3131    psArray *tests = psArrayAlloc (Ntest);
    3232    for (int i = 0; i < tests->n; i++) {
    33         sprintf (key, "PSF_MODEL_%d", i);
     33        snprintf (key, 64, "PSF_MODEL_%d", i);
    3434        modelName = psMetadataLookupPtr (&status, config, key);
     35
    3536        tests->data[i] = pmPSF_TestModel (stars, modelName, RADIUS);
    3637        psFree (modelName);
     
    5556        }
    5657    }
     58    // keep only the selected test:
    5759    test = tests->data[bestN];
    5860    modelName = psModelGetType (test->modelType);
    5961    psLogMsg ("psphot.pspsf", 3, "selected psf model %s, ApResid: %f +/- %f\n", modelName, test->ApResid, test->dApResid);
    60     psFree (modelName);
    6162
     63    // XXX I am having trouble tracking down the double frees vs leaks
     64    # if (0)
    6265    // we are keeping the modelPSF fits from the PSF test,
    6366    // but we replace these later on (apply_psf_model)
     
    7073          source->modelPSF = NULL;
    7174        } else {
     75          // source->modelPSF = psMemCopy(test->modelPSF->data[i]);
    7276          source->modelPSF = test->modelPSF->data[i];
    7377        }
    7478    }
    75     pmPSF *psf = test->psf;
     79    # endif
    7680
    77     // free unused test models:
    78     psFree (test);
    79     psFree (stars);
    80 
     81    pmPSF *psf = psMemCopy(test->psf);
     82    psFree (tests);
    8183    return (psf);
    8284}
  • trunk/psphot/src/find_peaks.c

    r4642 r4901  
    2121    psTimerStart ("psphot");
    2222
    23     // find the peaks in the smoothed image
     23    // set peak threshold
    2424    NSIGMA    = psMetadataLookupF32 (&status, config, "PEAK_NSIGMA");
    2525    threshold = NSIGMA*sky->sampleStdev + sky->sampleMean;
    2626    psLogMsg ("psphot", 3, "threshold: %f DN\n", threshold);
    2727
     28    // find the peaks in the smoothed image
    2829    psArray *peaks = pmFindImagePeaks (smooth, threshold);
    2930    if (peaks == NULL) psAbort ("find peaks", "no peaks found");
     
    3132
    3233    // make this optional
    33     DumpPeaks (peaks, "peaks.dat");
     34    // DumpPeaks (peaks, "peaks.dat");
    3435
    3536    psLogMsg ("psphot", 3, "%d peaks: %f sec\n", peaks->n, psTimerMark ("psphot"));
  • trunk/psphot/src/fit_galaxies.c

    r4642 r4901  
    2424
    2525    psTimerStart ("psphot");
     26
     27    float dt = 0;
     28    float dT = 0;
     29    float dT2 = 0;
     30    int dTn = 0;
     31
    2632    for (int i = 0; i < sources->n; i++) {
    2733        psSource *source = sources->data[i];
     
    7278        // fit as FLT, not PSF (skip poor fits)
    7379        psImageKeepCircle (source->mask, x, y, model->radius, OR, 0x80);
     80        psTimerStart ("galfit");
    7481        status = pmSourceFitModel_EAM (source, model, false);
     82        dt = psTimerMark ("galfit");
     83        dT += dt;
     84        dT2 += dt*dt;
     85        dTn ++;
    7586        psImageKeepCircle (source->mask, x, y, model->radius, AND, 0x7f);
    7687        if (!status) {
     
    105116
    106117    }
     118    dt = dT / dTn;
     119    fprintf (stderr, "dt: %f +/- %f\n", dt, sqrt(dT2/dTn - PS_SQR(dt)));
    107120    psLogMsg ("psphot", 3, "fit galaxies: %f sec for %d galaxies (%d failures, %d total iterations)\n", psTimerMark ("psphot"), Nfit, Nfail, Niter);
    108121    return (true);
  • trunk/psphot/src/image_stats.c

    r4642 r4901  
    3636        stats = psVectorStats (stats, subset, NULL, NULL, 0); // use a mask?
    3737        psFree (subset);
    38         psFree (rnd)
     38        psFree (rnd);
    3939    }
    4040
     
    5252    psLogMsg ("psphot", 3, "background: %f +/- %f\n", sky->sampleMean, sky->sampleStdev);
    5353
     54    psFree (stats);
    5455    return (sky);
    5556}
  • trunk/psphot/src/load_args.c

    r4641 r4901  
    3636
    3737  // load config information
     38  // XXX - 3 leaks from this
    3839  psMetadata *config = psMetadataParseConfig (NULL, &Nfail, argv[3], FALSE);
    3940
  • trunk/psphot/src/output.c

    r4641 r4901  
    33// output functions: we have several fixed modes (sx, obj, cmp)
    44
     5static int GetDophotType (psSource *source) {
     6
     7    switch (source->type) {
     8
     9      case PS_SOURCE_DEFECT:
     10      case PS_SOURCE_SATURATED:
     11        return (8);
     12
     13      case PS_SOURCE_SATSTAR:
     14        return (10);
     15
     16      case PS_SOURCE_PSFSTAR:
     17      case PS_SOURCE_GOODSTAR:
     18        return (1);
     19
     20      case PS_SOURCE_POOR_FIT_PSF:
     21        return (7);
     22
     23      case PS_SOURCE_FAIL_FIT_PSF:
     24      case PS_SOURCE_FAINTSTAR:
     25        return (4);
     26
     27      case PS_SOURCE_GALAXY:
     28      case PS_SOURCE_FAINT_GALAXY:
     29      case PS_SOURCE_DROP_GALAXY:
     30      case PS_SOURCE_FAIL_FIT_GAL:
     31      case PS_SOURCE_POOR_FIT_GAL:
     32        return (2);
     33
     34      case PS_SOURCE_OTHER:
     35      default:
     36        return (0);
     37    }
     38    return (0);
     39}
     40
    541void output (psImageData *imdata, psMetadata *config, psArray *sources) {
    642
    7   char *outputMode = psMetadataLookupPtr (&status, config, "OUTPUT_MODE");
    8 
    9   if (outputMode == NULL) {
    10     WriteSourcesText (imdata, config, sources);
     43    bool status;
     44
     45    char *outputMode = psMetadataLookupPtr (&status, config, "OUTPUT_MODE");
     46
     47    if (outputMode == NULL) {
     48        WriteSourcesText (imdata, config, sources);
     49        exit (0);
     50    }
     51
     52    if (!strcasecmp (outputMode, "OBJ")) {
     53        WriteSourcesOBJ (imdata, config, sources);
     54        exit (0);
     55    }
     56 
     57    if (!strcasecmp (outputMode, "SX")) {
     58        WriteSourcesSX (imdata, config, sources);
     59        exit (0);
     60    }
     61 
     62    if (!strcasecmp (outputMode, "CMP")) {
     63        WriteSourcesCMP (imdata, config, sources);
     64        exit (0);
     65    }
     66 
     67    if (!strcasecmp (outputMode, "CMF")) {
     68        WriteSourcesCMF (imdata, config, sources);
     69        exit (0);
     70    }
     71 
     72    psAbort ("psphot", "unknown output mode %s", outputMode);
     73}
     74
     75bool WriteSourcesText (psImageData *imdata, psMetadata *config, psArray *sources) {
     76
     77    bool status;
     78
     79    char *filename = psMetadataLookupPtr (&status, config, "OUTPUT");
     80
     81    DumpImage (imdata->image, filename);
     82
     83    // get these names from config?
     84    DumpModelPSF (sources, "psfsources.dat");
     85    DumpModelFLT (sources, "fltsources.dat");
     86    DumpModelNULL (sources, "nullsources.dat");
     87    DumpMoments (sources, "moments.dat");
     88
    1189    exit (0);
    12   }
    13 
    14   if (!strcasecmp (outputMode, "OBJ")) {
    15     WriteSourcesOBJ (imdata, config, sources);
    16     exit (0);
    17   }
    18  
    19   if (!strcasecmp (outputMode, "SX")) {
    20     WriteSourcesSX (imdata, config, sources);
    21     exit (0);
    22   }
    23  
    24   if (!strcasecmp (outputMode, "CMP")) {
    25     WriteSourcesCMP (imdata, config, sources);
    26     exit (0);
    27   }
    28  
    29   if (!strcasecmp (outputMode, "CMF")) {
    30     WriteSourcesCMF (imdata, config, sources);
    31     exit (0);
    32   }
    33  
    34   psAbort ("psphot", "unknown output mode %s", outputMode);
    35 }
    36 
    37 bool WriteSourceText (psImageData *imdata, psMetadata *config, psArray *sources) {
    38 
    39   char *filename = psMetadataLookupPtr (&status, config, "OUTPUT");
    40 
    41   DumpImage (imdata->image, filename);
    42 
    43   // get these names from config?
    44   DumpModelPSF (sources, "psfsources.dat");
    45   DumpModelFLT (sources, "fltsources.dat");
    46   DumpModelNULL (sources, "nullsources.dat");
    47   DumpMoments (sources, "moments.dat");
    48 
    49   exit (0);
    5090}
    5191
     
    5393bool WriteSourcesOBJ (psImageData *imdata, psMetadata *config, psArray *sources) {
    5494
    55 # define NCHAR 104
    56 
    57     char line[NCHAR];
    58 
    59     char *filename = psMetadataLookupPtr (&status, config, "OUTPUT");
     95    int i, type;
     96    bool status;
     97    psModel *model;
     98    psF32 *PAR, *dPAR;
     99    float dmag, apMag, fitMag;
     100
     101    char *filename = psMetadataLookupPtr (&status, config, "OUTPUT");
     102    psLine *line = psLineAlloc (104);  // 104 is dophot-defined line length
     103
     104    FILE *f = fopen (filename, "w");
     105    if (f == NULL) {
     106        psLogMsg ("WriteSourceOBJ", 3, "can't open output file for output %s\n", filename);
     107        return false;
     108    }
     109
     110    // write sources with models first
     111    for (i = 0; i < sources->n; i++) {
     112        psSource *source = (psSource *) sources->data[i];
     113        model = source->modelPSF;
     114        if (model == NULL) continue;
     115        PAR = model->params->data.F32;
     116        dPAR = model->dparams->data.F32;
     117
     118        pmSourcePhotometry (&fitMag, &apMag, model, source->pixels, source->mask);
     119        dmag = dPAR[1] / PAR[1];
     120
     121        type = GetDophotType (source);
     122        psLineInit (line);
     123        psLineAdd (line, "%3d", type);
     124        psLineAdd (line, "%8.2f", PAR[2]);
     125        psLineAdd (line, "%8.2f", PAR[3]);
     126        psLineAdd (line, "%8.3f", fitMag);
     127        psLineAdd (line, "%6.3f", dmag);
     128        psLineAdd (line, "%9.2f", PAR[0]);
     129        psLineAdd (line, "%9.3f", PAR[4]);
     130        psLineAdd (line, "%9.3f", PAR[5]);
     131        psLineAdd (line, "%7.2f", PAR[6]);
     132        psLineAdd (line, "%8.3f", 32.0);
     133        psLineAdd (line, "%8.3f", apMag);
     134        psLineAdd (line, "%8.2f", apMag - fitMag);
     135        fwrite (line->line, 1, line->Nline, f);
     136    }
     137    fclose (f);
     138    return true;
     139
     140}
     141
     142// elixir/sextractor-style output list with fixed line width
     143bool WriteSourcesSX (psImageData *imdata, psMetadata *config, psArray *sources) {
     144
     145    int i, type;
     146    bool status;
     147    psModel *model;
     148    psF32 *PAR, *dPAR;
     149    float dmag, apMag, fitMag;
     150
     151    char *filename = psMetadataLookupPtr (&status, config, "OUTPUT");
     152    psLine *line = psLineAlloc (104);  // 104 is dophot-defined line length
    60153
    61154    FILE *f = fopen (filename, "w");
     
    70163        model = (psModel  *) source->modelPSF;
    71164        if (model == NULL) continue;
    72         params = model->params;
    73         dparams = model->dparams;
     165        PAR = model->params->data.F32;
     166        dPAR = model->dparams->data.F32;
    74167
    75168        pmSourcePhotometry (&fitMag, &apMag, model, source->pixels, source->mask);
    76         dmag = dparams[0].data.F32[1] / params[0].data.F32[1];
    77 
     169        dmag = dPAR[1] / PAR[1];
     170
     171        // XXX EAM : fix this to match sextractor output
    78172        type = GetDophotType (source);
    79         init_line (line, &Nline);
    80         add_to_line (line, &Nline, "%3d", type);
    81         add_to_line (line, &Nline, "%8.2f", params[0].data.F32[2]);
    82         add_to_line (line, &Nline, "%8.2f", params[0].data.F32[3]);
    83         add_to_line (line, &Nline, "%8.3f", fitMag);
    84         add_to_line (line, &Nline, "%6.3f", dmag);
    85         add_to_line (line, &Nline, "%9.2f", params[0].data.F32[0]);
    86         add_to_line (line, &Nline, "%9.3f", params[0].data.F32[4]);
    87         add_to_line (line, &Nline, "%9.3f", params[0].data.F32[5]);
    88         add_to_line (line, &Nline, "%7.2f", params[0].data.F32[6]);
    89         add_to_line (line, &Nline, "%8.3f", 32.0);
    90         add_to_line (line, &Nline, "%8.3f", apMag);
    91         add_to_line (line, &Nline, "%8.2f", apMag - fitMag);
     173        psLineInit (line);
     174        psLineAdd (line, "%3d", type);
     175        psLineAdd (line, "%8.2f", PAR[2]);
     176        psLineAdd (line, "%8.2f", PAR[3]);
     177        psLineAdd (line, "%8.3f", fitMag);
     178        psLineAdd (line, "%6.3f", dmag);
     179        psLineAdd (line, "%9.2f", PAR[0]);
     180        psLineAdd (line, "%9.3f", PAR[4]);
     181        psLineAdd (line, "%9.3f", PAR[5]);
     182        psLineAdd (line, "%7.2f", PAR[6]);
     183        psLineAdd (line, "%8.3f", 32.0);
     184        psLineAdd (line, "%8.3f", apMag);
     185        psLineAdd (line, "%8.2f", apMag - fitMag);
     186        fwrite (line->line, 1, line->Nline, f);
    92187    }
    93188    fclose (f);
    94189    return true;
    95 
    96 }
    97 
    98 // elixir/sextractor-style output list with fixed line width
    99 bool WriteSourcesSX (psImageData *imdata, psMetadata *config, psArray *sources) {
    100 
    101 # define NCHAR 104
    102 
    103     char line[NCHAR];
    104 
    105     char *filename = psMetadataLookupPtr (&status, config, "OUTPUT");
     190}
     191
     192// elixir-style pseudo FITS table (header + ascii list)
     193bool WriteSourcesCMP (psImageData *imdata, psMetadata *config, psArray *sources) {
     194
     195    int i, type;
     196    bool status;
     197    psModel *model;
     198    psF32 *PAR, *dPAR;
     199    float dmag, apMag, fitMag;
     200
     201    char *filename = psMetadataLookupPtr (&status, config, "OUTPUT");
     202    psLine *line = psLineAlloc (104);  // 104 is dophot-defined line length
    106203
    107204    FILE *f = fopen (filename, "w");
     
    110207        return false;
    111208    }
     209
     210    // write imdata->header to file
    112211
    113212    // write sources with models first
     
    116215        model = (psModel  *) source->modelPSF;
    117216        if (model == NULL) continue;
    118         params = model->params;
    119         dparams = model->dparams;
     217        PAR = model->params->data.F32;
     218        dPAR = model->dparams->data.F32;
    120219
    121220        pmSourcePhotometry (&fitMag, &apMag, model, source->pixels, source->mask);
    122         dmag = dparams[0].data.F32[1] / params[0].data.F32[1];
     221        dmag = dPAR[1] / PAR[1];
    123222
    124223        // XXX EAM : fix this to match sextractor output
    125224        type = GetDophotType (source);
    126         init_line (line, &Nline);
    127         add_to_line (line, &Nline, "%3d", type);
    128         add_to_line (line, &Nline, "%8.2f", params[0].data.F32[2]);
    129         add_to_line (line, &Nline, "%8.2f", params[0].data.F32[3]);
    130         add_to_line (line, &Nline, "%8.3f", fitMag);
    131         add_to_line (line, &Nline, "%6.3f", dmag);
    132         add_to_line (line, &Nline, "%9.2f", params[0].data.F32[0]);
    133         add_to_line (line, &Nline, "%9.3f", params[0].data.F32[4]);
    134         add_to_line (line, &Nline, "%9.3f", params[0].data.F32[5]);
    135         add_to_line (line, &Nline, "%7.2f", params[0].data.F32[6]);
    136         add_to_line (line, &Nline, "%8.3f", 32.0);
    137         add_to_line (line, &Nline, "%8.3f", apMag);
    138         add_to_line (line, &Nline, "%8.2f", apMag - fitMag);
    139     }
    140     fclose (f);
    141     return true;
    142 
    143 }
    144 
    145 // elixir-style pseudo FITS table (header + ascii list)
    146 bool WriteSourcesCMP (psImageData *imdata, psMetadata *config, psArray *sources) {
    147 
    148 
    149 # define NCHAR 104
    150 
    151     char line[NCHAR];
    152 
    153     char *filename = psMetadataLookupPtr (&status, config, "OUTPUT");
    154 
    155     FILE *f = fopen (filename, "w");
    156     if (f == NULL) {
    157         psLogMsg ("WriteSourceOBJ", 3, "can't open output file for output %s\n", filename);
    158         return false;
    159     }
    160 
    161     // write imdata->header to file
    162 
    163     // write sources with models first
    164     for (i = 0; i < sources->n; i++) {
    165         psSource *source = (psSource *) sources->data[i];
    166         model = (psModel  *) source->modelPSF;
    167         if (model == NULL) continue;
    168         params = model->params;
    169         dparams = model->dparams;
    170 
    171         pmSourcePhotometry (&fitMag, &apMag, model, source->pixels, source->mask);
    172         dmag = dparams[0].data.F32[1] / params[0].data.F32[1];
    173 
    174         // XXX EAM : fix this to match sextractor output
    175         type = GetDophotType (source);
    176         init_line (line, &Nline);
    177         add_to_line (line, &Nline, "%3d", type);
    178         add_to_line (line, &Nline, "%8.2f", params[0].data.F32[2]);
    179         add_to_line (line, &Nline, "%8.2f", params[0].data.F32[3]);
    180         add_to_line (line, &Nline, "%8.3f", fitMag);
    181         add_to_line (line, &Nline, "%6.3f", dmag);
    182         add_to_line (line, &Nline, "%9.2f", params[0].data.F32[0]);
    183         add_to_line (line, &Nline, "%9.3f", params[0].data.F32[4]);
    184         add_to_line (line, &Nline, "%9.3f", params[0].data.F32[5]);
    185         add_to_line (line, &Nline, "%7.2f", params[0].data.F32[6]);
    186         add_to_line (line, &Nline, "%8.3f", 32.0);
    187         add_to_line (line, &Nline, "%8.3f", apMag);
    188         add_to_line (line, &Nline, "%8.2f", apMag - fitMag);
     225        psLineInit (line);
     226        psLineAdd (line, "%3d", type);
     227        psLineAdd (line, "%8.2f", PAR[2]);
     228        psLineAdd (line, "%8.2f", PAR[3]);
     229        psLineAdd (line, "%8.3f", fitMag);
     230        psLineAdd (line, "%6.3f", dmag);
     231        psLineAdd (line, "%9.2f", PAR[0]);
     232        psLineAdd (line, "%9.3f", PAR[4]);
     233        psLineAdd (line, "%9.3f", PAR[5]);
     234        psLineAdd (line, "%7.2f", PAR[6]);
     235        psLineAdd (line, "%8.3f", 32.0);
     236        psLineAdd (line, "%8.3f", apMag);
     237        psLineAdd (line, "%8.2f", apMag - fitMag);
     238        fwrite (line->line, 1, line->Nline, f);
    189239    }
    190240    fclose (f);
     
    195245bool WriteSourcesCMF (psImageData *imdata, psMetadata *config, psArray *sources) {
    196246
     247    bool status;
     248
    197249    char *filename = psMetadataLookupPtr (&status, config, "OUTPUT");
    198250
     
    200252
    201253    // write FITS table to file (use autocode tools)
    202 }
    203 
    204 // we require a fixed number of chars already allocated
    205 init_line (char *line, int *Nline) {
    206   *Nline = 0;
    207 }
    208 
    209 add_to_line (char *line, int *Nline, char *format, ...) {
    210 
    211     va_list ap;
    212 
    213     va_start (ap, format);
    214     Nchar = vsprintf (&line[*Nline], format, ap);
    215     *Nline += Nchar;
    216 }
    217 
     254
     255    return true;
     256}
  • trunk/psphot/src/psPolynomials.c

    r4375 r4901  
    4242}
    4343
     44static void psPolynomial1DFree (psPolynomial1D *poly) {
     45
     46  if (poly == NULL) return;
     47  psFree (poly->coeff);
     48  psFree (poly->coeffErr);
     49  psFree (poly->mask);
     50  return;
     51}
     52
    4453// XXX EAM : use Nterm = Norder + 1 definition 
    4554// XXX EAM : should we provide both order and nterms in struct?
     
    5463
    5564    newPoly = (psPolynomial1D* ) psAlloc(sizeof(psPolynomial1D));
    56     // p_psMemSetDeallocator(newPoly, (psFreeFcn) polynomial1DFree);
    57     // XXX EAM : me, being lazy
    58 
    5965    newPoly->type = type;
    6066    newPoly->n = nOrder;
     
    6773        newPoly->mask[i] = 0;
    6874    }
     75    p_psMemSetDeallocator(newPoly, (psFreeFcn) psPolynomial1DFree);
    6976    return(newPoly);
    7077}
     
    185192            myPoly->coeff[k] = coeffs->data.F64[k];
    186193        }
     194        psFree (ALUD);
     195        psFree (outPerm);
     196        psFree (coeffs);
    187197    }
    188198
     
    262272}
    263273
     274static void psPolynomial2DFree(psPolynomial2D *poly) {
     275
     276  if (poly == NULL) return;
     277  for (int i = 0; i < poly->nX + 1; i++) {
     278    psFree (poly->coeff[i]);
     279    psFree (poly->coeffErr[i]);
     280    psFree (poly->mask[i]);
     281  }
     282  psFree (poly->coeff);
     283  psFree (poly->coeffErr);
     284  psFree (poly->mask);
     285  return;
     286}
     287
    264288// XXX EAM : use Nterm = Norder + 1 definition 
    265289// the user requests a polynomial of order Norder
     
    277301
    278302    newPoly = (psPolynomial2D* ) psAlloc(sizeof(psPolynomial2D));
    279     // p_psMemSetDeallocator(newPoly, (psFreeFcn) polynomial2DFree);
    280     // XXX EAM : me, being lazy
    281 
    282303    newPoly->type = type;
    283304    newPoly->nX = nXorder;
     
    299320        }
    300321    }
     322    p_psMemSetDeallocator(newPoly, (psFreeFcn) psPolynomial2DFree);
    301323    return(newPoly);
    302324}
  • trunk/psphot/src/psUtils.c

    r4375 r4901  
    22
    33static psHash *timers = NULL;
     4
     5bool psTimerClear (char *name) {
     6
     7  bool status;
     8
     9  if (name == NULL) return false;
     10
     11  status = psHashRemove (timers, name);
     12  return (status);
     13}
     14
     15void psTimerFree () {
     16
     17  psFree (timers);
     18  p_psTimeFinalize();
     19  return;
     20}
    421
    522// start/restart a named timer
     
    1128
    1229    start = psTimeGetTime (PS_TIME_UTC);
    13 
    1430    psHashAdd (timers, name, start);
    15 
     31    psFree (start);
    1632    return (TRUE);
    1733}
     
    3147    mark = psTimeGetTime (PS_TIME_UTC);
    3248    delta = psTimeDelta (mark, start);
     49    psFree (mark);
     50    // psFree (start); -- XXX is psHashLookup not psMemCopying?
     51
    3352    return (delta);
    3453}
     
    191210            }
    192211            *status = true;
     212            // psFree (item);
    193213            return (value);
    194214        }       
     
    198218    if (item->type == PS_META_F32) {
    199219        value = item->data.F32;
     220        // psFree (item);
    200221        return (value);
    201222    }
  • trunk/psphot/src/psphot-utils.c

    r4630 r4901  
    439439
    440440# endif
     441
     442static void psImageDataFree (psImageData *imdata) {
     443
     444  if (imdata == NULL) return;
     445
     446  psFree (imdata->image);
     447  psFree (imdata->header);
     448  psFree (imdata->noise);
     449  psFree (imdata->mask);
     450  return;
     451}
     452
     453psImageData *psImageDataAlloc (psImage *image, psImage *noise, psImage *mask, psMetadata *header) {
     454 
     455    psImageData *imdata = psAlloc(sizeof(psImageData));
     456    imdata->image = image;
     457    imdata->header = header;
     458    imdata->noise = noise;
     459    imdata->mask = mask;
     460
     461    p_psMemSetDeallocator(imdata, (psFreeFcn) psImageDataFree);
     462    return (imdata);
     463}
     464 
  • trunk/psphot/src/psphot.c

    r4641 r4901  
    1414    // load input data (image and config)
    1515    // create or load mask and noise images
     16    // we have memory leaks here -- may be from psMetadata
    1617    imdata = setup (config);
    1718
  • trunk/psphot/src/psphot.h

    r4630 r4901  
    3131} pmPSF_Test;
    3232
     33// structure to carry a dynamic string
     34typedef struct {
     35  int NLINE;
     36  int Nline;
     37  char *line;
     38} psLine;
     39
    3340// used by mask operations
    3441# define AND true
    3542# define OR false
    3643
     44# define psMemCopy(A)(psMemIncrRefCounter((A)))
    3745
    3846// top-level psphot functions
     
    7179bool DumpImage (psImage *image, char *filename);
    7280bool DumpPSFTestData (pmPSF_Test *test, char *filename);
     81void output (psImageData *imdata, psMetadata *config, psArray *sources);
     82bool WriteSourcesText (psImageData *imdata, psMetadata *config, psArray *sources);
     83bool WriteSourcesOBJ (psImageData *imdata, psMetadata *config, psArray *sources);
     84bool WriteSourcesSX (psImageData *imdata, psMetadata *config, psArray *sources);
     85bool WriteSourcesCMP (psImageData *imdata, psMetadata *config, psArray *sources);
     86bool WriteSourcesCMF (psImageData *imdata, psMetadata *config, psArray *sources);
     87bool init_line (char *line, int *Nline);
     88bool add_to_line (char *line, int *Nline, char *format, ...);
    7389
    7490// psphot utilities
     
    86102psBool psMinimizeLMChi2_EAM(psMinimization *min, psImage *covar, psVector *params, const psVector *paramMask, const psArray *x, const psVector *y, const psVector *yErr, psMinimizeLMChi2Func func);
    87103psF64 p_psMinLM_dLinear (const psVector *Beta, const psVector *beta, psF64 lambda);
     104psImageData *psImageDataAlloc (psImage *image, psImage *noise, psImage *mask, psMetadata *header);
    88105
    89106// fitsource utilities
     
    110127// utilities
    111128bool psTimerStart (char *name);
     129void psTimerFree ();
     130bool psTimerClear (char *name);
    112131psF64 psTimerMark (char *name);
    113132psS32 psLogArguments (int *argc, char **argv);
     
    117136psF32 pmConfigLookupF32 (bool *status, psMetadata *config, psMetadata *header, char *name);
    118137psVector *psVectorCreate (double lower, double upper, double delta, psElemType type);
     138
     139// psLine functions
     140psLine *psLineAlloc (int Nline);
     141bool psLineInit (psLine *line);
     142bool psLineAdd (psLine *line, char *format, ...);
    119143
    120144// polynomial functions
  • trunk/psphot/src/pspsf.c

    r4642 r4901  
    11# include "psphot.h"
     2
     3static void pmPSFFree (pmPSF *psf) {
     4
     5  if (psf == NULL) return;
     6
     7  psFree (psf->params);
     8  return;
     9}
    210
    311// a PSF always has 4 parameters fewer than the equivalent model
     
    1624        return(NULL);
    1725    }     
     26
    1827    psf->params = psArrayAlloc (Nparams - 4);
    1928    for (int i = 0; i < psf->params->n; i++) {
     
    2130        psf->params->data[i] = Polynomial2DAlloc(1, 1, PS_POLYNOMIAL_ORD);
    2231    }
    23     // set the destructors
     32
     33    p_psMemSetDeallocator(psf, (psFreeFcn) pmPSFFree);
    2434    return(psf);
     35}
     36
     37static void pmPSF_TestFree (pmPSF_Test *test) {
     38
     39  if (test == NULL) return;
     40
     41  psFree (test->psf);
     42  psFree (test->sources);
     43  psFree (test->modelFLT);
     44  psFree (test->modelPSF);
     45  psFree (test->metric);
     46  psFree (test->fitMag);
     47  psFree (test->mask);
     48  return;
    2549}
    2650
     
    3256    test->modelType   = psModelSetType (modelName);
    3357    test->psf         = pmPSFAlloc (test->modelType);
    34     test->sources     = sources;
     58    test->sources     = psMemCopy(sources);
    3559    test->modelFLT    = psArrayAlloc (sources->n);
    3660    test->modelPSF    = psArrayAlloc (sources->n);
     
    4973        test->fitMag->data.F64[i] = 0;
    5074    }   
    51     // set the destructors
    52 
     75
     76    p_psMemSetDeallocator(test, (psFreeFcn) pmPSF_TestFree);
    5377    return (test);
    5478}
     
    7498    psTimerStart ("fit");
    7599    for (int i = 0; i < test->sources->n; i++) {
     100
    76101        psSource *source = test->sources->data[i];
    77102        psModel  *model  = pmSourceModelGuess (source, test->modelType);
     
    88113        if (!status) {
    89114          test->mask->data.U8[i] = 2;
     115          psFree (model);
    90116          continue;
    91117        }
     
    122148        if (!status) {
    123149            test->mask->data.U8[i] = 3;
     150            psFree (modelPSF);
    124151            goto next_source;
    125152        }
     
    154181    psLogMsg ("psphot.pspsf", 3, "test model %s, ap-fit: %f +/- %f, sky bias: %f\n",
    155182              modelName, test->ApResid, test->dApResid, test->skyBias);
     183
    156184    return (test);
    157185}
     
    223251  float dBin;
    224252  int   nKeep, nSkip;
    225  
    226253
    227254  // the measured (aperture - fit) magnitudes (dA == test->metric)
     
    280307    if (tmp->n < 2) {
    281308      maskB->data.U8[i] = 1;
     309      psFree (tmp);
    282310      continue;
    283311    }
     
    327355  test->skyBias = poly->coeff[1] / (M_PI * PS_SQR(RADIUS));
    328356
    329   psFree (maskB);
     357  psFree (rflux);
    330358  psFree (rfBin);
    331359  psFree (daBin);
     360  psFree (maskB);
    332361  psFree (daBinFit);
    333362  psFree (daResid);
  • trunk/psphot/src/setup.c

    r4642 r4901  
    2929    image = psFitsReadImage (NULL, file, region, 0);
    3030    psFree (file);
     31    // psFree (input);
     32    // XXX - does the current API expect to get a copy or a view?
    3133
    3234    // grab these values from the approrpiate location (image header if necessary)
     
    4244      noise = psFitsReadImage  (NULL, file, region, 0);
    4345      psFree (file);
     46      // psFree (noiseName); XXX - see psFree (input)
    4447    } else {
    4548
     
    7376      mask  = psFitsReadImage  (NULL, file, region, 0);
    7477      psFree (file);
     78      // psFree (maskName); XXX - see psFree (input)
    7579      // XXX require / convert mask to psU8?
    7680    } else {
     
    96100        }
    97101    }
     102
    98103    psLogMsg ("psphot", 3, "load data: %f sec\n", psTimerMark ("psphot"));
    99104
    100105    // save the image data & return it
    101     psImageData *imdata = psAlloc(sizeof(psImageData));
    102     imdata->image = image;
    103     imdata->header = header;
    104     imdata->noise = noise;
    105     imdata->mask = mask;
    106 
     106    psImageData *imdata = psImageDataAlloc(image, noise, mask, header);
    107107    return (imdata);
    108108}
  • trunk/psphot/src/source_moments.c

    r4574 r4901  
    55    bool     status  = false;
    66    psArray *sources = NULL;
     7
     8    psMemoryId id = psMemGetId ();
    79
    810    psTimerStart ("psphot");
     
    1719
    1820    for (int i = 0; i < peaks->n; i++) {
     21
    1922        // create a new source, add peak
    2023        psSource *source = pmSourceAlloc();
    21         source->peak = (psPeak *)peaks->data[i];
     24        source->peak = (psPeak *)psMemCopy(peaks->data[i]);
    2225
    2326        // allocate image, noise, mask arrays for each peak (square of radius OUTER)
     27        // XXX - this has 12 leaks (v.5)
    2428        pmSourceDefinePixels (source, imdata, source->peak->x, source->peak->y, OUTER);
    2529
    2630        // this should use ROBUST not SAMPLE median, but it is broken
    2731        status = pmSourceLocalSky_EAM (source, PS_STAT_SAMPLE_MEDIAN, INNER);
    28         if (!status) continue;
     32        if (!status) {
     33          psFree (source);
     34          continue;
     35        }
    2936
    3037        status = pmSourceMoments (source, RADIUS);
    31         if (!status) continue;
     38        if (!status) {
     39          psFree (source);
     40          continue;
     41        }
    3242       
    3343        psArrayAdd (sources, 100, source);
     44        psFree (source);
    3445    }
    3546
Note: See TracChangeset for help on using the changeset viewer.