- Timestamp:
- Apr 9, 2010, 4:41:16 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/stackphot.20100406/psphot/src/psphotStackChisqImage.c
r27625 r27649 12 12 psTimerStart ("psphot.chisq.image"); 13 13 14 pmFPAfile *chisqFile = pmFPAfileSelectSingle(config->files, "PSPHOT.CHISQ. OUTPUT", 0);14 pmFPAfile *chisqFile = pmFPAfileSelectSingle(config->files, "PSPHOT.CHISQ.IMAGE", 0); 15 15 psAssert (chisqFile, "missing chisq image FPA?"); 16 16 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; 26 18 27 19 int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM"); … … 30 22 // loop over the available readouts 31 23 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)) { 33 25 psError (PSPHOT_ERR_CONFIG, false, "failed to model background for PSPHOT.INPUT entry %d", i); 34 26 return false; … … 51 43 psLogMsg ("psphot", PS_LOG_INFO, "built chisq image: %f sec\n", psTimerMark ("psphot.chisq.image")); 52 44 53 psFree (chiReadout);54 45 return true; 55 46 } … … 57 48 bool psphotStackChisqImageAddReadout(const pmConfig *config, // Configuration 58 49 const pmFPAview *view, 59 pmReadout * chiReadout,50 pmReadout **chiReadout, 60 51 char *filename, 61 52 int index) … … 71 62 72 63 psImage *inImage = inReadout->image; 64 psAssert (inImage, "missing image?"); 65 73 66 psImage *inVariance = inReadout->variance; 67 psAssert (inVariance, "missing variance?"); 68 74 69 psImage *inMask = inReadout->mask; 70 psAssert (inMask, "missing mask?"); 75 71 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"); 79 84 80 85 // select the appropriate recipe information … … 105 110 return true; 106 111 } 112 113 bool 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 131 bool 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(®ex, "^%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.
