Changeset 6522
- Timestamp:
- Mar 5, 2006, 2:02:35 PM (20 years ago)
- Location:
- trunk/psphot/src
- Files:
-
- 3 added
- 6 edited
-
psModulesUtils.c (modified) (1 diff)
-
psModulesUtils.h (modified) (1 diff)
-
psphotArguments.c (modified) (1 diff)
-
psphotImageLoop.c (modified) (3 diffs)
-
psphotOutput.c (modified) (7 diffs)
-
psphotReadout.c (modified) (1 diff)
-
testPPimageLoop.c (added)
-
testPSastroLoop.c (added)
-
testPSphotLoop.c (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psModulesUtils.c
r6481 r6522 312 312 return false; 313 313 } 314 315 ppImageLoadDepth ppImageCheckDepth (psMetadata *recipe, char *name) { 316 317 bool status; 318 319 // determine the load depth 320 const char *depth = psMetadataLookupStr(&status, recipe, name); 321 if (! status || ! depth || strlen(depth) == 0) { 322 psLogMsg("psphot", PS_LOG_ERROR, "%s not specified in recipe.", name); 323 exit(EXIT_FAILURE); 324 } 325 326 if (!strcasecmp(depth, "FPA")) return (PP_LOAD_FPA); 327 if (!strcasecmp(depth, "CHIP")) return (PP_LOAD_CHIP); 328 if (!strcasecmp(depth, "CELL")) return (PP_LOAD_CELL); 329 330 psLogMsg(__func__, PS_LOG_ERROR, "%s in recipe is not FPA, CHIP or CELL.", name); 331 exit(EXIT_FAILURE); 332 333 return PP_LOAD_NONE; 334 } -
trunk/psphot/src/psModulesUtils.h
r6481 r6522 35 35 } ppFile; 36 36 37 typedef struct { 38 ppFile *input; 39 ppFile *resid; 40 ppFile *background; 41 ppFile *backSub; 42 ppFile *output; 43 ppFile *psfdata; 44 ppFile *psfsample; 45 } psphotData; 46 37 47 // psModule extra utilities 38 48 // bool pmSourceFitModel_EAM(pmSource *source, pmModel *model, const bool PSF); -
trunk/psphot/src/psphotArguments.c
r6481 r6522 176 176 177 177 static void usage (void) { 178 179 178 fprintf (stderr, "USAGE: psphot (image) (output)\n"); 180 179 exit (2); -
trunk/psphot/src/psphotImageLoop.c
r6379 r6522 1 1 # include "psphot.h" 2 2 3 bool psphotImageLoop (p pFile *file, ppConfig *config) {3 bool psphotImageLoop (psphotData *data, ppConfig *config) { 4 4 5 bool status; 6 ppImageLoadDepth imageLoadDepth; 5 pmFPA *fpa = data->input->fpa; 7 6 8 // determine the load depth 9 const char *depth = psMetadataLookupStr(&status, config->recipe, "LOAD.DEPTH"); 10 if (! status || ! depth || strlen(depth) == 0) { 11 psLogMsg("psphot", PS_LOG_ERROR, "LOAD.DEPTH not specified in recipe."); 12 exit(EXIT_FAILURE); 13 } 14 imageLoadDepth = PP_LOAD_NONE; 15 if (!strcasecmp(depth, "FPA")) imageLoadDepth = PP_LOAD_FPA; 16 if (!strcasecmp(depth, "CHIP")) imageLoadDepth = PP_LOAD_CHIP; 17 if (!strcasecmp(depth, "CELL")) imageLoadDepth = PP_LOAD_CELL; 18 if (imageLoadDepth == PP_LOAD_NONE) { 19 psLogMsg(__func__, PS_LOG_ERROR, "LOAD.DEPTH in recipe is not FPA, CHIP or CELL."); 20 exit(EXIT_FAILURE); 21 } 7 psphotDataIO (data, config, -1, -1); 22 8 23 if (imageLoadDepth == PP_LOAD_FPA) { 24 psTrace(__func__, 1, "Loading pixels for FPA...\n"); 25 ppImageLoadPixels(file, config->database, -1, -1); 26 } 27 28 for (int i = 0; i < file->fpa->chips->n; i++) { 29 pmChip *chip = file->fpa->chips->data[i]; // Chip of interest in input image 9 for (int i = 0; i < fpa->chips->n; i++) { 10 pmChip *chip = fpa->chips->data[i]; // Chip of interest in input image 30 11 31 12 psLogMsg ("psphot", 4, "Chip %d: %x %x\n", i, chip->exists, chip->process); 32 13 if (! chip->process) { continue; } 33 14 34 if (imageLoadDepth == PP_LOAD_CHIP) { 35 psTrace(__func__, 1, "Loading pixels for chip %d...\n", i); 36 ppImageLoadPixels(file, config->database, i, -1); 37 } 15 psphotDataIO (data, config, i, -1); 38 16 39 17 for (int j = 0; j < chip->cells->n; j++) { … … 43 21 if (! cell->process) { continue; } 44 22 45 if (imageLoadDepth == PP_LOAD_CELL) { 46 psTrace(__func__, 1, "Loading pixels for chip %d, cell %d...\n", i, j); 47 ppImageLoadPixels(file, config->database, i, j); 48 } 49 23 psphotDataIO (data, config, i, j); 24 50 25 // XXX optional mask and weight input image should be loaded here? 51 26 // this sets the weight map and basic mask applying CELL.BAD and CELL.SATURATION … … 61 36 // run a single-model test if desired 62 37 psphotModelTest (readout, config->arguments, config->recipe); 63 psphotReadout (readout, config->recipe); 64 psphotOutput (readout, config->arguments); 38 39 // run the actual photometry analysis 40 psphotReadout (readout, data, config); 41 42 // XXX what do we do if we have multiple readouts? 43 psphotOutput (readout, data, config); 65 44 } 66 45 } 67 46 } 47 psphotOutputClose (data); 68 48 return true; 69 49 } -
trunk/psphot/src/psphotOutput.c
r6495 r6522 14 14 static char *psfSample = NULL; 15 15 16 void psphotOutputCleanup () { 17 18 psFree (outputRoot); 19 psFree (outputName); 20 psFree (outputMode); 21 psFree (outputFormat); 22 psFree (extNumberFormat); 23 psFree (extNameKey); 24 psFree (extRoot); 25 psFree (psfFile); 26 psFree (psfSample); 27 return; 16 static psFits *outputFits = NULL; 17 static FILE *outputFile = NULL; 18 19 bool psphotDataIO (psphotData *data, ppConfig *config, int chip, int cell) { 20 21 // load input data, if depth is appropriate 22 ppImageLoadDepth loadDepth = ppImageCheckDepth (config->recipe, "LOAD.DEPTH"); 23 if ((chip == -1) && (cell == -1) && (loadDepth == PP_LOAD_FPA)) { 24 psTrace(__func__, 1, "Loading pixels for FPA...\n"); 25 ppImageLoadPixels(data->input, config->database, -1, -1); 26 } 27 if ((chip != -1) && (cell == -1) && (loadDepth == PP_LOAD_CHIP)) { 28 psTrace(__func__, 1, "Loading pixels for chip %d...\n", i); 29 ppImageLoadPixels(data->input, config->database, chip, -1); 30 } 31 if ((chip != -1) && (cell != -1) && (loadDepth == PP_LOAD_CELL)) { 32 psTrace(__func__, 1, "Loading pixels for chip %d, cell %d...\n", i, j); 33 ppImageLoadPixels(data->input, config->database, chip, cell); 34 } 35 36 37 38 if (saveDepth == PP_LOAD_FPA) { 39 psTrace(__func__, 1, "Saving objects for FPA...\n"); 40 psphotOutputOpen (file->fpa->phu); 41 } 42 43 ppImageLoadDepth saveDepth = ppImageCheckDepth (config->recipe, "SAVE.DEPTH"); 44 45 28 46 } 29 47 … … 46 64 extNameKey = psMetadataLookupStr (&status, config->recipe, "EXTNAME"); 47 65 extRoot = psMetadataLookupStr (&status, config->recipe, "EXTROOT"); 66 67 headExtname = psMetadataLookupStr (&status, config->recipe, "HEAD_EXTNAME"); 68 dataExtname = psMetadataLookupStr (&status, config->recipe, "DATA_EXTNAME"); 48 69 49 70 if (extNumberFormat == NULL) { … … 76 97 } 77 98 78 // for MEF output, we need to open a file up front99 // for MEF output, we only allow certain output formats 79 100 if (!strcasecmp (outputMode, "MEF")) { 101 if (!strcasecmp (outputFormat, "CMF")) goto valid_format; 80 102 psLogMsg ("psphot", PS_LOG_ERROR, "MEF output mode unavailable"); 81 103 exit (1); 82 104 } 105 valid_format: 83 106 84 107 // register background image-file names … … 99 122 } 100 123 101 // generate the SPLIT filenames 102 char *psphotSplitName (psMetadata *header) { 103 104 bool status; 105 106 char *newName = NULL; // destination for resulting name 107 char *extNameWord = NULL; // this contains the per-extension word to add 108 char extNumberWord[16]; // this will store the string-formatted number 109 110 // extNumberFormat must be set to a valid entry in psphotOutputPrep 111 sprintf (extNumberWord, extNumberFormat, extNumber); 112 113 // find the extname: 114 char *extNameVal = psMetadataLookupStr (&status, header, extNameKey); 115 116 extNameWord = extNameVal; 117 if ((extRoot != NULL) && (extNameVal != NULL)) { 118 // check that the extNameVal matches the expected root 119 if (strncmp (extNameVal, extRoot, strlen(extRoot))) { 120 psLogMsg ("psphotSplitName", PS_LOG_WARN, "header entry does not match expected format"); 124 bool psphotOutputOpen (psMetadata *phu){ 125 126 /* outputFile is used by text-format outputs */ 127 128 psFree (outputFile); 129 outputFile = psphotOutputName (phu, outputName); 130 131 /* for fits-format output, open outputFits */ 132 if (!strcasecmp (outputFormat, "CMF")) { 133 if (outputFits != NULL) { 134 psFitsClose (outputFits); 121 135 } 122 extNameWord = extNameVal + strlen(extRoot); 123 } 124 125 if (extNameWord != NULL) { 126 psStringStrip (extNameWord); 127 } 128 129 // note : if the user mis-specifies the output name, we will happily overwrite files 130 newName = psStringCopy (outputName); 131 newName = psphotNameSubstitute (newName, outputRoot, "%r"); 132 newName = psphotNameSubstitute (newName, extNameWord, "%x"); 133 newName = psphotNameSubstitute (newName, extNumberWord, "%n"); 134 135 return newName; 136 } 137 138 139 // given the input string, search for the key, and replace with the replacement 140 // the input string may be freed if not needed 141 char *psphotNameSubstitute (char *input, char *replace, char *key) { 142 143 char *p; 144 145 if (key == NULL) return input; 146 if (strlen(key) == 0) return input; 147 148 p = strstr (input, key); 149 if (p == NULL) return input; 150 151 // we have input = xxxkeyxxx 152 // we want output = xxxreplacexxx 153 154 // this is safe since we will subtract strlen(key) elements from input 155 char *output = psAlloc(strlen(input) + strlen(replace) + 1); 156 int Nc = p - input; 157 158 // copy the first segement into 'output' 159 strncpy (output, input, Nc); 160 161 // copy the key replacement to the start of the key 162 163 strcpy (&output[Nc], replace); 164 Nc += strlen (replace); 165 166 // copy the remainder to the end of the replacement 167 strcpy (&output[Nc], p + strlen(key)); 168 169 psFree (input); 170 return output; 136 outputFits = psFitsOpen (outputFile, "w"); 137 138 if (!strcasecmp (outputMode, "MEF")) { 139 psFitsWriteHeader (outputFits, phu); 140 } 141 } 142 return true; 143 } 144 145 bool psphotOutputClose (void) { 146 147 if (outputFile != NULL) { 148 psFitsClose (outputFile); 149 } 150 return true; 171 151 } 172 152 … … 190 170 } 191 171 172 if (!strcasecmp (outputMode, "MEF")) { 173 headExt = psphotOutputName (header, headExtname); 174 dataExt = psphotOutputName (header, dataExtname); 175 } 176 if (!strcasecmp (outputMode, "SPLIT")) { 177 dataExt = psphotOutputName (header, dataExtname); 178 } 179 192 180 char *residImage = psMetadataLookupStr (&status, arguments, "RESID_IMAGE"); 193 194 181 if (psfSample != NULL) psphotSamplePSFs (psf, readout->image, psfSample); 195 182 if (residImage != NULL) psphotSaveImage (header, readout->image, residImage); … … 225 212 } 226 213 if (!strcasecmp (outputFormat, "CMF")) { 227 pmSourcesWriteCMF (sources, outputFile, header);214 pmSourcesWriteCMF (sources, header, headExt, dataExt); 228 215 psFree (outputFile); 229 216 return; … … 483 470 psMetadataAdd (row, PS_LIST_TAIL, "MAG_RAW", PS_DATA_F32, "", source->fitMag + ZERO_POINT); 484 471 psMetadataAdd (row, PS_LIST_TAIL, "MAG_ERR", PS_DATA_F32, "", (int)(1000*dmag)); 485 psMetadataAdd (row, PS_LIST_TAIL, "MAG_GAL", PS_DATA_F32, "", type);486 psMetadataAdd (row, PS_LIST_TAIL, "MAG_AP", PS_DATA_F32, "", lsky);487 psMetadataAdd (row, PS_LIST_TAIL, "LOG_SKY", PS_DATA_F32, "", 32.0);488 psMetadataAdd (row, PS_LIST_TAIL, "FWHM_X", PS_DATA_F32, "", source->apMag + ZERO_POINT);472 psMetadataAdd (row, PS_LIST_TAIL, "MAG_GAL", PS_DATA_F32, "", 32.0); 473 psMetadataAdd (row, PS_LIST_TAIL, "MAG_AP", PS_DATA_F32, "", source->apMag + ZERO_POINT); 474 psMetadataAdd (row, PS_LIST_TAIL, "LOG_SKY", PS_DATA_F32, "", lsky); 475 psMetadataAdd (row, PS_LIST_TAIL, "FWHM_X", PS_DATA_F32, "", type); 489 476 psMetadataAdd (row, PS_LIST_TAIL, "FWHM_Y", PS_DATA_F32, "", PAR[4]); 490 477 psMetadataAdd (row, PS_LIST_TAIL, "THETA", PS_DATA_F32, "", PAR[5]); -
trunk/psphot/src/psphotReadout.c
r6481 r6522 12 12 // generate a background model (median, smoothed image) 13 13 skymodel = psphotImageMedian (readout, config); 14 15 // optional output of background-subtracted image 16 psphot 14 17 15 18 // find the peaks in the image
Note:
See TracChangeset
for help on using the changeset viewer.
