IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23259 for trunk/psModules


Ignore:
Timestamp:
Mar 10, 2009, 4:53:42 PM (17 years ago)
Author:
Paul Price
Message:

Changing API for psRandomAlloc() to make it easier to be deterministic. psRandomAlloc() now takes only a single argument, which is the generator type (only PS_RANDOM_TAUS is currently supported; others could easily be added). The seed used by the generator is set by psRandomSeed(). This allows us to use the same seed for the random number generator over multiple calls, which means that we can be deterministic by setting the seed. The old API for psRandomAlloc() is available using psRandomAllocSpecific(). Added to the configuration setup in psModules to include recording the random seed, and setting if desired. Updated all our products to use this API. Some fixes and updates to the configuration run-time information dumping. ppImage now dumps the configuration at the end, allowing the list of files in the run-time information to be set.

Location:
trunk/psModules
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/pmFPAMaskWeight.c

    r21363 r23259  
    331331
    332332    if (!psMemIncrRefCounter(rng)) {
    333         rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     333        rng = psRandomAlloc(PS_RANDOM_TAUS);
    334334    }
    335335
     
    371371
    372372    if (!psMemIncrRefCounter(rng)) {
    373         rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     373        rng = psRandomAlloc(PS_RANDOM_TAUS);
    374374    }
    375375
     
    532532
    533533    if (!psMemIncrRefCounter(rng)) {
    534         rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     534        rng = psRandomAlloc(PS_RANDOM_TAUS);
    535535    }
    536536
  • trunk/psModules/src/camera/pmFPA_JPEG.c

    r21183 r23259  
    154154
    155155    // measure the image statistics for scaling
    156     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     156    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS);
    157157    psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN);
    158158    stats->nSubsample = 10000;
  • trunk/psModules/src/config/pmConfig.c

    r23215 r23259  
    1313
    1414#include <stdio.h>
     15#include <stdlib.h>
    1516#include <string.h>
    1617#include <strings.h>            /* for strn?casecmp */
     
    2425#include <pslib.h>
    2526
    26 #include "pmConfig.h"
    2727#include "pmErrorCodes.h"
    2828#include "pmFPALevel.h"
    2929#include "pmConfigRecipes.h"
    3030#include "pmConfigCamera.h"
     31#include "pmConfigRun.h"
     32
     33#include "pmConfig.h"
    3134
    3235#ifdef HAVE_NEBCLIENT
     
    432435    // variable will contain the name of the configuration file.
    433436
    434     char *configFile = NULL;
    435     //
     437    char *configFile = NULL;            // Name of configuration file
     438
    436439    // First, try command line
    437     //
    438440    psS32 argNum = psArgumentGet(*argc, argv, "-ipprc");
    439441    if (argNum != 0) {
     
    447449        }
    448450    }
    449     //
     451
    450452    // Next, try environment variable
    451     //
    452453    if (!configFile) {
    453454        configFile = getenv(IPPRC_ENV);
    454455        if (configFile) {
    455             configFile = psStringCopy (configFile);
    456         }
    457     }
    458 
    459     //
     456            configFile = psStringCopy(configFile);
     457        }
     458    }
     459
    460460    // Last chance is ~/.ipprc
    461     //
    462461    if (!configFile) {
    463462        char *home = getenv("HOME");
     
    466465    }
    467466
    468     // We have the configuration filename; now we read and parse the config
    469     // file and store in psMetadata struct user.
     467    // Read and parse the config file and store in struct user.
    470468    // XXX move this section to pmConfigReadUser.c ?
    471 
    472469    if (!pmConfigFileRead(&config->user, configFile, "user")) {
    473470        psFree(config);
     
    477474    psFree(configFile);
    478475
    479     // XXX why was this being called here?  Is someone calling pmConfigRead multiple times?
    480     // pmConfigDone();
    481     assert (configPath == NULL);
     476    pmConfigRunCommand(config, *argc, argv);
    482477
    483478    // define the config-file search path (configPath).
     479    psAssert(configPath == NULL, "Configuration path is already defined.");
    484480    psString path = psMetadataLookupStr(NULL, config->user, "PATH");
    485     pmConfigSet (path);
     481    pmConfigSet(path);
    486482
    487483    // read the SITE file
     
    525521            psLogSetLevel(logLevel);
    526522        }
    527 
    528523
    529524        // Set logging format
     
    646641            psTimeInit(timeName);
    647642        }
     643    }
     644
     645    // Set the random number generator seed
     646    {
     647        psU64 seed = 0;                 // RNG seed
     648        int argNum = psArgumentGet(*argc, argv, "-seed"); // Argument number
     649        if (argNum > 0) {
     650            psArgumentRemove(argNum, argc, argv);
     651            if (argNum >= *argc) {
     652                psWarning("-seed command-line switch provided without the required seed value --- ignored.");
     653            } else {
     654                char *end = NULL;       // Pointer to end of consumed string
     655                seed = strtoll(argv[argNum], &end, 0);
     656                if (strlen(end) > 0) {
     657                    psError(PS_ERR_IO, true, "Unable to read random number generator seed: %s", argv[argNum]);
     658                    psFree(config);
     659                    return NULL;
     660                }
     661                psArgumentRemove(argNum, argc, argv);
     662            }
     663        }
     664        pmConfigRunSeed(config, seed);
    648665    }
    649666
  • trunk/psModules/src/config/pmConfigCamera.c

    r22700 r23259  
    213213    psStringAppend(&newName, "_%s-SKYCELL", name);
    214214    if (psMetadataLookup(oldCameras, newName)) {
     215        psFree(newName);
    215216        return true;
    216217    }
     
    469470    psStringAppend(&newName, "_%s-%s", name, mosaicLevel == PM_FPA_LEVEL_CHIP ? "CHIP" : "FPA");
    470471    if (psMetadataLookup(oldCameras, newName)) {
     472        psFree(newName);
    471473        return true;
    472474    }
  • trunk/psModules/src/config/pmConfigRecipes.h

    r12916 r23259  
    11/*  @file pmConfigRecipes.h
    22 *  @brief Configuration Recipe functions
    3  * 
     3 *
    44 *  @author ?, MHPCC
    55 *  @author Paul Price, IfA
    66 *  @author Eugene Magnier, IfA
    7  * 
     7 *
    88 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    99 *  @date $Date: 2007-04-19 02:10:12 $
     
    1313#ifndef PM_CONFIG_RECIPES_H
    1414#define PM_CONFIG_RECIPES_H
     15
     16#include <pmConfig.h>
    1517
    1618/// @addtogroup Config Configuration System
     
    2628
    2729
    28 bool pmConfigLoadRecipeArguments (int *argc, char **argv, pmConfig *config);
    29 bool pmConfigLoadRecipeOptions (int *argc, char **argv, pmConfig *config, char *flag);
    30 psMetadata *pmConfigRecipeOptions (pmConfig *config, char *recipe);
     30bool pmConfigLoadRecipeArguments(int *argc, char **argv, pmConfig *config);
     31bool pmConfigLoadRecipeOptions(int *argc, char **argv, pmConfig *config, char *flag);
     32psMetadata *pmConfigRecipeOptions(pmConfig *config, char *recipe);
    3133
    3234/// @}
  • trunk/psModules/src/config/pmConfigRun.c

    r23244 r23259  
    7272
    7373
    74 bool pmConfigRunCommand(pmConfig *config, int argc, const char **argv)
     74bool pmConfigRunCommand(pmConfig *config, int argc, char **argv)
    7575{
    7676    PS_ASSERT_PTR_NON_NULL(config, false);
     
    8181    psString command = NULL;
    8282    for (int i = 0; i < argc; i++) {
    83         psStringAppend(&command, "%s", argv[i]);
     83        psStringAppend(&command, "%s ", argv[i]);
    8484    }
    8585
     
    8989    return true;
    9090}
     91
     92
     93bool pmConfigRunSeed(pmConfig *config, psU64 seed)
     94{
     95    PS_ASSERT_PTR_NON_NULL(config, false);
     96
     97    psMetadata *run = configRun(config);// Run-time information
     98    psAssert(run, "Require run-time information");
     99
     100    if (!seed) {
     101        bool mdok;                          // Status of MD lookup
     102        seed = psMetadataLookupU64(&mdok, run, "SEED");
     103    }
     104    if (!seed) {
     105        bool mdok;                          // Status of MD lookup
     106        seed = psMetadataLookupU64(&mdok, config->user, "SEED");
     107    }
     108
     109    // seed may still be zero by this point
     110    seed = psRandomSeed(seed);
     111    return psMetadataAddU64(run, PS_LIST_TAIL, "SEED", PS_META_REPLACE, "Random number generator seed", seed);
     112}
     113
  • trunk/psModules/src/config/pmConfigRun.h

    r23243 r23259  
    44#include <pslib.h>
    55#include <pmConfig.h>
     6#include <pmFPAfile.h>
    67
    78/// Add a file to the list of files used in the run-time information
     
    1213
    1314/// Add the command line to the run-time information
    14 bool pmConfigRunCommand(pmConfig *config, ///< Configuration
    15                         int argc, const char **argv ///< Command line arguments
     15bool pmConfigRunCommand(
     16    pmConfig *config,                   ///< Configuration
     17    int argc, char **argv               ///< Command line arguments
     18    );
     19
     20/// Record the random number generator seed in the run-time information
     21bool pmConfigRunSeed(
     22    pmConfig *config,                   ///< Configuration
     23    psU64 seed                          ///< RNG seed
    1624    );
    1725
  • trunk/psModules/src/detrend/pmFringeStats.c

    r21183 r23259  
    6565        rng = psMemIncrRefCounter(random);
    6666    } else {
    67         rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     67        rng = psRandomAlloc(PS_RANDOM_TAUS);
    6868    }
    6969
  • trunk/psModules/src/detrend/pmRemnance.c

    r21183 r23259  
    2828    int numCols = image->numCols, numRows = image->numRows; // Size of image
    2929
    30     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0); // Random number generator
     30    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator
    3131
    3232    psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); // Statistics
  • trunk/psModules/src/detrend/pmShutterCorrection.c

    r21457 r23259  
    911911    psStats *stats = psStatsAlloc(meanStat | stdevStat); // Statistics to apply
    912912    if (!rng) {
    913         rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     913        rng = psRandomAlloc(PS_RANDOM_TAUS);
    914914    } else {
    915915        psMemIncrRefCounter(rng);
  • trunk/psModules/src/imcombine/pmSubtractionMatch.c

    r21422 r23259  
    214214    int numCols = ro1->image->numCols, numRows = ro1->image->numRows; // Image dimensions
    215215
    216     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0); // Random number generator
     216    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator
    217217
    218218    memCheck("start");
  • trunk/psModules/test/detrend/tap_pmMaskBadPixels.c

    r15160 r23259  
    282282        pmCell *cell = generateSimpleCell(NULL);
    283283        pmReadout *in = generateSimpleReadout(cell);
    284         psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     284        psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 0);
    285285
    286286        ok(!pmMaskFlagSuspectPixels(out, NULL, 1.0, 1, 1.0, rng), "pmMaskFlagSuspectPixels() returned NULL with NULL input pmReadout");
     
    301301        psFree(in->image);
    302302        in->image = NULL;
    303         psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     303        psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 0);
    304304        ok(!pmMaskFlagSuspectPixels(out, NULL, 1.0, 1, 1.0, rng), "pmMaskFlagSuspectPixels() returned NULL with NULL input pmReadout->image");
    305305        psFree(rng);
     
    319319        psFree(in->image);
    320320        in->image = psImageAlloc(0, 0, PS_TYPE_F32);
    321         psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     321        psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 0);
    322322        ok(!pmMaskFlagSuspectPixels(out, NULL, 1.0, 1, 1.0, rng), "pmMaskFlagSuspectPixels() returned NULL with empty input pmReadout->image");
    323323        psFree(rng);
     
    337337        psFree(in->image);
    338338        in->image = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_S32);
    339         psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     339        psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 0);
    340340        ok(!pmMaskFlagSuspectPixels(out, NULL, 1.0, 1, 1.0, rng), "pmMaskFlagSuspectPixels() returned NULL with incorrect type for pmReadout->image");
    341341        psFree(rng);
     
    355355        psFree(in->mask);
    356356        in->mask = psImageAlloc(0, 0, PS_TYPE_MASK);
    357         psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     357        psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 0);
    358358        ok(!pmMaskFlagSuspectPixels(out, NULL, 1.0, 1, 1.0, rng), "pmMaskFlagSuspectPixels() returned NULL with incorrect type for pmReadout->image");
    359359        psFree(rng);
     
    373373        psFree(in->mask);
    374374        in->mask = psImageAlloc(TEST_NUM_COLS/2, TEST_NUM_ROWS/2, PS_TYPE_MASK);
    375         psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     375        psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 0);
    376376        ok(!pmMaskFlagSuspectPixels(out, NULL, 1.0, 1, 1.0, rng), "pmMaskFlagSuspectPixels() returned NULL with bad size for in->mask");
    377377        psFree(rng);
     
    391391        psFree(in->mask);
    392392        in->mask = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_S32);
    393         psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     393        psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 0);
    394394        ok(!pmMaskFlagSuspectPixels(out, NULL, 1.0, 1, 1.0, rng), "pmMaskFlagSuspectPixels() returned NULL with bad type for in->mask");
    395395        psFree(rng);
     
    407407        pmCell *cell = generateSimpleCell(NULL);
    408408        pmReadout *in = generateSimpleReadout(cell);
    409         psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     409        psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 0);
    410410        ok(!pmMaskFlagSuspectPixels(out, NULL, 1.0, 1, 1.0, rng), "pmMaskFlagSuspectPixels() returned NULL with empty out image");
    411411        psFree(rng);
     
    423423        pmCell *cell = generateSimpleCell(NULL);
    424424        pmReadout *in = generateSimpleReadout(cell);
    425         psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     425        psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 0);
    426426        ok(!pmMaskFlagSuspectPixels(out, NULL, 1.0, 1, 1.0, rng), "pmMaskFlagSuspectPixels() returned NULL with incorrect type for out image");
    427427        psFree(rng);
     
    439439        pmCell *cell = generateSimpleCell(NULL);
    440440        pmReadout *in = generateSimpleReadout(cell);
    441         psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     441        psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 0);
    442442        ok(!pmMaskFlagSuspectPixels(out, NULL, 1.0, 1, 1.0, rng), "pmMaskFlagSuspectPixels() returned NULL with incorrect size for out image");
    443443        psFree(rng);
     
    455455        pmCell *cell = generateSimpleCell(NULL);
    456456        pmReadout *in = generateSimpleReadout(cell);
    457         psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     457        psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 0);
    458458
    459459        ok(!pmMaskFlagSuspectPixels(out, in, 0.0, 1, 1.0, rng), "pmMaskFlagSuspectPixels() returned NULL with rej input <= 0.0");
     
    472472        pmCell *cell = generateSimpleCell(NULL);
    473473        pmReadout *in = generateSimpleReadout(cell);
    474         psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     474        psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 0);
    475475
    476476        ok(!pmMaskFlagSuspectPixels(out, in, 1.0, 1, -1.0, rng), "pmMaskFlagSuspectPixels() returned NULL with frac input < 0.0");
  • trunk/psModules/test/imcombine/tap_pmImageCombine.c

    r11118 r23259  
    99psArray *generate_images(void)
    1010{
    11     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 12345);   // Random Number Generator
     11    psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 12345);   // Random Number Generator
    1212
    1313    // Generate images
  • trunk/psModules/test/objects/tap_pmFringe.c

    r15726 r23259  
    8989        ok(fringe != NULL, "pmFringeRegionsAlloc() returned non-NULL");
    9090        psImage *img = psImageAlloc(NUM_COLS, NUM_ROWS, PS_TYPE_F32);
    91         psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 10);
     91        psRandom *rng = psRandomAllocSpecific(PS_RANDOM_TAUS, 10);
    9292        fringe->x = psVectorAlloc(NUM_FRINGE_PNTS/2, PS_TYPE_F32);
    9393        fringe->y = psVectorAlloc(NUM_FRINGE_PNTS/2, PS_TYPE_F32);
  • trunk/psModules/test/objects/tap_pmSourceFitModel.c

    r14654 r23259  
    2727
    2828    // build a gauss-deviate vector (mean = 0.0, sigma = 1.0)
    29     psRandom *seed = psRandomAlloc (PS_RANDOM_TAUS, 0);
     29    psRandom *seed = psRandomAllocSpecific (PS_RANDOM_TAUS, 0);
    3030
    3131    static float radius[] = {3.0, 5.0, 7.0, 10.0, 15.0, 25.0};
  • trunk/psModules/test/objects/tap_pmSourceFitModel_Delta.c

    r14654 r23259  
    2323
    2424    // build a gauss-deviate vector (mean = 0.0, sigma = 1.0)
    25     psRandom *seed = psRandomAlloc (PS_RANDOM_TAUS, 0);
     25    psRandom *seed = psRandomAllocSpecific (PS_RANDOM_TAUS, 0);
    2626
    2727    // noise vector to noise up the image
     
    167167
    168168    // build a gauss-deviate vector (mean = 0.0, sigma = 1.0)
    169     psRandom *seed = psRandomAlloc (PS_RANDOM_TAUS, 0);
     169    psRandom *seed = psRandomAllocSpecific (PS_RANDOM_TAUS, 0);
    170170
    171171    static float radius[] = {3.0, 5.0, 7.0, 10.0, 15.0, 25.0};
Note: See TracChangeset for help on using the changeset viewer.