Changeset 21524
- Timestamp:
- Feb 17, 2009, 2:31:20 PM (17 years ago)
- Location:
- trunk/ppSub/src
- Files:
-
- 16 edited
-
ppSub.c (modified) (1 diff)
-
ppSub.h (modified) (5 diffs)
-
ppSubArguments.c (modified) (3 diffs)
-
ppSubBackground.c (modified) (3 diffs)
-
ppSubCamera.c (modified) (4 diffs)
-
ppSubDefineOutput.c (modified) (3 diffs)
-
ppSubLoop.c (modified) (2 diffs)
-
ppSubMakePSF.c (modified) (3 diffs)
-
ppSubMatchPSFs.c (modified) (6 diffs)
-
ppSubReadout.c (modified) (3 diffs)
-
ppSubReadoutPhotometry.c (modified) (6 diffs)
-
ppSubReadoutSubtract.c (modified) (6 diffs)
-
ppSubReadoutUpdate.c (modified) (4 diffs)
-
ppSubSetMasks.c (modified) (5 diffs)
-
ppSubVarianceFactors.c (modified) (2 diffs)
-
ppSubVersion.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppSub/src/ppSub.c
r21424 r21524 6 6 * 7 7 * @author IfA 8 * @version $Revision: 1.1 1$ $Name: not supported by cvs2svn $9 * @date $Date: 2009-02- 09 21:26:05$8 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2009-02-18 00:31:20 $ 10 10 * Copyright 2009 Institute for Astronomy, University of Hawaii 11 11 */ 12 13 #ifdef HAVE_CONFIG_H 14 #include <config.h> 15 #endif 16 17 #include <stdio.h> 18 #include <pslib.h> 19 #include <psmodules.h> 20 #include <psphot.h> 12 21 13 22 #include "ppSub.h" -
trunk/ppSub/src/ppSub.h
r21360 r21524 6 6 * 7 7 * @author IfA 8 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $9 * @date $Date: 2009-02- 06 01:37:17$8 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2009-02-18 00:31:20 $ 10 10 * Copyright 2009 Institute for Astronomy, University of Hawaii 11 11 */ … … 14 14 #define PP_SUB_H 15 15 16 #ifdef HAVE_CONFIG_H17 #include <config.h>18 #endif19 20 #include <stdio.h>21 #include <string.h>22 16 #include <pslib.h> 23 17 #include <psmodules.h> 24 #include <psphot.h>25 #include <ppStats.h>26 18 27 19 /// @addtogroup ppSub … … 32 24 /// Setup the arguments parsing 33 25 bool ppSubArgumentsSetup(int argc, char *argv[], ///< Command-line arguments 34 pmConfig *config ///< Configuration26 pmConfig *config ///< Configuration 35 27 ); 36 28 … … 53 45 ); 54 46 55 /// generate (if needed) and set or update the masks for input and reference images56 bool ppSubSetMasks (pmConfig *config,///< Configuration57 const pmFPAview *view ///< View of active readout47 /// Generate (if needed) and set or update the masks for input and reference images 48 bool ppSubSetMasks(pmConfig *config, ///< Configuration 49 const pmFPAview *view ///< View of active readout 58 50 ); 59 51 60 /// Generate the PSF-matching kernel and convolve the images as needed. Most of this function 61 /// involves looking up the parameters in the recipe and supplying them to the function 62 /// pmSubtractionMatch() 63 bool ppSubMatchPSFs (pmConfig *config, ///< Configuration 64 const pmFPAview *view ///< View of active readout 52 /// Generate the PSF-matching kernel and convolve the images as needed. Most of this function involves 53 /// looking up the parameters in the recipe and supplying them to the function pmSubtractionMatch() 54 bool ppSubMatchPSFs(pmConfig *config, ///< Configuration 55 const pmFPAview *view ///< View of active readout 65 56 ); 66 57 67 /// generate the output readout and pass the kernel info to the header68 bool ppSubDefineOutput(pmConfig *config, ///< Configuration69 const pmFPAview *view ///< View of active readout58 /// Generate the output readout and pass the kernel info to the header 59 bool ppSubDefineOutput(pmConfig *config, ///< Configuration 60 const pmFPAview *view ///< View of active readout 70 61 ); 71 62 72 /// Calculate the variance factor for the output image based on the input images 73 bool ppSubVarianceFactors(pmConfig *config, ///< Configuration 74 psMetadata *stats, ///< Statistics, for output 75 const pmFPAview *view ///< View of active readout 76 ); 77 78 /// Photometry stage 1: measure the PSF from the minuend image 79 bool ppSubMakePSF(pmConfig *config, ///< Configuration 80 const pmFPAview *view ///< View of active readout 63 /// Photometry stage 1: measure the PSF from the minuend image 64 bool ppSubMakePSF(pmConfig *config, ///< Configuration 65 const pmFPAview *view ///< View of active readout 81 66 ); 82 67 83 68 /// Perform the actual image subtraction, update output concepts 84 bool ppSubReadoutSubtract(pmConfig *config, ///< Configuration85 const pmFPAview *view ///< View of active readout69 bool ppSubReadoutSubtract(pmConfig *config, ///< Configuration 70 const pmFPAview *view ///< View of active readout 86 71 ); 87 72 88 73 89 74 /// Photometry stage 2: find and measure sources on the subtracted image 90 bool ppSubReadoutPhotometry(pmConfig *config, ///< Configuration91 psMetadata *stats, ///< Statistics, for output92 const pmFPAview *view ///< View of active readout75 bool ppSubReadoutPhotometry(pmConfig *config, ///< Configuration 76 psMetadata *stats, ///< Statistics, for output 77 const pmFPAview *view ///< View of active readout 93 78 ); 94 79 95 80 /// Renormalize, update headers and generate JPEGs 96 bool ppSubReadoutUpdate(pmConfig *config, ///< Configuration 97 const pmFPAview *view ///< View of active readout 81 bool ppSubReadoutUpdate(pmConfig *config, ///< Configuration 82 psMetadata *stats, ///< Statistics for output, or NULL 83 const pmFPAview *view ///< View of active readout 98 84 ); 99 85 … … 107 93 ); 108 94 109 /// Generate and Set the masks if needed110 bool ppSubSetMasks (111 pmConfig *config, ///< Configuration112 const pmFPAview *view ///< view to readout113 );114 115 /// Renormalize readout for peak pixels116 bool ppSubReadoutRenormPixels (117 pmConfig *config, ///< Configuration118 psMetadata *recipe, ///< Recipe119 pmReadout *readout ///< Readout120 );121 122 /// Renormalize readout for photometry analysis123 bool ppSubReadoutRenormPhot (124 pmConfig *config, ///< Configuration125 psMetadata *recipe, ///< Recipe126 pmReadout *readout ///< Readout127 );128 95 129 96 // Copy every instance of a single keyword from one metadata to another -
trunk/ppSub/src/ppSubArguments.c
r21424 r21524 6 6 * 7 7 * @author IfA 8 * @version $Revision: 1.5 8$ $Name: not supported by cvs2svn $9 * @date $Date: 2009-02- 09 21:26:05$8 * @version $Revision: 1.59 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2009-02-18 00:31:20 $ 10 10 * Copyright 2009 Institute for Astronomy, University of Hawaii 11 11 */ 12 13 #ifdef HAVE_CONFIG_H 14 #include <config.h> 15 #endif 16 17 #include <stdio.h> 18 #include <pslib.h> 19 #include <psmodules.h> 20 #include <psphot.h> 12 21 13 22 #include "ppSub.h" … … 240 249 psMetadataAddS32(arguments, PS_LIST_TAIL, "-opt-order", 0, "Maximum order for optimum kernel search", -1); 241 250 psMetadataAddBool(arguments, PS_LIST_TAIL, "-dual", 0, "Dual convolution", false); 242 psMetadataAddBool(arguments, PS_LIST_TAIL, "-renorm", 0, "Renormalise variance maps?", false);243 psMetadataAddStr(arguments, PS_LIST_TAIL, "-renorm-mean", 0,244 "Statistic for mean in renormalisation", NULL);245 psMetadataAddStr(arguments, PS_LIST_TAIL, "-renorm-stdev", 0,246 "Statistic for stdev in renormalisation", NULL);247 psMetadataAddF32(arguments, PS_LIST_TAIL, "-renorm-width", 0, "Gaussian width for renormalisation", NAN);248 psMetadataAddS32(arguments, PS_LIST_TAIL, "-renorm-num", 0, "Number of samples for renormalisation", 0);249 251 psMetadataAddBool(arguments, PS_LIST_TAIL, "-photometry", 0, "Perform photometry?", false); 250 252 psMetadataAddS32(arguments, PS_LIST_TAIL, "-threads", 0, "Number of threads", 0); … … 352 354 psMetadataLookupBool(NULL, arguments, "-dual")); 353 355 354 if (psMetadataLookupBool(NULL, arguments, "-renorm") ||355 psMetadataLookupBool(NULL, recipe, "RENORM")) {356 psMetadataAddBool(arguments, PS_LIST_TAIL, "RENORM", 0, "Renormalise variance maps?", true);357 }358 VALUE_ARG_RECIPE_INT("-renorm-num", "RENORM.NUM", S32, 0);359 VALUE_ARG_RECIPE_FLOAT("-renorm-width", "RENORM.WIDTH", F32);360 valueArgRecipeStr(arguments, recipe, "-renorm-mean", "RENORM.MEAN", recipe);361 valueArgRecipeStr(arguments, recipe, "-renorm-stdev", "RENORM.STDEV", recipe);362 363 356 // Need to update this because it could have been overwritten by the camera's own recipe 364 357 if (psMetadataLookupBool(NULL, arguments, "-photometry")) { -
trunk/ppSub/src/ppSubBackground.c
r21360 r21524 6 6 * 7 7 * @author IfA 8 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $9 * @date $Date: 2009-02- 06 01:37:17$8 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2009-02-18 00:31:20 $ 10 10 * Copyright 2009 Institute for Astronomy, University of Hawaii 11 11 */ 12 12 13 #ifdef HAVE_CONFIG_H 14 #include <config.h> 15 #endif 16 17 #include <stdio.h> 18 #include <pslib.h> 19 #include <psmodules.h> 20 #include <psphot.h> 21 13 22 #include "ppSub.h" 14 23 15 /**16 * Based on ppImageSubtractBackground()17 */18 24 bool ppSubBackground(pmConfig *config, const pmFPAview *view) 19 25 { 20 psAssert(config, " Needconfiguration");21 psAssert(view, " Need view to chip");26 psAssert(config, "Require configuration"); 27 psAssert(view, "Require view"); 22 28 23 bool status; // Status of metadata lookups29 bool mdok; // Status of metadata lookups 24 30 25 psMetadata *ppSubRecipe = psMetadataLookupPtr(NULL, config->recipes, PPSUB_RECIPE); 31 psMetadata *ppSubRecipe = psMetadataLookupPtr(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSub 26 32 psAssert(ppSubRecipe, "Need PPSUB recipe"); 27 28 psMetadata *psphotRecipe = psMetadataLookupPtr(NULL, config->recipes, PSPHOT_RECIPE); 33 psMetadata *psphotRecipe = psMetadataLookupPtr(NULL, config->recipes, PSPHOT_RECIPE); // Recipe for psphot 29 34 psAssert(psphotRecipe, "Need PSPHOT recipe for binning"); 30 35 31 psImageMaskType maskBad = pmConfigMaskGet("BLANK", config); 36 psImageMaskType maskBad = pmConfigMaskGet("BLANK", config); // Bits to mask 32 37 33 // select the output readout34 pmReadout * outRO = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT");38 pmReadout *outRO = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT"); // Output image 39 pmReadout *modelRO = pmFPAfileThisReadout(config->files, view, "PSPHOT.BACKMDL"); // Background model 35 40 36 // select the model readout, if it exist already; if not, generate it 37 pmReadout *modelRO = pmFPAfileThisReadout(config->files, view, "PSPHOT.BACKMDL"); 38 39 // if necessary, generate the background model 41 // Generate the background model, if required 40 42 if (!modelRO) { 41 43 // Create the background model … … 44 46 return false; 45 47 } 46 // select the model readout (should now exist)47 modelRO = pmFPAfileThisReadout(config->files, view, "PSPHOT.BACKMDL");48 // select the model readout (should now exist) 49 modelRO = pmFPAfileThisReadout(config->files, view, "PSPHOT.BACKMDL"); 48 50 if (!modelRO) { 49 51 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find background model"); … … 51 53 } 52 54 } 53 psImageBinning *binning = psMetadataLookupPtr(& status, psphotRecipe,55 psImageBinning *binning = psMetadataLookupPtr(&mdok, psphotRecipe, 54 56 "PSPHOT.BACKGROUND.BINNING"); // Binning for model 55 57 psImage *modelImage = modelRO->image; // Background model 56 57 58 psImage *image = outRO->image; // Image of interest 58 59 psImage *mask = outRO->mask; // Mask of interest -
trunk/ppSub/src/ppSubCamera.c
r21374 r21524 6 6 * 7 7 * @author IfA 8 * @version $Revision: 1.3 3$ $Name: not supported by cvs2svn $9 * @date $Date: 2009-02- 06 03:20:02$8 * @version $Revision: 1.34 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2009-02-18 00:31:20 $ 10 10 * Copyright 2009 Institute for Astronomy, University of Hawaii 11 11 */ 12 13 #ifdef HAVE_CONFIG_H 14 #include <config.h> 15 #endif 16 17 #include <stdio.h> 18 #include <pslib.h> 19 #include <psmodules.h> 20 #include <psphot.h> 12 21 13 22 #include "ppSub.h" … … 257 266 // psPhot input 258 267 if (psMetadataLookupBool(NULL, recipe, "PHOTOMETRY")) { 259 psphotModelClassInit (); // load implementation-specific models 260 261 262 // Internal-ish file for getting the PSF from the matched addition 268 psphotModelClassInit(); // load implementation-specific models 269 270 // Internal-ish file for getting the PSF from the minuend 263 271 pmFPAfile *psf = pmFPAfileDefineOutputFromFile(config, output, "PSPHOT.PSF.LOAD"); 264 272 if (!psf) { … … 272 280 pmFPAfileActivate(config->files, false, "PSPHOT.PSF.LOAD"); 273 281 274 pmFPAfile *psphotResid = pmFPAfileDefineOutputForFormat (config, NULL, "PSPHOT.RESID", output->cameraName, output->formatName);275 if (!psphotResid) {276 psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PSPHOT.RESID");277 return false;278 }279 // make this optional: psphotResid->save = true;280 }281 282 // Always do this, since we're using psphot for the background model.283 // XXX Not certain that I need to generate a separate pmFPAfile for PSPHOT.INPUT284 if (0) {285 282 pmFPAfile *psphot = pmFPAfileDefineFromFPA(config, output->fpa, 1, 1, "PSPHOT.INPUT"); 286 283 if (!psphot) { … … 297 294 return false; 298 295 } 299 300 296 } 301 297 -
trunk/ppSub/src/ppSubDefineOutput.c
r21360 r21524 6 6 * 7 7 * @author IfA 8 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $9 * @date $Date: 2009-02- 06 01:37:17$8 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2009-02-18 00:31:20 $ 10 10 * Copyright 2009 Institute for Astronomy, University of Hawaii 11 11 */ 12 12 13 #ifdef HAVE_CONFIG_H 14 #include <config.h> 15 #endif 16 17 #include <stdio.h> 18 #include <pslib.h> 19 #include <psmodules.h> 20 13 21 #include "ppSub.h" 14 22 15 bool ppSubDefineOutput (pmConfig *config, const pmFPAview *view) { 23 bool ppSubDefineOutput(pmConfig *config, const pmFPAview *view) 24 { 25 psAssert(config, "Require configuration"); 26 psAssert(view, "Require view"); 16 27 17 bool mdok; 18 19 // generate an output readout 28 // generate an output readout 20 29 pmCell *outCell = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT"); // Output cell 21 30 pmReadout *outRO = pmReadoutAlloc(outCell); // Output readout: subtraction … … 30 39 pmReadout *refConv = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV"); // Reference readout 31 40 32 // Add kernel descrption to header. We don't know which readout gets the kernels because 33 // it depends on which is larger (the choice is set in ppSubMatchPSFs) 34 bool inputHasKernel = true; 35 pmSubtractionKernels *kernels = psMetadataLookupPtr(&mdok, inConv->analysis, PM_SUBTRACTION_ANALYSIS_KERNEL); // Subtraction kernel 41 // Add kernel descrption to header. 42 // We don't know which readout has the kernels because it depends on which PSF is larger 43 bool mdok; // Status of MD lookup 44 psMetadata *analysis = inConv->analysis; // Analysis metadata with kernel information 45 pmSubtractionKernels *kernels = psMetadataLookupPtr(&mdok, analysis, 46 PM_SUBTRACTION_ANALYSIS_KERNEL); // Subtraction kernel 36 47 if (!kernels) { 37 kernels = psMetadataLookupPtr(&mdok, refConv->analysis, PM_SUBTRACTION_ANALYSIS_KERNEL);38 inputHasKernel = false;48 analysis = refConv->analysis; 49 kernels = psMetadataLookupPtr(&mdok, analysis, PM_SUBTRACTION_ANALYSIS_KERNEL); 39 50 } 40 51 if (!kernels) { … … 45 56 return false; 46 57 } 47 psMetadataAddStr(outHDU->header, PS_LIST_TAIL, "PPSUB.KERNEL", 0, "Subtraction kernel", kernels->description); 58 psMetadataAddStr(outHDU->header, PS_LIST_TAIL, "PPSUB.KERNEL", 0, "Subtraction kernel", 59 kernels->description); 48 60 49 if (inputHasKernel) { 50 outRO->analysis = psMetadataCopy(outRO->analysis, inConv->analysis); 51 } else { 52 outRO->analysis = psMetadataCopy(outRO->analysis, refConv->analysis); 53 } 61 outRO->analysis = psMetadataCopy(outRO->analysis, analysis); 54 62 55 63 #ifdef TESTING 56 psImage *kernelImage = NULL;57 58 if (inputHasKernel) {59 kernelImage = psMetadataLookupPtr(&mdok, inConv->analysis, "SUBTRACTION.KERNEL.IMAGE"); // Image of the kernels 60 } else {61 kernelImage = psMetadataLookupPtr(&mdok, refConv->analysis, "SUBTRACTION.KERNEL.IMAGE");64 { 65 psImage *kernelImage = psMetadataLookupPtr(&mdok, analysis, 66 "SUBTRACTION.KERNEL.IMAGE"); // Image of kernel 67 psFits *fits = psFitsOpen("kernel.fits", "w"); 68 psFitsWriteImage(fits, NULL, kernelImage, 0, NULL); 69 psFitsClose(fits); 62 70 } 63 64 psFits *fits = psFitsOpen("kernel.fits", "w");65 psFitsWriteImage(fits, NULL, kernelImage, 0, NULL);66 psFitsClose(fits);67 71 #endif 68 72 -
trunk/ppSub/src/ppSubLoop.c
r21360 r21524 6 6 * 7 7 * @author IfA 8 * @version $Revision: 1.2 3$ $Name: not supported by cvs2svn $9 * @date $Date: 2009-02- 06 01:37:17$8 * @version $Revision: 1.24 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2009-02-18 00:31:20 $ 10 10 * Copyright 2009 Institute for Astronomy, University of Hawaii 11 11 */ 12 13 #ifdef HAVE_CONFIG_H 14 #include <config.h> 15 #endif 16 17 #include <pslib.h> 18 #include <psmodules.h> 19 #include <ppStats.h> 12 20 13 21 #include "ppSub.h" … … 138 146 return false; 139 147 } 140 psImageMaskType maskValue = pmConfigMaskGet("MASK.VALUE", config);148 psImageMaskType maskValue = pmConfigMaskGet("MASK.VALUE", config); 141 149 ppStatsFPA(stats, output->fpa, view, maskValue, config); 142 150 } -
trunk/ppSub/src/ppSubMakePSF.c
r21360 r21524 6 6 * 7 7 * @author IfA 8 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $9 * @date $Date: 2009-02- 06 01:37:17$8 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2009-02-18 00:31:20 $ 10 10 * Copyright 2009 Institute for Astronomy, University of Hawaii 11 11 */ 12 12 13 #ifdef HAVE_CONFIG_H 14 #include <config.h> 15 #endif 16 17 #include <stdio.h> 18 #include <pslib.h> 19 #include <psmodules.h> 20 #include <psphot.h> 21 13 22 #include "ppSub.h" 14 23 15 /** 16 * Photometry stage 1: measure the PSF from the minuend image 17 */18 bool ppSubMakePSF (pmConfig *config, const pmFPAview *view) { 24 bool ppSubMakePSF(pmConfig *config, const pmFPAview *view) 25 { 26 psAssert(config, "Require configuration"); 27 psAssert(view, "Require view"); 19 28 20 bool mdok = false;21 22 // Photometry is to be performed in two stages:23 // 1. Measure the PSF using the PSF-matched images24 // 2. Find and measure sources on the subtracted image25 29 psTimerStart("PPSUB_PHOT"); 26 30 27 // Look up recipe values28 31 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSub 29 32 psAssert(recipe, "We checked this earlier, so it should be here."); 30 33 31 psMetadata *psphotRecipe = psMetadataLookupMetadata(NULL, config->recipes, PSPHOT_RECIPE); // Recipe for psphot 34 if (!psMetadataLookupBool(NULL, recipe, "PHOTOMETRY")) { 35 return true; 36 } 37 38 psMetadata *psphotRecipe = psMetadataLookupMetadata(NULL, config->recipes, PSPHOT_RECIPE);// psphot recipe 32 39 psAssert(recipe, "We checked this earlier, so it should be here."); 33 34 if (!psMetadataLookupBool(NULL, recipe, "PHOTOMETRY")) return true;35 40 36 41 bool reverse = psMetadataLookupBool(NULL, config->arguments, "REVERSE"); // Reverse sense of subtraction? 37 42 38 pmReadout *minuend = NULL; 39 pmFPAfile *minuendFile = NULL; 43 bool mdok = false; // Status of MD lookup 44 pmReadout *minuend = NULL; // Image that will be positive following subtraction 45 pmFPAfile *minuendFile = NULL; // File for minuend image 40 46 if (reverse) { 41 minuend = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV");42 minuendFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.REF.CONV");47 minuend = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV"); 48 minuendFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.REF.CONV"); 43 49 } else { 44 minuend = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.CONV");45 minuendFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.INPUT.CONV");50 minuend = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.CONV"); 51 minuendFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.INPUT.CONV"); 46 52 } 47 53 48 // supply the minuend pmFPAfile to psphot as PSPHOT.INPUT: 49 psMetadataAddPtr (config->files, PS_LIST_TAIL, "PSPHOT.INPUT", PS_DATA_UNKNOWN | PS_META_REPLACE, "psphot input : view on another pmFPAfile", minuendFile); 54 #if 1 55 pmReadout *template = minuend; 56 pmFPAfile *photFile = psMetadataLookupPtr(&mdok, config->files, "PSPHOT.INPUT"); // Photometry file 57 pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout to photometer 58 if (!photRO) { 59 pmCell *cell = pmFPAviewThisCell(view, photFile->fpa); // Cell to photometer 60 photRO = pmReadoutAlloc(cell); // Output readout: subtraction 61 } 62 photRO->image = psImageCopy(photRO->image, template->image, PS_TYPE_F32); 63 if (template->variance) { 64 photRO->variance = psImageCopy(photRO->variance, template->variance, PS_TYPE_F32); 65 } else { 66 psFree(photRO->variance); 67 photRO->variance = NULL; 68 } 69 if (template->mask) { 70 photRO->mask = psImageCopy(photRO->mask, template->mask, PS_TYPE_IMAGE_MASK); 71 } else { 72 psFree(photRO->mask); 73 photRO->mask = NULL; 74 } 75 #else 76 // Supply the minuend pmFPAfile to psphot as PSPHOT.INPUT: 77 psMetadataAddPtr(config->files, PS_LIST_TAIL, "PSPHOT.INPUT", PS_DATA_UNKNOWN | PS_META_REPLACE, 78 "psphot input: view on another pmFPAfile", minuendFile); 79 #endif 50 80 51 // old-style variance renormalization 52 if (!ppSubReadoutRenormPhot (config, recipe, minuend)) { 53 psError(PS_ERR_UNKNOWN, false, "failure in renormalization"); 54 return false; 55 } 56 57 // extract the loaded sources from the associated readout 81 // Extract the loaded sources from the associated readout, and generate PSF 82 // Here, we assume the image is background-subtracted 58 83 pmReadout *sourcesRO = pmFPAfileThisReadout(config->files, view, "PPSUB.SOURCES"); 59 84 psArray *sources = psMetadataLookupPtr(&mdok, sourcesRO->analysis, "PSPHOT.SOURCES"); 60 61 // generate PSF from the supplied sources (assumes image is background-subtracted)62 85 if (!psphotReadoutFindPSF(config, view, sources)) { 63 psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry on subtracted image.");64 return false;86 psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry on subtracted image."); 87 return false; 65 88 } 66 89 … … 70 93 psMetadataItemSupplement(hdu->header, psphotRecipe, "FWHM_MAJ"); 71 94 psMetadataItemSupplement(hdu->header, psphotRecipe, "FWHM_MIN"); 95 96 // Get rid of the generated header; it will be regenerated by the real photometry run 97 psMetadataRemoveKey(photRO->analysis, "PSPHOT.HEADER"); 72 98 73 99 return true; … … 87 113 88 114 // Blow away the sources psphot found --- they're irrelevant for the subtraction 89 // XXX is this still needed? These are now probably not being set 115 // XXX is this still needed? These are now probably not being set 90 116 // pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout with sources 91 117 // psMetadataRemoveKey(photRO->analysis, "PSPHOT.SOURCES"); -
trunk/ppSub/src/ppSubMatchPSFs.c
r21360 r21524 6 6 * 7 7 * @author IfA 8 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $9 * @date $Date: 2009-02- 06 01:37:17$8 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2009-02-18 00:31:20 $ 10 10 * Copyright 2009 Institute for Astronomy, University of Hawaii 11 11 */ 12 12 13 #ifdef HAVE_CONFIG_H 14 #include <config.h> 15 #endif 16 17 #include <stdio.h> 18 #include <pslib.h> 19 #include <psmodules.h> 20 #include <psphot.h> 21 13 22 #include "ppSub.h" 14 23 15 /** Generate the PSF-matching kernel and convolve the images as needed. Most of this function 16 * involves looking up the parameters in the recipe and supplying them to the function 17 * pmSubtractionMatch(); 18 */ 19 20 bool ppSubMatchPSFs (pmConfig *config, const pmFPAview *view) { 21 22 bool mdok; // Status of MD lookup 24 bool ppSubMatchPSFs(pmConfig *config, const pmFPAview *view) 25 { 26 psAssert(config, "Require configuration"); 27 psAssert(view, "Require view"); 23 28 24 29 // Look up recipe values … … 26 31 psAssert(recipe, "We checked this earlier, so it should be here."); 27 32 28 // input images33 // Input images 29 34 pmReadout *inRO = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT"); // Input readout 30 35 pmReadout *refRO = pmFPAfileThisReadout(config->files, view, "PPSUB.REF"); // Reference readout 31 36 32 // get or generate output image holders33 pmReadout *inConv = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.CONV"); // Input convolved readout37 // Output image holders 38 pmReadout *inConv = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.CONV"); // Input convolved 34 39 if (!inConv) { 35 pmCell *cell = pmFPAfileThisCell(config->files, view, "PPSUB.INPUT.CONV"); // Input convolved readout36 inConv = pmReadoutAlloc(cell); // Convolved version of input 40 pmCell *cell = pmFPAfileThisCell(config->files, view, "PPSUB.INPUT.CONV"); // Cell for convolved input 41 inConv = pmReadoutAlloc(cell); 37 42 } 38 pmReadout *refConv = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV"); // Reference convolved readout43 pmReadout *refConv = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV"); // Reference convolved 39 44 if (!refConv) { 40 pmCell *cell = pmFPAfileThisCell(config->files, view, "PPSUB.REF.CONV"); // Input convolved readout 41 refConv = pmReadoutAlloc(cell); // Convolved version of input 45 pmCell *cell = pmFPAfileThisCell(config->files, view, "PPSUB.REF.CONV"); // Cell for convolved ref. 46 refConv = pmReadoutAlloc(cell); 42 47 } 43 48 44 // options which control the generation of optimal parameters 45 bool optimum = psMetadataLookupBool(&mdok, recipe, "OPTIMUM"); // Derive optimum parameters? 46 float optMin = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.MIN"); // Minimum width for search 47 float optMax = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.MAX"); // Maximum width for search 48 float optStep = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.STEP"); // Step for search 49 bool mdok; // Status of MD lookup 49 50 50 // Vector with FWHMs for optimum search 51 psVector *optWidths = NULL; 52 if (optimum) { 53 optWidths = psVectorCreate(optWidths, optMin, optMax, optStep, PS_TYPE_F32); 54 } 55 56 // Sources in image : these must be loaded from previous analysis stages 57 pmReadout *sourcesRO = pmFPAfileThisReadout(config->files, view, "PPSUB.SOURCES"); // Readout with sources 58 psArray *sources = NULL; 51 // Sources in image, used for stamps: these must be loaded from previous analysis stages 52 pmReadout *sourcesRO = pmFPAfileThisReadout(config->files, view, "PPSUB.SOURCES"); // Readout with sources 53 psArray *sources = NULL; // Sources in image; used for stamps 59 54 if (sourcesRO) { 60 55 sources = psMetadataLookupPtr(&mdok, sourcesRO->analysis, "PSPHOT.SOURCES"); … … 66 61 float spacing = psMetadataLookupF32(NULL, recipe, "STAMP.SPACING"); // Typical stamp spacing 67 62 float threshold = psMetadataLookupF32(NULL, recipe, "STAMP.THRESHOLD"); // Threshold for stmps 68 69 63 const char *stampsName = psMetadataLookupStr(&mdok, config->arguments, "STAMPS"); // Filename for stamps 70 64 71 65 const char *typeStr = psMetadataLookupStr(NULL, recipe, "KERNEL.TYPE"); // Kernel type 72 66 psAssert(typeStr, "We put it here in ppSubArguments.c"); 73 74 67 pmSubtractionKernelsType type = pmSubtractionKernelsTypeFromString(typeStr); // Type of kernel 75 68 if (type == PM_SUBTRACTION_KERNEL_NONE) { … … 87 80 int binning = psMetadataLookupS32(NULL, recipe, "SPAM.BINNING"); // Binning for SPAM kernel 88 81 float penalty = psMetadataLookupF32(NULL, recipe, "PENALTY"); // Penalty for wideness 89 90 int optOrder = psMetadataLookupS32(&mdok, recipe, "OPTIMUM.ORDER"); // Order for search91 float optThresh = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.TOL"); // Tolerance for search92 93 82 int iter = psMetadataLookupS32(NULL, recipe, "ITER"); // Rejection iterations 94 83 float rej = psMetadataLookupF32(NULL, recipe, "REJ"); // Rejection threshold … … 98 87 float poorFrac = psMetadataLookupF32(&mdok, recipe, "POOR.FRACTION"); // Fraction for "poor" 99 88 100 // XXX EAM : do we need to / want to define different values for BAD and POOR subtraction vs BAD and POOR warp? 101 psImageMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config); // Bits to mask going in to pmSubtractionMatch 89 // Options which control the generation of optimal parameters 90 bool optimum = psMetadataLookupBool(&mdok, recipe, "OPTIMUM"); // Derive optimum parameters? 91 float optMin = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.MIN"); // Minimum width for search 92 float optMax = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.MAX"); // Maximum width for search 93 float optStep = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.STEP"); // Step for search 94 psVector *optWidths = NULL; // Vector with FWHMs for optimum search 95 if (optimum) { 96 optWidths = psVectorCreate(optWidths, optMin, optMax, optStep, PS_TYPE_F32); 97 } 98 int optOrder = psMetadataLookupS32(&mdok, recipe, "OPTIMUM.ORDER"); // Order for search 99 float optThresh = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.TOL"); // Tolerance for search 100 101 // XXX Do we need/want to define different values for BAD and POOR subtraction vs BAD and POOR warp? 102 psImageMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config); // Bits to mask in inputs 102 103 psImageMaskType maskPoor = pmConfigMaskGet("POOR.WARP", config); // Bits to mask for poor pixels 103 104 psImageMaskType maskBad = pmConfigMaskGet("BLANK", config); // Bits to mask for bad pixels … … 124 125 pmSubtractionThreadsFinalize(inRO, refRO); 125 126 127 psImageCovarianceTransfer(inConv->variance, inConv->covariance); 128 psImageCovarianceTransfer(refConv->variance, refConv->covariance); 129 126 130 // XXX drop the pixels associated with inRO and refRO (now that we have inConv and refConf) 127 131 -
trunk/ppSub/src/ppSubReadout.c
r21424 r21524 6 6 * 7 7 * @author IfA 8 * @version $Revision: 1.11 2$ $Name: not supported by cvs2svn $9 * @date $Date: 2009-02- 09 21:26:05$8 * @version $Revision: 1.113 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2009-02-18 00:31:20 $ 10 10 * Copyright 2009 Institute for Astronomy, University of Hawaii 11 11 */ 12 13 #ifdef HAVE_CONFIG_H 14 #include <config.h> 15 #endif 16 17 #include <stdio.h> 18 #include <pslib.h> 19 #include <psmodules.h> 12 20 13 21 #include "ppSub.h" … … 17 25 psTimerStart("PPSUB_MATCH"); 18 26 19 if (!ppSubSetMasks (config, view)) {20 psError(PS_ERR_UNKNOWN, false, "Unable to s ubtract background.");27 if (!ppSubSetMasks(config, view)) { 28 psError(PS_ERR_UNKNOWN, false, "Unable to set masks."); 21 29 return false; 22 30 } 23 31 24 if (!ppSubMatchPSFs (config, view)) {25 psError(PS_ERR_UNKNOWN, false, "Unable to subtract background.");32 if (!ppSubMatchPSFs(config, view)) { 33 psError(PS_ERR_UNKNOWN, false, "Unable to match PSFs."); 26 34 return false; 27 35 } 28 36 29 if (!ppSubDefineOutput (config, view)) { 30 psError(PS_ERR_UNKNOWN, false, "Unable to subtract background."); 31 return false; 32 } 33 34 if (!ppSubVarianceFactors (config, stats, view)) { 35 psError(PS_ERR_UNKNOWN, false, "Unable to subtract background."); 37 if (!ppSubDefineOutput(config, view)) { 38 psError(PS_ERR_UNKNOWN, false, "Unable to define output."); 36 39 return false; 37 40 } 38 41 39 42 if (!ppSubMakePSF(config, view)) { 40 psError(PS_ERR_UNKNOWN, false, "Unable to subtract background.");43 psError(PS_ERR_UNKNOWN, false, "Unable to generate PSF."); 41 44 return false; 42 45 } 43 46 44 if (!ppSubReadoutSubtract (config, view)) {45 psError(PS_ERR_UNKNOWN, false, "Unable to subtract background.");47 if (!ppSubReadoutSubtract(config, view)) { 48 psError(PS_ERR_UNKNOWN, false, "Unable to subtract images."); 46 49 return false; 47 50 } … … 53 56 } 54 57 55 if (!ppSubReadoutPhotometry (config, stats, view)) {56 psError(PS_ERR_UNKNOWN, false, "Unable to subtract background.");58 if (!ppSubReadoutPhotometry(config, stats, view)) { 59 psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry."); 57 60 return false; 58 61 } 59 62 60 if (!ppSubReadoutUpdate (config, view)) {61 psError(PS_ERR_UNKNOWN, false, "Unable to subtract background.");63 if (!ppSubReadoutUpdate(config, stats, view)) { 64 psError(PS_ERR_UNKNOWN, false, "Unable to update."); 62 65 return false; 63 66 } -
trunk/ppSub/src/ppSubReadoutPhotometry.c
r21374 r21524 6 6 * 7 7 * @author IfA 8 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $9 * @date $Date: 2009-02- 06 03:20:02$8 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2009-02-18 00:31:20 $ 10 10 * Copyright 2009 Institute for Astronomy, University of Hawaii 11 11 */ 12 12 13 #ifdef HAVE_CONFIG_H 14 #include <config.h> 15 #endif 16 17 #include <stdio.h> 18 #include <pslib.h> 19 #include <psmodules.h> 20 #include <psphot.h> 21 13 22 #include "ppSub.h" 14 23 15 /** 16 * Photometry stage 2: find and measure sources on the subtracted image 17 */ 18 bool ppSubReadoutPhotometry (pmConfig *config, psMetadata *stats, const pmFPAview *view) { 19 20 bool mdok = false; 24 bool ppSubReadoutPhotometry (pmConfig *config, psMetadata *stats, const pmFPAview *view) 25 { 26 psAssert(config, "Require configuration"); 27 psAssert(view, "Require view"); 21 28 22 29 // Look up recipe values … … 32 39 // The PSF (measured in ppSubMakePSF) is stored on the chip->analysis of PSPHOT.INPUT 33 40 // In order to use an incoming PSF, it must be stored on the chip->analysis of PSPHOT.PSF.LOAD 34 pmChip *psfInputChip = pmFPAfileThisChip(config->files, view, "PSPHOT.INPUT"); 41 pmChip *psfInputChip = pmFPAfileThisChip(config->files, view, "PSPHOT.INPUT"); // Chip with PSF 35 42 psAssert (psfInputChip, "should have been generated for ppSubMakePSF"); 36 37 pmChip *psfLoadChip = pmFPAfileThisChip(config->files, view, "PSPHOT.PSF.LOAD"); 43 pmChip *psfLoadChip = pmFPAfileThisChip(config->files, view, "PSPHOT.PSF.LOAD"); // Chip to have PSF 38 44 psAssert (psfLoadChip, "PSPHOT.PSF.LOAD should have been defined in ppSubCamera"); 39 40 pmPSF *psf = psMetadataLookupPtr(NULL, psfInputChip->analysis, "PSPHOT.PSF"); 45 pmPSF *psf = psMetadataLookupPtr(NULL, psfInputChip->analysis, "PSPHOT.PSF"); // PSF for photometry 41 46 if (!psf) { 42 47 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find PSF from psphot"); 43 48 return false; 44 49 } 45 psMetadataAddPtr(psfLoadChip->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN | PS_META_REPLACE, "PSF from matched addition", psf); 50 psMetadataAddPtr(psfLoadChip->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN | PS_META_REPLACE, 51 "PSF from ppSubMakePSF", psf); 52 53 bool mdok = false; 46 54 47 55 // psphotReadoutMinimal performs the photometry analysis on PSPHOT.INPUT; we need to move 48 56 // around the pointers so PSPHOT.INPUT corresponds to the output image; previously, it was 49 57 // equivalent to the minuend image. 50 pmFPAfile *outputFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.OUTPUT"); 58 pmFPAfile *outputFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.OUTPUT"); // Output file 51 59 pmReadout *outRO = pmFPAviewThisReadout(view, outputFile->fpa); // Readout with the sources 52 60 53 61 // XXX possibly rename this to PPSUB.RESID? 54 pmFPAfile *photFile = psMetadataLookupPtr(&mdok, config->files, "PSPHOT. RESID");55 pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout with the sources62 pmFPAfile *photFile = psMetadataLookupPtr(&mdok, config->files, "PSPHOT.INPUT"); // Photometry file 63 pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout to photometer 56 64 if (!photRO) { 57 pmCell *cell = pmFPA fileThisCell(config->files, view, "PSPHOT.RESID"); // Output cell65 pmCell *cell = pmFPAviewThisCell(view, photFile->fpa); // Cell to photometer 58 66 photRO = pmReadoutAlloc(cell); // Output readout: subtraction 59 67 } … … 62 70 photRO->variance = psImageCopy(photRO->variance, outRO->variance, PS_TYPE_F32); 63 71 } else { 64 psFree (photRO->variance);72 psFree(photRO->variance); 65 73 photRO->variance = NULL; 66 74 } … … 68 76 photRO->mask = psImageCopy(photRO->mask, outRO->mask, PS_TYPE_IMAGE_MASK); 69 77 } else { 70 psFree (photRO->mask);78 psFree(photRO->mask); 71 79 photRO->mask = NULL; 72 80 } 73 81 74 // pmFPAfile *photFile = outputFile; 75 psMetadataAddPtr (config->files, PS_LIST_TAIL, "PSPHOT.INPUT", PS_DATA_UNKNOWN | PS_META_REPLACE, "psphot input : view on another pmFPAfile", photFile); 76 77 // old-style variance renormalization 78 if (!ppSubReadoutRenormPhot (config, recipe, photRO)) { 79 psError(PS_ERR_UNKNOWN, false, "failure in renormalization"); 80 return false; 81 } 82 #if 0 83 psMetadataAddPtr(config->files, PS_LIST_TAIL, "PSPHOT.INPUT", PS_DATA_UNKNOWN | PS_META_REPLACE, 84 "psphot input: view on another pmFPAfile", photFile); 85 #endif 82 86 83 87 if (!psphotReadoutMinimal(config, view)) { … … 86 90 psErrorClear(); 87 91 } 92 #if 1 93 photRO->data_exists = true; 94 photRO->parent->data_exists = true; 95 photRO->parent->parent->data_exists = true; 96 #endif 88 97 89 98 if (stats) { … … 101 110 } 102 111 103 // XXX not sure that this is still needed (only if psphotReadoutMinimal measures the background)104 // if (!pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL") ||105 // !pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL.STDEV") ||106 // !pmFPAfileDropInternal (config->files, "PSPHOT.BACKGND")) {107 // psError(PS_ERR_UNKNOWN, false, "Unable to drop PSPHOT internal files.");108 // return false;109 // }110 112 111 // pmFPAfileActivate(config->files, false, "PSPHOT.INPUT"); 112 // pmFPAfileActivate(config->files, false, "PSPHOT.LOAD.PSF"); 113 113 114 114 115 -
trunk/ppSub/src/ppSubReadoutSubtract.c
r21424 r21524 6 6 * 7 7 * @author IfA 8 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $9 * @date $Date: 2009-02- 09 21:26:05$8 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2009-02-18 00:31:20 $ 10 10 * Copyright 2009 Institute for Astronomy, University of Hawaii 11 11 */ 12 12 13 #ifdef HAVE_CONFIG_H 14 #include <config.h> 15 #endif 16 17 #include <stdio.h> 18 #include <pslib.h> 19 #include <psmodules.h> 20 13 21 #include "ppSub.h" 22 14 23 #define WCS_TOLERANCE 0.001 // Tolerance for WCS 15 24 16 bool ppSubReadoutSubtract (pmConfig *config, const pmFPAview *view) { 25 bool ppSubReadoutSubtract(pmConfig *config, const pmFPAview *view) 26 { 27 psAssert(config, "Require configuration"); 28 psAssert(view, "Require view"); 17 29 18 bool mdok = false;19 30 20 31 // Look up recipe values 21 psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSUB_RECIPE); // Recipe for ppSim 32 bool mdok = false; // Status of MD lookup 33 psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSUB_RECIPE); // Recipe for ppSub 22 34 psAssert(recipe, "We checked this earlier, so it should be here."); 23 35 … … 25 37 26 38 // Subtraction is: minuend - subtrahend 27 pmReadout *minuend = NULL; 28 pmReadout *subtrahend = NULL; 39 pmReadout *minuend = NULL; // Positive image 40 pmReadout *subtrahend = NULL; // Negative image 29 41 if (reverse) { 30 42 minuend = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV"); … … 59 71 outRO->mask = (psImage*)psBinaryOp(outRO->mask, minuend->mask, "|", subtrahend->mask); 60 72 73 psArray *covars = psArrayAlloc(2); // Covariance pseudo-matrices 74 covars->data[0] = psMemIncrRefCounter(minuend->covariance); 75 covars->data[1] = psMemIncrRefCounter(subtrahend->covariance); 76 outRO->covariance = psImageCovarianceSum(covars); 77 psFree(covars); 78 61 79 outRO->data_exists = true; 62 80 outRO->parent->data_exists = true; … … 65 83 pmSubtractionVisualShowSubtraction(minuend->image, subtrahend->image, outRO->image); 66 84 67 // copy concepts from the input to the output (XXX should this always use minuend?) 68 pmFPAfile *inFile = psMetadataLookupPtr (&mdok, config->files, "PPSUB.INPUT"); 69 pmFPA *inFPA = inFile->fpa; 70 71 pmFPAfile *outFile = psMetadataLookupPtr (&mdok, config->files, "PPSUB.OUTPUT"); 72 pmFPA *outFPA = outFile->fpa; 73 85 // Copy concepts from the input to the output 86 pmFPAfile *inFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.INPUT"); // Input file 87 pmFPA *inFPA = inFile->fpa; // Input FPA 88 pmFPAfile *outFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.OUTPUT"); // Output file 89 pmFPA *outFPA = outFile->fpa; // Output FPA 74 90 if (!pmFPACopyConcepts(outFPA, inFPA)) { 75 91 psError(PS_ERR_UNKNOWN, false, "Unable to copy concepts from input to output."); … … 78 94 } 79 95 80 // get the HDUs and output Chip to copy the astrometry81 pmHDU *inHDU = inFPA->hdu; // input HDU82 pmHDU * outHDU = outFPA->hdu;83 pm Chip *outChip = pmFPAfileThisChip(config->files, view, "PPSUB.OUTPUT");84 96 // Copy astrometry over 97 // It should find its way into the output images and photometry 98 pmHDU *inHDU = inFPA->hdu; // Input HDU 99 pmHDU *outHDU = outFPA->hdu; // Output HDU 100 pmChip *outChip = pmFPAfileThisChip(config->files, view, "PPSUB.OUTPUT"); // Output chip 85 101 if (!outHDU || !inHDU) { 86 102 psError(PS_ERR_UNKNOWN, false, "Unable to find HDU at FPA level to copy astrometry."); 87 103 return false; 88 104 } 89 90 // Copy astrometry over91 // It should get into the output images and photometry92 105 if (!pmAstromReadWCS(outFPA, outChip, inHDU->header, 1.0)) { 93 106 psError(PS_ERR_UNKNOWN, false, "Unable to read WCS astrometry from input FPA."); 94 107 return false; 95 108 } 96 97 109 if (!pmAstromWriteWCS(outHDU->header, outFPA, outChip, WCS_TOLERANCE)) { 98 110 psError(PS_ERR_UNKNOWN, false, "Unable to write WCS astrometry to output FPA."); … … 102 114 return true; 103 115 } 104 105 // XXX this test code was in place to check for and squash unexpected NANs106 107 #if 0108 pmReadoutMaskApply(outRO, maskBad);109 110 for (int y = 0; y < outRO->image->numRows; y++) {111 for (int x = 0; x < outRO->image->numCols; x++) {112 if (isnan(outRO->image->data.F32[y][x]) && !(outRO->mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal)) {113 printf("Unmasked NAN at %d %d --> %d\n", x, y, outRO->mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x]);114 }115 }116 }117 #endif118 -
trunk/ppSub/src/ppSubReadoutUpdate.c
r21396 r21524 6 6 * 7 7 * @author IfA 8 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $9 * @date $Date: 2009-02- 07 00:15:00 $8 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2009-02-18 00:31:20 $ 10 10 * Copyright 2009 Institute for Astronomy, University of Hawaii 11 11 */ 12 12 13 #ifdef HAVE_CONFIG_H 14 #include <config.h> 15 #endif 16 17 #include <stdio.h> 18 #include <pslib.h> 19 #include <psmodules.h> 20 13 21 #include "ppSub.h" 14 22 15 /** 16 * Renormalize, update headers and generate JPEGs 17 */18 bool ppSubReadoutUpdate (pmConfig *config, const pmFPAview *view) { 23 bool ppSubReadoutUpdate(pmConfig *config, psMetadata *stats, const pmFPAview *view) 24 { 25 psAssert(config, "Require configuration"); 26 psAssert(view, "Require view"); 19 27 20 bool mdok = false; 28 bool mdok = false; // Status of MD lookup 21 29 22 30 // Look up recipe values … … 24 32 psAssert(recipe, "We checked this earlier, so it should be here."); 25 33 26 // select the output readout 27 pmReadout *outRO = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT"); 28 29 // Renormalising for pixels, because that's what magic desires 30 if (!ppSubReadoutRenormPixels (config, recipe, outRO)) { 31 psError(PS_ERR_BAD_PARAMETER_VALUE, false, "failure in renormalization"); 32 return false; 33 } 34 35 // select the output FPA and HDU to get the output header 36 pmFPAfile *outFile = psMetadataLookupPtr (&mdok, config->files, "PPSUB.OUTPUT"); 37 pmFPA *outFPA = outFile->fpa; 38 pmHDU *outHDU = outFPA->hdu; 34 pmFPAfile *outFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.OUTPUT"); // Output file 35 pmReadout *outRO = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT"); // Output image 36 pmFPA *outFPA = outFile->fpa; // Output FPA 37 pmHDU *outHDU = outFPA->hdu; // Output HDU 39 38 40 39 // Add additional data to the header … … 46 45 "Subtraction input", inFile->filename); 47 46 47 // Statistics on the matching 48 if (stats) { 49 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MODE); 50 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_STAMPS); 51 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_DEV_MEAN); 52 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_DEV_RMS); 53 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_NORM); 54 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_BGDIFF); 55 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MX); 56 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MY); 57 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MXX); 58 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MXY); 59 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MYY); 60 61 psMetadataAddF32(stats, PS_LIST_TAIL, "TIME_MATCH", 0, "Time to match PSFs", 62 psTimerClear("PPSUB_MATCH")); 63 } 64 48 65 // Generate binned JPEGs 49 66 { … … 54 71 55 72 // Target cells 56 pmCell *cell1 = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT.JPEG1"); 57 pmCell *cell2 = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT.JPEG2"); 73 pmCell *cell1 = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT.JPEG1"); // Rebinned cell once 74 pmCell *cell2 = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT.JPEG2"); // Rebinned cell twice 58 75 59 pmReadout *ro1 = pmReadoutAlloc(cell1); 60 pmReadout *ro2 = pmReadoutAlloc(cell2); // Binned readouts 76 pmReadout *ro1 = pmReadoutAlloc(cell1), *ro2 = pmReadoutAlloc(cell2); // Binned readouts 61 77 if (!pmReadoutRebin(ro1, outRO, maskBad, bin1, bin1)) { 62 78 psError(PS_ERR_UNKNOWN, false, "Unable to bin output (1st binning)"); -
trunk/ppSub/src/ppSubSetMasks.c
r21360 r21524 6 6 * 7 7 * @author IfA 8 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $9 * @date $Date: 2009-02- 06 01:37:17$8 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2009-02-18 00:31:20 $ 10 10 * Copyright 2009 Institute for Astronomy, University of Hawaii 11 11 */ 12 12 13 #ifdef HAVE_CONFIG_H 14 #include <config.h> 15 #endif 16 17 #include <stdio.h> 18 #include <pslib.h> 19 #include <psmodules.h> 20 #include <psphot.h> 21 13 22 #include "ppSub.h" 14 23 15 /** this function generates (if needed) and sets or updates the masks for both the input and 16 * reference images. this function also has the code for interpolation over bad pixels, but it 17 * is currently if-def-ed out18 */24 bool ppSubSetMasks(pmConfig *config, const pmFPAview *view) 25 { 26 psAssert(config, "Require configuration"); 27 psAssert(view, "Require view"); 19 28 20 bool ppSubSetMasks (pmConfig *config, const pmFPAview *view) { 21 22 psImageMaskType maskValue; 23 psImageMaskType markValue; 24 bool mdok = false; 25 29 psImageMaskType maskValue, markValue; // Mask values 26 30 if (!pmConfigMaskSetBits(&maskValue, &markValue, config)) { 27 31 psError(PS_ERR_UNKNOWN, false, "Unable to determine mask value."); … … 29 33 } 30 34 31 // set the mask bits needed by psphot (in psphot recipe)35 // Set the mask bits needed by psphot (in psphot recipe) 32 36 psphotSetMaskRecipe (config, maskValue, markValue); 33 37 34 38 // Look up recipe values 35 psMetadata *recipe = psMetadataLookupMetadata( &mdok, config->recipes, PPSUB_RECIPE); // Recipe for ppSim39 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim 36 40 psAssert(recipe, "We checked this earlier, so it should be here."); 37 41 38 42 psImageMaskType satValue = pmConfigMaskGet("SAT", config); 39 psAssert (satValue, "SAT must be non-zero");43 psAssert(satValue, "SAT must be non-zero"); 40 44 41 45 psImageMaskType badValue = pmConfigMaskGet("BAD", config); 42 psAssert (badValue, "BAD must be non-zero");46 psAssert(badValue, "BAD must be non-zero"); 43 47 44 48 // input images … … 49 53 psImage *reference = refRO->image; // Reference image 50 54 PS_ASSERT_IMAGES_SIZE_EQUAL(input, reference, false); 51 52 // XXX use psImageCopy below to avoid caring about image dimensions 53 int numCols = input->numCols; 54 int numRows = input->numRows; 55 int numCols = input->numCols, numRows = input->numRows; // Size of image 55 56 56 57 // Generate masks if they don't exist … … 78 79 } 79 80 if (!pmReadoutMaskNonfinite(refRO, satValue)) { 80 psError(PS_ERR_UNKNOWN, false, "Unable to mask non-finite pixels in reference.");81 return false;81 psError(PS_ERR_UNKNOWN, false, "Unable to mask non-finite pixels in reference."); 82 return false; 82 83 } 83 84 84 #if (0)85 // Look up recipe values86 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim87 psAssert(recipe, "We checked this earlier, so it should be here.");88 85 86 #if 0 87 // Interpolation over bad pixels: this takes a while! 89 88 bool mdok = false; 90 91 89 psString interpModeStr = psMetadataLookupStr(&mdok, recipe, "INTERPOLATION"); // Interpolation mode 92 90 psImageInterpolateMode interpMode = psImageInterpolateModeFromString(interpModeStr); // Interp … … 102 100 // Interpolate over bad pixels, so the bad pixels don't explode 103 101 if (!pmReadoutInterpolateBadPixels(inRO, maskVal, interpMode, poorFrac, maskPoor, maskBad)) { 104 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate bad pixels for input image.");105 return false;102 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate bad pixels for input image."); 103 return false; 106 104 } 107 105 if (!pmReadoutInterpolateBadPixels(refRO, maskVal, interpMode, poorFrac, maskPoor, maskBad)) { 108 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate bad pixels for reference image.");109 return false;106 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate bad pixels for reference image."); 107 return false; 110 108 } 111 109 maskVal |= maskBad; -
trunk/ppSub/src/ppSubVarianceFactors.c
r21374 r21524 6 6 * 7 7 * @author IfA 8 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $9 * @date $Date: 2009-02- 06 03:20:02$8 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2009-02-18 00:31:20 $ 10 10 * Copyright 2009 Institute for Astronomy, University of Hawaii 11 11 */ … … 96 96 vfItem->data.F32 = vf; 97 97 98 // Statistics on the matching99 if (stats) {100 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MODE);101 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_STAMPS);102 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_DEV_MEAN);103 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_DEV_RMS);104 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_NORM);105 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_BGDIFF);106 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MX);107 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MY);108 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MXX);109 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MXY);110 psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MYY);111 112 psMetadataAddF32(stats, PS_LIST_TAIL, "TIME_MATCH", 0, "Time to match PSFs",113 psTimerClear("PPSUB_MATCH"));114 }115 116 98 return true; 117 99 } -
trunk/ppSub/src/ppSubVersion.c
r21360 r21524 6 6 * 7 7 * @author IfA 8 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $9 * @date $Date: 2009-02- 06 01:37:17$8 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2009-02-18 00:31:20 $ 10 10 * Copyright 2009 Institute for Astronomy, University of Hawaii 11 11 */ 12 13 #ifdef HAVE_CONFIG_H 14 #include <config.h> 15 #endif 16 17 #include <stdio.h> 18 #include <pslib.h> 19 #include <psmodules.h> 20 #include <ppStats.h> 12 21 13 22 #include "ppSub.h"
Note:
See TracChangeset
for help on using the changeset viewer.
