Changeset 17426
- Timestamp:
- Apr 10, 2008, 10:54:53 AM (18 years ago)
- Location:
- trunk/ppStack/src
- Files:
-
- 3 edited
-
ppStackCamera.c (modified) (3 diffs)
-
ppStackLoop.c (modified) (1 diff)
-
ppStackMatch.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStack/src/ppStackCamera.c
r17257 r17426 72 72 { 73 73 bool haveWeights = false; // Do we have weight maps? 74 bool havePSF = false; // Do we have PSFs? 74 75 75 76 psMetadata *inputs = psMetadataLookupMetadata(NULL, config->arguments, "INPUTS"); // The inputs info … … 169 170 // Add the psf file 170 171 if (!psf || strlen(psf) == 0) { 171 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find PSF %d", i); 172 return false; 172 if (havePSFs) { 173 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find PSF %d", i); 174 return false; 175 } 173 176 } else { 174 psArray *psfFiles = psArrayAlloc(1); // Array of filenames for this FPA 175 psfFiles->data[0] = psMemIncrRefCounter(psf); 176 psMetadataAddArray(config->arguments, PS_LIST_TAIL, "PSF.FILENAMES", PS_META_REPLACE, 177 "Filenames of PSF files", psfFiles); 178 psFree(psfFiles); 179 180 bool status; 181 pmFPAfile *psfFile = pmFPAfileBindFromArgs(&status, imageFile, config, "PPSTACK.INPUT.PSF", 182 "PSF.FILENAMES"); 183 if (!status) { 184 psError(PS_ERR_UNKNOWN, false, "Unable to define file from psf %d (%s)", i, psf); 185 return false; 186 } 187 if (psfFile->type != PM_FPA_FILE_PSF) { 188 psError(PS_ERR_IO, true, "PPSTACK.INPUT.PSF is not of type PSF"); 189 return false; 177 if (!havePSFs && i != 0) { 178 psWarning("PSF not provided for all inputs --- ignoring."); 179 } else { 180 psArray *psfFiles = psArrayAlloc(1); // Array of filenames for this FPA 181 psfFiles->data[0] = psMemIncrRefCounter(psf); 182 psMetadataAddArray(config->arguments, PS_LIST_TAIL, "PSF.FILENAMES", PS_META_REPLACE, 183 "Filenames of PSF files", psfFiles); 184 psFree(psfFiles); 185 186 bool status; 187 pmFPAfile *psfFile = pmFPAfileBindFromArgs(&status, imageFile, config, "PPSTACK.INPUT.PSF", 188 "PSF.FILENAMES"); 189 if (!status) { 190 psError(PS_ERR_UNKNOWN, false, "Unable to define file from psf %d (%s)", i, psf); 191 return false; 192 } 193 if (psfFile->type != PM_FPA_FILE_PSF) { 194 psError(PS_ERR_IO, true, "PPSTACK.INPUT.PSF is not of type PSF"); 195 return false; 196 } 197 havePSFs = true; 190 198 } 191 199 } … … 233 241 234 242 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "INPUTS.NUM", 0, "Number of input files", i); 243 psMetadataAddBool(config->arguments, PS_LIST_TAIL, "HAVE.PSF", 0, "Have PSFs available?", havePSFs); 235 244 236 245 // Output image -
trunk/ppStack/src/ppStackLoop.c
r17266 r17426 215 215 pmReadout *sources = NULL; // Readout with sources to use for PSF matching 216 216 pmPSF *targetPSF = NULL; // Target PSF 217 {217 if (psMetadataLookupBool(NULL, config->arguments, "HAVE.PSF")) { 218 218 pmFPAfileActivate(config->files, false, NULL); 219 219 fileActivation(config, prepareFiles, true); -
trunk/ppStack/src/ppStackMatch.c
r17268 r17426 13 13 14 14 //#define TESTING 15 //#define NO_CONVOLUTION16 15 17 16 bool ppStackMatch(pmReadout *readout, psArray **regions, psArray **kernels, … … 22 21 assert(kernels && !*kernels); 23 22 assert(sourcesRO); 24 assert(psf);25 23 assert(config); 26 24 … … 37 35 int renormWidth = psMetadataLookupS32(&mdok, config->arguments, "RENORM.WIDTH"); // Width for renormalisation box 38 36 39 #ifndef NO_CONVOLUTION 40 int order = psMetadataLookupS32(NULL, recipe, "SPATIAL.ORDER"); // Spatial polynomial order 41 float regionSize = psMetadataLookupF32(NULL, recipe, "REGION.SIZE"); // Size of iso-kernel regs 42 float spacing = psMetadataLookupF32(NULL, recipe, "STAMP.SPACING"); // Typical stamp spacing 43 int footprint = psMetadataLookupS32(NULL, recipe, "STAMP.FOOTPRINT"); // Stamp half-size 44 float threshold = psMetadataLookupF32(NULL, recipe, "STAMP.THRESHOLD"); // Threshold for stmps 45 int iter = psMetadataLookupS32(NULL, recipe, "ITER"); // Rejection iterations 46 float rej = psMetadataLookupF32(NULL, recipe, "REJ"); // Rejection threshold 47 pmSubtractionKernelsType type = 48 pmSubtractionKernelsTypeFromString(psMetadataLookupStr(NULL, recipe, "KERNEL.TYPE")); // Kernel type 49 psVector *widths = psMetadataLookupPtr(NULL, recipe, "ISIS.WIDTHS"); // ISIS Gaussian widths 50 psVector *orders = psMetadataLookupPtr(NULL, recipe, "ISIS.ORDERS"); // ISIS Polynomial orders 51 int inner = psMetadataLookupS32(NULL, recipe, "INNER"); // Inner radius 52 int ringsOrder = psMetadataLookupS32(NULL, recipe, "RINGS.ORDER"); // RINGS polynomial order 53 int binning = psMetadataLookupS32(NULL, recipe, "SPAM.BINNING"); // Binning for SPAM kernel 54 psMaskType maskBlank = pmConfigMask(psMetadataLookupStr(NULL, recipe, "MASK.BLANK"), 55 config); // Mask for blank reg. 56 float badFrac = psMetadataLookupF32(NULL, recipe, "BADFRAC"); // Maximum bad fraction 57 bool optimum = psMetadataLookupBool(&mdok, recipe, "OPTIMUM"); // Derive optimum parameters? 58 float optMin = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.MIN"); // Minimum width for search 59 float optMax = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.MAX"); // Maximum width for search 60 float optStep = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.STEP"); // Step for search 61 float optThresh = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.TOL"); // Tolerance for search 62 int optOrder = psMetadataLookupS32(&mdok, recipe, "OPTIMUM.ORDER"); // Order for search 63 64 // These values are specified specifically for stacking 65 const char *stampsName = psMetadataLookupStr(NULL, config->arguments, "STAMPS"); // Filename for stamps 66 67 psVector *optWidths = NULL; // Vector with FWHMs for optimum search 68 if (optimum) { 69 optWidths = psVectorCreate(optWidths, optMin, optMax, optStep, PS_TYPE_F32); 70 } 71 72 psArray *sources = NULL; // Sources in image 73 if (sourcesRO) { 74 sources = psMetadataLookupPtr(&mdok, sourcesRO->analysis, "PSPHOT.SOURCES"); 75 } 76 77 // Generate a fake image to match to 78 float maxMag = -INFINITY; // Maximum magnitude of sources 79 for (int i = 0; i < sources->n; i++) { 80 pmSource *source = sources->data[i]; // Source of interest 81 if (source->psfMag > maxMag && source->psfMag != MAG_IGNORE) { 82 maxMag = source->psfMag; 83 } 84 } 85 86 pmReadout *fake = pmReadoutAlloc(NULL); // Fake readout with target PSF 87 88 if (!pmReadoutFakeFromSources(fake, readout->image->numCols, readout->image->numRows, sources, NULL, NULL, 89 psf, powf(10.0, -0.4 * maxMag), 0, false)) { 90 psError(PS_ERR_UNKNOWN, false, "Unable to generate fake image with target PSF."); 37 if (psMetadataLookupBool(&mdok, config->arguments, "HAVE.PSF")) { 38 assert(psf); 39 int order = psMetadataLookupS32(NULL, recipe, "SPATIAL.ORDER"); // Spatial polynomial order 40 float regionSize = psMetadataLookupF32(NULL, recipe, "REGION.SIZE"); // Size of iso-kernel regs 41 float spacing = psMetadataLookupF32(NULL, recipe, "STAMP.SPACING"); // Typical stamp spacing 42 int footprint = psMetadataLookupS32(NULL, recipe, "STAMP.FOOTPRINT"); // Stamp half-size 43 float threshold = psMetadataLookupF32(NULL, recipe, "STAMP.THRESHOLD"); // Threshold for stmps 44 int iter = psMetadataLookupS32(NULL, recipe, "ITER"); // Rejection iterations 45 float rej = psMetadataLookupF32(NULL, recipe, "REJ"); // Rejection threshold 46 pmSubtractionKernelsType type = 47 pmSubtractionKernelsTypeFromString(psMetadataLookupStr(NULL, recipe, "KERNEL.TYPE")); // Kernel type 48 psVector *widths = psMetadataLookupPtr(NULL, recipe, "ISIS.WIDTHS"); // ISIS Gaussian widths 49 psVector *orders = psMetadataLookupPtr(NULL, recipe, "ISIS.ORDERS"); // ISIS Polynomial orders 50 int inner = psMetadataLookupS32(NULL, recipe, "INNER"); // Inner radius 51 int ringsOrder = psMetadataLookupS32(NULL, recipe, "RINGS.ORDER"); // RINGS polynomial order 52 int binning = psMetadataLookupS32(NULL, recipe, "SPAM.BINNING"); // Binning for SPAM kernel 53 psMaskType maskBlank = pmConfigMask(psMetadataLookupStr(NULL, recipe, "MASK.BLANK"), 54 config); // Mask for blank reg. 55 float badFrac = psMetadataLookupF32(NULL, recipe, "BADFRAC"); // Maximum bad fraction 56 bool optimum = psMetadataLookupBool(&mdok, recipe, "OPTIMUM"); // Derive optimum parameters? 57 float optMin = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.MIN"); // Minimum width for search 58 float optMax = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.MAX"); // Maximum width for search 59 float optStep = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.STEP"); // Step for search 60 float optThresh = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.TOL"); // Tolerance for search 61 int optOrder = psMetadataLookupS32(&mdok, recipe, "OPTIMUM.ORDER"); // Order for search 62 63 // These values are specified specifically for stacking 64 const char *stampsName = psMetadataLookupStr(NULL, config->arguments, "STAMPS"); // Filename for stamps 65 66 psVector *optWidths = NULL; // Vector with FWHMs for optimum search 67 if (optimum) { 68 optWidths = psVectorCreate(optWidths, optMin, optMax, optStep, PS_TYPE_F32); 69 } 70 71 psArray *sources = NULL; // Sources in image 72 if (sourcesRO) { 73 sources = psMetadataLookupPtr(&mdok, sourcesRO->analysis, "PSPHOT.SOURCES"); 74 } 75 76 // Generate a fake image to match to 77 float maxMag = -INFINITY; // Maximum magnitude of sources 78 for (int i = 0; i < sources->n; i++) { 79 pmSource *source = sources->data[i]; // Source of interest 80 if (source->psfMag > maxMag && source->psfMag != MAG_IGNORE) { 81 maxMag = source->psfMag; 82 } 83 } 84 85 pmReadout *fake = pmReadoutAlloc(NULL); // Fake readout with target PSF 86 87 if (!pmReadoutFakeFromSources(fake, readout->image->numCols, readout->image->numRows, sources, NULL, 88 NULL, psf, powf(10.0, -0.4 * maxMag), 0, false)) { 89 psError(PS_ERR_UNKNOWN, false, "Unable to generate fake image with target PSF."); 90 psFree(fake); 91 psFree(optWidths); 92 psFree(output); 93 return false; 94 } 95 96 #ifdef TESTING 97 { 98 psFits *fits = psFitsOpen("fake.fits", "w"); 99 psFitsWriteImage(fits, NULL, fake->image, 0, NULL); 100 psFitsClose(fits); 101 } 102 #endif 103 104 // Do the image matching 105 if (!pmSubtractionMatch(output, NULL, readout, fake, footprint, regionSize, spacing, threshold, 106 sources, stampsName, type, size, order, widths, orders, inner, ringsOrder, 107 binning, optimum, optWidths, optOrder, optThresh, iter, rej, maskBad, 108 maskBlank, badFrac, PM_SUBTRACTION_MODE_1)) { 109 psError(PS_ERR_UNKNOWN, false, "Unable to match images."); 110 psFree(fake); 111 psFree(optWidths); 112 psFree(output); 113 return false; 114 } 91 115 psFree(fake); 92 116 psFree(optWidths); 93 psFree(output); 94 return false; 95 } 96 97 #ifdef TESTING 98 { 99 psFits *fits = psFitsOpen("fake.fits", "w"); 100 psFitsWriteImage(fits, NULL, fake->image, 0, NULL); 101 psFitsClose(fits); 102 } 103 #endif 104 105 // Do the image matching 106 if (!pmSubtractionMatch(output, NULL, readout, fake, footprint, regionSize, spacing, threshold, 107 sources, stampsName, type, size, order, widths, orders, inner, ringsOrder, 108 binning, optimum, optWidths, optOrder, optThresh, iter, rej, maskBad, 109 maskBlank, badFrac, PM_SUBTRACTION_MODE_1)) { 110 psError(PS_ERR_UNKNOWN, false, "Unable to match images."); 111 psFree(fake); 112 psFree(optWidths); 113 psFree(output); 114 return false; 115 } 116 psFree(fake); 117 psFree(optWidths); 118 119 // Replace original images with convolved 120 psFree(readout->image); 121 psFree(readout->mask); 122 psFree(readout->weight); 123 readout->image = psMemIncrRefCounter(output->image); 124 readout->mask = psMemIncrRefCounter(output->mask); 125 readout->weight = psMemIncrRefCounter(output->weight); 126 127 #else // NO_CONVOLUTION 128 // Fake the convolution 129 { 117 118 // Replace original images with convolved 119 psFree(readout->image); 120 psFree(readout->mask); 121 psFree(readout->weight); 122 readout->image = psMemIncrRefCounter(output->image); 123 readout->mask = psMemIncrRefCounter(output->mask); 124 readout->weight = psMemIncrRefCounter(output->weight); 125 } else { 126 // Fake the convolution 130 127 psRegion *region = psRegionAlloc(0, readout->image->numCols - 1, 0, readout->image->numRows - 1); 131 128 psMetadataAddPtr(output->analysis, PS_LIST_TAIL, PM_SUBTRACTION_ANALYSIS_REGION, 132 129 PS_DATA_REGION | PS_META_DUPLICATE_OK, "Fake subtraction region", region); 133 130 psFree(region); 134 pmSubtractionKernels *kernels = pmSubtractionKernelsPOIS( size, 0, PM_SUBTRACTION_MODE_1);131 pmSubtractionKernels *kernels = pmSubtractionKernelsPOIS(0, 0, PM_SUBTRACTION_MODE_1); 135 132 // Set solution to delta function 136 133 kernels->solution1 = psVectorAlloc(kernels->num + 2, PS_TYPE_F64); … … 142 139 psFree(kernels); 143 140 } 144 #endif145 141 146 142 // Extract the regions and solutions used in the image matching
Note:
See TracChangeset
for help on using the changeset viewer.
