Changeset 25027 for branches/pap/ppSub
- Timestamp:
- Aug 7, 2009, 4:08:25 PM (17 years ago)
- Location:
- branches/pap
- Files:
-
- 1 deleted
- 12 edited
- 2 copied
-
. (modified) (1 prop)
-
ppSub (modified) (1 prop)
-
ppSub/src/Makefile.am (modified) (2 diffs)
-
ppSub/src/ppSub.h (modified) (3 diffs)
-
ppSub/src/ppSubArguments.c (modified) (1 diff)
-
ppSub/src/ppSubCamera.c (modified) (5 diffs)
-
ppSub/src/ppSubKernel.c (modified) (1 diff)
-
ppSub/src/ppSubLoop.c (modified) (2 diffs)
-
ppSub/src/ppSubMatchPSFs.c (modified) (7 diffs)
-
ppSub/src/ppSubReadout.c (deleted)
-
ppSub/src/ppSubReadoutInverse.c (modified) (2 diffs)
-
ppSub/src/ppSubReadoutPhotometry.c (modified) (2 diffs)
-
ppSub/src/ppSubReadoutSubtract.c (modified) (2 diffs)
-
ppSub/src/ppSubThreshold.c (copied) (copied from trunk/ppSub/src/ppSubThreshold.c )
-
ppSub/src/ppSubVarianceRescale.c (copied) (copied from trunk/ppSub/src/ppSubVarianceRescale.c )
Legend:
- Unmodified
- Added
- Removed
-
branches/pap
- Property svn:mergeinfo changed
-
branches/pap/ppSub
- Property svn:mergeinfo deleted
-
branches/pap/ppSub/src/Makefile.am
r23808 r25027 30 30 ppSubVersion.c \ 31 31 ppSubBackground.c \ 32 ppSubVarianceRescale.c \ 32 33 ppSubCamera.c \ 33 34 ppSubData.c \ … … 44 45 ppSubReadoutStats.c \ 45 46 ppSubReadoutSubtract.c \ 46 ppSubSetMasks.c 47 ppSubSetMasks.c \ 48 ppSubThreshold.c 47 49 48 50 ppSubKernel_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PPSUB_CFLAGS) -
branches/pap/ppSub/src/ppSub.h
r23753 r25027 24 24 25 25 #define PPSUB_RECIPE "PPSUB" /// Name of the recipe to use 26 #define WCS_TOLERANCE 0.001 // Tolerance for WCS 26 27 27 28 // Output files, for activation/deactivation … … 77 78 ); 78 79 80 /// Threshold low pixels in image 81 bool ppSubLowThreshold(ppSubData *data ///< Processing data 82 ); 83 79 84 /// Generate the output readout and pass the kernel info to the header 80 85 bool ppSubDefineOutput(const char *name,///< Name of output to define … … 98 103 /// Higher-order background subtraction 99 104 bool ppSubBackground(pmConfig *config ///< Configuration 105 ); 106 107 /// Perform Variance correction (rescale within a modest range) 108 bool ppSubVarianceRescale(pmConfig *config ///< Configuration 100 109 ); 101 110 -
branches/pap/ppSub/src/ppSubArguments.c
r23853 r25027 84 84 psMetadataAddS32(arguments, PS_LIST_TAIL, "-threads", 0, "Number of threads", 0); 85 85 psMetadataAddStr(arguments, PS_LIST_TAIL, "-dumpconfig", 0, "file to dump configuration to", NULL); 86 psMetadataAddS32(arguments, PS_LIST_TAIL, "-convolve", 0, "Image to convolve [1 or 2]", 0); 86 87 psMetadataAddBool(arguments, PS_LIST_TAIL, "-photometry", 0, "Perform photometry?", NULL); 87 88 psMetadataAddBool(arguments, PS_LIST_TAIL, "-inverse", 0, "Generate inverse subtractions?", NULL); -
branches/pap/ppSub/src/ppSubCamera.c
r23753 r25027 163 163 164 164 165 // Now that the camera has been determined, we can read the recipe 166 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim 167 if (!recipe) { 168 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find recipe %s", PPSUB_RECIPE); 169 return false; 170 } 171 if (psMetadataLookupBool(NULL, config->arguments, "-photometry")) { 172 psMetadataAddBool(recipe, PS_LIST_TAIL, "PHOTOMETRY", PS_META_REPLACE, 173 "Perform photometry?", true); 174 } 175 if (psMetadataLookupBool(NULL, config->arguments, "-inverse")) { 176 psMetadataAddBool(recipe, PS_LIST_TAIL, "INVERSE", PS_META_REPLACE, 177 "Generate inverse subtractions?", true); 178 } 179 180 data->inverse = psMetadataLookupBool(NULL, recipe, "INVERSE"); 181 data->photometry = psMetadataLookupBool(NULL, recipe, "PHOTOMETRY"); 182 183 bool mdok; // Status of MD lookup 184 bool saveConv = psMetadataLookupBool(&mdok, recipe, "SAVE.CONVOLVED"); // Save convolved images? 185 165 186 // Convolved input image 166 187 pmFPAfile *inConvImage = defineOutputFile(config, input, true, "PPSUB.INPUT.CONV", PM_FPA_FILE_IMAGE); … … 171 192 return false; 172 193 } 194 if (saveConv) { 195 inConvImage->save = true; 196 inConvMask->save = true; 197 } 173 198 if (inVar) { 174 199 pmFPAfile *inConvVar = defineOutputFile(config, inConvImage, false, "PPSUB.INPUT.CONV.VARIANCE", … … 177 202 psError(PS_ERR_UNKNOWN, false, "Unable to define output files"); 178 203 return false; 204 } 205 if (saveConv) { 206 inConvVar->save = true; 179 207 } 180 208 } … … 188 216 return false; 189 217 } 218 if (saveConv) { 219 refConvImage->save = true; 220 refConvMask->save = true; 221 } 190 222 if (refVar) { 191 223 pmFPAfile *refConvVar = defineOutputFile(config, refConvImage, false, "PPSUB.REF.CONV.VARIANCE", … … 195 227 return false; 196 228 } 197 } 198 199 200 // Now that the camera has been determined, we can read the recipe 201 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim 202 if (!recipe) { 203 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find recipe %s", PPSUB_RECIPE); 204 return false; 205 } 206 if (psMetadataLookupBool(NULL, config->arguments, "-photometry")) { 207 psMetadataAddBool(recipe, PS_LIST_TAIL, "PHOTOMETRY", PS_META_REPLACE, 208 "Perform photometry?", true); 209 } 210 if (psMetadataLookupBool(NULL, config->arguments, "-inverse")) { 211 psMetadataAddBool(recipe, PS_LIST_TAIL, "INVERSE", PS_META_REPLACE, 212 "Generate inverse subtractions?", true); 213 } 214 215 data->inverse = psMetadataLookupBool(NULL, recipe, "INVERSE"); 216 data->photometry = psMetadataLookupBool(NULL, recipe, "PHOTOMETRY"); 217 229 if (saveConv) { 230 refConvVar->save = true; 231 } 232 } 218 233 219 234 // Output image -
branches/pap/ppSub/src/ppSubKernel.c
r21360 r25027 29 29 } 30 30 31 psTraceSetLevel("psModules.imcombine", 7);31 (void) psTraceSetLevel("psModules.imcombine", 7); 32 32 33 33 const char *inName = argv[1]; // Input file name -
branches/pap/ppSub/src/ppSubLoop.c
r23753 r25027 65 65 } 66 66 67 if (!ppSubLowThreshold(data)) { 68 psError(PS_ERR_UNKNOWN, false, "Unable to threshold images."); 69 return false; 70 } 71 67 72 // Set up subtraction files 68 73 if (!ppSubFilesIterateDown(config, PPSUB_FILES_SUB)) { … … 95 100 if (!ppSubBackground(config)) { 96 101 psError(PS_ERR_UNKNOWN, false, "Unable to subtract background."); 102 return false; 103 } 104 105 // Perform Variance correction (rescale within a modest range) 106 if (!ppSubVarianceRescale(config)) { 107 psError(PS_ERR_UNKNOWN, false, "Unable to rescale variance."); 97 108 return false; 98 109 } -
branches/pap/ppSub/src/ppSubMatchPSFs.c
r23758 r25027 18 18 #include <pslib.h> 19 19 #include <psmodules.h> 20 #include <psphot.h>21 20 22 21 #include "ppSub.h" 22 23 // Normalise a region on an image 24 static void normaliseRegion(psImage *image, // Image to normalise 25 const psRegion *region, // Region of image to normalise 26 float norm // Normalisation 27 ) 28 { 29 if (!image) { 30 return; 31 } 32 psAssert(region, "Expect region"); 33 psImage *subImage = psImageSubset(image, *region); // Sub-image 34 psBinaryOp(subImage, subImage, "*", psScalarAlloc(norm, PS_TYPE_F32)); 35 psFree(subImage); 36 return; 37 } 38 23 39 24 40 bool ppSubMatchPSFs(ppSubData *data) … … 60 76 pmReadout *inSourceRO = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.SOURCES"); 61 77 pmReadout *refSourceRO = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.SOURCES"); 62 psArray *inSources = psMetadataLookupPtr(&mdok, inSourceRO->analysis, "PSPHOT.SOURCES"); // Source list 63 psArray *refSources = psMetadataLookupPtr(&mdok, refSourceRO->analysis, "PSPHOT.SOURCES"); // Source list 78 psArray *inSources = inSourceRO ? psMetadataLookupPtr(&mdok, inSourceRO->analysis, "PSPHOT.SOURCES") : 79 NULL; // Source list from input image 80 psArray *refSources = refSourceRO ? psMetadataLookupPtr(&mdok, refSourceRO->analysis, "PSPHOT.SOURCES") : 81 NULL ; // Source list from reference image 64 82 65 83 psArray *sources = NULL; // Merged list of sources … … 92 110 float spacing = psMetadataLookupF32(NULL, recipe, "STAMP.SPACING"); // Typical stamp spacing 93 111 float threshold = psMetadataLookupF32(NULL, recipe, "STAMP.THRESHOLD"); // Threshold for stmps 94 const char *stampsName = psMetadataLookupStr(&mdok, config->arguments, "STAMPS"); // Filename for stamps95 112 96 113 const char *typeStr = psMetadataLookupStr(NULL, recipe, "KERNEL.TYPE"); // Kernel type … … 135 152 136 153 bool dual = psMetadataLookupBool(&mdok, recipe, "DUAL"); // Dual convolution? 137 pmSubtractionMode subMode = dual ? PM_SUBTRACTION_MODE_DUAL : PM_SUBTRACTION_MODE_UNSURE; // Subtracn mode 154 pmSubtractionMode subMode; // Subtraction mode 155 if (dual) { 156 subMode = PM_SUBTRACTION_MODE_DUAL; 157 } else { 158 int convolve = psMetadataLookupS32(NULL, config->arguments, "-convolve"); // Image number to convolve 159 switch (convolve) { 160 case 0: 161 subMode = PM_SUBTRACTION_MODE_UNSURE; 162 break; 163 case 1: 164 subMode = PM_SUBTRACTION_MODE_1; 165 break; 166 case 2: 167 subMode = PM_SUBTRACTION_MODE_2; 168 break; 169 default: 170 psErrorStackPrint(stderr, "Invalid value for -convolve"); 171 return false; 172 } 173 } 138 174 139 175 int threads = psMetadataLookupS32(NULL, config->arguments, "-threads"); // Number of threads … … 149 185 } else { 150 186 success = pmSubtractionMatch(inConv, refConv, inRO, refRO, footprint, stride, regionSize, 151 spacing, threshold, sources, stampsName, type, size, order,187 spacing, threshold, sources, data->stamps, type, size, order, 152 188 widths, orders, inner, ringsOrder, binning, penalty, optimum, 153 189 optWidths, optOrder, optThresh, iter, rej, sys, maskVal, … … 165 201 ppSubDataQuality(data, error, PPSUB_FILES_ALL); 166 202 return true; 203 } else if (error == PM_ERR_SMALL_AREA) { 204 psErrorStackPrint(stderr, "Insufficient area for PSF matching"); 205 psWarning("Insufficient area for PSF matching --- suspect bad data quality."); 206 ppSubDataQuality(data, error, PPSUB_FILES_ALL); 207 return true; 167 208 } else { 168 209 psError(PS_ERR_UNKNOWN, false, "Unable to match images."); … … 171 212 } 172 213 214 // Need to be careful with the normalisation 215 // We will normalise everything to the normalisation of the *input* image 216 { 217 // Since the entries are MULTI, we have to retrieve them differently 218 psMetadataIterator *regIter = psMetadataIteratorAlloc(inConv->analysis, PS_LIST_HEAD, 219 "^" PM_SUBTRACTION_ANALYSIS_REGION "$"); 220 psMetadataIterator *modeIter = psMetadataIteratorAlloc(inConv->analysis, PS_LIST_HEAD, 221 "^" PM_SUBTRACTION_ANALYSIS_MODE "$"); 222 psMetadataIterator *normIter = psMetadataIteratorAlloc(inConv->analysis, PS_LIST_HEAD, 223 "^" PM_SUBTRACTION_ANALYSIS_NORM "$"); 224 psMetadataItem *regItem; // Item with region 225 while ((regItem = psMetadataGetAndIncrement(regIter))) { 226 psAssert(regItem->type == PS_DATA_REGION && regItem->data.V, "Expect region type"); 227 psRegion *region = regItem->data.V; // Region of interest 228 psMetadataItem *modeItem = psMetadataGetAndIncrement(modeIter); // Item with mode 229 psAssert(modeItem && modeItem->type == PS_TYPE_S32, "Expect subtraction mode"); 230 pmSubtractionMode mode = modeItem->data.S32; // Subtraction mode 231 psMetadataItem *normItem = psMetadataGetAndIncrement(normIter); // Item with normalisation 232 psAssert(normItem && normItem->type == PS_TYPE_F32 && isfinite(normItem->data.F32), 233 "Expect normalisation"); 234 float norm = normItem->data.F32; // Normalisation 235 236 switch (mode) { 237 case PM_SUBTRACTION_MODE_1: // Convolved the input to match template 238 case PM_SUBTRACTION_MODE_DUAL: // Convolved both; template should have flux conserved 239 psLogMsg("ppSub", PS_LOG_INFO, "Correcting image for normalisation of %f\n", norm); 240 normaliseRegion(inConv->image, region, 1.0 / norm); 241 normaliseRegion(refConv->image, region, 1.0 / norm); 242 normaliseRegion(inConv->variance, region, 1.0 / PS_SQR(norm)); 243 normaliseRegion(refConv->variance, region, 1.0 / PS_SQR(norm)); 244 break; 245 case PM_SUBTRACTION_MODE_2: // Convolved the template to match input 246 // We're already happy! 247 psLogMsg("ppSub", PS_LOG_INFO, "Image normalisation is correct\n"); 248 break; 249 default: 250 psAbort("Invalid subtraction mode: %x", mode); 251 } 252 } 253 psFree(regIter); 254 psFree(modeIter); 255 psFree(normIter); 256 } 257 258 173 259 pmConceptsCopyFPA(inConv->parent->parent->parent, inRO->parent->parent->parent, true, true); 174 260 pmConceptsCopyFPA(refConv->parent->parent->parent, refRO->parent->parent->parent, true, true); -
branches/pap/ppSub/src/ppSubReadoutInverse.c
r23763 r25027 7 7 8 8 #include "ppSub.h" 9 10 9 11 10 bool ppSubReadoutInverse(pmConfig *config) … … 24 23 invRO->data_exists = invRO->parent->data_exists = invRO->parent->parent->data_exists = true; 25 24 26 pmConceptsCopyFPA(invRO->parent->parent->parent, outRO->parent->parent->parent, true, true); 25 // Get concepts from reference 26 pmFPAfile *refFile = psMetadataLookupPtr(NULL, config->files, "PPSUB.REF.CONV"); // File with concepts 27 pmFPA *invFPA = invRO->parent->parent->parent; // Inverse FPA 28 pmConceptsCopyFPA(invFPA, refFile->fpa, true, true); 29 30 // Get astrometry from (forward) subtraction 31 pmChip *outChip = outRO->parent->parent; // Output chip 32 pmFPA *outFPA = outChip->parent; // Output FPA 33 pmChip *invChip = invRO->parent->parent; // Inverse chip 34 pmHDU *invHDU = invFPA->hdu; // Inverse HDU 35 if (!pmAstromWriteWCS(invHDU->header, outFPA, outChip, WCS_TOLERANCE)) { 36 psError(PS_ERR_UNKNOWN, false, "Unable to write WCS astrometry to PPSUB.INVERSE."); 37 return false; 38 } 39 // Read from newly written astrometry so that it exists in the "inverse" FPA (for sources) 40 if (!pmAstromReadWCS(invFPA, invChip, invHDU->header, 1.0)) { 41 psError(PS_ERR_UNKNOWN, false, "Unable to read WCS astrometry."); 42 return false; 43 } 27 44 28 45 return true; -
branches/pap/ppSub/src/ppSubReadoutPhotometry.c
r23938 r25027 65 65 // equivalent to the minuend image. 66 66 pmReadout *inRO = pmFPAfileThisReadout(config->files, view, name); // Readout with image and sources 67 if (psMetadataLookup(inRO->analysis, "PSPHOT.SOURCES")) { 68 psMetadataRemoveKey(inRO->analysis, "PSPHOT.SOURCES"); 69 } 67 70 68 71 pmFPAfile *photFile = psMetadataLookupPtr(&mdok, config->files, "PSPHOT.INPUT"); // Photometry file … … 92 95 } 93 96 97 // If no sources were found, there's no error, but we want to trigger 'bad quality' 98 psArray *sources = psMetadataLookupPtr(NULL, photRO->analysis, "PSPHOT.SOURCES"); // Sources 99 if (!sources) { 100 ppSubDataQuality(data, PSPHOT_ERR_DATA, PPSUB_FILES_PHOT_SUB | PPSUB_FILES_PHOT_INV); 101 } 102 94 103 if (data->stats) { 95 psArray *sources = psMetadataLookupPtr(NULL, photRO->analysis, "PSPHOT.SOURCES"); // Sources96 104 bool mdok; 97 105 int numSources = psMetadataLookupS32(&mdok, data->stats, "NUM_SOURCES"); // Number of sources -
branches/pap/ppSub/src/ppSubReadoutSubtract.c
r23740 r25027 20 20 21 21 #include "ppSub.h" 22 23 #define WCS_TOLERANCE 0.001 // Tolerance for WCS24 22 25 23 bool ppSubReadoutSubtract(pmConfig *config) … … 46 44 subtrahend = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV"); 47 45 } 48 49 // XXX this should be replaced by SAVE options to the inConv and refConf pmFPAfiles50 #ifdef TESTING51 {52 pmReadoutMaskApply(minuend, maskVal);53 psFits *fits = psFitsOpen("minuend.fits", "w");54 psFitsWriteImage(fits, NULL, minuend->image, 0, NULL);55 psFitsClose(fits);56 }57 {58 pmReadoutMaskApply(subtrahend, maskVal);59 psFits *fits = psFitsOpen("subtrahend.fits", "w");60 psFitsWriteImage(fits, NULL, subtrahend->image, 0, NULL);61 psFitsClose(fits);62 }63 #endif64 46 65 47 // Do the actual subtraction
Note:
See TracChangeset
for help on using the changeset viewer.
