Changeset 15516
- Timestamp:
- Nov 8, 2007, 12:59:04 PM (19 years ago)
- Location:
- branches/eam_branch_20071023/psModules/src
- Files:
-
- 25 edited
-
camera/pmFPAConstruct.c (modified) (3 diffs)
-
camera/pmFPAFlags.c (modified) (3 diffs)
-
camera/pmFPAMosaic.c (modified) (8 diffs)
-
camera/pmHDU.c (modified) (2 diffs)
-
camera/pmHDUGenerate.c (modified) (10 diffs)
-
camera/pmReadoutFake.c (modified) (2 diffs)
-
concepts/pmConceptsAverage.h (modified) (1 diff)
-
concepts/pmConceptsStandard.c (modified) (1 diff)
-
config/pmConfig.c (modified) (1 diff)
-
config/pmConfig.h (modified) (1 diff)
-
config/pmConfigCamera.c (modified) (1 diff)
-
config/pmConfigRecipes.c (modified) (23 diffs)
-
imcombine/pmReadoutCombine.c (modified) (1 diff)
-
imcombine/pmStack.c (modified) (1 diff)
-
imcombine/pmStackReject.c (modified) (3 diffs)
-
imcombine/pmSubtraction.h (modified) (7 diffs)
-
imcombine/pmSubtractionKernels.c (modified) (4 diffs)
-
imcombine/pmSubtractionKernels.h (modified) (1 diff)
-
imcombine/pmSubtractionMatch.c (modified) (17 diffs)
-
imcombine/pmSubtractionMatch.h (modified) (3 diffs)
-
imcombine/pmSubtractionParams.c (modified) (19 diffs)
-
imcombine/pmSubtractionParams.h (modified) (1 diff)
-
imcombine/pmSubtractionStamps.c (modified) (21 diffs)
-
imcombine/pmSubtractionStamps.h (modified) (5 diffs)
-
objects/pmTrend2D.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20071023/psModules/src/camera/pmFPAConstruct.c
r15218 r15516 45 45 psMetadata *cellData = psMetadataLookupMetadata(&status, cells, cellName); // The data for the particular cell 46 46 if (!status || !cellData) { 47 ps LogMsg(__func__, PS_LOG_WARN,"Unable to find specs for cell %s: ignored\n", cellName);47 psWarning("Unable to find specs for cell %s: ignored\n", cellName); 48 48 } 49 49 … … 304 304 // Put in the cell data 305 305 if (newCell->config) { 306 ps LogMsg(__func__, PS_LOG_WARN,"Overwriting cell data in chip\n");306 psWarning("Overwriting cell data in chip\n"); 307 307 psFree(newCell->config); // Make way! 308 308 } … … 1304 1304 const char *chipName = componentsItem->name; // Name of the chip 1305 1305 if (componentsItem->type != PS_DATA_STRING) { 1306 ps LogMsg(__func__, PS_LOG_WARN,"Element %s in FPA within the camera configuration is not of "1306 psWarning("Element %s in FPA within the camera configuration is not of " 1307 1307 "type STR (type=%x) --- ignored.\n", chipName, componentsItem->type); 1308 1308 continue; -
branches/eam_branch_20071023/psModules/src/camera/pmFPAFlags.c
r13190 r15516 136 136 137 137 for (int i = 0; i < fpa->chips->n; i++) { 138 pmChip *chip = fpa->chips->data[i];139 if (chip == NULL) continue;140 if (chip->data_exists) return true;138 pmChip *chip = fpa->chips->data[i]; 139 if (chip == NULL) continue; 140 if (chip->data_exists) return true; 141 141 } 142 142 return false; … … 170 170 171 171 if (view->chip == -1) { 172 bool exists = pmFPACheckDataStatus (fpa);173 return exists;172 bool exists = pmFPACheckDataStatus (fpa); 173 return exists; 174 174 } 175 175 176 176 if (view->chip >= fpa->chips->n) { 177 psError(PS_ERR_IO, true, "Requested chip == %d >= fpa->chips->n == %ld", view->chip, fpa->chips->n);178 return false;177 psError(PS_ERR_IO, true, "Requested chip == %d >= fpa->chips->n == %ld", view->chip, fpa->chips->n); 178 return false; 179 179 } 180 180 pmChip *chip = fpa->chips->data[view->chip]; 181 181 182 182 if (view->cell == -1) { 183 bool exists = pmChipCheckDataStatus (chip);184 return exists;183 bool exists = pmChipCheckDataStatus (chip); 184 return exists; 185 185 } 186 186 187 187 if (view->cell >= chip->cells->n) { 188 psError(PS_ERR_IO, true, "Requested cell == %d >= chip->cells->n == %ld", view->cell, chip->cells->n);189 return false;188 psError(PS_ERR_IO, true, "Requested cell == %d >= chip->cells->n == %ld", view->cell, chip->cells->n); 189 return false; 190 190 } 191 191 pmCell *cell = chip->cells->data[view->cell]; 192 192 193 193 if (view->readout == -1) { 194 bool exists = pmCellCheckDataStatus (cell);195 return exists;194 bool exists = pmCellCheckDataStatus (cell); 195 return exists; 196 196 } 197 197 198 198 if (view->readout >= cell->readouts->n) { 199 psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouds->n == %ld", view->readout, cell->readouts->n);200 return false;199 psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouds->n == %ld", view->readout, cell->readouts->n); 200 return false; 201 201 } 202 202 pmReadout *readout = cell->readouts->data[view->readout]; … … 290 290 psArray *chips = fpa->chips; // Component chips 291 291 if (chips == NULL) { 292 ps LogMsg(__func__, PS_LOG_WARN,"WARNING: fpa->chips == NULL\n");292 psWarning("WARNING: fpa->chips == NULL\n"); 293 293 return(0); 294 294 } 295 295 if ((chipNum >= chips->n) || (NULL == (pmChip *) chips->data[chipNum])) { 296 ps LogMsg(__func__, PS_LOG_WARN,"WARNING: the specified chip (%d) does not exist.\n", chipNum);296 psWarning("WARNING: the specified chip (%d) does not exist.\n", chipNum); 297 297 return(0); 298 298 } -
branches/eam_branch_20071023/psModules/src/camera/pmFPAMosaic.c
r15288 r15516 704 704 psArray *readouts = cell->readouts; // The array of readouts 705 705 if (readouts->n > 1) { 706 ps LogMsg(__func__, PS_LOG_WARN, "Cell contains more than one readout (%ld) --- only the first will "707 "be mosaicked.\n",readouts->n);706 psWarning("Cell contains more than one readout (%ld) --- only the first will be mosaicked.\n", 707 readouts->n); 708 708 } 709 709 pmReadout *readout = readouts->data[0]; // The only readout we'll bother with … … 754 754 int x0Target = psMetadataLookupS32(&mdok, targetCell->concepts, "CELL.X0"); 755 755 if (!mdok) { 756 ps LogMsg(__func__, PS_LOG_WARN,"CELL.X0 is not set for the target cell; assuming 0.\n");756 psWarning("CELL.X0 is not set for the target cell; assuming 0.\n"); 757 757 FIX_CONCEPT(targetCell->concepts, "CELL.X0", S32, 0); 758 758 } 759 759 int y0Target = psMetadataLookupS32(&mdok, targetCell->concepts, "CELL.Y0"); 760 760 if (!mdok) { 761 ps LogMsg(__func__, PS_LOG_WARN,"CELL.Y0 is not set for the target cell; assuming 0.\n");761 psWarning("CELL.Y0 is not set for the target cell; assuming 0.\n"); 762 762 FIX_CONCEPT(targetCell->concepts, "CELL.Y0", S32, 0); 763 763 } 764 764 int xParityTarget = psMetadataLookupS32(&mdok, targetCell->concepts, "CELL.XPARITY"); 765 765 if (!mdok || (xParityTarget != -1 && xParityTarget != 1)) { 766 ps LogMsg(__func__, PS_LOG_WARN,"CELL.XPARITY is not set for the target cell; assuming 1.\n");766 psWarning("CELL.XPARITY is not set for the target cell; assuming 1.\n"); 767 767 FIX_CONCEPT(targetCell->concepts, "CELL.XPARITY", S32, 1); 768 768 xParityTarget = 1; … … 770 770 int yParityTarget = psMetadataLookupS32(&mdok, targetCell->concepts, "CELL.YPARITY"); 771 771 if (!mdok || (yParityTarget != -1 && yParityTarget != 1)) { 772 ps LogMsg(__func__, PS_LOG_WARN,"CELL.YPARITY is not set for the target cell; assuming 1.\n");772 psWarning("CELL.YPARITY is not set for the target cell; assuming 1.\n"); 773 773 FIX_CONCEPT(targetCell->concepts, "CELL.YPARITY", S32, 1); 774 774 yParityTarget = 1; … … 863 863 int x0Target = psMetadataLookupS32(&mdok, targetChip->concepts, "CHIP.X0"); 864 864 if (!mdok) { 865 ps LogMsg(__func__, PS_LOG_WARN,"CHIP.X0 is not set for the target chip; assuming 0.\n");865 psWarning("CHIP.X0 is not set for the target chip; assuming 0.\n"); 866 866 FIX_CONCEPT(targetChip->concepts, "CHIP.X0", S32, 0); 867 867 } 868 868 int y0Target = psMetadataLookupS32(&mdok, targetChip->concepts, "CHIP.Y0"); 869 869 if (!mdok) { 870 ps LogMsg(__func__, PS_LOG_WARN,"CHIP.Y0 is not set for the target chip; assuming 0.\n");870 psWarning("CHIP.Y0 is not set for the target chip; assuming 0.\n"); 871 871 FIX_CONCEPT(targetChip->concepts, "CHIP.Y0", S32, 0); 872 872 } 873 873 x0Target += psMetadataLookupS32(&mdok, targetCell->concepts, "CELL.X0"); 874 874 if (!mdok) { 875 ps LogMsg(__func__, PS_LOG_WARN,"CELL.X0 is not set for the target cell; assuming 0.\n");875 psWarning("CELL.X0 is not set for the target cell; assuming 0.\n"); 876 876 FIX_CONCEPT(targetCell->concepts, "CELL.X0", S32, 0); 877 877 } 878 878 y0Target += psMetadataLookupS32(&mdok, targetCell->concepts, "CELL.Y0"); 879 879 if (!mdok) { 880 ps LogMsg(__func__, PS_LOG_WARN,"CELL.Y0 is not set for the target cell; assuming 0.\n");880 psWarning("CELL.Y0 is not set for the target cell; assuming 0.\n"); 881 881 FIX_CONCEPT(targetCell->concepts, "CELL.Y0", S32, 0); 882 882 } 883 883 int xParityChipTarget = psMetadataLookupS32(&mdok, targetChip->concepts, "CHIP.XPARITY"); 884 884 if (!mdok || (xParityChipTarget != -1 && xParityChipTarget != 1)) { 885 ps LogMsg(__func__, PS_LOG_WARN,"CHIP.XPARITY is not set for the target chip; assuming 1.\n");885 psWarning("CHIP.XPARITY is not set for the target chip; assuming 1.\n"); 886 886 FIX_CONCEPT(targetChip->concepts, "CHIP.XPARITY", S32, 1); 887 887 xParityChipTarget = 1; … … 889 889 int yParityChipTarget = psMetadataLookupS32(&mdok, targetChip->concepts, "CHIP.YPARITY"); 890 890 if (!mdok || (yParityChipTarget != -1 && yParityChipTarget != 1)) { 891 ps LogMsg(__func__, PS_LOG_WARN,"CHIP.YPARITY is not set for the target chip; assuming 1.\n");891 psWarning("CHIP.YPARITY is not set for the target chip; assuming 1.\n"); 892 892 FIX_CONCEPT(targetChip->concepts, "CHIP.YPARITY", S32, 1); 893 893 yParityChipTarget = 1; … … 895 895 int xParityCellTarget = psMetadataLookupS32(&mdok, targetCell->concepts, "CELL.XPARITY"); 896 896 if (!mdok || (xParityCellTarget != -1 && xParityCellTarget != 1)) { 897 ps LogMsg(__func__, PS_LOG_WARN,"CELL.XPARITY is not set for the target cell; assuming 1.\n");897 psWarning("CELL.XPARITY is not set for the target cell; assuming 1.\n"); 898 898 FIX_CONCEPT(targetCell->concepts, "CELL.XPARITY", S32, 1); 899 899 xParityCellTarget = 1; … … 901 901 int yParityCellTarget = psMetadataLookupS32(&mdok, targetCell->concepts, "CELL.YPARITY"); 902 902 if (!mdok || (yParityCellTarget != -1 && yParityCellTarget != 1)) { 903 ps LogMsg(__func__, PS_LOG_WARN,"CELL.YPARITY is not set for the target cell; assuming 1.\n");903 psWarning("CELL.YPARITY is not set for the target cell; assuming 1.\n"); 904 904 FIX_CONCEPT(targetCell->concepts, "CELL.YPARITY", S32, 1); 905 905 yParityCellTarget = 1; … … 1334 1334 pmHDU *sourceHDU = pmHDUGetHighest(source, firstSourceChip, firstSourceCell); // The HDU for the source 1335 1335 if (!sourceHDU) { 1336 ps LogMsg(__func__, PS_LOG_WARN,"Unable to find HDU in source FPA; unable to copy headers.\n");1336 psWarning("Unable to find HDU in source FPA; unable to copy headers.\n"); 1337 1337 return false; 1338 1338 } 1339 1339 pmHDU *targetHDU = pmHDUGetHighest(target, targetChip, targetCell); // The HDU for the target 1340 1340 if (!targetHDU) { 1341 ps LogMsg(__func__, PS_LOG_WARN,"Unable to find HDU in target FPA; unable to copy headers.\n");1341 psWarning("Unable to find HDU in target FPA; unable to copy headers.\n"); 1342 1342 return false; 1343 1343 } -
branches/eam_branch_20071023/psModules/src/camera/pmHDU.c
r12696 r15516 119 119 120 120 if (*images) { 121 ps LogMsg(__func__, PS_LOG_WARN,"HDU %s has already been read --- overwriting.\n", hdu->extname);121 psWarning("HDU %s has already been read --- overwriting.\n", hdu->extname); 122 122 psFree(*images); // Blow away anything existing 123 123 } … … 167 167 168 168 if (!images && !hdu->header) { 169 ps LogMsg(__func__, PS_LOG_WARN,"Nothing to write for HDU %s\n", hdu->extname);169 psWarning("Nothing to write for HDU %s\n", hdu->extname); 170 170 return false; 171 171 } -
branches/eam_branch_20071023/psModules/src/camera/pmHDUGenerate.c
r15327 r15516 134 134 psMetadataItem *biassecItem = psMetadataLookup(cell->concepts, "CELL.BIASSEC"); // Bias sections 135 135 if (!biassecItem) { 136 psLogMsg(__func__, PS_LOG_WARN, "CELL.BIASSEC has not been initialised in cell --- " 137 "ignored.\n"); 136 psWarning("CELL.BIASSEC has not been initialised in cell --- ignored.\n"); 138 137 return false; 139 138 } … … 146 145 if (!mdok || (cellreaddir != 1 && cellreaddir != 2)) { 147 146 // Probably unnecessary, but just in case.... 148 ps LogMsg(__func__, PS_LOG_WARN,"CELL.READDIR is not set in cell --- ignored.\n");147 psWarning("CELL.READDIR is not set in cell --- ignored.\n"); 149 148 return false; 150 149 } … … 152 151 *readdir = cellreaddir; 153 152 } else if (*readdir != cellreaddir) { 154 ps LogMsg(__func__, PS_LOG_WARN,"CELL.READDIR does not match read direction for HDU --- ignored.\n");153 psWarning("CELL.READDIR does not match read direction for HDU --- ignored.\n"); 155 154 return false; 156 155 } … … 255 254 psMetadataItem *trimsecItem = psMetadataLookup(cell->concepts, "CELL.TRIMSEC"); // Item with trimsec 256 255 if (!trimsecItem || trimsecItem->type != PS_DATA_REGION) { 257 psLogMsg(__func__, PS_LOG_WARN, "CELL.TRIMSEC has not been initialised in cell --- " 258 "ignored.\n"); 256 psWarning("CELL.TRIMSEC has not been initialised in cell --- ignored.\n"); 259 257 continue; 260 258 } … … 264 262 if (!mdok || (cellreaddir != 1 && cellreaddir != 2)) { 265 263 // Probably unnecessary, but just in case.... 266 ps LogMsg(__func__, PS_LOG_WARN,"CELL.READDIR is not set in cell --- ignored.\n");264 psWarning("CELL.READDIR is not set in cell --- ignored.\n"); 267 265 continue; 268 266 } … … 270 268 readdir = cellreaddir; 271 269 } else if (readdir != cellreaddir) { 272 ps LogMsg(__func__, PS_LOG_WARN,"CELL.READDIR for cells within the HDU do not match!\n");270 psWarning("CELL.READDIR for cells within the HDU do not match!\n"); 273 271 cellreaddir = readdir; 274 272 } … … 282 280 if (readout->mask && 283 281 (readout->mask->numCols != image->numCols || readout->mask->numRows != image->numRows)) { 284 ps LogMsg(__func__, PS_LOG_WARN,"Image and mask have different sizes (%dx%d vs %dx%d)!\n",282 psWarning("Image and mask have different sizes (%dx%d vs %dx%d)!\n", 285 283 image->numCols, image->numRows, readout->mask->numCols, readout->mask->numRows); 286 284 } 287 285 if (readout->weight && 288 286 (readout->weight->numCols != image->numCols || readout->weight->numRows != image->numRows)) { 289 ps LogMsg(__func__, PS_LOG_WARN,"Image and weight have different sizes (%dx%d vs %dx%d)!\n",287 psWarning("Image and weight have different sizes (%dx%d vs %dx%d)!\n", 290 288 image->numCols, image->numRows, readout->weight->numCols, readout->weight->numRows); 291 289 } … … 318 316 319 317 if (previous != current) { 320 ps LogMsg(__func__, PS_LOG_WARN, "Images within the HDU are of different types "321 "(%x vs %x) --- promoting\n",previous, current);318 psWarning("Images within the HDU are of different types (%x vs %x) --- promoting\n", 319 previous, current); 322 320 return PS_MAX(previous, current); 323 321 } … … 336 334 if (source->numCols != region->x1 - region->x0 || source->numRows != region->y1 - region->y0) { 337 335 psString regionString = psRegionToString(*region); 338 ps LogMsg(__func__, PS_LOG_WARN,"Image size (%dx%d) does not match region (%s).\n",336 psWarning("Image size (%dx%d) does not match region (%s).\n", 339 337 source->numCols, source->numRows, regionString); 340 338 psFree(regionString); … … 475 473 476 474 if (biassecs->n != readout->bias->n) { 477 ps LogMsg(__func__, PS_LOG_WARN, "Number of bias sections (%ld) and number of biases (%ld)"478 " do not match.\n",biassecs->n, readout->bias->n);475 psWarning("Number of bias sections (%ld) and number of biases (%ld) do not match.\n", 476 biassecs->n, readout->bias->n); 479 477 } 480 478 psListIterator *biasIter = psListIteratorAlloc(readout->bias, PS_LIST_HEAD, false); // Iteratr -
branches/eam_branch_20071023/psModules/src/camera/pmReadoutFake.c
r15399 r15516 35 35 pmReadout *readout = pmReadoutAlloc(NULL); // Output readout 36 36 readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32); 37 psImageInit(readout->image, 0); 37 38 38 39 int numSources = sources->n; // Number of stars … … 86 87 fakeModel->params->data.F32[PM_PAR_I0] = powf(10.0, -0.4 * source->psfMag) / flux0; 87 88 89 psTrace("psModules.camera", 10, "Adding source at %f,%f with flux %f\n", 90 fakeModel->params->data.F32[PM_PAR_XPOS], fakeModel->params->data.F32[PM_PAR_YPOS], 91 fakeModel->params->data.F32[PM_PAR_I0]); 92 88 93 pmSource *fakeSource = pmSourceAlloc(); // Fake source to generate 89 94 fakeSource->peak = pmPeakAlloc(x, y, fakeModel->params->data.F32[PM_PAR_I0], PM_PEAK_LONE); -
branches/eam_branch_20071023/psModules/src/concepts/pmConceptsAverage.h
r15399 r15516 4 4 * @author Paul Price, IfA 5 5 * 6 * @version $Revision: 1.9.10. 1$ $Name: not supported by cvs2svn $7 * @date $Date: 2007-1 0-29 01:40:54 $6 * @version $Revision: 1.9.10.2 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2007-11-08 22:59:04 $ 8 8 * Copyright 2005-2006 Institute for Astronomy, University of Hawaii 9 9 */ -
branches/eam_branch_20071023/psModules/src/concepts/pmConceptsStandard.c
r15300 r15516 375 375 assert(pattern); 376 376 377 psList *biassecs ; // List of bias sections377 psList *biassecs = NULL; // List of bias sections 378 378 379 379 switch (concept->type) { -
branches/eam_branch_20071023/psModules/src/config/pmConfig.c
r15399 r15516 661 661 if (!cameraReadFormats(item->data.md, item->name)) { 662 662 psWarning("Unable to read formats for camera %s: removed.\n", item->name); 663 psErrorStackPrint(stderr, "errors from read failure\n"); 664 psErrorClear(); 663 665 psMetadataRemoveKey(cameras, item->name); 666 continue; 664 667 } 665 668 if (!cameraReadCalibrations(item->data.md, item->name)) { 666 669 psWarning("Unable to read calibrations for camera %s: removed.\n", item->name); 670 psErrorStackPrint(stderr, "errors from read failure\n"); 671 psErrorClear(); 667 672 psMetadataRemoveKey(cameras, item->name); 673 continue; 668 674 } 669 675 } -
branches/eam_branch_20071023/psModules/src/config/pmConfig.h
r15399 r15516 5 5 * @author Eugene Magnier, IfA 6 6 * 7 * @version $Revision: 1.31.2. 1$ $Name: not supported by cvs2svn $8 * @date $Date: 2007-1 0-29 01:40:54 $7 * @version $Revision: 1.31.2.2 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2007-11-08 22:59:04 $ 9 9 * 10 10 * Copyright 2005-2006 Institute for Astronomy, University of Hawaii -
branches/eam_branch_20071023/psModules/src/config/pmConfigCamera.c
r15289 r15516 464 464 while ((formatsItem = psMetadataGetAndIncrement(formatsIter))) { 465 465 assert(formatsItem->type == PS_DATA_METADATA); // We should have read it by now! 466 psMetadata *format = formatsItem->data. V; // The camera format466 psMetadata *format = formatsItem->data.md; // The camera format 467 467 468 468 // Add a new RULE which uniquely describes the mosaicked format. this is needed so -
branches/eam_branch_20071023/psModules/src/config/pmConfigRecipes.c
r12916 r15516 5 5 #include <stdio.h> 6 6 #include <string.h> 7 #include <strings.h> /* for strn?casecmp */7 #include <strings.h> /* for strn?casecmp */ 8 8 #include <unistd.h> 9 9 #include <libgen.h> … … 33 33 options = psMetadataAlloc (); 34 34 success = psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "OPTIONS", PS_DATA_METADATA, "", options); 35 assert (success); // type mismatch : OPTIONS already defined but wrong type36 psFree (options); // drop extra reference35 assert (success); // type mismatch : OPTIONS already defined but wrong type 36 psFree (options); // drop extra reference 37 37 } 38 38 … … 44 44 recipe = psMetadataAlloc(); 45 45 success = psMetadataAddPtr(options, PS_LIST_TAIL, recipeName, PS_DATA_METADATA, "", recipe); 46 assert (success); // type mismatch : OPTIONS already defined but wrong type47 psFree (recipe); // drop extra reference46 assert (success); // type mismatch : OPTIONS already defined but wrong type 47 psFree (recipe); // drop extra reference 48 48 } 49 49 return recipe; … … 67 67 // master recipe files in the site:recipe location when they are built. 68 68 if (config->site && (source & PM_RECIPE_SOURCE_SITE)) { 69 if (!loadRecipeSite(&status, config, config->site)) {69 if (!loadRecipeSite(&status, config, config->site)) { 70 70 psError(PS_ERR_IO, false, "Failed to read recipes from site config"); 71 return false;72 } 73 psTrace ("psModules.config", 3, "read recipes from site config");71 return false; 72 } 73 psTrace ("psModules.config", 3, "read recipes from site config"); 74 74 } 75 75 … … 81 81 if (!loadRecipeCamera(&status, config, config->camera)) { 82 82 psError(PS_ERR_IO, false, "Failed to read recipes from camera config"); 83 return false;84 } 85 if (status) {86 psTrace ("psModules.config", 3, "read recipes from camera config");87 } else {88 psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied by camera config");89 }83 return false; 84 } 85 if (status) { 86 psTrace ("psModules.config", 3, "read recipes from camera config"); 87 } else { 88 psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied by camera config"); 89 } 90 90 } 91 91 … … 94 94 if (!loadRecipeFromArguments(&status, config)) { 95 95 psError(PS_ERR_IO, false, "Failed to read recipes from command-line arguments"); 96 return false;97 } 98 if (status) {99 psTrace ("psModules.config", 3, "read recipes from command-line arguments");100 } else {101 psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied on command-line arguments");102 }96 return false; 97 } 98 if (status) { 99 psTrace ("psModules.config", 3, "read recipes from command-line arguments"); 100 } else { 101 psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied on command-line arguments"); 102 } 103 103 if (!loadRecipeSymbols(&status, config)) { 104 104 psError(PS_ERR_IO, false, "Failed to read recipes from symbolic references"); 105 return false;106 } 107 if (status) {108 psTrace ("psModules.config", 3, "read recipes from symbolic references");109 } else {110 psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied by symbolic reference");111 }105 return false; 106 } 107 if (status) { 108 psTrace ("psModules.config", 3, "read recipes from symbolic references"); 109 } else { 110 psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied by symbolic reference"); 111 } 112 112 if (!loadRecipeOptions(&status, config)) { 113 113 psError(PS_ERR_IO, false, "Failed to read recipes from symbolic references"); 114 return false;115 } 116 if (status) {114 return false; 115 } 116 if (status) { 117 117 psTrace ("psModules.config", 3, "read recipes from command-line arguments"); 118 118 } else { … … 135 135 options = psMetadataAlloc(); 136 136 success = psMetadataAddPtr(config->arguments, PS_LIST_TAIL, "OPTIONS", PS_DATA_METADATA, "Command-line options specified with -D", options); 137 assert (success); // type mismatch : OPTIONS already defined but wrong type138 psFree (options); // drop extra reference137 assert (success); // type mismatch : OPTIONS already defined but wrong type 138 psFree (options); // drop extra reference 139 139 } 140 140 … … 176 176 recipe = psMetadataAlloc(); 177 177 success = psMetadataAddPtr(options, PS_LIST_TAIL, recipeName, PS_DATA_METADATA, "", recipe); 178 assert (success); // type mismatch : recipe already defined but wrong type179 psFree (recipe); // drop extra reference178 assert (success); // type mismatch : recipe already defined but wrong type 179 psFree (recipe); // drop extra reference 180 180 } 181 181 … … 216 216 bool pmConfigLoadRecipeArguments (int *argc, char **argv, pmConfig *config) 217 217 { 218 bool success; 218 bool success; 219 219 220 220 psMetadata *recipes = psMetadataLookupMetadata(&success, config->arguments, "RECIPES"); … … 222 222 recipes = psMetadataAlloc(); 223 223 success = psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "RECIPES", PS_DATA_METADATA, "", recipes); 224 assert (success);225 psFree (recipes);224 assert (success); 225 psFree (recipes); 226 226 } 227 227 … … 271 271 // Load the recipe files for SITE : REQUIRED 272 272 static bool loadRecipeSite(bool *status, 273 pmConfig *config, // The configuration into which to read the recipes274 psMetadata *source // The source configuration, from which to read the filenames273 pmConfig *config, // The configuration into which to read the recipes 274 psMetadata *source // The source configuration, from which to read the filenames 275 275 ) 276 276 { … … 300 300 if (fileItem->type != PS_DATA_STRING) { 301 301 psError(PS_ERR_IO, true, "%s in site configuration RECIPES is not of type STR", fileItem->name); 302 return false;302 return false; 303 303 } 304 304 305 305 // Read the recipe file. if we fail on a file, give a warning, but continue 306 306 psMetadata *recipe = NULL; 307 if (!pmConfigFileRead(&recipe, fileItem->data.V, "recipe")) { 308 psError(PS_ERR_IO, false, "Failed to read recipe file %s listed in site configuration\n", (char *)fileItem->data.V); 309 return false; 307 if (!pmConfigFileRead(&recipe, fileItem->data.str, "recipe")) { 308 psError(PS_ERR_IO, false, "Failed to read recipe file %s listed in site configuration\n", 309 fileItem->data.str); 310 return false; 310 311 } 311 312 312 313 // if this named recipe exists, supplement it 313 psMetadataAdd(config->recipes, PS_LIST_TAIL, fileItem->name, PS_DATA_METADATA | PS_META_REPLACE,314 fileItem->comment, recipe);314 psMetadataAdd(config->recipes, PS_LIST_TAIL, fileItem->name, PS_DATA_METADATA | PS_META_REPLACE, 315 fileItem->comment, recipe); 315 316 psFree(recipe); // Drop reference 316 317 } … … 326 327 // for sourceType == SITE | CAMERA, RECIPES contains a list of files to be read (pmConfigFileRead) 327 328 static bool loadRecipeCamera(bool *status, // status variable 328 pmConfig *config, // The configuration into which to read the recipes329 psMetadata *source // The source configuration, from which to read the filenames329 pmConfig *config, // The configuration into which to read the recipes 330 psMetadata *source // The source configuration, from which to read the filenames 330 331 ) 331 332 { … … 345 346 psMetadata *recipes = psMetadataLookupMetadata(&success, source, "RECIPES"); // The list of recipes 346 347 if (!recipes) { 347 psTrace ("psModules.config", 3, "RECIPES not found in the camera configuration\n");348 psTrace ("psModules.config", 3, "RECIPES not found in the camera configuration\n"); 348 349 return true; 349 350 } … … 355 356 psMetadataItem *fileItem = NULL; // MD item containing the filename, from recipe iteration 356 357 while ((fileItem = psMetadataGetAndIncrement(recipesIter))) { 357 char *recipeName = fileItem->name;358 char *recipeFile = fileItem->data.V;359 360 psTrace("psModules.config", 3, "Supplementing %s from %s within camera configuration.\n", recipeName, recipeFile);358 char *recipeName = fileItem->name; 359 char *recipeFile = fileItem->data.str; 360 361 psTrace("psModules.config", 3, "Supplementing %s from %s within camera configuration.\n", recipeName, recipeFile); 361 362 362 363 // type mismatch is a serious error … … 368 369 psMetadata *recipe = NULL; 369 370 if (!pmConfigFileRead(&recipe, recipeFile, "recipe")) { 370 psError(PS_ERR_IO, false, "Failed to read recipe file %s listed in camera configuration\n", recipeFile); 371 return false; 371 psError(PS_ERR_IO, false, "Failed to read recipe file %s listed in camera configuration\n", 372 recipeFile); 373 return false; 372 374 } 373 375 374 376 // the named recipe must exist; supplement it 375 psMetadata *current = psMetadataLookupMetadata(NULL, config->recipes, recipeName);376 if (!current) {377 psError(PS_ERR_IO, false, "Failed to find recipe for %s in master recipe list", recipeName);378 psFree(recipe); // Drop reference379 return false;380 }381 382 if (!psMetadataUpdate(current, recipe)) {383 psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", recipeName);384 psFree(recipe); // Drop reference385 return false;386 }377 psMetadata *current = psMetadataLookupMetadata(NULL, config->recipes, recipeName); 378 if (!current) { 379 psError(PS_ERR_IO, false, "Failed to find recipe for %s in master recipe list", recipeName); 380 psFree(recipe); // Drop reference 381 return false; 382 } 383 384 if (!psMetadataUpdate(current, recipe)) { 385 psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", recipeName); 386 psFree(recipe); // Drop reference 387 return false; 388 } 387 389 psFree(recipe); // Drop reference 388 390 } … … 397 399 // entries for an existing recipe metadata 398 400 static bool loadRecipeFromArguments(bool *status, 399 pmConfig *config // The configuration into which to read the recipes401 pmConfig *config // The configuration into which to read the recipes 400 402 ) 401 403 { … … 425 427 // increment the ref counter to protect the data 426 428 427 psMetadata *recipe = item->data. V; // Recipe of interest429 psMetadata *recipe = item->data.md; // Recipe of interest 428 430 429 431 // if this named recipe exists, supplement it 430 432 psMetadata *current = psMetadataLookupMetadata(NULL, config->recipes, item->name); 431 433 if (!current) { 432 psError(PS_ERR_IO, false, "Failed to find recipe for %s in master recipe list", item->name);433 psFree(recipe); // Drop reference434 return false;435 }436 psTrace("psModules.config", 3, "Supplementing %s from arguments.\n", item->name);434 psError(PS_ERR_IO, false, "Failed to find recipe for %s in master recipe list", item->name); 435 psFree(recipe); // Drop reference 436 return false; 437 } 438 psTrace("psModules.config", 3, "Supplementing %s from arguments.\n", item->name); 437 439 438 440 if (!psMetadataUpdate (current, recipe)) { 439 psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", item->name);440 return false;441 }441 psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", item->name); 442 return false; 443 } 442 444 } 443 445 psFree(recipesIter); … … 449 451 // entries for an existing recipe metadata 450 452 static bool loadRecipeSymbols(bool *status, 451 pmConfig *config // The configuration into which to read the recipes453 pmConfig *config // The configuration into which to read the recipes 452 454 ) 453 455 { … … 465 467 while ((item = psMetadataGetAndIncrement(iter))) { 466 468 assert(item->type == PS_DATA_STRING); // It should be this type: we put it in ourselves 467 const char *sourceName = item->data. V; // The name of the symbolic reference469 const char *sourceName = item->data.str; // The name of the symbolic reference 468 470 const char *targetName = item->name; 469 psTrace("psModules.config", 3, "Supplementing %s from %s.\n", targetName, sourceName);470 471 // the target recipe must exist; select it472 psMetadata *targetMD = psMetadataLookupMetadata(&found, config->recipes, targetName);473 if (!targetMD) {474 psError(PS_ERR_IO, true, "Failed to find recipe for %s in master recipe list", targetName);475 return false;476 }471 psTrace("psModules.config", 3, "Supplementing %s from %s.\n", targetName, sourceName); 472 473 // the target recipe must exist; select it 474 psMetadata *targetMD = psMetadataLookupMetadata(&found, config->recipes, targetName); 475 if (!targetMD) { 476 psError(PS_ERR_IO, true, "Failed to find recipe for %s in master recipe list", targetName); 477 return false; 478 } 477 479 478 480 // search for sourceName : it may be in config->recipes or target MD 479 481 psMetadata *sourceMD = NULL; 480 sourceMD = psMetadataLookupMetadata(&found, config->recipes, sourceName);482 sourceMD = psMetadataLookupMetadata(&found, config->recipes, sourceName); 481 483 if (!sourceMD) { 482 sourceMD = psMetadataLookupMetadata(&found, targetMD, sourceName);483 if (!sourceMD) {484 psError(PS_ERR_IO, false, "Selected symbolic name %s does not exist in recipes", sourceName);485 return false;486 }487 }488 489 if (!psMetadataUpdate(targetMD, sourceMD)) {490 psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", targetName);491 return false;492 }484 sourceMD = psMetadataLookupMetadata(&found, targetMD, sourceName); 485 if (!sourceMD) { 486 psError(PS_ERR_IO, false, "Selected symbolic name %s does not exist in recipes", sourceName); 487 return false; 488 } 489 } 490 491 if (!psMetadataUpdate(targetMD, sourceMD)) { 492 psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", targetName); 493 return false; 494 } 493 495 } 494 496 psFree(iter); … … 501 503 // entries for an existing recipe metadata 502 504 static bool loadRecipeOptions(bool *status, 503 pmConfig *config // The configuration into which to read the recipes505 pmConfig *config // The configuration into which to read the recipes 504 506 ) 505 507 { … … 524 526 psMetadataItem *item = NULL; // MD item containing the filename, from recipe iteration 525 527 while ((item = psMetadataGetAndIncrement(recipesIter))) { 526 char *recipeName = item->name;527 psMetadata *recipe = item->data. V;528 char *recipeName = item->name; 529 psMetadata *recipe = item->data.md; 528 530 529 531 // type mismatch is a serious error … … 535 537 psMetadata *current = psMetadataLookupMetadata(NULL, config->recipes, recipeName); 536 538 if (!current) { 537 psError(PS_ERR_IO, false, "Selected recipe %s is not found in camera recipe", recipeName);538 return false;539 }539 psError(PS_ERR_IO, false, "Selected recipe %s is not found in camera recipe", recipeName); 540 return false; 541 } 540 542 if (!psMetadataUpdate (current, recipe)) { 541 psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", recipeName);542 return false;543 }543 psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", recipeName); 544 return false; 545 } 544 546 } 545 547 psFree(recipesIter); -
branches/eam_branch_20071023/psModules/src/imcombine/pmReadoutCombine.c
r14355 r15516 315 315 // Combination 316 316 if (!psVectorStats(stats, pixels, errors, mask, 1)) { 317 psError(PS_ERR_UNKNOWN, false, "Error in statistics."); 318 psFree(index); 319 psFree(pixels); 320 psFree(mask); 321 psFree(weights); 322 psFree(errors); 323 psFree(stats); 324 psFree(invScale); 325 return false; 326 } 327 328 outputImage[yOut][xOut] = psStatsGetValue(stats, params->combine); 329 if (!isfinite(outputImage[yOut][xOut])) { 317 // Can't do much about it, but it's not worth worrying about 318 psErrorClear(); 319 outputImage[yOut][xOut] = NAN; 330 320 outputMask[yOut][xOut] = params->blank; 331 } 332 if (params->weights) { 333 float stdev = psStatsGetValue(stats, combineStdev); 334 outputWeight[yOut][xOut] = PS_SQR(stdev); // Variance 335 // XXXX this is not the correct formal error. 336 // also, the weighted mean is not obviously the correct thing here 321 if (params->weights) { 322 outputWeight[yOut][xOut] = NAN; 323 } 324 } else { 325 outputImage[yOut][xOut] = psStatsGetValue(stats, params->combine); 326 if (!isfinite(outputImage[yOut][xOut])) { 327 outputMask[yOut][xOut] = params->blank; 328 } 329 if (params->weights) { 330 float stdev = psStatsGetValue(stats, combineStdev); 331 outputWeight[yOut][xOut] = PS_SQR(stdev); // Variance 332 // XXXX this is not the correct formal error. 333 // also, the weighted mean is not obviously the correct thing here 334 } 337 335 } 338 336 } -
branches/eam_branch_20071023/psModules/src/imcombine/pmStack.c
r15399 r15516 8 8 * @author GLG, MHPCC 9 9 * 10 * @version $Revision: 1.13.8. 1$ $Name: not supported by cvs2svn $11 * @date $Date: 2007-1 0-29 01:40:54 $10 * @version $Revision: 1.13.8.2 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2007-11-08 22:59:04 $ 12 12 * 13 13 * Copyright 2004-2007 Institute for Astronomy, University of Hawaii -
branches/eam_branch_20071023/psModules/src/imcombine/pmStackReject.c
r14701 r15516 52 52 53 53 // Convolve the image with the kernel --- we're basically applying a matched filter and then thresholding 54 psImage *convolved = NULL; // Convolved image 54 pmReadout *convRO = pmReadoutAlloc(NULL); // Readout with convolved image 55 pmReadout *inRO = pmReadoutAlloc(NULL); // Readout with input image 56 inRO->image = image; 55 57 for (int i = 0; i < numRegions; i++) { 56 58 psRegion *region = regions->data[i]; // Region of interest 57 59 psVector *solution = solutions->data[i]; // Solution of interest 58 if (!pmSubtractionConvolve( &convolved, NULL, NULL, image, NULL, NULL, 0,59 region, solution, kernels, true)) {60 if (!pmSubtractionConvolve(convRO, inRO, NULL, NULL, 0, region, solution, kernels, 61 PM_SUBTRACTION_MODE_1, true)) { 60 62 psError(PS_ERR_UNKNOWN, false, "Unable to convolve mask image in region %d.", i); 61 psFree(conv olved);62 psFree(i mage);63 psFree(convRO); 64 psFree(inRO); 63 65 return NULL; 64 66 } … … 73 75 if (!kernel) { 74 76 psError(PS_ERR_UNKNOWN, false, "Unable to generate kernel image."); 75 psFree(conv olved);76 psFree(i mage);77 psFree(convRO); 78 psFree(inRO); 77 79 return NULL; 78 80 } … … 85 87 psFree(kernel); 86 88 87 psImage *subConv = psImageSubset(conv olved, *region); // Sub-image of convolved image89 psImage *subConv = psImageSubset(convRO->image, *region); // Sub-image of convolved image 88 90 psBinaryOp(subConv, subConv, "*", psScalarAlloc(1.0 / sum, PS_TYPE_F32)); 89 91 } 90 psFree(image); 92 psFree(inRO); 93 psImage *convolved = psMemIncrRefCounter(convRO->image); 94 psFree(convRO); 91 95 92 96 // Threshold the convolved image -
branches/eam_branch_20071023/psModules/src/imcombine/pmSubtraction.h
r15325 r15516 6 6 * @author GLG, MHPCC 7 7 * 8 * @version $Revision: 1.19 $ $Name: not supported by cvs2svn $9 * @date $Date: 2007-1 0-17 02:45:40$8 * @version $Revision: 1.19.2.1 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-11-08 22:59:04 $ 10 10 * 11 11 * Copyright 2004-207 Institute for Astronomy, University of Hawaii … … 16 16 17 17 #include <pslib.h> 18 #include "pmSubtractionKernels.h" 19 #include "pmSubtractionStamps.h" 18 19 #include <pmHDU.h> 20 #include <pmFPA.h> 21 #include <pmSubtractionKernels.h> 22 #include <pmSubtractionStamps.h> 20 23 21 24 /// @addtogroup imcombine Image Combinations 22 25 /// @{ 23 26 27 /// Mask values for the subtraction mask 24 28 typedef enum { 25 PM_SUBTRACTION_MASK_CLEAR = 0x00, // No masking 26 PM_SUBTRACTION_MASK_REF = 0x01, // Reference image is bad 27 PM_SUBTRACTION_MASK_INPUT = 0x02, // Input image is bad 28 PM_SUBTRACTION_MASK_CONVOLVE = 0x04, // If convolved, would be bad 29 PM_SUBTRACTION_MASK_FOOTPRINT = 0x08, // Bad pixel within the stamp footprint 30 PM_SUBTRACTION_MASK_BORDER = 0x10, // Image border 31 PM_SUBTRACTION_MASK_REJ = 0x20, // Previously tried as a stamp, and rejected 29 PM_SUBTRACTION_MASK_CLEAR = 0x00, // No masking 30 PM_SUBTRACTION_MASK_BAD_1 = 0x01, // Image 1 is bad 31 PM_SUBTRACTION_MASK_BAD_2 = 0x02, // Image 2 is bad 32 PM_SUBTRACTION_MASK_CONVOLVE_1 = 0x04, // If image 1 is convolved, would be bad 33 PM_SUBTRACTION_MASK_CONVOLVE_2 = 0x08, // If image 2 is convolved, would be bad 34 PM_SUBTRACTION_MASK_FOOTPRINT_1 = 0x10, // Bad pixel within the stamp footprint of image 1 35 PM_SUBTRACTION_MASK_FOOTPRINT_2 = 0x20, // Bad pixel within the stamp footprint of image 2 36 PM_SUBTRACTION_MASK_BORDER = 0x40, // Image border 37 PM_SUBTRACTION_MASK_REJ = 0x80, // Previously tried as a stamp, and rejected 32 38 } pmSubtractionMasks; 33 39 … … 45 51 bool pmSubtractionConvolveStamp(pmSubtractionStamp *stamp, ///< Stamp to convolve 46 52 const pmSubtractionKernels *kernels, ///< Kernel parameters 47 int footprint ///< Half-size of region over which to calculate equation 53 int footprint, ///< Half-size of region over which to calculate equation 54 pmSubtractionMode mode ///< Mode for subtraction (which to convolve) 48 55 ); 49 56 … … 51 58 bool pmSubtractionCalculateEquation(pmSubtractionStampList *stamps, ///< Stamps 52 59 const pmSubtractionKernels *kernels, ///< Kernel parameters 53 int footprint ///< Half-size of region over which to calculate equation 60 int footprint, ///< Half-size of region over which to calculate equation 61 pmSubtractionMode mode ///< Mode for subtraction (which to convolve) 54 62 ); 55 63 … … 59 67 ); 60 68 69 /// Calculate deviations 70 psVector *pmSubtractionCalculateDeviations(pmSubtractionStampList *stamps, ///< Stamps 71 const psVector *solution, ///< Solution vector 72 int footprint, ///< Half-size of stamp 73 const pmSubtractionKernels *kernels, ///< Kernel parameters 74 pmSubtractionMode mode ///< Mode for subtraction 75 ); 76 61 77 /// Reject stamps 62 78 int pmSubtractionRejectStamps(pmSubtractionStampList *stamps, ///< Stamps 79 const psVector *deviations, ///< Deviations for each stamp 63 80 psImage *subMask, ///< Subtraction mask 64 const psVector *solution, ///< Solution vector65 int footprint, ///< Region to mask if stamp is bad66 81 float sigmaRej, ///< Number of RMS deviations above zero at which to reject 67 const pmSubtractionKernels *kernels ///< Kernel parameters82 int footprint ///< Half-size of stamp 68 83 ); 69 84 … … 81 96 82 97 /// Convolve image in preparation for subtraction 83 bool pmSubtractionConvolve(psImage **outImage, ///< Output image 84 psImage **outWeight, ///< Output weight map (or NULL) 85 psImage **outMask, ///< Output mask (or NULL) 86 const psImage *inImage, ///< Input image 87 const psImage *inWeight, ///< Input weight map (or NULL) 98 bool pmSubtractionConvolve(pmReadout *out, ///< Output image 99 const pmReadout *ro1, // Input image 1 100 const pmReadout *ro2, // Input image 2 88 101 const psImage *subMask, ///< Subtraction mask (or NULL) 89 102 psMaskType blank, ///< Mask value for blank regions … … 91 104 const psVector *solution, ///< The solution vector 92 105 const pmSubtractionKernels *kernels, ///< Kernel parameters 106 pmSubtractionMode mode, ///< Mode for subtraction 93 107 bool useFFT ///< Use Fast Fourier Transform for the convolution? 94 108 ); -
branches/eam_branch_20071023/psModules/src/imcombine/pmSubtractionKernels.c
r15399 r15516 4 4 5 5 #include <stdio.h> 6 #include <string .h>6 #include <strings.h> 7 7 #include <pslib.h> 8 8 … … 488 488 PS_ASSERT_INT_NONNEGATIVE(spatialOrder, NULL); 489 489 PS_ASSERT_INT_NONNEGATIVE(inner, NULL); 490 PS_ASSERT_INT_LESS_THAN (inner, size, NULL);490 PS_ASSERT_INT_LESS_THAN_OR_EQUAL(inner, size, NULL); 491 491 PS_ASSERT_INT_NONNEGATIVE(ringsOrder, NULL); 492 492 … … 572 572 for (int v = -size; v <= size; v++) { 573 573 int v2 = PS_SQR(v); // Square of v 574 float vPoly = power(v, vOrder); // Value of v^vOrder 574 // float vPoly = power(v, vOrder); // Value of v^vOrder 575 float vPoly = powf(v/(float)size, vOrder); // Value of v^vOrder 575 576 576 577 for (int u = -size; u <= size; u++) { … … 578 579 int distance2 = u2 + v2; // Distance from the centre 579 580 if (distance2 > lower2 && distance2 < upper2) { 580 float uPoly = power(u, uOrder); // Value of u^uOrder 581 // float uPoly = power(u, uOrder); // Value of u^uOrder 582 float uPoly = powf(u/(float)size, uOrder); // Value of u^uOrder 581 583 582 584 float polyVal = uPoly * vPoly; // Value of polynomial -
branches/eam_branch_20071023/psModules/src/imcombine/pmSubtractionKernels.h
r14671 r15516 14 14 PM_SUBTRACTION_KERNEL_RINGS, ///< Rings Instead of the Normal Gaussian Subtraction 15 15 } pmSubtractionKernelsType; 16 17 /// Modes --- specifies which image to convolve 18 typedef enum { 19 PM_SUBTRACTION_MODE_ERR, // Error in the mode 20 PM_SUBTRACTION_MODE_TARGET, // Convolve image 1 to match target PSF 21 PM_SUBTRACTION_MODE_1, // Convolve image 1 22 PM_SUBTRACTION_MODE_2, // Convolve image 2 23 PM_SUBTRACTION_MODE_UNSURE, // Not sure yet which image to convolve so try to satisfy both 24 PM_SUBTRACTION_MODE_DUAL, // Dual convolution 25 } pmSubtractionMode; 16 26 17 27 /// Kernels specification -
branches/eam_branch_20071023/psModules/src/imcombine/pmSubtractionMatch.c
r15329 r15516 50 50 51 51 static bool getStamps(pmSubtractionStampList **stamps, // Stamps to read 52 const pmReadout *r eference, // Reference readout53 const pmReadout * input, // Input readout, or NULL to generate fake stamps52 const pmReadout *ro1, // Readout 1 53 const pmReadout *ro2, // Readout 2 54 54 const psImage *subMask, // Mask for subtraction, or NULL 55 55 psImage *weight, // Weight map … … 57 57 float threshold, // Threshold for stamp finding 58 58 float stampSpacing, // Spacing between stamps 59 float targetWidth,// Target width for fake stamps60 59 int size, // Kernel half-size 61 int footprint // Convolution footprint for stamps 60 int footprint, // Convolution footprint for stamps 61 pmSubtractionMode mode // Mode for subtraction 62 62 ) 63 63 { 64 64 psTrace("psModules.imcombine", 3, "Finding stamps...\n"); 65 *stamps = pmSubtractionStampsFind(*stamps, r eference->image, subMask, region, threshold, stampSpacing);65 *stamps = pmSubtractionStampsFind(*stamps, ro1->image, subMask, region, threshold, stampSpacing, mode); 66 66 if (!*stamps) { 67 67 psError(PS_ERR_UNKNOWN, false, "Unable to find stamps."); … … 71 71 memCheck(" find stamps"); 72 72 73 if (!input && !pmSubtractionStampsGenerate(*stamps, targetWidth, footprint, size)) {74 psError(PS_ERR_UNKNOWN, false, "Unable to generate target stamps.");75 return false;76 }77 78 memCheck(" generate stamps");79 80 73 psTrace("psModules.imcombine", 3, "Extracting stamps...\n"); 81 if (!pmSubtractionStampsExtract(*stamps, reference->image, input ? input->image : NULL, 82 weight, footprint, size)) { 74 if (!pmSubtractionStampsExtract(*stamps, ro1->image, ro2 ? ro2->image : NULL, weight, footprint, size)) { 83 75 psError(PS_ERR_UNKNOWN, false, "Unable to extract stamps."); 84 76 return false; … … 94 86 95 87 96 bool pmSubtractionMatch(pmReadout *convolved, const pmReadout *r eference, const pmReadout *input,88 bool pmSubtractionMatch(pmReadout *convolved, const pmReadout *ro1, const pmReadout *ro2, 97 89 int footprint, float regionSize, float stampSpacing, float threshold, 98 const psArray *sources, const char *stampsName, float targetWidth,90 const psArray *sources, const char *stampsName, 99 91 pmSubtractionKernelsType type, int size, int spatialOrder, 100 92 const psVector *isisWidths, const psVector *isisOrders, 101 93 int inner, int ringsOrder, int binning, bool optimum, const psVector *optFWHMs, 102 94 int optOrder, float optThreshold, int iter, float rej, psMaskType maskBad, 103 psMaskType maskBlank, float badFrac )95 psMaskType maskBlank, float badFrac, pmSubtractionMode mode) 104 96 { 105 97 PS_ASSERT_PTR_NON_NULL(convolved, false); 106 PS_ASSERT_PTR_NON_NULL(r eference, false);107 PS_ASSERT_IMAGE_NON_NULL(r eference->image, false);108 PS_ASSERT_IMAGE_TYPE(r eference->image, PS_TYPE_F32, false);109 if (r eference->mask) {110 PS_ASSERT_IMAGE_NON_NULL(r eference->mask, false);111 PS_ASSERT_IMAGE_TYPE(r eference->mask, PS_TYPE_MASK, false);112 PS_ASSERT_IMAGES_SIZE_EQUAL(r eference->mask, reference->image, false);113 } 114 if (r eference->weight) {115 PS_ASSERT_IMAGE_NON_NULL(r eference->weight, false);116 PS_ASSERT_IMAGE_TYPE(r eference->weight, PS_TYPE_F32, false);117 PS_ASSERT_IMAGES_SIZE_EQUAL(r eference->weight, reference->image, false);118 } 119 if ( input) {120 PS_ASSERT_IMAGE_NON_NULL( input->image, false);121 PS_ASSERT_IMAGE_TYPE( input->image, PS_TYPE_F32, false);122 PS_ASSERT_IMAGES_SIZE_EQUAL( input->image, reference->image, false);123 if ( input->mask) {124 PS_ASSERT_IMAGE_NON_NULL( input->mask, false);125 PS_ASSERT_IMAGE_TYPE( input->mask, PS_TYPE_MASK, false);126 PS_ASSERT_IMAGES_SIZE_EQUAL( input->mask, reference->image, false);127 } 128 if ( input->weight) {129 PS_ASSERT_IMAGE_NON_NULL( input->weight, false);130 PS_ASSERT_IMAGE_TYPE( input->weight, PS_TYPE_F32, false);131 PS_ASSERT_IMAGES_SIZE_EQUAL( input->weight, reference->image, false);98 PS_ASSERT_PTR_NON_NULL(ro1, false); 99 PS_ASSERT_IMAGE_NON_NULL(ro1->image, false); 100 PS_ASSERT_IMAGE_TYPE(ro1->image, PS_TYPE_F32, false); 101 if (ro1->mask) { 102 PS_ASSERT_IMAGE_NON_NULL(ro1->mask, false); 103 PS_ASSERT_IMAGE_TYPE(ro1->mask, PS_TYPE_MASK, false); 104 PS_ASSERT_IMAGES_SIZE_EQUAL(ro1->mask, ro1->image, false); 105 } 106 if (ro1->weight) { 107 PS_ASSERT_IMAGE_NON_NULL(ro1->weight, false); 108 PS_ASSERT_IMAGE_TYPE(ro1->weight, PS_TYPE_F32, false); 109 PS_ASSERT_IMAGES_SIZE_EQUAL(ro1->weight, ro1->image, false); 110 } 111 if (ro2) { 112 PS_ASSERT_IMAGE_NON_NULL(ro2->image, false); 113 PS_ASSERT_IMAGE_TYPE(ro2->image, PS_TYPE_F32, false); 114 PS_ASSERT_IMAGES_SIZE_EQUAL(ro2->image, ro1->image, false); 115 if (ro2->mask) { 116 PS_ASSERT_IMAGE_NON_NULL(ro2->mask, false); 117 PS_ASSERT_IMAGE_TYPE(ro2->mask, PS_TYPE_MASK, false); 118 PS_ASSERT_IMAGES_SIZE_EQUAL(ro2->mask, ro1->image, false); 119 } 120 if (ro2->weight) { 121 PS_ASSERT_IMAGE_NON_NULL(ro2->weight, false); 122 PS_ASSERT_IMAGE_TYPE(ro2->weight, PS_TYPE_F32, false); 123 PS_ASSERT_IMAGES_SIZE_EQUAL(ro2->weight, ro1->image, false); 132 124 } 133 125 } else if (!stampsName && !sources) { … … 144 136 } 145 137 // stampsName may be anything 146 // targetWidth can be just about anything (except maybe negative, but it can be NAN)147 138 // We'll check kernel type when we allocate the kernels 148 139 PS_ASSERT_INT_POSITIVE(size, false); … … 196 187 } 197 188 198 psImage *inImage = NULL, *inMask = NULL; // Input image, mask, weight199 if (input) {200 inImage = input->image;201 inMask = input->mask;202 }203 204 189 // Where does our weight map come from? 205 190 psImage *weight = NULL; // Weight image to use 206 if (input && input->weight) { 207 weight = input->weight; 208 } else if (reference->weight) { 209 weight = reference->weight; 210 } else if (input) { 211 weight = input->image; 191 if (ro1->weight && ro2 && ro2->weight) { 192 weight = (psImage*)psBinaryOp(NULL, ro1->weight, "+", ro2->weight); 193 } else if (ro1->weight) { 194 weight = psMemIncrRefCounter(ro1->weight); 195 } else if (ro2) { 196 if (ro2->weight) { 197 weight = psMemIncrRefCounter(ro2->weight); 198 } else { 199 weight = (psImage*)psBinaryOp(NULL, ro1->image, "+", ro2->image); 200 } 212 201 } else { 213 weight = reference->image;202 weight = psMemIncrRefCounter(ro1->image); 214 203 } 215 204 … … 221 210 psVector *solution = NULL; // Solution to match PSF 222 211 pmSubtractionKernels *kernels = NULL; // Kernel basis functions 223 224 int numCols = reference->image->numCols, numRows = reference->image->numRows; // Image dimensions 212 int numCols = ro1->image->numCols, numRows = ro1->image->numRows; // Image dimensions 225 213 226 214 memCheck("start"); 227 215 228 subMask = pmSubtractionMask(reference->mask, inMask, maskBad, size, footprint, badFrac, useFFT); 216 subMask = pmSubtractionMask(ro1->mask, ro2 ? ro2->mask : NULL, maskBad, size, footprint, 217 badFrac, useFFT); 229 218 if (!subMask) { 230 219 psError(PS_ERR_UNKNOWN, false, "Unable to generate subtraction mask."); 220 psFree(weight); 231 221 return false; 232 222 } … … 260 250 261 251 if (sources) { 262 stamps = pmSubtractionStampsSetFromSources(sources, subMask, region, stampSpacing, 263 input ? 0 : 2 * footprint); 252 stamps = pmSubtractionStampsSetFromSources(sources, subMask, region, stampSpacing, mode); 264 253 } else if (stampsName && strlen(stampsName) > 0) { 265 // Read stamps from file 266 psTrace("psModules.imcombine", 3, "Reading stamps from %s...\n", stampsName); 267 const char *stampFormat = input ? "%f %f" : "%f %f %f"; // Format for reading stamp file 268 psArray *stampsData = stampsData = psVectorsReadFromFile(stampsName, stampFormat); 269 psVector *xStamp = NULL, *yStamp = NULL, *fluxStamp = NULL; // Stamp positions and fluxes 270 if (!stampsData) { 271 psError(PS_ERR_IO, false, "Unable to read stamps file %s", stampsName); 272 goto ERROR; 273 } 274 xStamp = stampsData->data[0]; 275 yStamp = stampsData->data[1]; 276 if (!input) { 277 fluxStamp = stampsData->data[2]; 278 } 279 280 // Correct for IRAF/FITS (unit-offset) positions to C (zero-offset) positions 281 psBinaryOp(xStamp, xStamp, "-", psScalarAlloc(1.0, PS_TYPE_F32)); 282 psBinaryOp(yStamp, yStamp, "-", psScalarAlloc(1.0, PS_TYPE_F32)); 283 284 stamps = pmSubtractionStampsSet(xStamp, yStamp, fluxStamp, reference->image, subMask, 285 region, stampSpacing, input ? 0 : footprint + size); 286 psFree(stampsData); 254 stamps = pmSubtractionStampsSetFromFile(stampsName, subMask, region, stampSpacing, mode); 255 } 256 257 // We get the stamps here; we will also attempt to get stamps at the first iteration, but it 258 // doesn't matter. 259 if (!getStamps(&stamps, ro1, ro2, subMask, weight, NULL, threshold, stampSpacing, 260 size, footprint, mode)) { 261 goto MATCH_ERROR; 262 } 263 264 if (mode == PM_SUBTRACTION_MODE_UNSURE || mode == PM_SUBTRACTION_MODE_TARGET) { 265 pmSubtractionMode newMode = pmSubtractionOrder(stamps, footprint); // Subtraction mode 266 switch (newMode) { 267 case PM_SUBTRACTION_MODE_1: 268 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Convolving image 1 to match image 2."); 269 break; 270 case PM_SUBTRACTION_MODE_2: 271 if (mode == PM_SUBTRACTION_MODE_TARGET) { 272 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 273 "Input PSF is larger than target PSF --- can't match image."); 274 goto MATCH_ERROR; 275 } 276 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Convolving image 2 to match image 1."); 277 break; 278 default: 279 psError(PS_ERR_UNKNOWN, false, "Unable to determine subtraction order."); 280 goto MATCH_ERROR; 281 } 282 mode = newMode; 287 283 } 288 284 289 285 // Define kernel basis functions 290 286 if (optimum && (type == PM_SUBTRACTION_KERNEL_ISIS || type == PM_SUBTRACTION_KERNEL_GUNK)) { 291 if (!getStamps(&stamps, reference, input, subMask, weight, NULL,292 threshold, stampSpacing, targetWidth, size, footprint)) {293 goto ERROR;294 }295 287 kernels = pmSubtractionKernelsOptimumISIS(type, size, inner, spatialOrder, optFWHMs, optOrder, 296 stamps, footprint, optThreshold );288 stamps, footprint, optThreshold, mode); 297 289 if (!kernels) { 298 290 psErrorClear(); … … 314 306 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Iteration %d.", k); 315 307 316 if (!getStamps(&stamps, r eference, input, subMask, weight, region,317 threshold, stampSpacing, targetWidth, size, footprint)) {318 goto ERROR;308 if (!getStamps(&stamps, ro1, ro2, subMask, weight, region, threshold, stampSpacing, 309 size, footprint, mode)) { 310 goto MATCH_ERROR; 319 311 } 320 312 321 313 psTrace("psModules.imcombine", 3, "Calculating equation...\n"); 322 if (!pmSubtractionCalculateEquation(stamps, kernels, footprint )) {314 if (!pmSubtractionCalculateEquation(stamps, kernels, footprint, mode)) { 323 315 psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation."); 324 goto ERROR;316 goto MATCH_ERROR; 325 317 } 326 318 … … 331 323 if (!solution) { 332 324 psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation."); 333 goto ERROR;325 goto MATCH_ERROR; 334 326 } 335 327 336 328 memCheck(" solve equation"); 337 329 330 psVector *deviations = pmSubtractionCalculateDeviations(stamps, solution, footprint, kernels, 331 mode); // Deviations for each stamp 332 if (!deviations) { 333 psError(PS_ERR_UNKNOWN, false, "Unable to calculate deviations."); 334 goto MATCH_ERROR; 335 } 336 337 memCheck(" calculate deviations"); 338 338 339 psTrace("psModules.imcombine", 3, "Rejecting stamps...\n"); 339 numRejected = pmSubtractionRejectStamps(stamps, subMask, solution, footprint, rej, kernels);340 numRejected = pmSubtractionRejectStamps(stamps, deviations, subMask, rej, footprint); 340 341 if (numRejected < 0) { 341 342 psError(PS_ERR_UNKNOWN, false, "Unable to reject stamps."); 342 goto ERROR; 343 } 343 psFree(deviations); 344 goto MATCH_ERROR; 345 } 346 psFree(deviations); 347 344 348 memCheck(" reject stamps"); 345 349 } … … 350 354 if (!solution) { 351 355 psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation."); 352 goto ERROR; 353 } 354 (void)pmSubtractionRejectStamps(stamps, subMask, solution, footprint, NAN, kernels); 356 goto MATCH_ERROR; 357 } 358 psVector *deviations = pmSubtractionCalculateDeviations(stamps, solution, footprint, kernels, 359 mode); // Deviations for each stamp 360 if (!deviations) { 361 psError(PS_ERR_UNKNOWN, false, "Unable to calculate deviations."); 362 goto MATCH_ERROR; 363 } 364 pmSubtractionRejectStamps(stamps, deviations, subMask, NAN, footprint); 365 psFree(deviations); 355 366 } 356 367 psFree(stamps); … … 372 383 psError(PS_ERR_UNKNOWN, false, "Unable to generate kernel image."); 373 384 psFree(convKernels); 374 goto ERROR;385 goto MATCH_ERROR; 375 386 } 376 387 … … 380 391 psFree(kernel); 381 392 psFree(convKernels); 382 goto ERROR;393 goto MATCH_ERROR; 383 394 } 384 395 psFree(kernel); … … 416 427 417 428 psTrace("psModules.imcombine", 2, "Convolving...\n"); 418 if (!pmSubtractionConvolve(&convolved->image, &convolved->weight, &convolved->mask, 419 reference->image, reference->weight, subMask, maskBlank, region, 420 solution, kernels, useFFT)) { 421 psError(PS_ERR_UNKNOWN, false, "Unable to convolve reference image."); 422 goto ERROR; 429 if (!pmSubtractionConvolve(convolved, ro1, ro2, subMask, maskBlank, region, 430 solution, kernels, mode, useFFT)) { 431 psError(PS_ERR_UNKNOWN, false, "Unable to convolve image."); 432 goto MATCH_ERROR; 423 433 } 424 434 psFree(kernels); … … 461 471 psFree(subMask); 462 472 subMask = NULL; 473 psFree(weight); 474 weight = NULL; 463 475 464 476 if (!pmSubtractionBorder(convolved->image, convolved->weight, convolved->mask, size, maskBlank)) { 465 477 psError(PS_ERR_UNKNOWN, false, "Unable to set border of convolved image."); 466 goto ERROR;478 goto MATCH_ERROR; 467 479 } 468 480 … … 472 484 return true; 473 485 474 ERROR:486 MATCH_ERROR: 475 487 psFree(region); 476 488 psFree(regionString); … … 479 491 psFree(stamps); 480 492 psFree(solution); 493 psFree(weight); 481 494 return false; 482 495 } 496 497 // Calculate the second order moments for an image 498 static float subtractionOrderMoment(const psKernel *kernel, // Image for which to measure moments 499 int radius // Maximum radius 500 ) 501 { 502 assert(kernel && kernel->kernel); 503 504 int xMin = PS_MAX(kernel->xMin, -radius), xMax = PS_MIN(kernel->xMax, radius); // Bounds in x 505 int yMin = PS_MAX(kernel->yMin, -radius), yMax = PS_MIN(kernel->yMax, radius); // Bounds in y 506 507 float xCentroid = 0.0, yCentroid = 0.0; // Centroid (first moment) 508 float sum = 0.0; // Sum (zero-th moment) 509 for (int y = yMin; y <= yMax; y++) { 510 for (int x = xMin; x <= xMax; x++) { 511 xCentroid += kernel->kernel[y][x] * x; 512 yCentroid += kernel->kernel[y][x] * y; 513 sum += kernel->kernel[y][x]; 514 } 515 } 516 xCentroid /= sum; 517 yCentroid /= sum; 518 519 float eta20 = 0.0, eta02 = 0.0; // Second moments 520 for (int y = yMin; y <= yMax; y++) { 521 float yDiff = y - yCentroid; 522 for (int x = xMin; x <= xMax; x++) { 523 float xDiff = x - xCentroid; 524 eta20 += PS_SQR(xDiff) * kernel->kernel[y][x]; 525 eta02 += PS_SQR(yDiff) * kernel->kernel[y][x]; 526 } 527 } 528 529 // Normalise to calculate the scale-invariant 530 float sum2 = PS_SQR(sum); 531 eta20 /= sum2; 532 eta02 /= sum2; 533 // eta11 /= sum2; 534 535 return eta20 + eta02; 536 } 537 538 #if 0 539 // Calculate the deviations for a particular subtraction order 540 static psVector *subtractionOrderDeviation(float *sumKernel, // Sum of the kernel 541 pmSubtractionStampList *stamps, // Stamps to convolve 542 const pmSubtractionKernels *kernels, // Kernel basis functions 543 int footprint, // Stamp footprint 544 pmSubtractionMode mode // Mode of subtraction 545 ) 546 { 547 assert(stamps); 548 assert(footprint >= 0); 549 assert(mode == PM_SUBTRACTION_MODE_1 || mode == PM_SUBTRACTION_MODE_2); 550 551 if (!pmSubtractionCalculateEquation(stamps, kernels, footprint, mode)) { 552 psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation."); 553 return NULL; 554 } 555 556 psVector *solution = pmSubtractionSolveEquation(NULL, stamps); 557 if (!solution) { 558 psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation."); 559 return NULL; 560 } 561 562 if (sumKernel) { 563 float sum = 0.0; // Sum of the kernel 564 psImage *image = pmSubtractionKernelImage(solution, kernels, 0.0, 0.0); // Image of kernel 565 for (int y = 0; y < image->numRows; y++) { 566 for (int x = 0; x < image->numCols; x++) { 567 sum += image->data.F32[y][x]; 568 } 569 } 570 psFree(image); 571 *sumKernel = sum; 572 } 573 574 psVector *deviations = pmSubtractionCalculateDeviations(stamps, solution, footprint, kernels, mode); 575 psFree(solution); 576 if (!deviations) { 577 psError(PS_ERR_UNKNOWN, false, "Unable to calculate deviations."); 578 return NULL; 579 } 580 581 return deviations; 582 } 583 #endif 584 585 pmSubtractionMode pmSubtractionOrder(pmSubtractionStampList *stamps, int radius) 586 { 587 PS_ASSERT_INT_POSITIVE(radius, PM_SUBTRACTION_MODE_ERR); 588 589 psVector *mask = psVectorAlloc(stamps->num, PS_TYPE_MASK); // Mask for stamps 590 psVector *moments = psVectorAlloc(stamps->num, PS_TYPE_F32); // Moments 591 for (int i = 0; i < stamps->num; i++) { 592 pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest 593 if (stamp->status != PM_SUBTRACTION_STAMP_CALCULATE && stamp->status != PM_SUBTRACTION_STAMP_USED) { 594 mask->data.PS_TYPE_MASK_DATA[i] = 0xff; 595 continue; 596 } 597 mask->data.PS_TYPE_MASK_DATA[i] = 0; 598 moments->data.F32[i] = subtractionOrderMoment(stamp->image1, radius) / 599 subtractionOrderMoment(stamp->image2, radius); 600 } 601 602 psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN); 603 if (!psVectorStats(stats, moments, NULL, mask, 0xff)) { 604 psError(PS_ERR_UNKNOWN, false, "Unable to calculate statistics for moments ratio."); 605 psFree(mask); 606 psFree(moments); 607 psFree(stats); 608 return PM_SUBTRACTION_MODE_ERR; 609 } 610 psFree(moments); 611 psFree(mask); 612 613 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Median ratio of second moments: %lf", stats->robustMedian); 614 pmSubtractionMode mode = (stats->robustMedian <= 1.0 ? PM_SUBTRACTION_MODE_1 : PM_SUBTRACTION_MODE_2); 615 psFree(stats); 616 617 return mode; 618 } 619 620 621 -
branches/eam_branch_20071023/psModules/src/imcombine/pmSubtractionMatch.h
r15305 r15516 4 4 #include <pslib.h> 5 5 6 #include "pmHDU.h" 7 #include "pmFPA.h" 8 #include "pmSubtractionKernels.h" 6 #include <pmHDU.h> 7 #include <pmFPA.h> 8 #include <pmSubtractionKernels.h> 9 #include <pmSubtractionStamps.h> 9 10 10 11 /// Match two images 11 12 bool pmSubtractionMatch(pmReadout *convolved, ///< Output convolved data 12 const pmReadout *r eference, ///< Reference data13 const pmReadout * input, ///< Input data13 const pmReadout *ro1, ///< Image 1 14 const pmReadout *ro2, ///< Image 2 14 15 // Stamp parameters 15 16 int footprint, ///< Stamp half-size … … 19 20 const psArray *sources, ///< Sources for stamps 20 21 const char *stampsName, ///< Filename for stamps 21 float targetWidth, ///< Width of PSF for simulated target22 22 // Kernel parameters 23 23 pmSubtractionKernelsType type, ///< Kernel type … … 38 38 psMaskType maskBad, ///< Value to mask 39 39 psMaskType maskBlank, ///< Mask for blank region 40 float badFrac ///< Maximum fraction of bad input pixels to accept 40 float badFrac, ///< Maximum fraction of bad input pixels to accept 41 pmSubtractionMode mode ///< Mode of subtraction 41 42 ); 42 43 44 /// Determine which image to convolve 45 pmSubtractionMode pmSubtractionOrder(pmSubtractionStampList *stamps, ///< Stamps that have been extracted 46 int footprint ///< Stamp half-size 47 ); 48 49 43 50 #endif -
branches/eam_branch_20071023/psModules/src/imcombine/pmSubtractionParams.c
r15247 r15516 50 50 #endif 51 51 52 /// Select the appropriate convolution, given the kernel basis function and subtraction mode 53 static inline psKernel *selectConvolution(const pmSubtractionStamp *stamp, // Stamp 54 int kernelIndex, // Index for kernel component 55 pmSubtractionMode mode // Mode of subtraction 56 ) 57 { 58 switch (mode) { 59 case PM_SUBTRACTION_MODE_1: 60 return stamp->convolutions1->data[kernelIndex]; 61 case PM_SUBTRACTION_MODE_2: 62 return stamp->convolutions2->data[kernelIndex]; 63 default: 64 psAbort("Unsupported subtraction mode: %x", mode); 65 } 66 return NULL; // Unreached 67 } 68 52 69 // Accumulate cross-term sums for a stamp 53 70 static void accumulateCross(double *sumI, // Sum of I(x)/sigma(x)^2 … … 55 72 double *sumIC, // Sum of I(x)conv(x)/sigma(x)^2 56 73 const pmSubtractionStamp *stamp, // Stamp with weight 57 const psKernel * input, // Input image, I(x)74 const psKernel *target, // Target stamp 58 75 int kernelIndex, // Index for kernel component 59 int footprint // Size of region of interest 76 int footprint, // Size of region of interest 77 pmSubtractionMode mode // Mode of subtraction 60 78 ) 61 79 { 62 80 psKernel *weight = stamp->weight; // Weight, sigma(x)^2 63 psKernel *convolution = s tamp->convolutions->data[kernelIndex]; // Convolution of interest81 psKernel *convolution = selectConvolution(stamp, kernelIndex, mode); // Convolution of interest 64 82 65 83 for (int y = -footprint; y <= footprint; y++) { 66 psF32 *in = & input->kernel[y][-footprint]; // Dereference input84 psF32 *in = &target->kernel[y][-footprint]; // Dereference input 67 85 psF32 *wt = &weight->kernel[y][-footprint]; // Dereference weight 68 86 psF32 *conv = &convolution->kernel[y][-footprint]; // Dereference convolution … … 82 100 const pmSubtractionStamp *stamp, // Stamp with input and weight 83 101 int kernelIndex, // Index for kernel component 84 int footprint // Size of region of interest 102 int footprint, // Size of region of interest 103 pmSubtractionMode mode // Mode of subtraction 85 104 ) 86 105 { 87 106 psKernel *weight = stamp->weight; // Weight, sigma(x)^2 88 psKernel *convolution = s tamp->convolutions->data[kernelIndex]; // Convolution of interest107 psKernel *convolution = selectConvolution(stamp, kernelIndex, mode); // Convolution of interest 89 108 90 109 for (int y = -footprint; y <= footprint; y++) { … … 100 119 } 101 120 102 static double accumulateChi2( psKernel *input, // Input stamp121 static double accumulateChi2(const psKernel *target, // Target stamp 103 122 pmSubtractionStamp *stamp, // Stamp with weight 104 123 int kernelIndex, // Index for kernel component 105 124 double coeff, // Coefficient of convolution 106 125 double bg, // Background term 107 int footprint // Size of region of interest 126 int footprint, // Size of region of interest 127 pmSubtractionMode mode // Mode of subtraction 108 128 ) 109 129 { 110 130 double chi2 = 0.0; 111 131 psKernel *weight = stamp->weight; // Weight, sigma(x)^2 112 psKernel *convolution = s tamp->convolutions->data[kernelIndex]; // Convolution of interest132 psKernel *convolution = selectConvolution(stamp, kernelIndex, mode); // Convolution of interest 113 133 114 134 for (int y = -footprint; y <= footprint; y++) { 115 psF32 *in = & input->kernel[y][-footprint]; // Dereference input135 psF32 *in = &target->kernel[y][-footprint]; // Dereference input 116 136 psF32 *wt = &weight->kernel[y][-footprint]; // Dereference weight 117 137 psF32 *conv = &convolution->kernel[y][-footprint]; // Dereference convolution … … 125 145 126 146 // Return the initial value of chi^2 127 static double initialChi2( psKernel *input, // Input stamp147 static double initialChi2(const psKernel *target, // Target stamp 128 148 const pmSubtractionStamp *stamp, // Stamp with weight 129 int footprint // Size of convolution 149 int footprint, // Size of convolution 150 pmSubtractionMode mode // Mode of subtraction 130 151 ) 131 152 { 132 153 psKernel *weight = stamp->weight; // Weight map 133 psKernel *reference = stamp->reference; // Reference stamp 154 psKernel *source; // Source stamp 155 switch (mode) { 156 case PM_SUBTRACTION_MODE_1: 157 source = stamp->image1; 158 break; 159 case PM_SUBTRACTION_MODE_2: 160 source = stamp->image2; 161 break; 162 default: 163 psAbort("Unsupported subtraction mode: %x", mode); 164 } 134 165 135 166 double chi2 = 0.0; // Chi^2 136 167 for (int y = -footprint; y <= footprint; y++) { 137 psF32 *in = & input->kernel[y][-footprint]; // Dereference input168 psF32 *in = &target->kernel[y][-footprint]; // Dereference input 138 169 psF32 *wt = &weight->kernel[y][-footprint]; // Dereference weight 139 psF32 *ref = & reference->kernel[y][-footprint]; // Derference reference170 psF32 *ref = &source->kernel[y][-footprint]; // Derference reference 140 171 for (int x = -footprint; x <= footprint; x++, in++, wt++, ref++) { 141 172 float diff = *in - *ref; // Temporary value … … 148 179 149 180 // Subtract a convolution from the input 150 static void subtractConvolution(psKernel * input, // Input stamp181 static void subtractConvolution(psKernel *target, // Target stamp 151 182 const pmSubtractionStamp *stamp, // Stamp with weight 152 183 int kernelIndex, // Index for kernel component 153 184 float coeff, // Coefficient of subtraction 154 185 float bg, // Background term 155 int footprint // Size of region of interest156 )157 { 158 psKernel *convolution = stamp->convolutions->data[kernelIndex]; // Convolution of interest 159 186 int footprint, // Size of region of interest 187 pmSubtractionMode mode // Mode of subtraction 188 ) 189 { 190 psKernel *convolution = selectConvolution(stamp, kernelIndex, mode); // Convolution of interest 160 191 for (int y = -footprint; y <= footprint; y++) { 161 psF32 *in = & input->kernel[y][-footprint]; // Dereference input192 psF32 *in = &target->kernel[y][-footprint]; // Dereference input 162 193 psF32 *conv = &convolution->kernel[y][-footprint]; // Dereference convolution 163 194 for (int x = -footprint; x <= footprint; x++, in++, conv++) { … … 173 204 int spatialOrder, const psVector *fwhms, int maxOrder, 174 205 const pmSubtractionStampList *stamps, int footprint, 175 float tolerance )206 float tolerance, pmSubtractionMode mode) 176 207 { 177 208 if (type != PM_SUBTRACTION_KERNEL_ISIS && type != PM_SUBTRACTION_KERNEL_GUNK) { … … 210 241 // Need to save the stamp inputs --- we're changing the values! 211 242 int numStamps = stamps->num; // Number of stamps 212 psArray * inputs = psArrayAlloc(numStamps); // Deep copies of the inputs243 psArray *targets = psArrayAlloc(numStamps); // Deep copies of the targets 213 244 psVector *badStamps = psVectorAlloc(numStamps, PS_TYPE_U8); // Mark the bad stamps 214 245 psVectorInit(badStamps, 0); … … 219 250 continue; 220 251 } 221 psKernel *input = stamp->input; // Input image of interest 222 psImage *copy = psImageCopy(NULL, input->image, PS_TYPE_F32); // Copy of the image 223 inputs->data[i] = psKernelAllocFromImage(copy, size + footprint, size + footprint); 252 psKernel *target; // Target image of interest 253 switch (mode) { 254 case PM_SUBTRACTION_MODE_1: 255 target = stamp->image2; 256 break; 257 case PM_SUBTRACTION_MODE_2: 258 target = stamp->image1; 259 break; 260 default: 261 psAbort("Unsupported subtraction mode: %x", mode); 262 } 263 psImage *copy = psImageCopy(NULL, target->image, PS_TYPE_F32); // Copy of the image 264 targets->data[i] = psKernelAllocFromImage(copy, size + footprint, size + footprint); 224 265 psFree(copy); // Drop reference 225 266 } … … 238 279 continue; 239 280 } 240 if (!pmSubtractionConvolveStamp(stamp, kernels, footprint )) {281 if (!pmSubtractionConvolveStamp(stamp, kernels, footprint, mode)) { 241 282 psError(PS_ERR_UNKNOWN, false, "Unable to convolve stamp %d.", i); 242 psFree( inputs);283 psFree(targets); 243 284 psFree(kernels); 244 285 psFree(badStamps); … … 258 299 "Sum of 1/sigma^2 is non-finite for stamp %d (%d,%d)\n", 259 300 i, (int)stamp->x, (int)stamp->y); 260 psFree( inputs);301 psFree(targets); 261 302 psFree(kernels); 262 303 psFree(badStamps); … … 265 306 266 307 for (int j = 0; j < numKernels; j++) { 267 accumulateConvolutions(&sumC->data.F64[j], &sumCC->data.F64[j], stamp, j, footprint );268 } 269 270 lastChi2 += initialChi2( inputs->data[i], stamp, footprint);308 accumulateConvolutions(&sumC->data.F64[j], &sumCC->data.F64[j], stamp, j, footprint, mode); 309 } 310 311 lastChi2 += initialChi2(targets->data[i], stamp, footprint, mode); 271 312 numPixels += PS_SQR(2 * footprint + 1); 272 313 } … … 297 338 } 298 339 pmSubtractionStamp *stamp = stamps->stamps->data[j]; // Stamp of interest 299 accumulateCross(&sumI, &sumII, &sumIC, stamp, inputs->data[j], i, footprint);340 accumulateCross(&sumI, &sumII, &sumIC, stamp, targets->data[j], i, footprint, mode); 300 341 } 301 342 … … 310 351 } 311 352 pmSubtractionStamp *stamp = stamps->stamps->data[j]; // Stamp of interest 312 chi2 += accumulateChi2( inputs->data[j], stamp, i, coeff, bg, footprint);353 chi2 += accumulateChi2(targets->data[j], stamp, i, coeff, bg, footprint, mode); 313 354 } 314 355 … … 328 369 if (bestIndex == -1) { 329 370 psError(PS_ERR_UNKNOWN, false, "Unable to find best kernel component in round %d.", iter); 330 psFree( inputs);371 psFree(targets); 331 372 psFree(sumC); 332 373 psFree(sumCC); … … 345 386 } 346 387 pmSubtractionStamp *stamp = stamps->stamps->data[j]; // Stamp of interest 347 subtractConvolution( inputs->data[j], stamp, bestIndex, bestCoeff, bestBG, footprint);388 subtractConvolution(targets->data[j], stamp, bestIndex, bestCoeff, bestBG, footprint, mode); 348 389 } 349 390 … … 361 402 lastChi2 = bestChi2; 362 403 } 363 psFree( inputs);404 psFree(targets); 364 405 psFree(sumC); 365 406 psFree(sumCC); … … 401 442 pmSubtractionStamp *stamp = stamps->stamps->data[j]; // Stamp of interest 402 443 psArray *convolutions = convNew->data[j]; // Convolutions for this stamp 403 convolutions->data[rank] = psMemIncrRefCounter(s tamp->convolutions->data[i]);444 convolutions->data[rank] = psMemIncrRefCounter(selectConvolution(stamp, i, mode)); 404 445 } 405 446 } … … 420 461 } 421 462 pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest 422 psFree(stamp->convolutions); 423 stamp->convolutions = convNew->data[i]; 463 psFree(stamp->convolutions1); 464 psFree(stamp->convolutions2); 465 switch (mode) { 466 case PM_SUBTRACTION_MODE_1: 467 stamp->convolutions1 = convNew->data[i]; 468 stamp->convolutions2 = NULL; 469 break; 470 case PM_SUBTRACTION_MODE_2: 471 stamp->convolutions1 = NULL; 472 stamp->convolutions2 = convNew->data[i]; 473 break; 474 default: 475 psAbort("Unsupported subtraction mode: %x", mode); 476 } 424 477 } 425 478 -
branches/eam_branch_20071023/psModules/src/imcombine/pmSubtractionParams.h
r14804 r15516 15 15 const pmSubtractionStampList *stamps, ///< Stamps 16 16 int footprint, ///< Convolution footprint for stamps 17 float tolerance ///< Maximum difference in chi^2 17 float tolerance, ///< Maximum difference in chi^2 18 pmSubtractionMode mode // Mode for subtraction 18 19 ); 19 20 -
branches/eam_branch_20071023/psModules/src/imcombine/pmSubtractionStamps.c
r15286 r15516 4 4 5 5 #include <stdio.h> 6 #include <string.h> 6 7 #include <pslib.h> 7 8 … … 45 46 psFree(stamp->matrix); 46 47 psFree(stamp->vector); 47 psFree(stamp-> reference);48 psFree(stamp->i nput);48 psFree(stamp->image1); 49 psFree(stamp->image2); 49 50 psFree(stamp->weight); 50 psFree(stamp->convolutions); 51 psFree(stamp->convolutions1); 52 psFree(stamp->convolutions2); 51 53 } 52 54 … … 65 67 // Is this position unmasked? 66 68 static bool checkStampMask(int x, int y, // Coordinates of stamp 67 const psImage *mask 69 const psImage *mask, // Mask 70 pmSubtractionMode mode // Mode for subtraction 68 71 ) 69 72 { … … 74 77 return false; 75 78 } 76 return (mask->data.PS_TYPE_MASK_DATA[y][x] & (PM_SUBTRACTION_MASK_BORDER | 77 PM_SUBTRACTION_MASK_FOOTPRINT | PM_SUBTRACTION_MASK_REJ)) ? 78 false : true; 79 80 psMaskType maskVal = PM_SUBTRACTION_MASK_BORDER | PM_SUBTRACTION_MASK_REJ; // Mask value 81 switch (mode) { 82 case PM_SUBTRACTION_MODE_1: 83 case PM_SUBTRACTION_MODE_TARGET: 84 maskVal |= PM_SUBTRACTION_MASK_FOOTPRINT_1; 85 break; 86 case PM_SUBTRACTION_MODE_2: 87 maskVal |= PM_SUBTRACTION_MASK_FOOTPRINT_2; 88 break; 89 case PM_SUBTRACTION_MODE_UNSURE: 90 case PM_SUBTRACTION_MODE_DUAL: 91 maskVal |= PM_SUBTRACTION_MASK_FOOTPRINT_1 | PM_SUBTRACTION_MASK_FOOTPRINT_2; 92 break; 93 default: 94 psAbort("Unsupported subtraction mode: %x", mode); 95 } 96 97 return (mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal) ? false : true; 79 98 } 80 99 … … 140 159 stamp->status = PM_SUBTRACTION_STAMP_INIT; 141 160 142 stamp-> reference= NULL;143 stamp->i nput= NULL;161 stamp->image1 = NULL; 162 stamp->image2 = NULL; 144 163 stamp->weight = NULL; 145 stamp->convolutions = NULL; 164 stamp->convolutions1 = NULL; 165 stamp->convolutions2 = NULL; 146 166 147 167 return stamp; … … 151 171 pmSubtractionStampList *pmSubtractionStampsFind(pmSubtractionStampList *stamps, const psImage *image, 152 172 const psImage *subMask, const psRegion *region, 153 float threshold, float spacing )173 float threshold, float spacing, pmSubtractionMode mode) 154 174 { 155 175 PS_ASSERT_IMAGE_NON_NULL(image, NULL); … … 226 246 for (int y = subRegion->y0; y <= subRegion->y1 ; y++) { 227 247 for (int x = subRegion->x0; x <= subRegion->y1 ; x++) { 228 if (checkStampMask(x, y, subMask ) && image->data.F32[y][x] > fluxStamp) {248 if (checkStampMask(x, y, subMask, mode) && image->data.F32[y][x] > fluxStamp) { 229 249 fluxStamp = image->data.F32[y][x]; 230 250 xStamp = x; … … 242 262 243 263 // Reset the postage stamps since we're making a new stamp 244 psFree(stamp-> reference);245 psFree(stamp->i nput);264 psFree(stamp->image1); 265 psFree(stamp->image2); 246 266 psFree(stamp->weight); 247 stamp->reference = stamp->input = stamp->weight = NULL; 248 249 stamp->status = PM_SUBTRACTION_STAMP_CALCULATE; 267 psFree(stamp->convolutions1); 268 psFree(stamp->convolutions2); 269 stamp->image1 = stamp->image2 = stamp->weight = NULL; 270 stamp->convolutions1 = stamp->convolutions2 = NULL; 271 272 stamp->status = PM_SUBTRACTION_STAMP_FOUND; 250 273 numFound++; 251 274 psTrace("psModules.imcombine", 5, "Found stamp in subregion %d: %d,%d\n", … … 266 289 pmSubtractionStampList *pmSubtractionStampsSet(const psVector *x, const psVector *y, const psVector *flux, 267 290 const psImage *image, const psImage *subMask, 268 const psRegion *region, float spacing, int exclusionZone) 291 const psRegion *region, float spacing, pmSubtractionMode mode) 292 269 293 { 270 294 PS_ASSERT_VECTOR_NON_NULL(x, NULL); … … 289 313 } 290 314 PS_ASSERT_FLOAT_LARGER_THAN(spacing, 0.0, NULL); 291 PS_ASSERT_INT_NONNEGATIVE(exclusionZone, NULL);292 315 293 316 int numStars = x->n; // Number of stars 294 psVector *exclude = psVectorAlloc(numStars, PS_TYPE_U8); // Exclude a star?295 psVectorInit(exclude, 0);296 297 // Apply exclusion zone around each star --- important when we're convolving to a specified PSF; less so298 // when we're trying to get a good subtraction.299 if (exclusionZone > 0) {300 psTrace("psModules.imcombine", 2, "Applying exclusion zone of %d pixels for stamps\n", exclusionZone);301 // We use something resembling a binary search --- coordinates are sorted in the x dimension, and then302 // to exclude stars within a nominated distance, we need only examine (i.e., calculate the303 // 2-dimensional distance to) other stars in the list that are within that distance of the x304 // coordinate of the star of interest. By marking both stars when we find a violation of the305 // exclusion zone, we need only search upwards from the x coordinate of the star of interest.306 307 int minDistance2 = PS_SQR(exclusionZone); // Minimum square distance for other stars308 psVector *indexes = psVectorSortIndex(NULL, x); // Indices for sorting in x309 for (int i = 0; i < numStars - 1; i++) {310 int iIndex = indexes->data.S32[i]; // Index for star i311 if (exclude->data.U8[iIndex]) {312 continue;313 }314 float ix = x->data.F32[iIndex], iy = y->data.F32[iIndex]; // Coordinates for star i315 float jx, jy; // Coordinates for star j316 for (int j = i + 1, jIndex = indexes->data.S32[j];317 j < numStars && (jx = x->data.F32[jIndex]) < ix + exclusionZone;318 j++, jIndex = indexes->data.S32[j]) {319 jy = y->data.F32[jIndex];320 if (PS_SQR(ix - jx) + PS_SQR(iy - jy) < minDistance2) {321 exclude->data.U8[iIndex] = 0xff;322 exclude->data.U8[jIndex] = 0xff;323 psTrace("psModules.imcombine", 5, "Excluding stamps %d,%d and %d,%d\n",324 (int)x->data.F32[iIndex], (int)y->data.F32[iIndex],325 (int)x->data.F32[jIndex], (int)y->data.F32[jIndex]);326 // Would 'break' here, but there might be more stamps within the exclusion zone.327 }328 }329 }330 psFree(indexes);331 }332 333 317 pmSubtractionStampList *stamps = pmSubtractionStampListAlloc(subMask->numCols, subMask->numRows, 334 318 region, spacing); // Stamp list … … 347 331 // Put the stars into their appropriate subregions 348 332 for (int i = 0; i < numStars; i++) { 349 if (exclude->data.U8[i]) {350 // Star has been excluded351 continue;352 }353 333 float xStamp = x->data.F32[i], yStamp = y->data.F32[i]; // Coordinates of stamp 354 334 int xPix = xStamp + 0.5, yPix = yStamp + 0.5; // Pixel coordinate of stamp … … 357 337 continue; 358 338 } 359 if (!checkStampMask(xPix, yPix, subMask )) {339 if (!checkStampMask(xPix, yPix, subMask, mode)) { 360 340 // Not a good stamp 361 341 continue; … … 386 366 } 387 367 } 388 psFree(exclude);389 368 390 369 // Sort the list by flux, with the brightest last … … 421 400 422 401 423 bool pmSubtractionStampsExtract(pmSubtractionStampList *stamps, psImage * reference, psImage *input,402 bool pmSubtractionStampsExtract(pmSubtractionStampList *stamps, psImage *image1, psImage *image2, 424 403 psImage *weight, int footprint, int kernelSize) 425 404 { 426 405 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, false); 427 PS_ASSERT_IMAGE_NON_NULL(reference, false); 428 PS_ASSERT_IMAGE_TYPE(reference, PS_TYPE_F32, false); 429 if (input) { 430 PS_ASSERT_IMAGE_NON_NULL(input, false); 431 PS_ASSERT_IMAGES_SIZE_EQUAL(input, reference, false); 432 PS_ASSERT_IMAGE_TYPE(input, PS_TYPE_F32, false); 433 } 434 if (weight) { 435 PS_ASSERT_IMAGE_NON_NULL(weight, false); 436 PS_ASSERT_IMAGES_SIZE_EQUAL(weight, reference, false); 437 PS_ASSERT_IMAGE_TYPE(weight, PS_TYPE_F32, false); 438 } 406 PS_ASSERT_IMAGE_NON_NULL(image1, false); 407 PS_ASSERT_IMAGE_TYPE(image1, PS_TYPE_F32, false); 408 if (image2) { 409 PS_ASSERT_IMAGE_NON_NULL(image2, false); 410 PS_ASSERT_IMAGES_SIZE_EQUAL(image2, image1, false); 411 PS_ASSERT_IMAGE_TYPE(image2, PS_TYPE_F32, false); 412 } 413 PS_ASSERT_IMAGE_NON_NULL(weight, false); 414 PS_ASSERT_IMAGES_SIZE_EQUAL(weight, image1, false); 415 PS_ASSERT_IMAGE_TYPE(weight, PS_TYPE_F32, false); 439 416 PS_ASSERT_INT_NONNEGATIVE(footprint, false); 440 417 PS_ASSERT_INT_NONNEGATIVE(kernelSize, false); 441 418 442 int numCols = reference->numCols, numRows = reference->numRows; // Size of images419 int numCols = image1->numCols, numRows = image1->numRows; // Size of images 443 420 int size = kernelSize + footprint; // Size of postage stamps 444 445 if (!weight) {446 // Use the input (or if I must, the reference) as a rough approximation to the variance map, and HOPE447 // that it's positive.448 weight = input ? input : reference;449 }450 421 451 422 for (int i = 0; i < stamps->num; i++) { 452 423 pmSubtractionStamp *stamp = stamps->stamps->data[i]; // Stamp of interest 453 if (!stamp || stamp->status != PM_SUBTRACTION_STAMP_ CALCULATE) {424 if (!stamp || stamp->status != PM_SUBTRACTION_STAMP_FOUND) { 454 425 continue; 455 426 } … … 468 439 } 469 440 441 // Catch memory leaks --- these should have been freed and NULLed before 442 assert(stamp->image1 == NULL); 443 assert(stamp->image2 == NULL); 444 assert(stamp->weight == NULL); 445 470 446 psRegion region = psRegionSet(x - size, x + size + 1, y - size, y + size + 1); // Region of interest 471 447 472 psImage * refSub = psImageSubset(reference, region); // Subimage with stamp473 stamp-> reference = psKernelAllocFromImage(refSub, size, size);474 psFree( refSub);// Drop reference475 476 if (i nput) {477 psImage * inSub = psImageSubset(input, region); // Subimage with stamp478 stamp->i nput = psKernelAllocFromImage(inSub, size, size);479 psFree( inSub);// Drop reference448 psImage *sub1 = psImageSubset(image1, region); // Subimage with stamp 449 stamp->image1 = psKernelAllocFromImage(sub1, size, size); 450 psFree(sub1); // Drop reference 451 452 if (image2) { 453 psImage *sub2 = psImageSubset(image2, region); // Subimage with stamp 454 stamp->image2 = psKernelAllocFromImage(sub2, size, size); 455 psFree(sub2); // Drop reference 480 456 } 481 457 482 458 psImage *wtSub = psImageSubset(weight, region); // Subimage with stamp 483 459 stamp->weight = psKernelAllocFromImage(wtSub, size, size); 484 psFree(wtSub); // Drop reference 460 psFree(wtSub); // Drop reference 461 462 stamp->status = PM_SUBTRACTION_STAMP_CALCULATE; 485 463 } 486 464 … … 488 466 } 489 467 490 468 #if 0 491 469 bool pmSubtractionStampsGenerate(pmSubtractionStampList *stamps, float fwhm, int footprint, int kernelSize) 492 470 { … … 517 495 float yStamp = y - (int)(y + 0.5); // y coordinate of star in stamp frame 518 496 519 psFree(stamp->i nput);520 stamp->i nput= psKernelAlloc(-size, size, -size, size);521 psKernel * input = stamp->input; // Target stamp497 psFree(stamp->image2); 498 stamp->image2 = psKernelAlloc(-size, size, -size, size); 499 psKernel *target = stamp->image2; // Target stamp 522 500 523 501 // Put in a Waussian, just for fun! … … 525 503 for (int u = -size; u <= size; u++) { 526 504 float z = (PS_SQR(u + xStamp) + PS_SQR(v + yStamp)) / (2.0 * PS_SQR(sigma)); 527 input->kernel[v][u] = flux / sigma * 0.5 * M_2_SQRTPI * M_SQRT1_2 / (1.0 + z + PS_SQR(z));505 target->kernel[v][u] = flux / sigma * 0.5 * M_2_SQRTPI * M_SQRT1_2 / (1.0 + z + PS_SQR(z)); 528 506 } 529 507 } … … 533 511 return true; 534 512 } 535 513 #endif 536 514 537 515 pmSubtractionStampList *pmSubtractionStampsSetFromSources(const psArray *sources, const psImage *subMask, 538 516 const psRegion *region, float spacing, 539 int exclusionZone)517 pmSubtractionMode mode) 540 518 { 541 519 PS_ASSERT_ARRAY_NON_NULL(sources, NULL); … … 561 539 562 540 pmSubtractionStampList *stamps = pmSubtractionStampsSet(x, y, flux, NULL, subMask, region, 563 spacing, exclusionZone); // Stamps to return541 spacing, mode); // Stamps to return 564 542 psFree(x); 565 543 psFree(y); … … 572 550 return stamps; 573 551 } 552 553 554 pmSubtractionStampList *pmSubtractionStampsSetFromFile(const char *filename, const psImage *subMask, 555 const psRegion *region, float spacing, 556 pmSubtractionMode mode) 557 { 558 PS_ASSERT_STRING_NON_EMPTY(filename, NULL); 559 // Let pmSubtractionStampsSet take care of the rest of the assertions 560 561 const char *format = (mode == PM_SUBTRACTION_MODE_TARGET ? "%f %f %f" : "%f %f"); // Format of file 562 psArray *data = psVectorsReadFromFile(filename, format); 563 if (!data) { 564 psError(PS_ERR_IO, false, "Unable to read stamps file %s", filename); 565 return NULL; 566 } 567 psVector *x = data->data[0], *y = data->data[1]; // Stamp positions 568 psVector *flux = (mode == PM_SUBTRACTION_MODE_TARGET ? data->data[2] : NULL); // Stamp fluxes 569 570 // Correct for IRAF/FITS (unit-offset) positions to C (zero-offset) positions 571 psBinaryOp(x, x, "-", psScalarAlloc(1.0, PS_TYPE_F32)); 572 psBinaryOp(y, y, "-", psScalarAlloc(1.0, PS_TYPE_F32)); 573 574 pmSubtractionStampList *stamps = pmSubtractionStampsSet(x, y, flux, NULL, subMask, region, spacing, 575 mode); 576 psFree(data); 577 578 return stamps; 579 580 } -
branches/eam_branch_20071023/psModules/src/imcombine/pmSubtractionStamps.h
r14802 r15516 9 9 typedef enum { 10 10 PM_SUBTRACTION_STAMP_INIT, ///< Initial state 11 PM_SUBTRACTION_STAMP_FOUND, ///< Found a suitable source for this stamp 12 PM_SUBTRACTION_STAMP_CALCULATE, ///< Calculate matrix and vector values for this stamp 11 13 PM_SUBTRACTION_STAMP_USED, ///< Use this stamp 12 14 PM_SUBTRACTION_STAMP_REJECTED, ///< This stamp has been rejected 13 PM_SUBTRACTION_STAMP_CALCULATE, ///< Calculate matrix and vector values for this stamp14 15 PM_SUBTRACTION_STAMP_NONE ///< No stamp in this region 15 16 } pmSubtractionStampStatus; … … 54 55 float flux; ///< Flux 55 56 float xNorm, yNorm; ///< Normalised position 56 psKernel * reference;///< Reference image postage stamp57 psKernel *i nput;///< Input image postage stamp57 psKernel *image1; ///< Reference image postage stamp 58 psKernel *image2; ///< Input image postage stamp 58 59 psKernel *weight; ///< Weight image postage stamp 59 psArray *convolutions; ///< Convolutions of the reference for each kernel component 60 psArray *convolutions1; ///< Convolutions of image 1 for each kernel component 61 psArray *convolutions2; ///< Convolutions of image 2 for each kernel component 60 62 psImage *matrix; ///< Associated matrix 61 63 psVector *vector; ///< Assoicated vector … … 72 74 const psRegion *region, ///< Region to search, or NULL 73 75 float threshold, ///< Threshold for stamps in the image 74 float spacing ///< Rough spacing for stamps 76 float spacing, ///< Rough spacing for stamps 77 pmSubtractionMode mode ///< Mode for subtraction 75 78 ); 76 79 77 80 /// Set stamps based on a list of x,y 78 ///79 /// We may optionally apply an exclusion zone around each star --- this is important when we're convolving to80 /// a specified PSF; less so when we're only trying to get a good subtraction.81 81 pmSubtractionStampList *pmSubtractionStampsSet(const psVector *x, ///< x coordinates for each stamp 82 82 const psVector *y, ///< y coordinates for each stamp … … 86 86 const psRegion *region, ///< Region to search, or NULL 87 87 float spacing, ///< Rough spacing for stamps 88 int exclusionZone ///< Exclusion zone around each star88 pmSubtractionMode mode ///< Mode for subtraction 89 89 ); 90 90 91 /// 91 /// Set stamps based on a list of sources 92 92 pmSubtractionStampList *pmSubtractionStampsSetFromSources( 93 const psArray *sources, ///< Sources for each stamp 94 const psImage *subMask, ///< Mask, or NULL 95 const psRegion *region, ///< Region to search, or NULL 96 float spacing, ///< Rough spacing for stamps 97 int exclusionZone ///< Exclusion zone around each star 93 const psArray *sources, ///< Sources for each stamp 94 const psImage *subMask, ///< Mask, or NULL 95 const psRegion *region, ///< Region to search, or NULL 96 float spacing, ///< Rough spacing for stamps 97 pmSubtractionMode mode ///< Mode for subtraction 98 ); 99 100 /// Set stamps based on values in a file 101 pmSubtractionStampList *pmSubtractionStampsSetFromFile( 102 const char *filename, ///< Filename of file containing x,y (or x,y,flux) on each line 103 const psImage *subMask, ///< Mask, or NULL 104 const psRegion *region, ///< Region to search, or NULL 105 float spacing, ///< Rough spacing for stamps 106 pmSubtractionMode mode ///< Mode for subtraction 98 107 ); 99 108 … … 107 116 ); 108 117 109 /// Generate target for stamps based on list110 bool pmSubtractionStampsGenerate(pmSubtractionStampList *stamps, ///< Stamps111 float fwhm, ///< FWHM for each stamp112 int footprint, ///< Stamp footprint size113 int size ///< Kernel half-size114 );115 116 118 #endif -
branches/eam_branch_20071023/psModules/src/objects/pmTrend2D.c
r15414 r15516 3 3 * @author EAM, IfA 4 4 * 5 * @version $Revision: 1.4.2. 1$ $Name: not supported by cvs2svn $6 * @date $Date: 2007-1 0-29 22:42:34 $5 * @version $Revision: 1.4.2.2 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2007-11-08 22:59:04 $ 7 7 * 8 8 * Copyright 2004 Institute for Astronomy, University of Hawaii … … 11 11 // XXXX: Ignore (2) 12 12 13 // XXXX: ignore 14 15 // XXXX: ignore 16 13 17 #ifdef HAVE_CONFIG_H 14 18 #include <config.h> … … 32 36 pmTrend2D *pmTrend2DAlloc (pmTrend2DMode mode, psImage *image, int nXtrend, int nYtrend, psStats *stats) 33 37 { 34 assert (image); 38 PS_ASSERT_PTR_NON_NULL(stats, NULL); 39 if (mode == PM_TREND_MAP) { 40 PS_ASSERT_PTR_NON_NULL(image, NULL); 41 } 35 42 36 43 pmTrend2D *trend = (pmTrend2D *) psAlloc(sizeof(pmTrend2D)); … … 73 80 break; 74 81 } 75 82 // XXX: Put a more graceful error here. 76 83 default: 77 84 psAbort ("error"); 78 85 } 79 86 return (trend); 87 } 88 89 bool psMemCheckTrend2D(psPtr ptr) 90 { 91 PS_ASSERT_PTR(ptr, false); 92 return ( psMemGetDeallocator(ptr) == (psFreeFunc) pmTrend2DFree); 80 93 } 81 94 … … 123 136 pmTrend2D *pmTrend2DFieldAlloc (pmTrend2DMode mode, int nXfield, int nYfield, int nXtrend, int nYtrend, psStats *stats) 124 137 { 138 PS_ASSERT_PTR_NON_NULL(stats, NULL); 125 139 pmTrend2D *trend = (pmTrend2D *) psAlloc(sizeof(pmTrend2D)); 126 140 psMemSetDeallocator(trend, (psFreeFunc) pmTrend2DFree); … … 164 178 165 179 default: 180 // XXX: Put a more graceful error here. 166 181 psAbort ("error"); 167 182 } … … 169 184 } 170 185 171 bool pmTrend2DFit (pmTrend2D *trend, psVector *mask, psMaskType maskVal, psVector *x, psVector *y, psVector *f, psVector *df) { 186 bool pmTrend2DFit (pmTrend2D *trend, psVector *mask, psMaskType maskVal, psVector *x, 187 psVector *y, psVector *f, psVector *df) 188 { 189 PS_ASSERT_PTR_NON_NULL(trend, false); 172 190 173 191 bool status; … … 199 217 } 200 218 201 double pmTrend2DEval (pmTrend2D *trend, float x, float y) { 219 double pmTrend2DEval (pmTrend2D *trend, float x, float y) 220 { 221 if (!trend) return 0.0; 202 222 203 223 double result; 204 205 assert (trend);206 207 224 switch (trend->mode) { 208 225 case PM_TREND_POLY_ORD: … … 221 238 } 222 239 223 psVector *pmTrend2DEvalVector (pmTrend2D *trend, psVector *x, psVector *y) { 224 240 psVector *pmTrend2DEvalVector (pmTrend2D *trend, psVector *x, psVector *y) 241 { 242 PS_ASSERT_PTR_NON_NULL(trend, NULL); 225 243 psVector *result; 226 244
Note:
See TracChangeset
for help on using the changeset viewer.
