Changeset 6311
- Timestamp:
- Feb 2, 2006, 1:30:35 PM (20 years ago)
- Location:
- trunk/psphot/src
- Files:
-
- 18 edited
-
Makefile.am (modified) (2 diffs)
-
pmCellSetMask.c (modified) (2 diffs)
-
psLibUtils.h (modified) (1 diff)
-
psLine.c (modified) (1 diff)
-
psModulesUtils.c (modified) (1 diff)
-
psModulesUtils.h (modified) (1 diff)
-
psphot.c (modified) (1 diff)
-
psphot.h (modified) (4 diffs)
-
psphotArguments.c (modified) (6 diffs)
-
psphotDefinePixels.c (modified) (1 diff)
-
psphotFindPeaks.c (modified) (1 diff)
-
psphotGrowthCurve.c (modified) (1 diff)
-
psphotImageBackground.c (modified) (1 diff)
-
psphotImageLoop.c (modified) (4 diffs)
-
psphotModelTest.c (modified) (7 diffs)
-
psphotOutput.c (modified) (6 diffs)
-
psphotParseCamera.c (modified) (5 diffs)
-
psphotReadout.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/Makefile.am
r6141 r6311 1 lib_LTLIBRARIES = libpsphot.la 2 bin_PROGRAMS = psphot psphotTest 1 # lib_LTLIBRARIES = libpsphot.la 2 # libpsphot_la_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(psphot_CFLAGS) 3 # libpsphot_la_LDFLAGS = $(PSMODULE_LIBS) $(PSLIB_LIBS) 3 4 4 libpsphot_la_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(psphot_CFLAGS) 5 libpsphot_la_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS) 5 bin_PROGRAMS = psphot 6 psphot_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(psphot_CFLAGS) 7 psphot_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS) 6 8 7 psphot_CPPFLAGS = $(libpsphot_la_CPPFLAGS) 8 psphot_LDADD = libpsphot.la 9 # psphot_CPPFLAGS = $(libpsphot_la_CPPFLAGS) 10 # psphot_LDFLAGS = $(PSMODULE_LIBS) $(PSLIB_LIBS) 11 # psphot_LDADD = libpsphot.la 9 12 10 psphotTest_CPPFLAGS = $(libpsphot_la_CPPFLAGS) 11 psphotTest_LDADD = libpsphot.la 12 13 14 libpsphot_la_SOURCES = \ 13 psphot_SOURCES = \ 15 14 psphotReadout.c \ 16 15 psphotImageStats.c \ … … 46 45 pmModelFitSet.c \ 47 46 pmCellSetMask.c \ 48 pmSourceFitSet.c 49 50 51 psphot_SOURCES = \ 47 pmSourceFitSet.c \ 52 48 psphot.c \ 53 49 psphotArguments.c \ 54 50 psphotParseCamera.c \ 55 psphot ImageLoop.c \56 psphot ModelTest.c51 psphotModelTest.c \ 52 psphotImageLoop.c 57 53 58 psphotTest_SOURCES = \ 59 psphotTest.c \ 60 psImageJpeg.c \ 61 psphotTestArguments.c 62 63 include_HEADERS = \ 54 noinst_HEADERS = \ 64 55 psLibUtils.h \ 65 56 psModulesUtils.h \ -
trunk/psphot/src/pmCellSetMask.c
r6117 r6311 6 6 7 7 // mask the excluded outer pixels 8 // these coordinates refer to the parent image 9 // these bounds will saturate on the subimage 10 // negative upper bounds will subtract from the *subimage* 8 11 float XMIN = psMetadataLookupF32 (&status, recipe, "XMIN"); 9 12 float XMAX = psMetadataLookupF32 (&status, recipe, "XMAX"); … … 17 20 pmReadout *readout = readouts->data[i]; // The readout of interest 18 21 22 // psRegionForImage creates a region for the subimage, not the parent 23 // XXX I propose that psRegionForImage treat the region as referring to the parent... 19 24 psRegion keep = psRegionForImage (readout->image, valid); 25 26 // psImageKeepRegion assumes the region refers to the parent coordinates 20 27 psImageKeepRegion (readout->mask, keep, "OR", PSPHOT_MASK_INVALID); 21 28 } -
trunk/psphot/src/psLibUtils.h
r5607 r6311 14 14 bool psLineInit (psLine *line); 15 15 bool psLineAdd (psLine *line, char *format, ...); 16 int psStringStrip (char *string); 16 17 17 18 # endif -
trunk/psphot/src/psLine.c
r5980 r6311 47 47 } 48 48 49 #ifndef whitespace 50 #define whitespace(c) (((c) == ' ') || ((c) == '\t')) 51 #endif 52 53 /* Strip whitespace from the start and end of STRING. */ 54 int psStringStrip (char *string) { 55 56 int i; 57 58 if (string == (char *) NULL) return (FALSE); 59 60 for (i = 0; whitespace (string[i]); i++); 61 if (i) memmove (string, string + i, strlen(string+i)+1); 62 for (i = strlen (string) - 1; (i > 0) && whitespace (string[i]); i--); 63 string[++i] = 0; 64 return (i); 65 66 } -
trunk/psphot/src/psModulesUtils.c
r6117 r6311 193 193 config->recipe = NULL; 194 194 config->arguments = NULL; 195 config->options = NULL; 195 196 config->database = NULL; 196 197 -
trunk/psphot/src/psModulesUtils.h
r6117 r6311 22 22 psMetadata *camera; // The camera configuration 23 23 psMetadata *recipe; // The recipe (i.e., specific setups) 24 psMetadata *arguments; // The command-line arguments 24 psMetadata *arguments; // Command-line arguments 25 psMetadata *options; // Command-line recipe options 25 26 psDB *database; // Database handle 26 27 } ppConfig; -
trunk/psphot/src/psphot.c
r6117 r6311 15 15 ppFile *input = psphotParseCamera (config); 16 16 17 // run a single-model test if desired - XXX push in psphotImageLoop?18 // psphotModelTest (input, options);17 // check on output mode,format, setup basic filename, etc 18 psphotOutputPrep (input, config); 19 19 20 20 // call psphot for each readout -
trunk/psphot/src/psphot.h
r6117 r6311 24 24 bool psphotImageLoop (ppFile *input, ppConfig *config); 25 25 26 bool psphotModelTest (pmReadout *readout, psMetadata * config);26 bool psphotModelTest (pmReadout *readout, psMetadata *arguments, psMetadata *recipe); 27 27 bool psphotReadout (pmReadout *readout, psMetadata *config); 28 28 bool ppImageLoadPixels (ppFile *input, psDB *db, int chipNum, int cellNum); … … 36 36 bool psphotBasicDeblend (psArray *sources, psMetadata *config, psStats *sky); 37 37 pmPSF *psphotChoosePSF (psMetadata *config, psArray *sources, psStats *sky); 38 void psphotOutput (pmReadout *readout, psMetadata * config);38 void psphotOutput (pmReadout *readout, psMetadata *arguments); 39 39 40 40 // optional object analysis steps … … 80 80 bool pmMomentsWriteText (psArray *sources, char *filename); 81 81 82 bool psphotSamplePSFs (psMetadata *config, pmPSF *psf, psImage *image);82 bool psphotSamplePSFs (pmPSF *psf, psImage *image, char *output); 83 83 bool psphotDumpMoments (psMetadata *config, psArray *sources); 84 84 int psphotSaveImage (psMetadata *header, psImage *image, char *filename); … … 86 86 int pmSourcesDophotType (pmSource *source); 87 87 bool psMetadataItemTransfer (psMetadata *out, psMetadata *in, char *key); 88 89 char *psphotSplitName (psMetadata *header); 90 void psphotOutputPrep (ppFile *file, ppConfig *config); 91 char *psphotNameSubstitute (char *input, char *replace, char *key); 88 92 89 93 bool psphotMagnitudes (psMetadata *config, psArray *sources, pmPSF *psf); -
trunk/psphot/src/psphotArguments.c
r6117 r6311 1 1 # include "psphot.h" 2 2 3 static void usage ( psMetadata *arguments);3 static void usage (void); 4 4 5 5 ppConfig *psphotArguments (int *argc, char **argv) { 6 6 7 7 int N; 8 9 if (*argc == 1) usage (); 8 10 9 11 // basic pslib options … … 22 24 23 25 // arguments (must be supplied for each run, or not used) 24 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-psf", 0, "input psf file", ""); 25 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-mask", 0, "Name of the mask image", ""); 26 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-resid", 0, "Name of the output residual image", ""); 27 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-weight", 0, "Name of the weight image", ""); 28 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "-chip", 0, "Chip number to process (if positive)", -1); 29 26 // mask image (input) is used by psphotImageLoop 27 if ((N = psArgumentGet (*argc, argv, "-mask"))) { 28 psArgumentRemove (N, argc, argv); 29 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "MASK_IMAGE", PS_META_REPLACE, "", psStringCopy(argv[N])); 30 psArgumentRemove (N, argc, argv); 31 } 32 33 // weight image (input) is used by psphotImageLoop 34 if ((N = psArgumentGet (*argc, argv, "-weight"))) { 35 psArgumentRemove (N, argc, argv); 36 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "WEIGHT_IMAGE", PS_META_REPLACE, "", psStringCopy(argv[N])); 37 psArgumentRemove (N, argc, argv); 38 } 39 40 // residual image (output) is used by psphotOutput 41 if ((N = psArgumentGet (*argc, argv, "-resid"))) { 42 psArgumentRemove (N, argc, argv); 43 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "RESID_IMAGE", PS_META_REPLACE, "", psStringCopy(argv[N])); 44 psArgumentRemove (N, argc, argv); 45 } 46 47 // chip selection is used to limit chips to be processed 48 if ((N = psArgumentGet (*argc, argv, "-chip"))) { 49 psArgumentRemove (N, argc, argv); 50 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "CHIP_SELECTION", PS_META_REPLACE, "", psStringCopy(argv[N])); 51 psArgumentRemove (N, argc, argv); 52 } 53 30 54 // run the test model (requires X,Y coordinate) 31 55 if ((N = psArgumentGet (*argc, argv, "-modeltest"))) { … … 58 82 } 59 83 60 // Parse command-line overrides of recipe values61 psMetadata *recipe= psMetadataAlloc ();84 // these other options override the recipe options 85 config->options = psMetadataAlloc (); 62 86 63 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "-photcode", 0, "photometry code", "NONE"); 64 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "-break", 0, "", "NONE"); 65 psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "-fitmode", 0, "", 2); 66 67 // analysis region : XXX override recipe 68 if ((N = psArgumentGet (*argc, argv, "-photcode"))) { 87 // PSF : optional psf file to be loaded 88 if ((N = psArgumentGet (*argc, argv, "-psf"))) { 69 89 psArgumentRemove (N, argc, argv); 70 psMetadataAddStr ( recipe, PS_LIST_TAIL, "PHOTCODE", PS_META_REPLACE, "", psStringCopy(argv[N]));90 psMetadataAddStr (config->options, PS_LIST_TAIL, "PSF_INPUT_FILE", PS_META_REPLACE, "", psStringCopy(argv[N])); 71 91 psArgumentRemove (N, argc, argv); 72 92 } 73 93 74 // analysis region : XXX override recipe75 if ((N = psArgumentGet (*argc, argv, "- break"))) {94 // photcode : used in output to supplement header data (argument or recipe?) 95 if ((N = psArgumentGet (*argc, argv, "-photcode"))) { 76 96 psArgumentRemove (N, argc, argv); 77 psMetadataAddStr ( recipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", psStringCopy(argv[N]));97 psMetadataAddStr (config->options, PS_LIST_TAIL, "PHOTCODE", PS_META_REPLACE, "", psStringCopy(argv[N])); 78 98 psArgumentRemove (N, argc, argv); 79 99 } 80 100 81 // analysis region : XXX override recipe82 if ((N = psArgumentGet (*argc, argv, "- fitmode"))) {101 // break : used from recipe throughout psphotReadout 102 if ((N = psArgumentGet (*argc, argv, "-break"))) { 83 103 psArgumentRemove (N, argc, argv); 84 psMetadataAddStr ( recipe, PS_LIST_TAIL, "FITMODE", PS_META_REPLACE, "", psStringCopy(argv[N]));104 psMetadataAddStr (config->options, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", psStringCopy(argv[N])); 85 105 psArgumentRemove (N, argc, argv); 86 106 } 87 107 88 // analysis region : XXX override recipe 108 // fitmode : used from recipe throughout psphotReadout 109 if ((N = psArgumentGet (*argc, argv, "-fitmode"))) { 110 psArgumentRemove (N, argc, argv); 111 psMetadataAddStr (config->options, PS_LIST_TAIL, "FITMODE", PS_META_REPLACE, "", psStringCopy(argv[N])); 112 psArgumentRemove (N, argc, argv); 113 } 114 115 // analysis region : overrides recipe value, used in psphotReadout/psphotEnsemblePSF 89 116 if ((N = psArgumentGet (*argc, argv, "-region"))) { 90 117 psArgumentRemove (N, argc, argv); 91 psMetadataAddStr ( recipe, PS_LIST_TAIL, "ANALYSIS_REGION", 0, "", psStringCopy(argv[N]));118 psMetadataAddStr (config->options, PS_LIST_TAIL, "ANALYSIS_REGION", 0, "", psStringCopy(argv[N])); 92 119 psArgumentRemove (N, argc, argv); 93 120 } … … 96 123 while ((N = psArgumentGet (*argc, argv, "-D"))) { 97 124 psArgumentRemove (N, argc, argv); 98 psMetadataAddStr ( recipe, PS_LIST_TAIL, argv[N], 0, "", argv[N+1]);125 psMetadataAddStr (config->options, PS_LIST_TAIL, argv[N], 0, "", argv[N+1]); 99 126 psArgumentRemove (N, argc, argv); 100 127 psArgumentRemove (N, argc, argv); … … 104 131 while ((N = psArgumentGet (*argc, argv, "-Df"))) { 105 132 psArgumentRemove (N, argc, argv); 106 psMetadataAddF32 ( recipe, PS_LIST_TAIL, argv[N], 0, "", atof(argv[N+1]));133 psMetadataAddF32 (config->options, PS_LIST_TAIL, argv[N], 0, "", atof(argv[N+1])); 107 134 psArgumentRemove (N, argc, argv); 108 135 psArgumentRemove (N, argc, argv); … … 112 139 while ((N = psArgumentGet (*argc, argv, "-Di"))) { 113 140 psArgumentRemove (N, argc, argv); 114 psMetadataAddS32 ( recipe, PS_LIST_TAIL, argv[N], 0, "", atoi(argv[N+1]));141 psMetadataAddS32 (config->options, PS_LIST_TAIL, argv[N], 0, "", atoi(argv[N+1])); 115 142 psArgumentRemove (N, argc, argv); 116 143 psArgumentRemove (N, argc, argv); 117 144 } 118 145 119 // place the recipe options on the arguments stack 120 psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "RECIPE.OPTIONS", PS_DATA_UNKNOWN, "", recipe); 121 122 if (!psArgumentParse(config->arguments, argc, argv)) usage (config->arguments); 123 if (*argc != 3) usage (config->arguments); 146 if (*argc != 3) usage (); 124 147 125 148 // input and output positions are fixed 126 psMetadataAddStr (config->arguments, PS_LIST_TAIL, " -input", PS_META_REPLACE, "", argv[1]);127 psMetadataAddStr (config->arguments, PS_LIST_TAIL, " -output", PS_META_REPLACE, "", argv[2]);149 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "INPUT_FILE", PS_META_REPLACE, "", argv[1]); 150 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "OUTPUT_ROOT", PS_META_REPLACE, "", argv[2]); 128 151 152 psTrace(__func__, 1, "Done with psphotArguments...\n"); 129 153 return (config); 130 154 } 131 155 132 static void usage ( psMetadata *arguments) {156 static void usage (void) { 133 157 134 158 fprintf (stderr, "USAGE: psphot (image) (output)\n"); 135 psArgumentHelp (arguments);136 159 exit (2); 137 160 } -
trunk/psphot/src/psphotDefinePixels.c
r6056 r6311 1 1 # include "psphot.h" 2 2 3 // x,y are defined in the parent image coords of readout->image 3 4 bool psphotDefinePixels(pmSource *mySource, 4 5 const pmReadout *readout, -
trunk/psphot/src/psphotFindPeaks.c
r6056 r6311 16 16 17 17 psImage *smooth = psImageCopy (NULL, readout->image, PS_TYPE_F32); 18 psphotSaveImage (NULL, smooth, "presmooth.fits"); 19 18 20 psImageSmooth (smooth, SIGMA, NSIGMA); 19 21 psLogMsg ("psphot", 4, "smooth: %f sec\n", psTimerMark ("psphot")); 22 23 psphotSaveImage (NULL, smooth, "smooth.fits"); 20 24 21 25 psTimerStart ("psphot"); -
trunk/psphot/src/psphotGrowthCurve.c
r6056 r6311 15 15 pmModel *modelRef = pmModelAlloc(psf->type); 16 16 17 // use this image region18 xc = 0.5* readout->image->numCols;19 yc = 0.5* readout->image->numRows;17 // use center of the image 18 xc = 0.5*(readout->image->numCols + readout->image->col0); 19 yc = 0.5*(readout->image->numRows + readout->image->row0); 20 20 dx = psf->growth->maxRadius + 1; 21 21 dy = psf->growth->maxRadius + 1; -
trunk/psphot/src/psphotImageBackground.c
r6056 r6311 28 28 double frnd = psRandomUniform (rnd); 29 29 int pixel = Npixels * frnd; 30 int ix = pixel /image->numCols;31 int iy = pixel %image->numCols;30 int ix = pixel % image->numCols; 31 int iy = pixel / image->numCols; 32 32 float value = image->data.F32[iy][ix]; 33 33 if (fabs(value - Sky) > dSky) continue; -
trunk/psphot/src/psphotImageLoop.c
r6117 r6311 5 5 bool status; 6 6 ppImageLoadDepth imageLoadDepth; 7 char filename[1024];8 7 9 8 // determine the load depth … … 27 26 } 28 27 29 char *outputRoot = psMetadataLookupPtr (&status, config->arguments, "-output");30 if (!status) psAbort ("psphot", "output file not specified");31 32 int Nout = 0;33 28 for (int i = 0; i < file->fpa->chips->n; i++) { 34 29 pmChip *chip = file->fpa->chips->data[i]; // Chip of interest in input image … … 53 48 } 54 49 50 // XXX optional mask and weight input image should be loaded here? 51 // this sets the weight map and basic mask applying CELL.BAD and CELL.SATURATION 55 52 pmCellSetWeights(cell); 56 53 … … 58 55 pmCellSetMask (cell, config->recipe); 59 56 60 61 57 // process each of the readouts 62 58 for (int k = 0; k < cell->readouts->n; k++) { 63 59 pmReadout *readout = cell->readouts->data[k]; // Readout of interest in input image 64 60 65 // psphotSaveImage (NULL, readout->image, "image.fits"); 66 // psphotSaveImage (NULL, readout->weight, "weight.fits"); 67 // psphotSaveImage (NULL, readout->mask, "mask.fits"); 61 // run a single-model test if desired 62 psphotModelTest (readout, config->arguments, config->recipe); 68 63 69 64 psphotReadout (readout, config->recipe); 70 71 // XXX EAM : temporarily write out only CMF with fixed extension 72 sprintf (filename, "%s.%02d.cmf", outputRoot, Nout); 73 psMetadata *header = pmReadoutGetHeader (readout); 74 75 psArray *sources = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.SOURCES"); 76 77 pmSourcesWriteCMF (sources, filename, header); 78 Nout++; 65 psphotOutput (readout, config->arguments); 79 66 } 80 67 } -
trunk/psphot/src/psphotModelTest.c
r6056 r6311 2 2 # include "psEllipse.h" 3 3 4 bool psphotModelTest (pmReadout *readout, psMetadata * config) {4 bool psphotModelTest (pmReadout *readout, psMetadata *arguments, psMetadata *recipe) { 5 5 6 6 bool status; … … 14 14 15 15 // run model fitting tests on a single source 16 if (!psMetadataLookupBool (&status, config, "TEST_FIT")) return false;16 if (!psMetadataLookupBool (&status, arguments, "TEST_FIT")) return false; 17 17 18 18 // what fitting mode to use? 19 char *psfModeWord = psMetadataLookupPtr (&status, config, "TEST_FIT_MODE");19 char *psfModeWord = psMetadataLookupPtr (&status, arguments, "TEST_FIT_MODE"); 20 20 if (!status) { 21 21 psfModeWord = psStringCopy ("EXT"); … … 25 25 // in psfMode, psf sets the model type 26 26 if (psfMode) { 27 char *psfFile = psMetadataLookupPtr (&status, config, "PSF_INPUT_FILE");27 char *psfFile = psMetadataLookupPtr (&status, arguments, "PSF_INPUT_FILE"); 28 28 if (!status) psAbort ("psphotModelTest", "PSF_INPUT_FILE not supplied"); 29 29 psMetadata *psfData = psMetadataConfigParse (NULL, &Nfail, psfFile, FALSE); … … 32 32 } else { 33 33 // find the model: supplied by user or first in the PSF_MODEL list 34 char *modelName = psMetadataLookupPtr (&status, config, "TEST_FIT_MODEL");34 char *modelName = psMetadataLookupPtr (&status, arguments, "TEST_FIT_MODEL"); 35 35 if (modelName == NULL) { 36 36 // get the list pointers for the PSF_MODEL entries 37 psMetadataItem *mdi = psMetadataLookup (config, "PSF_MODEL"); 38 if (mdi == NULL) psAbort ("psphotChoosePSF", "missing PSF_MODEL selection"); 37 38 psList *list = NULL; 39 psMetadataItem *mdi = psMetadataLookup (recipe, "PSF_MODEL"); 40 if (mdi == NULL) psAbort ("psphotModelTest", "missing PSF_MODEL selection"); 41 if (mdi->type == PS_DATA_STRING) { 42 list = psListAlloc(NULL); 43 psListAdd (list, PS_LIST_HEAD, mdi); 44 } else { 45 if (mdi->type != PS_DATA_METADATA_MULTI) psAbort ("psphotChoosePSF", "missing PSF_MODEL selection"); 46 list = psMemIncrRefCounter(mdi->data.list); 47 } 39 48 40 49 // take the first list element 41 psList *list = (psList *) mdi->data.list;42 50 item = psListGet (list, PS_LIST_HEAD); 43 51 modelName = item->data.V; … … 48 56 49 57 // find the fitting parameters (try test values first) 50 float INNER = psMetadataLookupF32 (&status, config, "TEST_FIT_INNER_RADIUS");58 float INNER = psMetadataLookupF32 (&status, arguments, "TEST_FIT_INNER_RADIUS"); 51 59 if (!status) { 52 INNER = psMetadataLookupF32 (&status, config, "SKY_INNER_RADIUS");60 INNER = psMetadataLookupF32 (&status, recipe, "SKY_INNER_RADIUS"); 53 61 } 54 62 55 float OUTER = psMetadataLookupF32 (&status, config, "TEST_FIT_OUTER_RADIUS");63 float OUTER = psMetadataLookupF32 (&status, arguments, "TEST_FIT_OUTER_RADIUS"); 56 64 if (!status) { 57 OUTER = psMetadataLookupF32 (&status, config, "SKY_OUTER_RADIUS");65 OUTER = psMetadataLookupF32 (&status, recipe, "SKY_OUTER_RADIUS"); 58 66 } 59 67 60 float RADIUS = psMetadataLookupF32 (&status, config, "TEST_FIT_RADIUS");68 float RADIUS = psMetadataLookupF32 (&status, arguments, "TEST_FIT_RADIUS"); 61 69 if (!status) { 62 RADIUS = psMetadataLookupF32 (&status, config, "PSF_FIT_RADIUS");70 RADIUS = psMetadataLookupF32 (&status, recipe, "PSF_FIT_RADIUS"); 63 71 } 64 72 65 float mRADIUS = psMetadataLookupF32 (&status, config, "TEST_MOMENTS_RADIUS");73 float mRADIUS = psMetadataLookupF32 (&status, arguments, "TEST_MOMENTS_RADIUS"); 66 74 if (!status) { 67 mRADIUS = psMetadataLookupF32 (&status, config, "PSF_MOMENTS_RADIUS");75 mRADIUS = psMetadataLookupF32 (&status, recipe, "PSF_MOMENTS_RADIUS"); 68 76 } 69 77 70 78 // define the source of interest 71 float xObj = psMetadataLookupF32 (&status, config, "TEST_FIT_X");72 float yObj = psMetadataLookupF32 (&status, config, "TEST_FIT_Y");79 float xObj = psMetadataLookupF32 (&status, arguments, "TEST_FIT_X"); 80 float yObj = psMetadataLookupF32 (&status, arguments, "TEST_FIT_Y"); 73 81 74 82 // construct the source structures … … 111 119 } 112 120 sprintf (name, "TEST_FIT_PAR%d", i); 113 value = psMetadataLookupF32 (&status, config, name);121 value = psMetadataLookupF32 (&status, arguments, name); 114 122 if (status) { 115 123 params[i] = value; … … 145 153 psImageKeepCircle (source->mask, xObj, yObj, RADIUS, "OR", PSPHOT_MASK_MARKED); 146 154 147 char *fitset = psMetadataLookupPtr (&status, config, "TEST_FIT_SET");155 char *fitset = psMetadataLookupPtr (&status, arguments, "TEST_FIT_SET"); 148 156 if (status) { 149 157 status = psphotFitSet (source, model, fitset, psfMode); -
trunk/psphot/src/psphotOutput.c
r6117 r6311 1 1 # include "psphot.h" 2 2 3 static int extNumber = -1; 4 5 static char *outputName = NULL; 6 static char *outputRoot = NULL; 7 static char *outputMode = NULL; 8 static char *outputFormat = NULL; 9 10 static char *extNumberFormat = NULL; 11 static char *extNameKey = NULL; 12 static char *extRoot = NULL; 13 14 void psphotOutputPrep (ppFile *file, ppConfig *config) { 15 16 bool status; 17 18 outputRoot = psMetadataLookupPtr (&status, config->arguments, "OUTPUT_ROOT"); 19 if (!status) psAbort ("psphot", "output file not specified"); 20 21 outputName = psMetadataLookupPtr (&status, config->recipe, "OUTPUT_NAME"); 22 outputMode = psMetadataLookupPtr (&status, config->recipe, "OUTPUT_MODE"); 23 outputFormat = psMetadataLookupPtr (&status, config->recipe, "OUTPUT_FORMAT"); 24 25 // rules to construct output names 26 extNumberFormat = psMetadataLookupPtr (&status, config->recipe, "EXTNUMBER_FORMAT"); 27 extNameKey = psMetadataLookupPtr (&status, config->recipe, "EXTNAME"); 28 extRoot = psMetadataLookupPtr (&status, config->recipe, "EXTROOT"); 29 30 if (extNumberFormat == NULL) { 31 extNumberFormat = psStringCopy ("%02d"); 32 } 33 34 psStringStrip (outputName); 35 psStringStrip (extNameKey); 36 psStringStrip (extRoot); 37 38 // validate the outputMode and outputFormat 39 status = false; 40 status |= !strcasecmp (outputFormat, "TEXT"); 41 status |= !strcasecmp (outputFormat, "OBJ"); 42 status |= !strcasecmp (outputFormat, "SX"); 43 status |= !strcasecmp (outputFormat, "CMP"); 44 status |= !strcasecmp (outputFormat, "CMF"); 45 if (!status) { 46 psLogMsg ("psphot", PS_LOG_ERROR, "invalid output format %s", outputFormat); 47 exit (1); 48 } 49 50 // validate the outputMode and outputFormat 51 status = false; 52 status |= !strcasecmp (outputMode, "MEF"); 53 status |= !strcasecmp (outputMode, "SPLIT"); 54 if (!status) { 55 psLogMsg ("psphot", PS_LOG_ERROR, "invalid output mode %s", outputMode); 56 exit (1); 57 } 58 59 // for MEF output, we need to open a file up front 60 if (!strcasecmp (outputMode, "MEF")) { 61 psLogMsg ("psphot", PS_LOG_ERROR, "MEF output mode unavailable"); 62 exit (1); 63 } 64 65 return; 66 } 67 68 // generate the SPLIT filenames 69 char *psphotSplitName (psMetadata *header) { 70 71 bool status; 72 73 char *newName = NULL; // destination for resulting name 74 char *extNameWord = NULL; // this contains the per-extension word to add 75 char extNumberWord[16]; // this will store the string-formatted number 76 77 // extNumberFormat must be set to a valid entry in psphotOutputPrep 78 sprintf (extNumberWord, extNumberFormat, extNumber); 79 80 // find the extname: 81 char *extNameVal = psMetadataLookupPtr (&status, header, extNameKey); 82 83 extNameWord = extNameVal; 84 if ((extRoot != NULL) && (extNameVal != NULL)) { 85 // check that the extNameVal matches the expected root 86 if (strncmp (extNameVal, extRoot, strlen(extRoot))) { 87 psLogMsg ("psphotSplitName", PS_LOG_WARN, "header entry does not match expected format"); 88 } 89 extNameWord = extNameVal + strlen(extRoot); 90 } 91 92 if (extNameWord != NULL) { 93 psStringStrip (extNameWord); 94 } 95 96 // note : if the user mis-specifies the output name, we will happily overwrite files 97 newName = psStringCopy (outputName); 98 newName = psphotNameSubstitute (newName, outputRoot, "%r"); 99 newName = psphotNameSubstitute (newName, extNameWord, "%x"); 100 newName = psphotNameSubstitute (newName, extNumberWord, "%n"); 101 102 return newName; 103 } 104 105 106 // given the input string, search for the key, and replace with the replacement 107 // the input string may be freed if not needed 108 char *psphotNameSubstitute (char *input, char *replace, char *key) { 109 110 char *p; 111 112 if (key == NULL) return input; 113 if (strlen(key) == 0) return input; 114 115 p = strstr (input, key); 116 if (p == NULL) return input; 117 118 // we have input = xxxkeyxxx 119 // we want output = xxxreplacexxx 120 121 // this is safe since we will subtract strlen(key) elements from input 122 char *output = psAlloc(strlen(input) + strlen(replace) + 1); 123 int Nc = p - input; 124 125 // copy the first segement into 'output' 126 strncpy (output, input, Nc); 127 128 // copy the key replacement to the start of the key 129 130 strcpy (&output[Nc], replace); 131 Nc += strlen (replace); 132 133 // copy the remainder to the end of the replacement 134 strcpy (&output[Nc], p + strlen(key)); 135 136 psFree (input); 137 return output; 138 } 139 3 140 // output functions: we have several fixed modes (sx, obj, cmp) 4 void psphotOutput (pmReadout *readout, psMetadata * config) {141 void psphotOutput (pmReadout *readout, psMetadata *arguments) { 5 142 6 143 bool status; 144 char *outputFile; 7 145 8 146 psTimerStart ("psphot"); … … 13 151 pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF"); 14 152 15 char *outputMode = psMetadataLookupPtr (&status, config, "OUTPUT_MODE"); 16 char *outputFile = psMetadataLookupPtr (&status, config, "OUTPUT_FILE"); 17 char *residImage = psMetadataLookupPtr (&status, config, "RESID_IMAGE"); 18 char *psfFile = psMetadataLookupPtr (&status, config, "PSF_OUTPUT_FILE"); 19 153 // starting value is -1 154 extNumber ++; 155 156 // for SPLIT output, we need to open a file for each output call 157 if (!strcasecmp (outputMode, "SPLIT")) { 158 outputFile = psphotSplitName (header); 159 } else { 160 // construct appropriate extname 161 psAbort ("psphotOutput", "programming error"); 162 } 163 164 fprintf (stderr, "output file: %s\n", outputFile); 165 return; 166 167 char *psfFile = psMetadataLookupPtr (&status, arguments, "PSF_OUTPUT_FILE"); 168 char *psfSample = psMetadataLookupPtr (&status, arguments, "PSF_SAMPLE_FILE"); 169 char *residImage = psMetadataLookupPtr (&status, arguments, "RESID_IMAGE"); 170 171 if (psfSample != NULL) psphotSamplePSFs (psf, readout->image, psfSample); 20 172 if (residImage != NULL) psphotSaveImage (header, readout->image, residImage); 21 psphotSamplePSFs (config, psf, readout->image);22 173 23 174 if (psfFile != NULL) { … … 30 181 return; 31 182 } 32 if (output Mode== NULL) {33 psLogMsg ("output", 3, "no data output modeselected");183 if (outputFormat == NULL) { 184 psLogMsg ("output", 3, "no data output format selected"); 34 185 return; 35 186 } 36 if (!strcasecmp (output Mode, "SX")) {187 if (!strcasecmp (outputFormat, "SX")) { 37 188 pmSourcesWriteSX (sources, outputFile); 38 189 return; 39 190 } 40 if (!strcasecmp (output Mode, "OBJ")) {191 if (!strcasecmp (outputFormat, "OBJ")) { 41 192 pmSourcesWriteOBJ (sources, outputFile); 42 193 return; 43 194 } 44 if (!strcasecmp (output Mode, "CMP")) {195 if (!strcasecmp (outputFormat, "CMP")) { 45 196 pmSourcesWriteCMP (sources, outputFile, header); 46 197 return; 47 198 } 48 if (!strcasecmp (output Mode, "CMF")) {199 if (!strcasecmp (outputFormat, "CMF")) { 49 200 pmSourcesWriteCMF (sources, outputFile, header); 50 201 return; 51 202 } 52 if (!strcasecmp (output Mode, "TEXT")) {203 if (!strcasecmp (outputFormat, "TEXT")) { 53 204 pmSourcesWriteText (sources, outputFile); 54 205 return; 55 206 } 56 207 57 psAbort ("psphot", "unknown output mode %s", output Mode);208 psAbort ("psphot", "unknown output mode %s", outputFormat); 58 209 } 59 210 … … 560 711 } 561 712 562 563 bool psphotSamplePSFs (psMetadata *config, pmPSF *psf, psImage *image) { 564 565 bool status; 713 bool psphotSamplePSFs (pmPSF *psf, psImage *image, char *output) { 566 714 567 715 // make sample PSFs for 4 corners and the center … … 569 717 570 718 // optional dump of all rough source data 571 char *output = psMetadataLookupPtr (&status, config, "PSF_SAMPLE_FILE");572 if (!status) return false;573 if (output == NULL) return false;574 719 if (output[0] == 0) return false; 575 720 … … 580 725 psFits *fits = psFitsOpen (output, "w"); 581 726 727 // the centers are in parent coordinates; they do not need to correspond to valid pixels... 582 728 sample = pmModelPSFatXY (image, modelEXT, psf, 25, 25, 25, 25); 583 729 psFitsWriteImage (fits, NULL, sample, 0); -
trunk/psphot/src/psphotParseCamera.c
r6117 r6311 1 1 # include "psphot.h" 2 3 # define METADATA_ADD_DEFAULT(CONFIG, TYPE, NAME, VALUE, COMMENT)\ 4 { psMetadataItem *ITEM; \ 5 ITEM = psMetadataLookup (CONFIG, NAME); \ 6 if (ITEM == NULL) { \ 7 psMetadataAdd##TYPE (CONFIG, PS_LIST_TAIL, NAME, 0, COMMENT, VALUE); \ 8 } else { psFree (ITEM); } } 2 9 3 10 ppFile *psphotParseCamera (ppConfig *config) { 4 11 5 bool status;6 7 12 ppFile *input = ppFileAlloc (); 8 13 9 input->filename = psMemIncrRefCounter(psMetadataLookupStr(NULL, config->arguments, " -input"));14 input->filename = psMemIncrRefCounter(psMetadataLookupStr(NULL, config->arguments, "INPUT_FILE")); 10 15 11 16 // Open the input image … … 33 38 } 34 39 35 // Determine the correct recipe to use 36 // if the user specifies a recipe, no default values are supplied40 // Determine the correct recipe to use (from camera or from user) 41 // if config->recipe is not NULL, it is a user-supplied recipe 37 42 if (!config->recipe) { 38 39 43 config->recipe = pmConfigRecipeFromCamera(config->camera, PSPHOT_RECIPE); 40 44 if (config->recipe == NULL) { … … 43 47 } 44 48 } 45 46 // recipe override values: 47 psMetadata *recipe = psMetadataLookupPtr (&status, config->arguments, "RECIPE.OPTIONS"); 49 50 // recipe override values (command-line options): 48 51 psMetadataItem *item = NULL; 49 psMetadataIterator *iter = psMetadataIteratorAlloc ( recipe, PS_LIST_HEAD, NULL);52 psMetadataIterator *iter = psMetadataIteratorAlloc (config->options, PS_LIST_HEAD, NULL); 50 53 while ((item = psMetadataGetAndIncrement (iter)) != NULL) { 51 54 psMetadataAddItem (config->recipe, item, PS_LIST_TAIL, PS_META_REPLACE); … … 54 57 psFree (iter); 55 58 56 psMetadataAddStr (config->recipe, PS_LIST_TAIL, "FITMODE", 0, "", "NONE"); 57 psMetadataAddStr (config->recipe, PS_LIST_TAIL, "PHOTCODE", 0, "", "NONE"); 58 psMetadataAddStr (config->recipe, PS_LIST_TAIL, "BREAK_POINT", 0, "", "NONE"); 59 // set default recipe values here 60 METADATA_ADD_DEFAULT (config->recipe, Str, "FITMODE", "NONE", ""); 61 METADATA_ADD_DEFAULT (config->recipe, Str, "PHOTCODE", "NONE", ""); 62 METADATA_ADD_DEFAULT (config->recipe, Str, "BREAK_POINT", "NONE", ""); 63 METADATA_ADD_DEFAULT (config->recipe, Str, "OUTPUT_FORMAT", "CMP", ""); 64 METADATA_ADD_DEFAULT (config->recipe, Str, "OUTPUT_MODE", "SPLIT", ""); 59 65 60 // XXX EAM : extend this to allow an array of selected chips by name61 66 // Chip selection: if we are using a single chip, select it for each FPA 62 int chipNum = psMetadataLookupS32(NULL, config->arguments, "-chip"); // Chip number to work on 63 if (chipNum >= 0) { 64 if (! pmFPASelectChip(input->fpa, chipNum)) { 65 psErrorStackPrint(stderr, "Chip number %d doesn't exist in camera.\n", chipNum); 66 exit(EXIT_FAILURE); 67 // Chip numbers to work on: -chip 1,2,3,5,8,10 68 char *chips = psMetadataLookupStr(NULL, config->arguments, "CHIP_SELECTIONS"); 69 if (chips != NULL) { 70 char *p = chips; 71 while (strlen(p)) { 72 char *q = strchr (p, ','); 73 if (q == NULL) { 74 q = p + strlen(p); 75 } else { 76 *q = 0; 77 q = q + 1; 78 } 79 int chipNum = atoi(p); 80 // XXX EAM : extend this to allow an array of selected chips (by name) 81 if (! pmFPASelectChip(input->fpa, chipNum)) { 82 psErrorStackPrint(stderr, "Chip number %d doesn't exist in camera.\n", chipNum); 83 exit(EXIT_FAILURE); 84 } 85 psLogMsg("psphot", PS_LOG_INFO, "Operating only on chip %d\n", chipNum); 86 p = q; 67 87 } 68 psLogMsg("psphot", PS_LOG_INFO, "Operating only on chip %d\n", chipNum);69 88 } 70 89 … … 72 91 input->fpa = pmFPAConstruct(config->camera); 73 92 93 psTrace(__func__, 1, "Done with psphotParseCamera...\n"); 74 94 return input; 75 95 } -
trunk/psphot/src/psphotReadout.c
r6117 r6311 8 8 psStats *sky = NULL; 9 9 bool status; 10 11 psphotSaveImage (NULL, readout->mask, "mask.fits"); 12 psphotSaveImage (NULL, readout->image, "image.fits"); 13 psphotSaveImage (NULL, readout->weight, "weight.fits"); 10 14 11 15 // measure image stats for initial guess
Note:
See TracChangeset
for help on using the changeset viewer.
