- Timestamp:
- Jun 5, 2008, 3:29:09 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080511/ppSim/src/ppSimLoadForceSources.c
r17930 r17935 1 1 # include "ppSim.h" 2 3 // Reset a pointer: free and set to NULL 4 #define RESET(PTR) \ 5 psFree(PTR); \ 6 PTR = NULL; 2 7 3 8 psArray *ppSimLoadForceSources(pmConfig *config, const pmFPAview *view) { 4 9 5 psArray *result = psArrayAlloc(0); 6 return result; 10 bool status; 7 11 8 # if (0) 12 pmFPAfile *outFile = psMetadataLookupPtr(NULL, config->files, "PPSIM.OUTPUT"); 13 psAssert(outFile, "missing PPSIM.OUTPUT"); 14 psAssert(outFile->fpa, "missing fpr for PPSIM.OUTPUT"); 9 15 10 // de-activate all files except PSASTRO.REFSTARS11 pm FPAfileActivate (config->files, false, NULL);12 pmFPAfileActivate (config->files, true, "PSASTRO.OUT.REFSTARS");16 pmChip *outChip = pmFPAviewThisChip (view, outFile->fpa); 17 pmPSF *psf = psMetadataLookupPtr (&status, outChip->analysis, "PSPHOT.PSF"); 18 assert (psf); 13 19 14 readout = pmFPAviewThisReadout (view, fpa);15 if (! readout->data_exists) { continue; }20 psArray *spots = psMetadataLookupPtr(&status, outFile->fpa->analysis, "FORCED.SPOTS"); 21 PS_ASSERT_PTR_NON_NULL (spots, NULL); 16 22 17 // read WCS data from the corresponding header 18 pmHDU *hdu = pmFPAviewThisHDU (view, fpa); 23 // in this program, we are looping over the output image, rather than the input as in ppImage 24 pmFPAfile *srcFile = psMetadataLookupPtr(NULL, config->files, "PPSIM.REAL.SOURCES"); 25 psAssert(srcFile, "missing PPSIM.REAL.SOURCES"); 19 26 20 int Nx = psMetadataLookupS32 (&status, hdu->header, "NAXIS1"); 21 int Ny = psMetadataLookupS32 (&status, hdu->header, "NAXIS2"); 27 pmFPA *fpa = srcFile->fpa; 28 pmChip *chip = pmFPAviewThisChip (view, fpa); 29 // pmCell *cell = pmFPAviewThisCell (view, fpa); 30 pmReadout *readout = pmFPAviewThisReadout (view, fpa); 22 31 23 float minX = -fieldPadding*Nx; 24 float maxX = (1+fieldPadding)*Nx; 25 float minY = -fieldPadding*Ny; 26 float maxY = (1+fieldPadding)*Ny; 32 // XXX we should have only one cell and readout per chip, right? 27 33 28 // the refstars is a subset within range of this chip 29 psArray *refstars = psArrayAllocEmpty (100); 34 // read WCS from existing output from psphot & psastro 35 // XXX can we be more flexible? ie, use the header of PPSIM.CHIP? 36 bool bilevelAstrometry = false; 37 status = psastroAstromGuessSetFPA (fpa, &bilevelAstrometry); 38 psAssert (status, "failed to set astrometry"); 30 39 31 // select the reference objects within range of this readout 32 // project the reference objects to this chip 33 for (int i = 0; i < refs->n; i++) { 34 pmAstromObj *ref = pmAstromObjCopy(refs->data[index->data.S32[i]]); 40 // the pixel scale is only used to set the focal-plane coordinate system 41 // setting this value to 1 makes this system have the units of pixels 42 float pixelScale = 1.0; 43 status = psastroAstromGuessSetChip (fpa, chip, view, pixelScale, bilevelAstrometry); 44 psAssert (status, "failed to set astrometry"); 35 45 36 psProject (ref->TP, ref->sky, fpa->toSky); 37 psPlaneTransformApply (ref->FP, fpa->fromTPA, ref->TP); 38 psPlaneTransformApply (ref->chip, chip->fromFPA, ref->FP); 46 float minX = 0.0; 47 float maxX = readout->image->numCols; 48 float minY = 0.0; 49 float maxY = readout->image->numRows; 39 50 40 // limit the X,Y range of the refs to the selected chip 41 if (ref->chip->x < minX) goto skip; 42 if (ref->chip->x > maxX) goto skip; 43 if (ref->chip->y < minY) goto skip; 44 if (ref->chip->y > maxY) goto skip; 51 // the sources is a subset within range of this chip 52 psArray *sources = psArrayAllocEmpty (100); 45 53 46 psArrayAdd (refstars, 100, ref);47 skip:48 psFree (ref);54 // Select the spots within range of this readout. Project the spots to this chip 55 for (int i = 0; i < spots->n; i++) { 56 pmAstromObj *obj = spots->data[i]; 49 57 50 if (nMax && (refstars->n >= nMax)) break;51 } 52 psTrace ("psastro", 4, "Added %ld refstars\n", refstars->n);58 psProject (obj->TP, obj->sky, fpa->toSky); 59 psPlaneTransformApply (obj->FP, fpa->fromTPA, obj->TP); 60 psPlaneTransformApply (obj->chip, chip->fromFPA, obj->FP); 53 61 54 psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSASTRO.REFSTARS", PS_DATA_ARRAY, "astrometry matches", refstars); 55 psFree (refstars); 62 // limit the X,Y range of the objs to the selected chip 63 if (obj->chip->x < minX) continue; 64 if (obj->chip->x > maxX) continue; 65 if (obj->chip->y < minY) continue; 66 if (obj->chip->y > maxY) continue; 56 67 57 if (matchLumFunc) { 58 // in this case, no PSASTRO.REFSTARS is added to readout->analysis 59 if (!psastroRefstarSubset (readout)) { 60 psError(PSASTRO_ERR_DATA, false, "Can't determine an appropriate refstar subset\n"); 61 psFree (index); 62 psFree (view); 63 return false; 64 } 65 } 66 } 67 } 68 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE; 68 // convert the pmAstromObj to pmSource 69 70 // instantiate a model for the PSF at this location, Io = 1.0 71 pmModel *model = pmModelFromPSFforXY (psf, obj->chip->x, obj->chip->y, 1.0); 72 73 // XXX let the flux limit be a user-defined number of sky sigmas (not just 1.0) 74 // XXX use a fixed radius?? 75 // float radius = model->modelRadius (model->params, roughNoise); 76 // radius = PS_MAX (radius, 1.0); 77 float radius = 5.0; 78 79 // construct a source, with model flux pixels set, based on the model 80 pmSource *source = pmSourceFromModel (model, readout, radius, PM_SOURCE_TYPE_STAR); 81 82 // XXX set the mag & err values (should this be done in pmSourceFromModel?) 83 // XXX i should be applying the gain and the correct effective area 84 // psEllipseAxes axes = pmPSF_ModelToAxes (model->params->data.F32, 20.0); 85 // psF64 Area = 2.0 * M_PI * axes.major * axes.minor; 86 87 // these are not really needed since we will be fitting for them 88 source->psfMag = NAN; 89 source->errMag = NAN; 90 91 // insert the source flux in the image 92 // XXX not sure the offset is really 0,0 93 pmSourceAddWithOffset (source, PM_MODEL_OP_FULL, 0xff, 0.0, 0.0); 94 pmSourceAddWithOffset (source, PM_MODEL_OP_FULL | PM_MODEL_OP_NOISE, 0xff, 0.0, 0.0); 95 96 // Blow away the image parts of the source, which makes the memory explode 97 RESET(source->pixels); 98 RESET(source->weight); 99 RESET(source->maskObj); 100 RESET(source->maskView); 101 RESET(source->modelFlux); 102 RESET(source->psfFlux); 103 RESET(source->blends); 104 105 psArrayAdd (sources, 100, source); 106 psFree(source); // Drop local reference 69 107 } 70 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;108 psTrace ("psastro", 4, "Added %ld sources\n", sources->n); 71 109 72 // activate all files except PSASTRO.OUTPUT 73 74 pmFPAfileActivate (config->files, true, NULL); 75 pmFPAfileActivate (config->files, false, "PSASTRO.OUT.REFSTARS"); 76 # endif 77 78 return NULL; 110 return sources; 79 111 }
Note:
See TracChangeset
for help on using the changeset viewer.
