IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 7, 2008, 10:55:21 AM (18 years ago)
Author:
eugene
Message:

fix errors with star density normalizations and flux consistency

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppSim/src/ppSimArguments.c

    r16494 r17557  
    1818}
    1919
    20 // Get a value from the command-line arguments or the recipe, and add it to the target
    21 bool valueArgRecipe(pmConfig *config,   // Configuration
    22                     psMetadata *arguments, // Command-line arguments
    23                     const char *argName, // Argument name in the command-line arguments
    24                     const psMetadata *recipe, // Recipe
     20// Get a value from the command-line arguments and add it to recipe options
     21bool valueArgRecipe(psMetadata *options,    // Target to which to add value
    2522                    const char *recipeName, // Name for value in the recipe
    26                     psMetadata *target // Target to which to add value
     23                    psMetadata *arguments,  // Command-line arguments
     24                    const char *argName     // Argument name in the command-line arguments
    2725    )
    2826{
    29     float value = psMetadataLookupF32(NULL, arguments, argName); // Value of interest
    30     if (isnan(value)) {
    31         bool mdok;                      // Status of MD lookup
    32         value = psMetadataLookupF32(&mdok, recipe, recipeName);
    33         if (!mdok) {
    34             psErrorStackPrint(stderr, "Unable to find %s in recipe %s", recipeName, PPSIM_RECIPE);
    35             psFree((psPtr)arguments);
    36             psFree(config);
    37             exit(PS_EXIT_CONFIG_ERROR);
    38         }
    39     }
    40     return psMetadataAddF32(target, PS_LIST_TAIL, recipeName, 0, NULL, value);
     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;
    4132}
    4233
     34// this function supplements the RECIPE:OPTIONS folder with command-line options
    4335void ppSimArguments(int argc, char *argv[], pmConfig *config)
    4436{
     37    bool mdok;                          // Status of MD lookup
     38
    4539    assert(config);
    4640
     41    // save the following command-line options in the arguments structure
    4742    psMetadata *arguments = psMetadataAlloc(); // Command-line arguments
    4843    psMetadataAddStr(arguments, PS_LIST_TAIL, "-format", 0, "Camera format name", NULL);
     
    6863    psMetadataAddF32(arguments, PS_LIST_TAIL, "-starsdensity", 0, "Density of fake stars at magnitude", NAN);
    6964    psMetadataAddStr(arguments, PS_LIST_TAIL, "-psfclass", 0, "Type of PSF model", NULL);
     65    psMetadataAddStr(arguments, PS_LIST_TAIL, "-galmodel", 0, "Type of Galaxy model", NULL);
    7066    psMetadataAddS32(arguments, PS_LIST_TAIL, "-bin", 0, "Binning in x and y", 1);
    7167
     
    9288    }
    9389
     90    // apply an alternate camera format
    9491    psString formatName = psMetadataLookupStr(NULL, arguments, "-format"); // Name of format
    9592    if (formatName) {
     
    114111    }
    115112
     113    // specify the type of simulated image to produce
     114    // XXX this should not be required if we supplied INPUT
    116115    const char *typeStr = psMetadataLookupStr(NULL, arguments, "-type"); // Exposure type
    117116    if (!typeStr) {
     
    138137    psMetadataAddStr(config->arguments, PS_LIST_TAIL, "FILTER", 0, "Filter name", filter);
    139138
     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
    140149    float expTime;
    141150    if (type == PPSIM_TYPE_BIAS) {
     
    148157        }
    149158    }
    150     psMetadataAddF32(config->arguments, PS_LIST_TAIL, "EXPTIME", 0, "Exposure time (s)", expTime);
    151 
    152     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe for ppSim
    153     if (!recipe) {
    154         psErrorStackPrint(stderr, "Unable to find recipe %s", PPSIM_RECIPE);
    155         psFree(arguments);
    156         psFree(config);
    157         exit(PS_EXIT_CONFIG_ERROR);
    158     }
    159 
    160     valueArgRecipe(config, arguments, "-biaslevel",    recipe, "BIAS.LEVEL",    config->arguments);
    161     valueArgRecipe(config, arguments, "-biasrange",    recipe, "BIAS.RANGE",    config->arguments);
    162     valueArgRecipe(config, arguments, "-darkrate",     recipe, "DARK.RATE",     config->arguments);
    163     valueArgRecipe(config, arguments, "-flatsigma",    recipe, "FLAT.SIGMA",    config->arguments);
    164     valueArgRecipe(config, arguments, "-flatrate",     recipe, "FLAT.RATE",     config->arguments);
    165     valueArgRecipe(config, arguments, "-shuttertime",  recipe, "SHUTTER.TIME",  config->arguments);
    166     valueArgRecipe(config, arguments, "-skyrate",      recipe, "SKY.RATE",      config->arguments);
    167     valueArgRecipe(config, arguments, "-starslum",     recipe, "STARS.LUM",     config->arguments);
    168     valueArgRecipe(config, arguments, "-starsmag",     recipe, "STARS.MAG",     config->arguments);
    169     valueArgRecipe(config, arguments, "-starsdensity", recipe, "STARS.DENSITY", config->arguments);
    170 
    171     bool mdok;                          // Status of MD lookup
     159    psMetadataAddF32(options, PS_LIST_TAIL, "EXPTIME", 0, "Exposure time (s)", expTime);
     160
     161    // 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");
     172
     173    psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSIM_RECIPE); // Recipe
     174
    172175    int biasOrder = psMetadataLookupS32(&mdok, recipe, "BIAS.ORDER"); // Overscan polynomial order
    173176    if (!mdok) {
    174177        psWarning("BIAS.ORDER(S32) is not set in the recipe %s --- assuming %d", PPSIM_RECIPE, biasOrder);
    175178    }
    176     psMetadataAddS32(config->arguments, PS_LIST_TAIL, "BIAS.ORDER", 0,
    177                      "Overscan polynomial order", biasOrder);
     179    psMetadataAddS32(options, PS_LIST_TAIL, "BIAS.ORDER", 0, "Overscan polynomial order", biasOrder);
    178180
    179181    int binning = psMetadataLookupS32(NULL, arguments, "-bin"); // Binning in x and y
     
    190192        float ra0     = psMetadataLookupF32(NULL, arguments, "-ra"); // Right Ascension of boresight
    191193        float dec0    = psMetadataLookupF32(NULL, arguments, "-dec"); // Declination of boresight
    192         float pa      = psMetadataLookupF32(NULL, arguments, "-pa"); // Position angle
    193         float seeing  = psMetadataLookupF32(NULL, arguments, "-seeing"); // Zero point
     194        float pa      = psMetadataLookupF32(NULL, arguments, "-pa");  // Position angle
     195        float seeing  = psMetadataLookupF32(NULL, arguments, "-seeing"); // seeing (FWHM in arcsec)
    194196
    195197        // XXX scale and zp should be supplied by the config file (allow override, but this is camera-dependent)
     
    199201        }
    200202
    201         float zp      = psMetadataLookupF32(NULL, arguments, "-zp"); // Zero point
     203        float zp = psMetadataLookupF32(NULL, arguments, "-zp"); // Zero point
    202204        if (isnan(zp)) {
    203205            // use the filter to get the zeropoint from the recipe
     
    234236        }
    235237
    236         psMetadataAddF32(config->arguments, PS_LIST_TAIL, "RA", 0, "Boresight RA (radians)", ra0 * M_PI / 180.0);
    237         psMetadataAddF32(config->arguments, PS_LIST_TAIL, "DEC", 0, "Boresight Declination (radians)", dec0 * M_PI / 180.0);
    238         psMetadataAddF32(config->arguments, PS_LIST_TAIL, "PA", 0, "Boresight position angle (radians)",pa * M_PI / 180.0);
    239         psMetadataAddF32(config->arguments, PS_LIST_TAIL, "SEEING", 0, "Seeing sigma (pix)", seeing / 2.0 / sqrt(2.0 * log(2.0)) / scale);
    240 
    241         psMetadataAddF32(config->arguments, PS_LIST_TAIL, "SCALE", 0, "Plate scale (arcsec/pix)", scale);
    242         psMetadataAddF32(config->arguments, PS_LIST_TAIL, "ZEROPOINT", 0, "Photometric zeropoint", zp);
    243         psMetadataAddF32(config->arguments, PS_LIST_TAIL, "SKY.MAGS", 0, "sky surface brightness", skymags);
    244 
    245         const char *psfClass = psMetadataLookupStr(NULL, arguments, "-psfclass"); // Filter name
     238        psMetadataAddF32(options, PS_LIST_TAIL, "RA", 0, "Boresight RA (radians)", ra0 * M_PI / 180.0);
     239        psMetadataAddF32(options, PS_LIST_TAIL, "DEC", 0, "Boresight Declination (radians)", dec0 * M_PI / 180.0);
     240        psMetadataAddF32(options, PS_LIST_TAIL, "PA", 0, "Boresight position angle (radians)",pa * M_PI / 180.0);
     241
     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
    246250        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);
    247254    }
    248255
     
    250257    return;
    251258}
     259
     260/* the following elements come from the config->arguments:
     261   
     262   PSPHOT.PSF
     263   INPUT
     264   TYPE
     265   FILTER
     266   BIAS.ORDER
     267   BINNING
     268   OUTPUT
     269   PSF.MODEL
     270   GALAXY.MODEL
     271
     272   all othr values should come from the recipe
     273*/
Note: See TracChangeset for help on using the changeset viewer.