Changeset 17818
- Timestamp:
- May 27, 2008, 7:12:46 PM (18 years ago)
- Location:
- branches/eam_branch_20080511/ppSim
- Files:
-
- 4 added
- 10 edited
-
notes.txt (modified) (1 diff)
-
src/Makefile.am (modified) (1 diff)
-
src/ppSim.h (modified) (3 diffs)
-
src/ppSimCreate.c (modified) (1 diff)
-
src/ppSimDetectionLimits.c (added)
-
src/ppSimDetections.c (added)
-
src/ppSimInsertStars.c (modified) (2 diffs)
-
src/ppSimLoadForceSources.c (modified) (2 diffs)
-
src/ppSimLoop.c (modified) (3 diffs)
-
src/ppSimMergeReadouts.c (modified) (2 diffs)
-
src/ppSimMergeSources.c (added)
-
src/ppSimPhotom.c (modified) (2 diffs)
-
src/ppSimPhotomFiles.c (added)
-
src/ppSimPhotomReadout.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080511/ppSim/notes.txt
r17709 r17818 1 2 3 2008.05.17 4 5 pmFPAfiles used in ppSim: 6 7 PPSIM.INPUT : an input image loaded by ppSim; the simulated features 8 may be added to this image. In fact, the features are 9 generated in the output image, and the two images are 10 added (as images) together. 11 12 PPSIM.OUTPUT : the output image. this file is used for the main 13 ppSimLoop function 14 15 PPSIM.CHIP : chip-mosaiced version of the output image. only 16 generated if photometry is requested. Is this 17 actually used as an output image? 18 19 PPSIM.REAL.SOURCES : real sources loaded by PPSIM. these sources 20 are subtracted from the image before testing 21 for the detectability of the fake sources and 22 before measuring the flux of fake or forced 23 soures. They should be the sources measured in 24 a previous psphot run, though any input list 25 could be used. Results are very ill-defined if 26 the sources do not correspond to actual image 27 sources! 28 29 PSPHOT.PSF.LOAD : input PSF model used to measure the input sources 30 31 PPSIM.SOURCES : output fake sources (injected fake sources with real values) 32 PPSIM.FAKE.SOURCES : output fake photometry (measured photometry for all fake sources) 33 PPSIM.FORCE.SOURCES : output force photometry 34 35 ** used within psphot functions: 36 PSPHOT.BACKMDL : model background generated by psphotModelBackground 37 PSPHOT.BACKMDL.STDEV : model background error generated by psphotModelBackground 38 PSPHOT.BACKGND : full-scale model background generated by psphotSubtractBackground 39 PSPHOT.BACKSUB : background-subtracted image 1 40 2 41 2008.05.15 -
branches/eam_branch_20080511/ppSim/src/Makefile.am
r17705 r17818 26 26 ppSimLoadSpots.c \ 27 27 ppSimPhotom.c \ 28 ppSimPhotomReadout.c \ 29 ppSimPhotomFiles.c \ 30 ppSimLoadForceSources.c \ 28 31 ppSimMergeReadouts.c \ 32 ppSimDetections.c \ 33 ppSimMergeSources.c \ 29 34 ppSimMosaicChip.c \ 30 35 ppSimRandomGaussian.c \ -
branches/eam_branch_20080511/ppSim/src/ppSim.h
r17705 r17818 16 16 17 17 #define PPSIM_RECIPE "PPSIM" 18 #define OUTPUT_FILE "PPSIM.OUTPUT"18 // #define OUTPUT_FILE "PPSIM.OUTPUT" 19 19 20 20 // Compare a value with minimum and maximum values, replacing where required. … … 174 174 float ppSimGetZeroPoint (psMetadata *recipe, char *filter); 175 175 176 bool ppSimMergeReadouts (pm Readout *outReadout, pmReadout *inReadout);176 bool ppSimMergeReadouts (pmConfig *config, pmFPAview *view); 177 177 178 178 double ppSimRandomGaussian (const psRandom *rnd, double mean, double sigma); … … 180 180 void ppSimRandomGaussianFree(); 181 181 182 bool ppSimPhotomFiles (pmConfig *config, pmFPAfile *input); 183 bool ppSimPhotomReadout(pmConfig *config, const pmFPAview *view); 184 psArray *ppSimLoadForceSources(pmConfig *config, const pmFPAview *view); 185 bool ppSimDetections (psImage *significance, psMetadata *recipe, psArray *sources); 186 psArray *ppSimMergeSources (psArray *in1, psArray *in2); 187 182 188 #endif -
branches/eam_branch_20080511/ppSim/src/ppSimCreate.c
r17706 r17818 3 3 pmFPAfile *ppSimCreate(pmConfig *config) 4 4 { 5 bool status;6 bool simImage = false;7 PS_ASSERT_PTR_NON_NULL(config, NULL);8 pmFPA *fpa = NULL;5 bool status; 6 bool simImage = false; 7 PS_ASSERT_PTR_NON_NULL(config, NULL); 8 pmFPA *fpa = NULL; 9 9 10 // the input image defines the camera. if it is not supplied, the user must have 11 // supplied a camera and other metadata on the command line 12 pmFPAfile *input = pmFPAfileDefineFromArgs (&status, config, "PPIMAGE.INPUT", "INPUT"); 13 if (!input) { 14 // if we have not specified the camera already, we need to interpolate the recipes associated with this camera, and read other command-line recipes 15 if (!pmConfigReadRecipes(config, PM_RECIPE_SOURCE_CL)) { 16 psError(PS_ERR_IO, false, "Error merging recipes from camera config for %s", config->cameraName); 17 return NULL; 18 } 19 } else { 20 // If an image is supplied, we still generate a fake image and merge them together downstream 21 // (otherwise, we get the variance wrong). 22 simImage = false; 23 if (input->type != PM_FPA_FILE_IMAGE) { 24 psError(PS_ERR_IO, true, "PPIMAGE.INPUT is not of type IMAGE"); 25 return NULL; 26 } 10 // the input image defines the camera. if it is not supplied, the user must have 11 // supplied a camera and other metadata on the command line 12 pmFPAfile *input = pmFPAfileDefineFromArgs (&status, config, "PPSIM.INPUT", "INPUT"); 13 if (!input) { 14 // if we have not specified the camera already, we need to interpolate the recipes associated with this camera, and read other command-line recipes 15 if (!pmConfigReadRecipes(config, PM_RECIPE_SOURCE_CL)) { 16 psError(PS_ERR_IO, false, "Error merging recipes from camera config for %s", config->cameraName); 17 return NULL; 27 18 } 19 } else { 20 // If an image is supplied, we still generate a fake image and merge them together downstream 21 // (otherwise, we get the variance wrong). 22 simImage = false; 23 if (input->type != PM_FPA_FILE_IMAGE) { 24 psError(PS_ERR_IO, true, "PPSIM.INPUT is not of type IMAGE"); 25 return NULL; 26 } 27 } 28 28 29 // generate the fpa structure used by the output camera (determined from INPUT or specified) 30 assert (config->camera); 31 fpa = pmFPAConstruct(config->camera); // FPA to contain the observation 32 if (!fpa) { 33 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to construct an FPA from camera configuration."); 29 // generate the fpa structure used by the output camera (determined from INPUT or specified) 30 assert (config->camera); 31 fpa = pmFPAConstruct(config->camera); // FPA to contain the observation 32 if (!fpa) { 33 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to construct an FPA from camera configuration."); 34 return NULL; 35 } 36 37 // define the output image file -- this is the basis for the ppSimLoop 38 pmFPAfile *output = pmFPAfileDefineOutput(config, fpa, "PPSIM.OUTPUT"); 39 if (!output) { 40 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to create output file from PPSIM.OUTPUT. Did you forget to specify the format?"); 41 return NULL; 42 } 43 if (output->type != PM_FPA_FILE_IMAGE) { 44 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "PPSIM.OUTPUT type is not IMAGE"); 45 psFree(fpa); 46 return NULL; 47 } 48 // XXX we should not require the output image to be written 49 output->save = true; 50 51 config->format = psMemIncrRefCounter (output->format); 52 config->formatName = psStringCopy (output->formatName); 53 54 // the recipe is now fully realized for the desired camera 55 psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe 56 57 char *typeStr = psMetadataLookupStr(NULL, recipe, "IMAGE.TYPE"); // Type of image to simulate 58 ppSimType type = ppSimTypeFromString (typeStr); // Type of image to simulate 59 60 if (type == PPSIM_TYPE_OBJECT) { 61 // adjust the seeing by the scale 62 float seeing = psMetadataLookupF32(&status, recipe, "SEEING"); 63 if (isnan(seeing)) { 64 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "seeing is not defined"); 65 psFree(fpa); 66 return NULL; 67 } 68 float scale = psMetadataLookupF32(&status, recipe, "PIXEL.SCALE"); 69 if (isnan(scale)) { 70 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "pixel scale is not defined"); 71 psFree(fpa); 72 return NULL; 73 } 74 psMetadataAddF32(recipe, PS_LIST_TAIL, "SEEING", PS_META_REPLACE, "Seeing SIGMA (pixels)", seeing / 2.0 / sqrt(2.0 * log(2.0)) / scale); 75 } 76 77 if ((type == PPSIM_TYPE_OBJECT) || (type == PPSIM_TYPE_FLAT)) { 78 // determine the zeropoint from the filter 79 float zp = psMetadataLookupF32(&status, recipe, "ZEROPOINT"); 80 if (isnan(zp)) { 81 char *filter = psMetadataLookupStr(&status, recipe, "FILTER"); 82 float zp = ppSimGetZeroPoint (recipe, filter); 83 psMetadataAddF32(recipe, PS_LIST_TAIL, "ZEROPOINT", PS_META_REPLACE, "Photometric zeropoint", zp); 84 } 85 } 86 87 // For photometry, we operate on the chip-mosaicked image. we create a copy of the mosaicked 88 // image for psphot so we can write out a clean image 89 bool doPhotom = psMetadataLookupBool(&status, recipe, "PHOTOM"); // Density of fakes 90 if (doPhotom) { 91 92 // we need a chip image if we perform photometry (is it necessary to build it if we don't use it?) 93 pmFPAfile *chipImage = pmFPAfileDefineChipMosaic(config, output->fpa, "PPSIM.CHIP"); 94 if (!chipImage) { 95 psError(PS_ERR_IO, false, _("Unable to generate new file from PPSIM.CHIP")); 96 psFree(fpa); 97 return NULL; 98 } 99 if (chipImage->type != PM_FPA_FILE_IMAGE) { 100 psError(PS_ERR_IO, true, "PPSIM.CHIP is not of type IMAGE"); 101 psFree(fpa); 34 102 return NULL; 35 103 } 36 104 37 // define the output image file -- this is the basis for the ppSimLoop 38 pmFPAfile *output = pmFPAfileDefineOutput(config, fpa, OUTPUT_FILE); 39 if (!output) { 40 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to create output file from %s. " 41 "Did you forget to specify the format?", OUTPUT_FILE); 42 return NULL; 105 // define associated psphot input/output files 106 if (!ppSimPhotomFiles (config, chipImage)) { 107 psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psphot"); 108 psFree(fpa); 109 return NULL; 43 110 } 44 if (output->type != PM_FPA_FILE_IMAGE) { 45 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "%s type is not IMAGE", OUTPUT_FILE); 111 } else { 112 // have we supplied a psf model? this happens in ppSimPhotomFiles if we request a photometry 113 // analysis. however, even if we do not, a psf model may be used to generate the fake 114 // sources. 115 if (psMetadataLookupPtr(NULL, config->arguments, "PSPHOT.PSF")) { 116 // tie the psf file to the chipMosaic 117 pmFPAfileBindFromArgs(&status, output, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF"); 118 if (!status) { 119 psError(PS_ERR_UNKNOWN, false, "Failed to find/build PSPHOT.PSF.LOAD"); 46 120 psFree(fpa); 47 return NULL; 121 return NULL; 122 } 48 123 } 49 // XXX we should not require the output image to be written 50 output->save = true; 124 } 51 125 52 config->format = psMemIncrRefCounter (output->format); 53 config->formatName = psStringCopy (output->formatName); 126 // PPSIM.SOURCES carries the constructed, fake sources with their true parameters 127 // XXX only invoke this code for OBJECT types of images? 128 pmFPAfile *simSources = pmFPAfileDefineOutput (config, output->fpa, "PPSIM.SOURCES"); 129 if (!simSources) { 130 psError(PS_ERR_UNKNOWN, false, "Cannot find a rule for PPSIM.SOURCES"); 131 return false; 132 } 133 simSources->save = true; 54 134 55 // the recipe is now fully realized for the desired camera 135 // if we have loaded an input image, we derive certain values from the image, if possible 136 if (input) { 137 // we need to extract certain metadata from the image and populate the recipe. 138 // or else we need to set the fpa concepts based on the recipe options... 139 56 140 psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe 57 141 58 char *typeStr = psMetadataLookupStr(NULL, recipe, "IMAGE.TYPE"); // Type of image to simulate59 ppSimType type = ppSimTypeFromString (typeStr); // Type of image to simulate142 ppSimArgToRecipeF32(&status, recipe, "EXPTIME", input->fpa->concepts, "FPA.EXPOSURE"); 143 char *filter = ppSimArgToRecipeStr(&status, recipe, "FILTER", input->fpa->concepts, "FPA.FILTER"); 60 144 61 if (type == PPSIM_TYPE_OBJECT) { 62 // adjust the seeing by the scale 63 float seeing = psMetadataLookupF32(&status, recipe, "SEEING"); 64 if (isnan(seeing)) { 65 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "seeing is not defined"); 66 psFree(fpa); 67 return NULL; 68 } 69 float scale = psMetadataLookupF32(&status, recipe, "PIXEL.SCALE"); 70 if (isnan(scale)) { 71 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "pixel scale is not defined"); 72 psFree(fpa); 73 return NULL; 74 } 75 psMetadataAddF32(recipe, PS_LIST_TAIL, "SEEING", PS_META_REPLACE, "Seeing SIGMA (pixels)", seeing / 2.0 / sqrt(2.0 * log(2.0)) / scale); 145 float zp = ppSimGetZeroPoint (recipe, filter); 146 psMetadataAddF32(recipe, PS_LIST_TAIL, "ZEROPOINT", PS_META_REPLACE, "Photometric zeropoint", zp); 147 } 148 149 pmFPALevel phuLevel = pmFPAPHULevel(output->format); // Level at which PHU goes 150 151 pmFPAview *view = pmFPAviewAlloc(0);// View for current level 152 153 if (phuLevel == PM_FPA_LEVEL_FPA) { 154 if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) { 155 psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA."); 156 psFree(fpa); 157 psFree(view); 158 return NULL; 159 } 160 } 161 162 pmChip *chip; // Chip from FPA 163 while ((chip = pmFPAviewNextChip(view, fpa, 1))) { 164 if (phuLevel == PM_FPA_LEVEL_CHIP) { 165 if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) { 166 psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA."); 167 psFree(fpa); 168 psFree(view); 169 return NULL; 170 } 76 171 } 77 172 78 if ((type == PPSIM_TYPE_OBJECT) || (type == PPSIM_TYPE_FLAT)) { 79 // determine the zeropoint from the filter 80 float zp = psMetadataLookupF32(&status, recipe, "ZEROPOINT"); 81 if (isnan(zp)) { 82 char *filter = psMetadataLookupStr(&status, recipe, "FILTER"); 83 float zp = ppSimGetZeroPoint (recipe, filter); 84 psMetadataAddF32(recipe, PS_LIST_TAIL, "ZEROPOINT", PS_META_REPLACE, "Photometric zeropoint", zp); 173 pmCell *cell; // Cell from chip 174 while ((cell = pmFPAviewNextCell(view, fpa, 1))) { 175 if (phuLevel == PM_FPA_LEVEL_CELL) { 176 if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) { 177 psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA."); 178 psFree(fpa); 179 psFree(view); 180 return NULL; 85 181 } 182 } 86 183 } 184 } 87 185 88 // For photometry, we operate on the chip-mosaicked image. we create a copy of the mosaicked 89 // image for psphot so we can write out a clean image 90 bool doPhotom = psMetadataLookupBool(&status, recipe, "PHOTOM"); // Density of fakes 91 if (doPhotom) { 186 psFree(fpa); 187 psFree(view); 92 188 93 // we need a chip image if we perform photometry (is it necessary to build it if we don't use it?) 94 pmFPAfile *chipImage = pmFPAfileDefineChipMosaic(config, output->fpa, "PPSIM.CHIP"); 95 if (!chipImage) { 96 psError(PS_ERR_IO, false, _("Unable to generate new file from PPSIM.CHIP")); 97 psFree(fpa); 98 return NULL; 99 } 100 if (chipImage->type != PM_FPA_FILE_IMAGE) { 101 psError(PS_ERR_IO, true, "PPSIM.CHIP is not of type IMAGE"); 102 psFree(fpa); 103 return NULL; 104 } 105 106 // *** Define two input files: 107 // PPSIM.REAL.SOURCES 108 109 // the input image(s) are required arguments; they define the camera 110 pmFPAfile *realSources = pmFPAfileDefineFromArgs (&status, config, "PPSIM.REAL.SOURCES", "REAL.SOURCES"); 111 if (!status) { 112 psError(PS_ERR_UNKNOWN, false, "Failed to build FPA from PPSIM.REAL.SOURCES"); 113 return false; 114 } 115 116 // this file is just used as a carrier; output files (eg, PSPHOT.RESID) are defined by 117 // psphotDefineFiles 118 pmFPAfile *psphotInput = pmFPAfileDefineFromFile (config, chipImage, 1, 1, "PSPHOT.INPUT"); 119 PS_ASSERT (psphotInput, false); 120 121 // define associated psphot input/output files 122 if (!psphotDefineFiles (config, psphotInput)) { 123 psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psphot"); 124 psFree(fpa); 125 return NULL; 126 } 127 } else { 128 // have we supplied a psf model? this happens in psphotDefineFiles if we request a photometry 129 // analysis. however, even if we do not, a psf model may be used to generate the fake 130 // sources. 131 if (psMetadataLookupPtr(NULL, config->arguments, "PSPHOT.PSF")) { 132 // tie the psf file to the chipMosaic 133 pmFPAfileBindFromArgs(&status, output, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF"); 134 if (!status) { 135 psError(PS_ERR_UNKNOWN, false, "Failed to find/build PSPHOT.PSF.LOAD"); 136 psFree(fpa); 137 return NULL; 138 } 139 } 140 } 141 142 // PPSIM.SOURCES carries the constructed, fake sources with their true parameters 143 // XXX only invoke this code for OBJECT types of images? 144 pmFPAfile *simSources = pmFPAfileDefineOutput (config, output->fpa, "PPSIM.SOURCES"); 145 if (!simSources) { 146 psError(PS_ERR_UNKNOWN, false, "Cannot find a rule for PPSIM.SOURCES"); 147 return false; 148 } 149 simSources->save = true; 150 151 // if we have loaded an input image, we derive certain values from the image, if possible 152 if (input) { 153 // we need to extract certain metadata from the image and populate the recipe. 154 // or else we need to set the fpa concepts based on the recipe options... 155 156 psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe 157 158 ppSimArgToRecipeF32(&status, recipe, "EXPTIME", input->fpa->concepts, "FPA.EXPOSURE"); 159 char *filter = ppSimArgToRecipeStr(&status, recipe, "FILTER", input->fpa->concepts, "FPA.FILTER"); 160 161 float zp = ppSimGetZeroPoint (recipe, filter); 162 psMetadataAddF32(recipe, PS_LIST_TAIL, "ZEROPOINT", PS_META_REPLACE, "Photometric zeropoint", zp); 163 } 164 165 pmFPALevel phuLevel = pmFPAPHULevel(output->format); // Level at which PHU goes 166 167 pmFPAview *view = pmFPAviewAlloc(0);// View for current level 168 169 if (phuLevel == PM_FPA_LEVEL_FPA) { 170 if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) { 171 psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA."); 172 psFree(fpa); 173 psFree(view); 174 return NULL; 175 } 176 } 177 178 pmChip *chip; // Chip from FPA 179 while ((chip = pmFPAviewNextChip(view, fpa, 1))) { 180 if (phuLevel == PM_FPA_LEVEL_CHIP) { 181 if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) { 182 psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA."); 183 psFree(fpa); 184 psFree(view); 185 return NULL; 186 } 187 } 188 189 pmCell *cell; // Cell from chip 190 while ((cell = pmFPAviewNextCell(view, fpa, 1))) { 191 if (phuLevel == PM_FPA_LEVEL_CELL) { 192 if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) { 193 psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA."); 194 psFree(fpa); 195 psFree(view); 196 return NULL; 197 } 198 } 199 } 200 } 201 202 psFree(fpa); 203 psFree(view); 204 205 return output; 189 return output; 206 190 } -
branches/eam_branch_20080511/ppSim/src/ppSimInsertStars.c
r17705 r17818 15 15 16 16 if (!stars->n) { return true; } 17 18 // XXX is this needed?19 // pmFPAfile *simSources = psMetadataLookupPtr(NULL, config->files, "PPSIM.SOURCES"); // Output sources20 17 21 18 pmCell *cell = readout->parent; … … 136 133 137 134 // NOTE: readout must be part of the pmFPAfile named "PPSIM.OUTPUT" 138 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY, "psphot sources", sources); 135 // XXX PPSIM.SOURCES are the fake sources with their *input* values 136 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PPSIM.SOURCES", PS_DATA_ARRAY, "fake sources", sources); 139 137 psFree(sources); 140 138 -
branches/eam_branch_20080511/ppSim/src/ppSimLoadForceSources.c
r17709 r17818 1 # include "ppSim.h" 2 3 psArray *ppSimLoadForceSources(pmConfig *config, const pmFPAview *view) { 4 5 # if (0) 6 1 7 // de-activate all files except PSASTRO.REFSTARS 2 8 pmFPAfileActivate (config->files, false, NULL); … … 77 83 pmFPAfileActivate (config->files, true, NULL); 78 84 pmFPAfileActivate (config->files, false, "PSASTRO.OUT.REFSTARS"); 85 # endif 86 87 return NULL; 88 } -
branches/eam_branch_20080511/ppSim/src/ppSimLoop.c
r17705 r17818 13 13 14 14 // in this program, we are looping over the output image, rather than the input as in ppImage 15 pmFPAfile *file = psMetadataLookupPtr(NULL, config->files, OUTPUT_FILE); // Output file15 pmFPAfile *file = psMetadataLookupPtr(NULL, config->files, "PPSIM.OUTPUT"); // Output file 16 16 assert(file); 17 18 // if we have an input image, we need to add the synthetic data on top of it below19 // XXX we may potentially use this input file to skip missing elements20 pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPIMAGE.INPUT");21 17 22 18 pmFPA *fpa = file->fpa; // FPA for file … … 111 107 112 108 psVector *biasCols = ppSimMakeBiassec (cell, config); 113 114 pmCell *inputCell = NULL;115 if (input) {116 inputCell = pmFPAviewThisCell (view, input->fpa);117 }118 109 119 110 for (int i = 0; i < cell->readouts->n; i++) { … … 169 160 readout->parent->parent->data_exists = true; 170 161 171 if (inputCell && inputCell->readouts->data[i]) { 172 pmReadout *inReadout = inputCell->readouts->data[i]; 173 if (!inReadout->weight) { 174 if (!pmReadoutGenerateWeight(inReadout, true)) { 175 psError (PS_ERR_UNKNOWN, false, "trouble creating weight"); 176 return false; 177 } 178 } 179 if (!ppSimMergeReadouts (readout, inReadout)) ESCAPE (PS_ERR_UNKNOWN, "problem merging input image with simulated image"); 180 } 162 // if there is an input image, merge it with the simulated image 163 if (!ppSimMergeReadouts (config, view)) ESCAPE (PS_ERR_UNKNOWN, "problem merging input image with simulated image"); 181 164 } 182 165 psFree(biasCols); -
branches/eam_branch_20080511/ppSim/src/ppSimMergeReadouts.c
r17703 r17818 2 2 3 3 // XXX add bounds to the inputs? 4 bool ppSimMergeReadouts (pm Readout *outReadout, pmReadout *inReadout) {4 bool ppSimMergeReadouts (pmConfig *config, pmFPAview *view) { 5 5 6 6 // bool mdok; 7 8 // if we have an input image, we need to add the synthetic data on top of it below 9 // XXX we may potentially use this input file to skip missing elements 10 pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPSIM.INPUT"); 11 if (!input) return true; 12 13 pmReadout *inReadout = pmFPAviewThisReadout (view, input->fpa); 14 if (!inReadout) return true; 15 16 if (!inReadout->weight) { 17 if (!pmReadoutGenerateWeight(inReadout, true)) { 18 psError (PS_ERR_UNKNOWN, false, "trouble creating weight"); 19 return false; 20 } 21 } 22 23 // output must exist or we made a programming error 24 pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PPSIM.OUTPUT"); // Output file 25 assert(output); 26 27 // XXX require outReadout? 28 pmReadout *outReadout = pmFPAviewThisReadout (view, output->fpa); 29 if (!outReadout) return true; 7 30 8 31 psImage *inSignal = inReadout->image; … … 12 35 psImage *outVariance = outReadout->weight; 13 36 14 // psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSIM_RECIPE); // Recipe15 37 assert (inSignal->numRows == outSignal->numRows); 16 38 assert (inSignal->numCols == outSignal->numCols); -
branches/eam_branch_20080511/ppSim/src/ppSimPhotom.c
r17708 r17818 18 18 ppSimMosaicChip(config, blankMask, view, "PPSIM.CHIP", "PPSIM.OUTPUT"); 19 19 20 // find or define a pmFPAfile PSPHOT.INPUT21 pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "P SPHOT.INPUT");20 // XXX have ppSimMosaicChip return the pointer? 21 pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PPSIM.CHIP"); 22 22 if (!status) { 23 psError(PSPHOT_ERR_CONFIG, false, "P SPHOT.INPUTI/O file is not defined");23 psError(PSPHOT_ERR_CONFIG, false, "PPSIM.CHIP I/O file is not defined"); 24 24 return false; 25 25 } 26 26 27 27 // we make a new copy of the output chip to keep psphot from modifying the output image 28 // XXX is this needed for ppSim? (yes, unless we do not do photometry and make a simulated image)28 // XXX is this needed for ppSim? only if we want to write out the image with and without subtracted sources 29 29 pmChip *oldChip = pmFPAviewThisChip (view, input->src); 30 30 pmChip *newChip = pmFPAviewThisChip (view, input->fpa); … … 45 45 return false; 46 46 } 47 48 47 ppSimDetectionLimits (config, view); 49 48 } -
branches/eam_branch_20080511/ppSim/src/ppSimPhotomReadout.c
r17709 r17818 1 # include "p sphotInternal.h"1 # include "ppSim.h" 2 2 3 bool p sphotReadout(pmConfig *config, const pmFPAview *view) {3 bool ppSimPhotomReadout(pmConfig *config, const pmFPAview *view) { 4 4 5 5 psTimerStart ("psphotReadout"); … … 18 18 } 19 19 20 // find the currently selected readout 21 // XXX keep this name or go with something like PPSIM.PHOT.INPUT?22 pmReadout *readout = pmFPAfileThisReadout (config->files, view, "P SPHOT.INPUT");20 // find the currently selected readout. 21 // we always perform photometry on the mosaiced chip 22 pmReadout *readout = pmFPAfileThisReadout (config->files, view, "PPSIM.CHIP"); 23 23 PS_ASSERT_PTR_NON_NULL (readout, false); 24 24 … … 27 27 28 28 // load the psf model, if suppled. FWHM_X,FWHM_Y,etc are saved in the recipe 29 // this function uses PSPHOT.PSF.LOAD as the pmFPAfile 29 30 pmPSF *psf = psphotLoadPSF (config, view, recipe); 30 31 assert (psf); … … 33 34 // PPSIM.REAL.SOURCES carries the pmSource objects (from psphot analysis or loaded externally) 34 35 psArray *realSources = psMetadataLookupPtr (NULL, readout->analysis, "PPSIM.REAL.SOURCES"); 35 psArray *fakeSources = psMetadataLookupPtr (NULL, readout->analysis, "PSPHOT.SOURCES"); 36 forceSources = ppSimLoadForceSources (config, view); 36 psArray *forceSources = ppSimLoadForceSources (config, view); 37 37 38 // replace all sources 39 psphotRemoveSources (realSources, recipe); 38 // XXX make a copy of the fake-source parameters so these can be saved independently 39 // from the measured fake-source parameters 40 psArray *injectedSources = psMetadataLookupPtr (NULL, readout->analysis, "PPSIM.SOURCES"); 41 psArray *fakeSources = psArrayAlloc (injectedSources->n); 42 for (int i = 0; i < injectedSources->n; i++) { 43 fakeSources->data[i] = pmSourceCopy (injectedSources->data[i]); 44 } 45 46 // remove all sources 47 psphotRemoveAllSources (realSources, recipe); 40 48 41 49 // generate a background model (median, smoothed image) 42 if (!psphotModelBackground (config, view, "P SPHOT.INPUT")) {50 if (!psphotModelBackground (config, view, "PPSIM.CHIP")) { 43 51 return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL); 44 52 } 45 if (!psphotSubtractBackground (config, view, "P SPHOT.INPUT")) {53 if (!psphotSubtractBackground (config, view, "PPSIM.CHIP")) { 46 54 return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL); 47 55 } … … 51 59 52 60 // XXX fake sources should measure peak->x,y, force sources should not 61 psMaskType maskVal = 0xff; 53 62 psImage *significance = psphotSignificanceImage (readout, recipe, 1, maskVal); 54 63 ppSimDetections (significance, recipe, fakeSources); … … 60 69 61 70 // replace all sources 62 psphotReplaceAll (realSources, recipe);71 psphotReplaceAllSources (realSources, recipe); 63 72 64 73 // construct an initial model for each object … … 67 76 psphotGuessModels (readout, forceSources, recipe, psf); 68 77 78 psArray *sources = NULL; 79 69 80 // linear fit to real + fake sources 70 psArray *sources = ppSimMergeSources (realSources, fakeSources);81 sources = ppSimMergeSources (realSources, fakeSources); 71 82 psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE); // XXX option to NOT subtract 72 psphotReplaceAll (sources, recipe);83 psphotReplaceAllSources (sources, recipe); 73 84 psFree (sources); // only frees the merged references 74 85 75 86 // linear fit to real + forced sources 76 psArray *sources = ppSimMergeSources (realSources, forceSources);87 sources = ppSimMergeSources (realSources, forceSources); 77 88 psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE); // XXX option to NOT subtract 78 psphotReplaceAll (sources, recipe);89 psphotReplaceAllSources (sources, recipe); 79 90 psFree (sources); // only frees the merged references 80 91 … … 85 96 if (!psphotApResid (readout, forceSources, recipe, psf)) { 86 97 psLogMsg ("psphot", 3, "failed on psphotApResid"); 87 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);98 return psphotReadoutCleanup (config, readout, recipe, NULL, psf, NULL); 88 99 } 89 100 90 // calculate source magnitudes 101 // calculate source magnitudes (for which set??) 91 102 pmReadout *background = psphotSelectBackground (config, view, false); 92 psphotMagnitudes(sources, recipe, psf, background); 103 psphotMagnitudes(fakeSources, recipe, psf, background); 104 psphotMagnitudes(forceSources, recipe, psf, background); 93 105 94 106 // drop the references to the image pixels held by each source 95 psphotSourceFreePixels (sources); 107 psphotSourceFreePixels (realSources); 108 psphotSourceFreePixels (fakeSources); 109 psphotSourceFreePixels (forceSources); 96 110 97 111 // create the exported-metadata and free local data 98 return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources); 112 // XXX this places the sources on readout->analysis as PSPHOT.SOURCES. modify? 113 // (or don't supply the sources, and do this with a different function) 114 psphotReadoutCleanup(config, readout, recipe, NULL, psf, NULL); 115 116 // add forceSources to the readout (real and fake already there) 117 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PPSIM.FAKE.SOURCES", PS_DATA_ARRAY, "fake photometry ", fakeSources); 118 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PPSIM.FORCE.SOURCES", PS_DATA_ARRAY, "forced photometry ", forceSources); 119 psFree (forceSources); 120 return true; 99 121 }
Note:
See TracChangeset
for help on using the changeset viewer.
