IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 9, 2010, 4:41:16 PM (16 years ago)
Author:
eugene
Message:

working on psphotStack (nearly done)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/stackphot.20100406/psphot/src/psphotStackChisqImage.c

    r27625 r27649  
    1212    psTimerStart ("psphot.chisq.image");
    1313
    14     pmFPAfile *chisqFile = pmFPAfileSelectSingle(config->files, "PSPHOT.CHISQ.OUTPUT", 0);
     14    pmFPAfile *chisqFile = pmFPAfileSelectSingle(config->files, "PSPHOT.CHISQ.IMAGE", 0);
    1515    psAssert (chisqFile, "missing chisq image FPA?");
    1616
    17     pmCell *chisqCell = pmFPAviewThisCell(view, chisqFile->fpa);
    18 
    19     // create a holder for the image
    20     pmReadout *chiReadout = pmFPAviewThisReadout(view, chisqFile->fpa);
    21     if (!chiReadout) {
    22       chiReadout = pmReadoutAlloc(chisqCell);
    23     } else {
    24       psMemIncrRefCounter(chiReadout);
    25     }
     17    pmReadout *chiReadout = NULL;
    2618
    2719    int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
     
    3022    // loop over the available readouts
    3123    for (int i = 0; i < num; i++) {
    32         if (!psphotStackChisqImageAddReadout(config, view, chiReadout, "PSPHOT.INPUT", i)) {
     24        if (!psphotStackChisqImageAddReadout(config, view, &chiReadout, "PSPHOT.INPUT", i)) {
    3325            psError (PSPHOT_ERR_CONFIG, false, "failed to model background for PSPHOT.INPUT entry %d", i);
    3426            return false;
     
    5143    psLogMsg ("psphot", PS_LOG_INFO, "built chisq image: %f sec\n", psTimerMark ("psphot.chisq.image"));
    5244
    53     psFree (chiReadout);
    5445    return true;
    5546}
     
    5748bool psphotStackChisqImageAddReadout(const pmConfig *config, // Configuration
    5849                                     const pmFPAview *view,
    59                                      pmReadout *chiReadout,
     50                                     pmReadout **chiReadout,
    6051                                     char *filename,
    6152                                     int index)
     
    7162
    7263    psImage *inImage     = inReadout->image;
     64    psAssert (inImage, "missing image?");
     65
    7366    psImage *inVariance  = inReadout->variance;
     67    psAssert (inVariance, "missing variance?");
     68
    7469    psImage *inMask      = inReadout->mask;
     70    psAssert (inMask, "missing mask?");
    7571
    76     psImage *chiImage    = chiReadout->image;
    77     psImage *chiVariance = chiReadout->variance;
    78     psImage *chiMask     = chiReadout->mask;
     72    if (*chiReadout == NULL) {
     73        *chiReadout = pmFPAGenerateReadout(config, view, "PSPHOT.CHISQ.IMAGE", input->fpa, NULL, 0);
     74    }
     75
     76    psImage *chiImage = (*chiReadout)->image;
     77    psAssert (chiImage, "missing chi image");
     78
     79    psImage *chiVariance = (*chiReadout)->variance;
     80    psAssert (chiVariance, "missing chi variance");
     81
     82    psImage *chiMask = (*chiReadout)->mask;
     83    psAssert (chiMask, "missing chi mask");
    7984
    8085    // select the appropriate recipe information
     
    105110    return true;
    106111}
     112
     113bool psphotStackRemoveChisqFromInputs (pmConfig *config) {
     114
     115    bool status = false;
     116
     117    int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM");
     118    psAssert (status, "programming error: must define PSPHOT.CHISQ.NUM");
     119
     120    int inputNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
     121    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     122
     123    pmFPAfileRemoveSingle (config->files, "PSPHOT.INPUT", chisqNum);
     124
     125    inputNum --;
     126    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "", inputNum);
     127
     128    return true;
     129}
     130
     131bool pmFPAfileRemoveSingle(psMetadata *files, const char *name, int num)
     132{
     133    PS_ASSERT_PTR_NON_NULL(files, NULL);
     134    PS_ASSERT_INT_NONNEGATIVE(num, NULL);
     135
     136    psList* mdList = files->list;
     137    psHash* mdHash = files->hash;
     138
     139    // Generate a REGEX to select only items that match 'name'
     140    psString regex = NULL;              // Regular expression
     141    if (name) {
     142        if (!psMetadataLookup(files, name)) {
     143            // No files match the requested name
     144            return false;
     145        }
     146        psStringAppend(&regex, "^%s$", name);
     147    }
     148
     149    psMetadataIterator *iter = psMetadataIteratorAlloc(files, PS_LIST_HEAD, regex); // Iterator
     150    psFree(regex);
     151    psMetadataItem *item;               // Item from iteration
     152
     153    bool found = false;
     154    int i = 0;                          // Counter
     155    for (i = 0; !found && (item = psMetadataGetAndIncrement(iter)); i++) {
     156        if (i == num) found = true;
     157    }
     158    psFree(iter);
     159    if (!found) {
     160        return false;
     161    }
     162
     163    char *key = item->name;
     164
     165    // look up the name via hash to see if we have a multi or not
     166    psMetadataItem* hashItem = psHashLookup(mdHash, name);
     167    if (hashItem == NULL) {
     168        psError(PS_ERR_UNKNOWN, false, _("Failed to remove metadata item, %s, from metadata table."), key);
     169        return false;
     170    }
     171
     172    if (hashItem->type == PS_DATA_METADATA_MULTI) {
     173        // multiple entries with same key, remove just the specified one
     174        psListRemoveData(hashItem->data.list, item);
     175    } else {
     176        psHashRemove(mdHash, key);
     177    }
     178    psListRemoveData(mdList, item);
     179
     180    return true;
     181}
Note: See TracChangeset for help on using the changeset viewer.