IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17672


Ignore:
Timestamp:
May 13, 2008, 4:56:38 PM (18 years ago)
Author:
eugene
Message:

substantial work on argument handling to support externally supplied images

Location:
branches/eam_branch_20080511/ppSim
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080511/ppSim/configure.ac

    r14186 r17672  
    1717AC_SYS_LARGEFILE
    1818
    19 PKG_CHECK_MODULES([PSLIB], [pslib >= 1.0.0])
     19PKG_CHECK_MODULES([PSLIB],    [pslib >= 1.0.0])
    2020PKG_CHECK_MODULES([PSMODULE], [psmodules >= 1.0.0])
    21 PKG_CHECK_MODULES([PSASTRO], [psastro >= 0.9.0])
     21PKG_CHECK_MODULES([PSPHOT],   [psphot >= 0.8.0])
     22PKG_CHECK_MODULES([PSASTRO],  [psastro >= 0.9.0])
    2223
    2324IPP_STDOPTS
  • branches/eam_branch_20080511/ppSim/src/Makefile.am

    r17630 r17672  
    11bin_PROGRAMS = ppSim ppSimSequence
    22
    3 ppSim_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSASTRO_CFLAGS) $(ppSim_CFLAGS)
    4 ppSim_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS) $(PSASTRO_LIBS)
     3ppSim_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSPHOT_CFLAGS) $(PSASTRO_CFLAGS) $(ppSim_CFLAGS)
     4ppSim_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS) $(PSPHOT_LIBS) $(PSASTRO_LIBS)
    55ppSim_SOURCES = \
    66        ppSim.c                 \
  • branches/eam_branch_20080511/ppSim/src/ppSim.c

    r17615 r17672  
    11# include "ppSim.h"
     2
     3int failure (pmConfig *config, psExit status, char *message) {
     4    psErrorStackPrint(stderr, message);
     5    psFree(config);
     6    pmModelClassCleanup();
     7    psLibFinalize();
     8    exit (status);
     9}
    210
    311int main(int argc, char *argv[])
     
    816    pmConfig *config = pmConfigRead(&argc, argv, PPSIM_RECIPE); // Configuration
    917    if (!config) {
    10         psErrorStackPrint(stderr, "Unable to read configurations.");
    11         exit(PS_EXIT_CONFIG_ERROR);
     18        failure (config, PS_EXIT_CONFIG_ERROR, "Unable to read configurations.");
    1219    }
    1320
    14     ppSimArguments(argc, argv, config);
     21    if (!ppSimArguments(argc, argv, config)) {
     22        failure (config, PS_EXIT_CONFIG_ERROR, "Error parsing command-line arguments");
     23    }
    1524
    1625    if (!ppSimCreate(config)) {
    17         psErrorStackPrint(stderr, "Unable to create output file.");
    18         psFree(config);
    19         exit(PS_EXIT_CONFIG_ERROR);
     26        failure (config, PS_EXIT_CONFIG_ERROR, "Unable to create output file.");
    2027    }
    2128
    2229    if (!ppSimLoop(config)) {
    23         psErrorStackPrint(stderr, "Unable to generate data.");
    24         psFree(config);
    25         exit(PS_EXIT_SYS_ERROR);
     30        failure (config, PS_EXIT_SYS_ERROR, "Unable to generate data.");
    2631    }
    2732
     
    3237    psLibFinalize();
    3338
    34     return PS_EXIT_SUCCESS;
     39    exit (PS_EXIT_SUCCESS);
    3540}
  • branches/eam_branch_20080511/ppSim/src/ppSim.h

    r17630 r17672  
    1313#include <psmodules.h>
    1414#include <psastro.h>
     15#include <psphot.h>
    1516
    1617#define PPSIM_RECIPE "PPSIM"
     
    1819
    1920// Compare a value with minimum and maximum values, replacing where required.
    20 #define COMPARE(VALUE,MIN,MAX) { \
    21         if (VALUE < MIN) { MIN = VALUE; } \
    22         if (VALUE > MAX) { MAX = VALUE; } \
     21#define COMPARE(VALUE,MIN,MAX) {                \
     22        if (VALUE < MIN) { MIN = VALUE; }       \
     23        if (VALUE > MAX) { MAX = VALUE; }       \
    2324    }
    2425
     
    7071
    7172/// Parse command-line arguments
    72 void ppSimArguments(int argc, char *argv[], ///< Command-line arguments
     73bool ppSimArguments(int argc, char **argv, ///< Command-line arguments
    7374                    pmConfig *config ///< Configuration
    74                     );
     75    );
    7576
    7677/// Create output file
     
    7879/// Returns a borrowed pointer to the FPA file.
    7980pmFPAfile *ppSimCreate(pmConfig *config ///< Configuration
    80                        );
     81    );
    8182
    8283// Return bounds of a chip, based on the concepts
    8384psRegion *ppSimChipBounds(const pmChip *chip, // Chip for which to determine size
    8485                          pmFPAview *view // View for chip
    85                           );
     86    );
    8687
    8788// Return bounds of an FPA, based on the concepts
    8889psRegion *ppSimFPABounds(const pmFPA *fpa       // FPA for which to determine size
    89                          );
     90    );
    9091
    9192/// Loop over the output file, generating simulated data
    9293bool ppSimLoop(pmConfig *config ///< Configuration
    93                  );
     94    );
    9495
    9596psVector *ppSimMakeBiassec (pmCell *cell, pmConfig *config);
     
    9899bool ppSimMakeSky (pmReadout *readout, psImage *expCorr, ppSimType type, pmConfig *config);
    99100
    100 psArray *ppSimLoadSpots (pmFPA *fpa, pmConfig *config);
     101bool ppSimLoadSpots (pmFPA *fpa, pmConfig *config);
    101102
    102103bool ppSimLoadStars (psArray *stars, pmFPA *fpa, pmConfig *config);
     
    147148float ppSimMagToFlux (float mag, float zp);
    148149
     150float ppSimArgToRecipeF32(bool *status,
     151                          psMetadata *options,    // Target to which to add value
     152                          const char *recipeName, // Name for value in the recipe
     153                          psMetadata *arguments,  // Command-line arguments
     154                          const char *argName    // Argument name in the command-line arguments
     155    );
     156
     157int ppSimArgToRecipeS32(bool *status,
     158                        psMetadata *options,    // Target to which to add value
     159                        const char *recipeName, // Name for value in the recipe
     160                        psMetadata *arguments,  // Command-line arguments
     161                        const char *argName      // Argument name in the command-line arguments
     162    );
     163
     164char *ppSimArgToRecipeStr(bool *status,
     165                          psMetadata *options,    // Target to which to add value
     166                          const char *recipeName, // Name for value in the recipe
     167                          psMetadata *arguments,  // Command-line arguments
     168                          const char *argName    // Argument name in the command-line arguments
     169    );
     170
     171ppSimType ppSimTypeFromString (char *typeStr);
     172char *ppSimTypeToString (ppSimType type);
     173
     174float ppSimGetZeroPoint (psMetadata *recipe, char *filter);
     175
    149176#endif
  • branches/eam_branch_20080511/ppSim/src/ppSimArguments.c

    r17557 r17672  
    1 #include "ppSim.h"
     1# include "ppSim.h"
    22
    33// Print usage information and die
     
    1818}
    1919
    20 // Get a value from the command-line arguments and add it to recipe options
    21 bool valueArgRecipe(psMetadata *options,    // Target to which to add value
    22                     const char *recipeName, // Name for value in the recipe
    23                     psMetadata *arguments,  // Command-line arguments
    24                     const char *argName     // Argument name in the command-line arguments
    25     )
     20// this function supplements the RECIPE:OPTIONS folder with command-line options
     21bool ppSimArguments(int argc, char **argv, pmConfig *config)
    2622{
    27     bool status;                                                    // Status of MD lookup
    28     float value = psMetadataLookupF32(&status, arguments, argName); // Value of interest
    29     if (isnan(value)) return true;
    30     status = psMetadataAddF32(options, PS_LIST_TAIL, recipeName, 0, NULL, value);
    31     return status;
    32 }
    33 
    34 // this function supplements the RECIPE:OPTIONS folder with command-line options
    35 void ppSimArguments(int argc, char *argv[], pmConfig *config)
    36 {
     23    bool status;
    3724    bool mdok;                          // Status of MD lookup
    3825
    3926    assert(config);
    4027
    41     // save the following command-line options in the arguments structure
     28    // save the following command-line options in the arguments structure.  these will later be
     29    // parsed and moved to the config->recipes:PPSIM_RECIPE folder
     30
    4231    psMetadata *arguments = psMetadataAlloc(); // Command-line arguments
    4332    psMetadataAddStr(arguments, PS_LIST_TAIL, "-format", 0, "Camera format name", NULL);
     
    7160
    7261    pmConfigFileSetsMD (config->arguments, &argc, argv, "PSPHOT.PSF", "-psf", "-psflist");
    73 
    74     // only one of -camera and -file is needed
    75     bool status = pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list");
    76     if (!config->camera && !status) {
    77         psErrorStackPrint(stderr, "A camera name (-camera NAME) or an image (-file NAME) must be specified");
    78         exit(PS_EXIT_CONFIG_ERROR);
     62    if (psErrorCodeLast () != PS_ERR_NONE) { psAbort ("problem with PSPHOT.PSF option"); }
     63
     64    // Only one of -camera and -file is needed or allowed.  The -camera option would have been
     65    // already parsed by pmConfigRead in ppSim.c and resulted in a value for config->camera
     66    bool loadImage = pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list");
     67    if (!config->camera && !loadImage) {
     68        psError(PS_ERR_IO, true, "A camera name (-camera NAME) or an image (-file NAME) must be specified");
     69        psFree(arguments);
     70        return false;
     71    }
     72    if (config->camera && loadImage) {
     73        psError(PS_ERR_IO, true, "Only one of (-camera NAME) and (-file NAME) may be specified");
     74        psFree(arguments);
     75        return false;
    7976    }
    8077
    8178    if (!psArgumentParse(arguments, &argc, argv)) {
    82         exit(PS_EXIT_CONFIG_ERROR);
     79        psError(PS_ERR_IO, false, "error in command-line arguments");
     80        psFree(arguments);
     81        return false;
    8382    }
    8483
    8584    if (argc != 2) {
    86         psErrorStackPrint(stderr, "Missing output filename");
    87         exit(PS_EXIT_CONFIG_ERROR);
     85        psError(PS_ERR_IO, true, "Missing output filename");
     86        psFree(arguments);
     87        return false;
     88    }
     89
     90    // output filename
     91    psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "Name of the output image", argv[1]);
     92
     93    // save the additional recipe values based on command-line options. These options override
     94    // the PPSIM recipe values loaded from recipe files
     95    psMetadata *options = pmConfigRecipeOptions (config, PPSIM_RECIPE);
     96    if (!options) {
     97        psError(PS_ERR_IO, false, "Unable to find recipe options for %s", PPSIM_RECIPE);
     98        psFree(arguments);
     99        return false;
     100    }
     101
     102    // these arguments may be used whether the input image is created or loaded
     103    ppSimArgToRecipeF32(&status, options, "STARS.LUM",     arguments, "-starslum");
     104    ppSimArgToRecipeF32(&status, options, "STARS.MAG",     arguments, "-starsmag");
     105    ppSimArgToRecipeF32(&status, options, "STARS.DENSITY", arguments, "-starsdensity");
     106
     107    // if we are loading the input image (not creating it), then we can skip the remaining arguments
     108    if (loadImage) {
     109        // if we are supplying an input image, it is so we may supply fake stars; force it to
     110        // be treated as an OBJECT image.
     111        psMetadataAddStr(options, PS_LIST_TAIL, "IMAGE.TYPE", 0, "Exposure type", "OBJECT");
     112
     113        // check for these options as well
     114        ppSimArgToRecipeStr(&status, options, "PSF.MODEL",    arguments, "-psfclass"); // PSF model class
     115        ppSimArgToRecipeStr(&status, options, "GALAXY.MODEL", arguments, "-galmodel"); // Galaxy model name
     116
     117        // 'seeing' is not required: we can load a psf-model instead; but if not, it is allowed
     118        ppSimArgToRecipeF32(&status, options, "SEEING", arguments, "-seeing"); // seeing (FWHM in arcsec)
     119
     120        // 'scale' is not required: we can use the WCS instead; but if not, it is allowed
     121        ppSimArgToRecipeF32(&status, options, "PIXEL.SCALE", arguments, "-scale"); // Plate scale
     122
     123        psFree (arguments);
     124        return true;
    88125    }
    89126
     
    96133        psMetadata *formats = psMetadataLookupMetadata(NULL, config->camera, "FORMATS"); // The camera formats
    97134        if (!formats) {
    98             psErrorStackPrint(stderr, "Unable to find FORMATS in camera configuration.");
     135            psError(PS_ERR_IO, false, "Unable to find FORMATS in camera configuration.");
    99136            psFree(arguments);
    100             psFree(config);
    101             exit(PS_EXIT_CONFIG_ERROR);
     137            return false;
    102138        }
    103139        psMetadata *format = psMetadataLookupMetadata(NULL, formats, formatName); // Format of interest
    104140        if (!format) {
    105             psErrorStackPrint(stderr, "Unable to find format %s in camera FORMATS.", formatName);
     141            psError(PS_ERR_IO, false, "Unable to find format %s in camera FORMATS.", formatName);
    106142            psFree(arguments);
    107             psFree(config);
    108             exit(PS_EXIT_CONFIG_ERROR);
     143            return false;
    109144        }
    110145        config->format = psMemIncrRefCounter(format);
    111146    }
    112147
    113     // specify the type of simulated image to produce
    114     // XXX this should not be required if we supplied INPUT
    115     const char *typeStr = psMetadataLookupStr(NULL, arguments, "-type"); // Exposure type
    116     if (!typeStr) {
    117         psErrorStackPrint(stderr, "An exposure type must be specified using -type");
    118         exit(PS_EXIT_CONFIG_ERROR);
    119     }
    120     ppSimType type = PPSIM_TYPE_NONE;   // Type to simulate
    121     if (strcasecmp(typeStr, "BIAS") == 0) {
    122         type = PPSIM_TYPE_BIAS;
    123     } else if (strcasecmp(typeStr, "DARK") == 0) {
    124         type = PPSIM_TYPE_DARK;
    125     } else if (strcasecmp(typeStr, "FLAT") == 0) {
    126         type = PPSIM_TYPE_FLAT;
    127     } else if (strcasecmp(typeStr, "OBJECT") == 0) {
    128         type = PPSIM_TYPE_OBJECT;
     148    char *typeStr = ppSimArgToRecipeStr (&status, options, "IMAGE.TYPE", arguments, "-type"); // Requested exposure type
     149    if (!status) {
     150        psError(PS_ERR_IO, false, "An exposure type must be specified using -type");
     151        psFree(arguments);
     152        return false;
     153    }
     154    ppSimType type = ppSimTypeFromString (typeStr);
     155
     156    char *filter = ppSimArgToRecipeStr(&status, options, "FILTER", arguments, "-filter"); // Filter name
     157
     158    // set the exposure time
     159    if (type == PPSIM_TYPE_BIAS) {
     160        psMetadataAddF32(options, PS_LIST_TAIL, "EXPTIME", 0, "Exposure time (s)", 0.0);
    129161    } else {
    130         psErrorStackPrint(stderr, "Unrecognised exposure type: %s", typeStr);
    131         exit(PS_EXIT_CONFIG_ERROR);
    132     }
    133     assert(type != PPSIM_TYPE_NONE);
    134     psMetadataAddS32(config->arguments, PS_LIST_TAIL, "TYPE", 0, "Exposure type", type);
    135 
    136     const char *filter = psMetadataLookupStr(NULL, arguments, "-filter"); // Filter name
    137     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "FILTER", 0, "Filter name", filter);
    138 
    139     // save the following additional recipe values based on command-line options
    140     // these options override the PPSIM recipe values loaded from recipe files
    141     psMetadata *options = pmConfigRecipeOptions (config, PPSIM_RECIPE);
    142     if (!options) {
    143         psErrorStackPrint(stderr, "Unable to find recipe options for %s", PPSIM_RECIPE);
    144         psFree(arguments);
    145         psFree(config);
    146         exit(PS_EXIT_CONFIG_ERROR);
    147     }
    148 
    149     float expTime;
    150     if (type == PPSIM_TYPE_BIAS) {
    151         expTime = 0.0;
    152     } else {
    153         expTime = psMetadataLookupF32(NULL, arguments, "-exptime"); // Exposure time
    154         if (isnan(expTime)) {
    155             psErrorStackPrint(stderr, "The exposure time must be specified using -exptime");
    156             exit(PS_EXIT_CONFIG_ERROR);
    157         }
    158     }
    159     psMetadataAddF32(options, PS_LIST_TAIL, "EXPTIME", 0, "Exposure time (s)", expTime);
     162        ppSimArgToRecipeF32(&status, options, "EXPTIME", arguments, "-exptime");
     163        if (!status) {
     164            psError(PS_ERR_IO, false, "The exposure time must be specified using -exptime");
     165            psFree(arguments);
     166            return false;
     167        }
     168    }
    160169
    161170    // these values all get moved from arguments to RECIPE:OPTIONS
    162     valueArgRecipe(options, "BIAS.LEVEL",    arguments, "-biaslevel");
    163     valueArgRecipe(options, "BIAS.RANGE",    arguments, "-biasrange");
    164     valueArgRecipe(options, "DARK.RATE",     arguments, "-darkrate");
    165     valueArgRecipe(options, "FLAT.SIGMA",    arguments, "-flatsigma");
    166     valueArgRecipe(options, "FLAT.RATE",     arguments, "-flatrate");
    167     valueArgRecipe(options, "SHUTTER.TIME",  arguments, "-shuttertime");
    168     valueArgRecipe(options, "SKY.RATE",      arguments, "-skyrate");
    169     valueArgRecipe(options, "STARS.LUM",     arguments, "-starslum");
    170     valueArgRecipe(options, "STARS.MAG",     arguments, "-starsmag");
    171     valueArgRecipe(options, "STARS.DENSITY", arguments, "-starsdensity");
     171    ppSimArgToRecipeF32(&status, options, "BIAS.LEVEL",    arguments, "-biaslevel");
     172    ppSimArgToRecipeF32(&status, options, "BIAS.RANGE",    arguments, "-biasrange");
     173    ppSimArgToRecipeF32(&status, options, "DARK.RATE",     arguments, "-darkrate");
     174    ppSimArgToRecipeF32(&status, options, "FLAT.SIGMA",    arguments, "-flatsigma");
     175    ppSimArgToRecipeF32(&status, options, "FLAT.RATE",     arguments, "-flatrate");
     176    ppSimArgToRecipeF32(&status, options, "SHUTTER.TIME",  arguments, "-shuttertime");
     177    ppSimArgToRecipeF32(&status, options, "SKY.RATE",      arguments, "-skyrate");
     178    ppSimArgToRecipeS32(&status, options, "BINNING",       arguments, "-bin");
    172179
    173180    psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSIM_RECIPE); // Recipe
    174 
    175     int biasOrder = psMetadataLookupS32(&mdok, recipe, "BIAS.ORDER"); // Overscan polynomial order
    176     if (!mdok) {
    177         psWarning("BIAS.ORDER(S32) is not set in the recipe %s --- assuming %d", PPSIM_RECIPE, biasOrder);
    178     }
    179     psMetadataAddS32(options, PS_LIST_TAIL, "BIAS.ORDER", 0, "Overscan polynomial order", biasOrder);
    180 
    181     int binning = psMetadataLookupS32(NULL, arguments, "-bin"); // Binning in x and y
    182     if (binning <= 0) {
    183         psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Binning (%d) is non-positive.", binning);
    184         exit(PS_EXIT_CONFIG_ERROR);
    185     }
    186     psMetadataAddS32(config->arguments, PS_LIST_TAIL, "BINNING", 0, "Binning in x and y", binning);
    187 
    188     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "Name of the output image", argv[1]);
    189181
    190182    if (type == PPSIM_TYPE_OBJECT) {
     
    197189        // XXX scale and zp should be supplied by the config file (allow override, but this is camera-dependent)
    198190        if (isnan(ra0) || isnan(dec0) || isnan(pa) || isnan(seeing)) {
    199             psErrorStackPrint(stderr, "-ra, -dec, -pa, -scale, -zp, -seeing must be specified for OBJECT type");
    200             exit(PS_EXIT_CONFIG_ERROR);
    201         }
    202 
    203         float zp = psMetadataLookupF32(NULL, arguments, "-zp"); // Zero point
    204         if (isnan(zp)) {
    205             // use the filter to get the zeropoint from the recipe
    206             psMetadataItem *zpItem = psMetadataLookup (recipe, "ZEROPTS");
    207             // check that item is multi...
    208            
    209             psArray *entries = psListToArray (zpItem->data.list);
    210          
    211             // search for matching filter
    212             for (int i = 0; i < entries->n; i++) {
    213                 psMetadataItem *item = entries->data[i];
    214                 psMetadata *entry = item->data.V;
    215 
    216                 char *filterName = psMetadataLookupStr (&status, entry, "FILTER");
    217                 assert (filterName);
    218 
    219                 if (strcmp(filterName, filter)) continue;
    220 
    221                 zp = psMetadataLookupF32 (&status, entry, "ZERO_PT");
    222                 assert (status);
    223                 break;
    224             }
    225             psFree (entries);
    226         }
    227 
    228         float scale   = psMetadataLookupF32(NULL, arguments, "-scale"); // Plate scale
    229         if (isnan(scale)) {
    230             scale = psMetadataLookupF32 (&status, recipe, "PIXEL.SCALE");
    231         }
    232 
    233         float skymags = psMetadataLookupF32(NULL, arguments, "-skymags"); // Position angle
    234         if (isnan(skymags)) {
    235             skymags = psMetadataLookupF32 (&status, recipe, "SKY.MAGS");
    236         }
    237 
     191            psError(PS_ERR_IO, false, "-ra, -dec, -pa, -scale, -zp, -seeing must be specified for OBJECT type");
     192            psFree(arguments);
     193            return false;
     194        }
     195
     196        float scale = ppSimArgToRecipeF32(&status, options, "PIXEL.SCALE", arguments, "-scale"); // Plate scale
     197        ppSimArgToRecipeF32(&status, options, "SKY.MAGS", arguments, "-skymags"); // Plate scale
     198        ppSimArgToRecipeStr(&status, options, "PSF.MODEL",    arguments, "-psfclass"); // PSF model class
     199        ppSimArgToRecipeStr(&status, options, "GALAXY.MODEL", arguments, "-galmodel"); // Galaxy model name
     200
     201        // the user supplies FWHM in arcsec; here we convert to Sigma in pixels
     202        psMetadataAddF32(options, PS_LIST_TAIL, "SEEING", 0, "Seeing SIGMA (pixels)", seeing / 2.0 / sqrt(2.0 * log(2.0)) / scale);
    238203        psMetadataAddF32(options, PS_LIST_TAIL, "RA", 0, "Boresight RA (radians)", ra0 * M_PI / 180.0);
    239204        psMetadataAddF32(options, PS_LIST_TAIL, "DEC", 0, "Boresight Declination (radians)", dec0 * M_PI / 180.0);
    240205        psMetadataAddF32(options, PS_LIST_TAIL, "PA", 0, "Boresight position angle (radians)",pa * M_PI / 180.0);
    241206
    242         // the user supplies FWHM in arcsec; here we convert to Sigma in pixels
    243         psMetadataAddF32(options, PS_LIST_TAIL, "SEEING", 0, "Seeing SIGMA (pixels)", seeing / 2.0 / sqrt(2.0 * log(2.0)) / scale);
    244 
    245         psMetadataAddF32(options, PS_LIST_TAIL, "SCALE", 0, "Plate scale (arcsec/pix)", scale);
    246         psMetadataAddF32(options, PS_LIST_TAIL, "ZEROPOINT", 0, "Photometric zeropoint", zp);
    247         psMetadataAddF32(options, PS_LIST_TAIL, "SKY.MAGS", 0, "sky surface brightness", skymags);
    248 
    249         const char *psfClass = psMetadataLookupStr(NULL, arguments, "-psfclass"); // PSF model class
    250         psMetadataAddStr(config->arguments, PS_LIST_TAIL, "PSF.MODEL", 0, "PSF model class", psfClass);
    251 
    252         const char *galModel = psMetadataLookupStr(NULL, arguments, "-galmodel"); // Galaxy model name
    253         psMetadataAddStr(config->arguments, PS_LIST_TAIL, "GALAXY.MODEL", 0, "Galaxy model", galModel);
     207        assert (filter != NULL);
     208
     209        ppSimArgToRecipeF32(&status, options, "ZEROPOINT", arguments, "-zp"); // Zero point
     210        if (!status) {
     211            float zp = ppSimGetZeroPoint (recipe, filter);
     212            psMetadataAddF32(options, PS_LIST_TAIL, "ZEROPOINT", 0, "Photometric zeropoint", zp);
     213        }
    254214    }
    255215
    256216    psFree(arguments);
    257     return;
     217    return true;
    258218}
    259219
     
    262222   PSPHOT.PSF
    263223   INPUT
    264    TYPE
    265    FILTER
    266    BIAS.ORDER
    267    BINNING
    268224   OUTPUT
    269    PSF.MODEL
    270    GALAXY.MODEL
    271 
    272    all othr values should come from the recipe
     225
     226   all other values should come from the recipe
    273227*/
  • branches/eam_branch_20080511/ppSim/src/ppSimCreate.c

    r17630 r17672  
    11# include "ppSim.h"
    2 
    3 // XXX this function forces us to define the camera (on the command line) and format (via the
    4 // PPSIM.OUTPUT entry).  In this case, we need to set config->format,formatName based on these
    5 // values.  This will be a problem when we want to load an input image (in order to add fake
    6 // stars).  We will need to add some logic in ppSimArguments to distinguish the cases of 1)
    7 // input image and 2) specified camera
    82
    93pmFPAfile *ppSimCreate(pmConfig *config)
     
    3024            return NULL;
    3125        }
    32        
    3326    } else {
    3427        simImage = false;
     
    3730            return NULL;
    3831        }
    39         fpa = input->fpa;
     32        fpa = psMemIncrRefCounter (input->fpa);
    4033    }
    4134
    4235    // define the output image file -- this is the basis for the ppSimLoop
    43     pmFPAfile *file = pmFPAfileDefineOutput(config, fpa, OUTPUT_FILE);
    44     if (!file) {
     36    pmFPAfile *output = pmFPAfileDefineOutput(config, fpa, OUTPUT_FILE);
     37    if (!output) {
    4538        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to create output file from %s.  "
    4639                "Did you forget to specify the format?", OUTPUT_FILE);
    4740        return NULL;
    4841    }
    49     if (file->type != PM_FPA_FILE_IMAGE) {
     42    if (output->type != PM_FPA_FILE_IMAGE) {
    5043        psError(PS_ERR_BAD_PARAMETER_TYPE, true, "%s type is not IMAGE", OUTPUT_FILE);
    5144        psFree(fpa);
    52         psFree(file);
    5345        return NULL;
    5446    }
    5547    // XXX we should not require the output image to be written
    56     file->save = true;
     48    output->save = true;
    5749
    58     config->format = psMemIncrRefCounter (file->format);
    59     config->formatName = psStringCopy (file->formatName);
     50    config->format = psMemIncrRefCounter (output->format);
     51    config->formatName = psStringCopy (output->formatName);
     52
     53    psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe
    6054
    6155    // For photometry, we operate on the chip-mosaicked image.  we create a copy of the mosaicked
    6256    // image for psphot so we can write out a clean image
    63     if (options->doPhotom) {
     57    bool doPhotom = psMetadataLookupBool(&status, recipe, "PHOTOM"); // Density of fakes
     58    if (doPhotom) {
    6459
    6560        // we need a chip image if we perform photometry (is it necessary to build it if we don't use it?)
     
    6762        if (!chipImage) {
    6863            psError(PS_ERR_IO, false, _("Unable to generate new file from PPSIM.CHIP"));
    69             psFree(options);
     64            psFree(fpa);
    7065            return NULL;
    7166        }
    7267        if (chipImage->type != PM_FPA_FILE_IMAGE) {
    7368            psError(PS_ERR_IO, true, "PPSIM.CHIP is not of type IMAGE");
    74             psFree(options);
     69            psFree(fpa);
    7570            return NULL;
    7671        }
     
    8479        if (!psphotDefineFiles (config, psphotInput)) {
    8580            psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psphot");
    86             return false;
     81            psFree(fpa);
     82            return NULL;
    8783        }
    8884    } else {
     
    9288        if (psMetadataLookupPtr(NULL, config->arguments, "PSPHOT.PSF")) {
    9389            // tie the psf file to the chipMosaic
    94             pmFPAfileBindFromArgs(&status, file, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF");
     90            pmFPAfileBindFromArgs(&status, output, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF");
    9591            if (!status) {
    9692                psError(PS_ERR_UNKNOWN, false, "Failed to find/build PSPHOT.PSF.LOAD");
    9793                psFree(fpa);
    98                 psFree(file);
    9994                return NULL;
    10095            }
     
    10499    // PPSIM.SOURCES carries the constructed, fake sources with their true parameters
    105100    // XXX only invoke this code for OBJECT types of images
    106     pmFPAfile *simSources = pmFPAfileDefineOutput (config, file->fpa, "PPSIM.SOURCES");
     101    pmFPAfile *simSources = pmFPAfileDefineOutput (config, output->fpa, "PPSIM.SOURCES");
    107102    if (!simSources) {
    108103        psError(PS_ERR_UNKNOWN, false, "Cannot find a rule for PPSIM.SOURCES");
     
    113108    // if we have loaded an input image, we do not need to populate the fpa
    114109    if (!simImage) {
    115         return file;
     110        // we need to extract certain metadata from the image and populate the recipe.
     111        // or else we need to set the fpa concepts based on the recipe options...
     112
     113        psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe
     114
     115        ppSimArgToRecipeF32(&status, recipe, "EXPTIME", fpa->concepts, "FPA.EXPOSURE");
     116        char *filter = ppSimArgToRecipeStr(&status, recipe, "FILTER", fpa->concepts, "FPA.FILTER");
     117
     118        float zp = ppSimGetZeroPoint (recipe, filter);
     119        psMetadataAddF32(recipe, PS_LIST_TAIL, "ZEROPOINT", PS_META_REPLACE, "Photometric zeropoint", zp);
     120
     121        return output;
    116122    }
    117123
    118     pmFPALevel phuLevel = pmFPAPHULevel(file->format); // Level at which PHU goes
     124    pmFPALevel phuLevel = pmFPAPHULevel(output->format); // Level at which PHU goes
    119125
    120126    pmFPAview *view = pmFPAviewAlloc(0);// View for current level
    121127
    122128    if (phuLevel == PM_FPA_LEVEL_FPA) {
    123         if (!pmFPAAddSourceFromView(fpa, "Simulation", view, file->format)) {
     129        if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) {
    124130            psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
    125131            psFree(fpa);
    126132            psFree(view);
    127             psFree(file);
    128133            return NULL;
    129134        }
     
    133138    while ((chip = pmFPAviewNextChip(view, fpa, 1))) {
    134139        if (phuLevel == PM_FPA_LEVEL_CHIP) {
    135             if (!pmFPAAddSourceFromView(fpa, "Simulation", view, file->format)) {
     140            if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) {
    136141                psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
    137142                psFree(fpa);
    138143                psFree(view);
    139                 psFree(file);
    140144                return NULL;
    141145            }
     
    145149        while ((cell = pmFPAviewNextCell(view, fpa, 1))) {
    146150            if (phuLevel == PM_FPA_LEVEL_CELL) {
    147                 if (!pmFPAAddSourceFromView(fpa, "Simulation", view, file->format)) {
     151                if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) {
    148152                    psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
    149153                    psFree(fpa);
    150154                    psFree(view);
    151                     psFree(file);
    152155                    return NULL;
    153156                }
     
    159162    psFree(view);
    160163
    161     return file;
     164    return output;
    162165}
  • branches/eam_branch_20080511/ppSim/src/ppSimInsertGalaxies.c

    r17557 r17672  
    1010   
    1111    if (!galaxies->n) { return true; }
    12 
    13     // XXX is this needed?
    14     // pmFPAfile *simSources = psMetadataLookupPtr(NULL, config->files, "PPSIM.SOURCES"); // Output sources
    1512
    1613    pmCell *cell = readout->parent;
     
    3835    if (isnan(skyRate)) {
    3936        float zp      = psMetadataLookupF32(&mdok, recipe, "ZEROPOINT"); assert (mdok);
    40         float scale   = psMetadataLookupF32(&mdok, recipe, "SCALE");    assert (mdok);
     37        float scale   = psMetadataLookupF32(&mdok, recipe, "PIXEL.SCALE"); assert (mdok);
    4138        float skyMags = psMetadataLookupF32(&mdok, recipe, "SKY.MAGS");  assert (mdok);
    4239        skyRate = scale * scale * ppSimMagToFlux (skyMags, zp);
     
    5653    int yParityCell = psMetadataLookupS32(NULL, cell->concepts, "CELL.YPARITY");
    5754
    58     int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y
     55    int binning = psMetadataLookupS32(NULL, recipe, "BINNING"); // Binning in x and y
    5956
    6057    // determine the galaxy model
    61     char *modelName = psMetadataLookupStr(&mdok, config->arguments, "GALAXY.MODEL"); // galaxy model name
     58    char *modelName = psMetadataLookupStr(&mdok, recipe, "GALAXY.MODEL"); // galaxy model name
    6259    if (modelName == NULL) {
    6360        modelName = defaultModel;
  • branches/eam_branch_20080511/ppSim/src/ppSimInsertStars.c

    r17557 r17672  
    4343    if (isnan(skyRate)) {
    4444        float zp      = psMetadataLookupF32(&mdok, recipe, "ZEROPOINT"); assert (mdok);
    45         float scale   = psMetadataLookupF32(&mdok, recipe, "SCALE");     assert (mdok);
     45        float scale   = psMetadataLookupF32(&mdok, recipe, "PIXEL.SCALE");     assert (mdok);
    4646        float skyMags = psMetadataLookupF32(&mdok, recipe, "SKY.MAGS");  assert (mdok);
    4747        skyRate = scale * scale * ppSimMagToFlux (skyMags, zp);
     
    6161    int yParityCell = psMetadataLookupS32(NULL, cell->concepts, "CELL.YPARITY");
    6262
    63     int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y
     63    int binning = psMetadataLookupS32(NULL, recipe, "BINNING"); // Binning in x and y
    6464
    6565    pmPSF *psf = psMetadataLookupPtr (&mdok, chip->analysis, "PSPHOT.PSF");
  • branches/eam_branch_20080511/ppSim/src/ppSimLoadSpots.c

    r17628 r17672  
    22
    33bool ppSimLoadSpots (pmFPA *fpa, pmConfig *config) {
     4
     5# if (0)
    46
    57    bool mdok;
     
    6466    }
    6567
     68# endif
     69
    6670    // XXX these need to be saved on PSPHOT.INPUT.CMF
    6771    return true;
  • branches/eam_branch_20080511/ppSim/src/ppSimLoadStars.c

    r17557 r17672  
    1 #include "ppSim.h"
     1# include "ppSim.h"
    22
    33bool ppSimLoadStars (psArray *stars, pmFPA *fpa, pmConfig *config) {
     
    2424    float pa      = psMetadataLookupF32(NULL, recipe, "PA");        // Position angle (radians)
    2525    float seeing  = psMetadataLookupF32(NULL, recipe, "SEEING");    // Seeing SIGMA (pixels)
    26     float scale   = psMetadataLookupF32(NULL, recipe, "SCALE") * M_PI / 3600.0 / 180.0; // Plate scale (radians/pixel)
     26    float scale   = psMetadataLookupF32(NULL, recipe, "PIXEL.SCALE") * M_PI / 3600.0 / 180.0; // Plate scale (radians/pixel)
    2727    float expTime = psMetadataLookupF32(NULL, recipe, "EXPTIME");   // Exposure time (sec)
    2828
     
    4040    psMetadataAdd(astroRecipe, PS_LIST_TAIL, "DEC_MAX", PS_DATA_F32 | PS_META_REPLACE, "", dec0 + radius);
    4141    psArray *refStars = psastroLoadRefstars(config);
    42     if (!refStars || refStars->n == 0) {
     42    if (!refStars) {
    4343        psError(PS_ERR_UNKNOWN, false, "Unable to find reference stars.");
    4444        psFree(refStars);
  • branches/eam_branch_20080511/ppSim/src/ppSimLoop.c

    r17630 r17672  
    11#include "ppSim.h"
     2
     3# define ESCAPE(CODE,MSG) { \
     4  psError(CODE, false, MSG); \
     5  psFree (rng); \
     6  return false; }
    27
    38bool ppSimLoop(pmConfig *config)
     
    813    pmFPAfile *file = psMetadataLookupPtr(NULL, config->files, OUTPUT_FILE); // Output file
    914    assert(file);
     15
    1016    pmFPA *fpa = file->fpa;             // FPA for file
    1117    assert(fpa);
    1218
    13     ppSimType type = psMetadataLookupS32(NULL, config->arguments, "TYPE"); // Type of image to simulate
     19    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe
    1420
    1521    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0); // Random number generator
    1622
    17     int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y
    18 
    19     // Load forced-photometry positions
    20     if (type == PPSIM_TYPE_OBJECT) {
    21       psArray *spots = ppSimLoadSpots (fpa, config);
    22     }
    23 
    24     // Load catalogue stars
     23    char *typeStr = psMetadataLookupStr(NULL, recipe, "IMAGE.TYPE"); // Type of image to simulate
     24    ppSimType type = ppSimTypeFromString (typeStr); // Type of image to simulate
     25    int binning = psMetadataLookupS32(NULL, recipe, "BINNING"); // Binning in x and y
     26
    2527    psArray *stars = psArrayAllocEmpty (1);
    26     if (type == PPSIM_TYPE_OBJECT) {
    27         ppSimLoadStars (stars, fpa, config);
    28     }
    29 
    30     // Add random stars
    31     if (type == PPSIM_TYPE_OBJECT) {
    32         ppSimMakeStars (stars, fpa, config, rng);
    33     }
    34 
    35     // Add random galaxies
    3628    psArray *galaxies = psArrayAllocEmpty (1);
    3729    if (type == PPSIM_TYPE_OBJECT) {
    38         ppSimMakeGalaxies (galaxies, fpa, config, rng);
     30        // Load forced-photometry positions
     31        if (!ppSimLoadSpots (fpa, config)) ESCAPE (PS_ERR_UNKNOWN, "failed to load forced-photometry spots");
     32
     33        // Load catalogue stars
     34        if (!ppSimLoadStars (stars, fpa, config)) ESCAPE (PS_ERR_UNKNOWN, "failed to load catalog stars");
     35
     36        // Add random stars
     37        if (!ppSimMakeStars (stars, fpa, config, rng)) ESCAPE (PS_ERR_UNKNOWN, "failed to make random stars");
     38
     39        // Add random galaxies
     40        if (!ppSimMakeGalaxies (galaxies, fpa, config, rng)) ESCAPE (PS_ERR_UNKNOWN, "failed to make random galaxies");
    3941    }
    4042
     
    176178        }
    177179
    178         ppSimMosaicChip(config, blankMask, view, "PPSIM.CHIP", "PPSIM.OUTPUT");
    179 
    180180        // we perform photometry on the readouts of this chip in the output
    181181        ppSimPhotom (config, view);
  • branches/eam_branch_20080511/ppSim/src/ppSimMakeBias.c

    r17557 r17672  
    88
    99    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe
     10
     11    bool bias = psMetadataLookupBool(&status, recipe, "BIAS"); // Generate a Bias?
     12    if (!bias) return true;
    1013
    1114    float biasLevel = psMetadataLookupF32(NULL, recipe, "BIAS.LEVEL"); // Bias level
  • branches/eam_branch_20080511/ppSim/src/ppSimMakeDark.c

    r17557 r17672  
    1010
    1111    psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSIM_RECIPE); // Recipe
     12
     13    bool dark = psMetadataLookupBool(&status, recipe, "DARK"); // Generate a DARK?
     14    if (!dark) return true;
    1215
    1316    float darkRate = psMetadataLookupF32(NULL, recipe, "DARK.RATE"); // Dark rate
  • branches/eam_branch_20080511/ppSim/src/ppSimMakeGalaxies.c

    r17557 r17672  
    99
    1010    bool galaxyFake = psMetadataLookupBool(&mdok, recipe, "GALAXY.FAKE"); // Density of fakes
    11     if (!galaxyFake) return NULL;
     11    if (!galaxyFake) return true;
    1212
    1313    float galaxyLum       = psMetadataLookupF32(&mdok, recipe, "GALAXY.LUM"); // Galaxy luminosity func slope
     
    3535    float zp              = psMetadataLookupF32(&mdok, recipe, "ZEROPOINT"); // Photometric zero point
    3636    float seeing          = psMetadataLookupF32(&mdok, recipe, "SEEING"); // Seeing sigma (pix)
    37     float scale           = psMetadataLookupF32(&mdok, recipe, "SCALE") * M_PI / 3600.0 / 180.0; // Plate scale (radians/pixel)
     37    float scale           = psMetadataLookupF32(&mdok, recipe, "PIXEL.SCALE") * M_PI / 3600.0 / 180.0; // Plate scale (radians/pixel)
    3838    float skyRate         = psMetadataLookupF32(&mdok, recipe, "SKY.RATE"); // Sky rate
    3939    if (isnan(skyRate)) {
     
    4242    }
    4343
    44     if (galaxyDensity <= 0) return NULL;
     44    if (galaxyDensity <= 0) return true;
    4545
    4646    // Size of FPA
     
    6666        psLogMsg("ppSim", PS_LOG_INFO,
    6767                 "Image noise is above brightest random galaxy --- no random galaxy added.");
    68         return NULL;
     68        return true;
    6969    }
    7070
     
    138138        }
    139139    }
    140     return galaxies;
     140    return true;
    141141}
  • branches/eam_branch_20080511/ppSim/src/ppSimMakeSky.c

    r17557 r17672  
    1515    psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe
    1616
     17    bool sky = psMetadataLookupBool(&status, recipe, "SKY"); // Generate a SKY flux?
     18    if (!sky) return true;
     19 
    1720    float expTime     = psMetadataLookupF32(&status, recipe, "EXPTIME"); // Exposure time
    1821    float flatSigma   = psMetadataLookupF32(&status, recipe, "FLAT.SIGMA"); // Flat-field coefficient
     
    2225    if (isnan(skyRate)) {
    2326        float zp      = psMetadataLookupF32(&status, recipe, "ZEROPOINT"); assert (status);
    24         float scale   = psMetadataLookupF32(&status, recipe, "SCALE");    assert (status);
     27        float scale   = psMetadataLookupF32(&status, recipe, "PIXEL.SCALE"); assert (status);
    2528        float skyMags = psMetadataLookupF32(&status, recipe, "SKY.MAGS");  assert (status);
    2629        skyRate = scale * scale * ppSimMagToFlux (skyMags, zp);
     
    3740    int yParityCell   = psMetadataLookupS32(&status, cell->concepts, "CELL.YPARITY");
    3841
    39     int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y
     42    int binning = psMetadataLookupS32(NULL, recipe, "BINNING"); // Binning in x and y
    4043
    4144    // Size of FPA
  • branches/eam_branch_20080511/ppSim/src/ppSimMakeStars.c

    r17616 r17672  
    11# include "ppSim.h"
     2
     3# define ESCAPE(MSG) { \
     4  psError(PS_ERR_BAD_PARAMETER_VALUE, true, MSG); \
     5  return false; }
    26
    37bool ppSimMakeStars(psArray *stars, pmFPA *fpa, pmConfig *config, const psRandom *rng) {
     
    2327    float zp           = psMetadataLookupF32(&status, recipe, "ZEROPOINT"); // Photometric zero point
    2428    float seeing       = psMetadataLookupF32(&status, recipe, "SEEING"); // Seeing SIGMA (pixels)
    25     float scale        = psMetadataLookupF32(&status, recipe, "SCALE") * M_PI / 3600.0 / 180.0; // Plate scale (radians/pixel)
     29    float scale        = psMetadataLookupF32(&status, recipe, "PIXEL.SCALE") * M_PI / 3600.0 / 180.0; // Plate scale (radians/pixel)
     30
     31    if (isnan(darkRate)) darkRate = 0.0;
     32    if (isnan(expTime))  ESCAPE("EXPTIME is not defined");
     33    if (isnan(zp))       ESCAPE("ZEROPOINT is not defined");
     34    if (isnan(seeing))   ESCAPE("SEEING is not defined");
     35    if (isnan(scale))    ESCAPE("PIXEL.SCALE is not defined");
    2636
    2737    bool flatLum       = psMetadataLookupBool(&status,recipe, "STARS.FLAT.LUM"); // were real stars generated?
     
    4757        refMag = psMetadataLookupF32(&status, fpa->concepts, "STARS.REAL.MAG.PEAK"); // Star brightest magnitude
    4858        refSum = psMetadataLookupF32(&status, fpa->concepts, "STARS.REAL.SUM.PEAK"); // Star brightest magnitude
    49         assert (status);
     59
     60        // if we tried and failed to load reference stars, set more artificial limits
     61        if (!status) {
     62            refMag = brightMag;
     63            refSum = 1;
     64        }
    5065    } else {
    5166        refMag = brightMag;
  • branches/eam_branch_20080511/ppSim/src/ppSimPhotom.c

    r17628 r17672  
    88    pmReadout *readout;
    99
     10    psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe
     11
     12    bool doPhotom = psMetadataLookupBool(&status, recipe, "PHOTOM"); // Density of fakes
     13    if (!doPhotom) return true;
     14   
    1015    psphotModelClassInit ();
     16
     17    int blankMask = 0;          // XXX not sure what this should be set to...
     18    ppSimMosaicChip(config, blankMask, view, "PPSIM.CHIP", "PPSIM.OUTPUT");
    1119
    1220    // find or define a pmFPAfile PSPHOT.INPUT
  • branches/eam_branch_20080511/ppSim/src/ppSimSetPSF.c

    r17557 r17672  
    2121    float seeing   = psMetadataLookupF32(&status, recipe, "SEEING"); // Seeing SIGMA (pixels)
    2222
    23     char *psfModelName = psMetadataLookupStr(&status, config->arguments, "PSF.MODEL"); // Name of PSF model
     23    char *psfModelName = psMetadataLookupStr(&status, recipe, "PSF.MODEL"); // Name of PSF model
    2424    if (psfModelName == NULL) {
    2525        psfModelName = defaultModel;
  • branches/eam_branch_20080511/ppSim/src/ppSimUtils.c

    r17557 r17672  
    1515    float dec0  = psMetadataLookupF32(NULL, recipe, "DEC"); // Boresight Dec (radians)
    1616    float pa    = psMetadataLookupF32(NULL, recipe, "PA");  // Position angle (radians)
    17     float scale = psMetadataLookupF32(NULL, recipe, "SCALE"); // plate scale in arcsec / pixel
     17    float scale = psMetadataLookupF32(NULL, recipe, "PIXEL.SCALE"); // plate scale in arcsec / pixel
    1818    scale *= M_PI / 3600.0 / 180.0; // convert plate scale to radians/pixel
    1919
    20     int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y
     20    int binning = psMetadataLookupS32(NULL, recipe, "BINNING"); // Binning in x and y
    2121
    2222    float x0 = 0.0, y0 = 0.0;
     
    9595}
    9696
     97char *ppSimTypeToString (ppSimType type) {
     98
     99    char *typeStr;
     100
     101    switch (type) {
     102      case PPSIM_TYPE_BIAS:   typeStr = psStringCopy ("BIAS");   break;
     103      case PPSIM_TYPE_DARK:   typeStr = psStringCopy ("DARK");   break;
     104      case PPSIM_TYPE_FLAT:   typeStr = psStringCopy ("FLAT");   break;
     105      case PPSIM_TYPE_OBJECT: typeStr = psStringCopy ("OBJECT"); break;
     106      default:
     107        psAbort("Should never get here.");
     108    }
     109    return (typeStr);
     110}
     111
     112ppSimType ppSimTypeFromString (char *typeStr) {
     113
     114    if (!strcasecmp (typeStr, "BIAS"))   return PPSIM_TYPE_BIAS;
     115    if (!strcasecmp (typeStr, "DARK"))   return PPSIM_TYPE_DARK;
     116    if (!strcasecmp (typeStr, "FLAT"))   return PPSIM_TYPE_FLAT;
     117    if (!strcasecmp (typeStr, "OBJECT")) return PPSIM_TYPE_OBJECT;
     118    psAbort("Should never get here.");
     119}
     120
    97121bool ppSimUpdateConceptsFPA (pmFPA *fpa, pmConfig *config) {
    98122
     
    103127    float expTime = psMetadataLookupF32(NULL, recipe, "EXPTIME"); // Exposure time
    104128
    105     const char *filter = psMetadataLookupStr(NULL, config->arguments, "FILTER"); // Filter name
     129    const char *filter = psMetadataLookupStr(NULL, recipe, "FILTER"); // Filter name
    106130    if (!filter) {
    107131        filter = "NONE";
    108132    }
    109133
    110     ppSimType type = psMetadataLookupS32(NULL, config->arguments, "TYPE"); // Type of image to simulate
    111 
    112     // Update FPA concepts
    113     const char *typeStr;                // Exposure type String
    114     switch (type) {
    115       case PPSIM_TYPE_BIAS:   typeStr = "BIAS";   break;
    116       case PPSIM_TYPE_DARK:   typeStr = "DARK";   break;
    117       case PPSIM_TYPE_FLAT:   typeStr = "FLAT";   break;
    118       case PPSIM_TYPE_OBJECT: typeStr = "OBJECT"; break;
    119       default:
    120         psAbort("Should never get here.");
    121     }
    122 
    123     psMetadataAddStr(fpa->concepts, PS_LIST_TAIL, "FPA.OBSTYPE", PS_META_REPLACE,
    124                      "Observation type", typeStr);
    125     psMetadataAddStr(fpa->concepts, PS_LIST_TAIL, "FPA.OBJECT", PS_META_REPLACE,
    126                      "Observation name", typeStr);
    127     psMetadataAddF32(fpa->concepts, PS_LIST_TAIL, "FPA.EXPTIME", PS_META_REPLACE,
    128                      "Exposure time (sec)", expTime);
     134    char *typeStr = psMetadataLookupStr(NULL, recipe, "IMAGE.TYPE"); // Type of image to simulate
     135
     136    psMetadataAddStr(fpa->concepts, PS_LIST_TAIL, "FPA.OBSTYPE", PS_META_REPLACE, "Observation type", typeStr);
     137    psMetadataAddStr(fpa->concepts, PS_LIST_TAIL, "FPA.OBJECT", PS_META_REPLACE, "Observation name", typeStr);
     138    psMetadataAddF32(fpa->concepts, PS_LIST_TAIL, "FPA.EXPOSURE", PS_META_REPLACE, "Exposure time (sec)", expTime);
    129139    psMetadataAddStr(fpa->concepts, PS_LIST_TAIL, "FPA.FILTERID", PS_META_REPLACE, "Filter name", filter);
    130140    psMetadataAddStr(fpa->concepts, PS_LIST_TAIL, "FPA.FILTER", PS_META_REPLACE, "Filter name", filter);
     
    139149    psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSIM_RECIPE); // Recipe
    140150
    141     int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y
     151    int binning = psMetadataLookupS32(NULL, recipe, "BINNING"); // Binning in x and y
    142152    float expTime = psMetadataLookupF32(NULL, recipe, "EXPTIME"); // Exposure time
    143153
     
    153163    return true;
    154164}
     165
     166bool ppSimRecipeValidation (pmConfig *config) {
     167
     168    bool status;
     169
     170    psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe
     171
     172    int binning = psMetadataLookupS32(&status, recipe, "BINNING"); // Binning in x and y
     173    if (binning <= 0) {
     174        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Binning (%d) is non-positive.", binning);
     175        exit(PS_EXIT_CONFIG_ERROR);
     176    }
     177    return true;
     178}
     179
     180// Get a value from the command-line arguments and add it to recipe options
     181float ppSimArgToRecipeF32(bool *status,
     182                          psMetadata *options,    // Target to which to add value
     183                          const char *recipeName, // Name for value in the recipe
     184                          psMetadata *arguments,  // Command-line arguments
     185                          const char *argName       // Argument name in the command-line arguments
     186    )
     187{
     188    bool myStatus;
     189    float value = psMetadataLookupF32(&myStatus, arguments, argName); // Value of interest
     190    if (status) { *status = myStatus; }
     191    if (isnan(value)) return value;
     192
     193    psMetadataAddF32(options, PS_LIST_TAIL, recipeName, PS_META_REPLACE, NULL, value);
     194    return value;
     195}
     196
     197// Get a value from the command-line arguments and add it to recipe options
     198int ppSimArgToRecipeS32(bool *status,
     199                        psMetadata *options,    // Target to which to add value
     200                        const char *recipeName, // Name for value in the recipe
     201                        psMetadata *arguments,  // Command-line arguments
     202                        const char *argName         // Argument name in the command-line arguments
     203    )
     204{
     205    bool myStatus;
     206    int value = psMetadataLookupS32(&myStatus, arguments, argName); // Value of interest
     207    if (status) { *status = myStatus; }
     208
     209    psMetadataAddS32(options, PS_LIST_TAIL, recipeName, PS_META_REPLACE, NULL, value);
     210    return value;
     211}
     212
     213// Get a value from the command-line arguments and add it to recipe options
     214char *ppSimArgToRecipeStr(bool *status,
     215                          psMetadata *options,    // Target to which to add value
     216                          const char *recipeName, // Name for value in the recipe
     217                          psMetadata *arguments,  // Command-line arguments
     218                          const char *argName       // Argument name in the command-line arguments
     219    )
     220{
     221    bool myStatus;
     222
     223    char *value = psMetadataLookupStr(&myStatus, arguments, argName); // Value of interest
     224    if (status) {
     225        *status = myStatus;
     226    }
     227    psMetadataAddStr(options, PS_LIST_TAIL, recipeName, PS_META_REPLACE, NULL, value);
     228    return value;
     229}
     230
     231float ppSimGetZeroPoint (psMetadata *recipe, char *filter) {
     232
     233    bool mdok;
     234    float zp;
     235
     236    // use the filter to get the zeropoint from the recipe
     237    psMetadataItem *zpItem = psMetadataLookup (recipe, "ZEROPTS");
     238    // check that item is multi...
     239           
     240    psArray *entries = psListToArray (zpItem->data.list);
     241         
     242    // search for matching filter
     243    for (int i = 0; i < entries->n; i++) {
     244        psMetadataItem *item = entries->data[i];
     245        psMetadata *entry = item->data.V;
     246
     247        char *filterName = psMetadataLookupStr (&mdok, entry, "FILTER");
     248        assert (filterName);
     249
     250        if (strcmp(filterName, filter)) continue;
     251
     252        zp = psMetadataLookupF32 (&mdok, entry, "ZERO_PT");
     253        assert (mdok);
     254        psFree (entries);
     255        return zp;
     256    }
     257    psFree (entries);
     258    return NAN;
     259}
Note: See TracChangeset for help on using the changeset viewer.