Changeset 17672
- Timestamp:
- May 13, 2008, 4:56:38 PM (18 years ago)
- Location:
- branches/eam_branch_20080511/ppSim
- Files:
-
- 19 edited
-
configure.ac (modified) (1 diff)
-
src/Makefile.am (modified) (1 diff)
-
src/ppSim.c (modified) (3 diffs)
-
src/ppSim.h (modified) (6 diffs)
-
src/ppSimArguments.c (modified) (6 diffs)
-
src/ppSimCreate.c (modified) (11 diffs)
-
src/ppSimInsertGalaxies.c (modified) (3 diffs)
-
src/ppSimInsertStars.c (modified) (2 diffs)
-
src/ppSimLoadSpots.c (modified) (2 diffs)
-
src/ppSimLoadStars.c (modified) (3 diffs)
-
src/ppSimLoop.c (modified) (3 diffs)
-
src/ppSimMakeBias.c (modified) (1 diff)
-
src/ppSimMakeDark.c (modified) (1 diff)
-
src/ppSimMakeGalaxies.c (modified) (5 diffs)
-
src/ppSimMakeSky.c (modified) (3 diffs)
-
src/ppSimMakeStars.c (modified) (3 diffs)
-
src/ppSimPhotom.c (modified) (1 diff)
-
src/ppSimSetPSF.c (modified) (1 diff)
-
src/ppSimUtils.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080511/ppSim/configure.ac
r14186 r17672 17 17 AC_SYS_LARGEFILE 18 18 19 PKG_CHECK_MODULES([PSLIB], [pslib >= 1.0.0])19 PKG_CHECK_MODULES([PSLIB], [pslib >= 1.0.0]) 20 20 PKG_CHECK_MODULES([PSMODULE], [psmodules >= 1.0.0]) 21 PKG_CHECK_MODULES([PSASTRO], [psastro >= 0.9.0]) 21 PKG_CHECK_MODULES([PSPHOT], [psphot >= 0.8.0]) 22 PKG_CHECK_MODULES([PSASTRO], [psastro >= 0.9.0]) 22 23 23 24 IPP_STDOPTS -
branches/eam_branch_20080511/ppSim/src/Makefile.am
r17630 r17672 1 1 bin_PROGRAMS = ppSim ppSimSequence 2 2 3 ppSim_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PS ASTRO_CFLAGS) $(ppSim_CFLAGS)4 ppSim_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS) $(PS ASTRO_LIBS)3 ppSim_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSPHOT_CFLAGS) $(PSASTRO_CFLAGS) $(ppSim_CFLAGS) 4 ppSim_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS) $(PSPHOT_LIBS) $(PSASTRO_LIBS) 5 5 ppSim_SOURCES = \ 6 6 ppSim.c \ -
branches/eam_branch_20080511/ppSim/src/ppSim.c
r17615 r17672 1 1 # include "ppSim.h" 2 3 int failure (pmConfig *config, psExit status, char *message) { 4 psErrorStackPrint(stderr, message); 5 psFree(config); 6 pmModelClassCleanup(); 7 psLibFinalize(); 8 exit (status); 9 } 2 10 3 11 int main(int argc, char *argv[]) … … 8 16 pmConfig *config = pmConfigRead(&argc, argv, PPSIM_RECIPE); // Configuration 9 17 if (!config) { 10 psErrorStackPrint(stderr, "Unable to read configurations."); 11 exit(PS_EXIT_CONFIG_ERROR); 18 failure (config, PS_EXIT_CONFIG_ERROR, "Unable to read configurations."); 12 19 } 13 20 14 ppSimArguments(argc, argv, config); 21 if (!ppSimArguments(argc, argv, config)) { 22 failure (config, PS_EXIT_CONFIG_ERROR, "Error parsing command-line arguments"); 23 } 15 24 16 25 if (!ppSimCreate(config)) { 17 psErrorStackPrint(stderr, "Unable to create output file."); 18 psFree(config); 19 exit(PS_EXIT_CONFIG_ERROR); 26 failure (config, PS_EXIT_CONFIG_ERROR, "Unable to create output file."); 20 27 } 21 28 22 29 if (!ppSimLoop(config)) { 23 psErrorStackPrint(stderr, "Unable to generate data."); 24 psFree(config); 25 exit(PS_EXIT_SYS_ERROR); 30 failure (config, PS_EXIT_SYS_ERROR, "Unable to generate data."); 26 31 } 27 32 … … 32 37 psLibFinalize(); 33 38 34 return PS_EXIT_SUCCESS;39 exit (PS_EXIT_SUCCESS); 35 40 } -
branches/eam_branch_20080511/ppSim/src/ppSim.h
r17630 r17672 13 13 #include <psmodules.h> 14 14 #include <psastro.h> 15 #include <psphot.h> 15 16 16 17 #define PPSIM_RECIPE "PPSIM" … … 18 19 19 20 // Compare a value with minimum and maximum values, replacing where required. 20 #define COMPARE(VALUE,MIN,MAX) { \21 if (VALUE < MIN) { MIN = VALUE; } \22 if (VALUE > MAX) { MAX = VALUE; } \21 #define COMPARE(VALUE,MIN,MAX) { \ 22 if (VALUE < MIN) { MIN = VALUE; } \ 23 if (VALUE > MAX) { MAX = VALUE; } \ 23 24 } 24 25 … … 70 71 71 72 /// Parse command-line arguments 72 void ppSimArguments(int argc, char *argv[], ///< Command-line arguments73 bool ppSimArguments(int argc, char **argv, ///< Command-line arguments 73 74 pmConfig *config ///< Configuration 74 );75 ); 75 76 76 77 /// Create output file … … 78 79 /// Returns a borrowed pointer to the FPA file. 79 80 pmFPAfile *ppSimCreate(pmConfig *config ///< Configuration 80 );81 ); 81 82 82 83 // Return bounds of a chip, based on the concepts 83 84 psRegion *ppSimChipBounds(const pmChip *chip, // Chip for which to determine size 84 85 pmFPAview *view // View for chip 85 );86 ); 86 87 87 88 // Return bounds of an FPA, based on the concepts 88 89 psRegion *ppSimFPABounds(const pmFPA *fpa // FPA for which to determine size 89 );90 ); 90 91 91 92 /// Loop over the output file, generating simulated data 92 93 bool ppSimLoop(pmConfig *config ///< Configuration 93 );94 ); 94 95 95 96 psVector *ppSimMakeBiassec (pmCell *cell, pmConfig *config); … … 98 99 bool ppSimMakeSky (pmReadout *readout, psImage *expCorr, ppSimType type, pmConfig *config); 99 100 100 psArray *ppSimLoadSpots (pmFPA *fpa, pmConfig *config);101 bool ppSimLoadSpots (pmFPA *fpa, pmConfig *config); 101 102 102 103 bool ppSimLoadStars (psArray *stars, pmFPA *fpa, pmConfig *config); … … 147 148 float ppSimMagToFlux (float mag, float zp); 148 149 150 float ppSimArgToRecipeF32(bool *status, 151 psMetadata *options, // Target to which to add value 152 const char *recipeName, // Name for value in the recipe 153 psMetadata *arguments, // Command-line arguments 154 const char *argName // Argument name in the command-line arguments 155 ); 156 157 int ppSimArgToRecipeS32(bool *status, 158 psMetadata *options, // Target to which to add value 159 const char *recipeName, // Name for value in the recipe 160 psMetadata *arguments, // Command-line arguments 161 const char *argName // Argument name in the command-line arguments 162 ); 163 164 char *ppSimArgToRecipeStr(bool *status, 165 psMetadata *options, // Target to which to add value 166 const char *recipeName, // Name for value in the recipe 167 psMetadata *arguments, // Command-line arguments 168 const char *argName // Argument name in the command-line arguments 169 ); 170 171 ppSimType ppSimTypeFromString (char *typeStr); 172 char *ppSimTypeToString (ppSimType type); 173 174 float ppSimGetZeroPoint (psMetadata *recipe, char *filter); 175 149 176 #endif -
branches/eam_branch_20080511/ppSim/src/ppSimArguments.c
r17557 r17672 1 # include "ppSim.h"1 # include "ppSim.h" 2 2 3 3 // Print usage information and die … … 18 18 } 19 19 20 // Get a value from the command-line arguments and add it to recipe options 21 bool valueArgRecipe(psMetadata *options, // Target to which to add value 22 const char *recipeName, // Name for value in the recipe 23 psMetadata *arguments, // Command-line arguments 24 const char *argName // Argument name in the command-line arguments 25 ) 20 // this function supplements the RECIPE:OPTIONS folder with command-line options 21 bool ppSimArguments(int argc, char **argv, pmConfig *config) 26 22 { 27 bool status; // Status of MD lookup 28 float value = psMetadataLookupF32(&status, arguments, argName); // Value of interest 29 if (isnan(value)) return true; 30 status = psMetadataAddF32(options, PS_LIST_TAIL, recipeName, 0, NULL, value); 31 return status; 32 } 33 34 // this function supplements the RECIPE:OPTIONS folder with command-line options 35 void ppSimArguments(int argc, char *argv[], pmConfig *config) 36 { 23 bool status; 37 24 bool mdok; // Status of MD lookup 38 25 39 26 assert(config); 40 27 41 // save the following command-line options in the arguments structure 28 // save the following command-line options in the arguments structure. these will later be 29 // parsed and moved to the config->recipes:PPSIM_RECIPE folder 30 42 31 psMetadata *arguments = psMetadataAlloc(); // Command-line arguments 43 32 psMetadataAddStr(arguments, PS_LIST_TAIL, "-format", 0, "Camera format name", NULL); … … 71 60 72 61 pmConfigFileSetsMD (config->arguments, &argc, argv, "PSPHOT.PSF", "-psf", "-psflist"); 73 74 // only one of -camera and -file is needed 75 bool status = pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list"); 76 if (!config->camera && !status) { 77 psErrorStackPrint(stderr, "A camera name (-camera NAME) or an image (-file NAME) must be specified"); 78 exit(PS_EXIT_CONFIG_ERROR); 62 if (psErrorCodeLast () != PS_ERR_NONE) { psAbort ("problem with PSPHOT.PSF option"); } 63 64 // Only one of -camera and -file is needed or allowed. The -camera option would have been 65 // already parsed by pmConfigRead in ppSim.c and resulted in a value for config->camera 66 bool loadImage = pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list"); 67 if (!config->camera && !loadImage) { 68 psError(PS_ERR_IO, true, "A camera name (-camera NAME) or an image (-file NAME) must be specified"); 69 psFree(arguments); 70 return false; 71 } 72 if (config->camera && loadImage) { 73 psError(PS_ERR_IO, true, "Only one of (-camera NAME) and (-file NAME) may be specified"); 74 psFree(arguments); 75 return false; 79 76 } 80 77 81 78 if (!psArgumentParse(arguments, &argc, argv)) { 82 exit(PS_EXIT_CONFIG_ERROR); 79 psError(PS_ERR_IO, false, "error in command-line arguments"); 80 psFree(arguments); 81 return false; 83 82 } 84 83 85 84 if (argc != 2) { 86 psErrorStackPrint(stderr, "Missing output filename"); 87 exit(PS_EXIT_CONFIG_ERROR); 85 psError(PS_ERR_IO, true, "Missing output filename"); 86 psFree(arguments); 87 return false; 88 } 89 90 // output filename 91 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "Name of the output image", argv[1]); 92 93 // save the additional recipe values based on command-line options. These options override 94 // the PPSIM recipe values loaded from recipe files 95 psMetadata *options = pmConfigRecipeOptions (config, PPSIM_RECIPE); 96 if (!options) { 97 psError(PS_ERR_IO, false, "Unable to find recipe options for %s", PPSIM_RECIPE); 98 psFree(arguments); 99 return false; 100 } 101 102 // these arguments may be used whether the input image is created or loaded 103 ppSimArgToRecipeF32(&status, options, "STARS.LUM", arguments, "-starslum"); 104 ppSimArgToRecipeF32(&status, options, "STARS.MAG", arguments, "-starsmag"); 105 ppSimArgToRecipeF32(&status, options, "STARS.DENSITY", arguments, "-starsdensity"); 106 107 // if we are loading the input image (not creating it), then we can skip the remaining arguments 108 if (loadImage) { 109 // if we are supplying an input image, it is so we may supply fake stars; force it to 110 // be treated as an OBJECT image. 111 psMetadataAddStr(options, PS_LIST_TAIL, "IMAGE.TYPE", 0, "Exposure type", "OBJECT"); 112 113 // check for these options as well 114 ppSimArgToRecipeStr(&status, options, "PSF.MODEL", arguments, "-psfclass"); // PSF model class 115 ppSimArgToRecipeStr(&status, options, "GALAXY.MODEL", arguments, "-galmodel"); // Galaxy model name 116 117 // 'seeing' is not required: we can load a psf-model instead; but if not, it is allowed 118 ppSimArgToRecipeF32(&status, options, "SEEING", arguments, "-seeing"); // seeing (FWHM in arcsec) 119 120 // 'scale' is not required: we can use the WCS instead; but if not, it is allowed 121 ppSimArgToRecipeF32(&status, options, "PIXEL.SCALE", arguments, "-scale"); // Plate scale 122 123 psFree (arguments); 124 return true; 88 125 } 89 126 … … 96 133 psMetadata *formats = psMetadataLookupMetadata(NULL, config->camera, "FORMATS"); // The camera formats 97 134 if (!formats) { 98 psErrorStackPrint(stderr, "Unable to find FORMATS in camera configuration.");135 psError(PS_ERR_IO, false, "Unable to find FORMATS in camera configuration."); 99 136 psFree(arguments); 100 psFree(config); 101 exit(PS_EXIT_CONFIG_ERROR); 137 return false; 102 138 } 103 139 psMetadata *format = psMetadataLookupMetadata(NULL, formats, formatName); // Format of interest 104 140 if (!format) { 105 psErrorStackPrint(stderr, "Unable to find format %s in camera FORMATS.", formatName);141 psError(PS_ERR_IO, false, "Unable to find format %s in camera FORMATS.", formatName); 106 142 psFree(arguments); 107 psFree(config); 108 exit(PS_EXIT_CONFIG_ERROR); 143 return false; 109 144 } 110 145 config->format = psMemIncrRefCounter(format); 111 146 } 112 147 113 // specify the type of simulated image to produce 114 // XXX this should not be required if we supplied INPUT 115 const char *typeStr = psMetadataLookupStr(NULL, arguments, "-type"); // Exposure type 116 if (!typeStr) { 117 psErrorStackPrint(stderr, "An exposure type must be specified using -type"); 118 exit(PS_EXIT_CONFIG_ERROR); 119 } 120 ppSimType type = PPSIM_TYPE_NONE; // Type to simulate 121 if (strcasecmp(typeStr, "BIAS") == 0) { 122 type = PPSIM_TYPE_BIAS; 123 } else if (strcasecmp(typeStr, "DARK") == 0) { 124 type = PPSIM_TYPE_DARK; 125 } else if (strcasecmp(typeStr, "FLAT") == 0) { 126 type = PPSIM_TYPE_FLAT; 127 } else if (strcasecmp(typeStr, "OBJECT") == 0) { 128 type = PPSIM_TYPE_OBJECT; 148 char *typeStr = ppSimArgToRecipeStr (&status, options, "IMAGE.TYPE", arguments, "-type"); // Requested exposure type 149 if (!status) { 150 psError(PS_ERR_IO, false, "An exposure type must be specified using -type"); 151 psFree(arguments); 152 return false; 153 } 154 ppSimType type = ppSimTypeFromString (typeStr); 155 156 char *filter = ppSimArgToRecipeStr(&status, options, "FILTER", arguments, "-filter"); // Filter name 157 158 // set the exposure time 159 if (type == PPSIM_TYPE_BIAS) { 160 psMetadataAddF32(options, PS_LIST_TAIL, "EXPTIME", 0, "Exposure time (s)", 0.0); 129 161 } else { 130 psErrorStackPrint(stderr, "Unrecognised exposure type: %s", typeStr); 131 exit(PS_EXIT_CONFIG_ERROR); 132 } 133 assert(type != PPSIM_TYPE_NONE); 134 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "TYPE", 0, "Exposure type", type); 135 136 const char *filter = psMetadataLookupStr(NULL, arguments, "-filter"); // Filter name 137 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "FILTER", 0, "Filter name", filter); 138 139 // save the following additional recipe values based on command-line options 140 // these options override the PPSIM recipe values loaded from recipe files 141 psMetadata *options = pmConfigRecipeOptions (config, PPSIM_RECIPE); 142 if (!options) { 143 psErrorStackPrint(stderr, "Unable to find recipe options for %s", PPSIM_RECIPE); 144 psFree(arguments); 145 psFree(config); 146 exit(PS_EXIT_CONFIG_ERROR); 147 } 148 149 float expTime; 150 if (type == PPSIM_TYPE_BIAS) { 151 expTime = 0.0; 152 } else { 153 expTime = psMetadataLookupF32(NULL, arguments, "-exptime"); // Exposure time 154 if (isnan(expTime)) { 155 psErrorStackPrint(stderr, "The exposure time must be specified using -exptime"); 156 exit(PS_EXIT_CONFIG_ERROR); 157 } 158 } 159 psMetadataAddF32(options, PS_LIST_TAIL, "EXPTIME", 0, "Exposure time (s)", expTime); 162 ppSimArgToRecipeF32(&status, options, "EXPTIME", arguments, "-exptime"); 163 if (!status) { 164 psError(PS_ERR_IO, false, "The exposure time must be specified using -exptime"); 165 psFree(arguments); 166 return false; 167 } 168 } 160 169 161 170 // these values all get moved from arguments to RECIPE:OPTIONS 162 valueArgRecipe(options, "BIAS.LEVEL", arguments, "-biaslevel"); 163 valueArgRecipe(options, "BIAS.RANGE", arguments, "-biasrange"); 164 valueArgRecipe(options, "DARK.RATE", arguments, "-darkrate"); 165 valueArgRecipe(options, "FLAT.SIGMA", arguments, "-flatsigma"); 166 valueArgRecipe(options, "FLAT.RATE", arguments, "-flatrate"); 167 valueArgRecipe(options, "SHUTTER.TIME", arguments, "-shuttertime"); 168 valueArgRecipe(options, "SKY.RATE", arguments, "-skyrate"); 169 valueArgRecipe(options, "STARS.LUM", arguments, "-starslum"); 170 valueArgRecipe(options, "STARS.MAG", arguments, "-starsmag"); 171 valueArgRecipe(options, "STARS.DENSITY", arguments, "-starsdensity"); 171 ppSimArgToRecipeF32(&status, options, "BIAS.LEVEL", arguments, "-biaslevel"); 172 ppSimArgToRecipeF32(&status, options, "BIAS.RANGE", arguments, "-biasrange"); 173 ppSimArgToRecipeF32(&status, options, "DARK.RATE", arguments, "-darkrate"); 174 ppSimArgToRecipeF32(&status, options, "FLAT.SIGMA", arguments, "-flatsigma"); 175 ppSimArgToRecipeF32(&status, options, "FLAT.RATE", arguments, "-flatrate"); 176 ppSimArgToRecipeF32(&status, options, "SHUTTER.TIME", arguments, "-shuttertime"); 177 ppSimArgToRecipeF32(&status, options, "SKY.RATE", arguments, "-skyrate"); 178 ppSimArgToRecipeS32(&status, options, "BINNING", arguments, "-bin"); 172 179 173 180 psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSIM_RECIPE); // Recipe 174 175 int biasOrder = psMetadataLookupS32(&mdok, recipe, "BIAS.ORDER"); // Overscan polynomial order176 if (!mdok) {177 psWarning("BIAS.ORDER(S32) is not set in the recipe %s --- assuming %d", PPSIM_RECIPE, biasOrder);178 }179 psMetadataAddS32(options, PS_LIST_TAIL, "BIAS.ORDER", 0, "Overscan polynomial order", biasOrder);180 181 int binning = psMetadataLookupS32(NULL, arguments, "-bin"); // Binning in x and y182 if (binning <= 0) {183 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Binning (%d) is non-positive.", binning);184 exit(PS_EXIT_CONFIG_ERROR);185 }186 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "BINNING", 0, "Binning in x and y", binning);187 188 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "Name of the output image", argv[1]);189 181 190 182 if (type == PPSIM_TYPE_OBJECT) { … … 197 189 // XXX scale and zp should be supplied by the config file (allow override, but this is camera-dependent) 198 190 if (isnan(ra0) || isnan(dec0) || isnan(pa) || isnan(seeing)) { 199 psErrorStackPrint(stderr, "-ra, -dec, -pa, -scale, -zp, -seeing must be specified for OBJECT type"); 200 exit(PS_EXIT_CONFIG_ERROR); 201 } 202 203 float zp = psMetadataLookupF32(NULL, arguments, "-zp"); // Zero point 204 if (isnan(zp)) { 205 // use the filter to get the zeropoint from the recipe 206 psMetadataItem *zpItem = psMetadataLookup (recipe, "ZEROPTS"); 207 // check that item is multi... 208 209 psArray *entries = psListToArray (zpItem->data.list); 210 211 // search for matching filter 212 for (int i = 0; i < entries->n; i++) { 213 psMetadataItem *item = entries->data[i]; 214 psMetadata *entry = item->data.V; 215 216 char *filterName = psMetadataLookupStr (&status, entry, "FILTER"); 217 assert (filterName); 218 219 if (strcmp(filterName, filter)) continue; 220 221 zp = psMetadataLookupF32 (&status, entry, "ZERO_PT"); 222 assert (status); 223 break; 224 } 225 psFree (entries); 226 } 227 228 float scale = psMetadataLookupF32(NULL, arguments, "-scale"); // Plate scale 229 if (isnan(scale)) { 230 scale = psMetadataLookupF32 (&status, recipe, "PIXEL.SCALE"); 231 } 232 233 float skymags = psMetadataLookupF32(NULL, arguments, "-skymags"); // Position angle 234 if (isnan(skymags)) { 235 skymags = psMetadataLookupF32 (&status, recipe, "SKY.MAGS"); 236 } 237 191 psError(PS_ERR_IO, false, "-ra, -dec, -pa, -scale, -zp, -seeing must be specified for OBJECT type"); 192 psFree(arguments); 193 return false; 194 } 195 196 float scale = ppSimArgToRecipeF32(&status, options, "PIXEL.SCALE", arguments, "-scale"); // Plate scale 197 ppSimArgToRecipeF32(&status, options, "SKY.MAGS", arguments, "-skymags"); // Plate scale 198 ppSimArgToRecipeStr(&status, options, "PSF.MODEL", arguments, "-psfclass"); // PSF model class 199 ppSimArgToRecipeStr(&status, options, "GALAXY.MODEL", arguments, "-galmodel"); // Galaxy model name 200 201 // the user supplies FWHM in arcsec; here we convert to Sigma in pixels 202 psMetadataAddF32(options, PS_LIST_TAIL, "SEEING", 0, "Seeing SIGMA (pixels)", seeing / 2.0 / sqrt(2.0 * log(2.0)) / scale); 238 203 psMetadataAddF32(options, PS_LIST_TAIL, "RA", 0, "Boresight RA (radians)", ra0 * M_PI / 180.0); 239 204 psMetadataAddF32(options, PS_LIST_TAIL, "DEC", 0, "Boresight Declination (radians)", dec0 * M_PI / 180.0); 240 205 psMetadataAddF32(options, PS_LIST_TAIL, "PA", 0, "Boresight position angle (radians)",pa * M_PI / 180.0); 241 206 242 // the user supplies FWHM in arcsec; here we convert to Sigma in pixels 243 psMetadataAddF32(options, PS_LIST_TAIL, "SEEING", 0, "Seeing SIGMA (pixels)", seeing / 2.0 / sqrt(2.0 * log(2.0)) / scale); 244 245 psMetadataAddF32(options, PS_LIST_TAIL, "SCALE", 0, "Plate scale (arcsec/pix)", scale); 246 psMetadataAddF32(options, PS_LIST_TAIL, "ZEROPOINT", 0, "Photometric zeropoint", zp); 247 psMetadataAddF32(options, PS_LIST_TAIL, "SKY.MAGS", 0, "sky surface brightness", skymags); 248 249 const char *psfClass = psMetadataLookupStr(NULL, arguments, "-psfclass"); // PSF model class 250 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "PSF.MODEL", 0, "PSF model class", psfClass); 251 252 const char *galModel = psMetadataLookupStr(NULL, arguments, "-galmodel"); // Galaxy model name 253 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "GALAXY.MODEL", 0, "Galaxy model", galModel); 207 assert (filter != NULL); 208 209 ppSimArgToRecipeF32(&status, options, "ZEROPOINT", arguments, "-zp"); // Zero point 210 if (!status) { 211 float zp = ppSimGetZeroPoint (recipe, filter); 212 psMetadataAddF32(options, PS_LIST_TAIL, "ZEROPOINT", 0, "Photometric zeropoint", zp); 213 } 254 214 } 255 215 256 216 psFree(arguments); 257 return ;217 return true; 258 218 } 259 219 … … 262 222 PSPHOT.PSF 263 223 INPUT 264 TYPE265 FILTER266 BIAS.ORDER267 BINNING268 224 OUTPUT 269 PSF.MODEL 270 GALAXY.MODEL 271 272 all othr values should come from the recipe 225 226 all other values should come from the recipe 273 227 */ -
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 } -
branches/eam_branch_20080511/ppSim/src/ppSimInsertGalaxies.c
r17557 r17672 10 10 11 11 if (!galaxies->n) { return true; } 12 13 // XXX is this needed?14 // pmFPAfile *simSources = psMetadataLookupPtr(NULL, config->files, "PPSIM.SOURCES"); // Output sources15 12 16 13 pmCell *cell = readout->parent; … … 38 35 if (isnan(skyRate)) { 39 36 float zp = psMetadataLookupF32(&mdok, recipe, "ZEROPOINT"); assert (mdok); 40 float scale = psMetadataLookupF32(&mdok, recipe, " SCALE");assert (mdok);37 float scale = psMetadataLookupF32(&mdok, recipe, "PIXEL.SCALE"); assert (mdok); 41 38 float skyMags = psMetadataLookupF32(&mdok, recipe, "SKY.MAGS"); assert (mdok); 42 39 skyRate = scale * scale * ppSimMagToFlux (skyMags, zp); … … 56 53 int yParityCell = psMetadataLookupS32(NULL, cell->concepts, "CELL.YPARITY"); 57 54 58 int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y55 int binning = psMetadataLookupS32(NULL, recipe, "BINNING"); // Binning in x and y 59 56 60 57 // determine the galaxy model 61 char *modelName = psMetadataLookupStr(&mdok, config->arguments, "GALAXY.MODEL"); // galaxy model name58 char *modelName = psMetadataLookupStr(&mdok, recipe, "GALAXY.MODEL"); // galaxy model name 62 59 if (modelName == NULL) { 63 60 modelName = defaultModel; -
branches/eam_branch_20080511/ppSim/src/ppSimInsertStars.c
r17557 r17672 43 43 if (isnan(skyRate)) { 44 44 float zp = psMetadataLookupF32(&mdok, recipe, "ZEROPOINT"); assert (mdok); 45 float scale = psMetadataLookupF32(&mdok, recipe, " SCALE"); assert (mdok);45 float scale = psMetadataLookupF32(&mdok, recipe, "PIXEL.SCALE"); assert (mdok); 46 46 float skyMags = psMetadataLookupF32(&mdok, recipe, "SKY.MAGS"); assert (mdok); 47 47 skyRate = scale * scale * ppSimMagToFlux (skyMags, zp); … … 61 61 int yParityCell = psMetadataLookupS32(NULL, cell->concepts, "CELL.YPARITY"); 62 62 63 int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y63 int binning = psMetadataLookupS32(NULL, recipe, "BINNING"); // Binning in x and y 64 64 65 65 pmPSF *psf = psMetadataLookupPtr (&mdok, chip->analysis, "PSPHOT.PSF"); -
branches/eam_branch_20080511/ppSim/src/ppSimLoadSpots.c
r17628 r17672 2 2 3 3 bool ppSimLoadSpots (pmFPA *fpa, pmConfig *config) { 4 5 # if (0) 4 6 5 7 bool mdok; … … 64 66 } 65 67 68 # endif 69 66 70 // XXX these need to be saved on PSPHOT.INPUT.CMF 67 71 return true; -
branches/eam_branch_20080511/ppSim/src/ppSimLoadStars.c
r17557 r17672 1 # include "ppSim.h"1 # include "ppSim.h" 2 2 3 3 bool ppSimLoadStars (psArray *stars, pmFPA *fpa, pmConfig *config) { … … 24 24 float pa = psMetadataLookupF32(NULL, recipe, "PA"); // Position angle (radians) 25 25 float seeing = psMetadataLookupF32(NULL, recipe, "SEEING"); // Seeing SIGMA (pixels) 26 float scale = psMetadataLookupF32(NULL, recipe, " SCALE") * M_PI / 3600.0 / 180.0; // Plate scale (radians/pixel)26 float scale = psMetadataLookupF32(NULL, recipe, "PIXEL.SCALE") * M_PI / 3600.0 / 180.0; // Plate scale (radians/pixel) 27 27 float expTime = psMetadataLookupF32(NULL, recipe, "EXPTIME"); // Exposure time (sec) 28 28 … … 40 40 psMetadataAdd(astroRecipe, PS_LIST_TAIL, "DEC_MAX", PS_DATA_F32 | PS_META_REPLACE, "", dec0 + radius); 41 41 psArray *refStars = psastroLoadRefstars(config); 42 if (!refStars || refStars->n == 0) {42 if (!refStars) { 43 43 psError(PS_ERR_UNKNOWN, false, "Unable to find reference stars."); 44 44 psFree(refStars); -
branches/eam_branch_20080511/ppSim/src/ppSimLoop.c
r17630 r17672 1 1 #include "ppSim.h" 2 3 # define ESCAPE(CODE,MSG) { \ 4 psError(CODE, false, MSG); \ 5 psFree (rng); \ 6 return false; } 2 7 3 8 bool ppSimLoop(pmConfig *config) … … 8 13 pmFPAfile *file = psMetadataLookupPtr(NULL, config->files, OUTPUT_FILE); // Output file 9 14 assert(file); 15 10 16 pmFPA *fpa = file->fpa; // FPA for file 11 17 assert(fpa); 12 18 13 p pSimType type = psMetadataLookupS32(NULL, config->arguments, "TYPE"); // Type of image to simulate19 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe 14 20 15 21 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0); // Random number generator 16 22 17 int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y 18 19 // Load forced-photometry positions 20 if (type == PPSIM_TYPE_OBJECT) { 21 psArray *spots = ppSimLoadSpots (fpa, config); 22 } 23 24 // Load catalogue stars 23 char *typeStr = psMetadataLookupStr(NULL, recipe, "IMAGE.TYPE"); // Type of image to simulate 24 ppSimType type = ppSimTypeFromString (typeStr); // Type of image to simulate 25 int binning = psMetadataLookupS32(NULL, recipe, "BINNING"); // Binning in x and y 26 25 27 psArray *stars = psArrayAllocEmpty (1); 26 if (type == PPSIM_TYPE_OBJECT) {27 ppSimLoadStars (stars, fpa, config);28 }29 30 // Add random stars31 if (type == PPSIM_TYPE_OBJECT) {32 ppSimMakeStars (stars, fpa, config, rng);33 }34 35 // Add random galaxies36 28 psArray *galaxies = psArrayAllocEmpty (1); 37 29 if (type == PPSIM_TYPE_OBJECT) { 38 ppSimMakeGalaxies (galaxies, fpa, config, rng); 30 // Load forced-photometry positions 31 if (!ppSimLoadSpots (fpa, config)) ESCAPE (PS_ERR_UNKNOWN, "failed to load forced-photometry spots"); 32 33 // Load catalogue stars 34 if (!ppSimLoadStars (stars, fpa, config)) ESCAPE (PS_ERR_UNKNOWN, "failed to load catalog stars"); 35 36 // Add random stars 37 if (!ppSimMakeStars (stars, fpa, config, rng)) ESCAPE (PS_ERR_UNKNOWN, "failed to make random stars"); 38 39 // Add random galaxies 40 if (!ppSimMakeGalaxies (galaxies, fpa, config, rng)) ESCAPE (PS_ERR_UNKNOWN, "failed to make random galaxies"); 39 41 } 40 42 … … 176 178 } 177 179 178 ppSimMosaicChip(config, blankMask, view, "PPSIM.CHIP", "PPSIM.OUTPUT");179 180 180 // we perform photometry on the readouts of this chip in the output 181 181 ppSimPhotom (config, view); -
branches/eam_branch_20080511/ppSim/src/ppSimMakeBias.c
r17557 r17672 8 8 9 9 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSIM_RECIPE); // Recipe 10 11 bool bias = psMetadataLookupBool(&status, recipe, "BIAS"); // Generate a Bias? 12 if (!bias) return true; 10 13 11 14 float biasLevel = psMetadataLookupF32(NULL, recipe, "BIAS.LEVEL"); // Bias level -
branches/eam_branch_20080511/ppSim/src/ppSimMakeDark.c
r17557 r17672 10 10 11 11 psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSIM_RECIPE); // Recipe 12 13 bool dark = psMetadataLookupBool(&status, recipe, "DARK"); // Generate a DARK? 14 if (!dark) return true; 12 15 13 16 float darkRate = psMetadataLookupF32(NULL, recipe, "DARK.RATE"); // Dark rate -
branches/eam_branch_20080511/ppSim/src/ppSimMakeGalaxies.c
r17557 r17672 9 9 10 10 bool galaxyFake = psMetadataLookupBool(&mdok, recipe, "GALAXY.FAKE"); // Density of fakes 11 if (!galaxyFake) return NULL;11 if (!galaxyFake) return true; 12 12 13 13 float galaxyLum = psMetadataLookupF32(&mdok, recipe, "GALAXY.LUM"); // Galaxy luminosity func slope … … 35 35 float zp = psMetadataLookupF32(&mdok, recipe, "ZEROPOINT"); // Photometric zero point 36 36 float seeing = psMetadataLookupF32(&mdok, recipe, "SEEING"); // Seeing sigma (pix) 37 float scale = psMetadataLookupF32(&mdok, recipe, " SCALE") * M_PI / 3600.0 / 180.0; // Plate scale (radians/pixel)37 float scale = psMetadataLookupF32(&mdok, recipe, "PIXEL.SCALE") * M_PI / 3600.0 / 180.0; // Plate scale (radians/pixel) 38 38 float skyRate = psMetadataLookupF32(&mdok, recipe, "SKY.RATE"); // Sky rate 39 39 if (isnan(skyRate)) { … … 42 42 } 43 43 44 if (galaxyDensity <= 0) return NULL;44 if (galaxyDensity <= 0) return true; 45 45 46 46 // Size of FPA … … 66 66 psLogMsg("ppSim", PS_LOG_INFO, 67 67 "Image noise is above brightest random galaxy --- no random galaxy added."); 68 return NULL;68 return true; 69 69 } 70 70 … … 138 138 } 139 139 } 140 return galaxies;140 return true; 141 141 } -
branches/eam_branch_20080511/ppSim/src/ppSimMakeSky.c
r17557 r17672 15 15 psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe 16 16 17 bool sky = psMetadataLookupBool(&status, recipe, "SKY"); // Generate a SKY flux? 18 if (!sky) return true; 19 17 20 float expTime = psMetadataLookupF32(&status, recipe, "EXPTIME"); // Exposure time 18 21 float flatSigma = psMetadataLookupF32(&status, recipe, "FLAT.SIGMA"); // Flat-field coefficient … … 22 25 if (isnan(skyRate)) { 23 26 float zp = psMetadataLookupF32(&status, recipe, "ZEROPOINT"); assert (status); 24 float scale = psMetadataLookupF32(&status, recipe, " SCALE");assert (status);27 float scale = psMetadataLookupF32(&status, recipe, "PIXEL.SCALE"); assert (status); 25 28 float skyMags = psMetadataLookupF32(&status, recipe, "SKY.MAGS"); assert (status); 26 29 skyRate = scale * scale * ppSimMagToFlux (skyMags, zp); … … 37 40 int yParityCell = psMetadataLookupS32(&status, cell->concepts, "CELL.YPARITY"); 38 41 39 int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y42 int binning = psMetadataLookupS32(NULL, recipe, "BINNING"); // Binning in x and y 40 43 41 44 // Size of FPA -
branches/eam_branch_20080511/ppSim/src/ppSimMakeStars.c
r17616 r17672 1 1 # include "ppSim.h" 2 3 # define ESCAPE(MSG) { \ 4 psError(PS_ERR_BAD_PARAMETER_VALUE, true, MSG); \ 5 return false; } 2 6 3 7 bool ppSimMakeStars(psArray *stars, pmFPA *fpa, pmConfig *config, const psRandom *rng) { … … 23 27 float zp = psMetadataLookupF32(&status, recipe, "ZEROPOINT"); // Photometric zero point 24 28 float seeing = psMetadataLookupF32(&status, recipe, "SEEING"); // Seeing SIGMA (pixels) 25 float scale = psMetadataLookupF32(&status, recipe, "SCALE") * M_PI / 3600.0 / 180.0; // Plate scale (radians/pixel) 29 float scale = psMetadataLookupF32(&status, recipe, "PIXEL.SCALE") * M_PI / 3600.0 / 180.0; // Plate scale (radians/pixel) 30 31 if (isnan(darkRate)) darkRate = 0.0; 32 if (isnan(expTime)) ESCAPE("EXPTIME is not defined"); 33 if (isnan(zp)) ESCAPE("ZEROPOINT is not defined"); 34 if (isnan(seeing)) ESCAPE("SEEING is not defined"); 35 if (isnan(scale)) ESCAPE("PIXEL.SCALE is not defined"); 26 36 27 37 bool flatLum = psMetadataLookupBool(&status,recipe, "STARS.FLAT.LUM"); // were real stars generated? … … 47 57 refMag = psMetadataLookupF32(&status, fpa->concepts, "STARS.REAL.MAG.PEAK"); // Star brightest magnitude 48 58 refSum = psMetadataLookupF32(&status, fpa->concepts, "STARS.REAL.SUM.PEAK"); // Star brightest magnitude 49 assert (status); 59 60 // if we tried and failed to load reference stars, set more artificial limits 61 if (!status) { 62 refMag = brightMag; 63 refSum = 1; 64 } 50 65 } else { 51 66 refMag = brightMag; -
branches/eam_branch_20080511/ppSim/src/ppSimPhotom.c
r17628 r17672 8 8 pmReadout *readout; 9 9 10 psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe 11 12 bool doPhotom = psMetadataLookupBool(&status, recipe, "PHOTOM"); // Density of fakes 13 if (!doPhotom) return true; 14 10 15 psphotModelClassInit (); 16 17 int blankMask = 0; // XXX not sure what this should be set to... 18 ppSimMosaicChip(config, blankMask, view, "PPSIM.CHIP", "PPSIM.OUTPUT"); 11 19 12 20 // find or define a pmFPAfile PSPHOT.INPUT -
branches/eam_branch_20080511/ppSim/src/ppSimSetPSF.c
r17557 r17672 21 21 float seeing = psMetadataLookupF32(&status, recipe, "SEEING"); // Seeing SIGMA (pixels) 22 22 23 char *psfModelName = psMetadataLookupStr(&status, config->arguments, "PSF.MODEL"); // Name of PSF model23 char *psfModelName = psMetadataLookupStr(&status, recipe, "PSF.MODEL"); // Name of PSF model 24 24 if (psfModelName == NULL) { 25 25 psfModelName = defaultModel; -
branches/eam_branch_20080511/ppSim/src/ppSimUtils.c
r17557 r17672 15 15 float dec0 = psMetadataLookupF32(NULL, recipe, "DEC"); // Boresight Dec (radians) 16 16 float pa = psMetadataLookupF32(NULL, recipe, "PA"); // Position angle (radians) 17 float scale = psMetadataLookupF32(NULL, recipe, " SCALE"); // plate scale in arcsec / pixel17 float scale = psMetadataLookupF32(NULL, recipe, "PIXEL.SCALE"); // plate scale in arcsec / pixel 18 18 scale *= M_PI / 3600.0 / 180.0; // convert plate scale to radians/pixel 19 19 20 int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y20 int binning = psMetadataLookupS32(NULL, recipe, "BINNING"); // Binning in x and y 21 21 22 22 float x0 = 0.0, y0 = 0.0; … … 95 95 } 96 96 97 char *ppSimTypeToString (ppSimType type) { 98 99 char *typeStr; 100 101 switch (type) { 102 case PPSIM_TYPE_BIAS: typeStr = psStringCopy ("BIAS"); break; 103 case PPSIM_TYPE_DARK: typeStr = psStringCopy ("DARK"); break; 104 case PPSIM_TYPE_FLAT: typeStr = psStringCopy ("FLAT"); break; 105 case PPSIM_TYPE_OBJECT: typeStr = psStringCopy ("OBJECT"); break; 106 default: 107 psAbort("Should never get here."); 108 } 109 return (typeStr); 110 } 111 112 ppSimType ppSimTypeFromString (char *typeStr) { 113 114 if (!strcasecmp (typeStr, "BIAS")) return PPSIM_TYPE_BIAS; 115 if (!strcasecmp (typeStr, "DARK")) return PPSIM_TYPE_DARK; 116 if (!strcasecmp (typeStr, "FLAT")) return PPSIM_TYPE_FLAT; 117 if (!strcasecmp (typeStr, "OBJECT")) return PPSIM_TYPE_OBJECT; 118 psAbort("Should never get here."); 119 } 120 97 121 bool ppSimUpdateConceptsFPA (pmFPA *fpa, pmConfig *config) { 98 122 … … 103 127 float expTime = psMetadataLookupF32(NULL, recipe, "EXPTIME"); // Exposure time 104 128 105 const char *filter = psMetadataLookupStr(NULL, config->arguments, "FILTER"); // Filter name129 const char *filter = psMetadataLookupStr(NULL, recipe, "FILTER"); // Filter name 106 130 if (!filter) { 107 131 filter = "NONE"; 108 132 } 109 133 110 ppSimType type = psMetadataLookupS32(NULL, config->arguments, "TYPE"); // Type of image to simulate 111 112 // Update FPA concepts 113 const char *typeStr; // Exposure type String 114 switch (type) { 115 case PPSIM_TYPE_BIAS: typeStr = "BIAS"; break; 116 case PPSIM_TYPE_DARK: typeStr = "DARK"; break; 117 case PPSIM_TYPE_FLAT: typeStr = "FLAT"; break; 118 case PPSIM_TYPE_OBJECT: typeStr = "OBJECT"; break; 119 default: 120 psAbort("Should never get here."); 121 } 122 123 psMetadataAddStr(fpa->concepts, PS_LIST_TAIL, "FPA.OBSTYPE", PS_META_REPLACE, 124 "Observation type", typeStr); 125 psMetadataAddStr(fpa->concepts, PS_LIST_TAIL, "FPA.OBJECT", PS_META_REPLACE, 126 "Observation name", typeStr); 127 psMetadataAddF32(fpa->concepts, PS_LIST_TAIL, "FPA.EXPTIME", PS_META_REPLACE, 128 "Exposure time (sec)", expTime); 134 char *typeStr = psMetadataLookupStr(NULL, recipe, "IMAGE.TYPE"); // Type of image to simulate 135 136 psMetadataAddStr(fpa->concepts, PS_LIST_TAIL, "FPA.OBSTYPE", PS_META_REPLACE, "Observation type", typeStr); 137 psMetadataAddStr(fpa->concepts, PS_LIST_TAIL, "FPA.OBJECT", PS_META_REPLACE, "Observation name", typeStr); 138 psMetadataAddF32(fpa->concepts, PS_LIST_TAIL, "FPA.EXPOSURE", PS_META_REPLACE, "Exposure time (sec)", expTime); 129 139 psMetadataAddStr(fpa->concepts, PS_LIST_TAIL, "FPA.FILTERID", PS_META_REPLACE, "Filter name", filter); 130 140 psMetadataAddStr(fpa->concepts, PS_LIST_TAIL, "FPA.FILTER", PS_META_REPLACE, "Filter name", filter); … … 139 149 psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSIM_RECIPE); // Recipe 140 150 141 int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y151 int binning = psMetadataLookupS32(NULL, recipe, "BINNING"); // Binning in x and y 142 152 float expTime = psMetadataLookupF32(NULL, recipe, "EXPTIME"); // Exposure time 143 153 … … 153 163 return true; 154 164 } 165 166 bool ppSimRecipeValidation (pmConfig *config) { 167 168 bool status; 169 170 psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe 171 172 int binning = psMetadataLookupS32(&status, recipe, "BINNING"); // Binning in x and y 173 if (binning <= 0) { 174 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Binning (%d) is non-positive.", binning); 175 exit(PS_EXIT_CONFIG_ERROR); 176 } 177 return true; 178 } 179 180 // Get a value from the command-line arguments and add it to recipe options 181 float ppSimArgToRecipeF32(bool *status, 182 psMetadata *options, // Target to which to add value 183 const char *recipeName, // Name for value in the recipe 184 psMetadata *arguments, // Command-line arguments 185 const char *argName // Argument name in the command-line arguments 186 ) 187 { 188 bool myStatus; 189 float value = psMetadataLookupF32(&myStatus, arguments, argName); // Value of interest 190 if (status) { *status = myStatus; } 191 if (isnan(value)) return value; 192 193 psMetadataAddF32(options, PS_LIST_TAIL, recipeName, PS_META_REPLACE, NULL, value); 194 return value; 195 } 196 197 // Get a value from the command-line arguments and add it to recipe options 198 int ppSimArgToRecipeS32(bool *status, 199 psMetadata *options, // Target to which to add value 200 const char *recipeName, // Name for value in the recipe 201 psMetadata *arguments, // Command-line arguments 202 const char *argName // Argument name in the command-line arguments 203 ) 204 { 205 bool myStatus; 206 int value = psMetadataLookupS32(&myStatus, arguments, argName); // Value of interest 207 if (status) { *status = myStatus; } 208 209 psMetadataAddS32(options, PS_LIST_TAIL, recipeName, PS_META_REPLACE, NULL, value); 210 return value; 211 } 212 213 // Get a value from the command-line arguments and add it to recipe options 214 char *ppSimArgToRecipeStr(bool *status, 215 psMetadata *options, // Target to which to add value 216 const char *recipeName, // Name for value in the recipe 217 psMetadata *arguments, // Command-line arguments 218 const char *argName // Argument name in the command-line arguments 219 ) 220 { 221 bool myStatus; 222 223 char *value = psMetadataLookupStr(&myStatus, arguments, argName); // Value of interest 224 if (status) { 225 *status = myStatus; 226 } 227 psMetadataAddStr(options, PS_LIST_TAIL, recipeName, PS_META_REPLACE, NULL, value); 228 return value; 229 } 230 231 float ppSimGetZeroPoint (psMetadata *recipe, char *filter) { 232 233 bool mdok; 234 float zp; 235 236 // use the filter to get the zeropoint from the recipe 237 psMetadataItem *zpItem = psMetadataLookup (recipe, "ZEROPTS"); 238 // check that item is multi... 239 240 psArray *entries = psListToArray (zpItem->data.list); 241 242 // search for matching filter 243 for (int i = 0; i < entries->n; i++) { 244 psMetadataItem *item = entries->data[i]; 245 psMetadata *entry = item->data.V; 246 247 char *filterName = psMetadataLookupStr (&mdok, entry, "FILTER"); 248 assert (filterName); 249 250 if (strcmp(filterName, filter)) continue; 251 252 zp = psMetadataLookupF32 (&mdok, entry, "ZERO_PT"); 253 assert (mdok); 254 psFree (entries); 255 return zp; 256 } 257 psFree (entries); 258 return NAN; 259 }
Note:
See TracChangeset
for help on using the changeset viewer.
