IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6311


Ignore:
Timestamp:
Feb 2, 2006, 1:30:35 PM (20 years ago)
Author:
eugene
Message:

updated to use new image/subimage/region coordinate consistency

Location:
trunk/psphot/src
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/Makefile.am

    r6141 r6311  
    1 lib_LTLIBRARIES = libpsphot.la
    2 bin_PROGRAMS = psphot psphotTest
     1# lib_LTLIBRARIES = libpsphot.la
     2# libpsphot_la_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(psphot_CFLAGS)
     3# libpsphot_la_LDFLAGS = $(PSMODULE_LIBS) $(PSLIB_LIBS)
    34
    4 libpsphot_la_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(psphot_CFLAGS)
    5 libpsphot_la_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS)
     5bin_PROGRAMS = psphot
     6psphot_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(psphot_CFLAGS)
     7psphot_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS)
    68
    7 psphot_CPPFLAGS = $(libpsphot_la_CPPFLAGS)
    8 psphot_LDADD = libpsphot.la
     9# psphot_CPPFLAGS = $(libpsphot_la_CPPFLAGS)
     10# psphot_LDFLAGS =  $(PSMODULE_LIBS) $(PSLIB_LIBS)
     11# psphot_LDADD = libpsphot.la
    912
    10 psphotTest_CPPFLAGS = $(libpsphot_la_CPPFLAGS)
    11 psphotTest_LDADD = libpsphot.la
    12 
    13 
    14 libpsphot_la_SOURCES =          \
     13psphot_SOURCES =                \
    1514        psphotReadout.c         \
    1615        psphotImageStats.c      \
     
    4645        pmModelFitSet.c         \
    4746        pmCellSetMask.c         \
    48         pmSourceFitSet.c     
    49 
    50 
    51 psphot_SOURCES =                \
     47        pmSourceFitSet.c        \
    5248        psphot.c                \
    5349        psphotArguments.c       \
    5450        psphotParseCamera.c     \
    55         psphotImageLoop.c       \
    56         psphotModelTest.c
     51        psphotModelTest.c       \
     52        psphotImageLoop.c       
    5753
    58 psphotTest_SOURCES =            \
    59         psphotTest.c            \
    60         psImageJpeg.c           \
    61         psphotTestArguments.c
    62 
    63 include_HEADERS =               \
     54noinst_HEADERS =                \
    6455        psLibUtils.h            \
    6556        psModulesUtils.h        \
  • trunk/psphot/src/pmCellSetMask.c

    r6117 r6311  
    66
    77    // mask the excluded outer pixels
     8    // these coordinates refer to the parent image
     9    // these bounds will saturate on the subimage
     10    // negative upper bounds will subtract from the *subimage*
    811    float XMIN  = psMetadataLookupF32 (&status, recipe, "XMIN");
    912    float XMAX  = psMetadataLookupF32 (&status, recipe, "XMAX");
     
    1720        pmReadout *readout = readouts->data[i]; // The readout of interest
    1821
     22        // psRegionForImage creates a region for the subimage, not the parent
     23        // XXX I propose that psRegionForImage treat the region as referring to the parent...
    1924        psRegion keep = psRegionForImage (readout->image, valid);
     25
     26        // psImageKeepRegion assumes the region refers to the parent coordinates
    2027        psImageKeepRegion (readout->mask, keep, "OR", PSPHOT_MASK_INVALID);
    2128    }
  • trunk/psphot/src/psLibUtils.h

    r5607 r6311  
    1414bool         psLineInit (psLine *line);
    1515bool         psLineAdd (psLine *line, char *format, ...);
     16int          psStringStrip (char *string);
    1617
    1718# endif
  • trunk/psphot/src/psLine.c

    r5980 r6311  
    4747}
    4848
     49#ifndef whitespace
     50#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
     51#endif
     52
     53/* Strip whitespace from the start and end of STRING. */
     54int psStringStrip (char *string) {
     55
     56  int i;
     57
     58  if (string == (char *) NULL) return (FALSE);
     59
     60  for (i = 0; whitespace (string[i]); i++);
     61  if (i) memmove (string, string + i, strlen(string+i)+1);
     62  for (i = strlen (string) - 1; (i > 0) && whitespace (string[i]); i--);
     63  string[++i] = 0;
     64  return (i);
     65
     66}
  • trunk/psphot/src/psModulesUtils.c

    r6117 r6311  
    193193  config->recipe = NULL;
    194194  config->arguments = NULL;
     195  config->options = NULL;
    195196  config->database = NULL;
    196197
  • trunk/psphot/src/psModulesUtils.h

    r6117 r6311  
    2222    psMetadata *camera;                 // The camera configuration
    2323    psMetadata *recipe;                 // The recipe (i.e., specific setups)
    24     psMetadata *arguments;              // The command-line arguments
     24    psMetadata *arguments;              // Command-line arguments
     25    psMetadata *options;                // Command-line recipe options
    2526    psDB       *database;               // Database handle
    2627} ppConfig;
  • trunk/psphot/src/psphot.c

    r6117 r6311  
    1515    ppFile *input = psphotParseCamera (config);
    1616
    17     // run a single-model test if desired - XXX push in psphotImageLoop?
    18     // psphotModelTest (input, options);
     17    // check on output mode,format, setup basic filename, etc
     18    psphotOutputPrep (input, config);
    1919
    2020    // call psphot for each readout
  • trunk/psphot/src/psphot.h

    r6117 r6311  
    2424bool            psphotImageLoop (ppFile *input, ppConfig *config);
    2525
    26 bool            psphotModelTest (pmReadout *readout, psMetadata *config);
     26bool            psphotModelTest (pmReadout *readout, psMetadata *arguments, psMetadata *recipe);
    2727bool            psphotReadout (pmReadout *readout, psMetadata *config);
    2828bool            ppImageLoadPixels (ppFile *input, psDB *db, int chipNum, int cellNum);
     
    3636bool            psphotBasicDeblend (psArray *sources, psMetadata *config, psStats *sky);
    3737pmPSF          *psphotChoosePSF (psMetadata *config, psArray *sources, psStats *sky);
    38 void            psphotOutput (pmReadout *readout, psMetadata *config);
     38void            psphotOutput (pmReadout *readout, psMetadata *arguments);
    3939
    4040// optional object analysis steps
     
    8080bool            pmMomentsWriteText (psArray *sources, char *filename);
    8181
    82 bool            psphotSamplePSFs (psMetadata *config, pmPSF *psf, psImage *image);
     82bool            psphotSamplePSFs (pmPSF *psf, psImage *image, char *output);
    8383bool            psphotDumpMoments (psMetadata *config, psArray *sources);
    8484int             psphotSaveImage (psMetadata *header, psImage *image, char *filename);
     
    8686int             pmSourcesDophotType (pmSource *source);
    8787bool            psMetadataItemTransfer (psMetadata *out, psMetadata *in, char *key);
     88
     89char           *psphotSplitName (psMetadata *header);
     90void            psphotOutputPrep (ppFile *file, ppConfig *config);
     91char           *psphotNameSubstitute (char *input, char *replace, char *key);
    8892
    8993bool            psphotMagnitudes (psMetadata *config, psArray *sources, pmPSF *psf);
  • trunk/psphot/src/psphotArguments.c

    r6117 r6311  
    11# include "psphot.h"
    22
    3 static void usage (psMetadata *arguments) ;
     3static void usage (void);
    44
    55ppConfig *psphotArguments (int *argc, char **argv) {
    66
    77    int N;
     8
     9    if (*argc == 1) usage ();
    810
    911    // basic pslib options
     
    2224
    2325    // arguments (must be supplied for each run, or not used)
    24     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-psf", 0, "input psf file", "");
    25     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-mask", 0,   "Name of the mask image", "");
    26     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-resid", 0,  "Name of the output residual image", "");
    27     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-weight", 0, "Name of the weight image", "");
    28     psMetadataAddS32(config->arguments, PS_LIST_TAIL, "-chip", 0, "Chip number to process (if positive)", -1);
    29    
     26    // mask image (input) is used by psphotImageLoop
     27    if ((N = psArgumentGet (*argc, argv, "-mask"))) {
     28        psArgumentRemove (N, argc, argv);
     29        psMetadataAddStr (config->arguments, PS_LIST_TAIL, "MASK_IMAGE", PS_META_REPLACE, "", psStringCopy(argv[N]));
     30        psArgumentRemove (N, argc, argv);
     31    }
     32
     33    // weight image (input) is used by psphotImageLoop
     34    if ((N = psArgumentGet (*argc, argv, "-weight"))) {
     35        psArgumentRemove (N, argc, argv);
     36        psMetadataAddStr (config->arguments, PS_LIST_TAIL, "WEIGHT_IMAGE", PS_META_REPLACE, "", psStringCopy(argv[N]));
     37        psArgumentRemove (N, argc, argv);
     38    }
     39
     40    // residual image (output) is used by psphotOutput
     41    if ((N = psArgumentGet (*argc, argv, "-resid"))) {
     42        psArgumentRemove (N, argc, argv);
     43        psMetadataAddStr (config->arguments, PS_LIST_TAIL, "RESID_IMAGE", PS_META_REPLACE, "", psStringCopy(argv[N]));
     44        psArgumentRemove (N, argc, argv);
     45    }
     46
     47    // chip selection is used to limit chips to be processed
     48    if ((N = psArgumentGet (*argc, argv, "-chip"))) {
     49        psArgumentRemove (N, argc, argv);
     50        psMetadataAddStr (config->arguments, PS_LIST_TAIL, "CHIP_SELECTION", PS_META_REPLACE, "", psStringCopy(argv[N]));
     51        psArgumentRemove (N, argc, argv);
     52    }
     53
    3054    // run the test model (requires X,Y coordinate)
    3155    if ((N = psArgumentGet (*argc, argv, "-modeltest"))) {
     
    5882    }
    5983
    60     // Parse command-line overrides of recipe values
    61     psMetadata *recipe = psMetadataAlloc ();
     84    // these other options override the recipe options
     85    config->options = psMetadataAlloc ();
    6286
    63     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-photcode", 0, "photometry code", "NONE");
    64     psMetadataAddStr (config->arguments, PS_LIST_TAIL, "-break", 0, "", "NONE");
    65     psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "-fitmode", 0, "", 2);
    66 
    67     // analysis region : XXX override recipe
    68     if ((N = psArgumentGet (*argc, argv, "-photcode"))) {
     87    // PSF : optional psf file to be loaded
     88    if ((N = psArgumentGet (*argc, argv, "-psf"))) {
    6989        psArgumentRemove (N, argc, argv);
    70         psMetadataAddStr (recipe, PS_LIST_TAIL, "PHOTCODE", PS_META_REPLACE, "", psStringCopy(argv[N]));
     90        psMetadataAddStr (config->options, PS_LIST_TAIL, "PSF_INPUT_FILE", PS_META_REPLACE, "", psStringCopy(argv[N]));
    7191        psArgumentRemove (N, argc, argv);
    7292    }
    7393
    74     // analysis region : XXX override recipe
    75     if ((N = psArgumentGet (*argc, argv, "-break"))) {
     94    // photcode : used in output to supplement header data (argument or recipe?)
     95    if ((N = psArgumentGet (*argc, argv, "-photcode"))) {
    7696        psArgumentRemove (N, argc, argv);
    77         psMetadataAddStr (recipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", psStringCopy(argv[N]));
     97        psMetadataAddStr (config->options, PS_LIST_TAIL, "PHOTCODE", PS_META_REPLACE, "", psStringCopy(argv[N]));
    7898        psArgumentRemove (N, argc, argv);
    7999    }
    80100
    81     // analysis region : XXX override recipe
    82     if ((N = psArgumentGet (*argc, argv, "-fitmode"))) {
     101    // break : used from recipe throughout psphotReadout
     102    if ((N = psArgumentGet (*argc, argv, "-break"))) {
    83103        psArgumentRemove (N, argc, argv);
    84         psMetadataAddStr (recipe, PS_LIST_TAIL, "FITMODE", PS_META_REPLACE, "", psStringCopy(argv[N]));
     104        psMetadataAddStr (config->options, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", psStringCopy(argv[N]));
    85105        psArgumentRemove (N, argc, argv);
    86106    }
    87107
    88     // analysis region : XXX override recipe
     108    // fitmode : used from recipe throughout psphotReadout
     109    if ((N = psArgumentGet (*argc, argv, "-fitmode"))) {
     110        psArgumentRemove (N, argc, argv);
     111        psMetadataAddStr (config->options, PS_LIST_TAIL, "FITMODE", PS_META_REPLACE, "", psStringCopy(argv[N]));
     112        psArgumentRemove (N, argc, argv);
     113    }
     114
     115    // analysis region : overrides recipe value, used in psphotReadout/psphotEnsemblePSF
    89116    if ((N = psArgumentGet (*argc, argv, "-region"))) {
    90117        psArgumentRemove (N, argc, argv);
    91         psMetadataAddStr (recipe, PS_LIST_TAIL, "ANALYSIS_REGION", 0, "", psStringCopy(argv[N]));
     118        psMetadataAddStr (config->options, PS_LIST_TAIL, "ANALYSIS_REGION", 0, "", psStringCopy(argv[N]));
    92119        psArgumentRemove (N, argc, argv);
    93120    }
     
    96123    while ((N = psArgumentGet (*argc, argv, "-D"))) {
    97124        psArgumentRemove (N, argc, argv);
    98         psMetadataAddStr (recipe, PS_LIST_TAIL, argv[N], 0, "", argv[N+1]);
     125        psMetadataAddStr (config->options, PS_LIST_TAIL, argv[N], 0, "", argv[N+1]);
    99126        psArgumentRemove (N, argc, argv);
    100127        psArgumentRemove (N, argc, argv);
     
    104131    while ((N = psArgumentGet (*argc, argv, "-Df"))) {
    105132        psArgumentRemove (N, argc, argv);
    106         psMetadataAddF32 (recipe, PS_LIST_TAIL, argv[N], 0, "", atof(argv[N+1]));
     133        psMetadataAddF32 (config->options, PS_LIST_TAIL, argv[N], 0, "", atof(argv[N+1]));
    107134        psArgumentRemove (N, argc, argv);
    108135        psArgumentRemove (N, argc, argv);
     
    112139    while ((N = psArgumentGet (*argc, argv, "-Di"))) {
    113140        psArgumentRemove (N, argc, argv);
    114         psMetadataAddS32 (recipe, PS_LIST_TAIL, argv[N], 0, "", atoi(argv[N+1]));
     141        psMetadataAddS32 (config->options, PS_LIST_TAIL, argv[N], 0, "", atoi(argv[N+1]));
    115142        psArgumentRemove (N, argc, argv);
    116143        psArgumentRemove (N, argc, argv);
    117144    }
    118145
    119     // place the recipe options on the arguments stack
    120     psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "RECIPE.OPTIONS", PS_DATA_UNKNOWN, "", recipe);
    121 
    122     if (!psArgumentParse(config->arguments, argc, argv)) usage (config->arguments);
    123     if (*argc != 3) usage (config->arguments);
     146    if (*argc != 3) usage ();
    124147
    125148    // input and output positions are fixed
    126     psMetadataAddStr (config->arguments, PS_LIST_TAIL, "-input",  PS_META_REPLACE, "", argv[1]);
    127     psMetadataAddStr (config->arguments, PS_LIST_TAIL, "-output", PS_META_REPLACE, "", argv[2]);
     149    psMetadataAddStr (config->arguments, PS_LIST_TAIL, "INPUT_FILE",  PS_META_REPLACE, "", argv[1]);
     150    psMetadataAddStr (config->arguments, PS_LIST_TAIL, "OUTPUT_ROOT", PS_META_REPLACE, "", argv[2]);
    128151
     152    psTrace(__func__, 1, "Done with psphotArguments...\n");
    129153    return (config);
    130154}
    131155
    132 static void usage (psMetadata *arguments) {
     156static void usage (void) {
    133157
    134158    fprintf (stderr, "USAGE: psphot (image) (output)\n");
    135     psArgumentHelp (arguments);
    136159    exit (2);
    137160}
  • trunk/psphot/src/psphotDefinePixels.c

    r6056 r6311  
    11# include "psphot.h"
    22
     3// x,y are defined in the parent image coords of readout->image
    34bool psphotDefinePixels(pmSource *mySource,
    45                        const pmReadout *readout,
  • trunk/psphot/src/psphotFindPeaks.c

    r6056 r6311  
    1616
    1717    psImage *smooth = psImageCopy (NULL, readout->image, PS_TYPE_F32);
     18    psphotSaveImage (NULL, smooth, "presmooth.fits");
     19
    1820    psImageSmooth (smooth, SIGMA, NSIGMA);
    1921    psLogMsg ("psphot", 4, "smooth: %f sec\n", psTimerMark ("psphot"));
     22
     23    psphotSaveImage (NULL, smooth, "smooth.fits");
    2024
    2125    psTimerStart ("psphot");
  • trunk/psphot/src/psphotGrowthCurve.c

    r6056 r6311  
    1515    pmModel *modelRef = pmModelAlloc(psf->type);
    1616
    17     // use this image region
    18     xc = 0.5*readout->image->numCols;
    19     yc = 0.5*readout->image->numRows;
     17    // use center of the image
     18    xc = 0.5*(readout->image->numCols + readout->image->col0);
     19    yc = 0.5*(readout->image->numRows + readout->image->row0);
    2020    dx = psf->growth->maxRadius + 1;
    2121    dy = psf->growth->maxRadius + 1;
  • trunk/psphot/src/psphotImageBackground.c

    r6056 r6311  
    2828        double frnd = psRandomUniform (rnd);
    2929        int pixel = Npixels * frnd;
    30         int ix = pixel / image->numCols;
    31         int iy = pixel % image->numCols;
     30        int ix = pixel % image->numCols;
     31        int iy = pixel / image->numCols;
    3232        float value = image->data.F32[iy][ix];
    3333        if (fabs(value - Sky) > dSky) continue;
  • trunk/psphot/src/psphotImageLoop.c

    r6117 r6311  
    55    bool status;
    66    ppImageLoadDepth imageLoadDepth;
    7     char filename[1024];
    87
    98    // determine the load depth
     
    2726    }
    2827
    29     char *outputRoot = psMetadataLookupPtr (&status, config->arguments, "-output");
    30     if (!status) psAbort ("psphot", "output file not specified");
    31 
    32     int Nout = 0;
    3328    for (int i = 0; i < file->fpa->chips->n; i++) {
    3429        pmChip *chip = file->fpa->chips->data[i]; // Chip of interest in input image
     
    5348            }
    5449
     50            // XXX optional mask and weight input image should be loaded here?
     51            // this sets the weight map and basic mask applying CELL.BAD and CELL.SATURATION
    5552            pmCellSetWeights(cell);
    5653
     
    5855            pmCellSetMask (cell, config->recipe);
    5956
    60 
    6157            // process each of the readouts
    6258            for (int k = 0; k < cell->readouts->n; k++) {
    6359                pmReadout *readout = cell->readouts->data[k]; // Readout of interest in input image
    6460
    65                 // psphotSaveImage (NULL, readout->image, "image.fits");
    66                 // psphotSaveImage (NULL, readout->weight, "weight.fits");
    67                 // psphotSaveImage (NULL, readout->mask, "mask.fits");
     61                // run a single-model test if desired
     62                psphotModelTest (readout, config->arguments, config->recipe);
    6863
    6964                psphotReadout (readout, config->recipe);
    70 
    71                 // XXX EAM : temporarily write out only CMF with fixed extension
    72                 sprintf (filename, "%s.%02d.cmf", outputRoot, Nout);
    73                 psMetadata *header = pmReadoutGetHeader (readout);
    74 
    75                 psArray *sources = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.SOURCES");
    76 
    77                 pmSourcesWriteCMF (sources, filename, header);
    78                 Nout++;
     65                psphotOutput (readout, config->arguments);
    7966            }
    8067        }
  • trunk/psphot/src/psphotModelTest.c

    r6056 r6311  
    22# include "psEllipse.h"
    33
    4 bool psphotModelTest (pmReadout *readout, psMetadata *config) {
     4bool psphotModelTest (pmReadout *readout, psMetadata *arguments, psMetadata *recipe) {
    55
    66    bool status;
     
    1414
    1515    // run model fitting tests on a single source
    16     if (!psMetadataLookupBool (&status, config, "TEST_FIT")) return false;
     16    if (!psMetadataLookupBool (&status, arguments, "TEST_FIT")) return false;
    1717
    1818    // what fitting mode to use?
    19     char *psfModeWord = psMetadataLookupPtr (&status, config, "TEST_FIT_MODE");
     19    char *psfModeWord = psMetadataLookupPtr (&status, arguments, "TEST_FIT_MODE");
    2020    if (!status) {
    2121        psfModeWord = psStringCopy ("EXT");
     
    2525    // in psfMode, psf sets the model type
    2626    if (psfMode) {
    27         char *psfFile = psMetadataLookupPtr (&status, config, "PSF_INPUT_FILE");
     27        char *psfFile = psMetadataLookupPtr (&status, arguments, "PSF_INPUT_FILE");
    2828        if (!status) psAbort ("psphotModelTest", "PSF_INPUT_FILE not supplied");
    2929        psMetadata *psfData = psMetadataConfigParse (NULL, &Nfail, psfFile, FALSE);
     
    3232    } else {
    3333        // find the model: supplied by user or first in the PSF_MODEL list
    34         char *modelName  = psMetadataLookupPtr (&status, config, "TEST_FIT_MODEL");
     34        char *modelName  = psMetadataLookupPtr (&status, arguments, "TEST_FIT_MODEL");
    3535        if (modelName == NULL) {
    3636            // get the list pointers for the PSF_MODEL entries
    37             psMetadataItem *mdi = psMetadataLookup (config, "PSF_MODEL");
    38             if (mdi == NULL) psAbort ("psphotChoosePSF", "missing PSF_MODEL selection");
     37
     38            psList *list = NULL;
     39            psMetadataItem *mdi = psMetadataLookup (recipe, "PSF_MODEL");
     40            if (mdi == NULL) psAbort ("psphotModelTest", "missing PSF_MODEL selection");
     41            if (mdi->type == PS_DATA_STRING) {
     42                list = psListAlloc(NULL);
     43                psListAdd (list, PS_LIST_HEAD, mdi);
     44            } else {
     45                if (mdi->type != PS_DATA_METADATA_MULTI) psAbort ("psphotChoosePSF", "missing PSF_MODEL selection");
     46                list = psMemIncrRefCounter(mdi->data.list);
     47            }
    3948
    4049            // take the first list element
    41             psList *list = (psList *) mdi->data.list;
    4250            item = psListGet (list, PS_LIST_HEAD);
    4351            modelName = item->data.V;
     
    4856
    4957    // find the fitting parameters (try test values first)
    50     float INNER = psMetadataLookupF32 (&status, config, "TEST_FIT_INNER_RADIUS");
     58    float INNER = psMetadataLookupF32 (&status, arguments, "TEST_FIT_INNER_RADIUS");
    5159    if (!status) {
    52         INNER = psMetadataLookupF32 (&status, config, "SKY_INNER_RADIUS");
     60        INNER = psMetadataLookupF32 (&status, recipe, "SKY_INNER_RADIUS");
    5361    }
    5462
    55     float OUTER = psMetadataLookupF32 (&status, config, "TEST_FIT_OUTER_RADIUS");
     63    float OUTER = psMetadataLookupF32 (&status, arguments, "TEST_FIT_OUTER_RADIUS");
    5664    if (!status) {
    57         OUTER = psMetadataLookupF32 (&status, config, "SKY_OUTER_RADIUS");
     65        OUTER = psMetadataLookupF32 (&status, recipe, "SKY_OUTER_RADIUS");
    5866    }
    5967
    60     float RADIUS = psMetadataLookupF32 (&status, config, "TEST_FIT_RADIUS");
     68    float RADIUS = psMetadataLookupF32 (&status, arguments, "TEST_FIT_RADIUS");
    6169    if (!status) {
    62         RADIUS = psMetadataLookupF32 (&status, config, "PSF_FIT_RADIUS");
     70        RADIUS = psMetadataLookupF32 (&status, recipe, "PSF_FIT_RADIUS");
    6371    }
    6472
    65     float mRADIUS = psMetadataLookupF32 (&status, config, "TEST_MOMENTS_RADIUS");
     73    float mRADIUS = psMetadataLookupF32 (&status, arguments, "TEST_MOMENTS_RADIUS");
    6674    if (!status) {
    67         mRADIUS = psMetadataLookupF32 (&status, config, "PSF_MOMENTS_RADIUS");
     75        mRADIUS = psMetadataLookupF32 (&status, recipe, "PSF_MOMENTS_RADIUS");
    6876    }
    6977
    7078    // define the source of interest
    71     float xObj     = psMetadataLookupF32 (&status, config, "TEST_FIT_X");
    72     float yObj     = psMetadataLookupF32 (&status, config, "TEST_FIT_Y");
     79    float xObj     = psMetadataLookupF32 (&status, arguments, "TEST_FIT_X");
     80    float yObj     = psMetadataLookupF32 (&status, arguments, "TEST_FIT_Y");
    7381
    7482    // construct the source structures
     
    111119        }
    112120        sprintf (name, "TEST_FIT_PAR%d", i);
    113         value = psMetadataLookupF32 (&status, config, name);
     121        value = psMetadataLookupF32 (&status, arguments, name);
    114122        if (status) {
    115123            params[i] = value;
     
    145153    psImageKeepCircle (source->mask, xObj, yObj, RADIUS, "OR", PSPHOT_MASK_MARKED);
    146154
    147     char *fitset = psMetadataLookupPtr (&status, config, "TEST_FIT_SET");
     155    char *fitset = psMetadataLookupPtr (&status, arguments, "TEST_FIT_SET");
    148156    if (status) {
    149157        status = psphotFitSet (source, model, fitset, psfMode);
  • trunk/psphot/src/psphotOutput.c

    r6117 r6311  
    11# include "psphot.h"
    22
     3static int   extNumber  = -1;
     4
     5static char *outputName = NULL;
     6static char *outputRoot = NULL;
     7static char *outputMode = NULL;
     8static char *outputFormat = NULL;
     9
     10static char *extNumberFormat = NULL;
     11static char *extNameKey = NULL;
     12static char *extRoot    = NULL;
     13
     14void psphotOutputPrep (ppFile *file, ppConfig *config) {
     15
     16    bool status;
     17
     18    outputRoot   = psMetadataLookupPtr (&status, config->arguments, "OUTPUT_ROOT");
     19    if (!status) psAbort ("psphot", "output file not specified");
     20
     21    outputName   = psMetadataLookupPtr (&status, config->recipe, "OUTPUT_NAME");
     22    outputMode   = psMetadataLookupPtr (&status, config->recipe, "OUTPUT_MODE");
     23    outputFormat = psMetadataLookupPtr (&status, config->recipe, "OUTPUT_FORMAT");
     24
     25    // rules to construct output names
     26    extNumberFormat = psMetadataLookupPtr (&status, config->recipe, "EXTNUMBER_FORMAT");
     27    extNameKey      = psMetadataLookupPtr (&status, config->recipe, "EXTNAME");
     28    extRoot         = psMetadataLookupPtr (&status, config->recipe, "EXTROOT");
     29
     30    if (extNumberFormat == NULL) {
     31        extNumberFormat = psStringCopy ("%02d");
     32    }
     33
     34    psStringStrip (outputName);
     35    psStringStrip (extNameKey);
     36    psStringStrip (extRoot);
     37
     38    // validate the outputMode and outputFormat
     39    status = false;
     40    status |= !strcasecmp (outputFormat, "TEXT");
     41    status |= !strcasecmp (outputFormat, "OBJ");
     42    status |= !strcasecmp (outputFormat, "SX");
     43    status |= !strcasecmp (outputFormat, "CMP");
     44    status |= !strcasecmp (outputFormat, "CMF");
     45    if (!status) {
     46        psLogMsg ("psphot", PS_LOG_ERROR, "invalid output format %s", outputFormat);
     47        exit (1);
     48    }
     49
     50    // validate the outputMode and outputFormat
     51    status = false;
     52    status |= !strcasecmp (outputMode, "MEF");
     53    status |= !strcasecmp (outputMode, "SPLIT");
     54    if (!status) {
     55        psLogMsg ("psphot", PS_LOG_ERROR, "invalid output mode %s", outputMode);
     56        exit (1);
     57    }
     58
     59    // for MEF output, we need to open a file up front
     60    if (!strcasecmp (outputMode, "MEF")) {
     61        psLogMsg ("psphot", PS_LOG_ERROR, "MEF output mode unavailable");
     62        exit (1);
     63    }
     64
     65    return;
     66}
     67
     68// generate the SPLIT filenames
     69char *psphotSplitName (psMetadata *header) {
     70
     71    bool status;
     72
     73    char *newName = NULL;     // destination for resulting name
     74    char *extNameWord = NULL; // this contains the per-extension word to add
     75    char  extNumberWord[16];  // this will store the string-formatted number
     76
     77    // extNumberFormat must be set to a valid entry in psphotOutputPrep
     78    sprintf (extNumberWord, extNumberFormat, extNumber);
     79
     80    // find the extname:
     81    char *extNameVal = psMetadataLookupPtr (&status, header, extNameKey);
     82           
     83    extNameWord = extNameVal;
     84    if ((extRoot != NULL) && (extNameVal != NULL)) {
     85        // check that the extNameVal matches the expected root
     86        if (strncmp (extNameVal, extRoot, strlen(extRoot))) {
     87            psLogMsg ("psphotSplitName", PS_LOG_WARN, "header entry does not match expected format");
     88        }
     89        extNameWord = extNameVal + strlen(extRoot);
     90    }
     91
     92    if (extNameWord != NULL) {
     93        psStringStrip (extNameWord);
     94    }
     95
     96    // note : if the user mis-specifies the output name, we will happily overwrite files
     97    newName = psStringCopy (outputName);
     98    newName = psphotNameSubstitute (newName, outputRoot, "%r");
     99    newName = psphotNameSubstitute (newName, extNameWord, "%x");
     100    newName = psphotNameSubstitute (newName, extNumberWord, "%n");
     101
     102    return newName;
     103}
     104
     105
     106// given the input string, search for the key, and replace with the replacement
     107// the input string may be freed if not needed
     108char *psphotNameSubstitute (char *input, char *replace, char *key) {
     109
     110    char *p;
     111
     112    if (key == NULL) return input;
     113    if (strlen(key) == 0) return input;
     114
     115    p = strstr (input, key);
     116    if (p == NULL) return input;
     117
     118    // we have input = xxxkeyxxx
     119    // we want output = xxxreplacexxx
     120
     121    // this is safe since we will subtract strlen(key) elements from input
     122    char *output = psAlloc(strlen(input) + strlen(replace) + 1);
     123    int Nc = p - input;
     124
     125    // copy the first segement into 'output'
     126    strncpy (output, input, Nc);
     127
     128    // copy the key replacement to the start of the key
     129
     130    strcpy (&output[Nc], replace);
     131    Nc += strlen (replace);
     132   
     133    // copy the remainder to the end of the replacement
     134    strcpy (&output[Nc], p + strlen(key));
     135
     136    psFree (input);
     137    return output;
     138}
     139
    3140// output functions: we have several fixed modes (sx, obj, cmp)
    4 void psphotOutput (pmReadout *readout, psMetadata *config) {
     141void psphotOutput (pmReadout *readout, psMetadata *arguments) {
    5142
    6143    bool status;
     144    char *outputFile;
    7145
    8146    psTimerStart ("psphot");
     
    13151    pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
    14152
    15     char *outputMode = psMetadataLookupPtr (&status, config, "OUTPUT_MODE");
    16     char *outputFile = psMetadataLookupPtr (&status, config, "OUTPUT_FILE");
    17     char *residImage = psMetadataLookupPtr (&status, config, "RESID_IMAGE");
    18     char *psfFile    = psMetadataLookupPtr (&status, config, "PSF_OUTPUT_FILE");
    19 
     153    // starting value is -1
     154    extNumber ++;
     155
     156    // for SPLIT output, we need to open a file for each output call
     157    if (!strcasecmp (outputMode, "SPLIT")) {
     158        outputFile = psphotSplitName (header);
     159    } else {
     160        // construct appropriate extname
     161        psAbort ("psphotOutput", "programming error");
     162    }
     163   
     164    fprintf (stderr, "output file: %s\n", outputFile);
     165    return;
     166
     167    char *psfFile    = psMetadataLookupPtr (&status, arguments, "PSF_OUTPUT_FILE");
     168    char *psfSample  = psMetadataLookupPtr (&status, arguments, "PSF_SAMPLE_FILE");
     169    char *residImage = psMetadataLookupPtr (&status, arguments, "RESID_IMAGE");
     170
     171    if (psfSample != NULL) psphotSamplePSFs (psf, readout->image, psfSample);
    20172    if (residImage != NULL) psphotSaveImage (header, readout->image, residImage);
    21     psphotSamplePSFs (config, psf, readout->image);
    22173
    23174    if (psfFile != NULL) {
     
    30181        return;
    31182    }
    32     if (outputMode == NULL) {
    33         psLogMsg ("output", 3, "no data output mode selected");
     183    if (outputFormat == NULL) {
     184        psLogMsg ("output", 3, "no data output format selected");
    34185        return;
    35186    }
    36     if (!strcasecmp (outputMode, "SX")) {
     187    if (!strcasecmp (outputFormat, "SX")) {
    37188        pmSourcesWriteSX (sources, outputFile);
    38189        return;
    39190    }
    40     if (!strcasecmp (outputMode, "OBJ")) {
     191    if (!strcasecmp (outputFormat, "OBJ")) {
    41192        pmSourcesWriteOBJ (sources, outputFile);
    42193        return;
    43194    }
    44     if (!strcasecmp (outputMode, "CMP")) {
     195    if (!strcasecmp (outputFormat, "CMP")) {
    45196        pmSourcesWriteCMP (sources, outputFile, header);
    46197        return;
    47198    }
    48     if (!strcasecmp (outputMode, "CMF")) {
     199    if (!strcasecmp (outputFormat, "CMF")) {
    49200        pmSourcesWriteCMF (sources, outputFile, header);
    50201        return;
    51202    }
    52     if (!strcasecmp (outputMode, "TEXT")) {
     203    if (!strcasecmp (outputFormat, "TEXT")) {
    53204        pmSourcesWriteText (sources, outputFile);
    54205        return;
    55206    }
    56207
    57     psAbort ("psphot", "unknown output mode %s", outputMode);
     208    psAbort ("psphot", "unknown output mode %s", outputFormat);
    58209}
    59210
     
    560711}
    561712
    562 
    563 bool psphotSamplePSFs (psMetadata *config, pmPSF *psf, psImage *image) {
    564 
    565     bool status;
     713bool psphotSamplePSFs (pmPSF *psf, psImage *image, char *output) {
    566714
    567715    // make sample PSFs for 4 corners and the center
     
    569717
    570718    // optional dump of all rough source data
    571     char *output = psMetadataLookupPtr (&status, config, "PSF_SAMPLE_FILE");
    572     if (!status) return false;
    573     if (output == NULL) return false;
    574719    if (output[0] == 0) return false;
    575720
     
    580725    psFits *fits = psFitsOpen (output, "w");
    581726
     727    // the centers are in parent coordinates; they do not need to correspond to valid pixels...
    582728    sample = pmModelPSFatXY (image, modelEXT, psf, 25, 25, 25, 25);
    583729    psFitsWriteImage (fits, NULL, sample, 0);
  • trunk/psphot/src/psphotParseCamera.c

    r6117 r6311  
    11# include "psphot.h"
     2
     3# define METADATA_ADD_DEFAULT(CONFIG, TYPE, NAME, VALUE, COMMENT)\
     4    { psMetadataItem *ITEM; \
     5      ITEM = psMetadataLookup (CONFIG, NAME); \
     6      if (ITEM == NULL) { \
     7        psMetadataAdd##TYPE (CONFIG, PS_LIST_TAIL, NAME, 0, COMMENT, VALUE); \
     8      } else { psFree (ITEM); } }
    29
    310ppFile *psphotParseCamera (ppConfig *config) {
    411
    5     bool status;
    6 
    712    ppFile *input = ppFileAlloc ();
    813
    9     input->filename = psMemIncrRefCounter(psMetadataLookupStr(NULL, config->arguments, "-input"));
     14    input->filename = psMemIncrRefCounter(psMetadataLookupStr(NULL, config->arguments, "INPUT_FILE"));
    1015
    1116    // Open the input image
     
    3338    }
    3439
    35     // Determine the correct recipe to use
    36     // if the user specifies a recipe, no default values are supplied
     40    // Determine the correct recipe to use (from camera or from user)
     41    // if config->recipe is not NULL, it is a user-supplied recipe
    3742    if (!config->recipe) {
    38 
    3943        config->recipe = pmConfigRecipeFromCamera(config->camera, PSPHOT_RECIPE);
    4044        if (config->recipe == NULL) {
     
    4347        }
    4448    }
    45    
    46     // recipe override values:
    47     psMetadata *recipe = psMetadataLookupPtr (&status, config->arguments, "RECIPE.OPTIONS");
     49
     50    // recipe override values (command-line options):
    4851    psMetadataItem *item = NULL;
    49     psMetadataIterator *iter = psMetadataIteratorAlloc (recipe, PS_LIST_HEAD, NULL);
     52    psMetadataIterator *iter = psMetadataIteratorAlloc (config->options, PS_LIST_HEAD, NULL);
    5053    while ((item = psMetadataGetAndIncrement (iter)) != NULL) {
    5154        psMetadataAddItem (config->recipe, item, PS_LIST_TAIL, PS_META_REPLACE);
     
    5457    psFree (iter);
    5558
    56     psMetadataAddStr (config->recipe, PS_LIST_TAIL, "FITMODE", 0, "", "NONE");
    57     psMetadataAddStr (config->recipe, PS_LIST_TAIL, "PHOTCODE", 0, "", "NONE");
    58     psMetadataAddStr (config->recipe, PS_LIST_TAIL, "BREAK_POINT", 0, "", "NONE");
     59    // set default recipe values here
     60    METADATA_ADD_DEFAULT (config->recipe, Str, "FITMODE", "NONE", "");
     61    METADATA_ADD_DEFAULT (config->recipe, Str, "PHOTCODE", "NONE", "");
     62    METADATA_ADD_DEFAULT (config->recipe, Str, "BREAK_POINT", "NONE", "");
     63    METADATA_ADD_DEFAULT (config->recipe, Str, "OUTPUT_FORMAT", "CMP", "");
     64    METADATA_ADD_DEFAULT (config->recipe, Str, "OUTPUT_MODE", "SPLIT", "");
    5965
    60     // XXX EAM : extend this to allow an array of selected chips by name
    6166    // Chip selection: if we are using a single chip, select it for each FPA
    62     int chipNum = psMetadataLookupS32(NULL, config->arguments, "-chip"); // Chip number to work on
    63     if (chipNum >= 0) {
    64         if (! pmFPASelectChip(input->fpa, chipNum)) {
    65             psErrorStackPrint(stderr, "Chip number %d doesn't exist in camera.\n", chipNum);
    66             exit(EXIT_FAILURE);
     67    // Chip numbers to work on: -chip 1,2,3,5,8,10
     68    char *chips = psMetadataLookupStr(NULL, config->arguments, "CHIP_SELECTIONS");
     69    if (chips != NULL) {
     70        char *p = chips;
     71        while (strlen(p)) {
     72            char *q = strchr (p, ',');
     73            if (q == NULL) {
     74                q = p + strlen(p);
     75            } else {
     76                *q = 0;
     77                q = q + 1;
     78            }
     79            int chipNum = atoi(p);
     80            // XXX EAM : extend this to allow an array of selected chips (by name)
     81            if (! pmFPASelectChip(input->fpa, chipNum)) {
     82                psErrorStackPrint(stderr, "Chip number %d doesn't exist in camera.\n", chipNum);
     83                exit(EXIT_FAILURE);
     84            }
     85            psLogMsg("psphot", PS_LOG_INFO, "Operating only on chip %d\n", chipNum);
     86            p = q;
    6787        }
    68         psLogMsg("psphot", PS_LOG_INFO, "Operating only on chip %d\n", chipNum);
    6988    }
    7089
     
    7291    input->fpa = pmFPAConstruct(config->camera);
    7392
     93    psTrace(__func__, 1, "Done with psphotParseCamera...\n");
    7494    return input;
    7595}
  • trunk/psphot/src/psphotReadout.c

    r6117 r6311  
    88    psStats     *sky     = NULL;
    99    bool         status;
     10
     11    psphotSaveImage (NULL, readout->mask, "mask.fits");
     12    psphotSaveImage (NULL, readout->image, "image.fits");
     13    psphotSaveImage (NULL, readout->weight, "weight.fits");
    1014
    1115    // measure image stats for initial guess
Note: See TracChangeset for help on using the changeset viewer.