Changeset 31154 for trunk/psphot/src/psphotStackImageLoop.c
- Timestamp:
- Apr 4, 2011, 1:12:39 PM (15 years ago)
- Location:
- trunk/psphot
- Files:
-
- 2 edited
-
. (modified) (2 props)
-
src/psphotStackImageLoop.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot
- Property svn:ignore
-
old new 19 19 psphot-config 20 20 Doxyfile 21 a.out.dSYM
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
trunk/psphot/src/psphotStackImageLoop.c
r30624 r31154 1 1 # include "psphotStandAlone.h" 2 #define WCS_NONLIN_TOL 0.001 // Non-linear tolerance for header WCS3 2 4 3 # define ESCAPE(MESSAGE) { \ … … 8 7 } 9 8 10 bool GetAstrometryFPA (pmConfig *config, pmFPAview *view); 11 bool SetAstrometryFPA (pmConfig *config, pmFPAview *view, bool bilevelAstrometry);12 bool GetAstrometryChip (pmConfig *config, pmFPAview *view, bool bilevelAstrometry);9 // XXX this implementation is not smart about multi-level astrometry headers 10 bool UpdateHeadersForFPA (pmConfig *config, pmFPAview *view); 11 bool UpdateHeadersForChip (pmConfig *config, pmFPAview *view); 13 12 14 13 bool psphotStackImageLoop (pmConfig *config) { … … 18 17 pmCell *cell; 19 18 pmReadout *readout; 19 20 psMemDump("startloop"); 20 21 21 22 pmFPAfile *inputRaw = psMetadataLookupPtr (&status, config->files, "PSPHOT.STACK.INPUT.RAW"); … … 32 33 // XXX for now, just load the full set of images up front 33 34 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for fpa in psphot."); 34 35 bool bilevelAstrometry = GetAstrometryFPA(config, view);36 35 37 36 // for psphot, we force data to be read at the chip level … … 51 50 if (! readout->data_exists) { continue; } 52 51 52 psMemDump("load"); 53 53 54 // PSF matching 54 55 if (!psphotStackMatchPSFs (config, view)) { … … 57 58 return false; 58 59 } 60 psMemDump("stackmatch"); 59 61 60 62 // XXX for now, we assume there is only a single chip in the PHU: … … 64 66 return false; 65 67 } 66 68 psMemDump("psphot"); 67 69 } 68 70 // drop all versions of the internal files … … 78 80 } 79 81 80 GetAstrometryChip(config, view, bilevelAstrometry);82 UpdateHeadersForChip(config, view); 81 83 82 84 // save output which is saved at the chip level 83 85 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed output for Chip in psphot."); 84 86 } 87 psMemDump("doneloop"); 85 88 86 SetAstrometryFPA(config, view, bilevelAstrometry);87 89 UpdateHeadersForFPA(config, view); 90 88 91 // save output which is saved at the fpa level 89 92 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed ouput for FPA in psphot."); … … 93 96 94 97 psFree (view); 98 99 psMemDump("doneoutput"); 95 100 return true; 96 101 } 97 102 98 /* 99 the easiest way to implement this is to assume we can pre-load the full set of images up front. 100 with 5 filters and 6000^2 (image, mask, var = 10 byte per pixel), we need 1.8GB, which is not too bad. 101 */ 102 103 # define UPDATE_HEADER 1 104 105 bool GetAstrometryFPA (pmConfig *config, pmFPAview *view) { 106 107 bool foundAstrometry = false; 108 bool bilevelAstrometry = false; 103 bool UpdateHeadersForChip (pmConfig *config, pmFPAview *view) { 109 104 110 105 int num = psphotFileruleCount(config, "PSPHOT.INPUT"); … … 122 117 psAssert (input, "missing input file"); 123 118 124 // find the FPA phu 125 pmHDU *phu = pmFPAviewThisPHU(view, input->fpa); 126 if (!phu) { 127 psWarning("Unable to read bilevel mosaic astrometry for input FPA entry %d", i); 128 continue; 119 // just copy the input headers to the output headers, then update version info 120 pmChip *inChip = pmFPAviewThisChip(view, input->fpa); ///< Chip in the input 121 pmHDU *inHDU = pmFPAviewThisHDU (view, input->fpa); 122 123 pmChip *outChip = pmFPAviewThisChip(view, output->fpa); ///< Chip in the output 124 pmHDU *outHDU = pmFPAviewThisHDU (view, output->fpa); 125 if (!outHDU) { 126 pmFPAAddSourceFromView(output->fpa, view, output->format); 127 outHDU = pmFPAviewThisHDU (view, output->fpa); 128 psAssert (outHDU, "failed to make HDU"); 129 129 } 130 131 char *ctype = psMetadataLookupStr(NULL, phu->header, "CTYPE1"); 132 if (!ctype) { 133 psWarning("Error in WCS keywords for input FPA entry %d", i); 134 continue; 130 if (!outHDU->header) { 131 outHDU->header = psMetadataCopy(NULL, inHDU->header); 135 132 } 136 137 if (!foundAstrometry) { 138 bilevelAstrometry = !strcmp (&ctype[4], "-DIS"); 139 } else { 140 if (bilevelAstrometry != !strcmp (&ctype[4], "-DIS")) { 141 psAbort("astrometry type mis-match"); 142 } 143 } 144 145 if (bilevelAstrometry) { 146 // update the output structures 147 if (!pmAstromReadBilevelMosaic(output->fpa, phu->header)) { 148 psWarning("Unable to read bilevel mosaic astrometry for input FPA."); 149 } 150 } 133 outChip->toFPA = psMemIncrRefCounter(inChip->toFPA); 134 outChip->fromFPA = psMemIncrRefCounter(inChip->fromFPA); 151 135 } 152 return bilevelAstrometry;136 return true; 153 137 } 154 138 155 bool GetAstrometryChip (pmConfig *config, pmFPAview *view, bool bilevelAstrometry) {139 bool UpdateHeadersForFPA (pmConfig *config, pmFPAview *view) { 156 140 157 141 int num = psphotFileruleCount(config, "PSPHOT.INPUT"); … … 169 153 psAssert (input, "missing input file"); 170 154 171 // Need to update the output for astrometry. Read WCS data from the corresponding 172 // header and save in the output fpa 173 pmHDU *inHDU = pmFPAviewThisHDU (view, input->fpa); 174 pmChip *outChip = pmFPAviewThisChip(view, output->fpa); ///< Chip in the output 155 output->fpa->toTPA = psMemIncrRefCounter(input->fpa->toTPA); 156 output->fpa->fromTPA = psMemIncrRefCounter(input->fpa->fromTPA); 157 output->fpa->toSky = psMemIncrRefCounter(input->fpa->toSky); 175 158 176 pmHDU *outHDU = pmFPAviewThisHDU (view, output->fpa); 177 if (!outHDU) { 178 pmFPAAddSourceFromView(output->fpa, view, output->format); 179 outHDU = pmFPAviewThisHDU (view, output->fpa); 180 psAssert (outHDU, "failed to make HDU"); 181 } 182 if (!outHDU->header) { 183 outHDU->header = psMetadataAlloc(); 184 } 159 pmConceptsCopyFPA(output->fpa, input->fpa, true, true); 185 160 186 if (bilevelAstrometry) { 187 if (!pmAstromReadBilevelChip (outChip, inHDU->header)) { 188 psWarning("Unable to read bilevel chip astrometry for input FPA."); 189 continue; 190 } 191 if (!pmAstromWriteBilevelChip(outHDU->header, outChip, WCS_NONLIN_TOL)) { 192 psWarning("Unable to generate WCS header."); 193 continue; 194 } 195 } else { 196 // we use a default FPA pixel scale of 1.0 197 if (!pmAstromReadWCS (output->fpa, outChip, inHDU->header, 1.0)) { 198 psWarning("Unable to read WCS astrometry for input FPA."); 199 continue; 200 } 201 if (!pmAstromWriteWCS(outHDU->header, output->fpa, outChip, WCS_NONLIN_TOL)) { 202 psWarning("Unable to generate WCS header."); 203 continue; 204 } 205 } 161 // XXX TEST 162 // pmFPASetFileStatus(output->fpa, true); 163 // pmFPASetDataStatus(output->fpa, true); 164 // pmChip *chip = output->fpa->chips->data[0]; 165 // pmCell *cell = chip->cells->data[0]; 166 // pmReadout *readout = cell->readouts->data[0]; 206 167 } 207 208 168 return true; 209 169 } 210 170 211 bool SetAstrometryFPA (pmConfig *config, pmFPAview *view, bool bilevelAstrometry) { 171 /* 172 the easiest way to implement this is to assume we can pre-load the full set of images up front. 173 with 5 filters and 6000^2 (image, mask, var = 10 byte per pixel), we need 1.8GB, which is not too bad. 174 */ 212 175 213 if (!bilevelAstrometry) return true;214 215 int num = psphotFileruleCount(config, "PSPHOT.INPUT");216 217 // loop over the available readouts218 for (int i = 0; i < num; i++) {219 220 // find the currently selected readout221 pmFPAfile *output = pmFPAfileSelectSingle(config->files, "PSPHOT.STACK.OUTPUT.IMAGE", i); // File of interest222 psAssert (output, "missing file?");223 224 pmHDU *PHU = pmFPAviewThisPHU(view, output->fpa);225 if (!PHU) {226 pmFPAAddSourceFromView(output->fpa, view, output->format);227 PHU = pmFPAviewThisPHU (view, output->fpa);228 psAssert (PHU, "failed to make PHU");229 }230 if (!PHU->header) {231 PHU->header = psMetadataAlloc();232 }233 234 if (!pmAstromWriteBilevelMosaic(PHU->header, output->fpa, WCS_NONLIN_TOL)) {235 psWarning("Unable to generate WCS header.");236 }237 }238 239 return true;240 }
Note:
See TracChangeset
for help on using the changeset viewer.
