IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6117


Ignore:
Timestamp:
Jan 20, 2006, 8:57:16 PM (20 years ago)
Author:
eugene
Message:

modifications to support psphot on pmReadout with full IPP config files

Location:
trunk/psphot/src
Files:
6 added
11 edited

Legend:

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

    r5993 r6117  
    5959}
    6060
     61pmModel *pmModelSelect (pmSource *source) {
     62    switch (source->type) {
     63      case PM_SOURCE_STAR:
     64        return source->modelPSF;
     65       
     66      case PM_SOURCE_EXTENDED:
     67        return source->modelEXT;
     68       
     69      default:
     70        return NULL;
     71    }
     72    return NULL;
     73}
     74
    6175bool pmSourcePhotometry (float *fitMag, float *obsMag, pmModel *model, psImage *image, psImage *mask) {
    6276
     
    162176    return (flux);
    163177}
     178
     179static void ppConfigFree (ppConfig *config) {
     180
     181  if (config == NULL) return;
     182  return;
     183}
     184
     185// allocate a ppConfig structrue
     186ppConfig *ppConfigAlloc (void) {
     187
     188  ppConfig *config = psAlloc (sizeof(ppConfig));
     189  psMemSetDeallocator(config, (psFreeFunc) ppConfigFree);
     190
     191  config->site = NULL;
     192  config->camera = NULL;
     193  config->recipe = NULL;
     194  config->arguments = NULL;
     195  config->database = NULL;
     196
     197  return (config);
     198}
     199
     200static void ppFileFree (ppFile *file) {
     201
     202  if (file == NULL) return;
     203  return;
     204}
     205
     206// allocate a ppFile structrue
     207ppFile *ppFileAlloc (void) {
     208
     209  ppFile *file = psAlloc (sizeof(ppFile));
     210  psMemSetDeallocator(file, (psFreeFunc) ppFileFree);
     211
     212  file->filename = NULL;
     213  file->fits = NULL;
     214  file->phu = NULL;
     215  file->fpa = NULL;
     216
     217  return (file);
     218}
     219
     220psMetadata *pmReadoutGetHeader (pmReadout *readout) {
     221
     222    p_pmHDU *hdu = NULL;
     223
     224    pmCell *cell = readout->parent;     // cell containing this readout;
     225    hdu = cell->hdu;                    // The data unit, containing the weight and mask originals
     226    if (hdu) return hdu->header;
     227   
     228    pmChip *chip = cell->parent;        // The parent chip
     229    hdu = chip->hdu;                    // The data unit, containing the weight and mask originals
     230    if (hdu) return hdu->header;
     231
     232    pmFPA *fpa = chip->parent;          // The parent FPA
     233    hdu = fpa->hdu;
     234    if (hdu) return hdu->header;
     235
     236    if (fpa->phu) return fpa->phu;
     237   
     238    psError(PS_ERR_UNKNOWN, true, "Unable to find the HDU in the hierarchy!\n");
     239    return NULL;
     240}
  • trunk/psphot/src/psModulesUtils.h

    r5718 r6117  
    99# include "psLibUtils.h"
    1010
     11// How much of the FPA to load at a time
     12typedef enum {
     13    PP_LOAD_NONE,                       // Don't load anything
     14    PP_LOAD_FPA,                        // Load the entire FPA at once
     15    PP_LOAD_CHIP,                       // Load by chip
     16    PP_LOAD_CELL,                       // Load by cell
     17} ppImageLoadDepth;
     18
     19// Configuration data
     20typedef struct {
     21    psMetadata *site;                   // The site configuration
     22    psMetadata *camera;                 // The camera configuration
     23    psMetadata *recipe;                 // The recipe (i.e., specific setups)
     24    psMetadata *arguments;              // The command-line arguments
     25    psDB       *database;               // Database handle
     26} ppConfig;
     27
     28// A file to process
     29typedef struct {
     30    char *filename;                     // File name
     31    psFits *fits;                       // The FITS file handle
     32    psMetadata *phu;                    // The FITS header
     33    pmFPA *fpa;                         // The FPA, with pixels and extensions
     34} ppFile;
     35
    1136// psModule extra utilities
    1237// bool      pmSourceFitModel_EAM(pmSource *source, pmModel *model, const bool PSF);
     
    1843// unify with paul's image/header/metadata functions
    1944psF32        pmConfigLookupF32 (bool *status, psMetadata *config, psMetadata *header, char *name);
     45pmModel *pmModelSelect (pmSource *source);
     46
     47ppConfig       *ppConfigAlloc (void);
     48ppFile         *ppFileAlloc (void);
     49psMetadata    *pmReadoutGetHeader (pmReadout *readout);
    2050
    2151# endif
  • trunk/psphot/src/psphot.c

    r6056 r6117  
    11# include "psphot.h"
    22
    3 // XXX need a better structure for handling optional sequence
     3// XXX need a better structure for handling optional sequences
    44int main (int argc, char **argv) {
    5 
    6     psMetadata  *config  = NULL;
    7     psMetadata  *header  = NULL;
    8     pmReadout   *readout  = NULL;
    9     psArray     *sources = NULL;
    10     psArray     *peaks   = NULL;
    11     pmPSF       *psf     = NULL;
    12     psStats     *sky     = NULL;
    13     bool         status;
    145
    156    psTimerStart ("complete");
    167
    17     // load command-line arguments and options
    18     config = psphotArguments (&argc, argv);
     8    // load implementation-specific models
     9    psphotModelGroupInit ();
     10
     11    // load command-line arguments, options, and system config data
     12    ppConfig *config = psphotArguments (&argc, argv);
    1913
    2014    // load input data (config and images (signal, noise, mask)
    21     readout = psphotSetup (config, &header);
     15    ppFile *input = psphotParseCamera (config);
    2216
    23     // run a single-model test if desired
    24     psphotModelTest (readout, config);
     17    // run a single-model test if desired - XXX push in psphotImageLoop?
     18    // psphotModelTest (input, options);
    2519
    26     // measure image stats for initial guess
    27     sky = psphotImageStats (readout, config);
     20    // call psphot for each readout
     21    psphotImageLoop (input, config);
    2822
    29     // generate a background model (currently, 2D polynomial)
    30     // XXX this should be available to be re-added to the original image
    31     psphotImageBackground (readout, config, sky);
    32 
    33     // find the peaks in the image
    34     peaks = psphotFindPeaks (readout, config, sky);
    35 
    36     // construct sources and measure basic stats
    37     sources = psphotSourceStats (readout, config, peaks);
    38 
    39     // classify sources based on moments, brightness
    40     psphotRoughClass (sources, config);
    41 
    42     // mark blended peaks PS_SOURCE_BLEND
    43     psphotBasicDeblend (sources, config, sky);
    44 
    45     // use bright stellar objects to measure PSF
    46     psf = psphotChoosePSF (config, sources, sky);
    47 
    48     // XXX change FITMODE to a string
    49     int FITMODE = psMetadataLookupS32 (&status, config, "FIT_MODE");
    50     switch (FITMODE) {
    51       case 0:
    52         psphotEnsemblePSF (readout, config, sources, psf, sky);
    53         break;
    54 
    55       case 1:
    56         psphotEnsemblePSF (readout, config, sources, psf, sky);
    57         psphotFullFit (readout, config, sources, psf, sky);
    58         psphotReplaceUnfit (sources);
    59         psphotApResid (readout, sources, config, psf);
    60         break;
    61 
    62       case 2:
    63         psphotEnsemblePSF (readout, config, sources, psf, sky);
    64         psphotBlendFit (readout, config, sources, psf, sky);
    65         psphotReplaceUnfit (sources);
    66         psphotApResid (readout, sources, config, psf);
    67         break;
    68 
    69       case 3:
    70         psphotApplyPSF (readout, config, sources, psf, sky);
    71         break;
    72 
    73       case 4:
    74         psphotApplyPSF (readout, config, sources, psf, sky);
    75         psphotFitExtended (readout, config, sources, sky);
    76         break;
    77     }
    78 
    79     // write out data in appropriate format
    80     psphotOutput (readout, header, config, sources, psf, sky);
    81     psLogMsg ("psphot", 3, "wrote output: %f sec\n", psTimerMark ("psphot"));
    8223    psLogMsg ("psphot", 3, "complete psphot run: %f sec\n", psTimerMark ("complete"));
    8324    exit (0);
  • trunk/psphot/src/psphot.h

    r6056 r6117  
    55# include <pmObjects.h>
    66# include <pmGrowthCurve.h>
     7# include <pmConfig.h>
     8# include <pmFPARead.h>
    79# include <pmPSF.h>
    810# include <pmPSFtry.h>
     
    1113# include "psModulesUtils.h"
    1214# include "psSparse.h"
     15#include "pmFPAConstruct.h"
     16
     17# define PSPHOT_RECIPE "PSPHOT"
    1318
    1419# define psMemCopy(A)(psMemIncrRefCounter((A)))
    1520
    1621// top-level psphot functions
    17 psMetadata     *psphotArguments (int *argc, char **argv);
    18 pmReadout      *psphotSetup (psMetadata *config, psMetadata **header);
     22ppConfig       *psphotArguments (int *argc, char **argv);
     23ppFile         *psphotParseCamera (ppConfig *config);
     24bool            psphotImageLoop (ppFile *input, ppConfig *config);
     25
    1926bool            psphotModelTest (pmReadout *readout, psMetadata *config);
     27bool            psphotReadout (pmReadout *readout, psMetadata *config);
     28bool            ppImageLoadPixels (ppFile *input, psDB *db, int chipNum, int cellNum);
     29
     30// psphotReadout functions
    2031psStats        *psphotImageStats (pmReadout *readout, psMetadata *config);
    2132psPolynomial2D *psphotImageBackground (pmReadout *readout, psMetadata *config, psStats *sky);
     
    2536bool            psphotBasicDeblend (psArray *sources, psMetadata *config, psStats *sky);
    2637pmPSF          *psphotChoosePSF (psMetadata *config, psArray *sources, psStats *sky);
    27 void            psphotOutput (pmReadout *readout, psMetadata *header, psMetadata *config, psArray *sources, pmPSF *psf, psStats *sky);
     38void            psphotOutput (pmReadout *readout, psMetadata *config);
    2839
    2940// optional object analysis steps
     
    4657bool            psphotGrowthCurve (pmReadout *readout, pmPSF *psf);
    4758void            psphotTestArguments (int *argc, char **argv);
     59bool            pmCellSetMask (pmCell *cell, psMetadata *recipe);
    4860
    4961// functions to set the correct source pixels
     
    5668
    5769// output functions
    58 bool            pmSourcesWriteText (pmReadout *readout, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky);
    59 bool            pmSourcesWriteOBJ  (pmReadout *readout, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky);
    60 bool            pmSourcesWriteCMP  (pmReadout *readout, psMetadata *header, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky);
    61 bool            pmSourcesWriteCMF  (pmReadout *readout, psMetadata *header, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky);
    62 bool            pmSourcesWriteSX   (pmReadout *readout, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky);
     70bool            pmSourcesWriteSX   (psArray *sources, char *filename);
     71bool            pmSourcesWriteOBJ  (psArray *sources, char *filename);
     72bool            pmSourcesWriteCMP  (psArray *sources, char *filename, psMetadata *header);
     73bool            pmSourcesWriteCMF  (psArray *sources, char *filename, psMetadata *header);
     74bool            pmSourcesWriteText (psArray *sources, char *filename);
    6375
    64 bool            pmModelWritePSFs (psArray *sources, psMetadata *config, char *filename, pmPSF *psf);
     76bool            pmModelWritePSFs (psArray *sources, char *filename);
    6577bool            pmModelWriteEXTs (psArray *sources, char *filename);
    6678bool            pmModelWriteNULLs (psArray *sources, char *filename);
     
    7486int             pmSourcesDophotType (pmSource *source);
    7587bool            psMetadataItemTransfer (psMetadata *out, psMetadata *in, char *key);
     88
     89bool            psphotMagnitudes (psMetadata *config, psArray *sources, pmPSF *psf);
    7690
    7791// PSF / DBL / EXT evaluation functions
     
    99113psPlane         psImageBicubeMin (psPolynomial2D *poly);
    100114
     115bool psImageJpegColormap (char *name);
     116bool psImageJpeg (psImage *image, char *filename, float zero, float scale);
     117
    101118// optional mode for clip fit?
    102119psPolynomial4D *psVectorChiClipFitPolynomial4D(
  • trunk/psphot/src/psphotArguments.c

    r5993 r6117  
    11# include "psphot.h"
    22
    3 static void usage (void) ;
     3static void usage (psMetadata *arguments) ;
    44
    5 psMetadata *psphotArguments (int *argc, char **argv) {
     5ppConfig *psphotArguments (int *argc, char **argv) {
    66
    77    int N;
    8     unsigned int Nfail;
    9 
    10     psMetadata *options = psMetadataAlloc ();
    118
    129    // basic pslib options
    1310    psLogSetFormat ("M");
    14     psArgumentVerbosity (argc, argv);
    1511
    16     // command-line options -- place on options MD
    17     // mask image
    18     if ((N = psArgumentGet (*argc, argv, "-mask"))) {
    19         psArgumentRemove (N, argc, argv);
    20         psMetadataAddStr (options, PS_LIST_TAIL, "MASK_IMAGE", 0, "", psStringCopy(argv[N]));
    21         psArgumentRemove (N, argc, argv);
     12    ppConfig *config = ppConfigAlloc ();
     13
     14    // load config data from default locations
     15    if (!pmConfigRead(&config->site, &config->camera, &config->recipe, argc, argv, PSPHOT_RECIPE)) {
     16        psErrorStackPrint(stderr, "Can't find site configuration!\n");
     17        exit (EXIT_FAILURE);
    2218    }
    2319
    24     // weight image
    25     if ((N = psArgumentGet (*argc, argv, "-weight"))) {
    26         psArgumentRemove (N, argc, argv);
    27         psMetadataAddStr (options, PS_LIST_TAIL, "WEIGHT_IMAGE", 0, "", psStringCopy(argv[N]));
    28         psArgumentRemove (N, argc, argv);
    29     }
     20    // Parse other command-line arguments
     21    config->arguments = psMetadataAlloc ();
    3022
    31     // output residual image
    32     if ((N = psArgumentGet (*argc, argv, "-resid"))) {
    33         psArgumentRemove (N, argc, argv);
    34         psMetadataAddStr (options, PS_LIST_TAIL, "RESID_IMAGE", 0, "", psStringCopy(argv[N]));
    35         psArgumentRemove (N, argc, argv);
    36     }
    37 
    38     // analysis region
    39     if ((N = psArgumentGet (*argc, argv, "-region"))) {
    40         psArgumentRemove (N, argc, argv);
    41         psMetadataAddStr (options, PS_LIST_TAIL, "ANALYSIS_REGION", 0, "", psStringCopy(argv[N]));
    42         psArgumentRemove (N, argc, argv);
    43     }
    44 
    45     // output residual image
    46     psMetadataAddStr (options, PS_LIST_TAIL, "PHOTCODE", 0, "", psStringCopy("NONE"));
    47     if ((N = psArgumentGet (*argc, argv, "-photcode"))) {
    48         psArgumentRemove (N, argc, argv);
    49         psMetadataAddStr (options, PS_LIST_TAIL, "PHOTCODE", PS_META_REPLACE, "", psStringCopy(argv[N]));
    50         psArgumentRemove (N, argc, argv);
    51     }
    52 
    53     // input PSF file
    54     if ((N = psArgumentGet (*argc, argv, "-psf"))) {
    55         psArgumentRemove (N, argc, argv);
    56         psMetadataAddStr (options, PS_LIST_TAIL, "PSF_INPUT_FILE", 0, "", psStringCopy (argv[N]));
    57         psArgumentRemove (N, argc, argv);
    58     }
    59 
    60     // run the 0ltest model (requires X,Y coordinate)
     23    // 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   
     30    // run the test model (requires X,Y coordinate)
    6131    if ((N = psArgumentGet (*argc, argv, "-modeltest"))) {
    62         psMetadataAddBool (options, PS_LIST_TAIL, "TEST_FIT",   0, "", true);
    63         psMetadataAddF32  (options, PS_LIST_TAIL, "TEST_FIT_X", 0, "", atof(argv[N+1]));
    64         psMetadataAddF32  (options, PS_LIST_TAIL, "TEST_FIT_Y", 0, "", atof(argv[N+2]));
     32        psMetadataAddBool (config->arguments, PS_LIST_TAIL, "TEST_FIT",   0, "", true);
     33        psMetadataAddF32  (config->arguments, PS_LIST_TAIL, "TEST_FIT_X", 0, "", atof(argv[N+1]));
     34        psMetadataAddF32  (config->arguments, PS_LIST_TAIL, "TEST_FIT_Y", 0, "", atof(argv[N+2]));
    6535
    6636        psArgumentRemove (N, argc, argv);
     
    7141        if ((N = psArgumentGet (*argc, argv, "-model"))) {
    7242            psArgumentRemove (N, argc, argv);
    73             psMetadataAddStr (options, PS_LIST_TAIL, "TEST_FIT_MODEL", 0, "", psStringCopy (argv[N]));
     43            psMetadataAddStr (config->arguments, PS_LIST_TAIL, "TEST_FIT_MODEL", 0, "", psStringCopy (argv[N]));
    7444            psArgumentRemove (N, argc, argv);
    7545        }
     
    7848        if ((N = psArgumentGet (*argc, argv, "-fitmode"))) {
    7949            psArgumentRemove (N, argc, argv);
    80             psMetadataAddStr (options, PS_LIST_TAIL, "TEST_FIT_MODE", 0, "", psStringCopy (argv[N]));
     50            psMetadataAddStr (config->arguments, PS_LIST_TAIL, "TEST_FIT_MODE", 0, "", psStringCopy (argv[N]));
    8151            psArgumentRemove (N, argc, argv);
    8252        }
    8353        if ((N = psArgumentGet (*argc, argv, "-fitset"))) {
    8454            psArgumentRemove (N, argc, argv);
    85             psMetadataAddStr (options, PS_LIST_TAIL, "TEST_FIT_SET", 0, "", psStringCopy (argv[N]));
     55            psMetadataAddStr (config->arguments, PS_LIST_TAIL, "TEST_FIT_SET", 0, "", psStringCopy (argv[N]));
    8656            psArgumentRemove (N, argc, argv);
    8757        }
    8858    }
    8959
    90     // other arbitrary options: -D key value (all added as string)
     60    // Parse command-line overrides of recipe values
     61    psMetadata *recipe = psMetadataAlloc ();
     62
     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"))) {
     69        psArgumentRemove (N, argc, argv);
     70        psMetadataAddStr (recipe, PS_LIST_TAIL, "PHOTCODE", PS_META_REPLACE, "", psStringCopy(argv[N]));
     71        psArgumentRemove (N, argc, argv);
     72    }
     73
     74    // analysis region : XXX override recipe
     75    if ((N = psArgumentGet (*argc, argv, "-break"))) {
     76        psArgumentRemove (N, argc, argv);
     77        psMetadataAddStr (recipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", psStringCopy(argv[N]));
     78        psArgumentRemove (N, argc, argv);
     79    }
     80
     81    // analysis region : XXX override recipe
     82    if ((N = psArgumentGet (*argc, argv, "-fitmode"))) {
     83        psArgumentRemove (N, argc, argv);
     84        psMetadataAddStr (recipe, PS_LIST_TAIL, "FITMODE", PS_META_REPLACE, "", psStringCopy(argv[N]));
     85        psArgumentRemove (N, argc, argv);
     86    }
     87
     88    // analysis region : XXX override recipe
     89    if ((N = psArgumentGet (*argc, argv, "-region"))) {
     90        psArgumentRemove (N, argc, argv);
     91        psMetadataAddStr (recipe, PS_LIST_TAIL, "ANALYSIS_REGION", 0, "", psStringCopy(argv[N]));
     92        psArgumentRemove (N, argc, argv);
     93    }
     94
     95    // other arbitrary recipe values: -D key value (all added as string)
    9196    while ((N = psArgumentGet (*argc, argv, "-D"))) {
    9297        psArgumentRemove (N, argc, argv);
    93         psMetadataAddStr (options, PS_LIST_TAIL, argv[N], 0, "", argv[N+1]);
     98        psMetadataAddStr (recipe, PS_LIST_TAIL, argv[N], 0, "", argv[N+1]);
    9499        psArgumentRemove (N, argc, argv);
    95100        psArgumentRemove (N, argc, argv);
    96101    }
    97102
    98     // other arbitrary options: -Df key value (all added as float)
     103    // other arbitrary recipe values: -Df key value (all added as float)
    99104    while ((N = psArgumentGet (*argc, argv, "-Df"))) {
    100105        psArgumentRemove (N, argc, argv);
    101         psMetadataAddF32 (options, PS_LIST_TAIL, argv[N], 0, "", atof(argv[N+1]));
     106        psMetadataAddF32 (recipe, PS_LIST_TAIL, argv[N], 0, "", atof(argv[N+1]));
    102107        psArgumentRemove (N, argc, argv);
    103108        psArgumentRemove (N, argc, argv);
    104109    }
    105110
    106     // other arbitrary options: -Di key value (all added as int)
     111    // other arbitrary recipe values: -Di key value (all added as int)
    107112    while ((N = psArgumentGet (*argc, argv, "-Di"))) {
    108113        psArgumentRemove (N, argc, argv);
    109         psMetadataAddS32 (options, PS_LIST_TAIL, argv[N], 0, "", atoi(argv[N+1]));
     114        psMetadataAddS32 (recipe, PS_LIST_TAIL, argv[N], 0, "", atoi(argv[N+1]));
    110115        psArgumentRemove (N, argc, argv);
    111116        psArgumentRemove (N, argc, argv);
    112117    }
    113118
    114     if (*argc != 4) usage ();
     119    // place the recipe options on the arguments stack
     120    psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "RECIPE.OPTIONS", PS_DATA_UNKNOWN, "", recipe);
    115121
    116     // load config information
    117     psMetadata *config = psMetadataAlloc ();
     122    if (!psArgumentParse(config->arguments, argc, argv)) usage (config->arguments);
     123    if (*argc != 3) usage (config->arguments);
    118124
    119     // add default values
    120     psMetadataAddStr (config, PS_LIST_TAIL, "BREAK_POINT", 0, "", "NONE");
    121     psMetadataAddS32 (config, PS_LIST_TAIL, "FIT_MODE", 0, "", 2);
    122 
    123     psMetadataAdd (config, PS_LIST_TAIL, "PSF_MODEL", PS_DATA_METADATA_MULTI, "folder for psf model entries", NULL);
    124 
    125     // config file values override defaults set here
    126     config = psMetadataConfigParse (config, &Nfail, argv[3], TRUE);
    127 
    128     psMetadataItem *item = NULL;
    129     psMetadataIterator *iter = psMetadataIteratorAlloc (options, PS_LIST_HEAD, NULL);
    130     while ((item = psMetadataGetAndIncrement (iter)) != NULL) {
    131         psMetadataAddItem (config, item, PS_LIST_TAIL, PS_META_REPLACE);
    132         psFree (item);
    133     }
    134     psFree (iter);
    135 
    136     // identify input image & optional weight & mask images
    137     // command-line entries override config-file entries
    138     psMetadataAddStr (config, PS_LIST_TAIL, "IMAGE",       PS_META_REPLACE, "", argv[1]);
    139     psMetadataAddStr (config, PS_LIST_TAIL, "OUTPUT_FILE", PS_META_REPLACE, "", argv[2]);
     125    // 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]);
    140128
    141129    return (config);
    142130}
    143131
    144 static void usage (void) {
     132static void usage (psMetadata *arguments) {
    145133
    146     fprintf (stderr, "USAGE: psphot (image) (output) (config)\n");
    147     fprintf (stderr, "options: \n");
    148     fprintf (stderr, "  -mask  (filename)\n");
    149     fprintf (stderr, "  -weight (filename)\n");
    150     fprintf (stderr, "  -resid (filename)\n");
    151     fprintf (stderr, "  -photcode (photcode)\n");
     134    fprintf (stderr, "USAGE: psphot (image) (output)\n");
     135    psArgumentHelp (arguments);
    152136    exit (2);
    153137}
  • trunk/psphot/src/psphotChoosePSF.c

    r5993 r6117  
    3434
    3535    // get the list pointers for the PSF_MODEL entries
     36    psList *list = NULL;
    3637    psMetadataItem *mdi = psMetadataLookup (config, "PSF_MODEL");
    3738    if (mdi == NULL) psAbort ("psphotChoosePSF", "missing PSF_MODEL selection");
    38 
    39     psList *list = (psList *) mdi->data.list;
    40     psListIterator *iter = psListIteratorAlloc (list, PS_LIST_HEAD, FALSE);
     39    if (mdi->type == PS_DATA_STRING) {
     40        list = psListAlloc(NULL);
     41        psListAdd (list, PS_LIST_HEAD, mdi);
     42    } else {
     43        if (mdi->type != PS_DATA_METADATA_MULTI) psAbort ("psphotChoosePSF", "missing PSF_MODEL selection");
     44        list = psMemIncrRefCounter(mdi->data.list);
     45    }
    4146
    4247    // set up an array to store the results
     
    4449
    4550    // try each model option listed in config
     51    psListIterator *iter = psListIteratorAlloc (list, PS_LIST_HEAD, FALSE);
    4652    for (int i = 0; i < models->n; i++) {
    4753
     
    5460    }
    5561    psFree (iter);
    56     // psFree (list); XXX is list freed with iter?
     62    psFree (list);
    5763    psFree (stars);
    5864
  • trunk/psphot/src/psphotImageStats.c

    r6056 r6117  
    3939    }
    4040
    41     // we store these values in mean,stdev
    42     bool status = false;
    43     float NOISE = psMetadataLookupF32 (&status, config, "RDNOISE");
    44     float GAIN  = psMetadataLookupF32 (&status, config, "GAIN");
     41    pmCell *cell = readout->parent;     // cell containing this readout;
     42    float gain = psMetadataLookupF32(NULL, cell->concepts, "CELL.GAIN"); // Cell gain
     43    float noise = psMetadataLookupF32(NULL, cell->concepts, "CELL.READNOISE"); // Cell read noise
    4544
    4645    // convert instrumental background to poisson stats
    4746    sky = psStatsAlloc (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
    4847    sky->sampleMean   = stats->sampleMedian;
    49     sky->sampleStdev  = sqrt(sky->sampleMean/GAIN + PS_SQR(NOISE));
     48    sky->sampleStdev  = sqrt(sky->sampleMean/gain + PS_SQR(noise));
    5049
    5150    psLogMsg ("psphot", 4, "background: %f +/- %f\n", sky->sampleMean, sky->sampleStdev);
  • trunk/psphot/src/psphotMagnitudes.c

    r5993 r6117  
    7171
    7272*/
     73
     74bool psphotMagnitudes (psMetadata *config, psArray *sources, pmPSF *psf) {
     75
     76    bool status;
     77
     78    float RADIUS = psMetadataLookupF32 (&status, config, "AP_RADIUS");
     79    for (int i = 0; i < sources->n; i++) {
     80        pmSource *source = (pmSource *) sources->data[i];
     81        pmSourceMagnitudes (source, psf, RADIUS);
     82    }   
     83    return true;
     84}
     85
  • trunk/psphot/src/psphotOutput.c

    r6056 r6117  
    22
    33// output functions: we have several fixed modes (sx, obj, cmp)
    4 void psphotOutput (pmReadout *readout, psMetadata *header, psMetadata *config, psArray *sources, pmPSF *psf, psStats *sky) {
     4void psphotOutput (pmReadout *readout, psMetadata *config) {
    55
    66    bool status;
    77
    88    psTimerStart ("psphot");
     9
     10    psMetadata *header = pmReadoutGetHeader (readout);
     11
     12    psArray *sources = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.SOURCES");
     13    pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
    914
    1015    char *outputMode = psMetadataLookupPtr (&status, config, "OUTPUT_MODE");
     
    2934        return;
    3035    }
     36    if (!strcasecmp (outputMode, "SX")) {
     37        pmSourcesWriteSX (sources, outputFile);
     38        return;
     39    }
    3140    if (!strcasecmp (outputMode, "OBJ")) {
    32         pmSourcesWriteOBJ (readout, config, outputFile, sources, psf, sky);
     41        pmSourcesWriteOBJ (sources, outputFile);
    3342        return;
    3443    }
    35     if (!strcasecmp (outputMode, "SX")) {
    36         pmSourcesWriteSX (readout, config, outputFile, sources, psf, sky);
     44    if (!strcasecmp (outputMode, "CMP")) {
     45        pmSourcesWriteCMP (sources, outputFile, header);
    3746        return;
    3847    }
    39     if (!strcasecmp (outputMode, "CMP")) {
    40         pmSourcesWriteCMP (readout, header, config, outputFile, sources, psf, sky);
     48    if (!strcasecmp (outputMode, "CMF")) {
     49        pmSourcesWriteCMF (sources, outputFile, header);
    4150        return;
    4251    }
    43     if (!strcasecmp (outputMode, "CMF")) {
    44         pmSourcesWriteCMF (readout, header, config, outputFile, sources, psf, sky);
     52    if (!strcasecmp (outputMode, "TEXT")) {
     53        pmSourcesWriteText (sources, outputFile);
    4554        return;
    4655    }
    47     if (!strcasecmp (outputMode, "TEXT")) {
    48         pmSourcesWriteText (readout, config, outputFile, sources, psf, sky);
    49         return;
    50     }
    5156
    5257    psAbort ("psphot", "unknown output mode %s", outputMode);
     
    5459
    5560// dophot-style output list with fixed line width
    56 bool pmSourcesWriteOBJ (pmReadout *readout, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {
     61bool pmSourcesWriteOBJ (psArray *sources, char *filename) {
    5762
    5863    int type;
    59     pmModel *model;
    6064    psF32 *PAR, *dPAR;
    6165    float dmag, apResid;
    62     bool status;
    6366
    6467    psLine *line = psLineAlloc (104);  // 104 is dophot-defined line length
     
    6972        return false;
    7073    }
    71 
    72     float RADIUS = psMetadataLookupF32 (&status, config, "AP_RADIUS");
    7374
    7475    // write sources with models
    7576    for (int i = 0; i < sources->n; i++) {
    7677        pmSource *source = (pmSource *) sources->data[i];
    77 
    78         model = pmSourceMagnitudes (source, psf, RADIUS);
     78        pmModel *model = pmModelSelect (source);
    7979        if (model == NULL) continue;
    8080
     
    106106
    107107// elixir-mode / sextractor-style output list with fixed line width
    108 bool pmSourcesWriteSX (pmReadout *readout, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {
    109 
    110     pmModel *model;
     108bool pmSourcesWriteSX (psArray *sources, char *filename) {
     109
    111110    psF32 *PAR, *dPAR;
    112111    float dmag;
    113     bool status;
    114112
    115113    psLine *line = psLineAlloc (110);  // 110 is sextractor line length
     
    120118        return false;
    121119    }
    122 
    123     float RADIUS = psMetadataLookupF32 (&status, config, "AP_RADIUS");
    124120
    125121    // write sources with models
    126122    for (int i = 0; i < sources->n; i++) {
    127123        pmSource *source = (pmSource *) sources->data[i];
    128 
    129         model = pmSourceMagnitudes (source, psf, RADIUS);
     124        pmModel *model = pmModelSelect (source);
    130125        if (model == NULL) continue;
    131126
     
    157152
    158153// elixir-style pseudo FITS table (header + ascii list)
    159 bool pmSourcesWriteCMP (pmReadout *readout, psMetadata *header, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {
     154bool pmSourcesWriteCMP (psArray *sources, char *filename, psMetadata *header) {
    160155
    161156    int i, type;
    162     pmModel *model;
    163157    psMetadataItem *mdi;
    164158    psF32 *PAR, *dPAR;
     
    167161
    168162    // find config information for output header
    169     float RADIUS = psMetadataLookupF32 (&status, config, "AP_RADIUS");
    170     float ZERO_POINT = psMetadataLookupF32 (&status, config, "ZERO_POINT");
     163    float ZERO_POINT = psMetadataLookupF32 (&status, header, "ZERO_PT");
    171164    if (!status) ZERO_POINT = 25.0;
    172165
    173166    // write necessary information to output header
    174     psphotUpdateHeader (header, config);
    175167    psMetadataAdd (header, PS_LIST_TAIL, "NSTARS",   PS_DATA_S32 | PS_META_REPLACE, "NUMBER OF STARS", sources->n);
    176168
     
    200192    for (i = 0; i < sources->n; i++) {
    201193        pmSource *source = (pmSource *) sources->data[i];
    202 
    203         model = pmSourceMagnitudes (source, psf, RADIUS);
     194        pmModel *model = pmModelSelect (source);
    204195        if (model == NULL) continue;
    205196
     
    232223// this format consists of a header derived from the image header
    233224// followed by a zero-size matrix, followed by the table data
    234 bool pmSourcesWriteCMF (pmReadout *readout, psMetadata *header, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {
     225bool pmSourcesWriteCMF (psArray *sources, char *filename, psMetadata *header) {
    235226
    236227    psArray *table;
     
    239230    psMetadata *theader;
    240231    int i, type;
    241     pmModel *model;
    242232    psF32 *PAR, *dPAR;
    243233    float dmag, lsky;
     
    245235
    246236    // find config information for output header
    247     float RADIUS = psMetadataLookupF32 (&status, config, "AP_RADIUS");
    248     float ZERO_POINT = psMetadataLookupF32 (&status, config, "ZERO_POINT");
    249 
    250     // write necessary information to output header
    251     psphotUpdateHeader (header, config);
     237    float ZERO_POINT = psMetadataLookupF32 (&status, header, "ZERO_PT");
    252238
    253239    table = psArrayAlloc (sources->n);
     
    256242    for (i = 0; i < sources->n; i++) {
    257243        pmSource *source = (pmSource *) sources->data[i];
    258 
    259         model = pmSourceMagnitudes (source, psf, RADIUS);
     244        pmModel *model = pmModelSelect (source);
    260245        if (model == NULL) continue;
    261246
     
    309294/***** Text Output Methods *****/
    310295
    311 bool pmSourcesWriteText (pmReadout *readout, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky) {
     296bool pmSourcesWriteText (psArray *sources, char *filename) {
    312297
    313298    char *name = (char *) psAlloc (strlen(filename) + 10);
    314299
    315300    sprintf (name, "%s.psf.dat", filename);
    316     pmModelWritePSFs (sources, config, name, psf);
     301    pmModelWritePSFs (sources, name);
    317302
    318303    sprintf (name, "%s.ext.dat", filename);
     
    330315
    331316// write the PSF sources to an output file
    332 bool pmModelWritePSFs (psArray *sources, psMetadata *config, char *filename, pmPSF *psf) {
     317bool pmModelWritePSFs (psArray *sources, char *filename) {
    333318
    334319    double dPos, dMag;
     
    337322    psF32 *PAR, *dPAR;
    338323    pmModel  *model;
    339     bool status;
    340 
    341     float RADIUS = psMetadataLookupF32 (&status, config, "AP_RADIUS");
    342324
    343325    f = fopen (filename, "w");
     
    350332    for (i = 0; i < sources->n; i++) {
    351333        pmSource *source = (pmSource *) sources->data[i];
    352 
    353334        if (source->type != PM_SOURCE_STAR) continue;
    354         model = pmSourceMagnitudes (source, psf, RADIUS);
     335        model = source->modelPSF;
    355336        if (model == NULL) continue;
    356337
  • trunk/psphot/src/psphotTest.c

    r5993 r6117  
    1515int main (int argc, char **argv) {
    1616
    17     psMetadata *row;
    18     psArray *table;
    19 
    20     psMetadataItem *mdi;
    2117    psRegion region = {0,0,0,0};        // a region representing the entire array
    22 
    2318    psphotTestArguments (&argc, argv);
    2419
     
    2722    psImage *image = psFitsReadImage (NULL, file, region, 0);
    2823    psFitsClose (file);
     24
     25    psImageJpegColormap (argv[5]);
     26
     27    // psImage *fimage = psImageCopy (NULL, image, PS_TYPE_F32);
     28
     29    int binning = atof(argv[6]);
     30
     31    psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEAN);
     32    psImage *fimage = psImageRebin (NULL, image, NULL, 0, binning, stats);
     33
     34    float min = atof(argv[3]);
     35    float max = atof(argv[4]);
     36
     37    psImageJpeg (fimage, argv[2], min, max);
     38
     39    psFree (header);
     40    psFree (image);
     41    exit (0);
     42}
     43
     44
     45# if (0)
     46
     47    psMetadata *row;
     48    psArray *table;
     49
     50    psMetadataItem *mdi;
    2951
    3052    psMetadataConfigWrite (header, argv[2]);
     
    5981    psFitsWriteHeader (header, fits);
    6082    psFitsWriteTable (fits, theader, table);
    61     psFitsClose (fits);
    6283
    63     psFree (header);
    64     psFree (image);
    65     exit (0);
    66 }
     84# endif
  • trunk/psphot/src/psphotTestArguments.c

    r5993 r6117  
    88  psArgumentVerbosity (argc, argv);
    99
    10   if (*argc != 4) usage ();
     10  if (*argc != 7) usage ();
    1111
    1212  return;
     
    1515static int usage () {
    1616
    17     fprintf (stderr, "USAGE: psphotTest (input.fits) (output.hdr) (out.fits)\n");
     17    fprintf (stderr, "USAGE: psphotTest (input.fits) (output.jpg) (zero) (scale) (colormap) (rebin)\n");
    1818    exit (2);
    1919}
Note: See TracChangeset for help on using the changeset viewer.