Changeset 6117
- Timestamp:
- Jan 20, 2006, 8:57:16 PM (20 years ago)
- Location:
- trunk/psphot/src
- Files:
-
- 6 added
- 11 edited
-
pmCellSetMask.c (added)
-
psImageJpeg.c (added)
-
psModulesUtils.c (modified) (2 diffs)
-
psModulesUtils.h (modified) (2 diffs)
-
psphot.c (modified) (1 diff)
-
psphot.h (modified) (7 diffs)
-
psphotArguments.c (modified) (3 diffs)
-
psphotChoosePSF.c (modified) (3 diffs)
-
psphotImageLoop.c (added)
-
psphotImageStats.c (modified) (1 diff)
-
psphotLoadPixels.c (added)
-
psphotMagnitudes.c (modified) (1 diff)
-
psphotOutput.c (modified) (17 diffs)
-
psphotParseCamera.c (added)
-
psphotReadout.c (added)
-
psphotTest.c (modified) (3 diffs)
-
psphotTestArguments.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psModulesUtils.c
r5993 r6117 59 59 } 60 60 61 pmModel *pmModelSelect (pmSource *source) { 62 switch (source->type) { 63 case PM_SOURCE_STAR: 64 return source->modelPSF; 65 66 case PM_SOURCE_EXTENDED: 67 return source->modelEXT; 68 69 default: 70 return NULL; 71 } 72 return NULL; 73 } 74 61 75 bool pmSourcePhotometry (float *fitMag, float *obsMag, pmModel *model, psImage *image, psImage *mask) { 62 76 … … 162 176 return (flux); 163 177 } 178 179 static void ppConfigFree (ppConfig *config) { 180 181 if (config == NULL) return; 182 return; 183 } 184 185 // allocate a ppConfig structrue 186 ppConfig *ppConfigAlloc (void) { 187 188 ppConfig *config = psAlloc (sizeof(ppConfig)); 189 psMemSetDeallocator(config, (psFreeFunc) ppConfigFree); 190 191 config->site = NULL; 192 config->camera = NULL; 193 config->recipe = NULL; 194 config->arguments = NULL; 195 config->database = NULL; 196 197 return (config); 198 } 199 200 static void ppFileFree (ppFile *file) { 201 202 if (file == NULL) return; 203 return; 204 } 205 206 // allocate a ppFile structrue 207 ppFile *ppFileAlloc (void) { 208 209 ppFile *file = psAlloc (sizeof(ppFile)); 210 psMemSetDeallocator(file, (psFreeFunc) ppFileFree); 211 212 file->filename = NULL; 213 file->fits = NULL; 214 file->phu = NULL; 215 file->fpa = NULL; 216 217 return (file); 218 } 219 220 psMetadata *pmReadoutGetHeader (pmReadout *readout) { 221 222 p_pmHDU *hdu = NULL; 223 224 pmCell *cell = readout->parent; // cell containing this readout; 225 hdu = cell->hdu; // The data unit, containing the weight and mask originals 226 if (hdu) return hdu->header; 227 228 pmChip *chip = cell->parent; // The parent chip 229 hdu = chip->hdu; // The data unit, containing the weight and mask originals 230 if (hdu) return hdu->header; 231 232 pmFPA *fpa = chip->parent; // The parent FPA 233 hdu = fpa->hdu; 234 if (hdu) return hdu->header; 235 236 if (fpa->phu) return fpa->phu; 237 238 psError(PS_ERR_UNKNOWN, true, "Unable to find the HDU in the hierarchy!\n"); 239 return NULL; 240 } -
trunk/psphot/src/psModulesUtils.h
r5718 r6117 9 9 # include "psLibUtils.h" 10 10 11 // How much of the FPA to load at a time 12 typedef enum { 13 PP_LOAD_NONE, // Don't load anything 14 PP_LOAD_FPA, // Load the entire FPA at once 15 PP_LOAD_CHIP, // Load by chip 16 PP_LOAD_CELL, // Load by cell 17 } ppImageLoadDepth; 18 19 // Configuration data 20 typedef struct { 21 psMetadata *site; // The site configuration 22 psMetadata *camera; // The camera configuration 23 psMetadata *recipe; // The recipe (i.e., specific setups) 24 psMetadata *arguments; // The command-line arguments 25 psDB *database; // Database handle 26 } ppConfig; 27 28 // A file to process 29 typedef struct { 30 char *filename; // File name 31 psFits *fits; // The FITS file handle 32 psMetadata *phu; // The FITS header 33 pmFPA *fpa; // The FPA, with pixels and extensions 34 } ppFile; 35 11 36 // psModule extra utilities 12 37 // bool pmSourceFitModel_EAM(pmSource *source, pmModel *model, const bool PSF); … … 18 43 // unify with paul's image/header/metadata functions 19 44 psF32 pmConfigLookupF32 (bool *status, psMetadata *config, psMetadata *header, char *name); 45 pmModel *pmModelSelect (pmSource *source); 46 47 ppConfig *ppConfigAlloc (void); 48 ppFile *ppFileAlloc (void); 49 psMetadata *pmReadoutGetHeader (pmReadout *readout); 20 50 21 51 # endif -
trunk/psphot/src/psphot.c
r6056 r6117 1 1 # include "psphot.h" 2 2 3 // XXX need a better structure for handling optional sequence 3 // XXX need a better structure for handling optional sequences 4 4 int main (int argc, char **argv) { 5 6 psMetadata *config = NULL;7 psMetadata *header = NULL;8 pmReadout *readout = NULL;9 psArray *sources = NULL;10 psArray *peaks = NULL;11 pmPSF *psf = NULL;12 psStats *sky = NULL;13 bool status;14 5 15 6 psTimerStart ("complete"); 16 7 17 // load command-line arguments and options 18 config = psphotArguments (&argc, argv); 8 // load implementation-specific models 9 psphotModelGroupInit (); 10 11 // load command-line arguments, options, and system config data 12 ppConfig *config = psphotArguments (&argc, argv); 19 13 20 14 // load input data (config and images (signal, noise, mask) 21 readout = psphotSetup (config, &header);15 ppFile *input = psphotParseCamera (config); 22 16 23 // run a single-model test if desired 24 psphotModelTest (readout, config);17 // run a single-model test if desired - XXX push in psphotImageLoop? 18 // psphotModelTest (input, options); 25 19 26 // measure image stats for initial guess27 sky = psphotImageStats (readout, config);20 // call psphot for each readout 21 psphotImageLoop (input, config); 28 22 29 // generate a background model (currently, 2D polynomial)30 // XXX this should be available to be re-added to the original image31 psphotImageBackground (readout, config, sky);32 33 // find the peaks in the image34 peaks = psphotFindPeaks (readout, config, sky);35 36 // construct sources and measure basic stats37 sources = psphotSourceStats (readout, config, peaks);38 39 // classify sources based on moments, brightness40 psphotRoughClass (sources, config);41 42 // mark blended peaks PS_SOURCE_BLEND43 psphotBasicDeblend (sources, config, sky);44 45 // use bright stellar objects to measure PSF46 psf = psphotChoosePSF (config, sources, sky);47 48 // XXX change FITMODE to a string49 int FITMODE = psMetadataLookupS32 (&status, config, "FIT_MODE");50 switch (FITMODE) {51 case 0:52 psphotEnsemblePSF (readout, config, sources, psf, sky);53 break;54 55 case 1:56 psphotEnsemblePSF (readout, config, sources, psf, sky);57 psphotFullFit (readout, config, sources, psf, sky);58 psphotReplaceUnfit (sources);59 psphotApResid (readout, sources, config, psf);60 break;61 62 case 2:63 psphotEnsemblePSF (readout, config, sources, psf, sky);64 psphotBlendFit (readout, config, sources, psf, sky);65 psphotReplaceUnfit (sources);66 psphotApResid (readout, sources, config, psf);67 break;68 69 case 3:70 psphotApplyPSF (readout, config, sources, psf, sky);71 break;72 73 case 4:74 psphotApplyPSF (readout, config, sources, psf, sky);75 psphotFitExtended (readout, config, sources, sky);76 break;77 }78 79 // write out data in appropriate format80 psphotOutput (readout, header, config, sources, psf, sky);81 psLogMsg ("psphot", 3, "wrote output: %f sec\n", psTimerMark ("psphot"));82 23 psLogMsg ("psphot", 3, "complete psphot run: %f sec\n", psTimerMark ("complete")); 83 24 exit (0); -
trunk/psphot/src/psphot.h
r6056 r6117 5 5 # include <pmObjects.h> 6 6 # include <pmGrowthCurve.h> 7 # include <pmConfig.h> 8 # include <pmFPARead.h> 7 9 # include <pmPSF.h> 8 10 # include <pmPSFtry.h> … … 11 13 # include "psModulesUtils.h" 12 14 # include "psSparse.h" 15 #include "pmFPAConstruct.h" 16 17 # define PSPHOT_RECIPE "PSPHOT" 13 18 14 19 # define psMemCopy(A)(psMemIncrRefCounter((A))) 15 20 16 21 // top-level psphot functions 17 psMetadata *psphotArguments (int *argc, char **argv); 18 pmReadout *psphotSetup (psMetadata *config, psMetadata **header); 22 ppConfig *psphotArguments (int *argc, char **argv); 23 ppFile *psphotParseCamera (ppConfig *config); 24 bool psphotImageLoop (ppFile *input, ppConfig *config); 25 19 26 bool psphotModelTest (pmReadout *readout, psMetadata *config); 27 bool psphotReadout (pmReadout *readout, psMetadata *config); 28 bool ppImageLoadPixels (ppFile *input, psDB *db, int chipNum, int cellNum); 29 30 // psphotReadout functions 20 31 psStats *psphotImageStats (pmReadout *readout, psMetadata *config); 21 32 psPolynomial2D *psphotImageBackground (pmReadout *readout, psMetadata *config, psStats *sky); … … 25 36 bool psphotBasicDeblend (psArray *sources, psMetadata *config, psStats *sky); 26 37 pmPSF *psphotChoosePSF (psMetadata *config, psArray *sources, psStats *sky); 27 void psphotOutput (pmReadout *readout, psMetadata * header, psMetadata *config, psArray *sources, pmPSF *psf, psStats *sky);38 void psphotOutput (pmReadout *readout, psMetadata *config); 28 39 29 40 // optional object analysis steps … … 46 57 bool psphotGrowthCurve (pmReadout *readout, pmPSF *psf); 47 58 void psphotTestArguments (int *argc, char **argv); 59 bool pmCellSetMask (pmCell *cell, psMetadata *recipe); 48 60 49 61 // functions to set the correct source pixels … … 56 68 57 69 // output functions 58 bool pmSourcesWrite Text (pmReadout *readout, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky);59 bool pmSourcesWriteOBJ (p mReadout *readout, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky);60 bool pmSourcesWriteCMP (p mReadout *readout, psMetadata *header, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky);61 bool pmSourcesWriteCMF (p mReadout *readout, psMetadata *header, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky);62 bool pmSourcesWrite SX (pmReadout *readout, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky);70 bool pmSourcesWriteSX (psArray *sources, char *filename); 71 bool pmSourcesWriteOBJ (psArray *sources, char *filename); 72 bool pmSourcesWriteCMP (psArray *sources, char *filename, psMetadata *header); 73 bool pmSourcesWriteCMF (psArray *sources, char *filename, psMetadata *header); 74 bool pmSourcesWriteText (psArray *sources, char *filename); 63 75 64 bool pmModelWritePSFs (psArray *sources, psMetadata *config, char *filename, pmPSF *psf);76 bool pmModelWritePSFs (psArray *sources, char *filename); 65 77 bool pmModelWriteEXTs (psArray *sources, char *filename); 66 78 bool pmModelWriteNULLs (psArray *sources, char *filename); … … 74 86 int pmSourcesDophotType (pmSource *source); 75 87 bool psMetadataItemTransfer (psMetadata *out, psMetadata *in, char *key); 88 89 bool psphotMagnitudes (psMetadata *config, psArray *sources, pmPSF *psf); 76 90 77 91 // PSF / DBL / EXT evaluation functions … … 99 113 psPlane psImageBicubeMin (psPolynomial2D *poly); 100 114 115 bool psImageJpegColormap (char *name); 116 bool psImageJpeg (psImage *image, char *filename, float zero, float scale); 117 101 118 // optional mode for clip fit? 102 119 psPolynomial4D *psVectorChiClipFitPolynomial4D( -
trunk/psphot/src/psphotArguments.c
r5993 r6117 1 1 # include "psphot.h" 2 2 3 static void usage ( void) ;3 static void usage (psMetadata *arguments) ; 4 4 5 p sMetadata*psphotArguments (int *argc, char **argv) {5 ppConfig *psphotArguments (int *argc, char **argv) { 6 6 7 7 int N; 8 unsigned int Nfail;9 10 psMetadata *options = psMetadataAlloc ();11 8 12 9 // basic pslib options 13 10 psLogSetFormat ("M"); 14 psArgumentVerbosity (argc, argv);15 11 16 // command-line options -- place on options MD17 // mask image 18 if ((N = psArgumentGet (*argc, argv, "-mask"))) {19 psArgumentRemove (N, argc, argv); 20 psMetadataAddStr (options, PS_LIST_TAIL, "MASK_IMAGE", 0, "", psStringCopy(argv[N]));21 psArgumentRemove (N, argc, argv);12 ppConfig *config = ppConfigAlloc (); 13 14 // load config data from default locations 15 if (!pmConfigRead(&config->site, &config->camera, &config->recipe, argc, argv, PSPHOT_RECIPE)) { 16 psErrorStackPrint(stderr, "Can't find site configuration!\n"); 17 exit (EXIT_FAILURE); 22 18 } 23 19 24 // weight image 25 if ((N = psArgumentGet (*argc, argv, "-weight"))) { 26 psArgumentRemove (N, argc, argv); 27 psMetadataAddStr (options, PS_LIST_TAIL, "WEIGHT_IMAGE", 0, "", psStringCopy(argv[N])); 28 psArgumentRemove (N, argc, argv); 29 } 20 // Parse other command-line arguments 21 config->arguments = psMetadataAlloc (); 30 22 31 // output residual image 32 if ((N = psArgumentGet (*argc, argv, "-resid"))) { 33 psArgumentRemove (N, argc, argv); 34 psMetadataAddStr (options, PS_LIST_TAIL, "RESID_IMAGE", 0, "", psStringCopy(argv[N])); 35 psArgumentRemove (N, argc, argv); 36 } 37 38 // analysis region 39 if ((N = psArgumentGet (*argc, argv, "-region"))) { 40 psArgumentRemove (N, argc, argv); 41 psMetadataAddStr (options, PS_LIST_TAIL, "ANALYSIS_REGION", 0, "", psStringCopy(argv[N])); 42 psArgumentRemove (N, argc, argv); 43 } 44 45 // output residual image 46 psMetadataAddStr (options, PS_LIST_TAIL, "PHOTCODE", 0, "", psStringCopy("NONE")); 47 if ((N = psArgumentGet (*argc, argv, "-photcode"))) { 48 psArgumentRemove (N, argc, argv); 49 psMetadataAddStr (options, PS_LIST_TAIL, "PHOTCODE", PS_META_REPLACE, "", psStringCopy(argv[N])); 50 psArgumentRemove (N, argc, argv); 51 } 52 53 // input PSF file 54 if ((N = psArgumentGet (*argc, argv, "-psf"))) { 55 psArgumentRemove (N, argc, argv); 56 psMetadataAddStr (options, PS_LIST_TAIL, "PSF_INPUT_FILE", 0, "", psStringCopy (argv[N])); 57 psArgumentRemove (N, argc, argv); 58 } 59 60 // run the 0ltest model (requires X,Y coordinate) 23 // 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 30 // run the test model (requires X,Y coordinate) 61 31 if ((N = psArgumentGet (*argc, argv, "-modeltest"))) { 62 psMetadataAddBool ( options, PS_LIST_TAIL, "TEST_FIT", 0, "", true);63 psMetadataAddF32 ( options, PS_LIST_TAIL, "TEST_FIT_X", 0, "", atof(argv[N+1]));64 psMetadataAddF32 ( options, PS_LIST_TAIL, "TEST_FIT_Y", 0, "", atof(argv[N+2]));32 psMetadataAddBool (config->arguments, PS_LIST_TAIL, "TEST_FIT", 0, "", true); 33 psMetadataAddF32 (config->arguments, PS_LIST_TAIL, "TEST_FIT_X", 0, "", atof(argv[N+1])); 34 psMetadataAddF32 (config->arguments, PS_LIST_TAIL, "TEST_FIT_Y", 0, "", atof(argv[N+2])); 65 35 66 36 psArgumentRemove (N, argc, argv); … … 71 41 if ((N = psArgumentGet (*argc, argv, "-model"))) { 72 42 psArgumentRemove (N, argc, argv); 73 psMetadataAddStr ( options, PS_LIST_TAIL, "TEST_FIT_MODEL", 0, "", psStringCopy (argv[N]));43 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "TEST_FIT_MODEL", 0, "", psStringCopy (argv[N])); 74 44 psArgumentRemove (N, argc, argv); 75 45 } … … 78 48 if ((N = psArgumentGet (*argc, argv, "-fitmode"))) { 79 49 psArgumentRemove (N, argc, argv); 80 psMetadataAddStr ( options, PS_LIST_TAIL, "TEST_FIT_MODE", 0, "", psStringCopy (argv[N]));50 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "TEST_FIT_MODE", 0, "", psStringCopy (argv[N])); 81 51 psArgumentRemove (N, argc, argv); 82 52 } 83 53 if ((N = psArgumentGet (*argc, argv, "-fitset"))) { 84 54 psArgumentRemove (N, argc, argv); 85 psMetadataAddStr ( options, PS_LIST_TAIL, "TEST_FIT_SET", 0, "", psStringCopy (argv[N]));55 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "TEST_FIT_SET", 0, "", psStringCopy (argv[N])); 86 56 psArgumentRemove (N, argc, argv); 87 57 } 88 58 } 89 59 90 // other arbitrary options: -D key value (all added as string) 60 // Parse command-line overrides of recipe values 61 psMetadata *recipe = psMetadataAlloc (); 62 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"))) { 69 psArgumentRemove (N, argc, argv); 70 psMetadataAddStr (recipe, PS_LIST_TAIL, "PHOTCODE", PS_META_REPLACE, "", psStringCopy(argv[N])); 71 psArgumentRemove (N, argc, argv); 72 } 73 74 // analysis region : XXX override recipe 75 if ((N = psArgumentGet (*argc, argv, "-break"))) { 76 psArgumentRemove (N, argc, argv); 77 psMetadataAddStr (recipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", psStringCopy(argv[N])); 78 psArgumentRemove (N, argc, argv); 79 } 80 81 // analysis region : XXX override recipe 82 if ((N = psArgumentGet (*argc, argv, "-fitmode"))) { 83 psArgumentRemove (N, argc, argv); 84 psMetadataAddStr (recipe, PS_LIST_TAIL, "FITMODE", PS_META_REPLACE, "", psStringCopy(argv[N])); 85 psArgumentRemove (N, argc, argv); 86 } 87 88 // analysis region : XXX override recipe 89 if ((N = psArgumentGet (*argc, argv, "-region"))) { 90 psArgumentRemove (N, argc, argv); 91 psMetadataAddStr (recipe, PS_LIST_TAIL, "ANALYSIS_REGION", 0, "", psStringCopy(argv[N])); 92 psArgumentRemove (N, argc, argv); 93 } 94 95 // other arbitrary recipe values: -D key value (all added as string) 91 96 while ((N = psArgumentGet (*argc, argv, "-D"))) { 92 97 psArgumentRemove (N, argc, argv); 93 psMetadataAddStr ( options, PS_LIST_TAIL, argv[N], 0, "", argv[N+1]);98 psMetadataAddStr (recipe, PS_LIST_TAIL, argv[N], 0, "", argv[N+1]); 94 99 psArgumentRemove (N, argc, argv); 95 100 psArgumentRemove (N, argc, argv); 96 101 } 97 102 98 // other arbitrary options: -Df key value (all added as float)103 // other arbitrary recipe values: -Df key value (all added as float) 99 104 while ((N = psArgumentGet (*argc, argv, "-Df"))) { 100 105 psArgumentRemove (N, argc, argv); 101 psMetadataAddF32 ( options, PS_LIST_TAIL, argv[N], 0, "", atof(argv[N+1]));106 psMetadataAddF32 (recipe, PS_LIST_TAIL, argv[N], 0, "", atof(argv[N+1])); 102 107 psArgumentRemove (N, argc, argv); 103 108 psArgumentRemove (N, argc, argv); 104 109 } 105 110 106 // other arbitrary options: -Di key value (all added as int)111 // other arbitrary recipe values: -Di key value (all added as int) 107 112 while ((N = psArgumentGet (*argc, argv, "-Di"))) { 108 113 psArgumentRemove (N, argc, argv); 109 psMetadataAddS32 ( options, PS_LIST_TAIL, argv[N], 0, "", atoi(argv[N+1]));114 psMetadataAddS32 (recipe, PS_LIST_TAIL, argv[N], 0, "", atoi(argv[N+1])); 110 115 psArgumentRemove (N, argc, argv); 111 116 psArgumentRemove (N, argc, argv); 112 117 } 113 118 114 if (*argc != 4) usage (); 119 // place the recipe options on the arguments stack 120 psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "RECIPE.OPTIONS", PS_DATA_UNKNOWN, "", recipe); 115 121 116 // load config information117 psMetadata *config = psMetadataAlloc ();122 if (!psArgumentParse(config->arguments, argc, argv)) usage (config->arguments); 123 if (*argc != 3) usage (config->arguments); 118 124 119 // add default values 120 psMetadataAddStr (config, PS_LIST_TAIL, "BREAK_POINT", 0, "", "NONE"); 121 psMetadataAddS32 (config, PS_LIST_TAIL, "FIT_MODE", 0, "", 2); 122 123 psMetadataAdd (config, PS_LIST_TAIL, "PSF_MODEL", PS_DATA_METADATA_MULTI, "folder for psf model entries", NULL); 124 125 // config file values override defaults set here 126 config = psMetadataConfigParse (config, &Nfail, argv[3], TRUE); 127 128 psMetadataItem *item = NULL; 129 psMetadataIterator *iter = psMetadataIteratorAlloc (options, PS_LIST_HEAD, NULL); 130 while ((item = psMetadataGetAndIncrement (iter)) != NULL) { 131 psMetadataAddItem (config, item, PS_LIST_TAIL, PS_META_REPLACE); 132 psFree (item); 133 } 134 psFree (iter); 135 136 // identify input image & optional weight & mask images 137 // command-line entries override config-file entries 138 psMetadataAddStr (config, PS_LIST_TAIL, "IMAGE", PS_META_REPLACE, "", argv[1]); 139 psMetadataAddStr (config, PS_LIST_TAIL, "OUTPUT_FILE", PS_META_REPLACE, "", argv[2]); 125 // 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]); 140 128 141 129 return (config); 142 130 } 143 131 144 static void usage ( void) {132 static void usage (psMetadata *arguments) { 145 133 146 fprintf (stderr, "USAGE: psphot (image) (output) (config)\n"); 147 fprintf (stderr, "options: \n"); 148 fprintf (stderr, " -mask (filename)\n"); 149 fprintf (stderr, " -weight (filename)\n"); 150 fprintf (stderr, " -resid (filename)\n"); 151 fprintf (stderr, " -photcode (photcode)\n"); 134 fprintf (stderr, "USAGE: psphot (image) (output)\n"); 135 psArgumentHelp (arguments); 152 136 exit (2); 153 137 } -
trunk/psphot/src/psphotChoosePSF.c
r5993 r6117 34 34 35 35 // get the list pointers for the PSF_MODEL entries 36 psList *list = NULL; 36 37 psMetadataItem *mdi = psMetadataLookup (config, "PSF_MODEL"); 37 38 if (mdi == NULL) psAbort ("psphotChoosePSF", "missing PSF_MODEL selection"); 38 39 psList *list = (psList *) mdi->data.list; 40 psListIterator *iter = psListIteratorAlloc (list, PS_LIST_HEAD, FALSE); 39 if (mdi->type == PS_DATA_STRING) { 40 list = psListAlloc(NULL); 41 psListAdd (list, PS_LIST_HEAD, mdi); 42 } else { 43 if (mdi->type != PS_DATA_METADATA_MULTI) psAbort ("psphotChoosePSF", "missing PSF_MODEL selection"); 44 list = psMemIncrRefCounter(mdi->data.list); 45 } 41 46 42 47 // set up an array to store the results … … 44 49 45 50 // try each model option listed in config 51 psListIterator *iter = psListIteratorAlloc (list, PS_LIST_HEAD, FALSE); 46 52 for (int i = 0; i < models->n; i++) { 47 53 … … 54 60 } 55 61 psFree (iter); 56 // psFree (list); XXX is list freed with iter?62 psFree (list); 57 63 psFree (stars); 58 64 -
trunk/psphot/src/psphotImageStats.c
r6056 r6117 39 39 } 40 40 41 // we store these values in mean,stdev 42 bool status = false; 43 float NOISE = psMetadataLookupF32 (&status, config, "RDNOISE"); 44 float GAIN = psMetadataLookupF32 (&status, config, "GAIN"); 41 pmCell *cell = readout->parent; // cell containing this readout; 42 float gain = psMetadataLookupF32(NULL, cell->concepts, "CELL.GAIN"); // Cell gain 43 float noise = psMetadataLookupF32(NULL, cell->concepts, "CELL.READNOISE"); // Cell read noise 45 44 46 45 // convert instrumental background to poisson stats 47 46 sky = psStatsAlloc (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV); 48 47 sky->sampleMean = stats->sampleMedian; 49 sky->sampleStdev = sqrt(sky->sampleMean/ GAIN + PS_SQR(NOISE));48 sky->sampleStdev = sqrt(sky->sampleMean/gain + PS_SQR(noise)); 50 49 51 50 psLogMsg ("psphot", 4, "background: %f +/- %f\n", sky->sampleMean, sky->sampleStdev); -
trunk/psphot/src/psphotMagnitudes.c
r5993 r6117 71 71 72 72 */ 73 74 bool psphotMagnitudes (psMetadata *config, psArray *sources, pmPSF *psf) { 75 76 bool status; 77 78 float RADIUS = psMetadataLookupF32 (&status, config, "AP_RADIUS"); 79 for (int i = 0; i < sources->n; i++) { 80 pmSource *source = (pmSource *) sources->data[i]; 81 pmSourceMagnitudes (source, psf, RADIUS); 82 } 83 return true; 84 } 85 -
trunk/psphot/src/psphotOutput.c
r6056 r6117 2 2 3 3 // output functions: we have several fixed modes (sx, obj, cmp) 4 void psphotOutput (pmReadout *readout, psMetadata * header, psMetadata *config, psArray *sources, pmPSF *psf, psStats *sky) {4 void psphotOutput (pmReadout *readout, psMetadata *config) { 5 5 6 6 bool status; 7 7 8 8 psTimerStart ("psphot"); 9 10 psMetadata *header = pmReadoutGetHeader (readout); 11 12 psArray *sources = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.SOURCES"); 13 pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF"); 9 14 10 15 char *outputMode = psMetadataLookupPtr (&status, config, "OUTPUT_MODE"); … … 29 34 return; 30 35 } 36 if (!strcasecmp (outputMode, "SX")) { 37 pmSourcesWriteSX (sources, outputFile); 38 return; 39 } 31 40 if (!strcasecmp (outputMode, "OBJ")) { 32 pmSourcesWriteOBJ ( readout, config, outputFile, sources, psf, sky);41 pmSourcesWriteOBJ (sources, outputFile); 33 42 return; 34 43 } 35 if (!strcasecmp (outputMode, " SX")) {36 pmSourcesWrite SX (readout, config, outputFile, sources, psf, sky);44 if (!strcasecmp (outputMode, "CMP")) { 45 pmSourcesWriteCMP (sources, outputFile, header); 37 46 return; 38 47 } 39 if (!strcasecmp (outputMode, "CM P")) {40 pmSourcesWriteCM P (readout, header, config, outputFile, sources, psf, sky);48 if (!strcasecmp (outputMode, "CMF")) { 49 pmSourcesWriteCMF (sources, outputFile, header); 41 50 return; 42 51 } 43 if (!strcasecmp (outputMode, " CMF")) {44 pmSourcesWrite CMF (readout, header, config, outputFile, sources, psf, sky);52 if (!strcasecmp (outputMode, "TEXT")) { 53 pmSourcesWriteText (sources, outputFile); 45 54 return; 46 55 } 47 if (!strcasecmp (outputMode, "TEXT")) {48 pmSourcesWriteText (readout, config, outputFile, sources, psf, sky);49 return;50 }51 56 52 57 psAbort ("psphot", "unknown output mode %s", outputMode); … … 54 59 55 60 // dophot-style output list with fixed line width 56 bool pmSourcesWriteOBJ (p mReadout *readout, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {61 bool pmSourcesWriteOBJ (psArray *sources, char *filename) { 57 62 58 63 int type; 59 pmModel *model;60 64 psF32 *PAR, *dPAR; 61 65 float dmag, apResid; 62 bool status;63 66 64 67 psLine *line = psLineAlloc (104); // 104 is dophot-defined line length … … 69 72 return false; 70 73 } 71 72 float RADIUS = psMetadataLookupF32 (&status, config, "AP_RADIUS");73 74 74 75 // write sources with models 75 76 for (int i = 0; i < sources->n; i++) { 76 77 pmSource *source = (pmSource *) sources->data[i]; 77 78 model = pmSourceMagnitudes (source, psf, RADIUS); 78 pmModel *model = pmModelSelect (source); 79 79 if (model == NULL) continue; 80 80 … … 106 106 107 107 // elixir-mode / sextractor-style output list with fixed line width 108 bool pmSourcesWriteSX (pmReadout *readout, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) { 109 110 pmModel *model; 108 bool pmSourcesWriteSX (psArray *sources, char *filename) { 109 111 110 psF32 *PAR, *dPAR; 112 111 float dmag; 113 bool status;114 112 115 113 psLine *line = psLineAlloc (110); // 110 is sextractor line length … … 120 118 return false; 121 119 } 122 123 float RADIUS = psMetadataLookupF32 (&status, config, "AP_RADIUS");124 120 125 121 // write sources with models 126 122 for (int i = 0; i < sources->n; i++) { 127 123 pmSource *source = (pmSource *) sources->data[i]; 128 129 model = pmSourceMagnitudes (source, psf, RADIUS); 124 pmModel *model = pmModelSelect (source); 130 125 if (model == NULL) continue; 131 126 … … 157 152 158 153 // elixir-style pseudo FITS table (header + ascii list) 159 bool pmSourcesWriteCMP (p mReadout *readout, psMetadata *header, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {154 bool pmSourcesWriteCMP (psArray *sources, char *filename, psMetadata *header) { 160 155 161 156 int i, type; 162 pmModel *model;163 157 psMetadataItem *mdi; 164 158 psF32 *PAR, *dPAR; … … 167 161 168 162 // find config information for output header 169 float RADIUS = psMetadataLookupF32 (&status, config, "AP_RADIUS"); 170 float ZERO_POINT = psMetadataLookupF32 (&status, config, "ZERO_POINT"); 163 float ZERO_POINT = psMetadataLookupF32 (&status, header, "ZERO_PT"); 171 164 if (!status) ZERO_POINT = 25.0; 172 165 173 166 // write necessary information to output header 174 psphotUpdateHeader (header, config);175 167 psMetadataAdd (header, PS_LIST_TAIL, "NSTARS", PS_DATA_S32 | PS_META_REPLACE, "NUMBER OF STARS", sources->n); 176 168 … … 200 192 for (i = 0; i < sources->n; i++) { 201 193 pmSource *source = (pmSource *) sources->data[i]; 202 203 model = pmSourceMagnitudes (source, psf, RADIUS); 194 pmModel *model = pmModelSelect (source); 204 195 if (model == NULL) continue; 205 196 … … 232 223 // this format consists of a header derived from the image header 233 224 // followed by a zero-size matrix, followed by the table data 234 bool pmSourcesWriteCMF (p mReadout *readout, psMetadata *header, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {225 bool pmSourcesWriteCMF (psArray *sources, char *filename, psMetadata *header) { 235 226 236 227 psArray *table; … … 239 230 psMetadata *theader; 240 231 int i, type; 241 pmModel *model;242 232 psF32 *PAR, *dPAR; 243 233 float dmag, lsky; … … 245 235 246 236 // find config information for output header 247 float RADIUS = psMetadataLookupF32 (&status, config, "AP_RADIUS"); 248 float ZERO_POINT = psMetadataLookupF32 (&status, config, "ZERO_POINT"); 249 250 // write necessary information to output header 251 psphotUpdateHeader (header, config); 237 float ZERO_POINT = psMetadataLookupF32 (&status, header, "ZERO_PT"); 252 238 253 239 table = psArrayAlloc (sources->n); … … 256 242 for (i = 0; i < sources->n; i++) { 257 243 pmSource *source = (pmSource *) sources->data[i]; 258 259 model = pmSourceMagnitudes (source, psf, RADIUS); 244 pmModel *model = pmModelSelect (source); 260 245 if (model == NULL) continue; 261 246 … … 309 294 /***** Text Output Methods *****/ 310 295 311 bool pmSourcesWriteText (p mReadout *readout, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky) {296 bool pmSourcesWriteText (psArray *sources, char *filename) { 312 297 313 298 char *name = (char *) psAlloc (strlen(filename) + 10); 314 299 315 300 sprintf (name, "%s.psf.dat", filename); 316 pmModelWritePSFs (sources, config, name, psf);301 pmModelWritePSFs (sources, name); 317 302 318 303 sprintf (name, "%s.ext.dat", filename); … … 330 315 331 316 // write the PSF sources to an output file 332 bool pmModelWritePSFs (psArray *sources, psMetadata *config, char *filename, pmPSF *psf) {317 bool pmModelWritePSFs (psArray *sources, char *filename) { 333 318 334 319 double dPos, dMag; … … 337 322 psF32 *PAR, *dPAR; 338 323 pmModel *model; 339 bool status;340 341 float RADIUS = psMetadataLookupF32 (&status, config, "AP_RADIUS");342 324 343 325 f = fopen (filename, "w"); … … 350 332 for (i = 0; i < sources->n; i++) { 351 333 pmSource *source = (pmSource *) sources->data[i]; 352 353 334 if (source->type != PM_SOURCE_STAR) continue; 354 model = pmSourceMagnitudes (source, psf, RADIUS);335 model = source->modelPSF; 355 336 if (model == NULL) continue; 356 337 -
trunk/psphot/src/psphotTest.c
r5993 r6117 15 15 int main (int argc, char **argv) { 16 16 17 psMetadata *row;18 psArray *table;19 20 psMetadataItem *mdi;21 17 psRegion region = {0,0,0,0}; // a region representing the entire array 22 23 18 psphotTestArguments (&argc, argv); 24 19 … … 27 22 psImage *image = psFitsReadImage (NULL, file, region, 0); 28 23 psFitsClose (file); 24 25 psImageJpegColormap (argv[5]); 26 27 // psImage *fimage = psImageCopy (NULL, image, PS_TYPE_F32); 28 29 int binning = atof(argv[6]); 30 31 psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEAN); 32 psImage *fimage = psImageRebin (NULL, image, NULL, 0, binning, stats); 33 34 float min = atof(argv[3]); 35 float max = atof(argv[4]); 36 37 psImageJpeg (fimage, argv[2], min, max); 38 39 psFree (header); 40 psFree (image); 41 exit (0); 42 } 43 44 45 # if (0) 46 47 psMetadata *row; 48 psArray *table; 49 50 psMetadataItem *mdi; 29 51 30 52 psMetadataConfigWrite (header, argv[2]); … … 59 81 psFitsWriteHeader (header, fits); 60 82 psFitsWriteTable (fits, theader, table); 61 psFitsClose (fits);62 83 63 psFree (header); 64 psFree (image); 65 exit (0); 66 } 84 # endif -
trunk/psphot/src/psphotTestArguments.c
r5993 r6117 8 8 psArgumentVerbosity (argc, argv); 9 9 10 if (*argc != 4) usage ();10 if (*argc != 7) usage (); 11 11 12 12 return; … … 15 15 static int usage () { 16 16 17 fprintf (stderr, "USAGE: psphotTest (input.fits) (output. hdr) (out.fits)\n");17 fprintf (stderr, "USAGE: psphotTest (input.fits) (output.jpg) (zero) (scale) (colormap) (rebin)\n"); 18 18 exit (2); 19 19 }
Note:
See TracChangeset
for help on using the changeset viewer.
