IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 17, 2009, 12:07:42 PM (17 years ago)
Author:
beaumont
Message:

merged with head

Location:
branches/cnb_branches/cnb_branch_20090301/psModules
Files:
14 deleted
59 edited
7 copied

Legend:

Unmodified
Added
Removed
  • branches/cnb_branches/cnb_branch_20090301/psModules

  • branches/cnb_branches/cnb_branch_20090301/psModules/src/astrom/pmAstrometryVisual.c

    r21422 r23351  
    2323
    2424//variables to determine when things are plotted
    25 static bool isVisual             = false;
    2625static bool plotGridMatch        = true;
    2726static bool plotTweak            = true;
     
    4847/* Initialization Routines  */
    4948
    50 bool pmAstromSetVisual (bool mode) {
    51     isVisual = mode;
    52     return true;
    53 }
    54 
    55 
    5649bool pmAstromVisualClose()
    5750{
     
    6861{
    6962    // make sure we want to plot this
    70     if (!plotRawStars || !isVisual) return true;
     63    if (!plotRawStars || !pmVisualIsVisual()) return true;
    7164
    7265    //set up plot region
    7366    if (!pmVisualInitWindow (&kapa, "psastro:plots")){
    74         isVisual = false;
    7567        return false;
    7668    }
     
    222214
    223215    // pause and wait for user input:
    224     pmVisualAskUser(&plotRawStars, &isVisual);
     216    pmVisualAskUser(&plotRawStars);
    225217
    226218    psFree (xVec);
     
    234226{
    235227    //make sure we want to plot this
    236     if (!isVisual || !plotRefStars) return true;
     228    if (!pmVisualIsVisual() || !plotRefStars) return true;
    237229
    238230    //set up plotting variables
    239231    if (!pmVisualInitWindow (&kapa, "psastro:plots")) {
    240         isVisual = false;
    241232        return false;
    242233    }
     
    284275
    285276    // pause and wait for user input:
    286     pmVisualAskUser(&plotRefStars, &isVisual);
     277    pmVisualAskUser(&plotRefStars);
    287278
    288279    psFree (xVec);
     
    301292
    302293    // make sure we want to plot this
    303     if ( !isVisual || !plotLumFunc ) return true;
     294    if ( !pmVisualIsVisual() || !plotLumFunc ) return true;
    304295
    305296    //set up plotting variables
    306297    if ( !pmVisualInitWindow (&kapa, "psastro:plots")){
    307         isVisual = false;
    308298        return false;
    309299    }
     
    377367
    378368        // pause and wait for user input:
    379         pmVisualAskUser (&plotLumFunc, &isVisual);
     369        pmVisualAskUser (&plotLumFunc);
    380370    }
    381371    return true;
     
    391381
    392382    //make sure we want to plot this
    393     if (!isVisual || !plotRemoveClumps) return true;
     383    if (!pmVisualIsVisual() || !plotRemoveClumps) return true;
    394384
    395385    //set up plot variables
    396386    if ( !pmVisualInitWindow (&kapa, "psastro:plots")) {
    397         isVisual = false;
    398387        return false;
    399388    }
     
    480469
    481470    //ask for user input and finish
    482     pmVisualAskUser (&plotRemoveClumps, &isVisual);
     471    pmVisualAskUser (&plotRemoveClumps);
    483472    psFree (xVec);
    484473    psFree (yVec);
     
    496485
    497486    //make sure we want to plot this
    498     if (!isVisual || !plotOneChipFit)
     487    if (!pmVisualIsVisual() || !plotOneChipFit)
    499488        return true;
    500489
    501490    if(!pmVisualInitWindow(&kapa, "psastro:plots") || !pmVisualInitWindow(&kapa2, "psastro:plots")) {
    502         isVisual = false;
    503491        return false;
    504492    }
     
    511499
    512500    //ask for user input and finish
    513     pmVisualAskUser(&plotOneChipFit, &isVisual);
     501    pmVisualAskUser(&plotOneChipFit);
    514502    return true;
    515503}
     
    522510{
    523511    //make sure we want to plot this
    524     if(!isVisual || !plotFixChips) return true;
     512    if(!pmVisualIsVisual() || !plotFixChips) return true;
    525513
    526514    if(!pmVisualInitWindow(&kapa, "psastro:plots")) {
    527         isVisual = false;
    528515        return false;
    529516    }
     
    588575    KapaPlotVector (kapa, xNew->n, yNew->data.F32, "y");
    589576
    590     pmVisualAskUser(&plotFixChips, &isVisual);
     577    pmVisualAskUser(&plotFixChips);
    591578    psFree(xNew);
    592579    psFree(yNew);
     
    606593
    607594    //make sure we want to plot this
    608     if (!isVisual || !plotAstromGuessCheck) return true;
     595    if (!pmVisualIsVisual() || !plotAstromGuessCheck) return true;
    609596
    610597    //set up graph window
    611598    if ( !pmVisualInitWindow (&kapa, "psastro:plots")) {
    612         isVisual = false;
    613599        return false;
    614600    }
     
    686672    psFree(xResid);
    687673    psFree(yResid);
    688     pmVisualAskUser (&plotAstromGuessCheck, &isVisual);
     674    pmVisualAskUser (&plotAstromGuessCheck);
    689675    return true;
    690676}
     
    696682{
    697683    //make sure we want to plot this
    698     if (!isVisual || !plotCommonScale) return true;
     684    if (!pmVisualIsVisual() || !plotCommonScale) return true;
    699685
    700686    if (!pmVisualInitWindow(&kapa, "psastro:plots")){
    701         isVisual = false;
    702687        return false;
    703688    }
     
    736721    KapaSendLabel (kapa, "Old Pixel Scale of FPA Chips (Not to Scale)", KAPA_LABEL_XP);
    737722
    738     pmVisualAskUser (&plotCommonScale, &isVisual);
     723    pmVisualAskUser (&plotCommonScale);
    739724
    740725    psFree(xVec);
     
    750735
    751736    //make sure we want to plot this
    752     if (!isVisual || !plotMosaicOneChip) return true;
     737    if (!pmVisualIsVisual() || !plotMosaicOneChip) return true;
    753738
    754739    if(!pmVisualInitWindow(&kapa, "psastro:plots") || !pmVisualInitWindow(&kapa2, "psastro:plots")) {
    755         isVisual = false;
    756740        return false;
    757741    }
     
    759743    //plot the residuals
    760744    if (!residPlot(rawstars, refstars, match, recipe, "Single Chip Fit Residuals - Mosaic Mode")) {
    761         isVisual = false;
     745        pmVisualSetVisual(false);
    762746        return false;
    763747    }
    764748
    765749    //ask for user input and finish
    766     pmVisualAskUser(&plotMosaicOneChip, &isVisual);
     750    pmVisualAskUser(&plotMosaicOneChip);
    767751
    768752    return true;
     
    775759{
    776760    //make sure we want to plot this
    777     if (!isVisual || !plotMosaicMatches) return true;
     761    if (!pmVisualIsVisual() || !plotMosaicMatches) return true;
    778762
    779763    char title[60];
     
    782766
    783767    if(!pmVisualInitWindow(&kapa, "psastro:plots") || !pmVisualInitWindow(&kapa2, "psastro:plots")) {
    784         isVisual = false;
    785768        return false;
    786769    }
    787770
    788771    if (!residPlot(rawstars, refstars, match, recipe, title)){
    789         isVisual = false;
     772        pmVisualSetVisual(false);
    790773        return false;
    791774    }
    792775
    793776    //ask for user input
    794     pmVisualAskUser (&plotMosaicMatches, &isVisual);
     777    pmVisualAskUser (&plotMosaicMatches);
    795778    return true;
    796779}
     
    807790{
    808791    //make sure we want to plot this
    809     if (!isVisual || !plotGridMatch) return true;
     792    if (!pmVisualIsVisual() || !plotGridMatch) return true;
    810793    if (!pmVisualInitWindow(&kapa, "psastro:plots")){
    811         isVisual = false;
    812794        return false;
    813795    }
     
    952934    KapaPlotVector (kapa, 2, yslice, "y");
    953935
    954     pmVisualAskUser(&plotGridMatch, &isVisual);
     936    pmVisualAskUser(&plotGridMatch);
    955937    psFree(dXplot);
    956938    psFree(dYplot);
     
    966948{
    967949    //make sure we want to plot this
    968     if (!isVisual || !plotTweak) return true;
     950    if (!pmVisualIsVisual() || !plotTweak) return true;
    969951    if (!pmVisualInitWindow(&kapa, "psastro:plots")) {
    970         isVisual = false;
    971952        return false;
    972953    }
     
    10511032                   KAPA_LABEL_XP);
    10521033
    1053     pmVisualAskUser(&plotTweak, &isVisual);
     1034    pmVisualAskUser(&plotTweak);
    10541035
    10551036    psFree(xIndices);
     
    13411322# else
    13421323
    1343 bool pmAstromSetVisual(bool mode) { return true; }
    13441324bool pmAstromVisualClose() { return true; }
    13451325bool pmAstromVisualPlotGridMatch (const psArray *raw, const psArray *ref, psImage *gridNP, double offsetX, double offsetY, double maxOffpix, double Scale, double Offset) { return true; }
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/astrom/pmAstrometryVisual.h

    r21422 r23351  
    2222    int sPeak;                          ///< sum of stars to peak bin
    2323} pmLumFunc;
    24 
    25 
    26 /** Enable or disable visual plotting for psastro routines
    27  * @param mode true/false to enable/disable plotting
    28  * @return true for success */
    29 bool pmAstromSetVisual(bool mode);
    3024
    3125
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/camera/pmFPACopy.c

    r22699 r23351  
    173173    int xParityTarget = psMetadataLookupS32(&mdokT, target->concepts, "CELL.XPARITY"); // Target x parity
    174174    assert(mdokS && mdokT);
     175
     176    if (xParityTarget == 0) {
     177        psMetadataItem *item = psMetadataLookup(target->concepts, "CELL.XPARITY"); // Item with parity
     178        xParityTarget = item->data.S32 = xParitySource;
     179    }
     180
    175181    psAssert (abs(xParitySource) == 1, "CELL.XPARITY not set for source");
    176182    psAssert (abs(xParityTarget) == 1, "CELL.XPARITY not set for target");
     
    192198    int yParitySource = psMetadataLookupS32(&mdokS, source->concepts, "CELL.YPARITY"); // Source parity
    193199    assert(mdokS && mdokT);
     200
     201    if (yParityTarget == 0) {
     202        psMetadataItem *item = psMetadataLookup(target->concepts, "CELL.YPARITY"); // Item with parity
     203        yParityTarget = item->data.S32 = yParitySource;
     204    }
     205
    194206    psAssert (abs(yParitySource) == 1, "CELL.YPARITY not set for source");
    195207    psAssert (abs(yParityTarget) == 1, "CELL.YPARITY not set for target");
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/camera/pmFPAMaskWeight.c

    r21363 r23351  
    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
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/camera/pmFPAWrite.c

    r22699 r23351  
    692692                     "Centre of covariance matrix in y", -yMinCovar);
    693693
     694    // Turn off compression
     695    int bitpix = fits->options ? fits->options->bitpix : 0; // Desired bits per pixel
     696    psFitsCompression *compress = psFitsCompressionGet(fits); // Current compression options
     697    if (!psFitsSetCompression(fits, PS_FITS_COMPRESS_NONE, NULL, 0, 0, 0)) {
     698        psError(PS_ERR_UNKNOWN, false, "Unable to set FITS compression to NONE");
     699        psFree(extname);
     700        psFree(header);
     701        psFree(images);
     702        psFree(compress);
     703        return false;
     704    }
     705    if (fits->options) {
     706        fits->options->bitpix = 0;
     707    }
     708
    694709    // Write images
    695710    if (!psFitsWriteImageCube(fits, header, images, extname)) {
     
    699714        psFree(header);
    700715        psFree(images);
     716        if (fits->options) {
     717            fits->options->bitpix = bitpix;
     718        }
     719        psFitsCompressionApply(fits, compress);
     720        psFree(compress);
    701721        return 0;
    702722    }
     
    704724    psFree(header);
    705725    psFree(images);
     726
     727    // Restore compression
     728    if (fits->options) {
     729        fits->options->bitpix = bitpix;
     730    }
     731    if (!psFitsCompressionApply(fits, compress)) {
     732        psError(PS_ERR_UNKNOWN, false, "Unable to set FITS compression to NONE");
     733        psFree(compress);
     734        return false;
     735    }
     736    psFree(compress);
    706737
    707738    return true;
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/camera/pmFPA_JPEG.c

    r21183 r23351  
    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;
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/camera/pmFPAfile.c

    r22699 r23351  
    5050
    5151    psFree (file->filename);
     52    psFree (file->origname);
    5253    psFree (file->extname);
    5354
     
    8889
    8990    file->filename = NULL;
     91    file->origname = NULL;
    9092    file->extname  = NULL;
    9193
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/camera/pmFPAfile.h

    r21363 r23351  
    9191    char *name;                         // the name of the rule (useful for debugging / tracing)
    9292    char *filename;                     // the current name of an active file
     93    char *origname;                     // the original name (before mangling) of an active file
    9394    char *extname;                      // the current name of an active file extension
    9495
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/camera/pmFPAfileDefine.c

    r22699 r23351  
    1111#include "pmConfig.h"
    1212#include "pmConfigMask.h"
     13#include "pmConfigRun.h"
    1314#include "pmDetrendDB.h"
    1415
     
    216217        file->imageId = config->imageId;
    217218    }
    218 
    219     // XXX this seems a bit of a hack: use the cameraName to determine the mosaic level...
    220     # if (0)
    221     if (cameraName) {
    222         if (!strcmp(cameraName + strlen(cameraName) - 5, "-CHIP")) {
    223             file->mosaicLevel = PM_FPA_LEVEL_CHIP;
    224         }
    225         if (!strcmp(cameraName + strlen(cameraName) - 5, "-FPA")) {
    226             file->mosaicLevel = PM_FPA_LEVEL_FPA;
    227         }
    228     }
    229     # endif
    230219
    231220    // Use the format we were told to, the format specified in the file rule, or default to the default format
     
    383372    }
    384373
    385     psTrace ("psModules.camera", 5, "file: %s, format: %s, fileLevel: %s, extLevel: %s, dataLevel: %s, freeLevel: %s\n",
    386              file->name, file->formatName, pmFPALevelToName (file->fileLevel), pmFPALevelToName(extLevel), pmFPALevelToName (file->dataLevel), pmFPALevelToName (file->freeLevel));
     374    psTrace("psModules.camera", 5,
     375            "file: %s, format: %s, fileLevel: %s, extLevel: %s, dataLevel: %s, freeLevel: %s\n",
     376            file->name, file->formatName, pmFPALevelToName(file->fileLevel), pmFPALevelToName(extLevel),
     377            pmFPALevelToName(file->dataLevel), pmFPALevelToName(file->freeLevel));
    387378
    388379    // add argument-supplied OUTPUT name to this file
    389380    char *outname = psMetadataLookupStr(&status, config->arguments, "OUTPUT");
    390     psMetadataAddStr(file->names, PS_LIST_TAIL, "OUTPUT", PS_META_NO_REPLACE, "", outname);
     381    psMetadataAddStr(file->names, PS_LIST_TAIL, "OUTPUT", PS_META_NO_REPLACE, "Output file name", outname);
    391382
    392383    // place the resulting file in the config system
    393     psMetadataAddPtr (config->files, PS_LIST_TAIL, name, PS_DATA_UNKNOWN, "", file);
     384    psMetadataAddPtr(config->files, PS_LIST_TAIL, name, PS_DATA_UNKNOWN, "Output file", file);
    394385    psFree(file);                       // we free this copy of file, but 'files' still has a copy
    395386    return file;                        // the returned value is a view into the version on 'files'
     
    426417}
    427418
    428 // search for argname on the config->argument list
    429 // construct an FPA based on the files in this list (must represent a single FPA)
    430 // built the association between the FPA elements (CHIP/CELL) and the files
    431 // define the pmFPAfile filename and bind it to this FPA
    432 // save the pmFPAfile on config->files
    433 // return the pmFPAfile (a view to the one saved on config->files)
    434 pmFPAfile *pmFPAfileDefineFromArgs(bool *success, pmConfig *config, const char *filename, const char *argname)
     419
     420/// Define a file from an array of filenames
     421static pmFPAfile *fpaFileDefineFromArray(pmConfig *config, // Configuration
     422                                         pmFPAfile *bind, // File to bind to, or NULL
     423                                         const char *name, // Name of file
     424                                         const psArray *filenames // Array of file names
     425    )
     426{
     427    PS_ASSERT_PTR_NON_NULL(config, NULL);
     428    PS_ASSERT_STRING_NON_EMPTY(name, NULL);
     429
     430    pmFPA *fpa = NULL;                  // FPA for file
     431    psMetadata *format = NULL;          // Camera format configuration
     432    psString formatName = NULL;         // Name of camera format
     433    psString cameraName = NULL;         // Name of camera
     434    pmFPALevel fileLevel = PM_FPA_LEVEL_NONE; // Level for files
     435    psMetadata *phu = NULL;             // Primary header
     436    if (bind) {
     437        // Use the FPA we're binding to
     438        fpa = psMemIncrRefCounter(bind->fpa);
     439        fileLevel = bind->fileLevel;
     440    } else {
     441        // Need to generate an FPA
     442        psString realName = pmConfigConvertFilename(filenames->data[0], config, false, false);
     443        if (!realName) {
     444            psError(PS_ERR_IO, false, "Failed to convert file name %s", (char *)filenames->data[0]);
     445            return NULL;
     446        }
     447
     448        // load the header of the first image
     449        // EXTWORD (fits->extword) is not relevant to the PHU
     450        psFits *fits = psFitsOpen(realName, "r"); // FITS file
     451        if (!fits) {
     452            psError(PS_ERR_IO, false, "Failed to open file %s", realName);
     453            psFree(realName);
     454            return NULL;
     455        }
     456        phu = psFitsReadHeader (NULL, fits); // Primary header
     457        if (!phu) {
     458            psError(PS_ERR_IO, false, "Failed to read file header %s", realName);
     459            psFree(realName);
     460            return NULL;
     461        }
     462        psFitsClose(fits);
     463
     464        // Determine the current format from the header; determine camera if not specified already.
     465        psMetadata *camera = NULL;      // Camera configuration
     466        format = pmConfigCameraFormatFromHeader(&camera, &cameraName, &formatName, config, phu, true);
     467        if (!format) {
     468            psError(PS_ERR_IO, false, "Failed to determine camera format for %s", realName);
     469            psFree(camera);
     470            psFree(formatName);
     471            psFree(realName);
     472            psFree(phu);
     473            return NULL;
     474        }
     475
     476        fileLevel = pmFPAPHULevel(format);
     477        if (fileLevel == PM_FPA_LEVEL_NONE) {
     478            psError(PS_ERR_IO, true, "Unable to determine file level for %s", realName);
     479            psFree(camera);
     480            psFree(formatName);
     481            psFree(realName);
     482            psFree(phu);
     483            return NULL;
     484        }
     485
     486        // build the template fpa, set up the basic view
     487        // XXX do we want this to be the baseCamera name or the metaCamera name?
     488        fpa = pmFPAConstruct(camera, cameraName);
     489        psFree(camera);
     490        if (!fpa) {
     491            psError(PS_ERR_IO, false, "Failed to construct FPA from %s", realName);
     492            psFree(formatName);
     493            psFree(realName);
     494            psFree(format);
     495            psFree(phu);
     496            return NULL;
     497        }
     498        psFree(realName);
     499    }
     500
     501    // load the given filerule (from config->camera) and bind it to the fpa
     502    // the returned file is just a view to the entry on config->files
     503    pmFPAfile *file = pmFPAfileDefineInput(config, fpa, cameraName, name); // File, to return
     504    if (!file) {
     505        psError(PS_ERR_IO, false, "File %s not defined", name);
     506        psFree(formatName);
     507        psFree(format);
     508        psFree(fpa);
     509        psFree(phu);
     510        return NULL;
     511    }
     512    psFree(cameraName);
     513    psFree(fpa);                        // Drop reference
     514
     515    file->format = format;
     516    file->formatName = formatName;
     517    file->fileLevel = fileLevel;
     518
     519    // We use the filerule and filesrc to identify the files in the file->names data
     520    psFree(file->filerule); // this is set in pmFPAfileDefineInput
     521    file->filerule = psStringCopy("@FILES");
     522    file->filesrc = psStringCopy("{CHIP.NAME}.{CELL.NAME}");
     523
     524    // Examine the list of input files and validate their cameras
     525    // Associate each filename with an element of the FPA
     526    // Save the association on file->names
     527    for (int i = 0; i < filenames->n; i++) {
     528        // Check that the file corresponds to the same camera and format
     529        if (!phu) {
     530            psString realName = pmConfigConvertFilename(filenames->data[i], config, false, false);
     531            if (!realName) {
     532                psError(PS_ERR_IO, false, "Failed to convert file name %s", (char*)filenames->data[i]);
     533                return NULL;
     534            }
     535            psFits *fits = psFitsOpen(realName, "r"); // FITS file
     536            if (!fits) {
     537                psError(PS_ERR_IO, false, "Failed to open file %s", realName);
     538                psFree(realName);
     539                return NULL;
     540            }
     541            phu = psFitsReadHeader(NULL, fits);
     542            psFitsClose(fits);
     543            if (!phu) {
     544                psError(PS_ERR_IO, false, "Failed to read file header %s", realName);
     545                psFree(realName);
     546                return NULL;
     547            }
     548            psFree(realName);
     549        }
     550
     551        if (i == 0 && file->type == PM_FPA_FILE_MASK) {
     552            if (!pmConfigMaskReadHeader(config, phu)) {
     553                psError(PS_ERR_IO, false, "Error reading mask bits");
     554                psFree(phu);
     555                return NULL;
     556            }
     557        }
     558
     559        if (bind || i > 0) {
     560            if (format) {
     561                bool valid = false;
     562                if (!pmConfigValidateCameraFormat(&valid, format, phu)) {
     563                    psError(PS_ERR_UNKNOWN, false, "Error in config scripts\n");
     564                    psFree(phu);
     565                    return NULL;
     566                }
     567                if (!valid) {
     568                    psError(PS_ERR_IO, false, "File %s is not from the required camera",
     569                            (char*)filenames->data[i]);
     570                    psFree(phu);
     571                    return NULL;
     572                }
     573            } else {
     574                format = pmConfigCameraFormatFromHeader(NULL, NULL, NULL, config, phu, true);
     575                if (!format) {
     576                    psError(PS_ERR_IO, false, "Failed to determine camera format from %s",
     577                            (char*)filenames->data[i]);
     578                    psFree(phu);
     579                    return NULL;
     580                }
     581            }
     582        }
     583
     584        // Ensure the format is set
     585        if (!file->format) {
     586            file->format = format;
     587        }
     588        if (!file->formatName) {
     589            file->formatName = formatName;
     590        }
     591
     592        // Set the view to the corresponding entry for this phu
     593        pmFPAview *view = NULL;         // View to PHU
     594        if (bind) {
     595            view = pmFPAIdentifySourceFromHeader(bind->fpa, phu, format);
     596        } else {
     597            view = pmFPAAddSourceFromHeader(fpa, phu, format);
     598        }
     599        psFree(phu);
     600        phu = NULL;
     601        if (!view) {
     602            psError(PS_ERR_IO, false, "Unable to determine source for %s", name);
     603            return NULL;
     604        }
     605
     606        // Associate the filename with the FPA element
     607        psString location = pmFPAfileNameFromRule(file->filesrc, file, view);
     608        psFree(view);
     609        psMetadataAddStr(file->names, PS_LIST_TAIL, location, 0, "Location of file", filenames->data[i]);
     610        psFree(location);
     611    }
     612
     613    return file;
     614}
     615
     616
     617pmFPAfile *pmFPAfileDefineFromArgs(bool *success, pmConfig *config,
     618                                   const char *filename, const char *argname)
    435619{
    436620    PS_ASSERT_PTR_NON_NULL(config, NULL);
     
    438622    PS_ASSERT_STRING_NON_EMPTY(argname, NULL);
    439623
    440     bool status;
    441     pmFPA *fpa = NULL;
    442     psFits *fits = NULL;
    443     pmFPAfile *file = NULL;
    444     psMetadata *phu = NULL;
    445     psMetadata *format = NULL;
    446     psMetadata *camera = NULL;
    447     psString formatName = NULL;
    448 
    449     // use success to identify valid exit conditions (as opposed to 'argument not supplied')
    450     if (success) {
    451         *success = false;
    452     }
    453 
    454     // we search the argument data for the named fileset (argname)
    455     psArray *infiles = psMetadataLookupPtr(&status, config->arguments, argname);
     624    // Search the argument data for the named fileset (argname)
     625    bool status;                        // Status of MD lookup
     626    psArray *filenames = psMetadataLookupPtr(&status, config->arguments, argname); // Filenames for file
    456627    if (!status) {
    457628        if (success) {
     
    460631        return NULL;
    461632    }
    462     if (infiles->n < 1) {
    463         psError(PS_ERR_IO, false, "Found n == %ld files in %s in arguments\n", infiles->n, argname);
    464         return NULL;
    465     }
    466 
    467     // this function is implicitly an INPUT operation: do not create the file
    468     psString realName = pmConfigConvertFilename (infiles->data[0], config, false, false);
    469     if (!realName) {
    470         psError(PS_ERR_IO, false, "Failed to convert file name %s\n", (char *) infiles->data[0]);
    471         return NULL;
    472     }
    473 
    474     // load the header of the first image
    475     // EXTWORD (fits->extword) is not relevant to the PHU
    476     fits = psFitsOpen (realName, "r");
    477     if (!fits) {
    478         psError(PS_ERR_IO, false, "Failed to open file %s\n", realName);
    479         psFree (realName);
    480         return NULL;
    481     }
    482     phu = psFitsReadHeader (NULL, fits);
    483 
    484     if (!phu) {
    485         psError(PS_ERR_IO, false, "Failed to read file header %s\n", realName);
    486         psFree (realName);
    487         return NULL;
    488     }
    489     psFitsClose(fits);
    490 
    491     // Determine the current format from the header; Determine camera if not specified already.
    492     // the returned pointers 'camera' and 'formatName' are allocated here
    493     psString cameraName = NULL;
    494     format = pmConfigCameraFormatFromHeader(&camera, &cameraName, &formatName, config, phu, true);
    495     if (!format) {
    496         psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", realName);
    497         psFree(phu);
    498         psFree(camera);
    499         psFree(formatName);
    500         psFree(realName);
    501         return NULL;
    502     }
    503 
    504     // build the template fpa, set up the basic view
    505     // XXX do we want this to be the baseCamera name or the metaCamera name?
    506     fpa = pmFPAConstruct(camera, cameraName);
    507     if (!fpa) {
    508         psError(PS_ERR_IO, false, "Failed to construct FPA from %s", realName);
    509         psFree(phu);
    510         psFree(camera);
    511         psFree(formatName);
    512         psFree(realName);
    513         psFree(format);
    514         return NULL;
    515     }
    516     psFree (realName);
    517     psFree (camera);
    518 
    519     // load the given filerule (from config->camera) and bind it to the fpa
    520     // the returned file is just a view to the entry on config->files
    521     file = pmFPAfileDefineInput(config, fpa, cameraName, filename);
    522     if (!file) {
    523         psError(PS_ERR_IO, false, "file %s not defined\n", filename);
    524         psFree(phu);
    525         psFree(formatName);
    526         psFree(format);
    527         psFree(fpa);
    528         return NULL;
    529     }
    530     psFree (cameraName);
    531     psFree (file->filerule); // this is set in pmFPAfileDefineInput
    532 
    533     file->format = format;
    534     file->formatName = formatName;
    535     file->filerule = psStringCopy("@FILES");
    536     file->filesrc = psStringCopy("{CHIP.NAME}.{CELL.NAME}");
    537     // we use the above rules to identify these files in the file->names data
    538 
    539     file->fileLevel = pmFPAPHULevel(format);
    540     if (file->fileLevel == PM_FPA_LEVEL_NONE) {
    541         psError(PS_ERR_IO, true, "Unable to determine file level for %s\n", file->name);
    542         psFree(phu);
    543         psFree(fpa);
    544         return NULL;
    545     }
    546 
    547     if (file->type == PM_FPA_FILE_MASK) {
    548         if (!pmConfigMaskReadHeader (config, phu)) {
    549             psError(PS_ERR_IO, false, "error in mask bits");
    550             return NULL;
    551         }
    552     }
    553 
    554     // examine the list of input files and validate their cameras
    555     // associated each filename with an element of the FPA
    556     // save the association on file->names
    557     for (int i = 0; i < infiles->n; i++) {
    558         if (i > 0) {
    559             // this function is implicitly an INPUT operation: do not create the file
    560             psString realName = pmConfigConvertFilename (infiles->data[i], config, false, false);
    561             if (!realName) {
    562                 psError(PS_ERR_IO, false, "Failed to convert file name %s", (char *) infiles->data[i]);
    563                 psFree(phu);
    564                 psFree(fpa);
    565                 return NULL;
    566             }
    567             // EXTWORD (fits->extword) is not relevant to the PHU
    568             fits = psFitsOpen (realName, "r");
    569             if (!fits) {
    570                 psError(PS_ERR_IO, false, "Failed to open file %s\n", realName);
    571                 psFree(realName);
    572                 psFree(phu);
    573                 psFree(fpa);
    574                 return NULL;
    575             }
    576             phu = psFitsReadHeader (NULL, fits);
    577             if (!phu) {
    578                 psError(PS_ERR_IO, false, "Failed to read file header %s", realName);
    579                 psFree(realName);
    580                 psFitsClose(fits);
    581                 psFree(phu);
    582                 psFree(fpa);
    583                 return NULL;
    584             }
    585             bool valid = false;
    586             if (!pmConfigValidateCameraFormat (&valid, format, phu)) {
    587                 psError(PS_ERR_UNKNOWN, false, "Error in config scripts\n");
    588                 psFree(realName);
    589                 psFitsClose(fits);
    590                 psFree(phu);
    591                 psFree(fpa);
    592                 return NULL;
    593             }
    594             if (!valid) {
    595                 psError(PS_ERR_IO, false, "file %s is not from the required camera", realName);
    596                 psFree(realName);
    597                 psFitsClose(fits);
    598                 psFree(phu);
    599                 psFree(fpa);
    600                 return NULL;
    601             }
    602             psFree(realName);
    603             psFitsClose(fits);
    604         }
    605 
    606         // set the view to the corresponding entry for this phu
    607         pmFPAview *view = pmFPAAddSourceFromHeader (fpa, phu, format);
    608         if (!view) {
    609             psError(PS_ERR_IO, false, "Unable to determine source for %s", file->name);
    610             psFree(phu);
    611             psFree(fpa);
    612             return NULL;
    613         }
    614 
    615         // associate the filename with the FPA element
    616         char *name = pmFPAfileNameFromRule(file->filesrc, file, view);
    617 
    618         // save the name association in the pmFPAfile structure
    619         psMetadataAddStr(file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]);
    620 
    621         psFree(view);
    622         psFree(name);
    623         psFree(phu);
    624     }
    625     psFree(fpa);
     633    if (filenames->n == 0) {
     634        psError(PS_ERR_IO, false, "No files in array in %s in arguments", argname);
     635        if (success) {
     636            *success = false;
     637        }
     638        return NULL;
     639    }
     640
     641    pmFPAfile *file = fpaFileDefineFromArray(config, NULL, filename, filenames); // File of interest
     642
    626643    if (success) {
    627         *success = true;
    628     }
    629 
    630     return file;
    631 }
    632 
    633 // search for argname on the config->argument list
    634 // construct an FPA based on the files in this list (must represent a single FPA)
    635 // built the association between the FPA elements (CHIP/CELL) and the files
    636 // define the pmFPAfile filename and bind it to this FPA
    637 // save the pmFPAfile on config->files
    638 // return the pmFPAfile (a view to the one saved on config->files)
    639 pmFPAfile *pmFPAfileBindFromArgs (bool *success, pmFPAfile *input, pmConfig *config, const char *filename, const char *argname)
     644        *success = file ? true : false;
     645    }
     646
     647    return file;
     648}
     649
     650pmFPAfile *pmFPAfileBindFromArgs(bool *success, pmFPAfile *input, pmConfig *config,
     651                                 const char *filename, const char *argname)
    640652{
    641653    PS_ASSERT_PTR_NON_NULL(input, NULL);
     
    644656    PS_ASSERT_STRING_NON_EMPTY(argname, NULL);
    645657
    646     bool status;
    647     psFits *fits = NULL;
    648     pmFPAfile *file = NULL;
    649     psMetadata *phu = NULL;
    650 
    651     // use success to identify valid exit conditions (as opposed to 'argument not supplied')
    652     if (success) {
    653         *success = false;
    654     }
    655 
    656     // we search the argument data for the named fileset (argname)
    657     psArray *infiles = psMetadataLookupPtr(&status, config->arguments, argname);
     658    // Search the argument data for the named fileset (argname)
     659    bool status;                        // Status of MD lookup
     660    psArray *filenames = psMetadataLookupPtr(&status, config->arguments, argname); // Filenames for file
    658661    if (!status) {
    659         // this is not an error: this just means no matching argument was supplied
    660662        if (success) {
    661663            *success = true;
     
    663665        return NULL;
    664666    }
    665     if (infiles->n < 1) {
    666         psError(PS_ERR_IO, false, "Found n == %ld files in %s in arguments\n", infiles->n, argname);
    667         return NULL;
    668     }
    669 
    670     // load the given filerule (from config->camera) and bind it to the fpa
    671     // the returned file is just a view to the entry on config->files
    672     file = pmFPAfileDefineInput (config, input->fpa, NULL, filename);
    673     if (!file) {
    674         psError(PS_ERR_IO, false, "file %s not defined\n", filename);
    675         psFree(phu);
    676         return NULL;
    677     }
    678 
    679     // set derived values
    680     file->fileLevel = input->fileLevel;
    681 
    682 
    683     // define the rule to identify these files in the file->names data
    684     psFree (file->filerule);
    685     psFree (file->filesrc);
    686     file->filerule = psStringCopy ("@FILES");
    687     file->filesrc = psStringCopy ("{CHIP.NAME}.{CELL.NAME}");
    688 
    689     // examine the list of input files and validate their cameras
    690     // associated each filename with an element of the FPA
    691     // save the association on file->names
    692     psMetadata *format = NULL;
    693     for (int i = 0; i < infiles->n; i++) {
    694         // this function is implicitly an INPUT operation: do not create the file
    695         psString realName = pmConfigConvertFilename (infiles->data[i], config, false, false);
    696         if (!realName) {
    697             psError(PS_ERR_IO, false, "Failed to convert file name %s", (char *) infiles->data[i]);
    698             return NULL;
    699         }
    700         // EXTWORD (fits->extword) is not relevant to the PHU
    701         fits = psFitsOpen (realName, "r");
    702         if (!fits) {
    703             psError(PS_ERR_IO, false, "Failed to open file %s\n", realName);
    704             psFree(realName);
    705             return NULL;
    706         }
    707         phu = psFitsReadHeader (NULL, fits);
    708         if (!phu) {
    709             psError(PS_ERR_IO, false, "Failed to read file header %s", realName);
    710             psFree(realName);
    711             psFitsClose(fits);
    712             return NULL;
    713         }
    714 
    715         if (!format) {
    716             format = pmConfigCameraFormatFromHeader(NULL, NULL, NULL, config, phu, true);
    717             if (!format) {
    718                 psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", realName);
    719                 psFree(phu);
    720                 psFree(realName);
    721                 psFitsClose(fits);
    722                 return NULL;
    723             }
    724         } else {
    725             bool valid = false;
    726             if (!pmConfigValidateCameraFormat(&valid, format, phu)) {
    727                 psError(PS_ERR_UNKNOWN, false, "Error in config scripts\n");
    728                 psFree(realName);
    729                 psFitsClose(fits);
    730                 return NULL;
    731             }
    732             if (!valid) {
    733                 psError(PS_ERR_IO, false, "specified data file %s does not match format of supplied INPUT\n",
    734                         realName);
    735                 psFree(realName);
    736                 psFitsClose(fits);
    737                 return NULL;
    738             }
    739         }
    740 
    741         psFree(realName);
    742         psFitsClose(fits);
    743 
    744         // set the view to the corresponding entry for this phu
    745         pmFPAview *view = pmFPAIdentifySourceFromHeader (input->fpa, phu, format);
    746         if (!view) {
    747             psError(PS_ERR_IO, false, "Unable to determine source for %s", file->name);
    748             psFree(phu);
    749             return NULL;
    750         }
    751 
    752         // associate the filename with the FPA element
    753         char *name = pmFPAfileNameFromRule(file->filesrc, file, view);
    754 
    755         // save the name association in the pmFPAfile structure
    756         psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]);
    757 
    758         if ((i == 0) && (file->type == PM_FPA_FILE_MASK)) {
    759             if (!pmConfigMaskReadHeader (config, phu)) {
    760                 psError(PS_ERR_IO, false, "error in mask bits");
    761                 return NULL;
    762             }
    763         }
    764 
    765         psFree(view);
    766         psFree(name);
    767         psFree(phu);
    768     }
    769     file->format = format;
    770     file->formatName = psStringCopy(config->formatName);
     667    if (filenames->n == 0) {
     668        psError(PS_ERR_IO, false, "No files in array in %s in arguments", argname);
     669        if (success) {
     670            *success = false;
     671        }
     672        return NULL;
     673    }
     674
     675    pmFPAfile *file = fpaFileDefineFromArray(config, input, filename, filenames); // File of interest
    771676
    772677    if (success) {
    773         *success = true;
    774     }
    775     return file;
    776 }
    777 
    778 // search for argname on the config->argument list
    779 // construct an FPA based on the files in this list (each represents the same FPA)
    780 // built the association between the FPA elements (CHIP/CELL) and the files
    781 // define the pmFPAfile filenames and bind them to the FPAs
    782 // save the pmFPAfiles on config->files
    783 // return the pmFPAfiles (a view to the one saved on config->files)
    784 pmFPAfile *pmFPAfileDefineSingleFromArgs (bool *success, pmConfig *config, const char *filename,
    785         const char *argname, int entry)
     678        *success = file ? true : false;
     679    }
     680
     681    return file;
     682}
     683
     684pmFPAfile *pmFPAfileDefineSingleFromArgs(bool *success, pmConfig *config, const char *filename,
     685                                         const char *argname, int entry)
    786686{
    787687    PS_ASSERT_PTR_NON_NULL(config, NULL);
     
    789689    PS_ASSERT_STRING_NON_EMPTY(argname, NULL);
    790690
    791     bool status;
    792     pmFPA *fpa = NULL;
    793     psFits *fits = NULL;
    794     pmFPAfile *file = NULL;
    795     psMetadata *phu = NULL;
    796     psMetadata *format = NULL;
    797 
    798     if (success) {
    799         *success = false;
    800     }
    801 
    802     // we search the argument data for the named fileset (argname)
    803     psArray *infiles = psMetadataLookupPtr(&status, config->arguments, argname);
     691    // Search the argument data for the named fileset (argname)
     692    bool status;                        // Status from MD lookup
     693    psArray *filenames = psMetadataLookupPtr(&status, config->arguments, argname); // Filenames for file
    804694    if (!status) {
    805         psTrace("psModules.camera", 5, "Failed to find %s in argument list", argname);
    806695        if (success) {
    807696            *success = true;
     
    809698        return NULL;
    810699    }
    811     if (infiles->n <= entry) {
    812         psError(PS_ERR_IO, false, "only %ld files in %s in argument, entry %d requested\n",
    813                 infiles->n, argname, entry);
    814         return NULL;
    815     }
    816 
    817     // examine the list of input files and validate their cameras
    818     // associated each filename with an element of the FPA
    819     // save the association on file->names
    820     // EXTWORD (fits->extword) is not relevant to the PHU
    821     fits = psFitsOpen (infiles->data[entry], "r");
    822     phu = psFitsReadHeader (NULL, fits);
    823     psFitsClose (fits);
    824 
    825     // on first call to this function, config->camera is not set.
    826     // later calls will give an error if the cameras do not match
    827     psMetadata *camera = NULL;
    828     psString formatName = NULL;
    829     psString cameraName = NULL;
    830     format = pmConfigCameraFormatFromHeader (&camera, &cameraName, &formatName, config, phu, true);
    831     if (!format) {
    832         psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", (char *)infiles->data[0]);
    833         psFree(phu);
    834         psFree(camera);
    835         psFree(formatName);
    836         return NULL;
    837     }
    838 
    839     // build the template fpa, set up the basic view
    840     fpa = pmFPAConstruct (camera, cameraName);
    841     if (!fpa) {
    842         psError(PS_ERR_IO, false, "Failed to construct FPA from %s", (char *)infiles->data[0]);
    843         psFree(phu);
    844         psFree(camera);
    845         psFree(formatName);
    846         psFree(format);
    847         return NULL;
    848     }
    849     psFree(camera);
    850 
    851     // load the given filerule (from config->camera) and bind it to the fpa
    852     // the returned file is just a view to the entry on config->files
    853     // we need a variable name here... (but in filerule)
    854     file = pmFPAfileDefineInput (config, fpa, cameraName, filename);
    855     if (!file) {
    856         psError(PS_ERR_IO, false, "file %s not defined\n", filename);
    857         psFree(phu);
    858         psFree(fpa);
    859         psFree(format);
    860         return NULL;
    861     }
    862     psFree(cameraName);
    863     FPA_TEST_ASSERT (file);
    864 
    865     file->format = format;
    866     file->formatName = formatName;
    867     file->filerule = psStringCopy ("@FILES");
    868     file->filesrc = psStringCopy ("{CHIP.NAME}.{CELL.NAME}");
    869     // adjust the above rules to identify these files in the file->names data
    870 
    871     file->fileLevel = pmFPAPHULevel(format);
    872     if (file->fileLevel == PM_FPA_LEVEL_NONE) {
    873         psError(PS_ERR_IO, true, "Unable to determine file level for %s\n", file->name);
    874         psFree(phu);
    875         psFree(fpa);
    876         return NULL;
    877     }
    878 
    879     if (file->type == PM_FPA_FILE_MASK) {
    880         if (!pmConfigMaskReadHeader (config, phu)) {
    881             psError(PS_ERR_IO, false, "error in mask bits");
    882             return NULL;
    883         }
    884     }
    885 
    886     // set the view to the corresponding entry for this phu
    887     pmFPAview *view = pmFPAAddSourceFromHeader (fpa, phu, format);
    888     if (!view) {
    889         psError(PS_ERR_IO, false, "Unable to determine source for %s", file->name);
    890         psFree(phu);
    891         psFree(fpa);
    892         return NULL;
    893     }
    894 
    895     // associate the filename with the FPA element
    896     char *name = pmFPAfileNameFromRule (file->filesrc, file, view);
    897 
    898     // save the name association in the pmFPAfile structure
    899     psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[entry]);
    900 
    901     psFree(phu);
    902     psFree(fpa);
    903     psFree(view);
    904     psFree(name);
     700    if (filenames->n <= entry) {
     701        psError(PS_ERR_IO, false, "Insufficient files (%ld) in array in %s in arguments",
     702                filenames->n, argname);
     703        if (success) {
     704            *success = false;
     705        }
     706        return NULL;
     707    }
     708
     709    psArray *single = psArrayAlloc(1);  // Array of single filename of interest
     710    single->data[0] = psMemIncrRefCounter(filenames->data[entry]);
     711    pmFPAfile *file = fpaFileDefineFromArray(config, NULL, filename, single); // File of interest
     712    psFree(single);
    905713
    906714    if (success) {
    907         *success = true;
    908     }
    909     return file;
    910 }
     715        *success = file ? true : false;
     716    }
     717
     718    return file;
     719}
     720
     721pmFPAfile *pmFPAfileDefineFromRun(bool *success, pmConfig *config, const char *filename)
     722{
     723    PS_ASSERT_PTR_NON_NULL(config, NULL);
     724    PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
     725
     726    psArray *filenames = pmConfigRunFileGet(config, filename); // Filenames used, or NULL
     727    if (!filenames) {
     728        if (success) {
     729            *success = true;
     730        }
     731        return NULL;
     732    }
     733
     734    pmFPAfile *file = fpaFileDefineFromArray(config, NULL, filename, filenames); // File of interest
     735    psFree(filenames);
     736
     737    if (success) {
     738        *success = file ? true : false;
     739    }
     740
     741    return file;
     742}
     743
    911744
    912745// define the named pmFPAfile from the camera->config
    913746// only valid for pmFPAfile->mode = READ
    914 pmFPAfile *pmFPAfileDefineFromConf (bool *success, const pmConfig *config, const char *filename)
     747pmFPAfile *pmFPAfileDefineFromConf(bool *success, const pmConfig *config, const char *filename)
    915748{
    916749    PS_ASSERT_PTR_NON_NULL(config, false);
     
    991824    pmFPA *fpa = NULL;
    992825    pmFPAfile *file = NULL;
     826
     827    if (type == PM_DETREND_TYPE_NONE) {
     828        return NULL;
     829    }
    993830
    994831    if (success) {
     
    11771014    PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
    11781015
    1179     pmFPAfile *file = pmFPAfileDefineOutputForFormat(config, NULL, filename, src->cameraName,
    1180                                                      src->formatName);
     1016    pmFPAfile *file = pmFPAfileDefineOutputForFormat(config, NULL, filename, src->cameraName, src->formatName);
     1017    if (!file) {
     1018        psError(PS_ERR_UNEXPECTED_NULL, false, "file %s not defined\n", filename);
     1019        return NULL;
     1020    }
    11811021    file->src = psMemIncrRefCounter(src->fpa); // inherit output elements from this source pmFPA
    11821022    file->xBin = xBin;
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/camera/pmFPAfileDefine.h

    r20637 r23351  
    5353// Note that the returned pmFPAfile is a view only, so it should not be freed by the caller --- the only
    5454// reference count is held by the config->files metadata.
    55 pmFPAfile *pmFPAfileDefineFromArgs (bool *found, pmConfig *config, const char *filename, const char *argname);
     55pmFPAfile *pmFPAfileDefineFromArgs(bool *found, pmConfig *config, const char *filename, const char *argname);
    5656
    5757// look for the given argname on the argument list; bind the associated files to the specified
     
    5959// Note that the returned pmFPAfile is a view only, so it should not be freed by the caller --- the only
    6060// reference count is held by the config->files metadata.
    61 pmFPAfile *pmFPAfileBindFromArgs (bool *found, pmFPAfile *input, pmConfig *config, const char *filename, const char *argname);
     61pmFPAfile *pmFPAfileBindFromArgs(bool *found, pmFPAfile *input, pmConfig *config, const char *filename, const char *argname);
     62
     63/// Define a file based on the filenames in the RUN metadata in the configuration
     64///
     65/// Note that the returned pmFPAfile is a view only, so it should not be freed by the caller --- the only
     66/// reference count is held by the config->files metadata.
     67pmFPAfile *pmFPAfileDefineFromRun(
     68    bool *found,                        ///< Found files?
     69    pmConfig *config,                   ///< Configuration
     70    const char *filename                ///< Name of file
     71    );
     72
    6273
    6374// look for the given argname on the argument list.  find the give filename from the file rules
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/camera/pmFPAfileIO.c

    r21363 r23351  
    2222#include "pmFPARead.h"
    2323#include "pmFPAWrite.h"
    24 #include "pmFPAfileIO.h"
    2524#include "pmFPAfileFitsIO.h"
    2625#include "pmSpan.h"
     
    4443#include "pmSubtractionIO.h"
    4544#include "pmConcepts.h"
     45#include "pmConfigRun.h"
     46
     47#include "pmFPAfileIO.h"
    4648
    4749// attempt create, read, write, close, or free pmFPAfiles available in files files are
     
    164166    }
    165167
     168    if (!pmConfigRunFileAdd(config, file)) {
     169        psError(PS_ERR_UNKNOWN, false, "Unable to add file to run-time information");
     170        return false;
     171    }
     172
    166173    // select a reading method
    167174    bool status = true;
     
    412419            return false;
    413420        }
     421    }
     422
     423    if (!pmConfigRunFileAdd(config, file)) {
     424        psError(PS_ERR_UNKNOWN, false, "Unable to add file to run-time information");
     425        return false;
    414426    }
    415427
     
    728740    // apply filename mangling rules (file://, path://, neb://)
    729741    bool create = file->mode == PM_FPA_MODE_WRITE ? true : false;
    730     psString tmpName = pmConfigConvertFilename (file->filename, config, create, false);
    731     if (!tmpName) {
     742    psString realName = pmConfigConvertFilename(file->filename, config, create, false);
     743    if (!realName) {
    732744        psError(PS_ERR_IO, false, "failed to determine real name from template for %s\n", file->filename);
    733745        return false;
    734746    }
    735     psFree (file->filename);
    736     file->filename = tmpName;
     747    psFree(file->origname);
     748    file->origname = file->filename;
     749    file->filename = realName;
    737750
    738751    switch (file->type) {
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/camera/pmHDUGenerate.c

    r21363 r23351  
    474474                }
    475475
     476                if (!biassecs || !readout->bias) {
     477                    // No need to worry about bias section
     478                    continue;
     479                }
     480
    476481                if (biassecs->n != readout->bias->n) {
    477482                    psWarning("Number of bias sections (%ld) and number of biases (%ld) do not match.\n",
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/concepts/pmConceptsStandard.c

    r22699 r23351  
    888888      default:
    889889        psError(PS_ERR_UNKNOWN, true, "Unable to parse %s.\n", pattern->name);
     890        return NULL;
     891    }
     892
     893    if (!time) {
     894        psError(PS_ERR_BAD_PARAMETER_SIZE, false, "Unable to parse time for %s", pattern->name);
    890895        return NULL;
    891896    }
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/config/Makefile.am

    r18905 r23351  
    11noinst_LTLIBRARIES = libpsmodulesconfig.la
    22
    3 libpsmodulesconfig_la_CPPFLAGS = $(SRCINC) $(PSMODULES_CFLAGS)
     3# PSMODULES_VERSION=`if [ -e ../../VERSION ]; then cat ../../VERSION; else svnversion; fi`
     4# PSMODULES_BRANCH=`if [ -e ../../BRANCH ]; then cat ../../BRANCH; else svn info | sed -n -e '/URL:/ h' -e '/Repository Root:/ { x; H; x; s|Repository Root: \(.*\)\nURL: \1\(.*\)|\2| ; s|^/|| ; s|/[a-zA-Z]*/src.*|| ; p }'; fi`
     5# PSMODULES_SOURCE=`if [ -e ../../SOURCE ]; then cat ../../SOURCE; else svn info | sed -n -e 's/Repository UUID: // p'; fi`
     6
     7# Force recompilation of pmVersion.c, since it gets the version information
     8# pmVersion.c: FORCE
     9#       touch pmVersion.c
     10# FORCE: ;
     11
     12libpsmodulesconfig_la_CPPFLAGS = $(SRCINC) $(PSMODULES_CFLAGS) -DPSMODULES_VERSION=$(SVN_VERSION) -DPSMODULES_BRANCH=$(SVN_BRANCH) -DPSMODULES_SOURCE=$(SVN_SOURCE)
    413libpsmodulesconfig_la_LDFLAGS  = -release $(PACKAGE_VERSION)
    514libpsmodulesconfig_la_SOURCES  = \
     
    1019        pmConfigMask.c \
    1120        pmConfigDump.c \
     21        pmConfigRun.c \
    1222        pmVersion.c \
    1323        pmErrorCodes.c
     
    2030        pmConfigMask.h \
    2131        pmConfigDump.h \
     32        pmConfigRun.h \
    2233        pmVersion.h \
    2334        pmErrorCodes.h
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/config/pmConfig.c

    r21314 r23351  
    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
     
    142145    config->format = NULL;
    143146    config->formatName = NULL;
    144     config->recipes = psMetadataAlloc();
     147    config->recipes = NULL;
    145148    config->recipesRead = PM_RECIPE_SOURCE_NONE;
    146149    config->recipesCamera = psMetadataAlloc();
     
    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
     
    648643    }
    649644
     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);
     665    }
     666
    650667    // Next, we do a similar thing for the camera configuration file.  The
    651668    // file is read and parsed into psMetadata struct "camera".
     
    11101127// camera.  If we are discovering the camera (config->camera == NULL), then we also load the
    11111128// recipe files for the camera.
    1112 psMetadata *pmConfigCameraFormatFromHeader(psMetadata **camera, psString *cameraName, psString *formatName, 
    1113                                            pmConfig *config, const psMetadata *header, bool readRecipes)
     1129psMetadata *pmConfigCameraFormatFromHeader(psMetadata **camera, psString *cameraName, psString *formatName,
     1130                                           pmConfig *config, const psMetadata *header, bool readRecipes)
    11141131{
    11151132    PS_ASSERT_PTR_NON_NULL(config, NULL);
     
    16721689                // if the object does not exist and create isn't set, then we
    16731690                // should puke
    1674                 psError(PM_ERR_SYS, true, "Unable to access file %s", filename);
     1691                psError(PM_ERR_SYS, true, "Unable to access file %s: %s", filename, nebErr(server));
    16751692                nebServerFree(server);
    16761693                return NULL;
     
    16851702        if (trunc) {
    16861703            if(truncate(path, 0) != 0) {
    1687                 psError(PS_ERR_IO, true, "Failed to truncate Nebulous file %s (real name %s)\n", filename, path);
     1704                psError(PS_ERR_IO, true, "Failed to truncate Nebulous file %s (real name %s)\n",
     1705                        filename, path);
    16881706                return NULL;
    16891707            }
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/config/pmConfigCamera.c

    r22700 r23351  
    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    }
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/config/pmConfigDump.c

    r19399 r23351  
    5454    psArray *keep = psStringSplitArray(save, " ,;", false); // List of items to keep
    5555
    56     bool result = configCull(config->recipes, keep); // Result of culling
     56    if (!configCull(config->recipes, keep)) {
     57        psError(PS_ERR_UNKNOWN, false, "Unable to cull system recipes.");
     58        psFree(keep);
     59        return false;
     60    }
    5761    psFree(keep);
    5862
    59     return result;
     63    // Need to cull recipes from all cameras as well
     64    psMetadata *cameras = psMetadataLookupMetadata(NULL, config->system, "CAMERAS"); // Known cameras
     65    if (!cameras) {
     66        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find CAMERAS in the system configuration.\n");
     67        return false;
     68    }
     69
     70    psMetadataIterator *iter = psMetadataIteratorAlloc(cameras, PS_LIST_HEAD, NULL); // Iterator for cameras
     71    psMetadataItem *item;               // Item from iteration
     72    keep = psArrayAllocEmpty(1);
     73    while ((item = psMetadataGetAndIncrement(iter))) {
     74        psAssert(item->type == PS_DATA_METADATA, "Should only be metadata types on the camera list.");
     75        psMetadata *camera = item->data.md; // Camera configuration
     76        bool mdok;                      // Status of MD lookup
     77        psMetadata *recipes = psMetadataLookupMetadata(&mdok, camera, "RECIPES"); // Recipe overrides
     78        if (!recipes) {
     79            continue;
     80        }
     81        if (!configCull(recipes, keep)) {
     82            psError(PS_ERR_UNKNOWN, false, "Unable to cull recipes for camera %s", item->name);
     83            psFree(iter);
     84            psFree(keep);
     85            return false;
     86        }
     87    }
     88    psFree(iter);
     89    psFree(keep);
     90
     91    return true;
    6092}
    6193
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/config/pmConfigRecipes.c

    r21387 r23351  
    1111#include "pmConfigRecipes.h"
    1212
    13 static bool loadRecipeSystem(bool *status, pmConfig *config, psMetadata *source);
     13static bool loadRecipeSystem(bool *status, pmConfig *config);
    1414static bool loadRecipeCamera(bool *status, pmConfig *config, psMetadata *source);
    1515static bool loadRecipeSymbols(bool *status, pmConfig *config, pmRecipeSource source);
     
    5656    PS_ASSERT_PTR_NON_NULL(config, false);
    5757
    58     if (!config->recipes) {
    59         config->recipes = psMetadataAlloc();
    60     }
    61 
    6258    // Read the recipe file names from the system configuration and camera configuration
    6359    // It is an error for config->system:recipes not to exist.  all programs install their
    6460    // master recipe files in the system:recipe location when they are built.
    6561    psAssert(config->system, "base config data defined");
    66     if (source & PM_RECIPE_SOURCE_SYSTEM) {
    67         if (!loadRecipeSystem(&status, config, config->system)) {
     62    if (!config->recipes || (source & PM_RECIPE_SOURCE_SYSTEM)) {
     63        if (!loadRecipeSystem(&status, config)) {
    6864            psError(PS_ERR_IO, false, "Failed to read recipes from system config");
    6965            return false;
     
    321317// Load the recipe files for SYSTEM : REQUIRED
    322318static bool loadRecipeSystem(bool *status,
    323                            pmConfig *config, // The configuration into which to read the recipes
    324                            psMetadata *source // The source configuration, from which to read the filenames
     319                           pmConfig *config // The configuration into which to read the recipes
    325320    )
    326321{
     
    329324    *status = false;
    330325
    331     if (!source) {
     326    if (!config->system) {
    332327        psError(PS_ERR_IO, true,
    333328                "The system configuration has not been read --- cannot read recipes from this location.\n");
     
    336331    }
    337332
    338     psMetadata *recipes = psMetadataLookupMetadata(NULL, source, "RECIPES"); // The list of recipes
    339     if (!recipes) {
    340         psError(PS_ERR_IO, false, "RECIPES not found in the system configuration\n");
    341         return false;
    342     }
    343 
    344     // Copy contents of the filenames to config->recipes from the "RECIPES" metadata in the source.
    345     // We could use psMetadataCopy for this, but it's better to check that everything's of the correct type.
    346     // If it's not of the correct type, we can tell the user which file it's in, so they can find it easier.
    347     psMetadataIterator *recipesIter = psMetadataIteratorAlloc(recipes, PS_LIST_HEAD, NULL); // Iterator
     333    if (!config->recipes) {
     334        config->recipes = psMemIncrRefCounter(psMetadataLookupMetadata(NULL, config->system, "RECIPES")); // The list of recipes
     335        if (!config->recipes) {
     336            psError(PS_ERR_IO, false, "RECIPES not found in the system configuration\n");
     337            return false;
     338        }
     339    }
     340
     341    // Read in the component recipes
     342    psMetadataIterator *recipesIter = psMetadataIteratorAlloc(config->recipes, PS_LIST_HEAD, NULL); // Iterator
    348343    psMetadataItem *item = NULL;        // MD item containing the filename, from recipe iteration
    349344    while ((item = psMetadataGetAndIncrement(recipesIter))) {
     
    353348            psFree(recipesIter);
    354349            return false;
    355         }
    356 
    357         // add the contents of this recipe file to config->recipes
    358         psMetadataAdd(config->recipes, PS_LIST_TAIL, item->name, PS_DATA_METADATA | PS_META_REPLACE,
    359                       item->comment, item->data.md);
     350        }
    360351    }
    361352    psFree(recipesIter);
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/config/pmConfigRecipes.h

    r12916 r23351  
    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/// @}
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/config/pmVersion.c

    r10291 r23351  
    88#include "pmVersion.h"
    99
    10 static const char *cvsTag = "$Name: not supported by cvs2svn $";// CVS tag name
     10#ifndef PSMODULES_VERSION
     11#error "PSMODULES_VERSION is not set"
     12#endif
     13#ifndef PSMODULES_BRANCH
     14#error "PSMODULES_BRANCH is not set"
     15#endif
     16#ifndef PSMODULES_SOURCE
     17#error "PSMODULES_SOURCE is not set"
     18#endif
     19
     20#define xstr(s) str(s)
     21#define str(s) #s
    1122
    1223psString psModulesVersion(void)
    1324{
    14     psString version = NULL;            // Version, to return
    15     psStringAppend(&version, "%s-%s",PACKAGE_NAME,PACKAGE_VERSION);
    16     return version;
     25    char *value = NULL;
     26    psStringAppend(&value, "%s@%s", xstr(PSMODULES_BRANCH), xstr(PSMODULES_VERSION));
     27    return value;
    1728}
     29
     30psString psModulesSource(void)
     31{
     32    return psStringCopy(xstr(PSMODULES_SOURCE));
     33}
     34
    1835
    1936psString psModulesVersionLong(void)
    2037{
    21     psString version = psModulesVersion(); // Version, to return
    22     psString tag = psStringStripCVS(cvsTag, "Name"); // CVS tag
     38    psString version = psModulesVersion();  // Version, to return
     39    psString source = psModulesSource();    // Source
    2340
    24     psStringAppend(&version, " (cvs tag %s) %s, %s", tag, __DATE__, __TIME__);
     41    psStringPrepend(&version, "psModules ");
     42    psStringAppend(&version, " from %s, built %s, %s", source, __DATE__, __TIME__);
     43    psFree(source);
    2544
    26     psFree(tag);
     45#ifdef __OPTIMIZE__
     46    psStringAppend(&version, " optimised");
     47#else
     48    psStringAppend(&version, " unoptimised");
     49#endif
     50
     51#ifdef HAVE_NEBCLIENT
     52    psStringAppend(&version, " with nebclient");
     53#else
     54    psStringAppend(&version, " without nebclient");
     55#endif
     56
    2757    return version;
     58};
     59
     60
     61bool psModulesVersionHeader(psMetadata *header)
     62{
     63    PS_ASSERT_METADATA_NON_NULL(header, false);
     64
     65    psString version = psModulesVersion(); // Software version
     66    psString source = psModulesSource();   // Software source
     67
     68    psStringPrepend(&version, "psModules version: ");
     69    psStringPrepend(&source, "psModules source: ");
     70
     71    psMetadataAddStr(header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, NULL, version);
     72    psMetadataAddStr(header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, NULL, source);
     73
     74    psFree(version);
     75    psFree(source);
     76
     77    return true;
    2878}
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/config/pmVersion.h

    r12696 r23351  
    11/*  @file pmVersion.h
    22 *  @brief Version functions
    3  * 
     3 *
    44 *  @author Paul Price, IfA
    55 *  @author Eugene Magnier, IfA
    6  * 
     6 *
    77 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    88 *  @date $Date: 2007-03-30 21:12:56 $
     
    2222 *  @return psString: String with version name.
    2323 */
    24 psString psModulesVersion(
    25     void
    26 );
     24psString psModulesVersion(void);
     25
     26/** Get current psModules source
     27 *
     28 *  Returns the current psModules source as a string.
     29 *
     30 *  @return psString: String with source.
     31 */
     32psString psModulesSource(void);
    2733
    2834/** Get current psModules version (full identification)
     
    3440psString psModulesVersionLong(void);
    3541
     42/// Populate a header with version information
     43bool psModulesVersionHeader(
     44    psMetadata *header                  ///< Header to populate
     45    );
     46
     47
    3648/// @}
    3749#endif
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/detrend/pmDetrendDB.c

    r20401 r23351  
    2020
    2121//
    22 static void pmDetrendSelectOptionsFree (pmDetrendSelectOptions *options)
    23 {
    24 
    25     if (!options)
     22static void pmDetrendSelectOptionsFree(pmDetrendSelectOptions *options)
     23{
     24
     25    if (!options) {
    2626        return;
    27 
    28     psFree (options->camera);
    29     psFree (options->filter);
    30     psFree (options->dettype);
    31     psFree (options->version);
     27    }
     28
     29    psFree(options->camera);
     30    psFree(options->filter);
     31    psFree(options->dettype);
     32    psFree(options->version);
    3233
    3334    return;
     
    3738pmDetrendSelectOptions *pmDetrendSelectOptionsAlloc(const char *camera, psTime time, pmDetrendType type)
    3839{
    39 
    4040    pmDetrendSelectOptions *options = psAlloc(sizeof(pmDetrendSelectOptions));
    4141    psMemSetDeallocator(options, (psFreeFunc) pmDetrendSelectOptionsFree);
     
    6363}
    6464
    65 static void pmDetrendSelectResultsFree (pmDetrendSelectResults *results)
    66 {
    67 
    68     if (!results)
     65static void pmDetrendSelectResultsFree(pmDetrendSelectResults *results)
     66{
     67
     68    if (!results) {
    6969        return;
    70 
    71     psFree (results->detID);
     70    }
     71
     72    psFree(results->detID);
    7273    psFree(results->level);
    7374
     
    7576}
    7677
    77 pmDetrendSelectResults *pmDetrendSelectResultsAlloc ()
     78pmDetrendSelectResults *pmDetrendSelectResultsAlloc(void)
    7879{
    7980
     
    8788}
    8889
    89 psString pmDetrendTypeToString (pmDetrendType type)
    90 {
    91 
    92     # define DETREND_STRING_CASE(TTT) \
    93 case PM_DETREND_TYPE_##TTT: \
    94     return psStringCopy (#TTT);
     90psString pmDetrendTypeToString(pmDetrendType type)
     91{
     92
     93#define DETREND_STRING_CASE(TYPE) \
     94  case PM_DETREND_TYPE_##TYPE: \
     95    return psStringCopy(#TYPE);
    9596
    9697    switch (type) {
    97         DETREND_STRING_CASE (MASK);
    98         DETREND_STRING_CASE (BIAS);
    99         DETREND_STRING_CASE (DARK);
    100         DETREND_STRING_CASE (FLAT);
    101         DETREND_STRING_CASE (FLATCORR);
    102         DETREND_STRING_CASE (SHUTTER);
    103         DETREND_STRING_CASE (FRINGE);
    104         DETREND_STRING_CASE (ASTROM);
     98        DETREND_STRING_CASE(NONE);
     99        DETREND_STRING_CASE(MASK);
     100        DETREND_STRING_CASE(BIAS);
     101        DETREND_STRING_CASE(DARK);
     102        DETREND_STRING_CASE(FLAT);
     103        DETREND_STRING_CASE(FLATCORR);
     104        DETREND_STRING_CASE(SHUTTER);
     105        DETREND_STRING_CASE(FRINGE);
     106        DETREND_STRING_CASE(ASTROM);
    105107    default:
    106108        return NULL;
     
    111113// detselect -camera (camera) -time (time) -type (type) [others]
    112114// returns: (type) (class) (exp_flag) DONE
    113 pmDetrendSelectResults *pmDetrendSelect (const pmDetrendSelectOptions *options,
    114         const pmConfig *config)
     115pmDetrendSelectResults *pmDetrendSelect(const pmDetrendSelectOptions *options, const pmConfig *config)
    115116{
    116117    PS_ASSERT_PTR_NON_NULL(options, NULL);
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/detrend/pmDetrendDB.h

    r20401 r23351  
    2525
    2626typedef enum {
     27    PM_DETREND_TYPE_NONE,
    2728    PM_DETREND_TYPE_MASK,
    2829    PM_DETREND_TYPE_BIAS,
     
    5960} pmDetrendSelectResults;
    6061
    61 psString pmDetrendTypeToString (pmDetrendType type);
     62psString pmDetrendTypeToString(pmDetrendType type);
    6263
    6364pmDetrendSelectOptions *pmDetrendSelectOptionsAlloc(const char *camera, psTime time, pmDetrendType type);
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/detrend/pmFringeStats.c

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

    r21183 r23351  
    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
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/detrend/pmShutterCorrection.c

    r21457 r23351  
    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);
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/extras/pmVisual.c

    r21422 r23351  
    1818#include "pmHDU.h"
    1919#include "pmFPA.h"
     20#include "pmFPAfile.h"
    2021#include "pmAstrometryObjects.h"
     22#include "pmSubtractionStamps.h"
     23#include "pmTrend2D.h"
    2124#include "pmFPAExtent.h"
    2225
     
    2831# define KAPAY 700
    2932
     33#include "pmAstrometryVisual.h"
     34#include "pmSubtractionVisual.h"
     35#include "pmStackVisual.h"
     36#include "pmSourceVisual.h"
     37
     38//#define TESTING
     39
     40static bool isVisual = false;
     41
     42
     43bool pmVisualSetVisual(bool value) {
     44    isVisual = value;
     45    return true;
     46}
     47
     48
     49bool pmVisualIsVisual(void) {return isVisual;}
     50
     51bool pmVisualClose(void) {
     52    pmAstromVisualClose();
     53    pmSubtractionVisualClose();
     54    pmStackVisualClose();
     55    pmSourceVisualClose();
     56    //XXX handle psphot
     57    //    psphotVisualClose();
     58    return true;
     59}
    3060
    3161bool pmVisualInitWindow (int *kapid, char *name) {
     
    3464        if (*kapid == -1) {
    3565            fprintf (stderr, "Failure to open kapa.\n");
     66            isVisual = false;
    3667            return false;
    3768        }
     
    5283
    5384
    54 bool pmVisualAskUser(bool *plotFlag, bool *packageFlag)
     85bool pmVisualAskUser(bool *plotFlag)
    5586{
    5687    char key[10];
     
    6394    }
    6495    if (key[0] == 'a') {
    65         *packageFlag = false;
     96        isVisual = false;
    6697    }
    6798    return true;
     
    182213
    183214bool pmVisualScaleImage(int kapaFD, psImage *inImage, const char *name, int channel, bool clip) {
    184 
    185215    KiiImage image;
    186216    KapaImageData data;
    187217    Coords coords;
    188218
    189     //make sure we have a compatible image type
     219    //make sure we have a compatible image
     220    if (inImage == NULL) {
     221        fprintf(stderr, "Image is NULL, and cannot be displayed\n");
     222        return false;
     223    }
     224
    190225    if(inImage->type.type != PS_TYPE_F32) {
    191226        fprintf(stderr, "Cannot display this image (imcompatible data type)\n");
     
    194229
    195230    strcpy (coords.ctype, "RA---TAN");
     231
    196232
    197233    double min, max, stdev, mean;
     
    304340
    305341#else
    306 
     342bool pmVisualSetVisual(bool value) {return true;}
     343bool pmVisualIsVisual(void) {return false;}
     344bool pmVisualClose(void) {return true;}
    307345bool pmVisualInitWindow(int *kapid, char *name){return true;}
    308346bool pmVisualInitGraph (int kapa, void *section, void *graphdata){return true;}
    309347
    310 bool pmVisualAskUser(bool *plotFlag, bool *packageFlag){return true;}
     348bool pmVisualAskUser(bool *plotFlag){return true;}
    311349bool pmVisualImStats(psImage *image, double *mean,
    312350                     double *stdev, double *min, double *max){return true;}
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/extras/pmVisual.h

    r21422 r23351  
    1010
    1111#if (HAVE_KAPA)
     12
     13
     14/** Globally enable or disable plotting
     15 * @param value - true to enable plotting
     16 * @return true
     17 */
     18bool pmVisualSetVisual(bool value);
     19
     20
     21/** Check whether plotting is enabled
     22 * @retrun true if plots should be generated
     23 */
     24bool pmVisualIsVisual(void);
     25
     26
     27/** Destroy plotting windows at the end of a run
     28 * @return true for success */
     29bool pmVisualClose(void);
    1230
    1331
     
    3250 * At the user's request, this will disable diagnostic plotting.
    3351 * @param plotFlag, set to false if this plot should be disabled in the future
    34  * @param packageFlag, set to false if all plots from this package (e.g. psastro, pmSubtraction)
    35  *                      should be disabled.
    3652 */
    37 bool pmVisualAskUser(bool *plotFlag, bool *packageFlag);
     53bool pmVisualAskUser(bool *plotFlag);
    3854
    3955
     
    115131
    116132// kapa-specific data types are changed to void
     133bool pmVisualSetVisual(bool value);
     134bool pmVisualIsVisual(void);
     135bool pmVisualClose(void);
    117136bool pmVisualInitWindow (int *kapid, char *name);
    118137bool pmVisualInitGraph (int kapa, void *section, void *graphdata);
    119 bool pmVisualAskUser(bool *plotFlag, bool *packageFlag);
     138bool pmVisualAskUser(bool *plotFlag);
    120139bool pmVisualScaleImage(int kapaFD, psImage *inImage,
    121140                        const char *name, int channel, bool clip);
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/imcombine/Makefile.am

    r21422 r23351  
    1919        pmSubtractionThreads.c  \
    2020        pmPSFEnvelope.c         \
    21         pmSubtractionVisual.c
     21        pmSubtractionVisual.c   \
     22        pmStackVisual.c
    2223
    2324pkginclude_HEADERS = \
     
    3738        pmSubtractionThreads.h  \
    3839        pmPSFEnvelope.h         \
    39         pmSubtractionVisual.h
     40        pmSubtractionVisual.h   \
     41        pmStackVisual.h
    4042
    4143CLEANFILES = *~
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/imcombine/pmPSFEnvelope.c

    r21363 r23351  
    3030
    3131#include "pmPSFEnvelope.h"
    32 
     32#include "pmStackVisual.h"
    3333
    3434
     
    115115    for (int i = 0; i < inputs->n; i++) {
    116116        pmPSF *psf = inputs->data[i];   // PSF of interest
     117        if (!psf) {
     118            continue;
     119        }
    117120        pmResiduals *resid = psf->residuals;// PSF residuals
    118121        psf->residuals = NULL;
     
    162165            psStringAppend(&name, "psf_field_%03d.fits", i);
    163166            psFits *fits = psFitsOpen(name, "w");
     167            pmStackVisualPlotTestImage(fakeRO->image, name);
    164168            psFitsWriteImage(fits, NULL, fakeRO->image, 0, NULL);
    165169            psFitsClose(fits);
     
    179183        // Write out the envelope
    180184        psFits *fits = psFitsOpen("psf_field_envelope.fits", "w");
     185        pmStackVisualPlotTestImage(envelope, "psf_field_envelope.fits");
    181186        psFitsWriteImage(fits, NULL, envelope, 0, NULL);
    182187        psFitsClose(fits);
     
    231236        // Write out the envelope
    232237        psFits *fits = psFitsOpen("psf_field_full.fits", "w");
     238        pmStackVisualPlotTestImage(readout->image, "psf_field_full.fits");
    233239        psFitsWriteImage(fits, NULL, readout->image, 0, NULL);
    234240        psFitsClose(fits);
     
    312318        {
    313319            psFits *fits = psFitsOpen("psf_field_model.fits", "w");
     320            pmStackVisualPlotTestImage(generated->image, "psf_field_model.fits");
    314321            psFitsWriteImage(fits, NULL, generated->image, 0, NULL);
    315322            psFitsClose(fits);
     
    318325        {
    319326            psFits *fits = psFitsOpen("psf_field_resid.fits", "w");
     327            pmStackVisualPlotTestImage(generated->image, "psf_field_resid.fits");
    320328            psFitsWriteImage(fits, NULL, generated->image, 0, NULL);
    321329            psFitsClose(fits);
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/imcombine/pmStack.c

    r21476 r23351  
    88 *  @author GLG, MHPCC
    99 *
    10  *  @version $Revision: 1.48 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2009-02-13 23:52:14 $
     10 *  @version $Revision: 1.48.2.1 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2009-02-19 17:59:50 $
    1212 *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
    1313 *
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/imcombine/pmSubtractionIO.c

    r22699 r23351  
    1616
    1717#include "pmSubtractionIO.h"
     18#include "pmStackVisual.h"
    1819
    1920#define ARRAY_BUFFER 16                 // Number to add to array at a time
     
    144145    // CVS tags, used to identify the version of this file (in case incompatibilities are introduced)
    145146    psString cvsFile = psStringCopy("$RCSfile: pmSubtractionIO.c,v $");
    146     psString cvsRev  = psStringCopy("$Revision: 1.9 $");
    147     psString cvsDate = psStringCopy("$Date: 2008-10-24 21:21:06 $");
     147    psString cvsRev  = psStringCopy("$Revision: 1.9.18.1 $");
     148    psString cvsDate = psStringCopy("$Date: 2009-02-19 17:59:50 $");
    148149    psStringSubstitute(&cvsFile, NULL, "RCSfile: ");
    149150    psStringSubstitute(&cvsRev,  NULL, "Revision: ");
     
    167168
    168169    psImage *image = psMetadataLookupPtr(NULL, ro->analysis, PM_SUBTRACTION_ANALYSIS_KERNEL_IMAGE); // Image
     170    pmStackVisualPlotTestImage(image, "Subtraction_kernels.fits");
     171
    169172    if (image && !psFitsWriteImage(fits, header, image, 0, EXTNAME_IMAGE)) {
    170173        psError(PS_ERR_IO, false, "Unable to write subtraction kernel image.");
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/imcombine/pmSubtractionMatch.c

    r21422 r23351  
    9090}
    9191
     92// Check input arguments
     93static bool subtractionMatchCheck(pmReadout *conv1, pmReadout *conv2, // Convolved images
     94                                  const pmReadout *ro1, const pmReadout *ro2, // Input images
     95                                  int stride, // Size for convolution patches
     96                                  float sysError, // Relative systematic error
     97                                  psImageMaskType maskVal, // Value to mask for input
     98                                  psImageMaskType maskBad, // Mask for output bad pixels
     99                                  psImageMaskType maskPoor, // Mask for output poor pixels
     100                                  float poorFrac, // Fraction for "poor"
     101                                  float badFrac,   // Maximum fraction of bad input pixels to accept
     102                                  pmSubtractionMode subMode // Mode of subtraction
     103                                  )
     104{
     105    if (subMode != PM_SUBTRACTION_MODE_2) {
     106        PM_ASSERT_READOUT_NON_NULL(conv1, false);
     107        if (conv1->image) {
     108            psFree(conv1->image);
     109            conv1->image = NULL;
     110        }
     111        if (conv1->mask) {
     112            psFree(conv1->mask);
     113            conv1->mask = NULL;
     114        }
     115        if (conv1->variance) {
     116            psFree(conv1->variance);
     117            conv1->variance = NULL;
     118        }
     119    }
     120    if (subMode != PM_SUBTRACTION_MODE_1) {
     121        PM_ASSERT_READOUT_NON_NULL(conv2, false);
     122        if (conv2->image) {
     123            psFree(conv2->image);
     124            conv2->image = NULL;
     125        }
     126        if (conv2->mask) {
     127            psFree(conv2->mask);
     128            conv2->mask = NULL;
     129        }
     130        if (conv2->variance) {
     131            psFree(conv2->variance);
     132            conv2->variance = NULL;
     133        }
     134    }
     135
     136    PM_ASSERT_READOUT_NON_NULL(ro1, false);
     137    PM_ASSERT_READOUT_NON_NULL(ro2, false);
     138    PM_ASSERT_READOUT_IMAGE(ro1, false);
     139    PM_ASSERT_READOUT_IMAGE(ro2, false);
     140    PS_ASSERT_IMAGES_SIZE_EQUAL(ro1->image, ro2->image, false);
     141    PS_ASSERT_INT_NONNEGATIVE(stride, false);
     142    if (isfinite(sysError)) {
     143        PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(sysError, 0.0, false);
     144        PS_ASSERT_FLOAT_LESS_THAN(sysError, 1.0, false);
     145    }
     146    // Don't care about maskVal
     147    // Don't care about maskBad
     148    // Don't care about maskPoor
     149    PS_ASSERT_FLOAT_LARGER_THAN(poorFrac, 0.0, false);
     150    PS_ASSERT_FLOAT_LESS_THAN_OR_EQUAL(poorFrac, 1.0, false);
     151    if (isfinite(badFrac)) {
     152        PS_ASSERT_FLOAT_LARGER_THAN(badFrac, 0.0, false);
     153        PS_ASSERT_FLOAT_LESS_THAN_OR_EQUAL(badFrac, 1.0, false);
     154    }
     155
     156    return true;
     157}
     158
     159
     160
     161bool pmSubtractionMatchPrecalc(pmReadout *conv1, pmReadout *conv2, const pmReadout *ro1, const pmReadout *ro2,
     162                               psMetadata *analysis, int stride, float sysError,
     163                               psImageMaskType maskVal, psImageMaskType maskBad, psImageMaskType maskPoor,
     164                               float poorFrac, float badFrac)
     165{
     166    PS_ASSERT_METADATA_NON_NULL(analysis, false);
     167
     168    // Extract the kernels
     169    pmSubtractionMode mode = PM_SUBTRACTION_MODE_UNSURE; // Subtraction mode: which image to convolve
     170    int size = 0;                       // Size of kernel
     171    psList *kernelList = psListAlloc(NULL); // List of kernels
     172    {
     173        psMetadataIterator *iter = psMetadataIteratorAlloc(analysis, PS_LIST_HEAD,
     174                                                           "^" PM_SUBTRACTION_ANALYSIS_KERNEL "$");
     175        psMetadataItem *item;               // Item from iteration
     176        while ((item = psMetadataGetAndIncrement(iter))) {
     177            if (item->type != PS_DATA_UNKNOWN) {
     178                psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unexpected type for kernel.");
     179                psFree(iter);
     180                psFree(kernelList);
     181                return false;
     182            }
     183            pmSubtractionKernels *kernel = item->data.V; // Kernel
     184            PM_ASSERT_SUBTRACTION_KERNELS_NON_NULL(kernel, false);
     185            size = PS_MAX(size, kernel->size);
     186            if (mode == PM_SUBTRACTION_MODE_UNSURE) {
     187                mode = kernel->mode;
     188            } else if (kernel->mode != mode) {
     189                // There's some confusion, so let's set the mode to dual convolution.
     190                // This is only used for the subtraction mask, so it's not a big deal.
     191                mode = PM_SUBTRACTION_MODE_DUAL;
     192            }
     193            psListAdd(kernelList, PS_LIST_TAIL, kernel);
     194        }
     195        psFree(iter);
     196    }
     197    if (psListLength(kernelList) == 0) {
     198        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find kernels");
     199        psFree(kernelList);
     200        return false;
     201    }
     202    psArray *kernels = psListToArray(kernelList); // Array of kernels
     203    psFree(kernelList);
     204
     205    // Extract the regions
     206    psArray *regions = psArrayAllocEmpty(kernels->n); // Array of regions
     207    {
     208        psMetadataIterator *iter = psMetadataIteratorAlloc(analysis, PS_LIST_HEAD,
     209                                                           "^" PM_SUBTRACTION_ANALYSIS_REGION "$");
     210        psMetadataItem *item;               // Item from iteration
     211        while ((item = psMetadataGetAndIncrement(iter))) {
     212            if (item->type != PS_DATA_REGION) {
     213                psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unexpected type for region.");
     214                psFree(iter);
     215                psFree(kernels);
     216                psFree(regions);
     217                return false;
     218            }
     219            psRegion *region = item->data.V; // Region
     220            psArrayAdd(regions, regions->n, region);
     221        }
     222        psFree(iter);
     223    }
     224    if (regions->n != kernels->n) {
     225        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Differing number of kernels (%ld) and regions (%ld)",
     226                kernels->n, regions->n);
     227        psFree(regions);
     228        psFree(kernels);
     229        return false;
     230    }
     231
     232    if (!subtractionMatchCheck(conv1, conv2, ro1, ro2, stride, sysError, maskVal, maskBad, maskPoor,
     233                               poorFrac, badFrac, mode)) {
     234        psFree(kernels);
     235        psFree(regions);
     236        return false;
     237    }
     238
     239    psImage *subMask = pmSubtractionMask(ro1->mask, ro2 ? ro2->mask : NULL, maskVal, size, 0,
     240                                         badFrac, useFFT); // Subtraction mask
     241    if (!subMask) {
     242        psError(PS_ERR_UNKNOWN, false, "Unable to generate subtraction mask.");
     243        psFree(kernels);
     244        psFree(regions);
     245        return false;
     246    }
     247
     248    psMetadata *outAnalysis = psMetadataAlloc(); // Output analysis values
     249
     250    psTrace("psModules.imcombine", 2, "Convolving...\n");
     251    for (int i = 0; i < kernels->n; i++) {
     252        pmSubtractionKernels *kernel = kernels->data[i]; // Kernel of interest
     253        psRegion *region = regions->data[i]; // Region of interest
     254
     255        if (!pmSubtractionAnalysis(outAnalysis, kernel, region, ro1->image->numCols, ro1->image->numRows)) {
     256            psError(PS_ERR_UNKNOWN, false, "Unable to generate QA data");
     257            psFree(outAnalysis);
     258            psFree(subMask);
     259            psFree(kernels);
     260            psFree(regions);
     261            return false;
     262        }
     263
     264        if (!pmSubtractionConvolve(conv1, conv2, ro1, ro2, subMask, stride, maskBad, maskPoor, poorFrac,
     265                                   sysError, region, kernel, true, useFFT)) {
     266            psError(PS_ERR_UNKNOWN, false, "Unable to convolve image.");
     267            psFree(outAnalysis);
     268            psFree(subMask);
     269            psFree(kernels);
     270            psFree(regions);
     271            return false;
     272        }
     273    }
     274
     275    psFree(subMask);
     276    psFree(kernels);
     277    psFree(regions);
     278
     279    if (conv1) {
     280        psMetadataCopy(conv1->analysis, outAnalysis);
     281    }
     282    if (conv2) {
     283        psMetadataCopy(conv2->analysis, outAnalysis);
     284    }
     285    psFree(outAnalysis);
     286
     287    return true;
     288}
     289
    92290
    93291bool pmSubtractionMatch(pmReadout *conv1, pmReadout *conv2, const pmReadout *ro1, const pmReadout *ro2,
     
    101299                        psImageMaskType maskPoor, float poorFrac, float badFrac, pmSubtractionMode subMode)
    102300{
    103     if (subMode != PM_SUBTRACTION_MODE_2) {
    104         PM_ASSERT_READOUT_NON_NULL(conv1, false);
    105         if (conv1->image) {
    106             psFree(conv1->image);
    107             conv1->image = NULL;
    108         }
    109         if (conv1->mask) {
    110             psFree(conv1->mask);
    111             conv1->mask = NULL;
    112         }
    113         if (conv1->variance) {
    114             psFree(conv1->variance);
    115             conv1->variance = NULL;
    116         }
    117     }
    118     if (subMode != PM_SUBTRACTION_MODE_1) {
    119         PM_ASSERT_READOUT_NON_NULL(conv2, false);
    120         if (conv2->image) {
    121             psFree(conv2->image);
    122             conv2->image = NULL;
    123         }
    124         if (conv2->mask) {
    125             psFree(conv2->mask);
    126             conv2->mask = NULL;
    127         }
    128         if (conv2->variance) {
    129             psFree(conv2->variance);
    130             conv2->variance = NULL;
    131         }
    132     }
    133 
    134     PM_ASSERT_READOUT_NON_NULL(ro1, false);
    135     PM_ASSERT_READOUT_NON_NULL(ro2, false);
    136     PM_ASSERT_READOUT_IMAGE(ro1, false);
    137     PM_ASSERT_READOUT_IMAGE(ro2, false);
    138     PS_ASSERT_IMAGES_SIZE_EQUAL(ro1->image, ro2->image, false);
     301    if (!subtractionMatchCheck(conv1, conv2, ro1, ro2, stride, sysError, maskVal, maskBad, maskPoor,
     302                               poorFrac, badFrac, subMode)) {
     303        return false;
     304    }
    139305
    140306    PS_ASSERT_INT_NONNEGATIVE(footprint, false);
    141     PS_ASSERT_INT_NONNEGATIVE(stride, false);
    142307    // regionSize can be just about anything (except maybe negative, but it can be NAN)
    143308    PS_ASSERT_FLOAT_LARGER_THAN(stampSpacing, 0.0, false);
     
    168333    PS_ASSERT_INT_POSITIVE(iter, false);
    169334    PS_ASSERT_FLOAT_LARGER_THAN(rej, 0.0, false);
    170     if (isfinite(sysError)) {
    171         PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(sysError, 0.0, NULL);
    172         PS_ASSERT_FLOAT_LESS_THAN(sysError, 1.0, NULL);
    173     }
    174     // Don't care about maskVal
    175     // Don't care about maskBad
    176     // Don't care about maskPoor
    177     PS_ASSERT_FLOAT_LARGER_THAN(poorFrac, 0.0, NULL);
    178     PS_ASSERT_FLOAT_LESS_THAN_OR_EQUAL(poorFrac, 1.0, NULL);
    179     if (isfinite(badFrac)) {
    180         PS_ASSERT_FLOAT_LARGER_THAN(badFrac, 0.0, NULL);
    181         PS_ASSERT_FLOAT_LESS_THAN_OR_EQUAL(badFrac, 1.0, NULL);
    182     }
    183335
    184336    // If the stamp footprint is smaller than the kernel size, then we won't get much signal in the outer
     
    214366    int numCols = ro1->image->numCols, numRows = ro1->image->numRows; // Image dimensions
    215367
    216     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0); // Random number generator
     368    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator
    217369
    218370    memCheck("start");
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/imcombine/pmSubtractionMatch.h

    r21183 r23351  
    4848    );
    4949
     50/// Match two images using precalculated kernel
     51bool pmSubtractionMatchPrecalc(pmReadout *conv1, ///< Output convolved data for image 1
     52                               pmReadout *conv2, ///< Output convolved data for image 2
     53                               const pmReadout *ro1, ///< Image 1
     54                               const pmReadout *ro2, ///< Image 2
     55                               psMetadata *analysis, ///< Analysis metadata with pre-calculated kernel, region
     56                               int stride, ///< Size for convolution patches
     57                               float sysError, ///< Relative systematic error
     58                               psImageMaskType maskVal, ///< Value to mask for input
     59                               psImageMaskType maskBad, ///< Mask for output bad pixels
     60                               psImageMaskType maskPoor, ///< Mask for output poor pixels
     61                               float poorFrac, ///< Fraction for "poor"
     62                               float badFrac ///< Maximum fraction of bad input pixels to accept
     63    );
     64
    5065/// Execute a thread job to measure the PSF width ratios
    5166bool pmSubtractionOrderThread(psThreadJob *job ///< Job to execute
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/imcombine/pmSubtractionVisual.c

    r21422 r23351  
    2828
    2929//variables to determine when things are plotted
    30 static bool isVisual             = false;
    3130static bool plotConvKernels      = true;
    3231static bool plotStamps           = true;
     
    4241// Initialization Routines
    4342
    44 /** start or stop plotting */
    45 bool pmSubtractionSetVisual (bool mode) {
    46     isVisual = mode;
    47     return true;
    48 }
    4943
    5044
     
    6559 *    @return true for success */
    6660bool pmSubtractionVisualPlotConvKernels(psImage *convKernels) {
    67     if (!isVisual || !plotConvKernels) return true;
     61    if (!pmVisualIsVisual() || !plotConvKernels) return true;
    6862    if (!pmVisualInitWindow(&kapa, "ppSub:Images")) {
    69         isVisual = false;
    7063        return false;
    7164    }
    7265    pmVisualScaleImage(kapa, convKernels, "Convolution_Kernels", 0, true);
    73     pmVisualAskUser(&plotConvKernels, &isVisual);
     66    pmVisualAskUser(&plotConvKernels);
    7467    return true;
    7568}
     
    8073    @return true for success */
    8174bool pmSubtractionVisualPlotStamps(pmSubtractionStampList *stamps, pmReadout *ro) {
    82     if (!isVisual || !plotStamps) return true;
     75    if (!pmVisualIsVisual() || !plotStamps) return true;
    8376    if (!pmVisualInitWindow (&kapa, "ppSub:Images")) {
    84         isVisual = false;
    8577        return false;
    8678    }
    8779    if (!pmVisualInitWindow (&kapa2, "ppSub:StampMasterImage")) {
    88         isVisual = false;
    8980        return false;
    9081    }
     
    145136    pmVisualScaleImage(kapa, canvas, "Subtraction_Stamps", 0, true);
    146137
    147     pmVisualAskUser(&plotStamps, &isVisual);
     138    pmVisualAskUser(&plotStamps);
    148139    return true;
    149140}
     
    152143bool pmSubtractionVisualPlotLeastSquares (pmSubtractionStampList *stamps, bool dual) {
    153144
    154     if (!isVisual || !plotLeastSquares) return true;
     145    if (!pmVisualIsVisual() || !plotLeastSquares) return true;
    155146    if (!pmVisualInitWindow (&kapa, "PPSub:Images")) {
    156         isVisual = false;
    157147        return false;
    158148    }
     
    209199    pmVisualScaleImage(kapa, canvas32, "Least_Squares", 0, true);
    210200
    211     pmVisualAskUser(&plotLeastSquares, &isVisual);
     201    pmVisualAskUser(&plotLeastSquares);
    212202    psFree(canvas);
    213203    psFree(canvas32);
     
    216206
    217207bool pmSubtractionVisualShowSubtraction(psImage *image, psImage *ref, psImage *sub) {
    218     if (!isVisual || !plotImage) return true;
     208    if (!pmVisualIsVisual() || !plotImage) return true;
    219209    if (!pmVisualInitWindow (&kapa, "PPSub:Images")) {
    220         isVisual = false;
    221210        return false;
    222211    }
     
    225214    pmVisualScaleImage(kapa, ref, "Reference", 1, true);
    226215    pmVisualScaleImage(kapa, sub, "Subtraction", 2, true);
    227     pmVisualAskUser(&plotImage, &isVisual);
     216    pmVisualAskUser(&plotImage);
    228217    return true;
    229218}
     
    267256
    268257#else
    269 bool pmSubtractionSetVisual (bool mode) {return true;}
    270258bool pmSubtractionVisualClose() {return true;}
    271259bool pmSubtractionVisualPlotConvKernels(psImage *convKernels) {return true;}
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/imcombine/pmSubtractionVisual.h

    r21422 r23351  
    22#define PM_SUBTRACTION_VISUAL_H
    33
    4 bool pmSubtractionSetVisual (bool mode);
    54bool pmSubtractionVisualClose();
    65bool pmSubtractionVisualPlotConvKernels(psImage *convKernels);
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/Makefile.am

    r21516 r23351  
    1919        pmModelUtils.c \
    2020        pmSource.c \
     21        pmSourceMasks.c \
    2122        pmSourceMoments.c \
    2223        pmSourceExtendedPars.c \
     
    6970        pmModelUtils.h \
    7071        pmSource.h \
     72        pmSourceMasks.h \
    7173        pmSourceExtendedPars.h \
    7274        pmSourceUtils.h \
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmFootprint.c

    r20937 r23351  
    2828   }
    2929
    30    psTrace("psModules.objects", 5, "---- begin ----\n");
     30   psTrace("psModules.objects", 10, "---- begin ----\n");
    3131
    3232   psFree(tmp->spans);
    3333   psFree(tmp->peaks);
    3434
    35    psTrace("psModules.objects", 5, "---- end ----\n");
     35   psTrace("psModules.objects", 10, "---- end ----\n");
    3636}
    3737
     
    4242                              const psImage *image) // region footprint lives in
    4343{
    44     psTrace("psModules.objects", 5, "---- begin ----\n");
     44    psTrace("psModules.objects", 10, "---- begin ----\n");
    4545
    4646    static int id = 1;
     
    6969    }
    7070
    71     psTrace("psModules.objects", 5, "---- end ----\n");
     71    psTrace("psModules.objects", 10, "---- end ----\n");
    7272    return(footprint);
    7373}
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmModel.c

    r21515 r23351  
    3232static void modelFree(pmModel *tmp)
    3333{
    34     psTrace("psModules.objects", 4, "---- %s() begin ----\n", __func__);
     34    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    3535    psFree(tmp->params);
    3636    psFree(tmp->dparams);
    37     psTrace("psModules.objects", 4, "---- %s() end ----\n", __func__);
     37    psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    3838}
    3939
     
    4444pmModel *pmModelAlloc(pmModelType type)
    4545{
    46     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     46    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    4747
    4848    pmModelClass *class = pmModelClassSelect (type);
     
    8787    tmp->modelFitStatus     = class->modelFitStatus;
    8888
    89     psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     89    psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    9090    return(tmp);
    9191}
     
    130130psF32 pmModelEval(pmModel *model, psImage *image, psS32 col, psS32 row)
    131131{
    132     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     132    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    133133    PS_ASSERT_PTR_NON_NULL(image, NAN);
    134134    PS_ASSERT_PTR_NON_NULL(model, NAN);
     
    144144    tmpF = model->modelFunc (NULL, model->params, x);
    145145    psFree(x);
    146     psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     146    psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    147147    return(tmpF);
    148148}
     
    150150psF32 pmModelEvalWithOffset(pmModel *model, psImage *image, psS32 col, psS32 row, int dx, int dy)
    151151{
    152     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     152    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    153153    PS_ASSERT_PTR_NON_NULL(image, false);
    154154    PS_ASSERT_PTR_NON_NULL(model, false);
     
    164164    tmpF = model->modelFunc (NULL, model->params, x);
    165165    psFree(x);
    166     psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     166    psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    167167    return(tmpF);
    168168}
     
    180180    )
    181181{
    182     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     182    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    183183
    184184    PS_ASSERT_PTR_NON_NULL(model, false);
     
    344344
    345345    psFree(x);
    346     psTrace("psModules.objects", 3, "---- %s(true) end ----\n", __func__);
     346    psTrace("psModules.objects", 10, "---- %s(true) end ----\n", __func__);
    347347    return(true);
    348348}
     
    356356                psImageMaskType maskVal)
    357357{
    358     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     358    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    359359    psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal, 0.0, 0.0);
    360     psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
     360    psTrace("psModules.objects", 10, "---- %s(%d) end ----\n", __func__, rc);
    361361    return(rc);
    362362}
     
    370370                psImageMaskType maskVal)
    371371{
    372     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     372    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    373373    psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal, 0.0, 0.0);
    374     psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
     374    psTrace("psModules.objects", 10, "---- %s(%d) end ----\n", __func__, rc);
    375375    return(rc);
    376376}
     
    386386                          int dy)
    387387{
    388     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     388    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    389389    psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal, dx, dy);
    390     psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
     390    psTrace("psModules.objects", 10, "---- %s(%d) end ----\n", __func__, rc);
    391391    return(rc);
    392392}
     
    402402                          int dy)
    403403{
    404     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     404    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    405405    psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal, dx, dy);
    406     psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
     406    psTrace("psModules.objects", 10, "---- %s(%d) end ----\n", __func__, rc);
    407407    return(rc);
    408408}
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmMoments.c

    r19879 r23351  
    2727pmMoments *pmMomentsAlloc()
    2828{
    29     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     29    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    3030    pmMoments *tmp = (pmMoments *) psAlloc(sizeof(pmMoments));
    3131    tmp->Mx = 0.0;
     
    5252    tmp->nPixels = 0;
    5353
    54     psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     54    psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    5555    return(tmp);
    5656}
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmPeaks.c

    r21514 r23351  
    3737                        pmPeakType type)
    3838{
    39     psTrace("psModules.objects", 5, "---- begin ----\n");
     39    psTrace("psModules.objects", 10, "---- begin ----\n");
    4040
    4141    if (peaks == NULL) {
     
    8282    psFree (peak);
    8383
    84     psTrace("psModules.objects", 5, "---- end ----\n");
     84    psTrace("psModules.objects", 10, "---- end ----\n");
    8585    return(peaks);
    8686}
     
    9696                                       psU32 row)
    9797{
    98     psTrace("psModules.objects", 4, "---- %s() begin ----\n", __func__);
     98    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    9999    PS_ASSERT_IMAGE_NON_NULL(image, NULL);
    100100    PS_ASSERT_IMAGE_TYPE(image, PS_TYPE_F32, NULL);
     
    104104        tmpVector->data.F32[col] = image->data.F32[row][col];
    105105    }
    106     psTrace("psModules.objects", 4, "---- %s() end ----\n", __func__);
     106    psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    107107    return(tmpVector);
    108108}
     
    117117                             psS32 y)
    118118{
    119     psTrace("psModules.objects", 4, "---- %s() begin ----\n", __func__);
     119    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    120120    if ((x >= valid.x0) &&
    121121            (x <= valid.x1) &&
    122122            (y >= valid.y0) &&
    123123            (y <= valid.y1)) {
    124         psTrace("psModules.objects", 4, "---- %s(true) end ----\n", __func__);
     124        psTrace("psModules.objects", 10, "---- %s(true) end ----\n", __func__);
    125125        return(true);
    126126    }
    127     psTrace("psModules.objects", 4, "---- %s(false) end ----\n", __func__);
     127    psTrace("psModules.objects", 10, "---- %s(false) end ----\n", __func__);
    128128    return(false);
    129129}
     
    140140                    pmPeakType type)
    141141{
    142     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     142    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    143143    static int id = 1;
    144144    pmPeak *tmp = (pmPeak *) psAlloc(sizeof(pmPeak));
     
    157157    psMemSetDeallocator(tmp, (psFreeFunc) peakFree);
    158158
    159     psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     159    psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    160160    return(tmp);
    161161}
     
    172172int pmPeaksCompareAscend (const void **a, const void **b)
    173173{
    174     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     174    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    175175    pmPeak *A = *(pmPeak **)a;
    176176    pmPeak *B = *(pmPeak **)b;
     
    180180    diff = A->value - B->value;
    181181    if (diff < FLT_EPSILON) {
    182         psTrace("psModules.objects", 3, "---- %s(-1) end ----\n", __func__);
     182        psTrace("psModules.objects", 10, "---- %s(-1) end ----\n", __func__);
    183183        return (-1);
    184184    } else if (diff > FLT_EPSILON) {
    185         psTrace("psModules.objects", 3, "---- %s(+1) end ----\n", __func__);
     185        psTrace("psModules.objects", 10, "---- %s(+1) end ----\n", __func__);
    186186        return (+1);
    187187    }
    188     psTrace("psModules.objects", 3, "---- %s(0) end ----\n", __func__);
     188    psTrace("psModules.objects", 10, "---- %s(0) end ----\n", __func__);
    189189    return (0);
    190190}
     
    194194int pmPeaksCompareDescend (const void **a, const void **b)
    195195{
    196     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     196    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    197197    pmPeak *A = *(pmPeak **)a;
    198198    pmPeak *B = *(pmPeak **)b;
     
    202202    diff = A->value - B->value;
    203203    if (diff < FLT_EPSILON) {
    204         psTrace("psModules.objects", 3, "---- %s(+1) end ----\n", __func__);
     204        psTrace("psModules.objects", 10, "---- %s(+1) end ----\n", __func__);
    205205        return (+1);
    206206    } else if (diff > FLT_EPSILON) {
    207         psTrace("psModules.objects", 3, "---- %s(-1) end ----\n", __func__);
     207        psTrace("psModules.objects", 10, "---- %s(-1) end ----\n", __func__);
    208208        return (-1);
    209209    }
    210     psTrace("psModules.objects", 3, "---- %s(0) end ----\n", __func__);
     210    psTrace("psModules.objects", 10, "---- %s(0) end ----\n", __func__);
    211211    return (0);
    212212}
     
    258258                         psF32 threshold)
    259259{
    260     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     260    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    261261    PS_ASSERT_VECTOR_NON_NULL(vector, NULL);
    262262    PS_ASSERT_VECTOR_NON_EMPTY(vector, NULL);
     
    276276            tmpVector = psVectorAlloc(0, PS_TYPE_U32);
    277277        }
    278         psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     278        psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    279279        return(tmpVector);
    280280    }
     
    341341    }
    342342
    343     psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     343    psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    344344    return(tmpVector);
    345345}
     
    363363psArray *pmPeaksInImage(const psImage *image, psF32 threshold)
    364364{
    365     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     365    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    366366    PS_ASSERT_IMAGE_NON_NULL(image, NULL);
    367367    PS_ASSERT_IMAGE_TYPE(image, PS_TYPE_F32, NULL);
    368368    if ((image->numRows == 1) || (image->numCols == 1)) {
    369369        psError(PS_ERR_UNKNOWN, true, "Currently, input image must have at least 2 rows and 2 columns.");
    370         psTrace("psModules.objects", 3, "---- %s(NULL) end ----\n", __func__);
     370        psTrace("psModules.objects", 10, "---- %s(NULL) end ----\n", __func__);
    371371        return(NULL);
    372372    }
     
    425425    //
    426426    if (image->numRows == 1) {
    427         psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     427        psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    428428        return(list);
    429429    }
     
    549549    psFree (tmpRow);
    550550    psFree (row1);
    551     psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     551    psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    552552    return(list);
    553553}
     
    560560    const psRegion valid)
    561561{
    562     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     562    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    563563    PS_ASSERT_PTR_NON_NULL(peaks, NULL);
    564564
     
    575575        psArrayAdd (output, 200, tmpPeak);
    576576    }
    577     psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     577    psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    578578    return(output);
    579579}
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmSource.c

    r21513 r23351  
    4141        return;
    4242
    43     psTrace("psModules.objects", 5, "---- begin ----\n");
     43    psTrace("psModules.objects", 10, "---- begin ----\n");
    4444    psFree(tmp->peak);
    4545    psFree(tmp->pixels);
     
    5555    psFree(tmp->extpars);
    5656    psFree(tmp->blends);
    57     psTrace("psModules.objects", 5, "---- end ----\n");
     57    psTrace("psModules.objects", 10, "---- end ----\n");
    5858}
    5959
     
    9494pmSource *pmSourceAlloc()
    9595{
    96     psTrace("psModules.objects", 5, "---- begin ----\n");
     96    psTrace("psModules.objects", 10, "---- begin ----\n");
    9797    static int id = 1;
    9898    pmSource *source = (pmSource *) psAlloc(sizeof(pmSource));
     
    131131    source->extNsigma = NAN;
    132132
    133     psTrace("psModules.objects", 5, "---- end ----\n");
     133    psTrace("psModules.objects", 10, "---- end ----\n");
    134134    return(source);
    135135}
     
    280280pmPSFClump pmSourcePSFClump(psRegion *region, psArray *sources, psMetadata *recipe)
    281281{
    282     psTrace("psModules.objects", 5, "---- begin ----\n");
     282    psTrace("psModules.objects", 10, "---- begin ----\n");
    283283
    284284    psArray *peaks  = NULL;
     
    496496    }
    497497
    498     psTrace("psModules.objects", 5, "---- end ----\n");
     498    psTrace("psModules.objects", 10, "---- end ----\n");
    499499    return (psfClump);
    500500}
     
    508508bool pmSourceRoughClass(psRegion *region, psArray *sources, psMetadata *recipe, pmPSFClump clump, psImageMaskType maskSat)
    509509{
    510     psTrace("psModules.objects", 5, "---- begin ----");
     510    psTrace("psModules.objects", 10, "---- begin ----");
    511511
    512512    PS_ASSERT_PTR_NON_NULL(sources, false);
     
    664664    psTrace ("psModules.objects", 2, "Ncr:      %3d\n", Ncr);
    665665
    666     psTrace("psModules.objects", 5, "---- end ----\n");
     666    psTrace("psModules.objects", 10, "---- end ----\n");
    667667    return true;
    668668}
     
    692692                     psF32 radius)
    693693{
    694     psTrace("psModules.objects", 5, "---- begin ----\n");
     694    psTrace("psModules.objects", 10, "---- begin ----\n");
    695695    PS_ASSERT_PTR_NON_NULL(source, false);
    696696    PS_ASSERT_PTR_NON_NULL(source->peak, false);
     
    807807        psTrace ("psModules.objects", 3, "insufficient valid pixels (%d vs %d; %f) for source\n",
    808808                 numPixels, (int)(0.75*R2), Sum);
    809         psTrace("psModules.objects", 5, "---- end (false) ----\n");
     809        psTrace("psModules.objects", 10, "---- end (false) ----\n");
    810810        return (false);
    811811    }
     
    824824        psTrace ("psModules.objects", 3, "large centroid swing; invalid peak %d, %d\n",
    825825                 source->peak->x, source->peak->y);
    826         psTrace("psModules.objects", 5, "---- end(false)  ----\n");
     826        psTrace("psModules.objects", 10, "---- end(false)  ----\n");
    827827        return (false);
    828828    }
     
    850850             source->moments->Mxx, source->moments->Myy, source->moments->Mxy);
    851851
    852     psTrace("psModules.objects", 5, "---- end ----\n");
     852    psTrace("psModules.objects", 10, "---- end ----\n");
    853853    return(true);
    854854}
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmSource.h

    r21516 r23351  
    1919/// @addtogroup Objects Object Detection / Analysis Functions
    2020/// @{
     21
     22#include <pmSourceMasks.h>
    2123
    2224/** pmSourceType enumeration
     
    3436    PM_SOURCE_TYPE_EXTENDED,            ///< an extended object (eg, galaxy) (subtracted model is EXT)
    3537} pmSourceType;
    36 
    37 // bit flags to distinguish analysis results
    38 typedef enum {
    39     PM_SOURCE_MODE_DEFAULT          = 0x00000000, ///< Initial value: resets all bits
    40     PM_SOURCE_MODE_PSFMODEL         = 0x00000001, ///< Source fitted with a psf model (linear or non-linear)
    41     PM_SOURCE_MODE_EXTMODEL         = 0x00000002, ///< Source fitted with an extended-source model
    42     PM_SOURCE_MODE_FITTED           = 0x00000004, ///< Source fitted with non-linear model (PSF or EXT; good or bad)
    43     PM_SOURCE_MODE_FAIL             = 0x00000008, ///< Fit (non-linear) failed (non-converge, off-edge, run to zero)
    44     PM_SOURCE_MODE_POOR             = 0x00000010, ///< Fit succeeds, but low-SN, high-Chisq, or large (for PSF -- drop?)
    45     PM_SOURCE_MODE_PAIR             = 0x00000020, ///< Source fitted with a double psf
    46     PM_SOURCE_MODE_PSFSTAR          = 0x00000040, ///< Source used to define PSF model
    47     PM_SOURCE_MODE_SATSTAR          = 0x00000080, ///< Source model peak is above saturation
    48     PM_SOURCE_MODE_BLEND            = 0x00000100, ///< Source is a blend with other sourcers
    49     PM_SOURCE_MODE_EXTERNAL         = 0x00000200, ///< Source based on supplied input position
    50     PM_SOURCE_MODE_BADPSF           = 0x00000400, ///< Failed to get good estimate of object's PSF
    51     PM_SOURCE_MODE_DEFECT           = 0x00000800, ///< Source is thought to be a defect
    52     PM_SOURCE_MODE_SATURATED        = 0x00001000, ///< Source is thought to be saturated pixels (bleed trail)
    53     PM_SOURCE_MODE_CR_LIMIT         = 0x00002000, ///< Source has crNsigma above limit
    54     PM_SOURCE_MODE_EXT_LIMIT        = 0x00004000, ///< Source has extNsigma above limit
    55     PM_SOURCE_MODE_MOMENTS_FAILURE  = 0x00008000, ///< could not measure the moments
    56     PM_SOURCE_MODE_SKY_FAILURE      = 0x00010000, ///< could not measure the local sky
    57     PM_SOURCE_MODE_SKYVAR_FAILURE   = 0x00020000, ///< could not measure the local sky variance
    58     PM_SOURCE_MODE_BELOW_MOMENTS_SN = 0x00040000, ///< moments not measured due to low S/N
    59     PM_SOURCE_MODE_BIG_RADIUS       = 0x00100000, ///< poor moments for small radius, try large radius
    60     PM_SOURCE_MODE_AP_MAGS          = 0x00200000, ///< source has an aperture magnitude
    61     PM_SOURCE_MODE_BLEND_FIT        = 0x00400000, ///< source was fitted as a blend
    62     PM_SOURCE_MODE_EXTENDED_FIT     = 0x00800000, ///< full extended fit was used
    63     PM_SOURCE_MODE_EXTENDED_STATS   = 0x01000000, ///< extended aperture stats calculated
    64     PM_SOURCE_MODE_LINEAR_FIT       = 0x02000000, ///< source fitted with the linear fit
    65     PM_SOURCE_MODE_NONLINEAR_FIT    = 0x04000000, ///< source fitted with the non-linear fit
    66     PM_SOURCE_MODE_RADIAL_FLUX      = 0x08000000, ///< radial flux measurements calculated
    67     PM_SOURCE_MODE_SIZE_SKIPPED     = 0x10000000, ///< size could not be determined
    68 } pmSourceMode;
    6938
    7039typedef enum {
     
    10170    pmSourceType type;                  ///< Best identification of object.
    10271    pmSourceMode mode;                  ///< analysis flags set for object.
    103     pmSourceTmpF tmpFlags;              ///< internal-only flags
     72    pmSourceTmpF tmpFlags;              ///< internal-only flags
    10473    psArray *blends;                    ///< collection of sources thought to be confused with object
    10574    float psfMag;                       ///< calculated from flux in modelPSF
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmSourceContour.c

    r20937 r23351  
    5959{
    6060
    61     psTrace("psModules.objects", 4, "---- %s() begin ----\n", __func__);
     61    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    6262
    6363    // We define variables incr and lastColumn so that we can use the same loop
     
    8080        float value = image->data.F32[y][subCol];
    8181        if (value <= threshold) {
    82             psTrace("psModules.objects", 4, "---- %s() end ----\n", __func__);
     82            psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    8383            return (subCol);
    8484        }
    8585        subCol += incr;
    8686    }
    87     psTrace("psModules.objects", 4, "---- %s() end ----\n", __func__);
     87    psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    8888    return (lastColumn);
    8989}
     
    9999{
    100100
    101     psTrace("psModules.objects", 4, "---- %s() begin ----\n", __func__);
     101    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    102102
    103103    // We define variables incr and lastColumn so that we can use the same loop
     
    119119        float value = image->data.F32[y][subCol];
    120120        if (value >= threshold) {
    121             psTrace("psModules.objects", 4, "---- %s() end ----\n", __func__);
     121            psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    122122            if (subCol == x) {
    123123                return (subCol);
     
    127127        subCol += incr;
    128128    }
    129     psTrace("psModules.objects", 4, "---- %s() end ----\n", __func__);
     129    psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    130130    return (lastColumn);
    131131}
     
    149149                       psU32 dir)
    150150{
    151     psTrace("psModules.objects", 4, "---- %s() begin ----\n", __func__);
     151    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    152152    //
    153153    // Convert coords to subImage space.
     
    159159    if (!((0 <= subCol) && (subCol < source->pixels->numCols))) {
    160160        psError(PS_ERR_UNKNOWN, true, "Starting column outside subImage range");
    161         psTrace("psModules.objects", 4, "---- %s(NAN) end ----\n", __func__);
     161        psTrace("psModules.objects", 10, "---- %s(NAN) end ----\n", __func__);
    162162        return(NAN);
    163163    }
    164164    if (!((0 <= subRow) && (subRow < source->pixels->numRows))) {
    165         psTrace("psModules.objects", 4, "---- %s(NAN) end ----\n", __func__);
     165        psTrace("psModules.objects", 10, "---- %s(NAN) end ----\n", __func__);
    166166        psError(PS_ERR_UNKNOWN, true, "Starting row outside subImage range");
    167167        return(NAN);
     
    172172    psF32 oldValue = pmModelEval(source->modelEXT, source->pixels, subCol, subRow);
    173173    if (oldValue == level) {
    174         psTrace("psModules.objects", 4, "---- %s() end ----\n", __func__);
     174        psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    175175        return(((psF32) (subCol + source->pixels->col0)));
    176176    }
     
    194194        psF32 newValue = pmModelEval(source->modelEXT, source->pixels, subCol, subRow);
    195195        if (oldValue == level) {
    196             psTrace("psModules.objects", 4, "---- %s() end ----\n", __func__);
     196            psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    197197            return((psF32) (subCol + source->pixels->col0));
    198198        }
     
    200200        if ((newValue <= level) && (level <= oldValue)) {
    201201            // This is simple linear interpolation.
    202             psTrace("psModules.objects", 4, "---- %s() end ----\n", __func__);
     202            psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    203203            return( ((psF32) (subCol + source->pixels->col0)) + ((psF32) incr) * ((level - newValue) / (oldValue - newValue)) );
    204204        }
     
    206206        if ((oldValue <= level) && (level <= newValue)) {
    207207            // This is simple linear interpolation.
    208             psTrace("psModules.objects", 4, "---- %s() end ----\n", __func__);
     208            psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    209209            return( ((psF32) (subCol + source->pixels->col0)) + ((psF32) incr) * ((level - oldValue) / (newValue - oldValue)) );
    210210        }
     
    213213    }
    214214
    215     psTrace("psModules.objects", 4, "---- %s(NAN) end ----\n", __func__);
     215    psTrace("psModules.objects", 10, "---- %s(NAN) end ----\n", __func__);
    216216    return(NAN);
    217217}
     
    222222psArray *pmSourceContour (psImage *image, int xc, int yc, float threshold)
    223223{
    224     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     224    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    225225    PS_ASSERT_PTR_NON_NULL(image, NULL);
    226226
     
    339339    tmpArray->data[0] = (psPtr *) xVec;
    340340    tmpArray->data[1] = (psPtr *) yVec;
    341     psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     341    psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    342342    return(tmpArray);
    343343}
     
    360360                               psF32 level)
    361361{
    362     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     362    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    363363    PS_ASSERT_PTR_NON_NULL(source, false);
    364364    PS_ASSERT_PTR_NON_NULL(image, false);
     
    390390            psFree(xVec);
    391391            psFree(yVec);
    392             psTrace("psModules.objects", 3, "---- %s(NULL) end ----\n", __func__);
     392            psTrace("psModules.objects", 10, "---- %s(NULL) end ----\n", __func__);
    393393            return(NULL);
    394394            //psLogMsg(__func__, PS_LOG_WARN, "WARNING: Could not find contour edge (NAN)\n");
     
    403403            psFree(xVec);
    404404            psFree(yVec);
    405             psTrace("psModules.objects", 3, "---- %s(NULL) end ----\n", __func__);
     405            psTrace("psModules.objects", 10, "---- %s(NULL) end ----\n", __func__);
    406406            return(NULL);
    407407            //psLogMsg(__func__, PS_LOG_WARN, "WARNING: Could not find contour edge (NAN)\n");
     
    428428            psFree(xVec);
    429429            psFree(yVec);
    430             psTrace("psModules.objects", 3, "---- %s(NULL) end ----\n", __func__);
     430            psTrace("psModules.objects", 10, "---- %s(NULL) end ----\n", __func__);
    431431            return(NULL);
    432432            //psLogMsg(__func__, PS_LOG_WARN, "WARNING: Could not find contour edge (NAN)\n");
     
    440440            psFree(xVec);
    441441            psFree(yVec);
    442             psTrace("psModules.objects", 3, "---- %s(NULL) end ----\n", __func__);
     442            psTrace("psModules.objects", 10, "---- %s(NULL) end ----\n", __func__);
    443443            return(NULL);
    444444            //psLogMsg(__func__, PS_LOG_WARN, "WARNING: Could not find contour edge (NAN)\n");
     
    457457    tmpArray->data[0] = (psPtr *) yVec;
    458458    tmpArray->data[1] = (psPtr *) xVec;
    459     psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     459    psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    460460    return(tmpArray);
    461461}
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmSourceFitModel.c

    r21512 r23351  
    5858                       psImageMaskType maskVal)
    5959{
    60     psTrace("psModules.objects", 5, "---- %s begin ----\n", __func__);
     60    psTrace("psModules.objects", 10, "---- %s begin ----\n", __func__);
    6161    PS_ASSERT_PTR_NON_NULL(source, false);
    6262    PS_ASSERT_PTR_NON_NULL(source->pixels, false);
     
    231231
    232232    rc = (onPic && fitStatus);
    233     psTrace("psModules.objects", 5, "---- %s(%d) end ----\n", __func__, rc);
     233    psTrace("psModules.objects", 10, "---- %s(%d) end ----\n", __func__, rc);
    234234    return(rc);
    235235}
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmSourceFitSet.c

    r21363 r23351  
    446446                     psImageMaskType maskVal)
    447447{
    448     psTrace("psModules.objects", 3, "---- %s begin ----\n", __func__);
     448    psTrace("psModules.objects", 10, "---- %s begin ----\n", __func__);
    449449    PS_ASSERT_PTR_NON_NULL(source, false);
    450450    PS_ASSERT_PTR_NON_NULL(source->pixels, false);
     
    533533    if (nPix <  thisSet->nParamSet + 1) {
    534534        psTrace (__func__, 4, "insufficient valid pixels\n");
    535         psTrace("psModules.objects", 3, "---- %s() end : fail pixels ----\n", __func__);
     535        psTrace("psModules.objects", 10, "---- %s() end : fail pixels ----\n", __func__);
    536536        for (int i = 0; i < modelSet->n; i++) {
    537537            pmModel *model = modelSet->data[i];
     
    602602
    603603    bool rc = (onPic && fitStatus);
    604     psTrace("psModules.objects", 5, "---- %s end (%d) ----\n", __func__, rc);
     604    psTrace("psModules.objects", 10, "---- %s end (%d) ----\n", __func__, rc);
    605605    return(rc);
    606606}
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmSourceMatch.c

    r21266 r23351  
    1616#define SOURCE_FAINTEST 50.0            // Faintest magnitude to consider
    1717#define SOURCES_MAX_LEAF 2              // Maximum number of points on a tree leaf
    18 
     18#define ARRAY_BUFFER 16                 // Buffer for array
    1919
    2020//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     
    6363        pmSource *source = sources->data[i]; // Source of interest
    6464        if (!source) continue;
    65         if (source->mode & SOURCE_MASK) continue;
    66         if (!isfinite(source->psfMag)) continue;
    67         if (!isfinite(source->errMag)) continue;
    68         if (source->psfMag > SOURCE_FAINTEST) continue;
     65        if (source->mode & SOURCE_MASK) continue;
     66        if (!isfinite(source->psfMag)) continue;
     67        if (!isfinite(source->errMag)) continue;
     68        if (source->psfMag > SOURCE_FAINTEST) continue;
    6969
    7070        float xSrc, ySrc;               // Coordinates of source
     
    113113}
    114114
    115 pmSourceMatch *pmSourceMatchAlloc(int num // Maximum number of images
    116     )
     115pmSourceMatch *pmSourceMatchAlloc(void)
    117116{
    118117    pmSourceMatch *match = psAlloc(sizeof(pmSourceMatch)); // Match data
     
    120119
    121120    match->num = 0;
    122     match->mag = psVectorAllocEmpty(num, PS_TYPE_F32);
    123     match->magErr = psVectorAllocEmpty(num, PS_TYPE_F32);
    124     match->image = psVectorAllocEmpty(num, PS_TYPE_U32);
    125     match->index = psVectorAllocEmpty(num, PS_TYPE_U32);
    126     match->mask = psVectorAllocEmpty(num, PS_TYPE_VECTOR_MASK);
     121    match->mag = psVectorAllocEmpty(ARRAY_BUFFER, PS_TYPE_F32);
     122    match->magErr = psVectorAllocEmpty(ARRAY_BUFFER, PS_TYPE_F32);
     123    match->image = psVectorAllocEmpty(ARRAY_BUFFER, PS_TYPE_U32);
     124    match->index = psVectorAllocEmpty(ARRAY_BUFFER, PS_TYPE_U32);
     125    match->mask = psVectorAllocEmpty(ARRAY_BUFFER, PS_TYPE_VECTOR_MASK);
    127126
    128127    return match;
     
    136135{
    137136    int num = match->num;               // Number of matches
    138     psAssert(num <= match->mag->nalloc, "Too many matches.");
    139     psAssert(num <= match->magErr->nalloc, "Too many matches.");
    140     psAssert(num <= match->image->nalloc, "Too many matches.");
    141     psAssert(num <= match->index->nalloc, "Too many matches.");
     137
     138    match->mag = psVectorExtend(match->mag, match->mag->nalloc, 1);
     139    match->magErr = psVectorExtend(match->magErr, match->magErr->nalloc, 1);
     140    match->image = psVectorExtend(match->image, match->image->nalloc, 1);
     141    match->index = psVectorExtend(match->index, match->index->nalloc, 1);
     142    match->mask = psVectorExtend(match->mask, match->mask->nalloc, 1);
    142143
    143144    match->mag->data.F32[num] = mag;
     
    148149    match->num++;
    149150
    150     match->mag->n = match->magErr->n = match->image->n = match->index->n = match->mask->n = match->num;
    151 }
    152 
    153 
    154 psArray *pmSourceMatchSources(const psArray *sourceArrays, float radius)
     151    return;
     152}
     153
     154
     155psArray *pmSourceMatchSources(const psArray *sourceArrays, float radius, bool cullSingles)
    155156{
    156157    PS_ASSERT_ARRAY_NON_NULL(sourceArrays, NULL);
     
    185186            matches = psArrayAlloc(numSources);
    186187            for (int j = 0; j < numSources; j++) {
    187                 pmSourceMatch *match = pmSourceMatchAlloc(numImages); // Match data
     188                pmSourceMatch *match = pmSourceMatchAlloc(); // Match data
    188189                pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);
    189190                matches->data[j] = match;
    190191            }
    191192            numMaster += numSources;
    192             goto match_image_done;
    193         }
    194 
    195         if (boundsImage->x0 > boundsMaster->x1 || boundsImage->x1 < boundsMaster->x0 ||
    196             boundsImage->y0 > boundsMaster->y1 || boundsImage->y1 < boundsMaster->y0) {
     193        } else if (boundsImage->x0 > boundsMaster->x1 || boundsImage->x1 < boundsMaster->x0 ||
     194                   boundsImage->y0 > boundsMaster->y1 || boundsImage->y1 < boundsMaster->y0) {
     195            // Bounds don't overlap --- can just add everything in to the master list
    197196            psTrace("psModules.objects", 7, "Bounds don't overlap\n");
    198             // Add everything in to the master list
    199197            long size = numMaster + numSources; // New size
    200198            xMaster = psVectorRealloc(xMaster, size);
     
    207205                   numSources * PSELEMTYPE_SIZEOF(PS_TYPE_F32));
    208206            for (int j = 0, k = numMaster; j < numSources; j++, k++) {
    209                 pmSourceMatch *match = pmSourceMatchAlloc(numImages); // Match data
     207                pmSourceMatch *match = pmSourceMatchAlloc(); // Match data
    210208                pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);
    211209                matches->data[k] = match;
     
    215213            yMaster->n = size;
    216214            matches->n = size;
    217 
    218             goto match_image_done;
    219         }
    220 
    221         // Match with the master list
    222 
    223         psTree *tree = psTreePlant(2, SOURCES_MAX_LEAF, xMaster, yMaster); // kd Tree with sources
    224         long numMatch = 0;              // Number of matches
    225 
    226         long size = numMaster + numSources; // New size
    227         xMaster = psVectorRealloc(xMaster, size);
    228         yMaster = psVectorRealloc(yMaster, size);
    229         matches = psArrayRealloc(matches, size);
    230 
    231         psVector *coords = psVectorAlloc(2, PS_TYPE_F32); // Coordinates for tree lookup
    232         for (int j = 0; j < numSources; j++) {
    233             coords->data.F32[0] = xImage->data.F32[j];
    234             coords->data.F32[1] = yImage->data.F32[j];
    235             long index = psTreeNearestWithin(tree, coords, radius); // Match index
    236             if (index >= 0) {
    237                 // Record the match
    238                 pmSourceMatch *match = matches->data[index]; // Match data
    239                 pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);
    240                 numMatch++;
    241             } else {
    242                 // Add to the master list
    243                 pmSourceMatch *match = pmSourceMatchAlloc(numImages); // Match data
    244                 pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);
    245                 xMaster->data.F32[numMaster] = xImage->data.F32[j];
    246                 yMaster->data.F32[numMaster] = yImage->data.F32[j];
    247                 matches->data[numMaster] = match;
    248                 numMaster++;
    249                 xMaster->n = yMaster->n = matches->n = numMaster;
    250             }
    251 
    252         }
    253         psFree(coords);
    254         psFree(tree);
    255 
    256 
    257     match_image_done:
     215        } else {
     216            // Match with the master list
     217            psTree *tree = psTreePlant(2, SOURCES_MAX_LEAF, xMaster, yMaster); // kd Tree with sources
     218            long numMatch = 0;          // Number of matches
     219
     220            long size = numMaster + numSources; // New size
     221            xMaster = psVectorRealloc(xMaster, size);
     222            yMaster = psVectorRealloc(yMaster, size);
     223            matches = psArrayRealloc(matches, size);
     224
     225            psVector *coords = psVectorAlloc(2, PS_TYPE_F32); // Coordinates for tree lookup
     226            for (int j = 0; j < numSources; j++) {
     227                coords->data.F32[0] = xImage->data.F32[j];
     228                coords->data.F32[1] = yImage->data.F32[j];
     229                long index = psTreeNearestWithin(tree, coords, radius); // Match index
     230                if (index >= 0) {
     231                    // Record the match
     232                    pmSourceMatch *match = matches->data[index]; // Match data
     233                    pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);
     234                    numMatch++;
     235                } else {
     236                    // Add to the master list
     237                    pmSourceMatch *match = pmSourceMatchAlloc(); // Match data
     238                    pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);
     239                    xMaster->data.F32[numMaster] = xImage->data.F32[j];
     240                    yMaster->data.F32[numMaster] = yImage->data.F32[j];
     241                    matches->data[numMaster] = match;
     242                    numMaster++;
     243                    xMaster->n = yMaster->n = matches->n = numMaster;
     244                }
     245
     246            }
     247            psFree(coords);
     248            psFree(tree);
     249        }
     250
    258251        psFree(boundsImage);
    259252        psFree(xImage);
     
    263256    }
    264257
    265     // Now cull the matches that contain only a single star
    266     int numGood = 0;                    // Number of good matches
     258    if (cullSingles) {
     259        // Now cull the matches that contain only a single star
     260        int numGood = 0;                    // Number of good matches
     261        for (int i = 0; i < matches->n; i++) {
     262            pmSourceMatch *match = matches->data[i]; // Match of interest
     263            if (match->num > 1) {
     264                if (i != numGood) {
     265                    psFree(matches->data[numGood]);
     266                    matches->data[numGood] = psMemIncrRefCounter(match);
     267                }
     268                numGood++;
     269            }
     270        }
     271        matches->n = numGood;
     272        for (int i = numGood; i < numMaster; i++) {
     273            psFree(matches->data[i]);
     274            matches->data[i] = NULL;
     275        }
     276    }
     277
     278    return matches;
     279}
     280
     281
     282psArray *pmSourceMatchMerge(psArray *sourceArrays, float radius)
     283{
     284    PS_ASSERT_ARRAY_NON_NULL(sourceArrays, NULL);
     285    PS_ASSERT_FLOAT_LARGER_THAN(radius, 0.0, NULL);
     286
     287    psArray *matches = pmSourceMatchSources(sourceArrays, radius, false); // Source matches
     288    if (!matches) {
     289        psError(PS_ERR_UNKNOWN, false, "Unable to match source lists.");
     290        return NULL;
     291    }
     292
     293    int index = 0;                      // Index to current position on list
    267294    for (int i = 0; i < matches->n; i++) {
     295        pmSource *source = NULL;        // Source to put in merged list
    268296        pmSourceMatch *match = matches->data[i]; // Match of interest
    269         if (match->num > 1) {
    270             if (i != numGood) {
    271                 psFree(matches->data[numGood]);
    272                 matches->data[numGood] = psMemIncrRefCounter(match);
    273                 //                psFree(match);
    274             }
    275             numGood++;
    276         }
    277     }
    278     matches->n = numGood;
    279     for (int i = numGood; i < numMaster; i++) {
    280         psFree(matches->data[i]);
    281         matches->data[i] = NULL;
    282     }
     297        for (int j = 0; j < match->num && !source; j++) {
     298            if (!isfinite(match->mag->data.F32[j]) || !isfinite(match->magErr->data.F32[j])) {
     299                continue;
     300            }
     301            int imgIndex = match->image->data.S32[j]; // Index of image
     302            int srcIndex = match->index->data.S32[j]; // Index of source for image
     303            psArray *list = sourceArrays->data[imgIndex]; // List of interest
     304            source = list->data[srcIndex];
     305            break;
     306        }
     307
     308        if (source) {
     309            psFree(matches->data[index]);
     310            matches->data[index] = psMemIncrRefCounter(source);
     311            index++;
     312        }
     313    }
     314
     315    // Clear out the rest of the list
     316    int num = index;                    // Number of good sources
     317    for (; index < matches->n; index++) {
     318        psFree(matches->data[index]);
     319        matches->data[index] = NULL;
     320    }
     321    matches->n = num;
    283322
    284323    return matches;
    285324}
    286 
    287325
    288326// Iterate on the star magnitudes and image transparencies
     
    290328static float sourceMatchRelphotIterate(psVector *trans, // Transparencies
    291329                                       psVector *stars, // Star magnitudes
     330                                       psVector *badImage, // Bad image mask
    292331                                       const psArray *matches, // Array of matches
    293332                                       const psVector *zp, // Zero points for each image (incl. airmass term)
     
    363402    for (int i = 0; i < numImages; i++) {
    364403        trans->data.F32[i] = accum->data.F64[i] / accumErr->data.F64[i];
    365 
     404        if (!isfinite(trans->data.F32[i])) {
     405            badImage->data.U8[i] = 0xFF;
     406        }
    366407        psTrace("psModules.objects", 3, "Transparency for image %d: %f\n", i, trans->data.F32[i]);
    367408    }
     
    379420            }
    380421            int index = match->image->data.U32[j]; // Image index
     422            if (badImage->data.U8[index]) {
     423                continue;
     424            }
    381425            float mag = match->mag->data.F32[j]; // Measured magnitude
    382426            float magErr2 = PS_SQR(match->magErr->data.F32[j]) + sysErr2; // Error in measured magnitude
     
    402446static int sourceMatchRelphotPhotometric(psVector *photo, // Photometric determination
    403447                                         const psVector *trans, // Estimated transparencies
     448                                         const psVector *badImage, // Bad image?
    404449                                         int transIter, // Iterations for transparency
    405450                                         float transClip, // Clipping level for transparency
     
    409454    psAssert(photo && photo->type.type == PS_TYPE_U8, "Need photometric determination");
    410455    psAssert(trans && trans->type.type == PS_TYPE_F32, "Need transparencies");
     456    psAssert(badImage && badImage->type.type == PS_TYPE_U8, "Need bad image determination");
    411457
    412458    int numImages = photo->n;              // Number of images
    413459
    414460    psAssert(trans->n == numImages, "Not enough transparencies: %ld", trans->n);
     461    psAssert(badImage->n == numImages, "Not enough bad image determinations: %ld", badImage->n);
    415462    psAssert(transIter >= 0, "Iterations for transparency must be non-negative: %d", transIter);
    416463    psAssert(transClip > 0, "Clipping level for transparency must be positive: %f", transClip);
     
    421468    stats->clipSigma = transClip;
    422469
    423     if (!psVectorStats(stats, trans, NULL, NULL, 0)) {
     470    if (!psVectorStats(stats, trans, NULL, badImage, 0xFF)) {
    424471        psError(PS_ERR_UNKNOWN, false, "Unable to perform statistics on transparencies.");
    425472        psFree(stats);
     
    432479    int numPhoto = 0;                   // Number of photometric images
    433480    for (int i = 0; i < numImages; i++) {
     481        if (badImage->data.U8[i]) {
     482            continue;
     483        }
    434484        if (trans->data.F32[i] < thresh) {
    435485            photo->data.U8[i] = 0xFF;
     
    451501                                      const psVector *zp, // Zero points for each image
    452502                                      const psVector *photo, // Photometric image?
     503                                      const psVector *badImage, // Bad image?
    453504                                      float starClip, // Clipping for stars
    454505                                      float sysErr2 // Systematic error squared
     
    468519    psAssert(!photo || photo->type.type == PS_TYPE_U8, "Photometric determination is wrong type");
    469520    psAssert(!photo || photo->n == numImages, "Not enough photometric determinations: %ld", photo->n);
     521    psAssert(!badImage || badImage->type.type == PS_TYPE_U8, "Photometric determination is wrong type");
     522    psAssert(!badImage || badImage->n == numImages, "Not enough bad determinations: %ld", badImage->n);
    470523
    471524    starClip = PS_SQR(starClip);
     
    481534            numMeasurements++;
    482535            int index = match->image->data.U32[j]; // Image index
     536            if (badImage->data.U8[index]) {
     537                continue;
     538            }
    483539            float mag = match->mag->data.F32[j]; // Measured magnitude
    484540            float magErr = match->magErr->data.F32[j]; // Error in measured magnitude
     
    489545            float dev = mag + cal - stars->data.F32[i]; // Deviation
    490546
    491             // only reject detections from photometric images (non-photometric images can
    492             // have large errors.  XXX Or: allow a much higher rejection threshold
    493             if (photo->data.U8[index]) {
    494               if (PS_SQR(dev) > starClip * (PS_SQR(magErr) + sysErr2)) {
    495                 numRejected++;
    496                 match->mask->data.PS_TYPE_VECTOR_MASK_DATA[j] = 0xFF;
    497               }
    498             }
     547            // only reject detections from photometric images (non-photometric images can
     548            // have large errors.  XXX Or: allow a much higher rejection threshold
     549            if (photo->data.U8[index]) {
     550                if (PS_SQR(dev) > starClip * (PS_SQR(magErr) + sysErr2)) {
     551                    numRejected++;
     552                    match->mask->data.PS_TYPE_VECTOR_MASK_DATA[j] = 0xFF;
     553                }
     554            }
    499555        }
    500556    }
     
    506562psVector *pmSourceMatchRelphot(const psArray *matches, // Array of matches
    507563                               const psVector *zp, // Zero points for each image (including airmass term)
    508                                int maxIter, // Maximum number of iterations
    509564                               float tol, // Relative tolerance for convergence
     565                               int iter1, // Number of iterations for pass 1
     566                               float rej1, // Limit on rejection between iterations for pass 1
     567                               float sys1, // Systematic error in measurements for pass 1
     568                               int iter2, // Number of iterations for pass 2
     569                               float rej2, // Limit on rejection between iterations for pass 2
     570                               float sys2, // Systematic error in measurements for pass 2
    510571                               float rejLimit, // Limit on rejection between iterations
    511572                               int transIter, // Clipping iterations for transparency
    512573                               float transClip, // Clipping level for transparency
    513                                float photoLevel, // Level at which we declare image is photometric
    514                                float starClip, // Clipping for stars
    515                                float sysErr // Systematic error in measurements
     574                               float photoLevel // Level at which we declare image is photometric
    516575                               )
    517576{
     
    521580    PS_ASSERT_FLOAT_LARGER_THAN(transClip, 0.0, NULL);
    522581
    523     sysErr *= sysErr;
     582    sys1 *= sys1;
     583    sys2 *= sys2;
    524584
    525585    int numImages = zp->n;              // Number of images
     
    529589    psVector *photo = psVectorAlloc(numImages, PS_TYPE_U8); // Photometric determination for each image
    530590    psVectorInit(photo, 0);
     591    psVector *badImage = psVectorAlloc(numImages, PS_TYPE_U8); // Bad image?
     592    psVectorInit(badImage, 0);
    531593    psVector *stars = psVectorAlloc(numStars, PS_TYPE_F32); // Magnitudes for each star
    532594
    533     float chi2 = sourceMatchRelphotIterate(trans, stars, matches, zp, photo, sysErr); // chi^2 for solution
     595    float chi2 = sourceMatchRelphotIterate(trans, stars, badImage, matches, zp,
     596                                           photo, sys1); // chi^2 for solution
    534597    psTrace("psModules.objects", 1, "Initial: chi^2 = %f\n", chi2);
    535598    float lastChi2 = INFINITY;          // chi^2 on last iteration
    536599    float fracRej = INFINITY;        // Fraction of measurements rejected
    537600
    538     // in the first passes, the transparencies are not well deteremined: use high systematic error and the rejection thresholds
    539     for (int i = 0; i < 5; i++) {
     601    // In the first passes, the transparencies are not well deteremined: use high systematic error and
     602    // rejection thresholds
     603    for (int i = 0; i < iter1; i++) {
    540604
    541605        // Identify photometric nights
    542         int numPhoto = sourceMatchRelphotPhotometric(photo, trans, transIter, transClip, photoLevel); // Number of photometric images
    543         if (numPhoto < 0) {
    544             psError(PS_ERR_UNKNOWN, false, "Unable to perform photometric determination");
    545             psFree(trans);
    546             psFree(photo);
    547             psFree(stars);
    548             return NULL;
    549         }
    550         psTrace("psModules.objects", 3, "Pass 1: Determined %d/%d are photometric", numPhoto, numImages);
    551 
    552         // XXX use 20 sigma rejection and 0.1 mag systematic error (move these to the recipe)
    553         fracRej = sourceMatchRelphotReject(trans, stars, matches, zp, photo, 20.0, PS_SQR(0.1));
    554         psTrace("psModules.objects", 3, "Pass 1: %f%% of measurements rejected", fracRej * 100);
    555 
    556         // XXX use 0.05 mag systematic error (move these to the recipe)
    557         chi2 = sourceMatchRelphotIterate(trans, stars, matches, zp, photo, PS_SQR(0.1)); // chi^2 for solution
    558         psTrace("psModules.objects", 1, "Pass 1: iter = %d: chi^2 = %f rejected = %f\n", i, chi2, fracRej);
    559     }
    560 
    561     for (int i = 0; i < maxIter && (fabsf(lastChi2 - chi2) > tol * chi2 || fracRej > rejLimit); i++) {
    562         lastChi2 = chi2;
    563 
    564         // Identify photometric nights
    565         int numPhoto = sourceMatchRelphotPhotometric(photo, trans, transIter, transClip,
     606        int numPhoto = sourceMatchRelphotPhotometric(photo, trans, badImage, transIter, transClip,
    566607                                                     photoLevel); // Number of photometric images
    567608        if (numPhoto < 0) {
     
    572613            return NULL;
    573614        }
    574         psTrace("psModules.objects", 3, "Determined %d/%d are photometric", numPhoto, numImages);
    575 
    576         fracRej = sourceMatchRelphotReject(trans, stars, matches, zp, photo, starClip, sysErr);
    577         psTrace("psModules.objects", 3, "%f%% of measurements rejected", fracRej * 100);
    578 
    579         chi2 = sourceMatchRelphotIterate(trans, stars, matches, zp, photo, sysErr); // chi^2 for solution
    580         psTrace("psModules.objects", 1, "iter = %d: chi^2 = %f rejected = %f\n", i, chi2, fracRej);
     615        psTrace("psModules.objects", 3, "Pass 1: Determined %d/%d are photometric", numPhoto, numImages);
     616
     617        fracRej = sourceMatchRelphotReject(trans, stars, matches, zp, photo, badImage, rej1, sys1);
     618        psTrace("psModules.objects", 3, "Pass 1: %f%% of measurements rejected", fracRej * 100);
     619
     620        chi2 = sourceMatchRelphotIterate(trans, stars, badImage, matches, zp, photo, sys1);
     621        psTrace("psModules.objects", 1, "Pass 1: iter = %d: chi^2 = %f rejected = %f\n", i, chi2, fracRej);
     622    }
     623
     624    for (int i = 0; i < iter2 && (fabsf(lastChi2 - chi2) > tol * chi2 || fracRej > rejLimit); i++) {
     625        lastChi2 = chi2;
     626
     627        // Identify photometric nights
     628        int numPhoto = sourceMatchRelphotPhotometric(photo, trans, badImage, transIter, transClip,
     629                                                     photoLevel); // Number of photometric images
     630        if (numPhoto < 0) {
     631            psError(PS_ERR_UNKNOWN, false, "Unable to perform photometric determination");
     632            psFree(trans);
     633            psFree(photo);
     634            psFree(stars);
     635            return NULL;
     636        }
     637        psTrace("psModules.objects", 3, "Pass 2: Determined %d/%d are photometric", numPhoto, numImages);
     638
     639        fracRej = sourceMatchRelphotReject(trans, stars, matches, zp, photo, badImage, rej2, sys2);
     640        psTrace("psModules.objects", 3, "Pass 2: %f%% of measurements rejected", fracRej * 100);
     641
     642        chi2 = sourceMatchRelphotIterate(trans, stars, badImage, matches, zp, photo, sys2);
     643        psTrace("psModules.objects", 1, "Pass 2: iter = %d: chi^2 = %f rejected = %f\n", i, chi2, fracRej);
    581644    }
    582645
    583646    psFree(photo);
     647    psFree(badImage);
    584648    psFree(stars);
    585649
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmSourceMatch.h

    r20953 r23351  
    3333
    3434/// Allocator for pmSourceMatch
    35 pmSourceMatch *pmSourceMatchAlloc(int num // Maximum number of images
    36                                   );
     35pmSourceMatch *pmSourceMatchAlloc(void);
    3736
    3837/// Add a source to a match
     
    4847///
    4948/// Returns an array of psSourceMatch
    50 psArray *pmSourceMatchSources(const psArray *sourceArrays, // Array of arrays of sources on each image
    51                               float radius // Correlation radius
     49psArray *pmSourceMatchSources(const psArray *sourceArrays, ///< Array of arrays of sources on each image
     50                              float radius, ///< Matching radius
     51                              bool cullSingles ///< Cull "matches" with only a single source?
    5252                              );
     53
     54/// Merge two source lists
     55///
     56/// Sources are pulled from the lists into a new list, with no effort made to adjust them.
     57psArray *pmSourceMatchMerge(psArray *sourceArrays, ///< Array of arrays of sources on each image
     58                            float radius ///< Matching radius
     59    );
    5360
    5461/// Perform relative photometry to calibrate images
    5562psVector *pmSourceMatchRelphot(const psArray *matches, // Array of matches
    5663                               const psVector *zp, // Zero points for each image (including airmass term)
    57                                int maxIter, // Maximum number of iterations
    5864                               float tol, // Relative tolerance for convergence
     65                               int iter1, // Number of iterations for pass 1
     66                               float rej1, // Limit on rejection between iterations for pass 1
     67                               float sys1, // Systematic error in measurements for pass 1
     68                               int iter2, // Number of iterations for pass 2
     69                               float rej2, // Limit on rejection between iterations for pass 2
     70                               float sys2, // Systematic error in measurements for pass 2
    5971                               float rejLimit, // Limit on rejection between iterations
    6072                               int transIter, // Clipping iterations for transparency
    6173                               float transClip, // Clipping level for transparency
    62                                float photoLevel, // Level at which we declare image is photometric
    63                                float starClip, // Clipping for stars
    64                                float sysErr // Systematic error in measurements
     74                               float photoLevel // Level at which we declare image is photometric
    6575    );
    6676
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmSourceSky.c

    r21363 r23351  
    5555    psImageMaskType markVal)
    5656{
    57     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     57    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    5858    PS_ASSERT_PTR_NON_NULL(source, false);
    5959    PS_ASSERT_IMAGE_NON_NULL(source->pixels, false);
     
    9191
    9292    if (isnan(value)) {
    93         psTrace("psModules.objects", 3, "---- %s(false) end ----\n", __func__);
     93        psTrace("psModules.objects", 10, "---- %s(false) end ----\n", __func__);
    9494        return(false);
    9595    }
     
    9898    }
    9999    source->moments->Sky = value;
    100     psTrace("psModules.objects", 3, "---- %s(true) end ----\n", __func__);
     100    psTrace("psModules.objects", 10, "---- %s(true) end ----\n", __func__);
    101101    return (true);
    102102}
     
    111111)
    112112{
    113     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     113    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    114114    PS_ASSERT_PTR_NON_NULL(source, false);
    115115    PS_ASSERT_IMAGE_NON_NULL(source->variance, false);
     
    147147
    148148    if (isnan(value)) {
    149         psTrace("psModules.objects", 3, "---- %s(false) end ----\n", __func__);
     149        psTrace("psModules.objects", 10, "---- %s(false) end ----\n", __func__);
    150150        return(false);
    151151    }
     
    154154    }
    155155    source->moments->dSky = value;
    156     psTrace("psModules.objects", 3, "---- %s(true) end ----\n", __func__);
     156    psTrace("psModules.objects", 10, "---- %s(true) end ----\n", __func__);
    157157    return (true);
    158158}
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmSourceUtils.c

    r20937 r23351  
    4949                            pmModelType modelType)
    5050{
    51     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     51    psTrace("psModules.objects", 10, "---- %s() begin ----\n", __func__);
    5252    PS_ASSERT_PTR_NON_NULL(source, NULL);
    5353    PS_ASSERT_PTR_NON_NULL(source->moments, NULL);
     
    6161    }
    6262
    63     psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     63    psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    6464    return(model);
    6565}
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmSourceVisual.c

    r21183 r23351  
    77#include "pmSourceVisual.h"
    88
    9 # if (HAVE_KAPA)
    10 # include <kapa.h>
     9#if (HAVE_KAPA)
     10#include <kapa.h>
     11#include "pmVisual.h"
    1112
    1213// functions used to visualize the analysis as it goes
    1314// these are invoked by the -visual options
    1415
    15 static bool isVisual = false;
    1616static int kapa1 = -1;
     17static bool plotPSF = true;
    1718// static int kapa2 = -1;
    1819// static int kapa3 = -1;
    1920
     21bool pmSourceVisualClose() {
     22    if (kapa1 != -1)
     23        KiiClose(kapa1);
     24    return true;
     25}
     26
    2027bool pmSourcePlotPoints3D (int myKapa, Graphdata *graphdata, psVector *xn, psVector *yn, psVector *zn, float theta, float phi);
    2128
    22 bool pmSourceSetVisual (bool mode) {
    23 
    24     isVisual = mode;
    25     return true;
    26 }
    2729
    2830bool pmSourceVisualPSFModelResid (pmTrend2D *trend, psVector *x, psVector *y, psVector *param, psVector *mask) {
    2931
    30     KapaSection section;  // put the positive profile in one and the residuals in another? 
     32    KapaSection section;  // put the positive profile in one and the residuals in another?
    3133
    3234    Graphdata graphdata;
    3335
    34     if (!isVisual) return true;
     36    if (!pmVisualIsVisual() || !plotPSF) return true;
    3537
    3638    if (kapa1 == -1) {
    3739        kapa1 = KapaOpenNamedSocket ("kapa", "pmSource:plots");
    38         if (kapa1 == -1) {
    39             fprintf (stderr, "failure to open kapa; visual mode disabled\n");
    40             isVisual = false;
    41             return false;
    42         }
    43     } 
     40        if (kapa1 == -1) {
     41            fprintf (stderr, "failure to open kapa; visual mode disabled\n");
     42            pmVisualSetVisual(false);
     43            return false;
     44        }
     45    }
    4446
    4547    KapaClearPlots (kapa1);
     
    5557
    5658    for (int i = 0; i < x->n; i++) {
    57         model->data.F32[i] = pmTrend2DEval (trend, x->data.F32[i], y->data.F32[i]);
    58         resid->data.F32[i] = param->data.F32[i] - model->data.F32[i];
    59         if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) continue;
    60         min = PS_MIN (min, resid->data.F32[i]);
    61         max = PS_MAX (max, resid->data.F32[i]);
    62         Min = PS_MIN (min, param->data.F32[i]);
    63         Max = PS_MAX (max, param->data.F32[i]);
     59        model->data.F32[i] = pmTrend2DEval (trend, x->data.F32[i], y->data.F32[i]);
     60        resid->data.F32[i] = param->data.F32[i] - model->data.F32[i];
     61        if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) continue;
     62        min = PS_MIN (min, resid->data.F32[i]);
     63        max = PS_MAX (max, resid->data.F32[i]);
     64        Min = PS_MIN (min, param->data.F32[i]);
     65        Max = PS_MAX (max, param->data.F32[i]);
    6466    }
    6567
     
    7072    psVector *Fn = psVectorAlloc (x->n, PS_TYPE_F32);
    7173    for (int i = 0; i < x->n; i++) {
    72         xn->data.F32[i] = x->data.F32[i] / 5000.0;
    73         yn->data.F32[i] = y->data.F32[i] / 5000.0;
    74         zn->data.F32[i] = (resid->data.F32[i] - min) / (max - min);
    75         Zn->data.F32[i] = (param->data.F32[i] - Min) / (Max - Min);
    76         Fn->data.F32[i] = (model->data.F32[i] - Min) / (Max - Min);
     74        xn->data.F32[i] = x->data.F32[i] / 5000.0;
     75        yn->data.F32[i] = y->data.F32[i] / 5000.0;
     76        zn->data.F32[i] = (resid->data.F32[i] - min) / (max - min);
     77        Zn->data.F32[i] = (param->data.F32[i] - Min) / (Max - Min);
     78        Fn->data.F32[i] = (model->data.F32[i] - Min) / (Max - Min);
    7779    }
    7880
     
    152154    // pause and wait for user input:
    153155    // continue, save (provide name), ??
    154     char key[10];
    155     fprintf (stdout, "[c]ontinue? ");
    156     if (!fgets(key, 8, stdin)) {
    157         psWarning("Unable to read option");
    158     }
     156    pmVisualAskUser(&plotPSF);
     157
    159158    return true;
    160159}
     
    173172
    174173    for (int i = 0; i < xn->n; i++) {
    175         xv->data.F32[2*i+0] = +xn->data.F32[i]*cos(theta) + yn->data.F32[i]*sin(theta)*cos(phi) + zn->data.F32[i]*sin(theta)*sin(phi);
    176         yv->data.F32[2*i+0] = -xn->data.F32[i]*sin(theta) + yn->data.F32[i]*cos(theta)*cos(phi) + zn->data.F32[i]*cos(theta)*sin(phi);
    177         zv->data.F32[2*i+0] = -yn->data.F32[i]*sin(phi)   + zn->data.F32[i]*cos(phi);
    178         xv->data.F32[2*i+1] = +xn->data.F32[i]*cos(theta) + yn->data.F32[i]*sin(theta)*cos(phi);
    179         yv->data.F32[2*i+1] = -xn->data.F32[i]*sin(theta) + yn->data.F32[i]*cos(theta)*cos(phi);
    180         zv->data.F32[2*i+1] = -yn->data.F32[i]*sin(phi);
    181         graphdata->xmin = PS_MIN(graphdata->xmin, xv->data.F32[2*i+0]);
    182         graphdata->xmax = PS_MAX(graphdata->xmax, xv->data.F32[2*i+0]);
    183         graphdata->ymin = PS_MIN(graphdata->ymin, zv->data.F32[2*i+0]);
    184         graphdata->ymax = PS_MAX(graphdata->ymax, zv->data.F32[2*i+0]);
    185         graphdata->xmin = PS_MIN(graphdata->xmin, xv->data.F32[2*i+1]);
    186         graphdata->xmax = PS_MAX(graphdata->xmax, xv->data.F32[2*i+1]);
    187         graphdata->ymin = PS_MIN(graphdata->ymin, zv->data.F32[2*i+1]);
    188         graphdata->ymax = PS_MAX(graphdata->ymax, zv->data.F32[2*i+1]);
     174        xv->data.F32[2*i+0] = +xn->data.F32[i]*cos(theta) + yn->data.F32[i]*sin(theta)*cos(phi) + zn->data.F32[i]*sin(theta)*sin(phi);
     175        yv->data.F32[2*i+0] = -xn->data.F32[i]*sin(theta) + yn->data.F32[i]*cos(theta)*cos(phi) + zn->data.F32[i]*cos(theta)*sin(phi);
     176        zv->data.F32[2*i+0] = -yn->data.F32[i]*sin(phi)   + zn->data.F32[i]*cos(phi);
     177        xv->data.F32[2*i+1] = +xn->data.F32[i]*cos(theta) + yn->data.F32[i]*sin(theta)*cos(phi);
     178        yv->data.F32[2*i+1] = -xn->data.F32[i]*sin(theta) + yn->data.F32[i]*cos(theta)*cos(phi);
     179        zv->data.F32[2*i+1] = -yn->data.F32[i]*sin(phi);
     180        graphdata->xmin = PS_MIN(graphdata->xmin, xv->data.F32[2*i+0]);
     181        graphdata->xmax = PS_MAX(graphdata->xmax, xv->data.F32[2*i+0]);
     182        graphdata->ymin = PS_MIN(graphdata->ymin, zv->data.F32[2*i+0]);
     183        graphdata->ymax = PS_MAX(graphdata->ymax, zv->data.F32[2*i+0]);
     184        graphdata->xmin = PS_MIN(graphdata->xmin, xv->data.F32[2*i+1]);
     185        graphdata->xmax = PS_MAX(graphdata->xmax, xv->data.F32[2*i+1]);
     186        graphdata->ymin = PS_MIN(graphdata->ymin, zv->data.F32[2*i+1]);
     187        graphdata->ymax = PS_MAX(graphdata->ymax, zv->data.F32[2*i+1]);
    189188    }
    190189    xv->n = xn->n;
     
    253252}
    254253
    255 # else
    256 # endif
     254#else
     255
     256bool pmSourceSetVisual(bool mode)
     257{
     258    return true;
     259}
     260
     261bool pmSourceVisualPSFModelResid(pmTrend2D *trend, psVector *x, psVector *y, psVector *param, psVector *mask)
     262{
     263    return true;
     264}
     265
     266#endif
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/objects/pmSourceVisual.h

    r20582 r23351  
    11/* @file  pmKapaPlots.h
    2  * @brief functions to make plots with the external program 'kapa' 
     2 * @brief functions to make plots with the external program 'kapa'
    33 *
    44 * @author EAM, IfA
    55 *
    6  * @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2008-11-08 01:52:34 $
     6 * @version $Revision: 1.1.16.1 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2009-02-19 17:59:50 $
    88 * Copyright 2006 Institute for Astronomy, University of Hawaii
    99 */
     
    1212#define PM_SOURCE_VISUAL_H
    1313
     14bool pmSourceVisualClose(void);
     15
    1416/// @addtogroup Extras Miscellaneous Funtions
    1517/// @{
    1618
    17 bool pmSourceSetVisual (bool mode);
    1819bool pmSourceVisualPSFModelResid (pmTrend2D *trend, psVector *x, psVector *y, psVector *param, psVector *mask);
    1920
  • branches/cnb_branches/cnb_branch_20090301/psModules/src/psmodules.h

    r22699 r23351  
    101101#include <pmReadoutCombine.h>
    102102#include <pmSubtractionVisual.h>
     103#include <pmStackVisual.h>
    103104
    104105// the following headers are from psModule:objects
     
    113114#include <pmPSF.h>
    114115#include <pmModel.h>
     116#include <pmSourceMasks.h>
    115117#include <pmSource.h>
    116118#include <pmSourceUtils.h>
  • branches/cnb_branches/cnb_branch_20090301/psModules/test/detrend/tap_pmMaskBadPixels.c

    r15160 r23351  
    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");
  • branches/cnb_branches/cnb_branch_20090301/psModules/test/imcombine/tap_pmImageCombine.c

    r11118 r23351  
    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
  • branches/cnb_branches/cnb_branch_20090301/psModules/test/objects/tap_pmFringe.c

    r15726 r23351  
    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);
  • branches/cnb_branches/cnb_branch_20090301/psModules/test/objects/tap_pmSourceFitModel.c

    r14654 r23351  
    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};
  • branches/cnb_branches/cnb_branch_20090301/psModules/test/objects/tap_pmSourceFitModel_Delta.c

    r14654 r23351  
    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.