- Timestamp:
- Jan 20, 2010, 5:20:00 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20091201/ppSub/src/ppSubMatchPSFs.c
r26581 r26649 36 36 psFree(subImage); 37 37 return; 38 } 39 40 // Measure the PSF for an image 41 static float subImagePSF(ppSubData *data, // Processing data 42 const pmReadout *ro, // Readout for which to measure PSF 43 psArray *sources // Sources with positions at which to measure PSF 44 ) 45 { 46 psAssert(data, "Require processing data"); 47 pmConfig *config = data->config; // Configuration 48 psAssert(config, "Require configuration"); 49 50 psAssert(ro, "Need readout"); 51 psAssert(sources, "Need sources."); 52 53 pmFPAfile *photFile = psMetadataLookupPtr(NULL, config->files, "PSPHOT.INPUT"); // Photometry file 54 psAssert(photFile, "Need photometry file."); 55 if (!pmFPACopy(photFile->fpa, ro->parent->parent->parent)) { 56 psError(PS_ERR_UNKNOWN, false, "Unable to copy FPA for photometry"); 57 return false; 58 } 59 60 pmFPAview *view = ppSubViewReadout(); // View to readout 61 pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout to photometer 62 63 if (psMetadataLookup(photRO->analysis, "PSPHOT.SOURCES")) { 64 psMetadataRemoveKey(photRO->analysis, "PSPHOT.SOURCES"); 65 } 66 if (psMetadataLookup(photRO->parent->parent->analysis, "PSPHOT.PSF")) { 67 psMetadataRemoveKey(photRO->parent->parent->analysis, "PSPHOT.PSF"); 68 } 69 70 // Extract the loaded sources from the associated readout, and generate PSF 71 // Here, we assume the image is background-subtracted 72 if (!psphotReadoutFindPSF(config, view, sources)) { 73 psErrorStackPrint(stderr, "Unable to determine PSF"); 74 psWarning("Unable to determine PSF."); 75 psFree(view); 76 return true; 77 } 78 79 psFree(view); 80 81 psMetadata *header = psMetadataLookupMetadata(NULL, photRO->analysis, "PSPHOT.HEADER"); 82 psAssert(header, "Require header."); 83 float fwhm = psMetadataLookupF32(NULL, header, "FWHM_MAJ"); 84 85 return fwhm; 86 } 87 88 // Scale the kernel parameters according to the PSFs 89 static bool subScaleKernel(ppSubData *data, // Processing data 90 psVector *kernelWidths, // Widths for kernel 91 int *kernelSize, // Size of kernel 92 int *stampSize // Size of stamps (footprint) 93 ) 94 { 95 psAssert(data, "Require processing data"); 96 pmConfig *config = data->config; // Configuration 97 psAssert(config, "Require configuration"); 98 99 // Nothing to do if pre-calculated kernel exists 100 pmFPAview *view = ppSubViewReadout(); // View to readout 101 pmReadout *kernelRO = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT.KERNELS"); // RO with kernel 102 if (kernelRO) { 103 psFree(view); 104 return true; 105 } 106 107 // Look up recipe values 108 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim 109 psAssert(recipe, "We checked this earlier, so it should be here."); 110 if (!psMetadataLookupBool(NULL, recipe, "SCALE")) { 111 // No scaling requested 112 psFree(view); 113 return true; 114 } 115 116 // Input images 117 pmReadout *inRO = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT"); // Input readout 118 pmReadout *refRO = pmFPAfileThisReadout(config->files, view, "PPSUB.REF"); // Reference readout 119 120 // Input sources 121 pmReadout *inSourceRO = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.SOURCES"); 122 pmReadout *refSourceRO = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.SOURCES"); 123 psArray *inSources = psMetadataLookupPtr(NULL, inSourceRO->analysis, "PSPHOT.SOURCES"); // Input sources 124 psArray *refSources = psMetadataLookupPtr(NULL, refSourceRO->analysis, "PSPHOT.SOURCES"); // Ref sources 125 126 psFree(view); 127 128 if (!inSources || !refSources) { 129 psWarning("Unable to scale kernel, since no sources were provided."); 130 return true; 131 } 132 133 134 float inFWHM = subImagePSF(data, inRO, inSources); // FWHM for input 135 float refFWHM = subImagePSF(data, refRO, refSources); // FWHM for reference 136 psLogMsg("ppSub", PS_LOG_INFO, "Input FWHM: %f\nReference FWHM: %f\n", inFWHM, refFWHM); 137 if (!isfinite(inFWHM) || !isfinite(refFWHM)) { 138 psWarning("Unable to scale kernel, since unable to measure PSFs."); 139 return true; 140 } 141 142 // float diff = sqrtf(PS_SQR(PS_MAX(inFWHM, refFWHM)) - PS_SQR(PS_MIN(inFWHM, refFWHM))); // Difference 143 float diff = PS_MAX(inFWHM, refFWHM); 144 145 float scaleRef = psMetadataLookupF32(NULL, recipe, "SCALE.REF"); // Reference for scaling 146 float scaleMin = psMetadataLookupF32(NULL, recipe, "SCALE.MIN"); // Minimum for scaling 147 float scaleMax = psMetadataLookupF32(NULL, recipe, "SCALE.MAX"); // Maximum for scaling 148 if (!isfinite(scaleRef) || !isfinite(scaleMin) || !isfinite(scaleMax)) { 149 psError(PPSUB_ERR_ARGUMENTS, false, 150 "Scale parameters (SCALE.REF=%f, SCALE.MIN=%f, SCALE.MAX=%f) not set in recipe.", 151 scaleRef, scaleMin, scaleMax); 152 return false; 153 } 154 155 float scale = diff / scaleRef; // Scaling factor 156 if (scale < scaleMin) { 157 scale = scaleMin; 158 } 159 if (scale > scaleMax) { 160 scale = scaleMax; 161 } 162 163 for (int i = 0; i < kernelWidths->n; i++) { 164 kernelWidths->data.F32[i] *= scale; 165 } 166 *kernelSize = *kernelSize * scale + 0.5; 167 *stampSize = *stampSize * scale + 0.5; 168 169 psLogMsg("ppSub", PS_LOG_INFO, "Scaled kernel parameters by %f: %d %d", scale, *kernelSize, *stampSize); 170 171 return true; 38 172 } 39 173 … … 133 267 float kernelErr = psMetadataLookupF32(NULL, recipe, "KERNEL.ERR"); // Relative systematic error in kernel 134 268 float sysErr = psMetadataLookupF32(NULL, recipe, "SYS.ERR"); // Relative systematic error in images 135 float skyErr = psMetadataLookupF32(NULL, recipe, "SKY.ERR"); // Relative systematic error in images269 float skyErr = psMetadataLookupF32(NULL, recipe, "SKY.ERR"); // Additional error in sky 136 270 137 271 float badFrac = psMetadataLookupF32(NULL, recipe, "BADFRAC"); // Maximum bad fraction … … 171 305 break; 172 306 default: 173 psError StackPrint(stderr, "Invalid value for -convolve");307 psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Invalid value for -convolve"); 174 308 return false; 175 309 } 310 } 311 312 if (!subScaleKernel(data, widths, &size, &footprint)) { 313 psError(PS_ERR_UNKNOWN, false, "Unable to scale kernel parameters"); 314 return false; 176 315 } 177 316
Note:
See TracChangeset
for help on using the changeset viewer.
