IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 11, 2010, 5:08:29 PM (16 years ago)
Author:
eugene
Message:

updates to support psphotStack

Location:
trunk/psphot
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot

  • trunk/psphot/src

    • Property svn:ignore
      •  

        old new  
        2121psphotForced
        2222psphotMakePSF
         23psphotStack
  • trunk/psphot/src/psphotStackChisqImage.c

    r27547 r27657  
    1212    psTimerStart ("psphot.chisq.image");
    1313
    14     // create a holder for the image
    15     pmReadout *chiImage = pmReadoutAlloc();
     14    pmFPAfile *chisqFile = pmFPAfileSelectSingle(config->files, "PSPHOT.CHISQ.IMAGE", 0);
     15    psAssert (chisqFile, "missing chisq image FPA?");
     16
     17    pmReadout *chiReadout = NULL;
    1618
    1719    int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
     
    2022    // loop over the available readouts
    2123    for (int i = 0; i < num; i++) {
    22         if (!psphotStackChisqImageAddReadout(config, view, chiImage, "PSPHOT.INPUT", i)) {
     24        if (!psphotStackChisqImageAddReadout(config, view, &chiReadout, "PSPHOT.INPUT", i)) {
    2325            psError (PSPHOT_ERR_CONFIG, false, "failed to model background for PSPHOT.INPUT entry %d", i);
    2426            return false;
     
    2628    }
    2729
     30    num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
     31    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
     32
     33    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "PSPHOT.CHISQ.NUM", PS_META_REPLACE, "", num);
     34    num++;
     35    psMetadataAddS32(config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "", num);
     36
    2837    // need to save the resulting image somewhere (PSPHOT.INPUT?)
     38    if (!psMetadataAddPtr(config->files, PS_LIST_TAIL, "PSPHOT.INPUT", PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "", chisqFile)) {
     39        psError(PM_ERR_CONFIG, false, "could not add chisqFPA to config files");
     40        return false;
     41    }
    2942
    3043    psLogMsg ("psphot", PS_LOG_INFO, "built chisq image: %f sec\n", psTimerMark ("psphot.chisq.image"));
     
    3447
    3548bool psphotStackChisqImageAddReadout(const pmConfig *config, // Configuration
    36                                      pmFPAview *view,
    37                                      pmReadout *chiReadout,
     49                                     const pmFPAview *view,
     50                                     pmReadout **chiReadout,
    3851                                     char *filename,
    3952                                     int index)
     
    4962
    5063    psImage *inImage     = inReadout->image;
     64    psAssert (inImage, "missing image?");
     65
    5166    psImage *inVariance  = inReadout->variance;
     67    psAssert (inVariance, "missing variance?");
     68
    5269    psImage *inMask      = inReadout->mask;
     70    psAssert (inMask, "missing mask?");
    5371
    54     psImage *chiImage    = chiReadout->image;
    55     psImage *chiVariance = chiReadout->variance;
    56     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");
    5784
    5885    // select the appropriate recipe information
     
    83110    return true;
    84111}
     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.