Changeset 27657 for trunk/psphot/src/psphotStackChisqImage.c
- Timestamp:
- Apr 11, 2010, 5:08:29 PM (16 years ago)
- Location:
- trunk/psphot
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot
-
Property svn:mergeinfo
set to
/branches/eam_branches/stackphot.20100406/psphot merged eligible
-
Property svn:mergeinfo
set to
-
trunk/psphot/src
- Property svn:ignore
-
old new 21 21 psphotForced 22 22 psphotMakePSF 23 psphotStack
-
- Property svn:ignore
-
trunk/psphot/src/psphotStackChisqImage.c
r27547 r27657 12 12 psTimerStart ("psphot.chisq.image"); 13 13 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; 16 18 17 19 int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM"); … … 20 22 // loop over the available readouts 21 23 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)) { 23 25 psError (PSPHOT_ERR_CONFIG, false, "failed to model background for PSPHOT.INPUT entry %d", i); 24 26 return false; … … 26 28 } 27 29 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 28 37 // 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 } 29 42 30 43 psLogMsg ("psphot", PS_LOG_INFO, "built chisq image: %f sec\n", psTimerMark ("psphot.chisq.image")); … … 34 47 35 48 bool psphotStackChisqImageAddReadout(const pmConfig *config, // Configuration 36 pmFPAview *view,37 pmReadout * chiReadout,49 const pmFPAview *view, 50 pmReadout **chiReadout, 38 51 char *filename, 39 52 int index) … … 49 62 50 63 psImage *inImage = inReadout->image; 64 psAssert (inImage, "missing image?"); 65 51 66 psImage *inVariance = inReadout->variance; 67 psAssert (inVariance, "missing variance?"); 68 52 69 psImage *inMask = inReadout->mask; 70 psAssert (inMask, "missing mask?"); 53 71 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"); 57 84 58 85 // select the appropriate recipe information … … 83 110 return true; 84 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.
