Changeset 5828 for trunk/psphot/src/psphotModelTest.c
- Timestamp:
- Dec 22, 2005, 4:20:27 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotModelTest.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotModelTest.c
r5802 r5828 1 1 # include "psphot.h" 2 # include "psEllipse.h" 2 3 3 int main (int argc, char **argv) {4 bool psphotModelTest (eamReadout *imdata, psMetadata *config) { 4 5 5 psphotModelGroupInit (); 6 bool status; 7 int modelType; 8 float obsMag, fitMag, value; 9 char name[64]; 10 pmPSF *psf; 6 11 7 psMetadata *config = modelTestArguments (&argc, argv); 8 eamReadout *imdata = psphotSetup (config); 12 psMetadataItem *item = NULL; 9 13 10 modelTestFitSource (imdata, config); 14 // what fitting mode to use? 15 char *psfModeWord = psMetadataLookupPtr (&status, config, "TEST_FIT_MODE"); 16 if (!status) { 17 psfModeWord = psStringCopy ("FLT"); 18 } 19 bool psfMode = !strcasecmp (psfModeWord, "PSF"); 11 20 12 exit (0); 21 // in psfMode, psf sets the model type 22 if (psfMode) { 23 char *psfFile = psMetadataLookupPtr (&status, config, "PSF_INPUT_FILE"); 24 if (!status) psAbort ("psphotModelTest", "PSF_INPUT_FILE not supplied"); 25 psf = psphotReadPSF (psfFile); 26 modelType = psf->type; 27 } else { 28 // find the model: supplied by user or first in the PSF_MODEL list 29 char *modelName = psMetadataLookupPtr (&status, config, "TEST_FIT_MODEL"); 30 if (modelName == NULL) { 31 // get the list pointers for the PSF_MODEL entries 32 psMetadataItem *mdi = psMetadataLookup (config, "PSF_MODEL"); 33 if (mdi == NULL) psAbort ("psphotChoosePSF", "missing PSF_MODEL selection"); 34 35 // take the first list element 36 psList *list = (psList *) mdi->data.list; 37 item = psListGet (list, PS_LIST_HEAD); 38 modelName = item->data.V; 39 } 40 modelType = pmModelSetType (modelName); 41 if (modelType < 0) psAbort ("fitsource", "unknown model %s", modelName); 42 } 43 44 // find the fitting parameters (try test values first) 45 float INNER = psMetadataLookupF32 (&status, config, "TEST_FIT_INNER_RADIUS"); 46 if (!status) { 47 INNER = psMetadataLookupF32 (&status, config, "SKY_INNER_RADIUS"); 48 } 49 50 float OUTER = psMetadataLookupF32 (&status, config, "TEST_FIT_OUTER_RADIUS"); 51 if (!status) { 52 OUTER = psMetadataLookupF32 (&status, config, "SKY_OUTER_RADIUS"); 53 } 54 55 float RADIUS = psMetadataLookupF32 (&status, config, "TEST_FIT_RADIUS"); 56 if (!status) { 57 RADIUS = psMetadataLookupF32 (&status, config, "PSF_FIT_RADIUS"); 58 } 59 60 float mRADIUS = psMetadataLookupF32 (&status, config, "TEST_MOMENTS_RADIUS"); 61 if (!status) { 62 mRADIUS = psMetadataLookupF32 (&status, config, "PSF_MOMENTS_RADIUS"); 63 } 64 65 // define the source of interest 66 float xObj = psMetadataLookupF32 (&status, config, "TEST_FIT_X"); 67 float yObj = psMetadataLookupF32 (&status, config, "TEST_FIT_Y"); 68 69 // construct the source structures 70 pmSource *source = pmSourceAlloc(); 71 source->peak = pmPeakAlloc (xObj, yObj, 0, 0); 72 psphotDefinePixels (source, imdata, xObj, yObj, OUTER); 73 74 // find the local sky 75 status = pmSourceLocalSky (source, PS_STAT_SAMPLE_MEDIAN, INNER); 76 if (!status) psAbort ("fitsource", "pmSourceLocalSky error"); 77 78 // get the source moments 79 status = pmSourceMoments (source, mRADIUS); 80 if (!status) psAbort ("fitsource", "pmSourceLocalSky error"); 81 source->peak->counts = source->moments->Peak; 82 83 fprintf (stderr, "sum: %f @ (%f, %f)\n", source->moments->Sum, source->moments->x, source->moments->y); 84 85 EllipseMoments moments; 86 moments.x2 = source->moments->Sx; 87 moments.y2 = source->moments->Sy; 88 moments.xy = source->moments->Sxy; 89 EllipseAxes axes = EllipseMomentsToAxes (moments); 90 91 fprintf (stderr, "axes: %f @ (%f, %f)\n", axes.theta*180/M_PI, axes.major, axes.minor); 92 93 // get the initial model parameter guess 94 pmModel *model = pmSourceModelGuess (source, modelType); 95 // if any parameters are defined, use those values 96 int nParams = pmModelParameterCount (modelType); 97 psF32 *params = model->params->data.F32; 98 for (int i = 0; i < nParams; i++) { 99 if (i == 2) { 100 params[i] = xObj; 101 continue; 102 } 103 if (i == 3) { 104 params[i] = yObj; 105 continue; 106 } 107 sprintf (name, "TEST_FIT_PAR%d", i); 108 value = psMetadataLookupF32 (&status, config, name); 109 if (status) { 110 params[i] = value; 111 } 112 } 113 114 float area = params[4]*params[5]; 115 fprintf (stderr, "peak: %f @ (%f, %f)\n", source->moments->Sum*area, (double)source->peak->x, (double)source->peak->y); 116 117 if (psfMode) { 118 pmModel *modelPSF = pmModelFromPSF (model, psf); 119 psFree (model); 120 model = modelPSF; 121 params = model->params->data.F32; 122 } 123 124 // list model input shape 125 EllipseShape shape; 126 shape.sx = 1.4 / model->params->data.F32[4]; 127 shape.sy = 1.4 / model->params->data.F32[5]; 128 shape.sxy = model->params->data.F32[6]; 129 axes = EllipseShapeToAxes (shape); 130 131 fprintf (stderr, "guess: %f @ (%f, %f)\n", axes.theta*180/M_PI, axes.major, axes.minor); 132 133 134 fprintf (stderr, "input parameters: \n"); 135 for (int i = 0; i < nParams; i++) { 136 fprintf (stderr, "%d : %f\n", i, params[i]); 137 } 138 139 // define the pixels used for the fit 140 psImageKeepCircle (source->mask, xObj, yObj, RADIUS, "OR", PSPHOT_MASK_MARKED); 141 142 char *fitset = psMetadataLookupPtr (&status, config, "TEST_FIT_SET"); 143 if (status) { 144 status = psphotFitSet (source, model, fitset, psfMode); 145 return status; 146 } 147 148 status = pmSourceFitModel (source, model, psfMode); 149 150 // measure the source mags 151 pmSourcePhotometry (&fitMag, &obsMag, model, source->pixels, source->mask); 152 fprintf (stderr, "ap: %f, fit: %f, apmifit: %f\n", obsMag, fitMag, obsMag - fitMag); 153 154 // write out positive object 155 psphotSaveImage (NULL, source->pixels, "object.fits"); 156 157 // subtract object, leave local sky 158 pmSourceSubModel (source->pixels, source->mask, model, false, false); 159 160 fprintf (stderr, "output parameters: \n"); 161 for (int i = 0; i < nParams; i++) { 162 fprintf (stderr, "%d : %f\n", i, params[i]); 163 } 164 165 // write out 166 psphotSaveImage (NULL, source->pixels, "resid.fits"); 167 psphotSaveImage (NULL, source->mask, "mask.fits"); 168 return true; 13 169 }
Note:
See TracChangeset
for help on using the changeset viewer.
