Changeset 5654 for trunk/psphot/src/psphotSparseMatrix.c
- Timestamp:
- Dec 1, 2005, 9:55:16 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotSparseMatrix.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotSparseMatrix.c
r5653 r5654 1 1 # include "psphot.h" 2 2 3 psSparse *psphotStarOverlaps (psArray *sources) { 3 bool psphotEnsemblePSF (eamReadout *imdata, psMetadata *config, psArray *sources, pmPSF *psf, psStats *sky) { 4 4 5 pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type); 6 psVector *x = psVectorAlloc(2, PS_TYPE_F32); 7 psVector *params = model->params; 5 bool status; 6 float x; 7 float y; 8 float Sky; 9 int Nfit = 0; 8 10 9 // source analysis is done in S/N order (brightest first) 11 psTimerStart ("psphot"); 12 13 // source analysis is done in spatial order 10 14 sources = psArraySort (sources, psphotSortByY); 11 15 12 // fill out the models for each object 13 // XXX need to assign the model parameters using the PSF function, with unit peak 16 float OUTER_RADIUS = psMetadataLookupF32 (&status, config, "SKY_OUTER_RADIUS"); 17 float PSF_FIT_NSIGMA = psMetadataLookupF32 (&status, config, "PSF_FIT_NSIGMA"); 18 float PSF_FIT_PADDING = psMetadataLookupF32 (&status, config, "PSF_FIT_PADDING"); 19 20 // set the object surface-brightness limit for fitted pixels 21 float FLUX_LIMIT = PSF_FIT_NSIGMA * sky->sampleStdev; 22 psLogMsg ("psphot.apply_psf_model", 4, "fitting pixels with at least %f object counts\n", FLUX_LIMIT); 23 24 // vector for model input coordinates 25 psVector *x = psVectorAlloc(2, PS_TYPE_F32); 26 27 // this function specifies the radius at this the model hits the given flux 28 pmModelRadius modelRadius = pmModelRadius_GetFunction (psf->type); 29 30 // this is the function to get the model function 31 pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type); 32 33 // pre-calculate all model pixels 14 34 psArray *pixlist = psArrayAlloc (sources->n); 15 35 for (int k = 0; k < sources->n; k++) { 16 src = sources->data[k]; 36 source = sources->data[k]; 37 38 // use the source moments, etc to guess basic model parameters 39 pmModel *modelFLT = pmSourceModelGuess (source, psf->type); 40 41 // set PSF parameters for this model 42 pmModel *model = pmModelFromPSF (modelFLT, psf); 43 // model->params->data.F32[2] = source->peak->x; 44 // model->params->data.F32[3] = source->peak->y; 45 model->params->data.F32[1] = 1.0; 46 x = model->params->data.F32[2]; 47 y = model->params->data.F32[3]; 48 psFree (modelFLT); 49 50 // set the fit radius based on the object flux limit and the model 51 // XXX EAM : FLUX_LIMIT should be set based on local sky model (not global median) 52 model->radius = modelRadius (model->params, FLUX_LIMIT) + PSF_FIT_PADDING; 53 if (isnan(model->radius)) { 54 psAbort ("apply_psf_model", "error in radius"); 55 } 56 57 // build the model image 17 58 nx = src->pixels->numCols; 18 59 ny = src->pixels->numRows; 19 60 im = psImageAlloc (nx, ny, PS_DATA_F32); 61 mk = psImageAlloc (nx, ny, PS_DATA_U8); 62 63 // fill in the model pixel values 64 psImageKeepCircle (mk, x, y, model->radius, "OR", PSPHOT_MASK_MARKED); 65 psVector *params = model->params; 20 66 for (int i = 0; i < nx; i++) { 21 67 for (int j = 0; j < ny; j++) { 68 if (mk->data.U8[j][i]) continue; 22 69 x->data.F32[0] = (float) i + pix->col0; 23 70 x->data.F32[1] = (float) j + pix->row0; … … 28 75 } 29 76 30 psVector *Aij = psVectorAlloc (100, PS_DATA_F32); 31 psVector *Bfj = psVectorAlloc (100, PS_DATA_F32); 32 psVector *Si = psVectorAlloc (100, PS_DATA_S32); 33 psVector *Sj = psVectorAlloc (100, PS_DATA_S32); 77 // fill out the sparse matrix 78 psSparse *sparse = psSparseAlloc (sources->n, 100); 79 psVector *Aij = sparse->Aij; 80 psVector *Bfj = sparse->Bfj; 81 psVector *Si = sparse->Si; 82 psVector *Sj = sparse->Sj; 34 83 35 84 int Ri, Rj; … … 42 91 // diagonal element (auto-cross-product) 43 92 f = psphotCrossProduct (pi, pi); 44 Aij->data.F32[Nelem] = f; 45 Si->data.S32[Nelem] = i; 46 Sj->data.S32[Nelem] = j; 47 Nelem ++; 48 49 Qii->data.F32[i] = f; 93 psSparseMatrixElement (sparse, i, i, f); 50 94 51 95 // find the image x model value 52 96 f = psphotCrossProduct (pi, pf); 53 Bfj->data.F32[i] = f;97 psSparseVectorElement (sparse, i, f); 54 98 55 99 // loop over all other stars following this one … … 64 108 // got an overlap; calculate cross-product and add to output array 65 109 f = psphotCrossProduct (pi, pj); 66 67 Aij->data.F32[Nelem] = f; 68 Si->data.S32[Nelem] = i; 69 Sj->data.S32[Nelem] = j; 70 Nelem ++; 71 72 Aij->data.F32[Nelem] = f; 73 Si->data.S32[Nelem] = j; 74 Sj->data.S32[Nelem] = i; 75 Nelem ++; 110 psSparseMatrixElement (sparse, j, i, f); 76 111 } 77 112 } 78 79 index = psVectorSortIndex (NULL, Sj); 80 81 psVector *tAij = psVectorAlloc (Nelem, PS_DATA_F32); 82 psVector *tSi = psVectorAlloc (Nelem, PS_DATA_S32); 83 psVector *tSj = psVectorAlloc (Nelem, PS_DATA_S32); 84 for (i = 0; i < Nelem; i++) { 85 j = index->data.U32[i]; 86 tAij->data.F32[i] = Aij->data.F32[j]; 87 tSi->data.S32[i] = Si->data.S32[j]; 88 tSj->data.S32[i] = Sj->data.S32[j]; 89 } 90 psFree (Aij); 91 psFree (Si); 92 psFree (Sj); 93 94 sparse->Aij = Aij; 95 sparse->Bfj = Bfj; 96 sparse->Qii = Qii; 97 sparse->Si = Si; 98 sparse->Sj = Sj; 99 sparse->Nelem = Nelem; 100 sparse->Nrows = sources->n; 101 113 114 psSparseResort (sparse); 102 115 return (match); 103 116 }
Note:
See TracChangeset
for help on using the changeset viewer.
