Changeset 17672 for branches/eam_branch_20080511/ppSim/src/ppSimCreate.c
- Timestamp:
- May 13, 2008, 4:56:38 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080511/ppSim/src/ppSimCreate.c
r17630 r17672 1 1 # include "ppSim.h" 2 3 // XXX this function forces us to define the camera (on the command line) and format (via the4 // PPSIM.OUTPUT entry). In this case, we need to set config->format,formatName based on these5 // values. This will be a problem when we want to load an input image (in order to add fake6 // stars). We will need to add some logic in ppSimArguments to distinguish the cases of 1)7 // input image and 2) specified camera8 2 9 3 pmFPAfile *ppSimCreate(pmConfig *config) … … 30 24 return NULL; 31 25 } 32 33 26 } else { 34 27 simImage = false; … … 37 30 return NULL; 38 31 } 39 fpa = input->fpa;32 fpa = psMemIncrRefCounter (input->fpa); 40 33 } 41 34 42 35 // define the output image file -- this is the basis for the ppSimLoop 43 pmFPAfile * file= pmFPAfileDefineOutput(config, fpa, OUTPUT_FILE);44 if (! file) {36 pmFPAfile *output = pmFPAfileDefineOutput(config, fpa, OUTPUT_FILE); 37 if (!output) { 45 38 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to create output file from %s. " 46 39 "Did you forget to specify the format?", OUTPUT_FILE); 47 40 return NULL; 48 41 } 49 if ( file->type != PM_FPA_FILE_IMAGE) {42 if (output->type != PM_FPA_FILE_IMAGE) { 50 43 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "%s type is not IMAGE", OUTPUT_FILE); 51 44 psFree(fpa); 52 psFree(file);53 45 return NULL; 54 46 } 55 47 // XXX we should not require the output image to be written 56 file->save = true;48 output->save = true; 57 49 58 config->format = psMemIncrRefCounter (file->format); 59 config->formatName = psStringCopy (file->formatName); 50 config->format = psMemIncrRefCounter (output->format); 51 config->formatName = psStringCopy (output->formatName); 52 53 psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe 60 54 61 55 // For photometry, we operate on the chip-mosaicked image. we create a copy of the mosaicked 62 56 // image for psphot so we can write out a clean image 63 if (options->doPhotom) { 57 bool doPhotom = psMetadataLookupBool(&status, recipe, "PHOTOM"); // Density of fakes 58 if (doPhotom) { 64 59 65 60 // we need a chip image if we perform photometry (is it necessary to build it if we don't use it?) … … 67 62 if (!chipImage) { 68 63 psError(PS_ERR_IO, false, _("Unable to generate new file from PPSIM.CHIP")); 69 psFree( options);64 psFree(fpa); 70 65 return NULL; 71 66 } 72 67 if (chipImage->type != PM_FPA_FILE_IMAGE) { 73 68 psError(PS_ERR_IO, true, "PPSIM.CHIP is not of type IMAGE"); 74 psFree( options);69 psFree(fpa); 75 70 return NULL; 76 71 } … … 84 79 if (!psphotDefineFiles (config, psphotInput)) { 85 80 psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psphot"); 86 return false; 81 psFree(fpa); 82 return NULL; 87 83 } 88 84 } else { … … 92 88 if (psMetadataLookupPtr(NULL, config->arguments, "PSPHOT.PSF")) { 93 89 // tie the psf file to the chipMosaic 94 pmFPAfileBindFromArgs(&status, file, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF");90 pmFPAfileBindFromArgs(&status, output, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF"); 95 91 if (!status) { 96 92 psError(PS_ERR_UNKNOWN, false, "Failed to find/build PSPHOT.PSF.LOAD"); 97 93 psFree(fpa); 98 psFree(file);99 94 return NULL; 100 95 } … … 104 99 // PPSIM.SOURCES carries the constructed, fake sources with their true parameters 105 100 // XXX only invoke this code for OBJECT types of images 106 pmFPAfile *simSources = pmFPAfileDefineOutput (config, file->fpa, "PPSIM.SOURCES");101 pmFPAfile *simSources = pmFPAfileDefineOutput (config, output->fpa, "PPSIM.SOURCES"); 107 102 if (!simSources) { 108 103 psError(PS_ERR_UNKNOWN, false, "Cannot find a rule for PPSIM.SOURCES"); … … 113 108 // if we have loaded an input image, we do not need to populate the fpa 114 109 if (!simImage) { 115 return file; 110 // we need to extract certain metadata from the image and populate the recipe. 111 // or else we need to set the fpa concepts based on the recipe options... 112 113 psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe 114 115 ppSimArgToRecipeF32(&status, recipe, "EXPTIME", fpa->concepts, "FPA.EXPOSURE"); 116 char *filter = ppSimArgToRecipeStr(&status, recipe, "FILTER", fpa->concepts, "FPA.FILTER"); 117 118 float zp = ppSimGetZeroPoint (recipe, filter); 119 psMetadataAddF32(recipe, PS_LIST_TAIL, "ZEROPOINT", PS_META_REPLACE, "Photometric zeropoint", zp); 120 121 return output; 116 122 } 117 123 118 pmFPALevel phuLevel = pmFPAPHULevel( file->format); // Level at which PHU goes124 pmFPALevel phuLevel = pmFPAPHULevel(output->format); // Level at which PHU goes 119 125 120 126 pmFPAview *view = pmFPAviewAlloc(0);// View for current level 121 127 122 128 if (phuLevel == PM_FPA_LEVEL_FPA) { 123 if (!pmFPAAddSourceFromView(fpa, "Simulation", view, file->format)) {129 if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) { 124 130 psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA."); 125 131 psFree(fpa); 126 132 psFree(view); 127 psFree(file);128 133 return NULL; 129 134 } … … 133 138 while ((chip = pmFPAviewNextChip(view, fpa, 1))) { 134 139 if (phuLevel == PM_FPA_LEVEL_CHIP) { 135 if (!pmFPAAddSourceFromView(fpa, "Simulation", view, file->format)) {140 if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) { 136 141 psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA."); 137 142 psFree(fpa); 138 143 psFree(view); 139 psFree(file);140 144 return NULL; 141 145 } … … 145 149 while ((cell = pmFPAviewNextCell(view, fpa, 1))) { 146 150 if (phuLevel == PM_FPA_LEVEL_CELL) { 147 if (!pmFPAAddSourceFromView(fpa, "Simulation", view, file->format)) {151 if (!pmFPAAddSourceFromView(fpa, "Simulation", view, output->format)) { 148 152 psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA."); 149 153 psFree(fpa); 150 154 psFree(view); 151 psFree(file);152 155 return NULL; 153 156 } … … 159 162 psFree(view); 160 163 161 return file;164 return output; 162 165 }
Note:
See TracChangeset
for help on using the changeset viewer.
